
// Validate 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,"");
	
		if (document.theForm.program.selectedIndex  == 0 )
	{
		alert("Please tell us the degree of interest.");
		document.theForm.program.focus();
		return false;	
	}
	
	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 (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.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.zip.value == "" )
	{
		alert("Please enter your zip code.");
		document.theForm.zip.focus();
		return false;	
	}

	if (document.theForm.area.value == "" || document.theForm.firstdigits.value == "" || document.theForm.lastdigits.value == "")
	{
		alert("Please enter your primary phone number.");
		document.theForm.area.focus();
		return false;	
	}
	
	if (document.theForm.MilitaryAffiliation.selectedIndex  == 0 )
	{
		alert("Please let us know if you are affiliated with the military.");
		document.theForm.MilitaryAffiliation.focus();
		return false;	
	}
	

	if (document.theForm.cbUnderstand.checked == false)
	{
		alert("Please select the checkbox agreeing that you understand that an Admission Representative \nwill contact you to provide you with additional information related to your specific goals.");
		return false;	
	}

  var formattedphone;
  formattedphone = document.theForm.area.value + "-" + document.theForm.firstdigits.value + "-" + document.theForm.lastdigits.value;
  document.theForm.phone.value = formattedphone;
  
/*var formattedphone2;
//  if (document.theForm.work_ext.value == "" )
//  {
   formattedphone2 = document.theForm.area2.value + "-" + document.theForm.firstdigits2.value + "-" + document.theForm.lastdigits2.value;
//  } 
//   else
//  { 
//  formattedphone2 = document.theForm.area2.value + "-" + document.theForm.firstdigits2.value + "-" + document.theForm.lastdigits2.value + "-" + document.theForm.work_ext.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
}