//*****************************************************************************
// C & G Technical Group Form Validation Script For Diversity Council
//*****************************************************************************

<!--
function Message(msgno) {
	alert(msgno);
}

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";

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.length < minLen || objField.value.length > maxLen) {
		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(0);
	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 < objForm.elements.length; xx++){
		 if (objForm.elements[xx].type == 'radio' && 
			 objForm.elements[xx].checked == true)
		 return true;
	}
	alert(strMessage);
	return false;	
}

function validateFormF(objForm) {
	with(objForm) {
	// Validate Form Input
//		if(!validateDropDown(venue,'You Must Select A Venue')) return false;
		if(!validateTextField(company,3,60,'You Must Tell Us What Company You Will Represent')) return false;
		if(!validateTextField(title,3,100,'What Is Your Title or Position With The Company')) return false;
		if(!validateTextField(fName,2,30,'What Is Your First Name')) return false;
		if(!validateTextField(lName,2,30,'What Is Your Last Name')) return false;
		if(!validateEmail(email,'Your Email Address Is Required')) return false;
		if(!validatePhoneNumber(dac,3,'You Entered An Invalid Phone Number Area Code')) return false;
		if(!validatePhoneNumber(dp1,3,'You Entered An Invalid Phone Number Exchange')) return false;
		if(!validatePhoneNumber(dp2,4,'You Entered An Invalid Phone Local Line Number')) return false;
		if(!validateRadio(objForm,'You Must Select A Payment Method')) return false;	
	}
}

function validateFormR(objForm) {
	with(objForm) {
	// Validate Form Input
		if(!validateDropDown(venue,'You Must Select A Venue')) return false;
		if(!validateTextField(company,3,60,'You Must Tell Us What Company You Will Represent')) return false;
		if(!validateTextField(title,3,100,'What Is Your Title or Position With The Company')) return false;
		if(!validateTextField(fName,2,30,'What Is Your First Name')) return false;
		if(!validateTextField(lName,2,30,'What Is Your Last Name')) return false;
		if(!validateEmail(email,'Your Email Address Is Required')) return false;
		if(!validatePhoneNumber(dac,3,'You Entered An Invalid Phone Number Area Code')) return false;
		if(!validatePhoneNumber(dp1,3,'You Entered An Invalid Phone Number Exchange')) return false;
		if(!validatePhoneNumber(dp2,4,'You Entered An Invalid Phone Local Line Number')) return false;
		if(hiddentotal.value == '0.00') {alert('You Must Select Sponsorship Level Before Continuing'); return false;}
	}
}
function validateFormJ(objForm) {
	with(objForm) {
	// Validate Form Input
		if(!validateTextField(company,3,60,'You Must Tell Us What Company You Will Represent')) return false;
		if(!validateTextField(title,3,40,'What Is Your Title or Position With The Company')) return false;
		if(!validateDropDown(district,'Please Select A Council District')) {return false;
			} else if(document.memberForm.district.value == 'Please Choose One') { 
				alert('Please Select A Council District') 
				document.memberForm.district.focus();
				return false;
			}
		if(!validateTextField(fName,2,30,'What Is Your First Name')) return false;
		if(!validateTextField(lName,2,30,'What Is Your Last Name')) return false;
		if(!validateTextField(address,2,60,'Please Enter Your Mailing Address')) return false;
		if(!validateTextField(city,2,60,'Please Enter Your Mailing Address City')) return false;
		if(!validateDropDown(state,'Please Select Your Mailing Address State')) return false;
		if(!validateTextField(zip,5,10,'Please Enter Your Mailing Address Postal Code')) return false;
		if(!validatePhoneNumber(dac,3,'You Entered An Invalid Phone Number Area Code')) return false;
		if(!validatePhoneNumber(dp1,3,'You Entered An Invalid Phone Number Exchange')) return false;
		if(!validatePhoneNumber(dp2,4,'You Entered An Invalid Phone Local Line Number')) return false;
		if(!validateEmail(email,'Your Email Address Is Required')) return false;
		if(!validateTextField(userid,2,12,'Please Enter A Userid for Member Only Access')) return false;
		if(!validateTextField(pwd,2,12,'Please Enter A Password for Member Only Access')) return false;
		if(!validateTextField(cpwd,2,12,'Password Confirmation Failed. Please Re-enter both')) return false;
		if(!validateRadio(objForm,'You Must Select A Payment Method')) return false;	

//		else
//		if(cpwd != pwd) {alert('Password Confirmation Failed. Please Re-enter both'); 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;
}
function WhichPayment(f) {
	var individuals = false;
	var paybycheck = false;
	for (xx=0; xx < f.elements.length; xx++){
		 if (f.elements[xx].type == 'radio' && 
			 f.elements[xx].checked == true) {
			 
			 if (f.elements[xx].value == '175' ||
			 	 f.elements[xx].value == '189')
				 	individuals = true;
			
			 if (f.elements[xx].name == 'ccmethod' &&
			     f.elements[xx].value == 'Check')
				 	paybycheck = true;
		}
	}
	if (individuals && paybycheck) {
		alert('Individual Registration Requires Credit Card Payment Only');
		return false;
	} else
		return true;
}
function TotalChoice(objbox)
	{ 	with (objbox.form)
		{
		
			//Add quantity selected to registration price:
			if (objbox.checked) {
				hiddentotal.value = 0;	
				hiddentotal.value = eval(objbox.value) + eval(hiddentotal.value);
			}else hiddentotal.value = eval(hiddentotal.value) - eval(objbox.value);
			
			//Move calculated Sales Total to form:
			document.registerForm.TotalSales.value = hiddentotal.value;
			
			//Ensure the total never goes negative:
			if (hiddentotal.value < 0) {
				alert('A Negative Total Entered - Sales Total = ' + hiddentotal.value); 
				InitForm();
			}
			//Now, return with formatted total:
			return(formatCurrency(hiddentotal.value));
	}
}

//Define function to format a value as currency:
function formatCurrency(num)
	{
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		   num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
		    cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		    num = num.substring(0,num.length-(4*i+3))+','+
		          num.substring(num.length-(4*i+3));
  	    return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function InitForm()
	{
		//Reset the displayed total on form:
		document.registerForm.TotalSales.value='$0.00';
		document.registerForm.hiddentotal.value=0;
		var mcounter=0;

		//Set all radio buttons on form to unchecked:
		for (xx=0; xx < document.registerForm.elements.length; xx++)
		{
		   if (document.registerForm.elements[xx].type == 'checkbox')
				document.registerForm.elements[xx].checked = false;
		}
}

function eventvenue(form) {
	form.event.value = form.venue.value + ' Luncheon';
    form.entrydate.value = gMon + '/' + gDay + '/' + gYear;
}
function ShowSponsor(sponsorType){
	switch(sponsorType)	{
		case 'divTitleSponsor':
			document.getElementById('divTitleSponsor').style.display = "block";
			document.getElementById('divRedDonor').style.display = "none";
			document.getElementById('divWhiteDonor').style.display = "none";
			document.getElementById('divBlueDonor').style.display = "none";
			break;
		case 'divRedDonor':
			document.getElementById('divTitleSponsor').style.display = "none";
			document.getElementById('divRedDonor').style.display = "block";
			document.getElementById('divWhiteDonor').style.display = "none";
			document.getElementById('divBlueDonor').style.display = "none";
			break;
		case 'divWhiteDonor':
			document.getElementById('divTitleSponsor').style.display = "none";
			document.getElementById('divRedDonor').style.display = "none";
			document.getElementById('divWhiteDonor').style.display = "block";
			document.getElementById('divBlueDonor').style.display = "none";
			break;
		case 'divBlueDonor':
			document.getElementById('divTitleSponsor').style.display = "none";
			document.getElementById('divRedDonor').style.display = "none";
			document.getElementById('divWhiteDonor').style.display = "none";
			document.getElementById("divBlueDonor").style.display = "block";
			break;
		case 'divCPDonor':
			document.getElementById('divTitleSponsor').style.display = "none";
			document.getElementById('divRedDonor').style.display = "none";
			document.getElementById('divWhiteDonor').style.display = "none";
			document.getElementById("divBlueDonor").style.display = "none";
			break;
	}	
}
var PrevWin = null;
function sendForm(f, action, target, page) {
	if (target != '_self') {
		PrevWin = open(action,target,'width=800,height=400,left=10,top=10,status=0,scrollbar=no,location=no,toolbar=no,resizable=no,directories=no');
		if (PrevWin && !PrevWin.closed) PrevWin.focus();
	}
	if (action) f.action = action;
	if (target) f.target = target;
	return true;
}
function winpop(filename,Ht,Wd)
{
	window.open(filename,"","height=" + Ht + ",width=" + Wd + ",status=no,toolbar=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes, left=50,top=50");
}
function SameAs(Form) {
	if (Form.sameas.checked == true) {
		Form.x_first_name.value = Form.fName.value;
		Form.x_last_name.value = Form.lName.value;
		Form.x_address.value = Form.address.value;
		Form.x_city.value = Form.city.value;
		Form.x_state.value = Form.state.value;
		Form.x_zip.value = Form.zip.value;
	}else if (Form.sameas.checked == false) {
		Form.x_first_name.value = '';
		Form.x_last_name.value = '';
		Form.x_address.value = '';
		Form.x_city.value = '';
		Form.x_state.value = '';
		Form.x_state.options[0].selected = true;
		Form.x_zip.value = '';
	}
	Form.x_first_name.focus();
}



