//-----------------------------begin validation contact form submit-----------------------------------
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;
}


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 evening phone number.");
		document.theForm.area.focus();
		return false;	
	}
	
	if (document.theForm.gradmonth.selectedIndex  == 0 )
	{
		alert("Please select your High School Graduation or G.E.D. MONTH of Completion.");
		document.theForm.gradmonth.focus();
		return false;	
	}	

	if (document.theForm.gradyear.selectedIndex  == 0 )
	{
		alert("Please select your High School Graduation or G.E.D. YEAR of Completion.");
		document.theForm.gradyear.focus();
		return false;	
	}	

	if (document.theForm.campus.selectedIndex  == 0 )
	{
		alert("Please select which AIU Campus you're interested in.");
		document.theForm.campus.focus();
		return false;	
	}	
	
	if (document.theForm.program.selectedIndex  == 0 )
	{
		alert("Please select the type of degree program you're interested in.");
		document.theForm.program.focus();
		return false;	
	}

	if (document.theForm.cbUnderstand.checked == false)
	{
		alert("Please select the checkbox agreeing that you understand that an Admission Advisor \nwill contact you to provide you with additional information related 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;
}
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 getCookie(Name) 
{
    var search = Name + "="
    if (document.cookie.length > 0) 
	{ 
        // if there are any cookies
        offset = document.cookie.indexOf(search)
        if (offset != -1) 
		{ 
            // if cookie exists
            offset += search.length

            // set index of beginning of value
            end = document.cookie.indexOf(";", offset)

            // set index of end of cookie value
            if (end == -1)
                end = document.cookie.length

            return unescape(document.cookie.substring(offset, end))
        }
    }
}

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);
}//end contact form submit	
