function doInArray(pArray,arrayEntryToFind) 
{ 
   for (i=0;i<pArray.length;i++) 
   { 
      if (pArray[i] == arrayEntryToFind) 
	 { 
	 	return true; 
	 } 
}

return false; 
} 

function floor(number)
{
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}

var popUpWin;
function popUpWindow(name, URLStr, width, height, vars)
{
		
	var left = screen.availWidth/2 - width/2;
	var top = screen.availHeight/2 - height/2;

	var toolbar = (/toolbar=yes/.test(vars) == true) ? "yes" : "no";
	var location = (/location=yes/.test(vars) == true) ? "yes" : "no";
	var directories = (/directories=yes/.test(vars) == true) ? "yes" : "no";
	var status = (/status=yes/.test(vars) == true) ? "yes" : "no";
	var menubar = (/menubar=yes/.test(vars) == true) ? "yes" : "no";
	var scrollbars = (/scrollbars=yes/.test(vars) == true) ? "yes" : "no";
	var resizable = (/resizable=yes/.test(vars) == true) ? "yes" : "no";
	var copyhistory = (/copyhistory=yes/.test(vars) == true) ? "yes" : "no";

	if ((typeof popUpWin) == 'object')
	{

	}
	popUpWin = open(URLStr, name, 'toolbar=' + toolbar + ',location=' + location + ',directories=' + directories + ',status=' + status + ',menubar=' + menubar + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',copyhistory=' + copyhistory + ',width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top);
	//popUpWin.focus();
}


function Get_url_params()
{
	params = new Array ();
	var argstring = window . location . search;
	if (argstring . charAt (0) != '?')
		return;
	argstring = argstring . substring (1, argstring . length);
	var argarray = argstring . split ('&');
	var i;
	var myarg;
	for (i = 0; i < argarray . length; ++ i)
	{
		myarg = argarray [i] . split ('=');
		if (myarg . length != 2)
			continue;
		var key = Get_myunescape(myarg[0]);
		var value = Get_myunescape(myarg[1]);
		
		params[key] = value;
	}
}

function Get_myunescape (strMy)
{
	strMy = '' + strMy;
	while (true)
	{
		var i = strMy . indexOf ('+');
		if (i < 0)
			break;
		str = strMy . substring (0, i) + ' ' + strMy . substring (i + 1, strMy . length);
	}
	return unescape (strMy);
}

function HiliteOnOff(intOn, formSection)
{
	var objOn = document.getElementById(formSection + 'On');
	var objOff = document.getElementById(formSection + 'Off');		

	if (objOn && objOff)
	{
		if (intOn)
		{
				objOn.className = 'HiliteOn'; 
				objOff.className = 'HiliteOff';		
		}
		else
		{
				objOn.className = 'HiliteOff'; 
				objOff.className = 'HiliteOn';		
		}
		return true;
	}
	return false;
}

///////////////////////////////////////////////////////////////////////////

function MortgageCalc_init(price)
{
	
document.formMortgageCalculator.txtListPrice.value = price;
document.formMortgageCalculator.txtDownPayment.value = Math.round(0.1*price,0);
MortgageCalc_Refresh();
}

function MortgageCalc_UpdateDownPayment()
{
// figure out the DownPayment value
  var temp = 0;
  var DownPaymentPercent = document.formMortgageCalculator.selQuickDownPayment.options[document.formMortgageCalculator.selQuickDownPayment.options.selectedIndex].value;


//  var drop1Value         = document.formMortgageCalculator.selQuickDownPayment.options[document.formMortgageCalculator.selQuickDownPayment.options.selectedIndex].value; 
	if (DownPaymentPercent == 0)
	{
		document.formMortgageCalculator.txtDownPayment.value = 0;
	}
	else
	{
		document.formMortgageCalculator.txtDownPayment.value = Math.round(((DownPaymentPercent / 100) * document.formMortgageCalculator.txtListPrice.value),0);
	}


  MortgageCalc_Refresh();

}



// Ugly Code, Needs To be Cleaned *** 
function MortgageCalc_Refresh()
{

// determine insurance stuff
  var DownPaymentPercent = Math.round(document.formMortgageCalculator.txtDownPayment.value / document.formMortgageCalculator.txtListPrice.value, 0);
  var insuranceRate = document.formMortgageCalculator.txtMortgageInsurance.value / 100;
  var MortgageMode = document.formMortgageCalculator.selMortgageMode.options[document.formMortgageCalculator.selMortgageMode.options.selectedIndex].value;
  
  //if ( DownPaymentPercent <= 0.05 )  { insuranceRate = 0.0275; } else
  //if ( DownPaymentPercent <= 0.1 )  { insuranceRate = 0.0200; } else
  //if ( DownPaymentPercent <= 0.15 ) { insuranceRate = 0.0175 } else
  //if ( DownPaymentPercent <= 0.20 ) { insuranceRate = 0.0100; } else
  //if ( DownPaymentPercent <= 0.30 ) { insuranceRate = 0.0065; } else
  //if ( DownPaymentPercent <= 0.35 ) { insuranceRate = 0.0050; } else


// figure out the amortization period
  var tempAmortization = document.formMortgageCalculator.selAmortization.options[document.formMortgageCalculator.selAmortization.options.selectedIndex].text;


  // get temporary values
  var temp_mortgageAmount = document.formMortgageCalculator.txtListPrice.value - document.formMortgageCalculator.txtDownPayment.value;
  var temp_insurance = Math.round((temp_mortgageAmount * insuranceRate)*100)/100;
  var temp_TotalMortgage = temp_insurance + temp_mortgageAmount;
  var mi;
  
if (MortgageMode == 'SEMI-ANNUAL')
{
	// Semi-Annual (Canadian)
  mi = Math.pow((1+(document.formMortgageCalculator.txtInterestRate.value / 100)/2),(2/12)) - 1;
}
else
{
	// Monthly (American)
  mi = document.formMortgageCalculator.txtInterestRate.value / (12 * 100); 
}


///////////////////////////////////////
  var base = 1;
  var mbase = 1 + mi;

  for (i=0; i<tempAmortization * 12; i++)
  {
    base = base * mbase;
	//document.formMortgageCalculator.txtDEBUG.value = document.formMortgageCalculator.txtDEBUG.value + 'Month:' + i + '/' + (tempAmortization * 12) + 'value:' + base + '\n';
  }
  var temp_TotalMortgagePayment = floor(temp_TotalMortgage * mi / ( 1 - (1/base)));
  var temp_TotalMortgageLifetimeCost = floor(temp_TotalMortgagePayment * tempAmortization * 12);
  	temp_TotalMortgageLifetimeCost = temp_TotalMortgageLifetimeCost + Number(document.formMortgageCalculator.txtDownPayment.value) + temp_insurance;
  var temp_TotalMortgageLifetimeInterest = temp_TotalMortgageLifetimeCost - document.formMortgageCalculator.txtListPrice.value - temp_insurance;

	insuranceRate = (insuranceRate*100);
		insuranceRate = (insuranceRate*100);	 // Decimal Place Rounding purposes only
	insuranceRate = Math.round(insuranceRate,2);	
		insuranceRate = (insuranceRate/100);     // Decimal Place Rounding purposes only
	if (temp_insurance == 0) 
	{ 
		temp_insurance = '0.00'; 
	}
	else
	{
		temp_insurance = dollarFormat(temp_insurance);
	}

	var MonthlyPayment = 0;
	MonthlyPayment = ((temp_mortgageAmount + temp_TotalMortgageLifetimeInterest)  / (tempAmortization * 12)); 

  // Display Financials
  document.getElementById('report_Price').innerHTML = dollarFormat(document.formMortgageCalculator.txtListPrice.value);
  document.getElementById('report_MortgageAmount').innerHTML = dollarFormat(temp_mortgageAmount);
  document.getElementById('report_Insurance').innerHTML = (temp_insurance);
  document.getElementById('report_TotalMortgage').innerHTML = dollarFormat(temp_TotalMortgage);
  document.getElementById('report_TotalMortgage2').innerHTML = dollarFormat(temp_TotalMortgage);  
  document.getElementById('report_InsuranceRate').innerHTML =  "Mortgage Insurance: [" + (insuranceRate) + "%]";

  //document.getElementById('report_TotalMortgagePayment').innerHTML = "$ " + temp_TotalMortgagePayment;
  document.getElementById('report_MonthlyPayment').innerHTML = dollarFormat(MonthlyPayment);    
  document.getElementById('report_TotalMortgageLifetimeCost').innerHTML = dollarFormat(temp_TotalMortgageLifetimeCost);
  document.getElementById('report_TotalMortgageLifetimeInterest').innerHTML =  dollarFormat(temp_TotalMortgageLifetimeInterest);  
  //document.getElementById('report_TotalMortgageLifetimePrinciple').innerHTML = dollarFormat(document.formMortgageCalculator.txtListPrice.value);  
  document.getElementById('report_TotalMortgageLifetimeInsurance').innerHTML = (temp_insurance);  
}

function MortgageCalc_MonthlyPayment(pMortgageBalance, pInterest, pMortgagePeriods) 
{
		Pa = (PrValue * IntRate) / (1 - Math.pow(1 + IntRate, -Period));	
	var pMonthly = (pMortgageBalance * pInterest) / (1 - Math.pow(1 + pInterest, -pMortgagePeriods));
	return pMonthly;
}





function dollarFormat(p) { 
  var pennies = (p - Math.floor(p))*100; 
  pennies = Math.round(pennies); 
  if (pennies<10) 
  {
    pennies = "0" + pennies; // add a leading zero 
  }
  var pstring = "." + pennies; 
  p = Math.floor(p);   // don't need the pennies anymore. 
  while (p >= 1) 
  { 
    modulus = p%1000; 
 	p = Math.floor(p/1000); 
	
	if (p >= 1) 
	{ 
		if (modulus>=100) 
		 thous = "," 
		else if (modulus>=10) 
		 thous = ",0"   // add one leading zero 
		else 
		 thous = ",00";   // add two leading zeros 
		} 
	else 
	{
		thous = ""; 
	}
	
    thous += modulus; 
 	pstring = thous + pstring; 
  } 
  pstring = "$" + pstring; 
  return pstring; 
}

// adaped from http://www.codelifter.com/main/javascript/emailaddresschecker1.html
function Email_CheckValidity(email)
{
// Note: The next expression must be all on one line...
//       allow no spaces, linefeeds, or carriage returns!
	var email_test = email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.biz)|(\..{2,2}))$)\b/gi);
	if (email_test)
	{
		return true;
	}
	else
	{
		return false;
	}
} 

function MM_jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function checkAllCheckBoxes(form, bChecked) 
{ 
  for (i=0; i<form.elements.length; i++) 
  { 
  	if (form.elements[i].type == "checkbox") 
	 { 
	 form.elements[i].checked = bChecked; 
	 } 
  } 
} 





// START TOOLTIP DISPLAY
var tipwidth='214px' //default tooltip width
var tipbgcolor='lightyellow'  //tooltip bgcolor
var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="-45px" //horizontal offset of tooltip from anchor link
var horizontal_offset="-236px" //horizontal offset of tooltip from anchor link

/////No further editing needed

var ie4=document.all
var ns6=document.getElementById&&!document.all



function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, tipwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
}
return edgeoffset
}

function fixedtooltip(menucontents, obj, e, tipwidth){

if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidetip()
dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
dropmenuobj.innerHTML=menucontents

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
}

function hidetip(e){

if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidetip(){
if (ie4||ns6)
delayhide=setTimeout("hidetip()",disappeardelay)
}

function clearhidetip(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}


// END TOOLTIP DISPLAY


// START BROWSER VERSION

// adapted from http://blogs.msdn.com/giorgio/archive/2009/04/14/how-to-detect-ie8-using-javascript-client-side.aspx
function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

// END BROWSER VERSION


// START TICKER

var ticker_width='500px';                  // width (in pixels)
var ticker_width_left ='510';                  // width + 10 (in pixels)
var ticker_height='18px';                  // height (in pixels)
var ticker_heightbox='22px';                  // height (in pixels)
var ticker_colour='';               // background colour: ffffcc
var ticker_moStop=true;                     // pause on mouseover (true or false)
var ticker_fontfamily = 'arial,sans-serif'; // font for content

var version = getInternetExplorerVersion();
if (version && version >= 8.0) {
	var ticker_speed = 5;
} else {
	var ticker_speed = 1;                        // scroll speed (1 = slow, 5 = fast)
}

var ticker_on = 1;                         // Ticker On = 1, Off = 0;


var cps=ticker_speed; 
var aw, mq; 
var fsz = parseInt(ticker_height) - 4; 

function ticker_startticker()
{
	if (document.getElementById) 
	{
				var tick = '<div style="position:relative;width:'+ticker_width+';height:'+ ticker_heightbox +';overflow:hidden;';
				if (ticker_colour){ tick += 'background-color:'+ticker_colour+'"';} else { tick += '"'; }
				if (ticker_moStop) tick += ' onmouseover="cps=0" onmouseout="cps=ticker_speed"'; tick +='><div id="mq" style="position:absolute;left:0px;top:0px;font-family:'+ticker_fontfamily+';font-size:'+fsz+'px;white-space:nowrap;"><\/div><\/div>'; 

			
		if (document.getElementById('ticker'))
		{
			document.getElementById('ticker').innerHTML = tick; 		
		
			mq = document.getElementById("mq"); 
			mq.style.left = ticker_width_left; 
			mq.innerHTML='<span id="tx">'+ticker_content+'<\/span>'; 
			aw = document.getElementById("tx").offsetWidth; 
			if (version && version >= 8.0) {
				lefttime=setInterval("ticker_scrollticker()",500);		
			} else {
				lefttime=setInterval("ticker_scrollticker()",50);		
			}
		}
	
	}
} 


function ticker_scrollticker()
{
	mq.style.left = (parseInt(mq.style.left)>(-10 - aw)) ?parseInt(mq.style.left)-cps+"px" : parseInt(ticker_width)+10+"px";
} 

if (ticker_on == 1)
{
	window.onload=ticker_startticker;
}
// END TICKER

//////////
// START VALIDATION

	function email_check_unique(email)
	{
		var email_params = 'email=' + email;
		var result = 'test';
		if (http)
		{
			
			http.open("POST", 'sys_check_unique_email.php', true);
			http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			http.onreadystatechange = function()
				{
					if (http.readyState == 4 && http.status == 200)
					{
						document.signup.email_check.value = http.responseText;
					}
				};
			http.send(email_params);
		}
		if (result == 'true')
		{
			return true;
		}
		return false;
	}

// END EMAIL
//////////

//////////
// START VALIDATION
String.prototype.trim = function() 
{ 
	// Strip leading and trailing white-space 
	return this.replace(/^\s*|\s*$/g, ""); 
} 

	function validate_field_text(field, field_label, line_break)
	{
		var msg = "";
		var strValue = '';

			// Text type fields
		   if (field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' || field.type == 'file' || field.type == 'password')
		   {
			strValue = field.value.trim();			  
		   }		   
		   
		   // Checkbox Field - use validate_field_radio()
		   
		   // Select Box Fields
		   if (field.type == 'select-one')
		   {
		   		var si = field.selectedIndex;
				if (si >= 0) 
				{
					strValue = field.options[si].value;
				}
		   }
		
		
		
		if (strValue.trim() == '')
		{
			msg += field_label;
			if (line_break == true)
			{
				msg += "\n"; 
			}
		}
		if (msg != '') {
			msg = "- " + msg;
		}
		return msg;
	}


	function validate_field_radio(field, field_label, line_break)
	{
		var msg = "";
		var strValue = '';
							
			for (i=0; i<field.length; i++)
			{
				if (field[i].checked==true)
				{
					strValue = field[i].value;
				}
			}		   
		
		
		
		if (strValue.trim() == '')
		{
			msg += field_label;
			if (line_break == true)
			{
				msg += "\n"; 
			}
		}
		if (msg != '') {
			msg = "- " + msg;
		}
		return msg;
	}
// END VALIDATION
//////////
function allowOnlyFloatingPointNumbers(textbox, val)
{
  val = val.replace(/[^0-9.-]/g, '');        // strip non-digit chars
  val = stripDuplicateChars(val, '.', 1, 0); // strip excess decimals 
  val = stripDuplicateChars(val, '-', 0, 1); // strip excess minus signs
  textbox.value = val;                       // replace textbox value
}

function stripDuplicateChars(str, strip, n, s)
{
  var count=0; var stripped=str.substring(0, s); var chr;
  for (var i=s; i<str.length; i++){ chr = str.substring(i, i+1);
    if (chr == strip){ count++; if (count<n+1){ stripped = stripped + chr;}}
    else {stripped = stripped + chr;}} return stripped;
}



