function doReset()
{
	document.forms[0].reset();
}

function ShowHideYearGraduated(layer_ref) 
{
	var d = 'none';
	
	if(document.forms[0].JOB_FUNCTION[0].checked == true)
	{ d = 'block'; } else { d = 'none'; }
	
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.display = d");
	}

	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].display = d;
	}
	
	if (document.getElementById && !document.all) {
		maxwell_smart = document.getElementById(layer_ref);
		maxwell_smart.style.display = d;
	}
}

function ShowHideInstitution(layer_ref) 
{
	var d = 'none';
	
	if(document.forms[0].JOB_FUNCTION[1].checked == true)
	{ d = 'block'; } else { d = 'none'; }
	
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.display = d");
	}

	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].display = d;
	}
	
	if (document.getElementById && !document.all) {
		maxwell_smart = document.getElementById(layer_ref);
		maxwell_smart.style.display = d;
	}
}

function formCheckAddr(mode, description)
{ 
	if(document.forms[0].RECEIVE_YES_NO[0].checked == false && document.forms[0].RECEIVE_YES_NO[1].checked == false)
	{
	alert("Please specify whether you wish to receive " + description +"?");
        document.forms[0].RECEIVE_YES_NO[0].focus();
		return false;
	}

	if(document.forms[0].RECEIVE_YES_NO[1].checked == true)
	// stop validation when "not to receive" response
	{
		return true;
	}

	if ((mode == "SHORT") || (mode == "ABBR"))
	{
		return true;
	}

	if (mode == "ADD")
	{
		if(document.forms[0].FIRSTNAME.value == "")
		{
			alert("Please specify your First name.");
        		document.forms[0].FIRSTNAME.focus();
			return false;
		}
		if(document.forms[0].LASTNAME.value == "")
		{
			alert("Please specify your Last name.");
        		document.forms[0].LASTNAME.focus();
			return false;
		}
	}
	if (mode != "RENEW")
	{
		if(document.forms[0].ADDRESS2.value == "")
		{
			alert("Please specify your Street Address.");
	        	document.forms[0].ADDRESS2.focus();
			return false;
		}
		if(document.forms[0].CITY.value == "")
		{
			alert("Please specify your City.");
	        	document.forms[0].CITY.focus();
			return false;
		}
		if (document.forms[0].STATE.selectedIndex == 0)
		{
			alert("Please specify your State/Province.");
		        document.forms[0].STATE.focus();
			return false;
		}

		// validate Canadian state/postal code combination
		if (!ValidCanPostal(document.forms[0].STATE[document.forms[0].STATE.selectedIndex].value,document.forms[0].ZIPCODE.value))
		{
			alert ("Invalid Canadian province/postal code combination.");
        		document.forms[0].STATE.focus();
			return false;
		}

		if (document.forms[0].ZIPCODE.value.length < 5)
		{
			alert("Please specify your Zip/Postal Code.");
        		document.forms[0].ZIPCODE.focus();
			return false;
		}
	}
	if(document.forms[0].EMAIL_ADDRESS.value == "")
	{
		alert("Please specify your E-mail Address.");
       	document.forms[0].EMAIL_ADDRESS.focus();
		return false;
    } 
	if ((document.forms[0].EMAIL_ADDRESS.value != "") && (!validEmail(document.forms[0].EMAIL_ADDRESS.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[0].EMAIL_ADDRESS.focus();
		return false;
	}	   
 }  

function formCheckDemo(mode, description)
{ 
	if (!CheckDemos(document.forms[0]))
	{
		return false;
	}
 }  
 

// declare global variables
var i;

// two arrays for Canadian province/postal code validation
var CanCodes=new Array("54","55","56","57","58","59","60","66","61","62","63","64","65");
var CanLetters=new Array("T","UV","R","E","A","B","X","X","KLMNP","C","GHJ","S","Y");

// check if first letter of postal code matches selected Canadian province
// StateCD is 2-digit code that Omeda uses to identify Canadian provinces (value of STATE field)
// PostCD is entered postal code (value of ZIPCODE field)
function ValidCanPostal(StateCD, PostCD)
{
	var fletter=PostCD.substring(0,1);
	fletter = fletter.toUpperCase();

	for(i=0;i<13;i++)
	{
		if (StateCD==CanCodes[i])
		{
			if (CanLetters[i].indexOf(fletter,0) == -1)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	return true;
}

function checkEmailValue(emailValue)
{     //runs the validate script and returns error box or nonerror

	if (emailValue == "")
	{
		alert("You have not entered email address. Please re-enter it.");
		return false;
	}

	startPos = 0;

	commaPos = emailValue.indexOf(",",startPos+1);	//position of semicolomn
	while (commaPos != -1)
	{
		endPos = commaPos;
		emailElement = emailValue.substring(startPos,endPos);
		if(!validEmail(emailElement))
		{
			alert("You have entered an invalid email address. Please re-enter it.");
			return false;
		}
		startPos = endPos + 1;		
		commaPos = emailValue.indexOf(",",startPos);	//position of semicolomn
	}
	endPos = emailValue.length;
	emailElement = emailValue.substring(startPos,endPos);

	if(!validEmail(emailElement))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		return false;
	}
	return true;		
}				

function validEmail(email)
{
	invalidchars = " /:;"

	if(email == "")
	{			//checks to see if blank field
		return false
	}
			
	for(i=0;i<invalidchars.length;i++){ //checks for invalid chars
			
	badchars = invalidchars.charAt(i)
			
	if(email.indexOf(badchars,0)!= -1)
	{
		return false
	}											}
	
	atPos = email.indexOf("@",1)  //holds position of "@"
			
	if(atPos == -1) 
	{	//checks to see if "@" present
		return false
	}
							
	if(email.indexOf("@",atPos+1) != -1) 
	{ //checks for second "@"
		return false
	}
							
	periodPos = email.indexOf(".",atPos) //holds position of "."
			
	if(periodPos == -1)
	{ //checks for presence of "."
		return false
	}
	if(periodPos+3 > email.length)
	{//makes sure at least two chars after the period
		return false
	}
	return true 
}
function ValidNum(NumObj)
{
	var myNum, cleanNum;
	
	myNum = NumObj.value
	cleanNum = parseInt(myNum);

	if( myNum == ""){return true;}
	
   	if(myNum != cleanNum)
	{
		alert("You have entered an invalid number for Year of Graduation. Please re-enter.");
		NumObj.focus();
		return false;
	}
	return true;
}

function AnswerCheck(form)
{ 
	if(form.RECEIVE_NEWSLETTER[0].checked == true)
	{
		if(form.FNAME.value == "")
		{
			alert("Please specify your First name.");
        		form.FNAME.focus();
			return false;
		}
		if(form.LNAME.value == "")
		{
			alert("Please specify your Last name.");
        		form.LNAME.focus();
			return false;
		}
        if(form.EMAIL_ADDRESS.value == "")
		{
			alert("Please specify your E-mail Address.");
        		form.EMAIL_ADDRESS.focus();
			return false;
        } 
		return true;
	}
} 
	
function checkDropdown(selectBox)
{

	if(selectBox.selectedIndex == "0")
	{
		return false;
	}
	else
	{
		return true;
	}
}

function CheckDropdown(selectBox)
{

	if(selectBox.selectedIndex == "0")
	{
		return false;
	}
	else
	{
		return true;
	}
}

function CheckUnselects(radioItem)
{
	for(i=0;i<radioItem.length;i++)
	{
		if(radioItem[i].checked)
		{
			return true;
		}//end if
	}//end for
	return false;
}
function CheckedRadioValue(radioItem)
{
	for(i=0;i<radioItem.length;i++)
	{
		if(radioItem[i].checked)
		{
			return radioItem[i].value;
		}//end if
	}//end for
	return false;
}
function CheckboxChecked(thisform,CheckBoxName)
{
var ChLength = CheckBoxName.length + 1;
var vName = CheckBoxName + "-";

var CBindex = 0;

	for ( i=0; i < thisform.elements.length; i++)
	{
		if (thisform.elements[i].type == "checkbox")
		{
			if (thisform.elements[i].name.substring(0,ChLength)==vName)
			{
				if (CBindex==0) {CBindex = i;}
				if (thisform.elements[i].checked)
				{
					return true;
					break;
				}
			}
		}

	}

	thisform.elements[CBindex].focus();
	return false;
}

