function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    status = ""
    return true
}


function trimSpaces(stringValue) {
	// Checks the first occurance of spaces and removes them
	for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
	stringValue = stringValue.substring(i);
	}
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}
function checkEmail(emailString) {
	splitVal = emailString.split('@');
	if(splitVal.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
		alert("Please enter a valid email address");
		return false;
	}
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}
function validation()
{
	document.advertisement.name.value=trimSpaces(document.advertisement.name.value);
  if (document.advertisement.name.value.length <=0)
  {
     alert("Please enter  your First Name ");
	 document.advertisement.name.focus();
	  return false;
  }
  	document.advertisement.lname.value=trimSpaces(document.advertisement.lname.value);
  if (document.advertisement.lname.value.length <=0)
  {
     alert("Please enter  your Last Name ");
	 document.advertisement.lname.focus();
	  return false;
  }
  
  if (!checkEmail(document.advertisement.email.value))
  {
    document.advertisement.email.focus();
  return false;
  }	
  
  document.advertisement.SSTax3.value=trimSpaces(document.advertisement.SSTax3.value);
  if (document.advertisement.SSTax3.value.length <=0)
  {
     alert("Please enter Social Security or Tax ID Correctly!!!");
	 document.advertisement.SSTax1.focus();
	  return false;
  }
  
   if(!document.advertisement.accept.checked){alert("Accept the terms of the privacy policy");
   document.advertisement.accept.focus();
return false; } 
  
  
 // document.advertisement.comment.value=trimSpaces(document.advertisement.comment.value);
//  if (document.advertisement.comment.value.length <=0)
//  {
//     alert("Please enter  Comments ");
//	 document.advertisement.comment.focus();
//	  return false;
//  }
  
   if(document.getElementById("CoBorroweryes").checked)
   {
	 
	  if (document.advertisement.coname.value.length <=0)
         {
		 	 alert("Please enter Co - Borrower's Name ");
			 document.advertisement.coname.focus();
			 return false;
          }
		  
		   if (document.advertisement.colastname.value.length <=0)
         {
		 	 alert("Please enter Co - Borrower's Last Name ");
			 document.advertisement.colastname.focus();
			 return false;
          }
		   if (!checkEmail(document.advertisement.comail.value))
         {
			 document.advertisement.comail.focus();
			 return false;
          }
		   if (document.advertisement.cob_taxid3.value.length <=0)
         {
		 	 alert("Please enter Co - Borrower's Social Security or Tax ID Correctly!!!");
			 document.advertisement.cob_taxid1.focus();
			 return false;
          }
		  
   }
  
 
  
  return true;
}
 
 function showCoBorrowerInfoPanel()
{
	document.getElementById("coBorrowerInfoPanel").style.display = "block";
 }

function hideCoBorrowerInfoPanel()
{
	document.getElementById("coBorrowerInfoPanel").style.display = "none";
 }
 
 
 
 function copyBoCurrentAddress()
{
	
	
	
	document.getElementById("cobadd").value = document.getElementById("stAdd").value;
	
	document.getElementById("cobcity").value = document.getElementById("city").value;
	
	document.getElementById("cobstate").value = document.getElementById("state").value;
	document.getElementById("cobzip").value = document.getElementById("zip").value;
	
	
	document.getElementById("cobyear").value = document.getElementById("years").value;
	
	document.getElementById("cobmonth").value = document.getElementById("months").value;
	
     document.getElementById("cobrent").value = document.getElementById("RentOwn").value;

  
}

function setFurnishGoverInfoOptionCheckBox(id)
{
	switch (id)
	{
		case "1":
		if(document.getElementById("Option").checked)
		{
		document.getElementById("American").disabled=true;
		document.getElementById("Asian").disabled=true;
		document.getElementById("Black").disabled=true;
		document.getElementById("Native").disabled=true;
		document.getElementById("White").disabled=true;
		}
		else
		{
	    document.getElementById("American").disabled=false;
		document.getElementById("Asian").disabled=false;
		document.getElementById("Black").disabled=false;
		document.getElementById("Native").disabled=false;
		document.getElementById("White").disabled=false;
 		}
		break;
		
       case "2":
	   if(document.getElementById("Option2").checked)
		{
	    document.getElementById("American2").disabled=true;
		document.getElementById("Asian2").disabled=true;
		document.getElementById("Black2").disabled=true;
		document.getElementById("Native2").disabled=true;
		document.getElementById("White2").disabled=true;
		}
		else
		{
	    document.getElementById("American2").disabled=false;
		document.getElementById("Asian2").disabled=false;
		document.getElementById("Black2").disabled=false;
		document.getElementById("Native2").disabled=false;
		document.getElementById("White2").disabled=false;
		document.getElementById("Option2").checked=false;
		}
		break;
		
		default:
		break;
	
	}
}
 
//function checkPurposeOfLoan()
//{
// if ($(section_PleaseSpecifyRow) != null)
// {
// $(section_PleaseSpecifyRow).style.display = "none";
// }
//
// if ($(boPurposeOfLoanDDL) != null)
// {
// var purpose = $(boPurposeOfLoanDDL).value;
// var panel = $(purposeOfLoanPleaseSpecifyPanel);
// if (purpose == "Other")
// {
// panel.style.display = "block";
// if ($(section_PleaseSpecifyRow) != null)
// {
// $(section_PleaseSpecifyRow).style.display = "block";
// }s
//}
// else
// {
// panel.style.display = "none";
// if ($(section_PleaseSpecifyRow) != null)
// {
// $(section_PleaseSpecifyRow).style.display = "none";
// }
// }
// }
//}
//
//function controlCoBorrowerInfoPanel()
//{
// var yes = $(hasCoBorrowerYesRB).checked;
// var no = $(hasCoBorrowerNoRB).checked;
//
// if (yes)
// {
// $(coBorrowerInfoPanel).style.display = "block";
//}
// else
// {
// if(!document.all){
// $("formTable").style.height = "px";
// }else{
// $("formTable").style.pixeHeight = ;
// }
//
// $(coBorrowerInfoPanel).style.display = "none";
//}
//}
//
//window.onload = function()
//{
// attatchFieldCheck();
// checkPurposeOfLoan();
// controlCoBorrowerInfoPanel();
// previousAddressInit();
// showSourceOtherPanel();
//
//// var name = coBoCurrentDifferentAddressRadioButtonList.replace(/_/g,"$");
//// var list = document.getElementsByName(name);
//// for(var i=0;i<list.length;i++)
//// {
//// list[i].attachEvent("onclick",coBoCurrentPanel);
//// }
//
// if ($(boFurnishGoverInfoOptionCheckBox) != null)
// {
// setFurnishGoverInfoOptionCheckBox('Bo');
// }
// if ($(coBoFurnishGoverInfoOptionCheckBox) != null)
// {
// setFurnishGoverInfoOptionCheckBox('CoBo');
// }
//}
//
//
//function returnRadioButtonListSelect(who)
//{
// var name = who.id.replace(/_/g,"$");
// var list = document.getElementsByName(name);
// var result = "" ;
// for(var i=0;i<list.length;i++)
// {
// var radio = list[i];
// if(radio.checked)
// {
// result = radio.value;
// break;
// }
// }
// return result;
//}
//
//
//function setNotApplicableCheckBox(flagStr)
//{
// if (flagStr == "CoBo")
// {
// if ($(coCheckBox).checked)
// {
// setFurnishInfoEmel($(coRaceRadioButtonList),true);
// $(coDeclinetoStateCheckBox).disabled = true;
// }
// else
// {
// setFurnishInfoEmel($(coRaceRadioButtonList),false);
// $(coDeclinetoStateCheckBox).disabled = false;
//}
// }
// if (flagStr == "Bo")
// {
// if ($(boCheckBox).checked)
// {
// setFurnishInfoEmel($(boRaceRadioButtonList),true);
// $(boDeclinetoStateCheckBox).disabled = true;
// }
// else
// {
// setFurnishInfoEmel($(boRaceRadioButtonList),false);
// $(boDeclinetoStateCheckBox).disabled = false;
// }
// }
//}
//
//function setDeclinetoStateCheckBox(flagStr)
//{
// if (flagStr == "CoBo")
// {
// if ($(coDeclinetoStateCheckBox).checked)
// {
// setFurnishInfoEmel($(coRaceRadioButtonList),true);
// $(coCheckBox).disabled = true;
// }
// else
// {
// setFurnishInfoEmel($(coRaceRadioButtonList),false);
// $(coCheckBox).disabled = false;
//}
// }
// if (flagStr == "Bo")
// {
// if ($(boDeclinetoStateCheckBox).checked)
// {
// setFurnishInfoEmel($(boRaceRadioButtonList),true);
// $(boCheckBox).disabled = true;
// }
// else
// {
// setFurnishInfoEmel($(boRaceRadioButtonList),false);
// $(boCheckBox).disabled = false;
// }
// }
//}
//
//function setFurnishGoverInfoOptionCheckBox(flagStr)
//{
// if (flagStr == "CoBo")
// {
// $(coSexRadioButtonList).disabled = $(coBoFurnishGoverInfoOptionCheckBox).checked;
// $(coEthRadioButtonList).disabled = $(coBoFurnishGoverInfoOptionCheckBox).checked;
// setFurnishInfoEmel($(coRaceRadioButtonList),$(coBoFurnishGoverInfoOptionCheckBox).checked ||
// $(coCheckBox).checked || $(coDeclinetoStateCheckBox).checked);
// $(coCheckBox).disabled = $(coBoFurnishGoverInfoOptionCheckBox).checked || $(coDeclinetoStateCheckBox).checked;
// $(coDeclinetoStateCheckBox).disabled = $(coBoFurnishGoverInfoOptionCheckBox).checked || $(coCheckBox).checked;
// }
// if (flagStr == "Bo")
// {
// $(boSexRadioButtonList).disabled = $(boFurnishGoverInfoOptionCheckBox).checked;
// $(boEthRadioButtonList).disabled = $(boFurnishGoverInfoOptionCheckBox).checked;
// setFurnishInfoEmel($(boRaceRadioButtonList),$(boFurnishGoverInfoOptionCheckBox).checked ||
// $(boCheckBox).checked || $(boDeclinetoStateCheckBox).checked);
// $(boCheckBox).disabled = $(boFurnishGoverInfoOptionCheckBox).checked || $(boDeclinetoStateCheckBox).checked;
// $(boDeclinetoStateCheckBox).disabled = $(boFurnishGoverInfoOptionCheckBox).checked || $(boCheckBox).checked;
// }
//}
//
//
//
//function setFurnishInfoEmel(container,disabled)
//{
// var list = container.getElementsByTagName("input");
//
// for(var i=0;i<list.length;i++)
// {
// list[i].disabled = disabled;
// }
//}
//
//
//
//function DoDisabled(who, container)
//{
// if(who)
// {
// var disabled = who.checked;
// var list = container.getElementsByTagName("input")
//
// for(var i=0;i<list.length;i++)
// {
// list[i].disabled = disabled;
// }
// }
//}
//
////function coBoCurrentPanel()
////{
//// if($("differAddr"))
//// {
//// $("differAddr").style.display = "none";
//
//// var name = coBoCurrentDifferentAddressRadioButtonList.replace(/_/g,"$");
//// var list = document.getElementsByName(name);
//// for(var i=0;i<list.length;i++)
//// {
//// var radio = list[i];
//// if(radio.checked && radio.value == "") $("differAddr").style.display = "block";
//// }
//// }
////}
//
//function showCoAddr(isShow)
//{
// $("differAddr").style.display = isShow ? "block" : "none";
// previousAddressInit();
//}
//
//function showCoPAddr(isShow)
//{
// $("differAddrPrevoius").style.display = isShow ? "block" : "none";
//}
//
//function checkAge(which)
//{
// var ages = which.value.split(",");
// var numeric = /^\d*$/
//
// for(i=0; i< ages.length; i++)
// {
// if (!numeric.test(ages[i]))
// {
// alert("Please enter numerals only. Separate ages by commas.");
// which.focus();
// which.select();
// return false;
// }
// }
// return true;
//}
//
//
//function checkFormatedNum(who,submitIT)
//{
// var numeric = /,/g;
// testvalue = who.value.replace(numeric,"");
// if (isNaN(testvalue) && testvalue != "")
// {
// alert("Please enter a loan amount.");
// who.focus();
// who.select();
// return false;
// }
// else if (submitIT && Trim(testvalue).length == )
// {
// alert("Please enter a loan amount.");
// who.focus();
// who.select();
// return false;
//}
//
// return true;
//}
//
//
//--------------------------------------------------------------------------------------------------------------
//
//
//
//function isDifferentAddress()
//{
// return true;
// }
//
//function isDifferentPreviousAddress()
//{
// return true;
// }
//
//
//----------- used by check required ---------------------
//
//function findParentDiv(who)
//{
// who = who.parentNode;
// while(who.tagName != "DIV" || who.tagName == "BODY")
// {
// who = who.parentNode;
// }
// if(who.tagName == "DIV")
// {
// return who;
// }
// else
// {
// return null;
// }
//}
//
//function findParentTR(who)
//{
// who = who.parentNode;
// while(who.tagName != "TR" || who.tagName == "BODY")
// {
// who = who.parentNode;
// }
// if(who.tagName == "TR")
// {
// return who;
//}
// else
// {
// return null;
// }
//}
//
//function checkRequredInput(parent)
//{
// var i;
// for(i=0;i<parent.childNodes.length;i++)
// {
// if((parent.childNodes[i].tagName == "INPUT" || parent.childNodes[i].tagName == "SELECT" ) && (parent.childNodes[i].value.length ==  || Trim(parent.childNodes[i].value).length == ))
// {
// if(parent.childNodes[i].getAttribute("checkRequired") != "false" && !parent.childNodes[i].readOnly)
// { return false; }
// }
// else
// {
// if(parent.childNodes[i].childNodes.length >  )
// {
// if(!checkRequredInput(parent.childNodes[i])){ return false; }
// }
// }
// }
// return true;
//}
//
//function IsParentShow(object)
//{
// object = object.parentNode;
// while(object != null && object.tagName != "BODY")
// {
// if(object.style.display == "none")
// {
// return false;
// }
// object = object.parentNode;
// }
// return true;
//}
//
//
//function checkRequired(from)
//{
// var required = document.getElementsByTagName("SPAN");
// var div,tr;
// var i;
// var result = true;
//
// clear warning message
// $(warnPanel).style.display = "none";
// removeWarn();
//
// for(i=0;i<required.length;i++)
// {
// if(required[i].getAttribute("required") == "true")
// {
// field name div
// div = findParentDiv(required[i]);
// if(div != null)
// {
// field tr
// tr = findParentTR(div);
//
// if(tr != null && IsParentShow(tr))
// {
// if(!checkRequredInput(tr.cells[]))
// {
// if(required[i].getAttribute("Boflag") == "BO")
// {
// show warning message
// div.className = "WarnLabelBox";
// buildWarn("Borrower " + required[i].getAttribute("fieldName"));
// $(warnPanel).style.display = "block";
// result = false;
// }
// var yes = $(hasCoBorrowerYesRB).checked;
// var dAddress = isDifferentAddress();
// var dPreviousAddress = isDifferentPreviousAddress();
// if (yes)
// {
// if(required[i].getAttribute("Boflag") == "COBO")
// {
// if (required[i].getAttribute("DiffAddress") == "diffAddress")
// {
// if (dAddress )
// {
// show warning message
// div.className = "WarnLabelBox";
// buildWarn("Co-Borrower " + required[i].getAttribute("fieldName"));
// $(warnPanel).style.display = "block";
// result = false;
// }
// }
// else if (required[i].getAttribute("DiffAddress") == "diffPreviousAddress")
// {
// if (dPreviousAddress)
// {
// show warning message
// div.className = "WarnLabelBox";
// buildWarn("Co-Borrower Previous " + required[i].getAttribute("fieldName"));
// $(warnPanel).style.display = "block";
// result = false;
// }
// }
// else
// {
// show warning message
// div.className = "WarnLabelBox";
// buildWarn("Co-Borrower " + required[i].getAttribute("fieldName"));
// $(warnPanel).style.display = "block";
// result = false;
// }
// }
// }
// }
// else
// {
// div.className = "";
//}
// }
// else
// {
// div.className = "";
// }
// }
// }
// }
//
// if ($(privacyPolicyPanel)!= null)
// {
// if (!$(policyCheckBox).checked)
// {
// $(privacyPolicyPanel).className = "WarnLabelBox";
// buildWarn("Privacy Policy");
// $(warnPanel).style.display = "block";
// result = false;
// }
// }
//
// if (!result)
// {
// $(warnPanel).style.display = "block";
// stopEvent(from);
// return false;
// }
// else
// {
// return true;
//}
//}
//
//function buildWarn(fieldName)
//{
// var li = document.createElement("li")
// li.innerHTML = fieldName;
// $("warnMessageList").appendChild(li);
// document.getElementById("warnMessageList").appendChild(li);
//
//}
//
//function removeWarn()
//{
// while($("warnMessageList").childNodes.length >  )
// {
// $("warnMessageList").removeChild($("warnMessageList").childNodes[]);
// }
// if ($(privacyPolicyPanel) != null)
// {$(privacyPolicyPanel).className = "";}
//}
//
//add by yemol to fix defect 
//function previousAddressInit()
//{
// var isShowBo,isShowCobo;
//
// if($(Table).attributes("isShow").value == "True")
// {
// isShowBo = true;
// isShowCobo = true;
// }
// else
// {
//
// var boYear = $(boCurrentYearsAtTB) != null ? $(boCurrentYearsAtTB).value : ;
// var coBoYear = $(coBoCurrentYearsAtTextBox) != null ? $(coBoCurrentYearsAtTextBox).value : ;
//
//
// if(boYear.length >  )
// {
// isShowBo = boYear* <;
// }
// else
// {
// isShowBo = false;
// }
// if(coBoYear.length >  )
// {
// isShowCobo = coBoYear* <;
// }
// else
// {
// isShowCobo = false;
// }
// }
//
//
// showAddressRow($("boSectionRow"),isShowBo);
// showAddressRow($("boSectionRow"),isShowBo);
// showAddressRow($("boSectionRow"),isShowBo);
// showAddressRow($("boSectionRow"),isShowBo);
//
// showAddressRow($("coBoSectionRow"),isShowCobo);
// showAddressRow($("coBoSectionRow"),isShowCobo);
// showAddressRow($("coBoSectionRow"),isShowCobo);
// showAddressRow($("coBoSectionRow"),isShowCobo);
//
//}
//
//function showAddressRow(row,isShow)
//{
// if(row != null)
// {
// if( document.all )
// row.style.display = isShow ? "block" :"none";
// else
// row.style.display = isShow ? "table-row" :"none";
// }
//}
//
//
//function copyBoCurrentAddress()
//{
// if($(boCurrentAddressTB))
// {
// $(coBoCurrentAddressTextBox).value = $(boCurrentAddressTB).value;
// }
//
// if($(boCurrentCityTB))
// {
// $(coBoCurrentCityTextBox).value = $(boCurrentCityTB).value;
// }
//
// if($(boCurrentStateDDL))
// {
// $(coBoCurrentStateDropDownList).value = $(boCurrentStateDDL).value;
// }
//
// if($(boCurrentZipTB))
// {
// $(coBoCurrentZipTextBox).value = $(boCurrentZipTB).value;
// }
//
// if($(boCurrentExtZipTB))
// {
// $(coBoCurrentExtZipTextBox).value = $(boCurrentExtZipTB).value;
// }
//
// if($(boCurrentYearsAtTB))
// {
// $(coBoCurrentYearsAtTextBox).value = $(boCurrentYearsAtTB).value;
// }
//
// if($(boCurrentMonthsAtTB))
// {
// $(coBoCurrentMonthsAtTextBox).value = $(boCurrentMonthsAtTB).value;
// }
//
// if($(boRentOrOwnDDL))
// {
// $(coRentOrOwnDDL).value = $(boRentOrOwnDDL).value;
// }
//}
//
//function copyBoPreviousAddress()
//{
// if($(boPreviousAddressTB))
// {
// $(coBoPreviousAddressTextBox).value = $(boPreviousAddressTB).value;
//}
//
// if($(boPreviousCityTB))
// {
// $(coBoPreviousCityTextBox).value = $(boPreviousCityTB).value;
// }
//
// if($(boPreviousStateDDL))
// {
// $(coBoPreviousStateDropDownList).value = $(boPreviousStateDDL).value;
//}
//
// if($(boPreviousZipTB))
// {
// $(coBoPreviousZipTextBox).value = $(boPreviousZipTB).value;
// }
//
// if($(boPreviousExtZipTB))
// {
// $(coBoPreviousExtZipTextBox).value = $(boPreviousExtZipTB).value;
//}
//
// if($(boPreviousYearsAtTB))
// {
// $(coBoPreviousYearsAtTextBox).value = $(boPreviousYearsAtTB).value;
// }
//
// if($(boPreviousMonthsAtTB))
// {
// $(coBoPreviousMonthsAtTextBox).value = $(boPreviousMonthsAtTB).value;
//}
//
// if($(boPreviousRentOrOwnDDL))
// {
// $(coPreviousRentOrOwnDDL).value = $(boPreviousRentOrOwnDDL).value;
// }
//}
//
//function showSourceOtherPanel()
//{
// if ($(ApplicationLeadSourceDropDownList) != null)
// {
// if ($(ApplicationLeadSourceDropDownList).value == "OtherTypeOfLeadSource")
// {
// $(leadSourcePanel).style.display = "block";
// }
// else
// {
// $(leadSourcePanel).style.display = "none";
// }
//}
//}
// 
