
function popupHelp(wurl, wname){
	var winl = (screen.width-300)/2;
	var wint = (screen.height-200)/2;
	window.open(wurl,wname,'width=300,height=200,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,status=no,location=no,top='+ wint +',left='+ winl);
	return;
}

function openFAQ(){
var winl = (screen.width-680)/2;
var wint = (screen.height-518)/2;
window.open('http://server.iad.liveperson.net/hc/s-55889769/cmd/kbresource/front_page!PAGETYPE','h','scrollbars=yes,menubar=no,height=518,width=680,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl); 
return;
}

function ThankYouPopup(wurl, wname){
	var winl = (screen.width-300)/2;
	var wint = (screen.height-200)/2;
	window.open(wurl,wname,'width=600,height=340,menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,location=no,top='+ wint +',left='+ winl);
	return;
}

function SelectMe(elementid, val)
{
  if (elementid && typeof(val) == 'string')
  {
    var el = document.getElementById(elementid);
    if (el && el.type == 'select-one' && val && typeof(val) == 'string')
    {
      for (var i = 0; i < el.options.length; i++)
      {
        var opt = el.options[i];
        if (opt.value.toLowerCase() == val.toLowerCase())
        {
          opt.selected = true;
        }
        else
        {
          opt.selected = false;
        }
      }
    }
    else
    {
      alert('Element must be a single select. Value must be a string.');
    }
  }
  else
  {
    alert('ElementID must be a string.');
  }
}
  
function Grabemail()
{
  if ((document.RateAlert.RateAlertEmail.value == "") || (document.RateAlert.RateAlertEmail.value == "youremail@email.com"))
  {
	  alert('You need to enter your email address');
    return;
  }
  if (echeck(document.RateAlert.RateAlertEmail.value) == false)
  {
    alert('Invalid email address, please try again.');
    return;
  }
  else
  {
	  document.images['grabemail'].src = "http://quickapply.com/raimg.cfm?email=" + document.RateAlert.RateAlertEmail.value;
	  opengrabemail();
  }
}

function GrabElearningEmail()
{
  if ((document.elearning.email.value == "") || (document.elearning.email.value == "youremail@email.com"))
  {
	  alert('You need to enter your email address');
    return false;
  }
  if (echeck(document.elearning.email.value) == false)
  {
    alert('Invalid email address, please try again.');
    return false;
  }
  else
  {
	  document.images['emailimage'].src = "CaptureEmailImage.cfm?email=" + document.elearning.email.value;
	  ThankYouPopup("ElearningThanks.cfm", "Thanks");
  }
  return false;
}

function opengrabemail(){
var winl = (screen.width-680)/2;
var wint = (screen.height-518)/2;
window.open('pop_thankU4email.htm','h','scrollbars=no,menubar=no,height=180,width=435,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl); 
return;
}

function openflash(){
var winl = (screen.width-680)/2;
var wint = (screen.height-518)/2;
window.open('pop_HowThisWorks.htm','h','scrollbars=no,menubar=no,height=518,width=680,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl); 
return;
}

function openlendersflash(){
var winl = (screen.width-680)/2;
var wint = (screen.height-518)/2;
window.open('pop_LendersDemo.htm','h','scrollbars=no,menubar=no,height=518,width=680,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl); 
return;
}
function openquickleadflash(){
var winl = (screen.width-680)/2;
var wint = (screen.height-518)/2;
window.open('QuickLeadPres.htm','h','scrollbars=no,menubar=no,height=518,width=680,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl); 
return;
}

function opentellafriend(){
var winl = (screen.width-680)/2;
var wint = (screen.height-518)/2;
window.open('tellafriend.cfm','h','scrollbars=no,menubar=no,height=406,width=286,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl); 
return;
}

function openprivacy(){
var winl = (screen.width-680)/2;
var wint = (screen.height-518)/2;
window.open('pop_Privacy.htm','h','scrollbars=yes,menubar=no,height=518,width=680,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl); 
return;
}

function openphoneprivacy(){
var winl = (screen.width-300)/2;
var wint = (screen.height-300)/2;
window.open('pop_phoneprivacy.htm','Privacy','scrollbars=no,menubar=no,height=335,width=300,resizable=no,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl); 
return;
}
	 
function openquickquide(){
var winl = (screen.width-500)/2;
var wint = (screen.height-300)/2;
window.open('pop_quickguide.cfm','qg','scrollbars=no,menubar=no,height=300,width=500,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl);  
return;
}

function openFieldSecured(){
var winl = (screen.width-300)/2;
var wint = (screen.height-110)/2;
window.open('pop_fieldsecured.htm','qg','scrollbars=no,menubar=no,height=110,width=300,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl);  
return;
}

function opentopguide(cssnum){
var winl = (screen.width-300)/2;
var wint = (screen.height-250)/2;
var winURL = 'pop_' + cssnum + '_topguide.htm'
window.open(winURL,'topguide','scrollbars=no,menubar=no,height=250,width=300,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl); 
return;
}

function chkPblocker(win,url,Jh,Mk)
{
	var Wd=xq(top,url,Jh,Mk);
	if(!Wd){Wd=xq(win,url,Jh,Mk)}
	if(!Wd){alertUnload()}
	else{Wd.close();}
}

function xq(win,url,name,features){
	var Wd;
	if(features){Wd=win.open(url,name,features)}
	else if(name){Wd=win.open(url,name)}
	else{Wd=win.open(url)}
	return Wd;
}

function frmFocus(_e) {
	if(document.layers){
		//thisbrowser="NN4";
		_e.className='temp';
	}
	else if(!document.all && document.getElementById){
		//thisbrowser="NN6";
		_e.className='temp';
		_e.style.background='#87D6FF';
	}
	else if(document.all){
		//thisbrowser="ie"
		_e.style.background='#87D6FF';
	}
}
function frmBlur(_e) {
	if(document.layers){
		//thisbrowser="NN4";
		_e.className='temp';
	}
	else if(!document.all && document.getElementById){
		//thisbrowser="NN6";
		_e.className='temp';
		_e.style.background='#ffffff';
		_e.style.border = '1px solid #899BB1';
	}
	else if(document.all){
		//thisbrowser="ie"
		_e.style.background='#ffffff';
		_e.style.border = '1px solid #899BB1';
	}	
}

function secure(_imgname, fieldname) 
{
	if (fieldname != "") 
	{
		try
		{
			document.images[_imgname].src= "img/1201-secureseal.gif";
			//document.images[_imgname].style= "cursor:hand";
		}
		catch (e)
		{
		}
	}
	else 
	{
		try
		{
			document.images[_imgname].src= "images/blank.gif";
		}
		catch (e)
		{
		}
	}
}

function checkcashout(){
//set cashout amount
	if(document.app.cash_out.value == "") 
	{
		document.app.cash_out.value = 0;
	}

// START: LRE rollout of Cashout Upsell
	var cashOutValue = getInteger(document.app.cash_out.value);
	var totalMortgageBalance = getInteger(document.app.mortgage1_balance.value);
	var totalLoanAmount = totalMortgageBalance + cashOutValue
	var appHomeValue = getInteger(document.app.home_value.value);
	var availableCashOut = 0;



    //
	// get available cash out if LTV (totalLoanAmount/appHomeValue) less then threshold
	//
	if ((totalMortgageBalance <= 100000) && (totalLoanAmount < (appHomeValue * 0.9))) {
		availableCashOut = appHomeValue * 0.9 - totalMortgageBalance;
	}
	else if ((totalMortgageBalance <= 200000) && (totalLoanAmount < (appHomeValue * 0.85))) {
		availableCashOut = appHomeValue * 0.85 - totalMortgageBalance;
	}
	availableCashOut = Math.min(availableCashOut, 100000);
	var additionalCashOut = availableCashOut - cashOutValue;
	var loanamount_cashout = availableCashOut + totalMortgageBalance;
	var loanamount_nocashout = cashOutValue + totalMortgageBalance;
	
	if (additionalCashOut > 0
	&& confirm("You have enough equity available to take out an additional $"
	+ addCommasToNumString(String(additionalCashOut))
	+ ". Click \"OK\" to increase your loan amount."
	+ " Click \"Cancel\" to keep the current loan amount."))
	{
		setFormFieldValue(document.app.cash_out, availableCashOut);
		setFormFieldValue(document.app.loan_amount, loanamount_cashout);
	}
	else
	{
		setFormFieldValue(document.app.loan_amount, loanamount_nocashout);
	}
	// END: LRE rollout of Cashout Upsell

	/* Zero out optional value fields */
	if (document.app.cash_out.value == "") 
	{
		document.app.cash_out.value = "0";
	}
	return true;
}

function setFormFieldValue(hField, selectedValue) {
    if (!hField) {
        return;
    }
    try {
        if (hField.type) {
            if (hField.type == "radio") {
                setRadioValue(hField.form.elements[hField.name], selectedValue);
                return;
            } else {
                hField.value = selectedValue;
                return;
            }
        }
    } catch(ex) {
    }
    try {
        if (hField.length && hField[0] && (hField[0].type == "radio")) {
            setRadioValue(hField[0].form.elements[hField[0].name], selectedValue);
            return;
        }
    } catch(ex) {
    }
} 

function formCheck(formobj,_frm){
	// Enter name of mandatory fields
	//formobj.elements['Submit'].value='Please Wait....';
	//debugger;
	
	//disableAfterSubmit();
	
	if (_frm == 'mortgage')
	{
		if(formobj.elements['scn'].value == "1"){
			var fieldRequired = Array("first_name", "last_name","email","prefix_home_phone","home_phone","suffix_home_phone","home_state","city","home_address","home_zip");
			var fieldDescription = Array("First name", "Last name", "Email","Home phone prefix (xxx)","Home phone xxx-","Home phone suffix -xxxx","State","City","Address","Zip Code");
		}
		else if(formobj.elements['scn'].value == "2"){
			var fieldRequired = Array("PropertyType","credit","interest_rate","home_value","loan_amount","mort_bal","loan_type");
			var fieldDescription = Array("Property Type","Credit","Interest Rate","Home Value","Loan Amount","Mortgage Balanace","Loan Type");
		}
		else if(formobj.elements['scn'].value == "5"){
			var fieldRequired = Array("first_name", "last_name","prefix_home_phone","home_phone","suffix_home_phone","city","home_address","home_zip");
			var fieldDescription = Array("First name", "Last name","Home phone prefix (xxx)","Home phone xxx-","Home phone suffix -xxxx","City","Address","Zip Code");
		}
		else if (formobj.elements['loan_type'].value == "New Home Loan"){
			var fieldRequired = Array("first_name", "last_name","email","prefix_home_phone","home_phone","suffix_home_phone","home_state","city","home_address","home_zip","PropertyType","credit","loan_amount","loan_type");
			var fieldDescription = Array("First name", "Last name", "Email","Home phone prefix (xxx)","Home phone xxx-","Home phone suffix -xxxx","State","City","Address","Zip Code","Property Type","Credit","Loan Amount","Loan Type");
		}
		else {
			var fieldRequired = Array("first_name", "last_name","email","prefix_home_phone","home_phone","suffix_home_phone","home_state","city","home_address","home_zip","PropertyType","credit","interest_rate","home_value","loan_amount","mort_bal","loan_type");
			var fieldDescription = Array("First name", "Last name", "Email","Home phone prefix (xxx)","Home phone xxx-","Home phone suffix -xxxx","State","City","Address","Zip Code","Property Type","Credit","Interest Rate","Home Value","Loan Amount","Mortgage Balanace","Loan Type");
		}
	}
	else
	{
		var fieldRequired = Array("first_name", "last_name","email","prefix_home_phone","home_phone","suffix_home_phone","home_state","credit_card_account","prefix_work_phone","work_phone","suffix_work_phone");
		var fieldDescription = Array("First name", "Last name", "Email","Home phone prefix (xxx)","Home phone xxx-","Home phone suffix -xxxx","State","List one of your Credit Card Accounts:","Work phone prefix (xxx)","Work phone xxx-","Work phone suffix -xxxx");	
	}
	
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].value == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}
	
  try
  {
	  if (echeck(formobj.email.value)==false)
    {
		  alertMsg += " - Bad Email Format\n";
	  }
  }
  catch (e)
  {
  }
  
    try
  {
	  if ((formobj.mort_bal.value/formobj.home_value.value) * 100 > 105)
    {
		  alertMsg += " - LTV must be below 105%\n";
	  }
  }
  catch (e)
  {
  }
  
  try
  {
	  if (echeck(formobj.pass_email.value)==false)
    {
		  alertMsg += " - Bad Email Format\n";
	  }
  }
  catch (e)
  {
  }
	
	if (alertMsg.length == l_Msg)
	{
		document.app.validNavigation.value='1';
		if (document.app.cash_out)
		{
			return checkcashout();
		}
	}
	else
	{
		alert(alertMsg);
		//formobj.elements['Submit'].value='Submit';
		return false;
	}
	return true;
}

function echeck(str) 
{
		var at = "@";
		var dot = ".";
		var lat = str.indexOf(at);
		var lstr = str.length;
		var ldot = str.indexOf(dot);
		if (str.indexOf(at) == -1)
    {
      return false;
    }
		if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr)
    {
      return false;
    }
		if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr)
    {
      return false;
    }
	  if (str.indexOf(at,(lat+1)) != -1)
    {
      return false;
    }
		if (str.substring(lat-1,lat) == dot || str.substring(lat+1,lat+2) == dot)
    {
      return false;
    }
		if (str.indexOf(dot,(lat+2)) == -1)
    {
      return false;
    }
		if (str.indexOf(" ") != -1)
    {
      return false
    }
 		return true					
}

function nexttab(thisone, maxlength, nextfieldname)
{
  if (thisone.type == "select-one")
  {
    eval('document.' + thisone.form.name + '.' + nextfieldname + '.focus()');
  }
  else
  {
	  if ( thisone.value.length == maxlength )
	  {
	   eval('document.' + thisone.form.name + '.' + nextfieldname + '.focus()');
	  }
  }
}

if ( document.layers )
{
   document.captureEvents( Event.KEYUP );
   document.onkeyup = nexttab;
}

function checkLoanPurpose()	{
	var myLayer;
	var myLayer2;
	var selectedValue = document.app.loan_type.options[ document.app.loan_type.selectedIndex].value;

	if(selectedValue == '')
	{
			if(document.layers){
				//thisbrowser="NN4";
			}
			else if(!document.all && document.getElementById){
				//thisbrowser="NN6";
				document.getElementById("NotForNewHome").style.display = 'none';
			}
		 	else if(document.all){
				//thisbrowser="ie"
				document.all["NotForNewHome"].style.display='none';
			}

	}
	else if(selectedValue == 'New Home Loan')
	{
			if(document.layers){
				//thisbrowser="NN4";
			}
			else if(!document.all && document.getElementById){
				//thisbrowser="NN6";
				document.getElementById("NotForNewHome").style.display = '';
			}
		 	else if(document.all){
				//thisbrowser="ie"
				document.all["NotForNewHome"].style.display='none';
			}

	}
	else
	{
			if(document.layers){
				//thisbrowser="NN4";
			}
			else if(!document.all && document.getElementById){
				//thisbrowser="NN6";
				document.getElementById("NotForNewHome").style.display = '';
			}
		 	else if(document.all){
				//thisbrowser="ie"
				document.all["NotForNewHome"].style.display='';
			}

	}
}

// Flash Detection
var _nRequiredVersion = 6; 
var flash2Installed = false; 
var flash3Installed = false; 
var flash4Installed = false; 
var flash5Installed = false; 
var flash6Installed = false; 
var flash7Installed = false; 
var _nMaxVersion = 7;	
var _nActualVersion = 0;	
var _bIsRightVersion = false;	
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; 
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; 
if(isIE && isWin){
document.writeln('<SCR' + 'IPT LANGUAGE=VBScript\>');
document.writeln('on error resume next');
document.writeln('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2")))');
document.writeln('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3")))');
document.writeln('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4")))');
document.writeln('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))'); 
document.writeln('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))'); 
document.writeln('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7")))'); 
document.writeln('</SCR' + 'IPT\>'); 
}
function detectFlashCDD1101235978810() 
{ 
if (navigator.plugins) 
{
if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) 
{
var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
flash2Installed = flashVersion == 2; 
flash3Installed = flashVersion == 3;
flash4Installed = flashVersion == 4;
flash5Installed = flashVersion == 5;
flash6Installed = flashVersion == 6;
flash7Installed = flashVersion >= 7;
}
}
for (var i = 2; i <= _nMaxVersion; i++) 
{ 
if (eval("flash" + i + "Installed") == true) _nActualVersion = i;
}
if(navigator.userAgent.indexOf("WebTV") != -1) _nActualVersion = 3; 

if (_nActualVersion >= _nRequiredVersion) 
{
_bIsRightVersion = true; 
} 
}
detectFlashCDD1101235978810();

/// Rotator Href code ///

function makequickquidevisible(imagenum)
{
	if (imagenum=="2") openquickquide();
	if (imagenum=="3") openflash();
}

function makequickquidevisible(imagenum)
{
	if (imagenum=="2") openFAQ();
}

	// IE BG Image Fix
	try {
		document.execCommand( "BackgroundImageCache", false, true );
	} catch( e ) { };
	
	// END FIX

	// Opens and closes the navigation sub-menu 
	function montre(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
		}
	if (d) {d.style.display='block';}
	}
//	function montreOff(id) {
	//alert("off");
	//var d = document.getElementById(id);
		//for (var i = 1; i<=10; i++) {
			//if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
		//}

	//} 
	// END SUBNAV SCRIPT
	// Opens and closes the navigation sub-menu 
	function loanPurposeAction(loantype) 
  {
    var hstate = document.app.home_state.value;
	  var newpage = "http://www.quickapply.com/qc401.cfm?loan_type=1&state=" + hstate + "&QAS=1312"
      switch (loantype.options[loantype.selectedIndex].value)
      {
        case 'New Purchase Loan':
				window.location=newpage;
			    return true;
		 case 'New Home Loan':
				window.location=newpage;
			    return true;
	    }
      return false;
	}
	function creditAction(credit) 
  {
	  var hstate = document.app.home_state.value;
	  var newpage = "http://www.quickapply.com/qc401.cfm?loan_type=2&state=" + hstate + "&QAS=1312"
      switch (credit.options[credit.selectedIndex].value)
      {
        case '4':
				window.location=newpage;
			    return true;
	    }
      return false;
	}
	// Inner Popup Div 
	function divVisible() {
		if (document.all) {
		document.getElementById('coverSelect').style.visibility="visible";
		document.getElementById('coverSelect').style.width="384px";
		document.getElementById('coverSelect').style.height="373px";
		document.getElementById('coverSelect').style.top="100px";
		document.getElementById('coverSelect').style.left="6px";
		
		document.getElementById('innerpopup').style.visibility="visible";
		document.getElementById('innerpopup').style.width="374px";
		document.getElementById('innerpopup').style.height="363px";
		document.getElementById('innerpopup').style.top="100px";
		document.getElementById('innerpopup').style.left="6px";
		document.getElementById('innerpopup').style.border="5px solid #ffffff";
		document.getElementById('innerpopup').style.background="#eee";
		}
		document.getElementById('innerpopup').style.visibility="visible";
		document.getElementById('innerpopup').style.width="374px";
		document.getElementById('innerpopup').style.height="363px";
		document.getElementById('innerpopup').style.top="100px";
		document.getElementById('innerpopup').style.left="6px";
		document.getElementById('innerpopup').style.border="5px solid #ffffff";
		document.getElementById('innerpopup').style.background="#eee";
	}
		
	function divHide() 
  {
		if (document.all) 
    {
      document.getElementById('coverSelect').style.visibility="hidden";
    }
    document.getElementById('innerpopup').style.visibility="hidden";
	}
	
	function openWait()
  {
	  document.getElementById('innerwait').style.visibility="visible";
  }
    function closeWait()
  {
	  document.getElementById('innerwait').style.visibility="hidden";
	  //document.getElementById('waittrigger').style.visibility="hidden";
  }