// JavaScript Document

function close_window() {

    window.close();

}

//POP UPS

function popLogin(url)

    {

        x = window.open(url,"details","scrollbars=no,screenX=0,left=0,screenY=0,top=0,width=500,height=400,resizable=no");

    }
	function popRegister(url)

    {

        x = window.open(url,"details","scrollbars=no,screenX=0,left=0,screenY=0,top=0,width=500,height=700,resizable=no");

    }

function popIDXMLS(url)

    {

        x = window.open(url,"details","scrollbars=yes,screenX=0,left=0,screenY=0,top=0,width=958,height=650,resizable=yes");

    }

		function popMLS(url)

    {

        x = window.open(url,"details","scrollbars=yes,screenX=0,left=0,screenY=0,top=0,width=710,height=700,resizable=yes");

    }

function popNews(url)

    {

        x = window.open(url,"details","scrollbars=yes,screenX=0,left=0,screenY=0,top=0,width=525,height=600,resizable=no");

    }

function popCart(url)

    {

        x = window.open(url,"details","scrollbars=yes,screenX=0,left=0,screenY=0,top=0,width=620,height=700,resizable=no");

    }

function popupCart(url) {

    x = window.open(url,"details","scrollbars=no,screenX=0,left=0,screenY=0,top=0,width=616,height=700,resizable=no");

	}

		

//SAVINGS CALCULATOR

function calcSavings(){

 var houseprice=document.form1.price.value;

 var packageprice = document.form1.package.value;

 document.form1.price1.value=usCurrency(houseprice);

 document.form1.price2.value=usCurrency(houseprice);

 var comm = houseprice * .06;

 document.form1.agentcommission.value=usCurrency(comm);

 varlowcomm = houseprice * .03;

 document.form1.commissionbad.value=usCurrency(varlowcomm);

 document.form1.cost.value=usCurrency(comm);

 document.form1.servicefee.value=usCurrency(packageprice);

 var sav=(houseprice * .03) - packageprice;

 document.form1.savings.value=usCurrency(sav);

 document.form1.price.value="";
 var sellerscost = eval(houseprice * .03) + eval(packageprice)
document.form1.scost.value=usCurrency(sellerscost);

}



function usCurrency(num){

   upperLimit = 6e13;

   num = num-0;

   if (isNaN(num) == true) return "NA";

   else if (num < 0) return "$ 0.00";

   else if (num > upperLimit) return "A Lot";

   else {

      var COMMA = false; 

      num = Number((Math.round(num*100))/100);

      if (num > 999.99) COMMA = true;

      num += "";        // convert to string

      if (num.indexOf("e") != -1) return "$ " + num;

      if (num.indexOf(".") == 0) num = "0" + num;

      if (num.indexOf(".") == -1) num += ".00";

      if ((num.length - num.indexOf(".")) == 2) num += "0";

      if ((num.length - num.indexOf(".")) != 3) return "error";

       if (COMMA == true) {

         // Only takes three lines with regexes

         re = /(d)(d{3})(.|,)/;

         while (num.match(re)) {

           num = num.replace(re, "$1,$2$3")

         }

      }

   return num;

   }

}

//END SAVINGS CALCULATOR
