var fill = false;
function saveData()
{ 
     //return true;
     if(Checknull(document.QuesForm.firstname.value)) {
        alert("Please Enter your First Name");
        document.QuesForm.firstname.focus();
        return false;
	 }
     if(Checknull(document.QuesForm.lastname.value)) {
        alert("Please Enter your Last Name");
        document.QuesForm.lastname.focus();
        return false;
	 }
	 if(Checknull(document.QuesForm.email.value))
  	 {
			alert("Please enter a valid E-Mail Address");
			document.QuesForm.email.select();
			document.QuesForm.email.focus();
	        return false;
 	 }
	
	 if(!Checknull(document.QuesForm.email.value))
	{
		if(checkEmail(document.QuesForm.email))
		{
			alert("Please enter a valid E-Mail Address");
			document.QuesForm.email.select();
			document.QuesForm.email.focus();
	        return false;
		}
	}
	// Should be the final one to be checked.
	for (var i=0; i < document.QuesForm.Affiliation.length; i++)
    {
   		if (document.QuesForm.Affiliation[i].checked)
      	{
      		return true;
        }		
   }
   alert("Please enter your ASU Affiliation");
   return false;
}
//-------------------------------------------------//
function selectContents( fieldObject){

// selecting the contents in the field.
    fieldObject.select();
}
//------------------------------------------------//
function Checknull(textobj){
if((textobj == "") || (textobj == null)){
 {
    return true;
 }
return false;
}
} 
//----------------------------------------------------//
function isNumber( stringObj )
{
  var str = stringObj.value;
  var x =  str.length;
  
  if(x==0)
    char1 = str;
  else
    char1 = str.charAt(x-1);

 
  i = parseInt(char1);

  if(char1!="0")
      if(!( i>=0 && i <= 9))
          stringObj.value  = ""+(str.substring(0,x-1));

}
//----------------------------------------------------//
function checkEmail(mail)
{
    if( mail.value.indexOf("@") == 0 )
           return true; 
	
	var len = mail.value.length;
	var pos = mail.value.lastIndexOf(".");
	var ast = mail.value.lastIndexOf("@");
	var bpos = len - pos;
	var dif = pos - ast;
	if(pos == 0 || ast ==0)
		return true;
	if(len > pos+2 && len < pos+5)
		return false;
	/*if ( dif == 1)
		return true;
		
    if(bpos > 4 || bpos <= 2)
	   return true;*/
	
	return true;
}

//------------------------------------------------//
//-----------------------------------------------//
function getSelectValue(objectName){
	return objectName.options[objectName.selectedIndex].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;
}

function clearAll()
{
 document.QuesForm.firstname.value="";
 //document.QuesForm.middlename.value="";
 document.QuesForm.lastname.value="";
 document.QuesForm.email.value="";
 document.QuesForm.combo2.selected.index=0;

 // Added on Feb 27 to clear the radio buttons
 document.QuesForm.option1.options.selectedIndex = 0; 
 document.QuesForm.option2.options.selectedIndex = 0; 
 document.QuesForm.option3.options.selectedIndex = 0; 
 
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function addMoreInterests(frm){
		//Redirect to Freshmaninteresets.asp 
		
		//after storing the previous values in session.???- chk if form values are accessible in 2nd page
		//before redirecting validate the form so that all the values are entered.
		
		//var frm = document.forms["QuesForm"];
		frm.hdnMoreInterests.value = true;
		set_DOB_PHONE(document.QuesForm);
		if(saveData())
		{
		frm.action = "process.asp";
		frm.submit();
		}
		else
		{
			//cancel the action
		}
}

function HidePersonalInfo()
{			
	//flag value that specifies if the innermenu is open
	var tblObj = document.getElementById(id);
	var dispState = tblObj.style.display;
	if (dispState == 'none') 
	{
		tblObj.style.display = 'block'
	}
	else
	{
	tblObj.style.display = 'none'
	}
}


