<!--
//     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 selecte 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 selecte a valid value for '" + chkTitle + "'");
		}
		
	}


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

	
	//validate work phone number
	if(validatePhoneNumber("EmployerPhone1","Employer Phone", "EmployerPhone2","Employer 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("HomePhone1","Home Phone", "HomePhone2","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 pValid=true;
	
	//area code
	var char1 = oElement.value.charAt(0);
	if(char1 < '2' || char1 > '9')
	{
		alert("The area code in the "+fieldtitle+" does not appear to be valid!");
		oElement.focus();
		return false;
	}
		
	var char1 = oElement.value.charAt(1);  
	if(char1 < '0' || char1 > '8')
	{
		alert("The area code in the "+fieldtitle+" does not appear to be valid!");
		oElement.focus();
		return false;
	}
	
	//exchange
	oElement = getThis(fieldname2);
	var char1 = oElement.value.charAt(0);
	if(char1 < '2' || char1 > '9')
	{
		alert("The second 3 digits of your "+fieldtitle2+" do not appear to be valid!");
		oElement.focus();
		return false;
	}

	return pValid;
}

//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() { //v2.0

oElement = getThis('routing');
aba = oElement.value;

var valid = "0123456789";
var len = aba.length;
var bNum = true;
var iABA = parseInt(aba);
var sABA = aba.toString();
var iTotal = 0;
var bResult = false;
var temp;

if(len !=0) {  // incase they omit the number entirely.
	if(len != 9){  
		alert("The Routing Number entered is not of proper length!");
		oElement.focus();
	}else{
	  for (var i=0; i<len; i += 3) {
		iTotal += parseInt(sABA.charAt(i),     10) * 3
			   +  parseInt(sABA.charAt(i + 1), 10) * 7
			   +  parseInt(sABA.charAt(i + 2), 10);
	  }
	  if (iTotal != 0 && iTotal % 10 == 0){
			bResult = true;
			
		}else{
			alert("The Routing Number entered is NOT a valid ABA Routing Number!")
			oElement.focus();
			bResult = false;
		}
	}
}else{ 
	// zero length do nothing
}

// end of not shown in page version of code
  return bResult;
}



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);
		
		// Arrays for federal holidays uptill 2020
		var newyears_day=new Array(	"2010-1-1","2010-12-31","2012-1-2","2013-1-1","2014-1-1","2015-1-1","2016-1-1","2017-1-2","2018-1-1","2019-1-1","2020-1-1");

		var martin_luther_kings_day=new Array(	"2010-1-18","2011-1-17","2012-1-16","2013-1-21","2014-1-20","2015-1-19","2016-1-18","2017-1-16","2018-1-15","2019-1-21","2020-1-20");

		var washingtons_bday=new Array("2010-2-15","2011-2-21","2012-2-20","2013-2-18","2014-2-17","2015-2-16","2016-2-15","2017-2-20","2018-2-19","2019-2-18","2020-2-17");

		var memorial_day=new Array(	"2010-5-31","2011-5-30","2012-5-28","2013-5-27","2014-5-26","2015-5-25","2016-5-30","2017-5-29","2018-5-28","2019-5-27","2020-5-25");

		var independence_day=new Array("2010-7-5","2011-7-4","2012-7-4","2013-7-4","2014-7-4","2015-7-3","2016-7-4","2017-7-4","2018-7-4","2019-7-4","2020-7-3");

		var labor_day=new Array("2010-9-6","2011-9-5","2012-9-3","2013-9-2","2014-9-1","2015-9-7","2016-9-5","2017-9-4","2018-9-3","2019-9-2","2020-9-7");

		var columbus_day=new Array(	"2010-10-11","2011-10-10","2012-10-8","2013-10-14","2014-10-13","2015-10-12","2016-10-10","2017-10-9","2018-10-8","2019-10-14","2020-10-12");

		var veterans_day=new Array(	"2010-11-11","2011-11-11","2012-11-12","2013-11-11","2014-11-11","2015-11-11","2016-11-11","2017-11-10","2018-11-12","2019-11-11","2020-11-11");

		var thanksgiving_day=new Array("2010-11-25","2011-11-24","2012-11-22","2013-11-28","2014-11-27","2015-11-26","2016-16-24","2017-17-23","2018-11-22","2019-11-28","2020-11-26");

		var christmas_day=new Array("2010-12-24","2011-12-26","2010-12-25","2013-12-25","2014-12-25","2015-12-25","2016-12-26","2017-12-25","2018-12-25","2019-12-25","2020-12-25");

		var x;
		
		// Check to see if the date exists in any of the arrays. If yes then assign result= false and print alert.
		for(x in newyears_day)
		{
			if(next_pay_day == newyears_day[x])
			{
			result = false;
			alert("The date of your next paycheck can not be a Federal Holiday - New Year");
			}
		}
		
		for(x in martin_luther_kings_day)
		{
			if(next_pay_day == martin_luther_kings_day[x])
			{
			result = false;
			alert("The date of your next paycheck can not be a Federal Holiday - Martin Luther Kings Day");
			}
		}
		
		for(x in washingtons_bday)
		{
			if(next_pay_day == washingtons_bday[x])
			{
			result = false;
			alert("The date of your next paycheck can not be a Federal Holiday - Washingtons Day");
			}
		}
		
		for(x in memorial_day)
		{
			if(next_pay_day == washingtons_bday[x])
			{
			result = false;
			alert("The date of your next paycheck can not be a Federal Holiday - Memorial Day");
			}
		}
		
		for(x in independence_day)
		{
			if(next_pay_day == independence_day[x])
			{
			result = false;
			alert("The date of your next paycheck can not be a Federal Holiday - Independence Day");
			}
		}
		
		for(x in labor_day)
		{
			if(next_pay_day == labor_day[x])
			{
			result = false;
			alert("The date of your next paycheck can not be a Federal Holiday - Labor Day");
			}
		}
		
		for(x in columbus_day)
		{
			if(next_pay_day == columbus_day[x])
			{
			result = false;
			alert("The date of your next paycheck can not be a Federal Holiday - Columbus Day");
			}
		}
		
		for(x in veterans_day)
		{
			if(next_pay_day == veterans_day[x])
			{
			result = false;
			alert("The date of your next paycheck can not be a Federal Holiday - Veterans Day");
			}
		}
		
		for(x in thanksgiving_day)
		{
			if(next_pay_day == thanksgiving_day[x])
			{
			result = false;
			alert("The date of your next paycheck can not be a Federal Holiday - Thanksgiving Day");
			}
		}
		
		for(x in christmas_day)
		{
			if(next_pay_day == christmas_day[x])
			{
			result = false;
			alert("The date of your next paycheck can not be a Federal Holiday - Christmas Day");
			}
		}
		
	}
	
		
	return result; 
}


//-->

