siteID = 12;

function goToPage(newURL)
{
  if (newURL == "") {
    // alert("Preview: Nothing selected in text");
  } else {
    trackURL(newURL);
    document.location = newURL;
    // alert("Preview: Would go to site: " + newURL);
  }
  
    return false;
}

function leaving(toURL,leaving){
  // alert("going to: " + toURL);
  from = document.location;
  
  trackURL(toURL);
  
  // alert("from: " + from);
  if (leaving == 1) {
		//to external website
		if(!isException(toURL)) {
		      	redir = "/auto_loans/leaving.html?toURL=" + escape(toURL) + "&" + "fromURL=" + escape(document.location);
		} else {
			//If in the exception list, just send you to the url with no interstitial
			redir = "/c/b.jsp?s=" + siteID + "&p=0" + "&d=" + escape(toURL);
		}
  } else {
		//to another Group website
		if( toURL.indexOf("hsbcusa.com") > 0 || toURL.indexOf("hsbc.com") > 0 )	{
			redir = "/auto_loans/leaving_hsbc.html?toURL=" + escape(toURL) + "&" + "fromURL=" + escape(document.location);
		}
		else {
			//Everything else
		    redir = "/c/b.jsp?s=" + siteID + "&p=0" + "&d=" + escape(toURL);
		}
  }
  
  hostname = window.location.hostname;
  protocol = "http";
  port = getRegionSpecificPort();
  
  redirURL = protocol + "://" + hostname + ":" + port + redir;
  //alert("region specific redir URL = " + redirURL);
  //document.location = redir;  
  window.location.href = redirURL;  

  return false;
}


function leavingOriginations(toURL,leaving){
  // alert("going to: " + toURL);
  from = document.location;
  
  trackURL(toURL);
  
  // alert("from: " + from);
  if (leaving == 1) {
		//to external website
		if(!isException(toURL)) {
		      	redir = "/auto_loans/features/content/leaving.html?toURL=" + escape(toURL) + "&" + "fromURL=" + escape(document.location);
		} else {
			//If in the exception list, just send you to the url with no interstitial
			redir = "/c/b.jsp?s=" + siteID + "&p=0" + "&d=" + escape(toURL);
		}
  } else {
		//to another Group website
		if( toURL.indexOf("hsbcusa.com") > 0 || toURL.indexOf("hsbc.com") > 0 )	{
			redir = "/auto_loans/leaving_hsbc.html?toURL=" + escape(toURL) + "&" + "fromURL=" + escape(document.location);
		}
		else {
			//Everything else
		    redir = "/c/b.jsp?s=" + siteID + "&p=0" + "&d=" + escape(toURL);
		}
  }
  
  hostname = window.location.hostname;
  protocol = "http";
  port = getRegionSpecificPort();
  
  redirURL = protocol + "://" + hostname + ":" + port + redir;
  //alert("region specific redir URL = " + redirURL);
  //document.location = redir;  
//  window.location.href = redirURL;  

   var windowOptions = 'location=no,menubar=yes,resizable=yes,scrollbars=yes,toolbar=no,width=600,height=400';
   window.open(redirURL,'',windowOptions);

  return false;
}


function leavingAutoECare(toURL,leaving,fromURL){
  // alert("going to: " + toURL);
  from = document.location;
  
  trackURL(toURL);

    
  // alert("from: " + from);
  if (leaving == 1) {
		//to external website
		if(!isException(toURL)) {
		      	redir = "/auto_ecare/leaving.html?toURL=" + escape(toURL) + "&" + "fromURL=" + escape(fromURL);
		} else {
			//If in the exception list, just send you to the url with no interstitial
			redir = "/c/b.jsp?s=" + siteID + "&p=0" + "&d=" + escape(toURL);
		}
  } else {
		//to another Group website
		if( toURL.indexOf("hsbcusa.com") > 0 || toURL.indexOf("hsbc.com") > 0 )	{
			redir = "/auto_ecare/leaving_hsbc.html?toURL=" + escape(toURL) + "&" + "fromURL=" + escape(document.location);
		}
		else {
			//Everything else
		    redir = "/c/b.jsp?s=" + siteID + "&p=0" + "&d=" + escape(toURL);
		}
  }

  
  hostname = window.location.hostname;
  protocol = "http";
  port = getRegionSpecificPort();
  
  redirURL = protocol + "://" + hostname + ":" + port + redir;
  //alert("region specific redir URL = " + redirURL);
  //document.location = redir;  
  window.location.href = redirURL;  

  return false;
}




function getRegionSpecificPort()
{
	var hostname = window.location.hostname;
	var port = 80;
	if (hostname.indexOf("localhost") >= 0) {
		port = "9080";
	}
	else if ((hostname.indexOf("ist.") >= 0 )|| (hostname.indexOf("ist1.") >= 0)) {
		port = "85";
	}
	return port;
}

//attach the launch_link function to all the anchor onclick events
//for tracking the link clicks.
//Also track the page.
function page_init()
{
	attach_link_launcher(window.document.body);
	trackPage();
}

function preparePrint() {
   var newURL = location.href;
   if (newURL.indexOf('?')<1) {
      newURL = newURL + "?printFormat=yes";
   } else {
      newURL = newURL + "&printFormat=yes";
   }
   options = 'location=no,menubar=yes,resizable=yes,scrollbars=yes,toolbar=no,width=600,height=400';
   window.open(newURL,'printable',options);
}

function do_print()
{
	window.print();
        setActiveStyleSheet('default');
}

function disclaimer(newURL) {
 fullURL = '/hsbcusa/disclaimer.html?toURL=' + escape(newURL) + '&fromURL=' + escape(document.location);
 options = 'location=no,menubar=yes,resizable=yes,scrollbars=yes,toolbar=no,width=760,height=400';
 window.open(fullURL,'printable',options);
 return false;
}

function notrackURL(targetURL) {}

function trackURL(targetURL){
var re = new RegExp("^(.*?)://([^/]+)(.*)");
  var m = re.exec(targetURL);
  if (m == null) {
    //alert("No match");
  } else {
    //var s = "Match at position " + m.index + ":\n";
    //for (i = 0; i < m.length; i++) {
    //  s = s + m[i] + "\n";
    //}
    //alert(s);
    targetServer = m[2];
    targetURI    = m[3];
    trackURL     = targetServer + targetURI
    if (dcsIsOnsite && dcsIsOnsite(targetServer)) {
    	trackURL = "Offsite: " + trackURL;
    }
    dcsMultiTrack('DCS.dcssip',targetServer,'DCS.dcsuri',targetURI,'WT.ti',trackURL,"DCS.dcsref",location.href,"DCSext.HSBCexit","1");
    
  }
}

function go_home() {
  document.location = default_host;
}

function go_default() {
  document.location = default_host + pagePath;
}

function submitMe(form, but, butName){
    but.name = butName;
    form.submit();
  }

  



function autoTab(input,len, e) {

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
 
  
function toggleVersions(obj1, obj2,obj3,obj4) 
{
	document.getElementById(obj1).style.display= 'block';
	document.getElementById(obj2).style.display= 'none';
	document.getElementById(obj3).style.display= 'none';
	document.getElementById(obj4).style.display= 'block';
}  

//For Save Application Data
function saveForm(form,event,uaction){	
	form.action = event;
	form.userAction.value = uaction;
	form.submit();
}

function saveVehicleQualificationForm(form,event,uaction){	
	enableChildElement("form071");
	enableChildElement("form094");
	form.action = event;
	form.userAction.value = uaction;
	form.submit();
	disableChildElement("form071");
	disableChildElement("form094");
}




//For Close window
function closeWindow(){	
	if(window.event.clientX < 0 && window.event.clientY < 0)
	{	
		var form = document.forms[0]; 		 	 	
  		form.action = form.action + "?action=" + "ev_orig_closewindow";
  		form.userAction.value = "EXIT";  		
		form.submit();	
	}	 	
}

// **** For Time out Functionality - Start ****//

var timerCounter = "60000";  //set counter increments to 1 minute
var counter = 0;	
var timeoutEvent;

function initializeTimeOut(timeoutpage){
	
	var page = timeoutpage;
	if("timeout1"==page){
		timeoutEvent = "ev_orig_timeout1";
	}else if("timeout2"==page){
			timeoutEvent = "ev_orig_timeout2";
		}
			
	timeoutWarning();
	startTimeoutTimer();
} 
	
function timeoutWarning() {	
  	setTimeout("displayWarning()",1200000); //display popup warning after 20 minutes
}

function displayWarning() {	
	warnPopup = window.open("originations/TimeOutWarnPopUp.jsp","Warning","width=335,height=300,scrollbars=no");
  	setTimeout("warnPopup.close()",300000); //close popup warning after 5 minutes
}


function startTimeoutTimer() {	
  	setTimeout("checkForTimeout()",timerCounter);
}

function checkForTimeout() {
	
  	counter = counter + 1;  	
  	  		    
  	if (counter == 25) { //after 25 minutes redirect to Timeout page  		
  		var form = document.forms[0];   		 	  	 	
  	 	form.action = form.action + "?action=" + timeoutEvent+"&siab_microsite=auto_loans";
  	 	form.pageIndicator.value = "time-out-2";
  	 	form.target = "_self";
		form.submit();				   
  	} 	
  	setTimeout("checkForTimeout()",timerCounter);  	
}

function resetTimeoutTimer() {
	counter = 0;  	
  	timeoutWarning();
}

function closeSession(){	
	var form = document.forms[0]; 	 	  	 	
  	form.action = form.action + "?action=" + timeoutEvent + "&siab_microsite=auto_loans";
  	form.pageIndicator.value = "time-out-2";  	
  	form.target = "_self";  	
	form.submit();	
}
// **** For Time out Functionality - End ****//

// **** For Application Lookup Functionality - START ****//
function lookupNewWindow()
{
	window.location = "/new_window";
	var obj = window.open("/lookup","AutoOriginations","menubar=no,status=yes,location=yes,toolbar=no,scrollbars=yes,resizable=yes");
	obj.focus();
}

function cancelLookup(form,event,userAction) 
{
	var answer = confirm("Are you actually want to cancel this look up")
	if (answer)
	{
		form.userAction.value=userAction;
		form.action = event;
		form.submit();
	}
}

// Application Summary - START
function selectedAppId(form,event,appNumber)
{
	form.appNumber.value = appNumber;
	form.action = event;
	form.userAction.value = "CONTINUE";
	form.submit();
}
// Application Summary - END

// Application Overview - START
function selectedAppOverView(form,event,action,url) {
	var pageIndicator = document.getElementById("pageIndicator").value;
	var appNumber = document.getElementById("appNumber").value;
	form.actionURL.value = url;
	form.userAction.value=action;
	form.action = event;
	form.target = "AutoOriginations";
	window.location = "/command?action=ev_orig_NewWindowOpen&appNumber="+appNumber+"&actionURL="+url+"&userAction="+action+"&pageIndicator="+pageIndicator;
	var obj = window.open("","AutoOriginations","menubar=no,status=yes,location=no,toolbar=no,scrollbars=yes,resizable=yes"); 
	obj.focus();
	form.submit();
}

function submitBack(form,event,action) 
{
	form.userAction.value=action;
	form.target = "_self";
	form.action = event;
	form.submit();
}
// Application Overview - END
// **** For Application Lookup Functionality - END ****//

// **** For General Display Functionality - START ****//

function showIframeDiv(id)
{
	var browser=navigator.appName;
    var b_version=navigator.appVersion;
    var version=parseFloat(b_version);
	
     if ((browser=="Microsoft Internet Explorer")&& (version>=4))
	 {
	 if (document.getElementById(id).style.display == 'none')
     {
          document.getElementById(id).style.display = ''; 
		  document.getElementById('showIframe').innerHTML='<IFRAME id="iframe1" name="iframe1" src="" scroll="none" style="filter: Alpha(opacity=\'1\'); "></iframe>';
     }
	 }
	 else
	 {
		  document.getElementById(id).style.position = 'relative'; 
		  document.getElementById(id).style.display = ''; 
	 }
}



function show(id)
{
	if (document.getElementById(id).style.display == 'none')
    {
		document.getElementById(id).style.display = '';
    }
}

function hide(id)
{
	document.getElementById(id).style.display = 'none';
}

function showDivision(id) 
{
	if (document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display="block";
	}
}

function hideDivision(id) 
{
	document.getElementById(id).style.display="none";
}

function cancelApplication()
{
	var answer=confirm("Are you sure you do want to cancel? Please click OK to cancel your application or Cancel to return to your application.");
	if(answer)
	{
		window.close(); 
		returnHome("","");
	}
    
}
// **** For General Display Functionality - END ****//

// **** For Capture Applicat Information Functionality - START ****//
function dropDownEmployment(document, selectValue, divID1, divID2,divID3) 
{
	var selectedValue = document.getElementById(selectValue).value;
	if(selectedValue == 'activemilitary')
	{
		if(selectValue != 'jointEmploymentStatus')
		{
		document.getElementById(divID1).style.display="block";
		}
		document.getElementById(divID2).style.display="block";
		document.getElementById(divID3).style.display="none";
	}
	else if(selectedValue == 'employed' || selectedValue == 'selfemployed')
	{
		document.getElementById(divID1).style.display="none";
		document.getElementById(divID2).style.display="block";
		document.getElementById(divID3).style.display="none"
	}
	else
	{
		document.getElementById(divID1).style.display="none";
		document.getElementById(divID2).style.display="none";
		document.getElementById(divID3).style.display="none";
	}
	
	if(selectValue == 'employmentStatus')
	{
		createDynamicMonthlyIncome(document, selectedValue, "monthlyIncomeSource");
	}
	else
	{
		createDynamicMonthlyIncome(document, selectedValue, "jointMonthlyIncomeSource");
	}
}

function createDynamicMonthlyIncome(document, selectedValue, selectbox)
{
	removeAllOptions(document.getElementById(selectbox));
	if(selectedValue == 'activemilitary' || selectedValue == 'employed' || selectedValue == 'selfemployed')
	{
		addOption(document.getElementById(selectbox),"W2P","Salary income with W2 Tax Form");
		addOption(document.getElementById(selectbox),"99P","Salary income with 1099 Tax Form");
		addOption(document.getElementById(selectbox),"SSI","Social Security Income");
		addOption(document.getElementById(selectbox),"LTD","Permanent and Long-Term Disability");
		addOption(document.getElementById(selectbox),"STD","Short-Term Disability or Workers Comp");
	}
	else
	{
		addOption(document.getElementById(selectbox),"W2P","Salary income with W2 Tax Form");
		addOption(document.getElementById(selectbox),"99P","Salary income with 1099 Tax Form");
		addOption(document.getElementById(selectbox),"AL","Alimony");
		addOption(document.getElementById(selectbox),"CS","Child Support");
		addOption(document.getElementById(selectbox),"RNT","Rental Income");
		addOption(document.getElementById(selectbox),"PEN","Retirement Pension or Annuity");
		addOption(document.getElementById(selectbox),"SSI","Social Security Income");
		addOption(document.getElementById(selectbox),"LTD","Permanent and Long-Term Disability");
		addOption(document.getElementById(selectbox),"STD","Short-Term Disability or Workers Comp");
		addOption(document.getElementById(selectbox),"FOS","Foster Care");
		addOption(document.getElementById(selectbox),"OTH","Other");
	}
}

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=1;i--)
	{
		selectbox.remove(i);
	}
}

function addOption(selectbox, value, text)
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function dropDownState(document, selectValue, divID) 
{
	var selectedValue = document.getElementById(selectValue).value;
	if(selectedValue == 'WI')
	{
		document.getElementById(divID).style.display="block";
	}
	else
	{
		document.getElementById(divID).style.display="none";
	}
}

function vehicleInfoDisplay(document, selectValue, auctionInd)
{
	var selectedValue = document.getElementById(selectValue).value;
	if(auctionInd == 'won')
	{
		if(selectedValue == '')
		{
			document.getElementById("form074").disabled=true;
			document.getElementById("form066").disabled=true;
			document.getElementById("form071").disabled=true;
			document.getElementById("form094").disabled=true;
		}
		else
		{
			document.getElementById("form074").disabled=false;
		}
	}
	vehicleDetailsDisplay();
}

function vehicleDetailsDisplay()
{
	var vehicleYear = document.getElementById("form074").value;
	var vehicleMake = document.getElementById("form066").value;
	var vehicleModel = document.getElementById("form071").value;
	var vehicleTrim = document.getElementById("form094").value;
	if(vehicleYear == '')
	{
		document.getElementById("form066").disabled=true;
		document.getElementById("form071").disabled=true;
		document.getElementById("form094").disabled=true;
	}
	else
	{
		if(vehicleMake == '')
		{
			document.getElementById("form071").disabled=true;
			document.getElementById("form094").disabled=true;
		}
		else if(vehicleMake == '01|*Unknown Make')
		{
			document.getElementById("form071").value="01|*Unknown Model";
			document.getElementById("form094").value="00001|*Unknown Trim";
			document.getElementById("form071").disabled=true;
			document.getElementById("form094").disabled=true;
		}
		else
		{
			if(vehicleModel == '')
			{
				document.getElementById("form094").disabled=true;
			}
			else if(vehicleModel == '01|*Unknown Model')
			{
				document.getElementById("form094").value="00001|*Unknown Trim";
				document.getElementById("form094").disabled=true;
			}
		}
	}
}

function MaritalInfoDisplay(document, selectedValue, divID)
{
	if(selectedValue == 'married' || selectedValue == 'legally-separated')
	{
		document.getElementById(divID).style.display="block";
	}
	else
	{
		document.getElementById(divID).style.display="none";
	}
}

function showPreviousJob(document, years, months, divID)
{
	var selectedYears = document.getElementById(years).value;
	var selectedMonths = document.getElementById(months).value;
	if(selectedMonths != '')
	{
		selectedYears = 0 + selectedYears;
		selectedMonths = 0 + selectedMonths;
		if(selectedYears <=0 && selectedMonths <12)
		{
			document.getElementById(divID).style.display="block";
		}
		else
		{
			reInitPreviousJob(document, divID);
			document.getElementById(divID).style.display="none";
		}
	}
	else
	{
		if(selectedYears == '0' || selectedYears == '00')
		{
			document.getElementById(divID).style.display="block";
		}
		else
		{
			reInitPreviousJob(document, divID);
			document.getElementById(divID).style.display="none";
		}
	}
}

function showSecondJob(document, check1, check2, divID)
{
	var otherIncomeCheck1 = document.getElementById(check1).checked;
	var otherIncomeCheck2 = document.getElementById(check2).checked;
	if(otherIncomeCheck1 || otherIncomeCheck2)
	{
		if (document.getElementById(divID).style.display == 'none')
		{
		     document.getElementById(divID).style.display="block";
		}
	}
	else
	{
		reInitSecondJob(document, divID);
		document.getElementById(divID).style.display="none";
	}
}

function toggleAmount(chkbox,checkid,spanid, amountid)
{
	var otherIncomeChecked = document.getElementById(checkid).checked;
	var textarea = document.getElementById(spanid);
	if(otherIncomeChecked)
	{
		textarea.style.visibility = "visible";
	}
	else
	{
		textarea.style.visibility = "hidden";
		document.getElementById(amountid).value="";
	}
}

function jointMonthlyIncomeSourceDisplay(document, monthlyGrossIncome, divID)
{
	var monthlyIncome = document.getElementById(monthlyGrossIncome).value;
	if(monthlyIncome != '')
	{
		monthlyIncome = 0 + monthlyIncome;
		if(monthlyIncome > 0)
		{
			document.getElementById(divID).style.display="block";
		}
		else
		{
			document.getElementById(divID).style.display="none";
			document.getElementById(divID).value="";
			document.getElementById("jointMonthlyIncomeClass").className="";
			document.getElementById("jointMonthlyIncomeError").style.display="none";
		}
	}
	else
	{
		document.getElementById(divID).style.display="none";
		document.getElementById(divID).value="";
		document.getElementById("jointMonthlyIncomeClass").className="";
		document.getElementById("jointMonthlyIncomeError").style.display="none";
	}
}

//Capture Applicant Info dynamic fields re-initialisation methods - START
function reInitWisconsinDetails(document, form, selectValue, maritalStatus, address)
{
	var selectedValue = document.getElementById(selectValue).value;
	if(selectedValue != 'WI')
	{
		form.maritalStatus[0].checked=false;
		form.maritalStatus[1].checked=false;
		form.maritalStatus[2].checked=false;
		document.getElementById("maritalStatusClass").className="";
		document.getElementById("maritalStatusError").style.display="none";
		reInitMaritalStatus(document, form, "single", address);
		MaritalInfoDisplay(document, "single", "spouseInfo");
	}
}

function reInitEmploymentStatus(document, form, selectValue)
{
	var selectedValue = document.getElementById(selectValue).value;
	if(selectedValue == 'employed' || selectedValue == 'selfemployed')
	{
		document.getElementById("militaryRank").value="";
		document.getElementById("militaryClass").className="";
		document.getElementById("militaryError").style.display="none";
		form.liveOnBaseInd[0].checked=false;
		form.liveOnBaseInd[1].checked=false;
		document.getElementById("liveOnBaseClass").className="";
		document.getElementById("liveOnBaseError").style.display="none";
		reinitEmploymentDuration();
	}
	else if(selectedValue == '' || selectedValue == 'retired' || selectedValue == 'other')
	{
		document.getElementById("militaryRank").value="";
		document.getElementById("militaryClass").className="";
		document.getElementById("militaryError").style.display="none";
		form.liveOnBaseInd[0].checked=false;
		form.liveOnBaseInd[1].checked=false;
		document.getElementById("liveOnBaseClass").className="";
		document.getElementById("liveOnBaseError").style.display="none";
		reinitEmploymentDuration();
	}else if(selectedValue == 'activemilitary'){
		reinitEmploymentDuration();
	
	}
}
function reinitEmploymentDuration()
{
		document.getElementById("currentEmploymentYears").value="";
		document.getElementById("currentEmploymentMonths").value="";
		document.getElementById("currentEmploymentClass").className="";
		document.getElementById("currentEmploymentError").style.display="none";
		
		document.getElementById("previousEmploymentYears").value="";
		document.getElementById("previousEmploymentMonths").value="";
		document.getElementById("previousEmploymentClass").className="";
		document.getElementById("previousEmploymentError").style.display="none";

}

function reInitJointEmploymentStatus(document, form, selectValue)
{
		document.getElementById("jointCurrentEmploymentYears").value="";
		document.getElementById("jointCurrentEmploymentMonths").value="";
		document.getElementById("jointCurrentEmploymentClass").className="";
		document.getElementById("jointCurrentEmploymentError").style.display="none";
		document.getElementById("jointPreviousEmploymentYears").value="";
		document.getElementById("jointPreviousEmploymentMonths").value="";
		document.getElementById("jointPreviousEmploymentClass").className="";
		document.getElementById("jointPreviousEmploymentError").style.display="none";
}

function reInitMaritalStatus(document, form, selectedValue, address)
{
	if(selectedValue == '' || selectedValue == 'single')
	{
		document.getElementById("spouseFirstName").value="";
		document.getElementById("spouseMiddleInitial").value="";
		document.getElementById("spouseLastName").value="";
		document.getElementById("spouseSuffix").value="";
		document.getElementById("spouseNameClass").className="";
		document.getElementById("spouseNameError").style.display="none";
		form.spouseAddressOption[0].checked=false;
		form.spouseAddressOption[1].checked=false;
		document.getElementById("spouseAddressOptionClass").className="";
		document.getElementById("spouseAddressOptionError").style.display="none";
		reInitAddress(document, form, address);
	}
}

function reInitOtherMonthlyIncome(document, form, otherMonthlyCheck, otherMonthlyAmount, spanID, divID)
{
	var check = "";
	var amount = "";
	var span= "";
	var fieldClass = "";
	var fieldError = "";

	for(var i=2; i<12; i++)
	{
		check = otherMonthlyCheck + i;
		amount = otherMonthlyAmount + i;
		fieldClass = amount + "Class";
		fieldError = amount + "Error";
		span = spanID + i;
		document.getElementById(check).checked=false;
		document.getElementById(amount).value="";
		var textarea = document.getElementById(span);		
		textarea.style.visibility="hidden";
		document.getElementById(fieldClass).className="";
		document.getElementById(fieldError).style.display="none";
	}

	document.getElementById(otherMonthlyCheck+1).checked=false;
	document.getElementById(otherMonthlyAmount+0).value="";
	var textarea1 = document.getElementById(spanID+1);		
	textarea1.style.visibility="hidden";
	document.getElementById(otherMonthlyAmount+1+"Class").className="";
	document.getElementById(otherMonthlyAmount+1+"Error").style.display="none";

	reInitSecondJob(document, divID);
	document.getElementById(divID).style.display="none";
}

function reInitPreviousJob(document, divID)
{
	if(divID == 'previousEmployment')
	{
		document.getElementById("previousEmploymentYears").value="";
		document.getElementById("previousEmploymentMonths").value="";
		document.getElementById("previousEmploymentClass").className="";
		document.getElementById("previousEmploymentError").style.display="none";
	}
	if(divID == 'jointPreviousEmployment')
	{
		document.getElementById("jointPreviousEmploymentYears").value="";
		document.getElementById("jointPreviousEmploymentMonths").value="";
		document.getElementById("jointPreviousEmploymentClass").className="";
		document.getElementById("jointPreviousEmploymentError").style.display="none";
	}
}

function reInitSecondJob(document, divID)
{
	if(divID == 'secondJobEmployment')
	{
		document.getElementById("secondJobEmploymentYears").value="";
		document.getElementById("secondJobEmploymentMonths").value="";
		document.getElementById("secondJobEmploymentClass").className="";
		document.getElementById("secondJobEmploymentError").style.display="none";
	}
	if(divID == 'jointSecondJobEmployment')
	{
		document.getElementById("jointSecondJobEmploymentYears").value="";
		document.getElementById("jointSecondJobEmploymentMonths").value="";
		document.getElementById("jointSecondJobEmploymentClass").className="";
		document.getElementById("jointSecondJobEmploymentError").style.display="none";
	}
}

function reInitAddress(document, form, address)
{
	if(address == 'jointAddress')
	{
		document.getElementById("jointStreetNumber").value="";
		document.getElementById("jointStreetName").value="";
		document.getElementById("jointAptUnit").value="";
		document.getElementById("jointCity").value="";
		document.getElementById("jointState").value="";
		document.getElementById("jointZipCode").value="";
		document.getElementById("jointAddress1Class").className="";
		document.getElementById("jointAddress1Error").style.display="none";
		document.getElementById("jointAddress2Class").className="";
		document.getElementById("jointAddress2Error").style.display="none";
	}
	else
	{
		document.getElementById("spouseStreetNumber").value="";
		document.getElementById("spouseStreetName").value="";
		document.getElementById("spouseAptUnit").value="";
		document.getElementById("spouseCity").value="";
		document.getElementById("spouseState").value="";
		document.getElementById("spouseZipCode").value="";
		document.getElementById("spouseAddress1Class").className="";
		document.getElementById("spouseAddress1Error").style.display="none";
		document.getElementById("spouseAddress2Class").className="";
		document.getElementById("spouseAddress2Error").style.display="none";
	}
}
//Capture Applicant Info dynamic fields re-initialisation methods - END
// **** For Capture Applicat Information Functionality - END ****//

// **** For Vehicle Qualification Functionality - START ****//
function markSelectedOpenLoan()
{
	var selecteLoanIndex = 0+parseInt(document.VehicleQualificationForm.toMarkLoan.value);
	selecteLoanIndex = (selecteLoanIndex-1);
	selecteLoanIndex =selecteLoanIndex+2; 
	if(selecteLoanIndex!=0)
	{
		document.getElementById('Loan'+selecteLoanIndex).checked=true;
		document.getElementById('red_check' + selecteLoanIndex).src='/auto_loans/images/red_check.gif';	
	}
	
	var noneInd = document.VehicleQualificationForm.toMarkNone.value;
	if(noneInd=='yes')
	{
		document.getElementById('red_check0').src='/auto_loans/images/red_check.gif';	
		document.getElementById('None').checked=true;
		document.VehicleQualificationForm.lender.value = 'None';
		document.VehicleQualificationForm.openDate.value = '';
		document.VehicleQualificationForm.monthlyPayment.value = '';
	}
}

function uploadSelectedLoan(lender,date,payment,checked,size)
{
	for(var i=0;i<=size;i++)
	{		
		document.getElementById('red_check'+i).src='/auto_loans/images/placeholder.gif';
	}	
	document.getElementById(checked).src='/auto_loans/images/red_check.gif';	
	document.VehicleQualificationForm.lender.value = lender;	
	document.VehicleQualificationForm.openDate.value = date;
	document.VehicleQualificationForm.monthlyPayment.value = payment;
}
// **** For Vehicle Qualification Functionality - END ****//

// **** For Process Loan Tersm Functionality - START ****//
var option;
var size;
var index;
function setTermCharacteristic(option)
{
	document.ProcessLoanTermsForm.termCharacteristic.value=option;
}

function markSelectedLoan()
{
	var selecteLoanIndex = document.ProcessLoanTermsForm.selectedloan.value;
	var loanSize = document.ProcessLoanTermsForm.loansSize.value;
	if(selecteLoanIndex!=-1)
	{
		stylesOn(loanSize,selecteLoanIndex);
		document.getElementById('loan_term_options'+selecteLoanIndex).checked=true;
		document.getElementById('Continue').disabled=false;
		document.getElementById('Continue').style.cursor = 'pointer';
	}
}

function stylesOn(size,option) 
{
	for(var i=0;i<size-1;i++)
	{
		document.getElementById('option_title_'+i).style.color='black';
		document.getElementById('option_choice_'+i).className='bottom';
		document.getElementById('option_rate_'+i).style.fontWeight='normal';
		document.getElementById('option_payment_'+i).style.fontWeight='normal';
		document.getElementById('option_months_'+i).style.fontWeight='normal';
		document.getElementById('option_rate_savings_'+i).style.fontWeight='normal';
		document.getElementById('option_monthly_savings_'+i).style.fontWeight='normal';
		document.getElementById('option_total_savings_'+i).style.fontWeight='normal';

		switch(i)
		{
			case 0: document.getElementById('option_rate_'+i).className="middle unchecked";
					break;
			case 1: document.getElementById('option_payment_'+i).className="middle unchecked";
					break;
			case 2: document.getElementById('option_months_'+i).className="middle unchecked";
					break;
		}	
	}
	
	switch(option)
	{
		case '0' :	document.getElementById('option_title_'+option).style.color='#C00';
					document.getElementById('option_rate_'+option).className='middle bg_light_yellow';
					document.getElementById('option_choice_'+option).className='bottom checked';
					document.getElementById('option_rate_'+option).style.fontWeight='bold';
					document.getElementById('option_payment_'+option).style.fontWeight='bold';
					document.getElementById('option_months_'+option).style.fontWeight='bold';
					document.getElementById('option_rate_savings_'+option).style.fontWeight='bold';
					document.getElementById('option_monthly_savings_'+option).style.fontWeight='bold';
					document.getElementById('option_total_savings_'+option).style.fontWeight='bold';
					break;		
		case '1' :	document.getElementById('option_title_'+option).style.color='#C00';
					document.getElementById('option_choice_'+option).className='bottom checked';
					document.getElementById('option_rate_'+option).style.fontWeight='bold';
					document.getElementById('option_payment_'+option).className='middle bg_light_yellow';
					document.getElementById('option_payment_'+option).style.fontWeight='bold';
					document.getElementById('option_months_'+option).style.fontWeight='bold';
					document.getElementById('option_rate_savings_'+option).style.fontWeight='bold';
					document.getElementById('option_monthly_savings_'+option).style.fontWeight='bold';
					document.getElementById('option_total_savings_'+option).style.fontWeight='bold';
					break;
	 case '2':		document.getElementById('option_title_'+option).style.color='#C00';
					document.getElementById('option_choice_'+option).className='bottom checked';
					document.getElementById('option_rate_'+option).style.fontWeight='bold';
					document.getElementById('option_payment_'+option).style.fontWeight='bold';
					document.getElementById('option_months_'+option).className='middle bg_light_yellow';
					document.getElementById('option_months_'+option).style.fontWeight='bold';
					document.getElementById('option_rate_savings_'+option).style.fontWeight='bold';
					document.getElementById('option_monthly_savings_'+option).style.fontWeight='bold';
					document.getElementById('option_total_savings_'+option).style.fontWeight='bold';
					break;
	}	
}

function noThanksOffer()
{
	var answer=confirm("Are you sure you do not want to continue with your application?");
	if(answer)
	{
		saveForm(document.ProcessLoanTermsForm,"/tudpage","QUIT");
	}
}
// **** For Process Loan Tersm Functionality - END ****//

// **** For Vehicle Registration Functionality - START ****//
function RegInfoDisplay(document, form, selectedValue, infoID, actionID)
{
	var jointInd = document.getElementById("jointIndicator").value;
	if(selectedValue == 'Yes')
	{
		document.getElementById(infoID).style.display="none";
		reInitNameInfo(document, form, infoID);
		if(jointInd == 'Yes')
		{
			document.getElementById(actionID).style.display="none";
			reInitActionInfo(document, form, actionID);
		}
	}
	else if(selectedValue == 'No')
	{
		document.getElementById(infoID).style.display="block";
		if(jointInd == 'Yes')
		{
			document.getElementById(actionID).style.display="none";
			reInitActionInfo(document, form, actionID);
		}
	}
	else
	{
		document.getElementById(infoID).style.display="none";
		reInitNameInfo(document, form, infoID);
		if(jointInd == 'Yes')
		{
			document.getElementById(actionID).style.display="block";
		}
	}
}
//Vehicle Registration dynamic fields re-initialisation methods - START
function reInitNameInfo(document, form, regName)
{
	if(regName == 'correctRegName')
	{
		document.getElementById("firstName").value="";
		document.getElementById("middleInitial").value="";
		document.getElementById("lastName").value="";
		document.getElementById("suffix").value="";
		document.getElementById("nameClass").className="";
		document.getElementById("nameError").style.display="none";
	}
	else if(regName == 'jointCorrectRegName')
	{
		document.getElementById("jointFirstName").value="";
		document.getElementById("jointMiddleInitial").value="";
		document.getElementById("jointLastName").value="";
		document.getElementById("jointSuffix").value="";
		document.getElementById("jointNameClass").className="";
		document.getElementById("jointNameError").style.display="none";
	}
	else
	{	
		document.getElementById("otherIndFirstName").value="";
		document.getElementById("otherIndMiddleInitial").value="";
		document.getElementById("otherIndLastName").value="";
		document.getElementById("otherIndSuffix").value="";
		document.getElementById("otherNameClass").className="";
		document.getElementById("otherNameError").style.display="none";
		reInitActionInfo(document, form, "otherAction");
	}
}

function reInitActionInfo(document, form, actionName)
{
	if(actionName == 'applicantAction')
	{
		form.singleAction[0].checked=false;
		form.singleAction[1].checked=false;
		document.getElementById("actionClass").className="";
		document.getElementById("actionError").style.display="none";
	}
	else if(actionName == 'jointApplicantAction')
	{
		form.jointAction[0].checked=false;
		form.jointAction[1].checked=false;
		document.getElementById("jointActionClass").className="";
		document.getElementById("jointActionError").style.display="none";
	}
	else
	{	
		form.otherAction[0].checked=false;
		form.otherAction[1].checked=false;
		document.getElementById("otherActionClass").className="";
		document.getElementById("otherActionError").style.display="none";
	}
}
//Vehicle Registration dynamic fields re-initialisation methods - END
// **** For Vehicle Registration Functionality - END ****//

// **** For Capture Employment Information Functionality - START ****//
function dropDownChange(document, selectValue, divID) 
{
	var selectedValue = document.getElementById(selectValue).value;
	if(selectedValue == 'union')
	{
		document.getElementById(divID).style.display="block";
	}
	else
	{
		document.getElementById(divID).style.display="none";
		reInitUnionPhoneInfo(document, divID)
	}
}

//Capture Employment Info dynamic fields re-initialisation methods - START
function reInitUnionPhoneInfo(document, unionName)
{
	var unionNameClass = unionName + "Class";
	var unionNameError = unionName + "Error";
	if(unionName == 'unionPhoneNumber')
	{
		document.getElementById("employerUnionPhoneAreaCode").value="";
		document.getElementById("employerUnionPhoneSuffix").value="";
		document.getElementById("employerUnionPhoneExchange").value="";
		document.getElementById("employerUnionPhoneExt").value="";
	}
	else if(unionName == 'secondJobUnionPhoneNumber')
	{
		document.getElementById("secondJobEmployerUnionPhoneAreaCode").value="";
		document.getElementById("secondJobEmployerUnionPhoneSuffix").value="";
		document.getElementById("secondJobEmployerUnionPhoneExchange").value="";
		document.getElementById("secondJobEmployerUnionPhoneExt").value="";
	}
	else if(unionName == 'jointUnionPhoneNumber')
	{
		document.getElementById("jointEmployerUnionPhoneAreaCode").value="";
		document.getElementById("jointEmployerUnionPhoneSuffix").value="";
		document.getElementById("jointEmployerUnionPhoneExchange").value="";
		document.getElementById("jointEmployerUnionPhoneExt").value="";
	}
	else
	{
		document.getElementById("jointSecondJobEmployerUnionPhoneAreaCode").value="";
		document.getElementById("jointSecondJobEmployerUnionPhoneSuffix").value="";
		document.getElementById("jointSecondJobEmployerUnionPhoneExchange").value="";
		document.getElementById("jointSecondJobEmployerUnionPhoneExt").value="";
	}
	document.getElementById(unionNameClass).className="";
	document.getElementById(unionNameError).style.display="none";
}
//Capture Employment Info dynamic fields re-initialisation methods - END
// **** For Capture Employment Information Functionality - END ****//

// **** For Obtain and Return Loan Package Functionality - START ****//
function disable(but1,but2,but3)
{
	document.getElementById(but1).disabled = true;	
	document.getElementById(but2).disabled = false;	
	document.getElementById(but3).style.display = 'block';
}

function defaultDisable()
{
	var selected = document.ObtainLoanPackageForm.defaultSelect.value;
	if(selected == "overnight")
	{
		document.getElementById('onmail').disabled = true;
		document.getElementById('cmd_obtainloanhome').disabled = false;		
	}
	else if(selected == "email")
	{		
		document.getElementById('cmd_obtainloanhome').disabled = false;		
	}
}

function returnHome(form,event)
{
	var hostname = window.location.hostname;
	var protocol = "http";
	var port = getRegionSpecificPort();
  
	var redirURL = protocol + "://" + hostname + ":" + port + "/command?action=ev_orig_finished";

	window.opener.location.href = redirURL;
	return false;
}

function returnLookup(event)
{

  
	var hostname = window.location.hostname;
	var protocol = "http";
	var port = getRegionSpecificPort();
  
	var redirURL = protocol + "://" + hostname + ":" + port + "/command?action=ev_orig_Lookup";
	
	window.opener.location.href = redirURL;
	
	return false;
	
	
}

function saveForm(form,event,uaction)
{	
	form.action = event;	
	form.target = "_self";
	form.userAction.value = uaction;
	form.submit();
}
// **** For Obtain and Return Loan Package Functionality - END ****//

// **** For Process TUD2 Functionality - START ****//
function showOtherFields() 
{
	var selectbox = document.getElementById("tud2CancelReason");
	var selectedValue = selectbox.value ;
	for(var i=0; i<selectbox.options.length; i++)
	{
		var optionValue = selectbox.options[i].value;
		var code = optionValue.substring(0,optionValue.indexOf("|")); 
	    var type = optionValue.substring(optionValue.lastIndexOf("|")+1);
	    if(optionValue == selectedValue)
	    {
		    if(type == '2' || type == '3')
		    {
		    	document.getElementById(code+"_divID").style.display="block";
		    }
	    }
		else if(optionValue != selectedValue || optionValue != '')
		{
		    if(type == '2' || type == '3')
		    {
		    	document.getElementById(code+"_divID").style.display="none";
		    }
	    }
	}
}

function showOtherLender() 
{
	var optionValue = document.ProcessTUD2Form.turnDownSubReasonSelectOption.value ;
	var value = optionValue.substring(optionValue.indexOf("|")+1); 
	if(value=="Other") 
	{
		lenderNameOtherTR.style.display = 'block';
	}
	else
	{
		lenderNameOtherTR.style.display = 'none';
	}
}

//Process TUD2 dynamic fields re-initialisation methods - START
function reInitTUD2Info(document, form, selectValue)
{
	var selectbox = document.getElementById(selectValue);
	var selectedValue = selectbox.value;
	var c1=1;
	var c2=1;
	var c3=1;
	for(var i=0; i<selectbox.options.length; i++)
	{
		var optionValue = selectbox.options[i].value;
		if(optionValue != selectedValue || optionValue != '')
		{
			var code = optionValue.substring(0,optionValue.indexOf("|")); 
		    var type = optionValue.substring(optionValue.lastIndexOf("|")+1);
		    if(type == '2')
		    {
		    	document.getElementById("tud2OtherReason" + code).value="";
		    }
		    else if(type == '3')
		    {
		    	var radioOptionCount = 0 + document.getElementById(code + "radioOptionCount").value;
		    	var textOptionCount = 0 + document.getElementById(code + "textOptionCount").value;
		    	var selectOptionCount = 0 + document.getElementById(code + "selectOptionCount").value;
		    	if(radioOptionCount > 0)
		    	{
			    	for(; c1<=radioOptionCount; c1++)
			    	{
			    		document.getElementById(code + "tud2SubReasonRadioOption" + c1);
			    	}
		    	}
		    	if(textOptionCount > 0)
		    	{
			    	for(; c2<=textOptionCount; c2++)
			    	{
			    		document.getElementById(code + "tud2SubReasonTextName" + c2).value="";
			    	}
		    	}
		    	if(selectOptionCount > 0)
		    	{
			    	for(; c3<=selectOptionCount; c3++)
			    	{
			    		document.getElementById(code + "tud2SubReasonSelectOption" + c3).value="";
			    	}
		    	}
		    }
		}
	}
}
//Process TUD2 dynamic fields re-initialisation methods - END
// **** For Process TUD2 Functionality - END ****//

// **** For Processing Page Functionality - START ****//
function redirect()
{
	setTimeout('windowClose()',4000);
	document.ProcessingPageForm.submit();
	return false;
}

function ReloadImg() 
{
	var img = document.getElementById("procImg");
	img.src = "/auto_loans/images/bluebar.gif";
}

function windowClose()
{
	window.self.close();
}


// **** For Processing Page Functionality - END ****//


function submitSAP(form, event, useraction){
	if(ctr==0 )
	{
		//if not already clicked
		//Put the button name in to the array and submit.
		clickedButList[ctr] = useraction;
		ctr = ctr+1;
		form.action= form.action+'?action='+event+'&siab_microsite=auto_ecare';
		form.userAction.value = useraction;
		form.submit();
		return true;
	}else{
		return false;
	}
  }