//validates form

function validateData(form)
	{
	var re = / /g;
	var check
	 document.theForm.email.value = document.theForm.email.value.replace(re,"");
	 check = document.theForm.email.value.replace(re,"");
	
	var formattedphone;
	 formattedphone = document.theForm.area.value + "-" + document.theForm.firstdigits.value + "-" + document.theForm.lastdigits.value;
	 document.theForm.phone.value = formattedphone;
	 
	if (document.theForm.first_name.value == "" )
	{
		alert("Please enter your first name.");
		document.theForm.first_name.focus();
		return false;	
	}
	
	if (document.theForm.last_name.value == "" )
	{
		alert("Please enter your last name.");
		document.theForm.last_name.focus();
		return false;	
	}
	if (document.theForm.address.value == "" )
	{
		alert("Please enter your address.");
		document.theForm.address.focus();
		return false;	
	}
	if (document.theForm.city.value == "" )
	{
		alert("Please enter your city.");
		document.theForm.city.focus();
		return false;	
	}

	if (document.theForm.state.selectedIndex  == 0 )
	{
		alert("Please select your state.");
		document.theForm.state.focus();
		return false;	
	}
	if (document.theForm.country.selectedIndex  == 0 )
	{
		alert("Please select your country.");
		document.theForm.country.focus();
		return false;	
	}
	if (document.theForm.zip.value == "" )
	{
		alert("Please enter your zip code.");
		document.theForm.zip.focus();
		return false;	
	}
	if (IsEmailValid('theForm','email') == false) 
	{
		alert ("Please enter your E-mail address before continuing:  must be in the format of xxxx@xxx.xxx.");
		document.theForm.email.focus();
		return false;
	}
	if (document.theForm.area.value == "" || document.theForm.firstdigits.value == "" || document.theForm.lastdigits.value == "")
	{
		alert("Please enter your phone number.");
		document.theForm.area.focus();
		return false;	
	}
	
	if (document.theForm.time_zone.selectedIndex  == 0 )
	{
		alert("Please select your time zone.");
		document.theForm.time_zone.focus();
		return false;	
	}
	
	if (document.theForm.program.selectedIndex  == 0 )
	{
		alert("Please tell us the degree of interest.");
		document.theForm.program.focus();
		return false;	
	}
	
	if (document.theForm.Military.selectedIndex  == 0 )
	{
		alert("Please tell us if you are active in the military.");
		document.theForm.Military.focus();
		return false;	
	}
	
	if (document.theForm.cbUnderstand.checked == false)
	{
		alert("Please select the checkbox agreeing that you understand that an Admissions Advisor\nwill contact you within the next few days to provide you with additional information\nrelated to your specific goals.");
		return false;	
	}

	 
	 
	 var formattedphone2;
	 formattedphone2 = document.theForm.area2.value + "-" + document.theForm.firstdigits2.value + "-" + document.theForm.lastdigits2.value;
	 document.theForm.work_phone.value = formattedphone2;
	 
	 return true;
	}
	
	function IsEmailValid(FormName,ElemName)
	{
	var EmailOk  = true
	var Temp     = document.forms[FormName].elements[ElemName]
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1
	
	if ((AtSym < 1) ||                     // '@' cannot be in first position
	   (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
	   (Period == Length ) ||             // Must be atleast one valid char after '.'
	   (Space  != -1))                    // No empty spaces permitted
	 {  
	     EmailOk = false
	     Temp.focus()
	 }
	return EmailOk
	}
	
	function setCookie(name, value, expire) 
	{
	    strCookie = name + "=" + escape(value);
	    if (expire)
	        strCookie += "; expires=" + expire.toGMTString();
	
	    document.cookie = strCookie;
	}
	
	function saveValue(txtBox)
	{
		setCookie(txtBox.name,txtBox.value);
	}

	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	function autoTab(input,len, e) 
	{
		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(input.value.length >= len && !containsElement(filter,keyCode)) 
		{
			input.value = input.value.slice(0, len);
			input.form[(getIndex(input)+1) % input.form.length].focus();
		}
	
		function containsElement(arr, ele) 
		{
			var found = false, index = 0;
			while(!found && index < arr.length)
	
			if(arr[index] == ele)
				found = true;
			else
				index++;
	
			return found;
		}
	
		function getIndex(input) 
		{
			var index = -1, i = 0, found = false;
			while (i < input.form.length && index == -1)
			if (input.form[i] == input)
				index = i;
			else 
				i++;
			return index;
		}
	
	return true;
	}