<!--


var errorStringStart = '<IMG src="images/error.gif" class="errorPop" border="0" title="';
var errorStringEnd = '">';
var f = document.forms[0];
var ctlPrefix;// = source.id.substring(0, source.id.indexOf('CV_'));

var nn4 = (document.layers) ? true : false;
var ie = (document.all) ? true : false;
var dom = (document.getElementById && !document.all) ? true : false;
var path = '';

var CV_txtHomePhoneEnabled = false;
var CV_txtWorkPhoneEnabled = false;
var CV_txtPrimaryPhoneEnabled = false;
var CV_txtSecondaryPhoneEnabled = false;
var CV_txtFaxPhoneEnabled = false;

window.onload = initForm;



function ValidateCV(enabled, cv)
{
	if (enabled == true)
	{
		ValidatorValidate(cv);
	}
}

function CV_ClientValidatePhone(source, args)
{
	var isValid = true;

	var pat = "^[0-9]{3}$";
	var REx = new RegExp(pat);
	var errorOutput = '';
	var ac;
	var pf;
	var sf;
	var phoneNumberType;



	if( source.id == (ctlPrefix + 'CV_txtHomePhone'))
	{
		phoneNumberType = 'Home';
	}
	else if( source.id == (ctlPrefix + 'CV_txtWorkPhone'))
	{
		phoneNumberType = 'Work';
	}
	else if( source.id == (ctlPrefix + 'CV_txtPrimaryPhone'))
	{
		phoneNumberType = 'Primary';
	}
	else if( source.id == (ctlPrefix + 'CV_txtSecondaryPhone'))
	{
		phoneNumberType = 'Secondary';
	}
	else if( source.id == (ctlPrefix + 'CV_txtFaxPhone'))
	{
		phoneNumberType = 'Fax';
	}

	ac = eval("f." + ctlPrefix + "txt" + phoneNumberType + "PhoneAreaCode.value;");
	pf = eval("f." + ctlPrefix + "txt" + phoneNumberType + "PhonePrefix.value;");
	sf = eval("f." + ctlPrefix + "txt" + phoneNumberType + "PhoneSuffix.value;");

	if( ! REx.test(ac) )
	{
		isValid = false;
		errorOutput += 'Phone Number Area Code should be 3 digits(0-9)\n'
	}

	if( ! REx.test(pf) )
	{
		isValid = false;
		errorOutput += 'Phone Number Prefix should be 3 digits(0-9)\n'
	}
	
	pat = "^[0-9]{4}$";
	REx = new RegExp(pat);

	if( ! REx.test(sf) )
	{
		isValid = false;
		errorOutput += 'Phone Number Suffix should be 4 digits(0-9)\n'
	}

	if( ! isValid )
	{
		source.innerHTML = errorStringStart + errorOutput + errorStringEnd;
		source.title = errorOutput;
	}

	args.IsValid = isValid;
}

function CV_ClientValidateListItemGroup(source, args)
{
	var isValid = true;

	if( source.id == (ctlPrefix + 'CV_cblCreditTypes') )
	{
		var creditExcellent = eval("f." + ctlPrefix + "cbCreditExcellent;");
		var creditSubPrime  = eval("f." + ctlPrefix + "cbCreditSubprime;");

		if( !(creditExcellent.checked || creditSubPrime.checked) )
		{
			isValid = false;
		}
	}
	else if( source.id == (ctlPrefix + 'CV_rblCurrentlyPurchasingOnlineLeads') )
	{
		var purchasingLeads_Y = eval("f." + ctlPrefix + "rbCurrentlyPurchasingOnlineLeads_Y;");
		var purchasingLeads_N = eval("f." + ctlPrefix + "rbCurrentlyPurchasingOnlineLeads_N;");
		
		if( ! (purchasingLeads_N.checked || purchasingLeads_Y.checked) )
		{
			isValid = false;
		}
	}

	args.IsValid = isValid;
}


function getElement(id)
{
	if(nn4)
	{path = document.layers[id];}
	else if(ie)
	{path = document.all[id];}
	else
	{path = document.getElementById(id);}

	return path
}

function modifyVisibility(id, displayType)
{
	if(ie || dom)
	{
		if(displayType == "none")
			{id.style.display = "none";}
		else if( displayType == "block" )
			{id.style.display = "block";}
	}
}

function showHideSecondaryQuestions()
{
	var loanType = getElement(ctlPrefix + 'ddlLoanPurpose');
	var secondaryQs = getElement('formSecondaryQuestions');

	if( loanType.selectedIndex == 0)
	{
		modifyVisibility(secondaryQs, "none");
		// TODO: inactivate all client side validation controls within this div
	}
	else if( loanType.selectedIndex > 0)
	{
		modifyVisibility(secondaryQs, "block");
		// TODO: activate all client side validation controls within this div
	}
}

function isAllVisible()
{
	var bVisible = true;
	var secondaryQs = getElement('formSecondaryQuestions');
	

	if(secondaryQs == undefined)
	{
		bVisible = false;
	}
	else if(secondaryQs.style.display == 'none')
	{
		bVisible = false;
	}
	
	if( bVisible == false )
	{
		alert('Please please select a Loan Purpose above before proceeding');
	}
	else
	{
//		bVisible = Page_ClientValidate(); // from WebUIValidation.js
	}

	return bVisible;
}


function initForm()
{
	ctlPrefix = '';
	
	if(document.forms[0].elements[1] != undefined)
	{
		ctlPrefix = document.forms[0].elements[1].id.substring(0, document.forms[0].elements[1].id.indexOf('_') + 1);
		
		var secondaryQs = getElement('formSecondaryQuestions');
		if(secondaryQs != undefined)
		{
			secondaryQs.style.display = "block";
			modifyVisibility(secondaryQs, "none");

			var loanType = getElement(ctlPrefix + 'ddlLoanPurpose');

			showHideSecondaryQuestions();
			loanType.onchange = showHideSecondaryQuestions;
		}
	}
}
-->
