function switch_type(){
	if(document.signup.user_type.value == 'seeker'){
		document.signup.type.disabled = true;
		document.getElementById("ddType").style.display = 'none'
	}
	else{
		document.signup.type.disabled = false;
		document.getElementById("ddType").style.display = 'inline'
	}
}


//mcalc funcs

//Remove "," separator

function RemoveCommas(number)
{
	string = number + "";
        for (var i = 0; i < string.length; i++) 
          {
	     var thechar = string.substring(i, i + 1);
	     if(thechar == ",") 
               {	
			string=string.substring(0,i)+string.substring(i+1,string.length);
		}
    }

    return string;
}




// Add the "," separator
function AddCommas(number)
{
	just_integer=Math.floor(number);
	decimal_integer=number-just_integer;
    decimal_integer=Math.round(decimal_integer*100);
	decimal_integer=decimal_integer;

	string = just_integer + "";
	string_dec = decimal_integer + "";
  if(string.length>3)
   {
	var number_of_commas=Math.floor(string.length/3);
    var string_head=string.substring(0,string.length-(number_of_commas*3));
	var string_temp="";
	var string_temp2="";
	var string_ready="";

	for (var i = 1; i < number_of_commas+1; i++) 
    {
		var string_temp=","+string.substring(string.length-(3*i),string.length-(3*(i-1)));
		string_temp2=string_temp2+string_temp;	
		string_temp="";	
    }
	string_ready=string_head+string_temp2+"."+string_dec;
	if(string.length==number_of_commas*3)
           { 
               return string_ready.substring(1,string_ready.length); 
           }
	if(string_ready.substring(0,1)=="0")
          {
	       string_ready=string_ready.substring(1,string_ready.length)
	 
               if(string_ready.substring(0,1)=="0")
                 {
         	       string_ready=string_ready.substring(1,string_ready.length);

		       if(string_ready.substring(0,1)=="0")
                          {
         	              string_ready=string_ready.substring(1,string_ready.length);
		          }
		 }

          } 
	return string_ready;
    }

	return number;
}


// Verify
function CheckString(field, error) {
    var string = field.value;

    for (var i = 0; i < string.length; i++) {
	  var thechar = string.substring(i, i + 1);
	  if(!((thechar >= "0" && thechar <= "9") || thechar == "." || thechar==",")) {
		alert(error);
		return false;
	  }
    }
    return true;
}

function round(number){ return Math.floor(number*100)/100; }

function Calculate(form){
    if (!CheckString(form.PP, "Input Error in Purchase Price")){form.PP.focus(); return;}
	if (!CheckString(form.PD, "Input Error in Percent Down")){form.PD.focus(); return;}
	if (!CheckString(form.IR, "Input Error in Interest Rate")){form.IR.focus(); return;}
	if (!CheckString(form.MT, "Input Error in Mortgage Term")){form.MT.focus(); return;}
	if ((form.PP.value == "") ||
		(form.PD.value == "") ||
		(form.IR.value == "") ||
		(form.MT.value == "")){ return;}

    //price = form.PP.value;
    price = RemoveCommas(form.PP.value);
    down = form.PD.value;
    irate = form.IR.value/100.0;
    years = form.MT.value;

    if ((down > 100 || down < 0)&&down != "") {
	alert("Input Error in Percent Down");
	form.PD.focus();
	return;
    }

    if ((irate > 100 || irate < 0)&&irate != "") {
	alert("Input Error in Interest Rate");
	form.IR.focus();
	return;
    }

    if ((years > 100 || years < 1)&&years != "") {
	alert("Input Error in Mortgage Term");
	form.MT.focus();
	return;
    }

    loan = price - (down / 100.0 * price);
    payments = years * 12;

    pay = 0;
    if (irate != 0) {
        var monthly_rate = irate/12;
			base = 1;
			mbase = monthly_rate + 1; 

        for (i=0; i < payments; i++){ base *= mbase; }

		pay = round(loan*monthly_rate / ( 1 - (1/base)));
    }
    else pay = round(loan / payments);

	pay = AddCommas(pay);
form.Total.value=pay;
}

function ClearAll(form){
	form.PP.value = "";
	form.PD.value = "";
	form.IR.value = "";
	form.MT.value = "";
	form.Total.value = "";
}

// include this in your html-code
// <SCRIPT language=javascript src="common.js" type=text/javascript></SCRIPT>

function Illuminate(theRow)
{
    var theCells = null;
    // if the browser can't get the row -> exits
    if (typeof(theRow.style) == 'undefined') {
        return false;
    }
    // Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }
        // Defines the new color
        var newColor = '#F0FDEF';
    // Sets the new color...
    var rowCellsCnt = theCells.length;
    var c = null;
    // ... with DOM compatible browsers except Opera
/*    if (domDetect) {
        for (c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
    }
    // ... with other browsers
    else {
*/
        for (c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
        }
//      }
    return true;
} // end function Illuminate

function Deluminate(theRow, theRowNum)
{
    var theCells = null;
    // if the browser can't get the row -> exits
    if (typeof(theRow.style) == 'undefined') {
        return false;
    }
    // Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }
        // Defines the new color
        var newColor = '#E4E4E4';
        if (theRowNum == 1) {
                newColor = '#F2F2F2';
        }
    // Sets the new color...
    var rowCellsCnt = theCells.length;
    var c = null;
    // ... with DOM compatible browsers except Opera
/*    if (domDetect) {
        for (c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
    }
    // ... with other browsers
    else {
*/
        for (c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
        }
//      }
    return true;
} // end function Deluminate