//*****************************************************************************
// C & G Technical Group Form Validation Script For Sankofa Connection
//*****************************************************************************

<!--
var gDate = new Date();
var gDay = gDate.getDate();
var gMon = gDate.getMonth() + 1;
var gYear = gDate.getFullYear();
var gTime = gDate.getTime();
var gHours = gDate.getHours();
var gMinutes = gDate.getMinutes();
var gSeconds = gDate.getSeconds();

var reInteger = /^\d+$/
var digits = "0123456789";
// U.S. phone numbers have 10 digits.
// They are formatted as 123 456 7890 or (123) 456-7890.
var digitsInUSPhoneNumber = 10;
// whitespace characters as defined by this sample code
var whitespace = " \t\n\r";
var numberoftimes = 0; 
function validateSubOnce (strMessage) {
	numberoftimes += 1;
	if (numberoftimes > 1) { 
		if (numberoftimes == 3) {
				strMessage = "DO NOT PRESS SUBMIT MULTIPLE TIMES!!! YOUR ACCOUNT WILL BE BILLED EACH TIME YOU PRESS SUBMIT!!! Processing may take up to one minute.";
		}
		 alert(strMessage);
		 return false; 
	}  
	return true;
} 
function isEmpty(s)
{ return ((s == null) || (s.length == 0))
}
function TrimSTR(strValue) {
	// REMOVE leading spaces.
	while (true) {
		if (strValue.indexOf(" ") == 0) {	// a leading space has been found so...
			strValue = strValue.substring(1, strValue.length)	// slice it off.
		} else {	// the first character in the string is no longer a space so...
			break	// exit the loop.
		}
	}
	// REMOVE trailing spaces.
	if (strValue.length > 0) {	// the string is not null.
		while (true) {
			if (strValue.lastIndexOf(" ") == strValue.length - 1) {	// a trailing space has been found so...
				strValue = strValue.substring(0, strValue.length - 1)	// slice it off.
			} else {	// the last character in the string is no longer a space so...
				break	// exit the loop.
			}
		}
	}
	// ASSIGN return value
	return strValue
}
function stripCharsInBag (s, bag)
{ var i;
	var returnString = "";
	for (i = 0; i < s.length; i++)
	{
	// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}
function stripCharsNotInBag (s, bag)
{ var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is in bag, append to returnString.
	for (i = 0; i < s.length; i++)
	{
	// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (bag.indexOf(c) != -1) returnString += c;
	}
	return returnString;
}
function isInteger (s)	{
	if (isEmpty(s)) return false;
	return reInteger.test(s)
}
function stripWhitespace (s) {
	return stripCharsInBag (s, whitespace)
}
function isNumeric(objField, strLength, strMessage) {
	// INITIALIZE procedure-scope variables.
	var blnNumeric = true

	// SCAN string for non-numeric characters.
	for (var i = 0; i < objField.value.length; i++) {
		if (objField.value.length > strLength) {
			alert(strMessage);
			objField.focus();
			blnNumeric = false;
			break;
		}
		if (isEmpty(i)) {
			alert(strMessage);
			objField.focus();
			blnNumeric = false;
			break;
		}
		var strDigit = objField.value.charAt(i);
		if (strDigit < 0 || strDigit > 9) {	//non-numeric character has been found.
			alert(strMessage);
			objField.focus();
			blnNumeric = false;
			break;
		}
	}
	// ASSIGN return value.
	return blnNumeric
}
function validateTextField (objField, minLen, maxLen, strMessage) {
// Validate a Text Field
	if(objField.value == "") {
		alert(strMessage);
		objField.focus();
		return false;
	}
	if(objField.value == "First Name" && objField.name == 'FirstName') {
		alert(strMessage);
		objField.focus();
		return false;
	}
	if(objField.value == "Last Name" && objField.name == 'LastName') {
		alert(strMessage);
		objField.focus();
		return false;
	}
	if(objField.value.length < minLen || objField.value.length > maxLen) {
		alert(strMessage);
		objField.focus();
		return false;
	}
	return true;
}
function validateTextAmount (objField, minLen, maxLen, strMessage) {
// Validate a Text Field
	if(objField.value == "") {
		alert(strMessage);
		objField.focus();
		return false;
	}

	if(objField.value.length < minLen || objField.value.length > maxLen) {
		alert(strMessage);
		objField.focus();
		return false;
	}
	
	if(objField.value < 200.00) {
		alert(strMessage);
		objField.focus();
		return false;
	}
	return true;
}

function validateEmail(objField, strMessage) {
// Validates e-mail address form inputs.
	if (objField.value == "") {	// no value entered in field.
	// DISPLAY validation failure message.
		alert(strMessage);
		objField.focus();
		return false;
	}
	if (objField.value.indexOf ('@', 0) == -1 || objField.value.indexOf ('.', 0) == -1) {	// address does not contain the "@" and "." characters.
		alert(strMessage);
		objField.select();
		objField.focus();
		return false;
	}
	else {	// the address is acceptable.
		return true;
	}
}
function validatePhoneNumber(field, strLength, strMessage){
	sx = stripCharsNotInBag(field.value,digits); // Strip all non-digit chars;
	if (sx.length < strLength) {
		alert(strMessage);
		field.focus();
		return false;
	}
	return true;
}
function validateNumber(field, strLength, strMessage){
	sx = stripCharsNotInBag(field.value,digits); // Strip all non-digit chars;
	if (sx.length > strLength) {
		strMessage = 'MSG0010 - Numeric value ' + field.value + ' is too Long';
		alert(strMessage);
		field.focus();
		return false;
	}
	for (i = 0; i < field.value.length; i++) {
		var strDigit = field.value.charAt(i);
		if (strDigit == ',' || strDigit == '.') {
			continue;
		}else if (digits.indexOf(strDigit) == -1) {	//non-numeric character has been found.
				alert(strMessage);
				field.focus();
				return false;
				break;
		}
	}
	return true;
}
function validateZip(field, strMessage) {
	sx = stripWhitespace(field.value); // Strip all non-digit chars
	if(sx.length < 5) { // Postals need to be at least 5
		alert(strMessage);
		field.focus();
		return false;
	}
	return true;
}
function validateState(field, strMessage) {
	if (field.selectedindex == 0 && field.value == ''){
		alert(strMessage); 
		field.focus();
		return false;
	}
	return true;
}

function validateDropDown(objField, strMessage) {
	if (objField.options[0].selected == true && objField.value == '') {	//No Dropdown Value Selected.
		alert(strMessage);
		objField.focus();
		return false;
	}
		// Check that current character isn't whitespace.
	var c = objField.value.charAt(1);
	if ( c == '-' || c=='') {
		alert(strMessage);
		objField.focus();
		return false;
	} 
	return true;
}
function validateAreaCode(objField, state, strMessage) {
	if (isEmpty(objField.value)) {
		alert(strMessage);
		objField.focus();
		return false;
	}else {
		if (!areacode(objField.value, state)){	         //Invalid Area Code.
			objField.focus();
			return false;
		}
	}
	return true;
}
function validateDLExpireDate(objField, strMessage) {
	//Set dates
	today=new Date();					//Current Date
	oneday=1000*60*60*24				//Get 1 day in milliseconds
	if (objField.value.indexOf('/') <= 0 || objField.value.length < 10) {
		alert(strMessage);
		objField.focus();
		return false;
	}else{
		mon=objField.value.slice(0,2);
		day=objField.value.slice(3,objField.value.length-5);
		yer=objField.value.slice(6,objField.value.length);
		dldate =new Date(yer, mon, day) //Month is 0-11 in JavaScript
		//Calculate difference btw the two dates, and convert to days
		expdate=Math.ceil((today.getTime()-dldate.getTime())/(oneday))
	}
	if (expdate > -30) {
		expdate = expdate + 30;
		alert('MSGP003 - Your Driver License Expired ' + expdate + ' Days Ago');
		objField.focus();
		return false;
	}
	return true;
}
function validateRadio(objForm, strMessage){
	for (xx=0; xx < document.subscribeForm.elements.length; xx++){
		 if (document.subscribeForm.elements[xx].type == 'radio' && 
			 document.subscribeForm.elements[xx].checked == true &&
			 document.subscribeForm.elements[xx].name == objForm)
		 return true;
	}
	alert(strMessage);
	return false;	
}
function validateCheckBox(objForm, strMessage){
	for (xx=0; xx < document.subscribeForm.elements.length; xx++){
		 if (document.subscribeForm.elements[xx].type == 'checkbox' && 
			 document.subscribeForm.elements[xx].checked == true &&
			 document.subscribeForm.elements[xx].name == objForm.name)
		 return true;
	}
	alert(strMessage);
	return false;	
}

function validateForm(objForm) {
	with(objForm) {
	// Validate Form Input
		if(!validateTextField(FirstName,2,30,'Please Enter Your Name For Our Records')) return false;
		if(!validateTextField(LastName,2,30,'Please Enter Your Name For Our Records')) return false;
		if(!validateTextField(Address,2,60,'Please Enter The City Where Your Business Is Located')) return false;
		if(!validateTextField(City,2,30,'Please Enter The City Where Your Business Is Located')) return false;
		if(!validateDropDown(State,'Please Enter Your The State Where Your Business Is Located')) return false;
		if(!validateTextField(PostalCode,5,10,'Please Enter Your The Postal Code Where Your Business Is Located')) return false;
		if(!validateTextField(ContactNumber,10,15,'You Entered An Invalid Area Code For Contact Number')) return false;
		if(!validateEmail(Email,'Please Enter A Valid Email Address')) return false;
		

	}
}

function dateMark(field1, e){
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

	if(field1.value.length == 2 && !containsKeycode(filter,keyCode)){
		field1.value = field1.value.slice(0, field1.value.length);
		field1.value = field1.value + '/';
	}
	if(field1.value.length == 5 && !containsKeycode(filter,keyCode)){
		field1.value = field1.value.slice(0, field1.value.length);
		field1.value = field1.value + '/';
	}
	return true;
}
function ssnMark(field1, e){
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

	if (document.matrixForm.ssntin.options[1].selected == true) {
		if(field1.value.length == 3 && !containsKeycode(filter,keyCode)){
			field1.value = field1.value.slice(0, field1.value.length);
			field1.value = field1.value + '-';
		}
		if(field1.value.length == 6 && !containsKeycode(filter,keyCode)){
			field1.value = field1.value.slice(0, field1.value.length);
			field1.value = field1.value + '-';
		}
	}
	if (document.matrixForm.ssntin.options[2].selected == true) {
		if(field1.value.length == 2 && !containsKeycode(filter,keyCode)){
			field1.value = field1.value.slice(0, field1.value.length);
			field1.value = field1.value + '-';
		}
	}
	return true;
}
function autoTab(field1, field2, len, mark, e){
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

	if(field1.value.length >= len && !containsKeycode(filter,keyCode)) {
		if (mark == 2) field1.value = '(' + field1.value + ')';
		if (mark == 1) field1.value = field1.value + '-';

		field1.value = field1.value.slice(0, field1.value.length);
		field2.focus();
	}
	return true;
}
function containsKeycode(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length) {
		if(arr[index] == ele)
			found = true;
		else
			index++;
	}
	return found;
}




