// auto tabbing for phone field starts

var phone_field_length=0;
function TabNext(obj,event,len,next_field)
{
	if(event == "down")
	{
	  phone_field_length=obj.value.length;
	}
	else if(event == "up")
	{
	  if(obj.value.length != phone_field_length)
	  {
		phone_field_length=obj.value.length;
		
		if(phone_field_length == len)
		{
			next_field.focus();
		}
		
	  }
	}
}


// auto tabbing for phone field ends



//document.onKeyPress = getEnterKey;
if (navigator.appName == 'Netscape') {
    window.captureEvents(Event.KEYPRESS);
    window.onKeyPress = getEnterKey;
}

function getEnterKey(keyStroke) 
{

	// when user presses 'Enter' key 
	isNetscape=(document.layers);
	keyCode = (isNetscape) ? keyStroke.which : event.keyCode;
	if (keyCode==13) 
	{
		validation();
	}

}
//  End -->


function stringvalidateusername(field)
{
	
  var valid="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
	
  for (var i=0; i<field.length; i++) 
  {
		if (valid.indexOf(field.charAt(i)) < 0) 
		{
			//alert('invalid characters');
			return false;
		}
  }
			  
}
	
function stringvalidatepassword(field)
{
	
  var valid="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-._!@#%^&*"
		
  for (var i=0; i<field.length; i++) 
  {
		if (valid.indexOf(field.charAt(i)) < 0) 
		{
			//alert('invalid characters');
			return false;
		}
  }
  
}
	
// validation for first or last name
function stringvalidatename(field)
{
	
  var valid="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ'."
	
  for (var i=0; i<field.length; i++) 
  {
		if (valid.indexOf(field.charAt(i)) < 0) 
		{
			//alert('invalid characters');
			return false;
		}
  }
			  
}

function stringvalidatestate(field)
{
	
  var valid="0123456789abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	
  for (var i=0; i<field.length; i++) 
  {
		if (valid.indexOf(field.charAt(i)) < 0) 
		{
			//alert('invalid characters');
			return false;
		}
  }
			  
}

function stringvalidatecity(field)
{
	
  var valid="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	
  for (var i=0; i<field.length; i++) 
  {
		if (valid.indexOf(field.charAt(i)) < 0) 
		{
			//alert('invalid characters');
			return false;
		}
  }
			  
}

	
function integersonly(field)
{
	
  var valid="0123456789"
	
  for (var i=0; i<field.length; i++) 
  {
		if (valid.indexOf(field.charAt(i)) < 0) 
		{
			//alert('invalid characters');
			return false;
		}
  }
			  
}

function integersnhiphen(field)
{
	
  var valid="0123456789-"
	
  for (var i=0; i<field.length; i++) 
  {
		if (valid.indexOf(field.charAt(i)) < 0) 
		{
			//alert('invalid characters');
			return false;
		}
  }
			  
}

	
function validation()
{
  
  if (trim(document.CustSupport.txtFirstName.value) == "")
  {
     	alert("Please enter your First name.");
  	  document.CustSupport.txtFirstName.focus();
    	return false;
  }
  var ret = stringvalidatename(trim(document.CustSupport.txtFirstName.value))
  if (ret==false)
  {
		alert("Please don't include any numbers/special characters other than '. in first name.");
		document.CustSupport.txtFirstName.focus();
		return false;
  }


  if (trim(document.CustSupport.txtLastName.value) == "")
  {
   	alert("Please enter your last name.");
	  document.CustSupport.txtLastName.focus();
  	return false;
  }
  
 var ret1 = stringvalidatename(trim(document.CustSupport.txtLastName.value))
  if (ret1==false)
	{
		alert("Please don't include any numbers/special characters other than '. in last name.");
		document.CustSupport.txtLastName.focus();
		return false;
	}

 
   if(trim(document.CustSupport.txtEmailAddress.value) == "")
   {
     alert("Please enter your email address.");
     document.CustSupport.txtEmailAddress.focus();
 	return false;
   } 
 
 
 	var fieldname="Email";
 	var fieldvalue=trim(document.CustSupport.txtEmailAddress.value)
 	var specialcharset="`~!|\#$%^&*():;{}[]'?/<>,+=";
 	var ret6 = validemail(fieldvalue,fieldname,specialcharset)
 	if (ret6 == "false")
 	{
 		document.CustSupport.txtEmailAddress.focus();
 		return false;
 	}
 	
  
   
  if (trim(document.CustSupport.txtSchoolName.value) == "")
  {
   	alert("Please enter your School Name.");
	document.CustSupport.txtSchoolName.focus();
	return false;
  }
  
  if (document.CustSupport.cboBrowser[document.CustSupport.cboBrowser.selectedIndex].value == 0)
  {
     	alert("Please select type of browser.");
  	document.CustSupport.cboBrowser.focus();
  	return false;
  }
  if (document.CustSupport.cboOS[document.CustSupport.cboOS.selectedIndex].value == 0)
    {
       	alert("Please select operating system.");
    	document.CustSupport.cboOS.focus();
    	return false;
  }
  if (document.CustSupport.cboConnection[document.CustSupport.cboConnection.selectedIndex].value == 0)
      {
         	alert("Please select Internet Connection Speed.");
      	document.CustSupport.cboConnection.focus();
      	return false;
  }
  
   if (trim(document.CustSupport.txtQuestion.value) == "")
   {
     	alert("Please enter your Question or Problem.");
  	document.CustSupport.txtQuestion.focus();
  	return false;
   }
  
  
  document.CustSupport.action="custfeedback_mail.php";
  //document.CustSupport.submit();
  return true;
  	
}

function showStates()
{

   if (document.CustSupport.cboCountry.value != "0")
   {
	document.CustSupport.action="CustSupport.php?loadstate=yes";
	document.CustSupport.submit();
   }
}



//function to trim preceding and following spaces for text fields
function trim(str)
{
	temp=" ";
		var countspcatfrnt=-1;
		var len;
		i=0;
		len=str.length;
		while(temp==" ")
		{
			temp=str.substring(i,i+1);
			countspcatfrnt+=1;//counting front spaces
			i+=1;	
		}
		temp=" ";
		var countspcatrear=-1;
		var trimvalue=""
		i=0;
		while(temp==" ")
		{
			temp=str.substring(((len-i)-1),(len-i));
			countspcatrear+=1;//counting rear spaces
			i++;
		}
		i=0;
		for(i=countspcatfrnt; i<=(len-countspcatrear-1); i++)
			trimvalue=trimvalue + str.substring(i,i+1);
				
		return trimvalue;
}

function statecheck()
{

	if(document.CustSupport.cboCountry[document.CustSupport.cboCountry.selectedIndex].value == "253")
	{
		document.CustSupport.cboState.disabled = false;
		//document.CustSupport.cboCounty.disabled = false;
		document.CustSupport.txtStateOthers.disabled = true;
		document.CustSupport.cboState.focus();
		return true;
	}
	else
	{
		document.CustSupport.cboState.disabled = true;
    	//document.CustSupport.cboCounty.disabled = true;
		document.CustSupport.txtStateOthers.disabled = false;
		document.CustSupport.txtStateOthers.focus();
		return true;
	}
}

/*function onloadstatecheck()
{
	if(document.CustSupport.cboCountry[document.CustSupport.cboCountry.selectedIndex].value == "253")
	{
		document.CustSupport.cboState.disabled = false;
		document.CustSupport.cboCounty.disabled = false;
		document.CustSupport.txtStateOthers.disabled = true;
//		document.CustSupport.cboState.focus();
		return true;
	}
	else
	{
		document.CustSupport.cboState.disabled = true;
    	document.CustSupport.cboCounty.disabled = true;
		document.CustSupport.txtStateOthers.disabled = false;
//		document.CustSupport.txtStateOthers.focus();
		return true;
	}
}*/
function formload()
 {
	
  document.CustSupport.action="newCustSupport.php#country";
  document.CustSupport.submit();
 }

  function cleanfield(obj,varval)
{

	 var valid="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     field=obj.value;
	  for (var i=0; i<field.length; i++) 
  {
		
		  
		if (valid.indexOf(field.charAt(i)) > 0) 
		{
		
		    obj.value = "";
    	    obj.focus();
	       return true;

		}
  }

	/*if(obj.value == varval)
	{
		 alert("hello");

	
	}*/
}
function fillfield(obj,varval)
{

	if(obj.value == "")
	{
	    obj.value = varval;
	    return true;
	}
}
 function storegrade()
  {
	  
   var checkedval="";
    for (counter = 0; counter < document.CustSupport.chkGrade.length; counter++)
      {
          if (document.CustSupport.chkGrade[counter].checked)
          {
             
             if(checkedval=="")
              {
              checkedval=document.CustSupport.chkGrade[counter].value;
              }
             else
             {
              checkedval=checkedval+","+document.CustSupport.chkGrade[counter].value;
             }
          }
      }
   document.CustSupport.txtGrade.value=checkedval;
  
  }
	  
function resetform()
{

	document.CustSupport.hdnFormSubmition.value="no";
	
	document.CustSupport.action="newCustSupport.php";
//	document.CustSupport.href="CustSupport.php";
	document.CustSupport.submit();
}

//----------------------------------------------------------------
//=======TRIM==========END==============
//----------------------------------------------------------------  
