// JavaScript Document

// suckerfish dropdowns - http://www.htmldog.com/articles/suckerfish/dropdowns/ - thank you htmldog!!!
sfHover = function() {
	var nav = document.getElementById("mainNav"); 
	if (nav) {
		var sfEls = document.getElementById("mainNav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


<!--Fonction MENU Slide pages Prod -->
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function flevDivPositionValue(sDiv, sProperty) { // v2.1, Marja Ribbers-de Vroed, FlevOOware
	this.opera = (window.opera); // Opera 5+
	this.ns4 = (document.layers); // Netscape 4.x
	this.ns6 = (document.getElementById && !document.all && !this.opera); // Netscape 6+
	this.ie = (document.all);  // Internet Explorer 4+
    var sValue = ""; docObj = eval("MM_findObj('" + sDiv + "')"); if (docObj == null) {return 0;}
	if ((sProperty == "left") || (sProperty == "top")) {
		if (!this.ns4) {docObj = docObj.style;} 
		sValue = eval("docObj." + sProperty);
		if ((this.ie) && (sValue == "")) { // IE (on PC) bug with nested layers
			if (sProperty == "top") { sValue = eval(sDiv + ".offsetTop"); } 
			else { sValue = eval(sDiv + ".offsetLeft"); } 
		};
	}
	else {
		if (this.opera) {
			docObj = docObj.style;
			if (sProperty == "height") { sValue = docObj.pixelHeight; } 
			else if (sProperty == "width") { sValue = docObj.pixelWidth; } 
		}
		else if (this.ns4) {sValue = eval("docObj.clip." + sProperty);} 
		else if (this.ns6) {sValue = document.defaultView.getComputedStyle(docObj, "").getPropertyValue(sProperty); } 
	    else if (this.ie) { 
			if (sProperty == "width") { sValue = eval(sDiv + ".offsetWidth"); } 
			else if (sProperty == "height") { sValue = eval(sDiv + ".offsetHeight"); } 
		}
   	}
	sValue = (sValue == "") ? 0 : sValue; 
	if (isNaN(sValue)) { if (sValue.indexOf('px') > 0) { sValue = sValue.substring(0,sValue.indexOf('px')); } } 
	return parseInt(sValue); 
}

function flevPersistentLayer() { // v3.3, Marja Ribbers-de Vroed, FlevOOware
	var sD = arguments[0], oD = eval("MM_findObj('" + sD + "')"), iWW, iWH, iSX, iSY, iT = 10, sS = "";
	if (!document.layers) {oD = oD.style;}
	if (oD.tmpTimeout != null) {clearTimeout(oD.tmpTimeout);}
	var sXL = arguments[1], sXC = arguments[2], sXR = arguments[3], sYT = arguments[4], sYC = arguments[5], sYB = arguments[6];
	var iS = (arguments.length > 7) ? parseInt(arguments[7]) : 0, iPx = (arguments.length > 8) ? parseInt(arguments[8]) : 0;
	if (window.innerWidth) { // NS4, NS6 and Opera
		var oW = window; iWW = oW.innerWidth; iWH = oW.innerHeight; iSX = oW.pageXOffset; iSY = oW.pageYOffset; }
	else if (document.documentElement && document.documentElement.clientWidth) { // IE6 in standards compliant mode
		var oDE = document.documentElement; iWW = oDE.clientWidth; iWH = oDE.clientHeight; iSX = oDE.scrollLeft; iSY = oDE.scrollTop; }
	else if (document.body) { // IE4+
		var oDB = document.body; iWW = oDB.clientWidth; iWH = oDB.clientHeight; iSX = oDB.scrollLeft; iSY = oDB.scrollTop; }
	else {return;}
 
	var iCX = iNX = flevDivPositionValue(sD, 'left'), iCY = iNY = flevDivPositionValue(sD, 'top');


      if (iNX > iWW || iSY > 9900 || iWW < 800) { 
        var DivFloating = document.getElementById("Layer1");
        DivFloating.style.display='none';
      }
      else {
          var DivFloating = document.getElementById("Layer1");
          DivFloating.style.display='';    
	    if (sXL != "") {iNX = iSX + parseInt(sXL);} 
	    else if (sXC != "") {iNX = Math.round(iSX + (iWW/2) - (flevDivPositionValue(sD, 'width')/2));}
	    else if (sXR != "") {iNX = iSX + iWW - (flevDivPositionValue(sD, 'width') + parseInt(sXR));}

	    if (sYT != "") {iNY = iSY + parseInt(sYT);}
	    else if (sYC != "") {iNY = Math.round(iSY + (iWH/2) - (flevDivPositionValue(sD, 'height')/2));}
	    else if (sYB != "") {iNY = iSY + (iWH - flevDivPositionValue(sD, 'height') - parseInt(sYB));}

	    if ((iCX != iNX) || (iCY != iNY)) {
	        if (iS > 0) {
		      if (iPx > 0) { iT = iS;
			    var iPxX = iPx, iPxY = iPx, iMX = Math.abs(iCX - iNX), iMY = Math.abs(iCY - iNY);
			    // take care of diagonal movement
			    if (iMX < iMY) {iPxY = (iMX != 0) ? ((iMY/iMX)*iPx) : iPx;}
			    else {iPxX = (iMY != 0) ? ((iMX/iMY)*iPx) : iPx;}
			    if (iPxX >= iMX) {iPxX = Math.min(Math.ceil(iPxX), iPx);}
			    if (iPxY >= iMY) {iPxY = Math.min(Math.ceil(iPxY), iPx);}
			    // temporary X/Y coordinates
			    if ((iCX < iNX) && (iCX + iPxX < iNX)) {iNX = iCX + iPxX;}
			    if ((iCX > iNX) && (iCX - iPxX > iNX)) {iNX = iCX - iPxX;}
			    if ((iCY < iNY) && (iCY + iPxY < iNY)) {iNY = iCY + iPxY;}
			    if ((iCY > iNY) && (iCY - iPxY > iNY)) {iNY = iCY - iPxY;} }
		      else { 
			    var iMX = ((iNX - iCX) / iS), iMY = ((iNY - iCY) / iS); 
			    iMX = (iMX > 0) ? Math.ceil(iMX) : Math.floor(iMX); iNX = iCX + iMX; 
			    iMY = (iMY > 0) ? Math.ceil(iMY) : Math.floor(iMY); iNY = iCY + iMY; } }
	    if ((parseInt(navigator.appVersion)>4 || navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {sS="px";}
	    if (iMX != 0) {eval("oD.left = '" + iNX + sS + "'");}
	    if (iMY != 0) {eval("oD.top = '" + iNY + sS + "'");} }
      }
      sXL = iWW/2+240;
	var sF = "flevPersistentLayer('" + sD + "','" + sXL + "','" + sXC + "','" + sXR + "','" + sYT + "','" + sYC + "','" + sYB + "'," + iS + "," + iPx + ")";
	oD.tmpTimeout = setTimeout(sF,10);
}

function flevInitPersistentLayer() { // v3.3, Marja Ribbers-de Vroed, FlevOOware

	if (arguments.length < 8) {return;}
	var sD = arguments[0]; if (sD == "") {return;}
	var	oD = eval("MM_findObj('" + sD + "')"); if (!oD) {return;}
	var iCSS = parseInt(arguments[1]);
	var sXL = arguments[2], sXC = arguments[3], sXR = arguments[4], sYT = arguments[5], sYC = arguments[6], sYB = arguments[7];
	var iS = (arguments.length > 8) ? parseInt(arguments[8]) : 0, iPx = (arguments.length > 9) ? parseInt(arguments[9]) : 0;
	if (iCSS != 0) { if (!document.layers) {oD = oD.style;} sXL = parseInt(oD.left), sYT = parseInt(oD.top);}

	var sF = "flevPersistentLayer('" + sD + "','" + sXL + "','" + sXC + "','" + sXR + "','" + sYT + "','" + sYC + "','" + sYB + "'," + iS + "," + iPx + ")";
	eval(sF);
}


/*// js for switching content on and off under a specific id
function clickObject(name,elementId) { 
	if (!document.getElementById) return;
	var navRoot = document.getElementById(elementId);
	if (navRoot) {
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.id == name) {
				node.className = "texton";			
			} else {
				node.className = "textoff";
			}
		}
	}
}

// turn items on or off, displayed or not displayed
function textOn(name) {
	var item = document.getElementById(name);
	item.className= "texton";
}
function textOff(name) {
	var item = document.getElementById(name);
	item.className= "textoff";
}
// show items as selected
function selected(item,child) {
	for (i=0; i<item.childNodes.length; i++) {
		node = item.childNodes[i];
		if (child == node.id)
			node.className += " selected";
	}		
}
function selectItem(name) {
	var item = document.getElementById(name);
	item.className= "selected";
}

// hide mainNav and utilties for simple eloan background
function hideNav(trigger) {
	var trigger = getQueryVariable(trigger);
	if (trigger) {  
		document.write("<style>\#mainNav, \#utilities \{ display: none; \}\#header \{margin-bottom: -30px;border-bottom: 4px solid \#006699;}</style>");
	}
}

//////////////////// determines page and sets tab to selected
// grabs variables from the address bar
function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
        }
    } 
      //alert('Query Variable ' + variable + ' not found');
}

// grabs variable from url and populates form field, add this to your page: window.onload = getVariables("formName","inputName")
function getVariables(formName,inputName) {
	var fromURL = unescape(getQueryVariable(inputName));
	var cleanURL = fromURL.replace("undefined"," ");
	if (cleanURL) {		
		if (cleanURL != " ")
			eval('document.'+formName+'.'+inputName+'.value = '+'cleanURL');
	}
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function commify(formItem) {
	var formItem = formItem;
    var Num = eval('document.quote.'+formItem+'.value');
    var newNum = "";
    var newNum2 = "";
    var count = 0;
    
    //check for decimal number
    if (Num.indexOf('.') != -1){  //number ends with a decimal point
        if (Num.indexOf('.') == Num.length-1){
            Num += "00";
        }
        if (Num.indexOf('.') == Num.length-2){ //number ends with a single digit
            Num += "0";
        }
        
        var a = Num.split("."); 
        Num = a[0];   //the part we will commify
        var end = a[1] //the decimal place we will ignore and add back later
    }
    else {var end = "00";}  
 
    //this loop actually adds the commas   
    for (var k = Num.length-1; k >= 0; k--){
      var oneChar = Num.charAt(k);
      if (count == 3){
        newNum += ",";
        newNum += oneChar;
        count = 1;
        continue;
      }
      else {
        newNum += oneChar;
        count ++;
      }
   }  //but now the string is reversed!
   
  //re-reverse the string
  for (var k = newNum.length-1; k >= 0; k--){
      var oneChar = newNum.charAt(k);
      newNum2 += oneChar;
  }
   
   // add dollar sign and decimal ending from above
   newNum2 = "$" + newNum2 + "." + end;
   if (formItem == "loanamount") {
   document.quote.loanamount.value = newNum2;
   }
   if (formItem == "propValue") {
   document.quote.propValue.value = newNum2;
   }
}

function init() {    
	// define the variables
	var nav = document.getElementById("mainNav");
	var nav2 = document.getElementById("smallNav"); // for smaller navs
	var context = getQueryVariable('context'); //gets context from function above
	var moduleOption = getQueryVariable('moduleOption'); //gets moduleOption from function above
	
		
	if (nav) {
		selected(nav,context);
	}
	if (nav2) {
		selected(nav2,context);
	}	
	if (moduleOption) {
		clickObject(moduleOption,"switchModules");
	} else {
		clickObject("Main","switchModules");
	}	
	
	// loans landing page - shows user what they are applying for (displays on setup.wm and shortapp.wm)
	var landingloanamount = getQueryVariable('landingloanamount');
	var state = getQueryVariable('state');
	var landingLoan = document.getElementById('landingLoan');
	if ((landingloanamount) || (state)) {
		if (landingLoan) {
			textOn("landingLoan");
		}
	}	
	
	changeUrl();// for landing pages
}

window.onload = init;
*/
/*// loans landing page - formats text showing user what they are applying for (displays on setup.wm and shortapp.wm)
function landingLoan(text) {	
	var landingloanamount = getQueryVariable('landingloanamount');
	if (!landingloanamount) landingloanamount = 'Loan+Amount';
	var state = getQueryVariable('state');
	var autoState = getQueryVariable('borrowers%5B0%5D.residences%5B0%5D.address.state');
	var autoAmount = getQueryVariable('product.loanamount');
	var purpose = getQueryVariable('purpose');
	if (!purpose) var purpose = getQueryVariable('context'); if (!purpose) var purpose = '';
	
	if ((landingloanamount) || (state)) {
		// this code changes the purpose trigger into some text that makes sense for the landing pages
		if (purpose == 'purch') { purpose = 'Home Mortgage';}
		if (purpose == 'refi') { purpose = 'Refinance';}
		if (purpose == 'equity') { purpose = 'Home Equity';}
		if (purpose == 'debt') { purpose = 'Debt Consolidation';}
		if (purpose == 'auto') { purpose = 'Auto';}
		if (purpose == 'secondMortgage') { purpose = 'Second Mortgage';}
		if (purpose == 'moto') { purpose = 'Motorcycle';}
		if (autoAmount) landingloanamount=autoAmount; // for auto
		if (landingloanamount == 'Loan%20Amount' || landingloanamount == 'Loan+Amount') landingloanamount = ''; else landingloanamount = (formatCurrency(landingloanamount)); 
		if (autoState) state=autoState; // for auto
		if (state == ('')) state = ''; else state = ' in ' + (getState(state));
		var text = landingloanamount + ' ' + purpose + ' loan' + state + '.';		
		return text;
	}
} 

// directs pages for loans landing page (for small_app.wm)
function changeUrl(purpose) {
	var form = document.form;
	if (!form) {
	} else { 
		var purpose = document.form.purpose.value;
		var name0;
		var name1;
		if (purpose == '') {name0="disabledLoanAmount"; name1="disabledStates";} 
		if (purpose == 'purch') {name0="homeLoanAmount"; name1="regularStates";}
		if (purpose == 'refi') {name0="homeLoanAmount"; name1="regularStates";}
		if (purpose == 'equity') {name0="homeLoanAmount"; name1="equityStates";}
		if (purpose == 'debt') {name0="homeLoanAmount"; name1="regularStates";}
		if (purpose == 'preapp') {name0="preappLoanAmount"; name1="regularStates";}
		if (purpose == 'auto') {name0="autoLoanAmount"; name1="autoStates";}
		if (purpose == 'secondMortgage') {name0="homeLoanAmount"; name1="equityStates";}

		clickObject(name0,"loanAmount");
		clickObject(name1,"stateOptions");
				
		var context = purpose; 
		document.form.context.value = context;	
		
		return purpose;
	}
}

// goes with small_app.wm landing pages
function selectState(state) {
	var regularStates = document.form.regularStates.value;
	var equityStates = document.form.equityStates.value;
	if (state == 'regularStates') state = regularStates;	
	if (state == 'equityStates') state = equityStates;	
	document.form.state.value = state;
	return state;
}
function completeFields() {
	if (document.form.purpose.value == '') {alert("Please choose a Loan Purpose.");  return false;}
}

// for auto calculator
function autoCalc(name) {
	if (name == "loanamount") { 
		document.autoform.calculateBy[0].checked = true;
		document.autoform.calculateBy[1].checked = false;
		document.autoform.monthly.className="";
		document.autoform.loanamount.className="autoFocus";
		document.autoform.monthly.disabled=true; 
		document.autoform.loanamount.disabled=false; 
		document.autoform.loanamount.focus();
		document.autoform.monthly.value='';} 
	if (name == "monthly") { 
		document.autoform.calculateBy[0].checked = false;
		document.autoform.calculateBy[1].checked = true;
		document.autoform.monthly.className="autoFocus";
		document.autoform.loanamount.className="";
		document.autoform.monthly.disabled=false; 
		document.autoform.loanamount.disabled=true; 
		document.autoform.monthly.focus(); 
		document.autoform.loanamount.value='';} 
}

// auto calc - if user selects lease buyout and then trys to select motorcycle, alert them
function lbo(loantype) {
	var loantype = document.autoform.loantype.value;
	if (loantype == "vlbo") {
		alert("Sorry, Lease Buyout is for Auto only");
		document.autoform.vehicletype.value="auto";
	}
}

// turn help items on or off, displayed or not displayed, used on auto calc 
function helptext(name) {
	var item = document.getElementById(name);
	if (item.className == "helptextOn") {
		item.className= "helptextOff";
		if (name == "help_loanamount") { textOn("monthly_img"); }// special case, turn on question mark img
	} else {
		item.className= "helptextOn";
		if (name == "help_loanamount") { textOff("monthly_img"); }// special case, turn on question mark img
	}
}

// switches out the differenct credit level definitions on auto calc page
function creditLevel(level) {
	var level = document.autoform.creditlevel.value;
	clickObject(level,"help_creditlevel");
}

// takes amount from url and puts it on the calculator page
function showCalcAmount(text) {
	var monthly = getQueryVariable('monthly');
	var loanamount = getQueryVariable('loanamount');
	if (loanamount) { text = formatCurrency(loanamount); }
	if (monthly) { text = formatCurrency(monthly); }
	return text;
}

// auto app PowerCheck delivery options: changes how the check will be sent based on oversees selection
function changeOffshore(offshoreOptions) { 
	// set original choice for "when" options, in case user choses yes, then changes his/her mind
	var options;
	if (offshoreOptions == 'overnight') {options = 'overnight';}	
	if (offshoreOptions == 'usps') {options = 'usps';}
	// if user choses yes, set delivery option to yes
	if (offshoreOptions == 'y') {
		document.appform["processing.powercheck.delivery.when"][0].checked = true;
		document.appform["processing.powercheck.delivery.when"][1].disabled = true;
	}
	// if user choses no, return "when" option to original choice
	if (offshoreOptions == 'n' && options == 'overnight') {
		document.appform["processing.powercheck.delivery.when"][0].checked = true;
		document.appform["processing.powercheck.delivery.when"][1].disabled = false;
	}
	if (offshoreOptions == 'n' && options == 'usps') {
		document.appform["processing.powercheck.delivery.when"][1].checked = true;
		document.appform["processing.powercheck.delivery.when"][1].disabled = false;
	}
	if (offshoreOptions == 'n' && !options) {
		document.appform["processing.powercheck.delivery.when"][1].disabled = false;
	}

	return offshoreOptions;
}

// Bolt|Peters popup functions for surveys and usability studys
function popUp(URL) {
	var day = new Date();
	var id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=450,height=520');");
}

function stateOptions(purpose) {
	if (purpose == 'equity') {
		document.form.state[4].disabled = true;
	}
	return purpose;
}

function getState(id) {
	if (id == '1') {id = 'Alabama';}
	if (id == '2') {id = 'Alaska';}
	if (id == '3') {id = 'Arizona';}
	if (id == '4') {id = 'Arkansas';}
	if (id == '5') {id = 'California';}
	if (id == '6') {id = 'Colorado';}
	if (id == '7') {id = 'Connecticut';}
	if (id == '8') {id = 'Delaware';}
	if (id == '9') {id = 'District of Columbia';}
	if (id == '10') {id = 'Florida';}
	if (id == '11') {id = 'Georgia';}
	if (id == '12') {id = 'Hawaii';}
	if (id == '13') {id = 'Idaho';}
	if (id == '14') {id = 'Illinois';}
	if (id == '15') {id = 'Indiana';}
	if (id == '16') {id = 'Iowa';}
	if (id == '17') {id = 'Kansas';}
	if (id == '18') {id = 'Kentucky';}
	if (id == '19') {id = 'Louisiana';}
	if (id == '20') {id = 'Maine';}
	if (id == '21') {id = 'Maryland';}
	if (id == '22') {id = 'Massachusetts';}
	if (id == '23') {id = 'Michigan';}
	if (id == '24') {id = 'Minnesota';}
	if (id == '25') {id = 'Mississippi';}
	if (id == '26') {id = 'Missouri';}
	if (id == '27') {id = 'Montana';}
	if (id == '28') {id = 'Nebraska';}
	if (id == '29') {id = 'Nevada';}
	if (id == '30') {id = 'New Hampshire';}
	if (id == '31') {id = 'New Jersey';}
	if (id == '32') {id = 'New Mexico';}
	if (id == '33') {id = 'New York';}
	if (id == '34') {id = 'North Carolina';}
	if (id == '35') {id = 'North Dakota';}
	if (id == '36') {id = 'Ohio';}
	if (id == '37') {id = 'Oklahoma';}
	if (id == '38') {id = 'Oregon';}
	if (id == '39') {id = 'Pennsylvania';}
	if (id == '40') {id = 'Rhode Island';}
	if (id == '41') {id = 'South Carolina';}
	if (id == '42') {id = 'South Dakota';}
	if (id == '43') {id = 'Tennessee';}
	if (id == '44') {id = 'Texas';}
	if (id == '45') {id = 'Utah';}
	if (id == '46') {id = 'Vermont';}
	if (id == '47') {id = 'Virginia';}
	if (id == '48') {id = 'Washington';}
	if (id == '49') {id = 'West Virginia';}
	if (id == '50') {id = 'Wisconsin';}
	if (id == '51') {id = 'Wyoming';}
	return id;
}

// CHANGES CURRENCY FORMAT
function formatCurrency(num) {

    var num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num)) num = "0";

    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();

    if(cents<10)
        cents = "0" + cents;

    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
        num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
    }

    return (((sign)?'':'-') + '$' + num);
}

// CHANGES CURRENCY FORMAT - no $ or commas
function formatCurrency2(num) {

    var num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num)) num = "0";

    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();

    if(cents<10)
        cents = "0" + cents;

    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
        num = num.substring(0,num.length-(4*i+3))+ num.substring(num.length-(4*i+3));
    }

    return (((sign)?'':'-') + num);
}

function go() { 
	top.location.href = document.helpForm.links.options[document.helpForm.links.selectedIndex].value; 
}

function go3() { 
	top.location.href = document.testform.links1.options[document.testform.links1.selectedIndex].value; 
}
*/