// Validation routines for SSO Meeting Registration, edited Dec 2004, G. Vigoreaux
function validate3() {
		   	if  (document.page3.ID.value == '' &&
			document.page3.Last_Name.value == ''){
			window.alert('Please enter a Member ID or a Last Name.');
			document.page3.ID.focus();
            return false; 
            }
}

function validate5() {
//declare local and global variables
	var si1 = document.form5.country.selectedIndex;
	country_name = document.form5.country.options[si1].value;

		   	if  (document.form5.first_name.value == ''){
			window.alert('Please enter a First Name.');
			document.form5.first_name.focus();
            return false; 
            }
		    if  (document.form5.last_name.value == ''){
			window.alert('Please enter a Family Name.');
			document.form5.last_name.focus();
            return false; 
            }
		    if  (document.form5.address_1.value == ''){
			window.alert('Please enter an Office Address Line 1.');
			document.form5.address_1.focus();
            return false; 
            }
		    if  (document.form5.city.value == ''){
			window.alert('Please enter a City.');
			document.form5.city.focus();
            return false; 
            }
			if (country_name == "" || country_name == "Canada") {	
				if  (!verifyDropDown(document.form5.state_province.selectedIndex))  {
						window.alert('Please select a State/Province.');
						document.form5.state_province.focus();
           				return false; 
           			}
			}
		    if  (document.form5.zip.value == ''){
			window.alert('Please enter a Zip/Postal Code.');
			document.form5.zip.focus();
            return false; 
            }
		    if  (document.form5.work_phone.value == ''){
			window.alert('Please enter a valid Office Phone.');
			document.form5.work_phone.focus();
            return false; 
            } 			
			if (country_name == "" ||  country_name == "Canada") {	
				if  (!isValidPhoneNumber(document.form5.work_phone)){
				window.alert('Please enter a valid Office Phone (999-999-9999).');
				document.form5.work_phone.focus();
        		return false; 
        		}
				if  (!isValidPhoneNumber(document.form5.fax)){
				window.alert('Please enter a valid Fax (999-999-9999).');
				document.form5.fax.focus();
        		return false; 
        		}
			}
			if 	(document.form5.email.value == '' || !isEmail(document.form5.email.value)){
			window.alert('Please enter a valid Email Address.');
			document.form5.email.focus();
            return false; 
            }
}	

function validate6() {
	for (i=0; i < 4; i++) {
		if (document.page6.Category[i].checked == true) {
			return true;
		}
	}
	window.alert('Please select at least one category.');
    return false; 
}

function validate8() {
	if (document.page8.attend[0].checked == false &&
		document.page8.attend[1].checked == false) {
			window.alert('Please indicate your intention to attend.');
            return false; 
	}
}


function validate12A() {
		   	if  (document.page12A.Last_Name.value == ''){
			window.alert('Please enter Spouse Last Name.');
			document.page12A.Last_Name.focus();
            return false; 
            }
}

function validate13() {
	if  (document.page13.cardnumber.value == '' ||
	!_CF_checkcreditcard(document.page13.cardnumber.value)) {
		window.alert('Please enter a valid Credit Card Number.');
		document.page13.cardnumber.focus();
		return false; 
	}
	 if  (document.page13.nameoncard.value == ''){
			window.alert('Please enter a valid Name on Card.');
			document.page13.nameoncard.focus();
            return false; 
      } 
     // document.page13.SubmitPage13.value = 'Processing Registration';
	 document.page13.SubmitPage13.disabled = true;
}

function validateEmail() {
	if 	(document.form5.email.value == '' || !isEmail(document.form5.email.value)){
			window.alert('Please enter a valid Email Address.');
			document.form5.email.focus();
            return false; 
            }
}	

function cartWindow() {
	newWin = window.open('DisplayCart.cfm','newWin','width=700,height=480,resizable,scrollbars');
}

function displayADA() {
		if 	(document.form5.ada.checked == true){
			newWin = window.open('ADA.cfm','newWin',	
			'width=600,height=500,resizable');
		}
}

function verifyDropDown(val) {
if (val == 0) {
	return false;}
else {
	return true;}
}

function isValidPhoneNumber(me){
	var sPhoneNumber = me.value;
	var FoundX=0;

	if (sPhoneNumber == null || sPhoneNumber == '' || sPhoneNumber == ' ') 
		return true;

	var strippedNumber = sPhoneNumber.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(strippedNumber))) 		
		return false;
	else {
		sPhoneNumber = parseInt(strippedNumber) 	
		sPhoneNumber = sPhoneNumber.toString();
		if (sPhoneNumber.length  < 10) 
			return false;		
		}

	if (strippedNumber.length < 10) return false; 		
	for (i = 0; i < strippedNumber.length; i++) {
		if (strippedNumber.charAt(i) < "0" || strippedNumber.charAt(i) > "9") {
	     		if (strippedNumber.charAt(i) == "X" || strippedNumber.charAt(i) == "x") {
				FoundX = FoundX + 1
				if (FoundX > 1) return false;
				}
			else
				return false;
		}
    	 }
	return true;
}

function isEmail(theEmail){
	var s = theEmail;
	var ok = 1;
	
	//Check to make sure it is more than 6 characters in length
	if ((s.length < 7)){
		ok = 0;
	}

	//Check to make sure it is has an @ character and there is at least one character before it
	var at = s.indexOf('@');
	if (at < 1){
		ok = 0;
	}
	
	//Check to make sure it is has only one @ character
	if (at != s.lastIndexOf('@')){
		ok = 0;
	}

	//Check to make sure there is at least one full stop after the @ character and the number of characters from the full stop to the end is between 2-5 characters in length
	if ((s.lastIndexOf('.') < (at+1)) || (s.lastIndexOf('.') > (s.length-3)) || (s.lastIndexOf('.') < (s.length-6))){
		ok = 0;
	}

	//Check to make sure there are no funny characters
	if ((s.indexOf(',') != -1) || 
		(s.indexOf(' ') != -1) || 
		(s.indexOf(';') != -1) || 
		(s.indexOf(':') != -1) || 
		(s.indexOf('?') != -1) || 
		(s.indexOf('/') != -1) || 
		(s.indexOf('"') != -1) || 
		(s.indexOf('\\') != -1) || 
		(s.indexOf("'") != -1) || 
		(s.indexOf('[') != -1) || 
		(s.indexOf(']') != -1)){
		ok = 0;
	}
	
	if (s.length == 0){
		ok = 1
	}
	
	if (ok == 1){
	return true;}
	else
	{
	return false;}
}

function _CF_checkcreditcard(object_value)
    {
	var white_space = " -";
	var creditcard_string="";
	var check_char;


    if (object_value.length == 0)
        return true;

	// squish out the white space
	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i))
		if (check_char < 0)
			creditcard_string += object_value.substring(i, (i + 1));
	}	

	// if all white space return error
    if (creditcard_string.length == 0)
        return false;
	 
	 	
	// make sure number is a valid integer
	if (creditcard_string.charAt(0) == "+")
        return false;

	if (!_CF_checkinteger(creditcard_string))
		return false;

    // now check mod10

	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for (var i = 0; i < creditcard_string.length; i++)
	{
		tempdigit = eval(creditcard_string.charAt(i))

		if (doubledigit)
		{
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if ((tempdigit / 10) >= 1.0)
			{
				checkdigit++;
			}

			doubledigit = false;
		}
		else
		{
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}	
	return (checkdigit % 10) == 0 ? true : false;

    }


function _CF_checkinteger(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
	return _CF_checknumber(object_value);
    else
	return false;
    }


function _CF_numberrange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
	{
        if (object_value < min_value)
		return false;
	}

    // check maximum
    if (max_value != null)
	{
	if (object_value > max_value)
		return false;
	}
	
    //All tests passed, so...
    return true;
    }



function _CF_checknumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks

		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
    }



function _CF_checkrange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false

    if (object_value.length == 0)
        return true;


    if (!_CF_checknumber(object_value))
	{
	return false;
	}
    else
	{
	return (_CF_numberrange((eval(object_value)), min_value, max_value));
	}
	
    //All tests passed, so...
    return true;
    }



function _CF_checkphone(object_value)
    {
    if (object_value.length == 0)
        return true;
		
    if (object_value.length != 12)
        return false;

	// check if first 3 characters represent a valid area code
    if (!_CF_checknumber(object_value.substring(0,3)))
		return false;
    else
	if (!_CF_numberrange((eval(object_value.substring(0,3))), 100, 1000))
		return false;

	// check if area code/exchange separator is either a'-' or ' '
	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " ")
        return false

	// check if  characters 5 - 7 represent a valid exchange
    if (!_CF_checknumber(object_value.substring(4,7)))
		return false;
    else
	if (!_CF_numberrange((eval(object_value.substring(4,7))), 100, 1000))
		return false;
	
	// check if exchange/number separator is either a'-' or ' '
	if (object_value.charAt(7) != "-" && object_value.charAt(7) != " ")
        return false;

	// make sure last for digits are a valid integer
	if (object_value.charAt(8) == "-" || object_value.charAt(8) == "+")
        return false;
	else
	{
		return (_CF_checkinteger(object_value.substring(8,12)));
	}
    }



function _CF_checkzip(object_value)
    {
    if (object_value.length == 0)
        return true;
		
    if (object_value.length != 5 && object_value.length != 10)
        return false;

	// make sure first 5 digits are a valid integer
	if (object_value.charAt(0) == "-" || object_value.charAt(0) == "+")
        return false;

	if (!_CF_checkinteger(object_value.substring(0,5)))
		return false;

	if (object_value.length == 5)
		return true;
	
	// make sure

	// check if separator is either a'-' or ' '
	if (object_value.charAt(5) != "-" && object_value.charAt(5) != " ")
        return false;

	// check if last 4 digits are a valid integer
	if (object_value.charAt(6) == "-" || object_value.charAt(6) == "+")
        return false;

	return (_CF_checkinteger(object_value.substring(6,10)));
    }
	
function _CF_checkdate(object_value)
    {
    //Returns true if value is a date format or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a date in the mm/dd/yyyy format
	isplit = object_value.indexOf('/');

	if (isplit == -1 || isplit == object_value.length)
		return false;

    sMonth = object_value.substring(0, isplit);

	if (sMonth.length == 0)
        return false;

	isplit = object_value.indexOf('/', isplit + 1);

	if (isplit == -1 || (isplit + 1 ) == object_value.length)
		return false;

    sDay = object_value.substring((sMonth.length + 1), isplit);

	if (sDay.length == 0)
        return false;

	sYear = object_value.substring(isplit + 1);

	if (!_CF_checkinteger(sMonth)) //check month
		return false;
	else
	if (!_CF_checkrange(sMonth, 1, 12)) //check month
		return false;
	else
	if (!_CF_checkinteger(sYear)) //check year
		return false;
	else
	if (!_CF_checkrange(sYear, 0, 9999)) //check year
		return false;
	else
	if (!_CF_checkinteger(sDay)) //check day
		return false;
	else
	if (!_CF_checkday(sYear, sMonth, sDay)) // check day
		return false;
	else
		return true;
    }



function _CF_checkday(checkYear, checkMonth, checkDay)
    {

	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
			checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else
	if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else
		if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}

	return _CF_checkrange(checkDay, 1, maxDay); //check day
    }


function onlyMe() {
	if (document.page10D.me.checked )
{
    document.page10D.me2.checked = false;
    document.page10D.me.checked = true;
    
}
else {
    document.page10D.me2.checked = true;
    document.page10D.me.checked = false;
   
}

}
