<!--
//     Browser check 

IS_DOM = (document.getElementById) ? true : false;
IS_IE = (document.all) ? true : false;
IS_IE50 = (navigator.userAgent.indexOf("IE 5.0") != -1);
IS_Mac = (navigator.appVersion.indexOf("Mac") != -1);
IS_IE5Mac = IS_IE && IS_Mac && IS_DOM;
var browserName = navigator.appName;

	
function RequestedAmount() {

oElement = getThis('BorrowAmount');
var selIndex = oElement.selectedIndex;
amount = oElement.options[selIndex].value;


if(amount>500)
{

	if(confirm("WARNING:\n\nRequiring MORE than $500 GREATLY DECREASES your chance of getting a loan.\n\nIF YOU NEED MORE THAN $500, please apply for $500 the first time and accept the loan and then APPLY AGAIN to get an ADDITIONAL loan from another lender.\n\nWould you like to reduce your requested amount to $500?"))
	{ //if we can change to 500

	oElement.selectedIndex = 4;
			
			
	} //if we can change to 500


} // if amount is > 500


}

	
function getThis(sId){

		var oObject;
		oObject = false;
		
		if (IS_DOM) {
			if (document.getElementById(sId)) {
				oObject = document.getElementById(sId);
			}
		}
		else if (IS_IE)
		{
			if (document.all[sID]) {
				oObject = document.all[sID];
			}
		}
		return oObject;
}

function CheckForm(frmIn, fullform)
{


	
for(i=0; i<frmIn.elements.length; i++)
	{
		oElement = frmIn.elements[i];

		chkType			= "";
		chkRequired		= "";
		chkMinLength	= "";
		chkMaxLength	= "";
		chkReqLength	= "";
		chkMinVal		= "";
		chkMaxVal		= "";
		chkChecked		= "";
		chkTitle		= "";
		chkStep			= "";

		if(document.all)	// if IE
		{
			if(oElement.chkType)
				chkType			= oElement.chkType;
			if(oElement.chkRequired)
				chkRequired		= oElement.chkRequired;
			if(oElement.chkMinLength)
				chkMinLength	= oElement.chkMinLength;
			if(oElement.chkMaxLength)
				chkMaxLength	= oElement.chkMaxLength;
			if(oElement.chkReqLength)
				chkReqLength	= oElement.chkReqLength;
			if(oElement.chkMinVal)
				chkMinVal		= oElement.chkMinVal;
			if(oElement.chkMaxVal)
				chkMaxVal		= oElement.chkMaxVal;
			if(oElement.chkChecked)
				chkChecked		= oElement.chkChecked;
			if(oElement.chkTitle)
				chkTitle		= oElement.chkTitle;
			if(oElement.chkStep)
				chkStep			= oElement.chkStep;	
		}
		else	// if firefox
		{
			if(oElement.hasAttribute("chkType"))
				chkType			= oElement.getAttribute("chkType");
			if(oElement.hasAttribute("chkRequired"))
				chkRequired		= oElement.getAttribute("chkRequired");
			if(oElement.hasAttribute("chkMinLength"))
				chkMinLength	= oElement.getAttribute("chkMinLength");
			if(oElement.hasAttribute("chkMaxLength"))
				chkMaxLength	= oElement.getAttribute("chkMaxLength");
			if(oElement.hasAttribute("chkReqLength"))
				chkReqLength	= oElement.getAttribute("chkReqLength");
			if(oElement.hasAttribute("chkMinVal"))
				chkMinVal		= oElement.getAttribute("chkMinVal");
			if(oElement.hasAttribute("chkMaxVal"))
				chkMaxVal		= oElement.getAttribute("chkMaxVal");
			if(oElement.hasAttribute("chkChecked"))
				chkChecked		= oElement.getAttribute("chkChecked");
			if(oElement.hasAttribute("chkTitle"))
				chkTitle		= oElement.getAttribute("chkTitle");
			if(oElement.hasAttribute("chkStep"))
				chkStep		= oElement.getAttribute("chkStep");				
		}

		
			
		//----end, do we skip this iteration because we're not on this step-----//

		sTitle = ((chkTitle && chkTitle != "") ? chkTitle : oElement.name);
		if(oElement.type == "text" || oElement.type == "textarea" || oElement.type == "password")
		{
			if(chkRequired && chkRequired == "true" && oElement.value.length == 0)
				return PresentFormError(oElement, "Please fill out required field '" + sTitle + "'");

			if(chkRequired && chkRequired == "true" || oElement.value.length > 0)
			{
				if(chkMinLength && chkMinLength.length > 0 && oElement.value.length < parseInt(chkMinLength, 10))
					return PresentFormError(oElement, "Please fill in at least " + chkMinLength + " characters for field '" + sTitle + "'");

				if(chkMaxLength && chkMaxLength.length > 0 && oElement.value.length > parseInt(chkMaxLength, 10))
					return PresentFormError(oElement, "Please fill in at most " + chkMaxLength + " characters for field '" + sTitle + "'");

				if(chkReqLength && chkReqLength.length > 0 && oElement.value.length != parseInt(chkReqLength, 10))
					return PresentFormError(oElement, "Please fill in " + chkReqLength + " characters for field '" + sTitle + "'");

				if(chkType && chkType.length > 0)
				{
					switch(chkType)
					{
						case "alpha":
							for(j=0; j<oElement.value.length; j++)
							{
								ch = oElement.value.charAt(j);
								if(!((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')))
									return PresentFormError(oElement, "Please enter only alphabetical characters in field '" + sTitle + "'");
							}
							break;
						case "num":
							for(j=0; j<oElement.value.length; j++)
							{
								ch = oElement.value.charAt(j);
								if(ch < '0' || ch > '9')
									return PresentFormError(oElement, "Please enter only numeric characters in field '" + sTitle + "'");
							}
							break;
						case "email":
							bValid = true;
							ch = '';
							bFoundAt = false;
							for(j=0; j<oElement.value.length; j++)
							{
								if(ch == '.' && oElement.value.charAt(j) == '.')
									bValid = false;
								ch = oElement.value.charAt(j);
								if(ch == '@')
									bFoundAt = true;
								if(ch == ' ' || ch == '	' || ch == ',' || ch == '!' || ch == '?' || ch == '<' || ch == '>' || ch == '/' || ch == '\\' || ch == ':' || ch == ';' || ch == '[' || ch == ']' || ch == '{' || ch == '}' || ch == '=' || ch == '"' || ch == '`' || ch == '~')
									bValid = false;
								if(bFoundAt && (ch == '+' || ch == '\''))
									bValid = false;
							}

							j = 0;
							while(bValid && j < oElement.value.length && oElement.value.charAt(j) != '@')
								j ++;
							if(j == 0 || j == oElement.value.length)
								bValid = false;
							j += 2;
							while(bValid == true && j < oElement.value.length && oElement.value.charAt(j) != '.')
								j ++;
							j += 2;
							if(j >= oElement.value.length)
								bValid = false;
							if(oElement.value.charAt(oElement.value.length-1) == '.' || oElement.value.charAt(oElement.value.length-2) == '.')
								bValid = false;
							if(!bValid)
								return PresentFormError(oElement, "Please enter a valid email address in field '" + sTitle + "'");
							break;
					}
				}

				if(chkMinVal && chkType && (chkType == "num" || chkType == "num") && parseFloat(oElement.value) < parseFloat(chkMinVal))
					return PresentFormError(oElement, "Please enter a value no less than " + chkMinVal + " in field '" + sTitle + "'");


				if(chkMaxVal && chkType && (chkType == "num" || chkType == "num") && parseFloat(oElement.value) > parseFloat(chkMaxVal))
					return PresentFormError(oElement, "Please enter a value no higher than " + chkMaxVal + " in field '" + sTitle + "'");
			}
		}
		else if(oElement.type == "checkbox")
		{
			if(chkChecked && chkChecked == "true" && !(oElement.checked))
				return PresentFormError(oElement, "You must check the checkbox for " + sTitle);

			if(chkChecked && chkChecked == "false" && oElement.checked)
				return PresentFormError(oElement, "You must not check the checkbox for " + chkTitle);
		}
		else if(oElement.type == "select-multiple")
		{
			if(chkRequired == "true" && oElement.selectedIndex == -1)
				return PresentFormError(oElement, "You must select at least one value for '" + chkTitle + "'");
		}
	else if(oElement.type == "select-one")
		{
			if((chkRequired == "true") && ((oElement.selectedIndex == -1) || (oElement.selectedIndex == 0)))
				return PresentFormError(oElement, "You must select a valid value for '" + chkTitle + "'");
		}
		
	}


	//--------sanity checks-----------//
//if it's the long form
if( fullform == "long")
{

	
	//validate work phone number
	if(validatePhoneNumber("EmployerPhone","Employer Phone") == false)
		return false;
	
	if(validatePhoneNumber("MobilePhone","Mobile Phone") == false)
		return false;

		
	//if(ABAMod10() == false)
			//return false;
			
	if(validateNextPayDate() == false)
			return false;
			
	
	
	getThis('plsWait').style.display='block';
}
if(fullform == "short")
{
	RequestedAmount();
		//validate home phone number
	if(validatePhoneNumber("HomePhone","Home Phone") == false)
		return false;
		//validate email extension
	if(validEmailExtension() == false)
		return false;
}

//don't show the exit pop.	
cashformsubmit = true;

if(fullform == 'shortshow')
	getThis('plsWait').style.display='block';
	
return true;
}


function PresentFormError(oElement, sMessage)
{
	alert(sMessage);
	oElement.focus();
	return false;
}

//-------------make sure they have direct deposit--------//
function directDeposit()
{
	var selObj = getThis('DirectDeposit');
	
	
	var selIndex = selObj.selectedIndex;
	if (selObj.options[selIndex].value == "false")
		alert("You need to have Direct Deposit in order to get a payday loan!\n\nClick On the \"No Bank Account?\" link to get a free bank account with Direct Deposit.");
		selObj.selectedIndex = 0;
		
		return false;

}
//-------------make sure account type is checking---------//
function accountType()
{
	var selObj = getThis('AccountType');
	
	
	var selIndex = selObj.selectedIndex;
	if (selObj.options[selIndex].value == "saving")
		alert("Most lenders will not give you a loan if you do not have a Checking Account!\n\nClick On the \"No Bank Account?\" link to get a free checking bank account with Direct Deposit.");
		selObj.selectedIndex = 0;
		
		return false;

}
//phone number validation
function validatePhoneNumber(fieldname,fieldtitle, fieldname2,fieldtitle2)
{
	oElement = getThis(fieldname);
	
	var number = oElement.value;
	var prefix = '';

	if (number.substr(0, 3) == '440')
	{
		number = number.substr(3);
	}
	else if (number.substr(0, 2) == '44')
	{
		number = number.substr(2);
	}
	else if (number.substr(0, 1) == '0')
	{
		number = number.substr(1);
	}

	if (number.Length != 10 && number.Length != 9)

	prefix = number.charAt(0);

	switch(fieldtitle)
	{
		case 'Home Phone':
		case 'Employer Phone':
			if (prefix != 1 && prefix != 2 && prefix != 5 && prefix != 7 && prefix != 8)
			{
				alert("The phone number prefix in the " + fieldtitle + " does not appear to be valid!");
				oElement.focus();
				return false;
			}
		break;
		case 'Mobile Phone':
			if (prefix != 7)
			{
				alert("The phone number prefix in the " + fieldtitle + " does not appear to be valid!");
				oElement.focus();
				return false;
			}
		break;
		default:
			alert("The phone number in the " + fieldtitle + " is invalid!");
			return false;

	}

	return true;
}

//validate email extension
function validEmailExtension()
{
		
	oElement = getThis('email');
	var eVal = oElement.value;

	var sString = eVal.toString();
	var indexdot = sString.lastIndexOf('.')+1;
	var domain = sString.substring(indexdot, sString.length);
	//alert(indexdot + " " + sString.length + " " + domain);
	if((domain.length == 3) && ((domain == "ocm") || (domain == "ent") || (domain=="cim")))
	{
		alert("Your email address extension does not appear to be valid!");
		oElement.focus();
		return false;
	}
	
	return true;

}

//--------------routing------------//
function ABAMod10()
{
	oElement = getThis('sort_code');
	sortcode = oElement.value.toString();

	var len = sortcode.length;
	var bResult = false;
	var i = 0;

	// incase they omit the number entirely.
	if(len !=0)
	{  
		// allow for dashes or spaces between numbers
		if(len != 6)
		{  
			alert("The Routing Number entered is not of proper length!");
			oElement.focus();
		}

		if (parseInt(sortcode) != sortcode)
		{
			alert("The sort code is not a valid integer");
			oElement.focus();
			return false;
		}
	}

	return true;
}



function validateCheck(obj,  msg)
{ 
	if (document.forms[0].elements[obj].checked == true) 
		return true;

	else
		alert("You must check the " + msg + " checkbox.");
		
	return false; 
}

function validateNextPayDate()
{ 
	var result = true 

	var today = new Date();
	var todayDay = today.getDate();
	var todayMonth = today.getMonth() +1;
	var todayYear = today.getFullYear();
	//todayYear += 1900;

	paycheckMonth = parseInt(getThis('pd1m').value,10);
	paycheckDay = parseInt(getThis('pd1d').value,10);
	paycheckYear = parseInt(getThis('pd1y').value,10);
	
	//alert("todayMonth: " + todayMonth + "\npaycheckMonth: " +  paycheckMonth + "\ntodayDay: " + todayDay + "\npaycheckDay: " + paycheckDay);
	//alert(todayYear + " " + paycheckYear);
	
if ( (todayYear >= paycheckYear) && ((todayMonth > paycheckMonth) || ((todayMonth == paycheckMonth) && (todayDay >= paycheckDay)) ))
		result = false;

	if(result == false)
		alert("The date of your next paycheck has to be in the future.");
		
	else
		//-----------validate for weekends---------//
	{
		var myDate=new Date();
		myDate.setFullYear(paycheckYear,paycheckMonth-1,paycheckDay);	
		thisDay=myDate.getDay()
		//alert("thisDay: " + thisDay);
		if( (thisDay == 6) || (thisDay == 0) )
		{
			result = false;
			alert("The day of your next paycheck can not be a Saturday or a Sunday.");
		}
	}
	
	//validate valid date, day exists in the month.
	if(result != false)
	{
		var numDays = daysInMonth(paycheckMonth-1, paycheckYear);
		if(paycheckDay > numDays)
		{
			result = false;
			alert("The date of your next paycheck is not a valid!");
		}
		
		
		//validate for more than 31 days in the future.
		if( (paycheckMonth > todayMonth) && (paycheckDay >= todayDay))
		{
			result = false;
			alert("The date of your next paycheck can not be more than 31 days away!");
		}
		
	}
	
	if(result !=false)
	{
		//Format the date
		var next_pay_day=(paycheckYear+"-"+paycheckMonth+"-"+paycheckDay);
	}
	
		
	return result; 
}


//-->

