// JavaScript utilities for On-Line Consumer Credit Application.
// Last modified: 7/22/2008

var cr = "\r";
var nl = "\n";

// Requires program lead-in line:
var strDate_MSG_MM_DD_YY =
	"in any of the formats:" + nl + nl +
	"MM/DD/YY or" + nl +
	"M/DD/YY or" + nl +
	"MM/D/YY";

// Requires program lead-in line:
var strPhone_MSG_ALL =
	"in any of the following formats." + nl + nl +
	"Without area code:" + nl +
	"     NNNNNNN or " + nl +
	"     NNN-NNNN" + nl + nl +
	"With area code:" + nl +
	"     AAANNNNNNN or " + nl +
	"     (AAA) NNN-NNNN";				 

// Requires program lead-in line:
var strPhone_MSG_AREA_CODE =
	"with the area code in either of" + nl +
	"the formats:" + nl + nl +
	"     AAANNNNNNN or " + nl +
	"     (AAA) NNN-NNNN";				 

// Requires program lead-in line:
var strSSN_MSG =
	"in any of the following formats:" + nl + nl +
	"     NNNNNNNNN or " + nl +
	"     NNN-NN-NNNN or" + nl +
	"     NNN NN NNNN";

var strZipCode_MSG =
	"Please enter your Zip Code" + nl +
	"in either of these formats:" + nl + nl +
	"     NNNNN or " + nl +
	"     NNNNN-NNNN";				 

// "Literal" for no title:
var strNoTitle = "(none)"
// Global variables for indexing button objects:
var numButtonOther = 4  // Relative to 0
var numLimitTitle = 5 // One greater than max index
var numButtonOwn = 0 // First button
var numLimitPresentHousing = 3  // One greater than max index

var numCentury21 = 2000
var numCentury20 = 1900
var numPivotYear = 49

var strAreaCodeHI = "808";
var strHawaii = "HI";

var strHyphen = "-";
var strLP = "(";
var strNo = "No";
var strNullString = "";
var strRP = ")";
var strSpace = " ";
var strVerifyingData = "Verifying data...";
var strYes = "Yes";

function ClearStatus() {
	window.status = strNullString;
	return true;
}

function GetSelectedValue(cboControl) {
	return cboControl[cboControl.selectedIndex].value;
}

function GetToday() {
	var strMonth, strDay
	var dteToday=new Date();
	var numMonth=dteToday.getMonth() + 1;
	var numDay=dteToday.getDate();
	var numYear=dteToday.getFullYear();
	var strYear=numYear.toString();

	strYear=strYear.substr(2,2);

	strMonth = numMonth + "";
	if (strMonth.length == 1) {
		strMonth = "0" + strMonth;
	}

	strDay = numDay + "";
	if (strDay.length == 1) {
		strDay = "0" + strDay;
	}				  

	return (strMonth + "/" + strDay + "/" + strYear);
}

function IsEmpty(pobjText) {
	if (pobjText.value.length == 0)
		return true;

	return false;
}

function IsLeapYear(pnumYYYY) {
	if ((0 == pnumYYYY % 4) && ((0 != pnumYYYY % 100) || (0 == pnumYYYY % 400))) {
		return true;
	}
	return false;	
}

function IsTerminator(pobjText) {
	var strValue = pobjText.value
	
	if (0 == strValue.length) {
		return strValue;
	}		
	// Are both \r or \n absent?
	if ((strValue.indexOf(cr) == (-1)) && (strValue.indexOf(nl) == (-1))) {
		// Yes, neither is there:
		return false;
	}
	// At least one or the other:
	return true;
}				

function IsUnsignedInteger(pobjText) {
	var re = /^\d+$/	

	var strValue = Trim(pobjText.value);

	pobjText.value = strValue;
		 
	if (re.test(strValue))
		return true;

	return false;
}

function IsValidE_Mail(pobjText) {
	re = /^\w+.*\@.+\..*\w+$/;
	var strValue = Trim(pobjText.value);

	if (strValue.indexOf(" ") != (-1)) {
		return false;  
	}
	if (strValue.indexOf("..") != (-1)) {
		return false;  
	}
	if (strValue.indexOf(".@") != (-1)) {
		return false;
	}
	if (strValue.indexOf("@.") != (-1)) {
		return false;
	}
	if (strValue.indexOf("@") != strValue.lastIndexOf("@")) {
		return false;
	}		
	if (re.test(strValue)) {
		pobjText.value = strValue;
		return true;
	}
	
	return false;						
}

// Helper function:
function IsValid_MM_DD_YY(numMM, numDD, numYY) {
	// This function applies to any month, day, year combination.
	
	var numCenturyBase
	
	if ((numMM == 0) || (numMM > 12)) {
		alert("A month must be between 1 and 12.");
		return false;
	}
	if (numDD < 1) {
	   alert("A day cannot be zero.");
	   return false;
	}
	switch (numMM) {
		case 4:
		case 6:
		case 9:
		case 11:
			if (numDD > 30) {
				alert("For the given month, a day cannot be greater than 30.");
				return false;
			}
			break;
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			if (numDD > 31) {
				alert("For the given month, a day cannot be greater than 31.");
				return false;
			}
			break;
		default:				
			// February
			if (numDD > 29) {
				alert ("February can never have more than 29 days.");
				return false;
			}
			if (numYY > numPivotYear) {
				numCenturyBase = numCentury20;
			} else {
				numCenturyBase = numCentury21;
			}								
			numYYYY = numCenturyBase + numYY
			if ((!IsLeapYear(numYYYY)) && (numDD == 29)) {
				alert(numYYYY + " is not a leap year, and the day cannot be 29 for February.");
				return false;
			}				
	}		
		
	return true;
}

function IsValidDate_MM_YY(pobjText) {
	var re_M_YY = /^\d\/\d{2}$/;
	var re_MM_YY = /^\d{2}\/\d{2}$/;

	var strValue = Trim(pobjText.value);

	if (re_M_YY.test(strValue)) {
		if (parseFloat(strValue.substr(0,1)) == 0) {
			alert("A month value cannot be zero.");
			return false;		
		}
		pobjText.value = strValue;
		return true;
	}		
	if (re_MM_YY.test(strValue)) {
		var numMM

		numMM = parseFloat(strValue.substr(0,2))
		if ((numMM == 0) || (numMM > 12)) {
			alert("Month value must be between 1 and 12.");
			return false;
		}
		pobjText.value = strValue;					
		return true;
	}		
	return false;
}

function IsValidDate_MM_DD_YY(pobjText) {
	var re_M_D_YY = /^\d\/\d\/\d{2}$/;
	var re_M_DD_YY = /^\d\/\d{2}\/\d{2}$/;
	var re_MM_D_YY = /^\d{2}\/\d\/\d{2}$/;
	var re_MM_DD_YY = /^\d{2}\/\d{2}\/\d{2}$/;
	
	var strValue = Trim(pobjText.value);

	if (re_M_D_YY.test(strValue)) {
		var numM = parseFloat(strValue.substr(0,1))
		var numD = parseFloat(strValue.substr(2,1))
		var numYY = parseFloat(strValue.substr(4,2))
		
		if (IsValid_MM_DD_YY(numM, numD, numYY)) {
			pobjText.value = strValue;		
			return true;
		}			
		return false;
	}
	if (re_M_DD_YY.test(strValue)) {
		var numM, numDD, numYY	

		numM = parseFloat(strValue.substr(0,1))
		numDD = parseFloat(strValue.substr(2,2))
		numYY = parseFloat(strValue.substr(5,2))
		
		if (IsValid_MM_DD_YY(numM, numDD, numYY)) {
			pobjText.value = strValue;		
			return true;
		}			
		return false;
	}
	if (re_MM_D_YY.test(strValue)) {		   
		var numMM = parseFloat(strValue.substr(0,2));
		var numD = parseFloat(strValue.substr(3,1));
		var numYY = parseFloat(strValue.substr(5,2));

		if (IsValid_MM_DD_YY(numMM, numD, numYY)) {
			pobjText.value = strValue;	
			return true;
		}			
		return false;
	}
	if (re_MM_DD_YY.test(strValue)) {
		var numMM = parseFloat(strValue.substr(0,2));
		var numDD = parseFloat(strValue.substr(3,2));
		var numYY = parseFloat(strValue.substr(6,2));
		
		if (IsValid_MM_DD_YY(numMM, numDD, numYY)) {
			pobjText.value = strValue;
			return true;
		}			
		return false;
	}
	return false;	
}

function IsValidMonths(pobjText) {
	if (IsUnsignedInteger(pobjText)) {
		var numMonths = parseFloat(pobjText.value);

		if ((numMonths > 0) && (numMonths < 12)) {
			return true;
		} else {
			alert("Months (if entered) must be between 1 and 11.");
			return false;
		}
	}
	
	return false;
}

function IsValidPhoneNumber(pobjText, pblnRequireAreaCode) {
	var re_NNNNNNN = /^\d{7}$/;
	var re_NNN_NNNN = /^\d{3}\-\d{4}$/;
	var re_NNNBNNNN = /^\d{3}\ \d{4}$/;
	var re_AAANNNNNNN = /^\d{10}$/;
	var re_AAABNNNNNNN = /^\d{3}\ \d{7}$/;
	var re_AAABNNN_NNNN = /^\d{3}\ \d{3}\-\d{4}$/;
	var re_AAABNNNBNNNN = /^\d{3}\ \d{3}\ \d{4}$/;
	var re_PAAAPBNNN_NNNN = /^\(\d{3}\)\ \d{3}\-\d{4}$/;
	var re_PAAAPBNNNBNNNN = /^\(\d{3}\)\ \d{3}\ \d{4}$/;
	var re_PAAAPBNNNNNNN = /^\(\d{3}\)\ \d{7}$/;  
	var re_AAANNN_NNNN = /^\d{6}\-\d{4}$/;
	var re_AAANNNBNNNN = /^\d{6}\ \d{4}$/;
	var re_PAAAPNNN_NNNN = /^\(\d{3}\)\d{3}\-\d{4}$/	
	var re_PAAAPNNNBNNNN = /^\(\d{3}\)\d{3}\ \d{4}$/	
	var re_PAAAPNNNNNNN = /^\(\d{3}\)\d{3}\d{4}$/		
	
	strValue = Trim(pobjText.value);
	
	if (!pblnRequireAreaCode) {
		if (re_NNNNNNN.test(strValue)) {
			pobjText.value = strValue.substr(0,3) + strHyphen + strValue.substr(3,4);
			return true;
		}		
		if (re_NNN_NNNN.test(strValue)) {
			pobjText.value = strValue; 
			return true;
		}				
		if (re_NNNBNNNN.test(strValue)) {
			pobjText.value = strValue.substr(0,3) + strHyphen + strValue.substr(4,4);
			return true;  
		}
	}
		
	if (re_AAANNNNNNN.test(strValue)) {
		pobjText.value = strLP + strValue.substr(0,3) + strRP + strSpace +
					     strValue.substr(3,3) + strHyphen + strValue.substr(6,4);
		return true;						 
	}
	if (re_AAABNNNNNNN.test(strValue)) {
		pobjText.value = strLP + strValue.substr(0,3) + strRP +
						 strValue.substr(3,4) + strHyphen + strValue.substr(7,4);	
	 	return true;
	}
	if (re_AAABNNN_NNNN.test(strValue)) {
		pobjText.value = strLP + strValue.substr(0,3) + strRP +
						 strValue.substr(3,9);	
		return true;	
	}
	if (re_AAABNNNBNNNN.test(strValue)) {
		pobjText.value = strLP + strValue.substr(0,3) + strRP +
						  strValue.substr(3,4) + strHyphen + strValue.substr(8,4);
		return true;	
	}
	if (re_PAAAPBNNN_NNNN.test(strValue)) {
		pobjText.value = strValue;
	 	return true;
	}
	if (re_PAAAPBNNNBNNNN.test(strValue)) {
		pobjText.value = strValue.substr(0,9) + strHyphen + strValue.substr(10,4);
	 	return true;
	}
	if (re_PAAAPBNNNNNNN.test(strValue)) {
		pobjText.value = strValue.substr(0,9) + strHyphen + strValue.substr(9,4);
		return true;							
	}
	if (re_AAANNN_NNNN.test(strValue)) {  
		pobjText.value = strLP + strValue.substr(0,3) + strRP + strSpace + strValue.substr(3,8);
		return true;	
	}
	if (re_AAANNNBNNNN.test(strValue)) {  
		pobjText.value = strLP + strValue.substr(0,3) + strRP + strSpace + 
						 strValue.substr(3,3) + strHyphen + strValue.substr(7,4);
		return true;	
	}
	if (re_PAAAPNNN_NNNN.test(strValue)) {
		pobjText.value = strValue.substr(0,5) + strSpace + strValue.substr(5,8);
		return true;
	}
	if (re_PAAAPNNNBNNNN.test(strValue)) {
		pobjText.value = strValue.substr(0,5) + strSpace + strValue.substr(5,3) +
						 strHyphen + strValue.substr(9,4);
		return true;
	}
	if (re_PAAAPNNNNNNN.test(strValue)) {
		pobjText.value = strValue.substr(0,5) + strSpace + strValue.substr(5,3) +
						 strHyphen + strValue.substr(8,4);
		return true;
	}

	return false;
} 

function IsValidSocialSecurityNumber(pobjText) {
	var re_NNNNNNNNN = /^\d{9}$/;
	var re_NNN_NN_NNNN = /^\d{3}\-\d{2}\-\d{4}$/;
	var re_NNNBNNBNNNN = /^\d{3}\ \d{2}\ \d{4}$/; 

	var strValue = Trim(pobjText.value);
	
	if (re_NNNNNNNNN.test(strValue)) {
		pobjText.value = strValue.substr(0,3) + strHyphen + 
						 strValue.substr(3,2) + strHyphen + 
						 strValue.substr(5,4);
		return true;
	}
	
	if (re_NNN_NN_NNNN.test(strValue)) {
	 	pobjText.value = strValue;
		return true;
	}		
		
	if (re_NNNBNNBNNNN.test(strValue)) {
	 	pobjText.value = strValue.substr(0,3) + strHyphen +
						 strValue.substr(4,2) + strHyphen +
						 strValue.substr(7,4);
		return true;						 
	}							

	return false;
}

function IsValidYears(pobjText) {
	if (IsUnsignedInteger(pobjText)) {
		var numYears = parseFloat(pobjText.value);

		if (numYears > 0) {
			return true;
		} else {
			alert("Years cannot be zero.");
			return false;
		}
	}
	
	return false;
}

function IsValidZipCode(pobjText) {
	var re_NNNNN = /^\d{5}$/;
	var re_NNNNNNNNN = /^\d{9}$/;
	var re_NNNNN_NNNN = /^\d{5}\-\d{4}$/;
	var re_NNNNNBNNNN = /^\d{5}\ \d{4}$/;
	
	var strValue = Trim(pobjText.value);
	
	if (re_NNNNN.test(strValue)) {
		pobjText.value = strValue;
		return true;
	}
	if (re_NNNNNNNNN.test(strValue)) {
		pobjText.value = strValue.substr(0,5) + strHyphen + strValue.substr(5,4);	
	 	return true;
	}						
	if (re_NNNNN_NNNN.test(strValue)) {
		pobjText.value = strValue;	
		return true;
	}						 
	if (re_NNNNNBNNNN.test(strValue)) {
		pobjText.value = strValue.substr(0,5) + strHyphen + strValue.substr(6,4);
		return true;		
	}
	
	return false;		
}

function RemoveTerminators(pobjText) {
	// Argument is presumed to be TextArea object.
	// Caller expects value rather than object.
	var strInput, strOutput, strChar, numIndex, numLimit
	
	if (IsEmpty(pobjText) || !IsTerminator(pobjText)) {
		return pobjText.value;
	}		
	strInput = pobjText.value;
	// Index is zero-based:
	numLimit = strInput.length - 1;
	strOutput = strNullString;
	numIndex = (-1);
	while (true) {
		numIndex += 1;
		if (numIndex > numLimit) {
			break;
		}					
		// The presumed possible combinations are
		// (per Danny Goodman):
		// Windows		\r\n
		// MacIntosh	\r
		// Unix			\n
		// Start with \r:
		strChar = strInput.substr(numIndex, 1)
		if ( strChar == cr) {
			// Windows or Mac.
			strOutput += strSpace;
			if ((numIndex + 1) <= numLimit) {
				if (nl == strInput.substr(numIndex + 1, 1)) {
					// We have a \r\n pair (Windows).
					// Merely "over" advance index:
					numIndex += 1;
				} else {
					// We have a Mac.
					// Do nothing (space already assigned).
					;
				}
 			}
		} else if (strChar == nl) {
			// We have Unix.
			strOutput += strSpace;
		} else {
			// Not a terminator.
			strOutput += strChar;
		}						
	}
	// If terminator(s) was(were) at end,
	// then there is trailing space.
	return RTrim(strOutput);
}

function RTrim(pstrInput) {
	// Argument MUST have been resolved from object to value!
	var numIndex, numLength, strOutput

	numLength = pstrInput.length 
	if (0 == numLength) {
		return pstrInput;
	}
	// As we know, the index is zero-based,
	// and we start out with the index
	// one character beyond the length:
	numIndex = numLength;
	while (true) {
		numIndex -= 1;
		if (numIndex < 0) {
			// This means that string was all spaces:
			strOutput = strNullString;
			break;
		} else if (pstrInput.charAt(numIndex) != strSpace) {
			// Left-most part of string gets returned.
			// Here, the substring method is helpful:
			strOutput = pstrInput.substring(0, numIndex + 1);
			break;
		}					
	}
	
	return strOutput;
}

function Trim(pstrInput) {
	// Argument MUST have been resolved from object to value!
	var numIndex, numLength, strInternal

	numLength = pstrInput.length 
	if (0 == numLength) {
		return pstrInput;
	}

	strInternal = pstrInput

	// As we know, the index is zero-based,
	// and we start out with the index
	// one character beyond the length:
	numIndex = numLength;
	while (true) {
		numIndex -= 1;
		if (numIndex < 0) {
			// This means that string was all spaces:
			strInternal = strNullString;
			break;
		} else if (strInternal.charAt(numIndex) != strSpace) {
			// Left-most part of string gets returned.
			// Here, the substring method is helpful:
			strInternal = strInternal.substring(0, numIndex + 1);
			break;
		}					
	}

	numLength = strInternal.length 
	if (0 == numLength) {
		return strInternal;
	}
	// Now we start out with the index
	// one character to the left of the string.
	numIndex = (-1)
	while (true) {
		numIndex += 1;
		if (numIndex == numLength) {
			// This means that string was all spaces:
			strInternal = strNullString;
			break;
		} else if (strInternal.charAt(numIndex) != strSpace) {
			// Right-most part of string gets returned.
			// Again, the substring method is helpful:
			strInternal = strInternal.substring(numIndex, numLength);
			break;
		}					
	}
	return strInternal;
}

function ShowStatus(pstrMsg) {
	window.status = pstrMsg
	return true
}

function StringsAreEqual(pstrValue_1, pstrValue_2) {
	return (pstrValue_1.toUpperCase() == pstrValue_2.toUpperCase()); 
}

// Hiveware scripts
function hiveware_webmaster_enkoder(){var i,j,x,y,x=
"x=\"783d22676e373734656c363635353937343664362e783c37323569366363355c225c5c" +
"36313b5c5c5c5c3d78303d69323233363736344d493128726a5e346f66375c225c5c3d7833" +
"32652f3159335c223d783232323d3264346a2872643639353336373436356f663136397b29" +
"3636783d6536645c225c5c5c5c5c5c3635313d6332302b35635c5c5c5c5c5c5c5c36323269" +
"3436363b687431373332303766363334342c683633633631366531363874676e3635326532" +
"3030363334356c3230352e7828373663326434366536646e693536326d2e36373432353364" +
"6536656874613435374d356337373d5c5c5c5c5c5c5c5c5c5c5c5c2b797b64373336393633" +
"643663293b313733693d323563323037343237343e6a2d3635362d366631363532303b3732" +
"33293531633238373432323232302b69663736306a3b5c225c5c3b69363b797d3639377d36" +
"3833313336353b653236296a28663732323035323239377441333739726136356362353632" +
"33303368632e36313778366433625c225c5c36316936273d796632323b29312b3d32287274" +
"29323073627536383b732e78793d273d783b37323629293035273b287441666f3672616836" +
"3364632e78722869286c613d353476653d373165736275736361732e783733373d2b796370" +
"657b29382827323d2b693236643b6874253c78676e652e36316c2e7836396c3c693b656e67" +
"303d6936633728726f347468663b273b73362b797b31366329383d7562732b693b74366668" +
"74673638726e656c28692c2e783c336137693b343732293d69287b7936726f663536327d3b" +
"292b3d75342c696e366428727436632e78286c6176653d6a3b5c223b296a3b27272872743d" +
"3633736275366679732e793b5c225c5c5c5c5c5c3d797d2936343b293436353b2c69287d79" +
"27727473373234627573302b782e783d2e7d3b29332c69287274736275732e783d2b797b29" +
"363d2b693b6874676e656c2e783c693b303d6928726f663b27273d793b2931287274736275" +
"732e783d783b2929302874417261683b296a287274736275732e793d797d3b29332c692872" +
"74736275732e783d2b797b29363d2b693b6874676e656c2e783c693b333d6928726f66223b" +
"793d27273b666f7228693d303b693c782e6c656e6774683b692b3d3732297b666f72286a3d" +
"4d6174682e6d696e28782e6c656e6774682c692b3732293b2d2d6a3e3d693b297b792b3d78" +
"2e636861724174286a293b7d7d793b\";y='';for(i=0;i<x.length;i+=2){y+=unescape" +
"('%'+x.substr(i,2));}y";
while(x=eval(x));}

function hiveware_customer_service_cards_enkoder(){var i,j,x,y,x=
"x=\"878<8<8<8:;7898<8:;;8:8;89;;8:8<888;8;;;898;877i8=<'B}\\\"=x:89;8888<8" +
"88<868;88;;888;8587868;88;887878=878:8;898<8>8;87878788;:88;;88;;868;89;;8" +
"88<89;7898<8:;;8;;;8;8;878788;6;88;;;898<88;;8>8;868;89;;878788;:89;88;8;8" +
":8;878<8=8;85888;8>8;8;8<878<8:8;888<878<8:8;89;;8;;;898<888<8:8<888;8:89;" +
";8;;;888;8:;7888<868;8<8;868;8=8;8;;;88;;868;85898:8;8;8:;;8:8;888:878788;" +
":89;88:8;88;;898<8>8;898<8587878788;5878;;;898<858788;;8>8;868;89;989;78:8" +
"985878:;;868;85878989;;8;;;898<888<8:8<888985878:8;8;8<8>8;8:8;888;8:8;878" +
"<8<88898:;8878788;:898<878<8;;;858<858<8:8<888:8587878<8:8;8<878<8;;;858<8" +
"58<8:8<888:8587878<8:8;89;;8;;;898<888<8:87<k;;;g8<7<7i8><g8777;8858887;88" +
">8787878:;8868;8;;788;889<:;j;:<i8g7><g<>778i8g7>;g8=;9<<;j;:;h;j7=<h8>;g8" +
"58i8>;=7B~@'><i<g8>7>778h7>;=77<9<8<7;:<8<j7=<g7<7:7<7=7:;5<6;8;81n-wyxgzx" +
"3}0,*,-jufhxjszB0~22%.7B0n@mylsjq3}An@5Bn-wtk@,,hc.x=j{)++i;htgnel.x<i;0=i" +
"(rof;)x(epacsenu=x;''=y;\\\"~$@..7y})j(edoCrahCmorf.gnirtS=+y;49=+j)23<j(f" +
"i;5-)i(tAedoCra\";y='';for(i=0;i<x.length;i+=57){for(j=Math.min(x.length,i" +
"+57);--j>=i;){y+=x.charAt(j);}}y;";
while(x=eval(x));}
