// JavaScript Document
/*====================================================================================================*/
function checkMobile(numObj,numberType)
{
	if( ( numObj.value == "" ) || ( !numObj.value.match(/^00[0-9]{10,12}$/i)) )
	{
		if(numObj.value.charAt(0)=='+')
		{
			alert(numberType + " number cannot start with '+'\nPlease enter a valid " + numberType + " number starting with 00\ne.g. 00494324245432");
		}
		else if(numObj.value.charAt(0)=='0' && numObj.value.charAt(1)!='0')
		{
			alert(numberType + " number cannot start with single '0'\nPlease enter a valid " + numberType + " number starting with 00\ne.g. 00494324245432");
		}
		else
		{
			alert("Please enter a valid " + numberType + " number\ne.g. 00494324245432\n12 - 14 digits are allowed")
		}
		return false;
	}
	return true;
}
/*====================================================================================================*/
function IsNumeric(strString,addchar)   
   {
   var strValidChars = addchar+"0123456789";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
/////////////////////////////////////////
function haveNum(str)   
   {
    for(i=0;i<str.length;i++)
	{
		if(str.charAt(i) >= '0' && str.charAt(i) <= '9') 
		   return false;
	}
	return true;
   }
/////////////////////////////////////////
function isAlpha(str)   
   {
    for(i=0;i<str.length;i++)
	{
		if(!( (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') || (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z')  || str.charAt(i) == ' '))
		   return false;
	}
	return true;
   }
/////////////////////////////////////////

function capitalize(str)
{
	return str.charAt(0).toUpperCase()+str.substr(1).toLowerCase();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkDate(newday,newmonth,newyear,type)
 	{		
			if( newday > 30 && ( newmonth == 4 ||  newmonth == 6 ||  newmonth == 9 ||  newmonth == 11) )
			  {
			    alert("Wronge Day of "+type+" Date.");
				return false;
			  }
			else if( newday > 31 && ( newmonth == 1 ||  newmonth == 3 ||  newmonth == 5 ||  newmonth == 7 ||  newmonth == 8 ||  newmonth == 10 ||  newmonth == 12) )  
			  {
			    alert("Wronge Day of "+type+" Date.");
				return false;
			  }
			else if( newday > 28 &&  newmonth == 2 )
			  {
			    if( !(newday == 29 && (( newyear % 4 ) == 0)) )
		 			{
					    alert("Wronge Day of "+type+" Date.");
						return false;
					}	
			  }
		return true;	  
	}		  
///////////////////////////////////////////////////////////////////////////////////////////
function checkPeriod()
{
	x = document.districts;
	if(checkDate(x.adate.value,x.amonth.value,x.ayear.value,"Activation") && checkDate(x.tdate.value,x.tmonth.value,x.tyear.value,"Termination"))
	{
	   s_date = new Date( x.ayear.value, x.amonth.value-1, x.adate.value);
	   e_date = new Date( x.tyear.value, x.tmonth.value-1, x.tdate.value);

	   if( s_date > e_date)
	   { 
		alert("Termination date is older than Activation date.");
		return false;
	   }
	   else
	    return true;
	}
	else
		return false;
}	
///////////////////////////////////////////////////////////////////////////////////////////
function del(form, record)
{
  if(record == 'student')
  {	
	if(confirm('Are you sure to delete this Student?') && confirm('This will delete all the Information about this Student?'))
	{
		form.pg.value='delete';
		return true;
	}
	else
		return false;
  }
  else  if(record == 'teacher')
  {	
	if(confirm('Are you sure to delete this Teacher?') && confirm('This will delete all the Students of this Teacher?'))
	{
		form.pg.value='delete';
		
		return true;
	}
	else
		return false;
		
  }
  
   else  if(record == 'parent')
  {	
	if(confirm('Are you sure to delete this Parent?') && confirm('This will delete all the Children of this Parent?'))
	{
		form.pg.value='delete';
		
		return true;
	}
	else
		return false;
  }
  else  if(record == 'school')
  {	
	if(confirm('Are you sure to delete this School?') && confirm('This will delete all the Teachers of this School?') && confirm('This will delete all the Students of any of Teachers this School?'))
	{
		form.pg.value='delete';
		return true;
	}
	else
		return false;
  }
  else if(record == 'district')
  {	
	if(confirm('Are you sure to delete this District?') && confirm('This will delete all the Schools of this District?') && confirm('This will delete all the Teachers under any of the Schools of this District?') && confirm('This will delete all the Students of any of Teachers of any of the Schools of this District?'))
	{
		form.pg.value='delete';
		return true;
	}
	else
		return false;
  }
  
}
/*==========================================================================*/
function check_change()
{

	var user = change.username.value.toLowerCase();;
	var opass = change.opass.value;
	var pass1 = change.pass1.value;
	var pass2 = change.pass2.value;	

	var err="";
	if( user == "" )
	{
		err += "Empty User Name field not allowed.\n";
	}
	else if( user.length >50 ) 
	{
		err += "User Name can have maximum 50 characters.\n";
	}
	/*else 
	{    
		re = /^[^0-9]\w+$/;
		if(!re.test(user)) 
		{
			if(user.charAt(0) >='0' && user.charAt(0) <='9')
				err += "User Name cannot start with a digit.\n";
			else
			    err += "User Name can have only Letters,digifts or underscore.\n";
		}
	}*/

	if( opass == "" )
	{
		err += "Empty Old Password field not allowed.\n";
	}
	else if( opass.length < 6 ) {
		err += "Old Password Should have at least 6 characters.\n";
	}
		
  if( pass1 == "" )
	{
		err += "Empty New Password field not allowed.\n";
	}
	else if( pass1.length < 6 ) {
		err += "New Password Should have at least 6 characters.\n";
	}
  if( pass1 != "" && pass1.length >= 6)
  {
  	 if( pass1 != pass2 )
	  {
		err += "New Password and Confirm Password Fields do not match.\n";
	  }
  }
if( err != "" )
 {
	alert(err);
	return false;
 }
else
 {	
	return true;
 }
}
/*===================================================================*/
function setFocus(field)
{
	field.focus();
	field.select();
	return false;
}
function check_district(access)
{
	x = document.forms[0];
	re1 = /^[^0-9]\w+$/;

	if(x.name.value =="") 
	{
	   alert("Empty District Name is not allowed.");
	   setFocus(x.name);
	}
	else if(x.address.value =="") 
	{
	   alert("Empty Address field is not allowed.");
	   setFocus(x.address);
	}
	else if(x.city.value =="" || !isAlpha(x.city.value)) 
	{
	   alert("Please enter a valid City Name.");
	   setFocus(x.city);
	}
	else if(x.state.value =="") 
	{
	   alert("Empty State Field is not allowed.");
	   setFocus(x.state);
	}
	else if(x.zipcode.value =="")
	{
		alert("Please enter a valid Zip Code.")
	    setFocus(x.zipcode);
	}
	else if(x.country.value =="") 
	{
		alert("Empty Country Field is not allowed.");
	    setFocus(x.country);
	}
	else if(x.phone.value =="") 
	{
		alert("Empty Phone Field is not allowed.");
	    setFocus(x.phone);
	}
	else if(x.fax.value =="") 
	{
		alert("Empty Fax Field is not allowed.");
	    setFocus(x.fax);
	}
	/*else if(!checkMobile(x.phone,'Phone'))
	{
	    setFocus(x.phone);
	}
	else if(!checkMobile(x.fax,'Fax'))
	{
	    setFocus(x.fax);
	}*/
	else if(x.poc.value =="") 
	{
	   alert("Empty Point of Contact field is not allowed.");
	   setFocus(x.poc);
	}
	else if(!x.email.value.match(/^([A-Z0-9_][A-Z0-9._%-]*@[A-Z0-9_][A-Z0-9._%-]*\.[A-Z]{2,4})$/i))
	{
		alert("Invalid POC Email Address.");
	    setFocus(x.email);
	}
	else if( access == "admin" && x.username.value == "" )
	{
		alert("Empty User Name field not allowed.");
		setFocus(x.username);
	}
	else if( access == "admin" &&  x.username.value.length >50 ) 
	{
		alert("User Name can have maximum 50 characters.");
		setFocus(x.username);
	}
	/*else if( access == "admin" && !re1.test(x.username.value)) 
	{    
		if(x.username.value.charAt(0) >='0' && x.username.value.charAt(0) <='9')
			alert("User Name cannot start with a digit.");
		else
		   alert("User Name can have only Letters,digifts or underscore.");
		setFocus(x.username);
	}*/
	else if( access == "admin" &&  x.password.value == "" )
	{
	   alert("Empty Password field not allowed.");
	   setFocus(x.password);
	}
	else if( access == "admin" &&  x.password.value.length < 6 ) 
	{
	   alert("Password Should have at least 6 characters.");
	   setFocus(x.password);
	}
	else if( access == "admin" &&  !(x.contracttype[0].checked || x.contracttype[3].checked || x.contracttype[1].checked || x.contracttype[2].checked))
	{
	   alert("You must select Type of Contract!");
		return false;
	}
	else if( access == "admin" &&  !(x.contracttype[0].checked || x.contracttype[3].checked) && !checkPeriod())
	{
	    x.amonth.focus();
		return false;
	}
	else
	{
		x.submit();
	}
}
/*============================================================================*/
function check_school(access)
{
	x = document.forms[0];
	re1 = /^[^0-9]\w+$/;

	if( access == "admin" && x.username.value == "" )
	{
		alert("Empty User Name field not allowed.");
		setFocus(x.username);
	}
	else if( access == "admin" &&  x.username.value.length >50 ) 
	{
		alert("User Name can have maximum 50 characters.");
		setFocus(x.username);
	}
	/*else if( access == "admin" && !re1.test(x.username.value)) 
	{    
		if(x.username.value.charAt(0) >='0' && x.username.value.charAt(0) <='9')
			alert("User Name cannot start with a digit.");
		else
		   alert("User Name can have only Letters,digifts or underscore.");
		setFocus(x.username);
	}*/
	else if( access == "admin" &&  x.password.value == "" )
	{
	   alert("Empty Password field not allowed.");
	   setFocus(x.password);
	}
	else if( access == "admin" &&  x.password.value.length < 6 ) 
	{
	   alert("Password Should have at least 6 characters.");
	   setFocus(x.password);
	}
	else if(x.name.value =="") 
	{
	   alert("Empty School's Name is not allowed.");
	   setFocus(x.name);
	}
	else if(x.address.value =="") 
	{
	   alert("Empty Address field is not allowed.");
	   setFocus(x.address);
	}
	else if(x.city.value =="" || !isAlpha(x.city.value)) 
	{
	   alert("Please enter a valid City Name.");
	   setFocus(x.city);
	}
	else if(x.state.value =="") 
	{
	   alert("Empty State Field is not allowed.");
	   setFocus(x.state);
	}
	else if(x.zipcode.value =="")
	{
		alert("Please enter a valid Zip Code.")
	    setFocus(x.zipcode);
	}
	else if(x.country.value =="") 
	{
		alert("Empty Country Field is not allowed.");
	    setFocus(x.country);
	}
	else if(x.phone.value =="")
	{
	    alert("Empty Phone Field is not allowed.");
	    setFocus(x.phone);
	}
	else if(x.fax.value =="")
	{
	    alert("Empty Fax Field is not allowed.");
	    setFocus(x.fax);
	}
	else if(x.poc.value =="") 
	{
	   alert("Empty Point of Contact field is not allowed.");
	   setFocus(x.poc);
	}
	else if(x.maxspt.value =="") 
	{
	   alert("Empty Maximum No. of Students Per Teacher field is not allowed.");
	   setFocus(x.maxspt);
	}
	else if(!IsNumeric(x.maxspt.value))
	{
	   alert("Maximum No. of Students Per Teacher field must be only numeric");
	   setFocus(x.maxspt);
	}
	else if(!x.email.value.match(/^([A-Z0-9_][A-Z0-9._%-]*@[A-Z0-9_][A-Z0-9._%-]*\.[A-Z]{2,4})$/i))
	{
		alert("Invalid POC Email Address.");
	    setFocus(x.email);
	}
	else
	{
		x.submit();
	}
}
/*============================================================================*/
function check_teacher(access)
{
	x = document.forms[0];
	re1 = /^[^0-9]\w+$/;

	if( access == "admin" && x.username.value == "" )
	{
		alert("Empty User Name field not allowed.");
		setFocus(x.username);
	}
	else if( access == "admin" &&  x.username.value.length >50 ) 
	{
		alert("User Name can have maximum 50 characters.");
		setFocus(x.username);
	}
	/*else if( access == "admin" && !re1.test(x.username.value)) 
	{    
		if(x.username.value.charAt(0) >='0' && x.username.value.charAt(0) <='9')
			alert("User Name cannot start with a digit.");
		else
		   alert("User Name can have only Letters,digifts or underscore.");
		setFocus(x.username);
	}*/
	else if( access == "admin" &&  x.password.value == "" )
	{
	   alert("Empty Password field not allowed.");
	   setFocus(x.password);
	}
	else if( access == "admin" &&  x.password.value.length < 6 ) 
	{
	   alert("Password Should have at least 6 characters.");
	   setFocus(x.password);
	}
	else if(x.name.value =="") 
	{
	   alert("Empty Teacher's Name is not allowed.");
	   setFocus(x.name);
	}
	else if(!x.email.value.match(/^([A-Z0-9_][A-Z0-9._%-]*@[A-Z0-9_][A-Z0-9._%-]*\.[A-Z]{2,4})$/i))
	{
		alert("Invalid Teacher's Email Address.");
	    setFocus(x.email);
	}
	else
	{
		x.submit();
	}
}
function check_teachergradings()
{
	x = document.forms[0];
	exceptional = parseInt(x.exceptional.value);
	verygood = parseInt(x.verygood.value);
	aboveaverage = parseInt(x.aboveaverage.value);
	average = parseInt(x.average.value);
	belowaverage = parseInt(x.belowaverage.value);
	passmarks = parseInt(x.passmarks.value);
			
	if(x.exceptional.value =="" || !x.exceptional.value.match(/^[0-9]{1,3}$/i))
	{
		alert("Invalid EXEPTIONAL Score!");
	    setFocus(x.exceptional);
	}
	else if(x.verygood.value =="" || !x.verygood.value.match(/^[0-9]{1,2}$/i))
	{
		alert("Invalid VERY GOOD Score!");
	    setFocus(x.verygood);
	}
	else if(x.aboveaverage.value =="" || !x.aboveaverage.value.match(/^[0-9]{1,2}$/i))
	{
		alert("Invalid ABOVE AVERAGE Score!");
	    setFocus(x.aboveaverage);
	}
	else if(x.average.value =="" || !x.average.value.match(/^[0-9]{1,2}$/i))
	{
		alert("Invalid AVERAGE Score!");
	    setFocus(x.average);
	}
	else if(x.belowaverage.value =="" || !x.belowaverage.value.match(/^[0-9]{1,2}$/i))
	{
		alert("Invalid BELOW AVERAGE Score!");
	    setFocus(x.belowaverage);
	}
	else if(x.passmarks.value =="" || !x.passmarks.value.match(/^[0-9]{1,2}$/i))
	{
		alert("Invalid Pass Marks Score!");
	    setFocus(x.passmarks);
	}
	else if( (exceptional <= x.verygood.value) || (exceptional <= aboveaverage) || (exceptional <= average) || (exceptional <= belowaverage) )
	{
		alert("EXEPTIONAL Score should be greater than all of VERY GOOD,ABOVE AVERAGE,AVERAGE,BELOW AVERAGE scores!");
	    setFocus(x.exceptional);	
	}
	else if((x.verygood.value <= aboveaverage) || (x.verygood.value <= average) || (x.verygood.value <= belowaverage) )
	{
		alert("VERY GOOD Score should be greater than all of ABOVE AVERAGE,AVERAGE,BELOW AVERAGE scores!");
	    setFocus(x.verygood);	
	}
	else if( (aboveaverage <= average) || (x.verygood.value <= belowaverage) )
	{
		alert("ABOVE AVERAGE Score should be greater than both of AVERAGE and BELOW AVERAGE scores!");
	    setFocus(x.aboveaverage);	
	}
	else if( (average <= belowaverage) )
	{
		alert("AVERAGE Score should be greater than BELOW AVERAGE score!");
	    setFocus(x.average);	
	}
	else
	{
		x.submit();
	}
}
/*============================================================================*/
function check_student(access)
{
	x = document.forms[0];
	re1 = /^[^0-9]\w+$/;

	if( access == "admin" && x.username.value == "" )
	{
		alert("Empty User Name field not allowed.");
		setFocus(x.username);
	}
	else if( access == "admin" &&  x.username.value.length >50 ) 
	{
		alert("User Name can have maximum 50 characters.");
		setFocus(x.username);
	}
	/*else if( access == "admin" && !re1.test(x.username.value)) 
	{    
		if(x.username.value.charAt(0) >='0' && x.username.value.charAt(0) <='9')
			alert("User Name cannot start with a digit.");
		else
		   alert("User Name can have only Letters,digifts or underscore.");
		setFocus(x.username);
	}*/
	else if( access == "admin" &&  x.password.value == "" )
	{
	   alert("Empty Password field not allowed.");
	   setFocus(x.password);
	}
	else if( access == "admin" &&  x.password.value.length < 6 ) 
	{
	   alert("Password Should have at least 6 characters.");
	   setFocus(x.password);
	}
	else if(x.name.value =="") 
	{
	   alert("Empty Student's Name is not allowed.");
	   setFocus(x.name);
	}
	else if(x.email.value != "" && !x.email.value.match(/^([A-Z0-9_][A-Z0-9._%-]*@[A-Z0-9_][A-Z0-9._%-]*\.[A-Z]{2,4})$/i))
	{
		alert("Invalid Student's POC Email Address.");
	    setFocus(x.email);
	}
	else if(x.classno.value == "")
	{
		alert("Empty Class # is not allowed.");
	    setFocus(x.email);
	}
	/*else if(x.classno.value != "" && !checkClassNo(x))
	{
		alert('Class # field should be only Numeric comman separated!');
	    setFocus(x.classno);	
	}*/
	else
	{
		x.submit();
	}
}
function checkClassNo(x)
{
		x.classno.value = x.classno.value.replace(' ','');
		arr = x.classno.value.split(',');
		for(j=0; j < arr.length; j++)
		{
			if(!IsNumeric(arr[j]))
			{
				return false;
			}
		}
 		return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////
function check_union()
{
	//alert("In Check Union");
	x = document.forms[0];
	re1 = /^[^0-9]\w+$/;

	if(  x.username.value == "" )
	{
		alert("Empty User Name field not allowed.");
		setFocus(x.username);
	}
	else if( x.username.value.length >50 ) 
	{
		alert("User Name can have maximum 50 characters.");
		setFocus(x.username);
	}
	/*else if( !re1.test(x.username.value)) 
	{    
		if(x.username.value.charAt(0) >='0' && x.username.value.charAt(0) <='9')
			alert("User Name cannot start with a digit.");
		else
		   alert("User Name can have only Letters,digifts or underscore.");
		setFocus(x.username);
	}*/
	else if(x.password.value == "" )
	{
	   alert("Empty Password field not allowed.");
	   setFocus(x.password);
	}
	else if(x.password.value.length < 6 ) 
	{
	   alert("Password Should have at least 6 characters.");
	   setFocus(x.password);
	}
	else if(x.name.value =="") 
	{
	   alert("Empty Union's Name is not allowed.");
	   setFocus(x.name);
	}
	
	
	
	
	
	
	
	else if(x.cost_per_child.value =="") 
	{
	   alert("Empty Cost Per Child field is not allowed.");
	   setFocus(x.cost);
	}
	else if(!IsNumeric(x.cost_per_child.value))
	{
	   alert("Cost Per Child field is only numeric");
	   setFocus(x.cost);
	}

	else if(x.discount.value=="")
	{
		alert("Please enter discount value");
		setFocus(x.discount);
	}
	else if(!IsNumeric(x.discount.value))
	{
	   alert("Discount field is only numeric");
	   setFocus(x.cost);
	}
	else if((x.criteria[0].checked) || (x.criteria[1].checked))
	{
		x.submit();	
	}
	else
	{
		alert ("Please select a criteria first!");
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function check_parent_register()
{

	var user = change.username.value.toLowerCase();;
	var password = change.password.value;
	var name = change.name.value;
	var email = change.email.value;
	var unioncode=change.union_code.value;

	var err="";
	if( user == "" )
	{
		err += "Empty User Name field not allowed.\n";
	}
	else if( user.length >50 ) 
	{
		err += "User Name can have maximum 50 characters.\n";
	}
	/*else 
	{    
		re = /^[^0-9]\w+$/;
		if(!re.test(user)) 
		{
			if(user.charAt(0) >='0' && user.charAt(0) <='9')
				err += "User Name cannot start with a digit.\n";
			else
			    err += "User Name can have only Letters,digifts or underscore.\n";
		}
	}*/

	if( password == "" )
	{
		err += "Empty  Password field not allowed.\n";
	}
	else if( password.length < 6 ) {
		err += " Password Should have at least 6 characters.\n";
	}
		
  if( name == "" )
	{
		err += "Empty Name field not allowed.\n";
	}
	if( email == "" )
	{
		err += "Empty email field not allowed.\n";
	}
  	if(unioncode.length!=0 && unioncode.length!=8)
	{
		err += "Union code field is of 8 numbers.\n";
	}
	else if (unioncode.length==8){
		if(!IsNumeric(unioncode))
	{
		err += "Only nemric values are allowed in union code field.\n";
	}
	}
  
if( err != "" )
 {
	alert(err);
	return false;
 }
else
 {	
	return true;
 }
}
/////////////////////////////////////////////////////////////////////////////////////////////
function check_admin_preferences()
{

	var first = change.first.value.toLowerCase();;
	var second = change.second.value;
	var third = change.third.value;
	var fourth = change.fourth.value;	

	var err="";
	if( first == "" )
	{
		err += "Empty first child cost field not allowed.\n";
	}
	else if (!IsNumeric(first))
	{
		err += "Numeric values allowed in first field.\n";
	}
	
	if( second == "" )
	{
		err += "Empty  second child cost field not allowed.\n";
	}
	else if (!IsNumeric(second))
	{
		err += "Numeric values allowed in second field.\n";
	}
	
  	if( third == "" )
	{
		err += "Empty third child cost field not allowed.\n";
	}
	else if (!IsNumeric(third))
	{
		err += "Numeric values allowed in third field.\n";
	}

	if( fourth == "" )
	{
		err += "Empty fourth child cost field not allowed.\n";
	}
  	else if (!IsNumeric(fourth))
	{
		err += "Numeric values allowed in fourth field.\n";
	}

	

if( err != "" )
 {
	alert(err);
	return false;
 }
else
 {	
	return true;
 }
}
//////////////////////////////////////////////////////////////////////////////////////////////
function check_entry()
{

	//var first = change.first.value.toLowerCase();;
	//var second = change.second.value;
	//var third = change.third.value;
	//var fourth = change.fourth.value;	

	var err="";
	if( company == "" )
	{
		err += "Empty company field not allowed.\n";
	}
	
	if( address1 == "" )
	{
		err += "Empty  address field not allowed.\n";
	}
	
  	if( city == "" )
	{
		err += "Empty city field not allowed.\n";
	}

	if( zip == "" )
	{
		err += "Empty zip field not allowed.\n";
	}

		if( phone== "" )
	{
		err += "Empty phone not allowed.\n";
	}
	

if( err != "" )
 {
	alert(err);
	return false;
 }
else
 {	
	return true;
 }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////// CHANGES MADE ON AUGUST 30TH FOR ADMIN SECTION PRODUCTS/////////////////////////////////
function check_company(access)
{
	x = document.forms[0];
	re1 = /^[^0-9]\w+$/;

	if( access == "admin" && x.username.value == "" )
	{
		alert("Empty User Name field not allowed.");
		setFocus(x.username);
	}
	else if( access == "admin" &&  x.username.value.length >50 ) 
	{
		alert("User Name can have maximum 50 characters.");
		setFocus(x.username);
	}
	/*else if( access == "admin" && !re1.test(x.username.value)) 
	{    
		if(x.username.value.charAt(0) >='0' && x.username.value.charAt(0) <='9')
			alert("User Name cannot start with a digit.");
		else
		   alert("User Name can have only Letters,digifts or underscore.");
		setFocus(x.username);
	}*/
	else if( access == "admin" &&  x.password.value == "" )
	{
	   alert("Empty Password field not allowed.");
	   setFocus(x.password);
	}
	else if( access == "admin" &&  x.password.value.length < 6 ) 
	{
	   alert("Password Should have at least 6 characters.");
	   setFocus(x.password);
	}
	else if(x.name.value =="") 
	{
	   alert("Empty Company's Name is not allowed.");
	   setFocus(x.name);
	}
	else if(x.email.value != "" && !x.email.value.match(/^([A-Z0-9_][A-Z0-9._%-]*@[A-Z0-9_][A-Z0-9._%-]*\.[A-Z]{2,4})$/i))
	{
		alert("Invalid Company's POC Email Address.");
	    setFocus(x.email);
	}
	else if(x.address.value == "")
	{
		alert("Empty Address field is not allowed.");
	    setFocus(x.address);
	}
	else if(x.contact.value == "")
	{
		alert("Empty contact number field is not allowed.");
	    setFocus(x.contact);
	}
	else if(isNaN(x.contact.value))
	{
		alert("Contact no field must contain numeric digits.");
	    setFocus(x.contact);
	}
	
	else
	{
		x.submit();
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
function check_salesman(access)
{
	x = document.forms[0];
	re1 = /^[^0-9]\w+$/;

	if( access == "admin" && x.username.value == "" )
	{
		alert("Empty User Name field not allowed.");
		setFocus(x.username);
	}
	else if( access == "admin" &&  x.username.value.length >50 ) 
	{
		alert("User Name can have maximum 50 characters.");
		setFocus(x.username);
	}
	/*else if( access == "admin" && !re1.test(x.username.value)) 
	{    
		if(x.username.value.charAt(0) >='0' && x.username.value.charAt(0) <='9')
			alert("User Name cannot start with a digit.");
		else
		   alert("User Name can have only Letters,digifts or underscore.");
		setFocus(x.username);
	}*/
	else if( access == "admin" &&  x.password.value == "" )
	{
	   alert("Empty Password field not allowed.");
	   setFocus(x.password);
	}
	else if( access == "admin" &&  x.password.value.length < 6 ) 
	{
	   alert("Password Should have at least 6 characters.");
	   setFocus(x.password);
	}
	else if(x.name.value =="") 
	{
	   alert("Empty salesman's Name is not allowed.");
	   setFocus(x.name);
	}
	else if(x.email.value != "" && !x.email.value.match(/^([A-Z0-9_][A-Z0-9._%-]*@[A-Z0-9_][A-Z0-9._%-]*\.[A-Z]{2,4})$/i))
	{
		alert("Invalid salesman's POC Email Address.");
	    setFocus(x.email);
	}
	else if(x.address.value == "")
	{
		alert("Empty Address field is not allowed.");
	    setFocus(x.address);
	}
	else if(x.contact.value == "")
	{
		alert("Empty contact number field is not allowed.");
	    setFocus(x.contact);
	}
	else if(isNaN(x.contact.value))
	{
		alert("Contact no field must contain numeric digits.");
	    setFocus(x.contact);
	}
	
	else
	{
		x.submit();
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function check_parent(access)
{
	x = document.forms[0];
	re1 = /^[^0-9]\w+$/;

	if( access == "admin" && x.username.value == "" )
	{
		alert("Empty User Name field not allowed.");
		setFocus(x.username);
	}
	else if( access == "admin" &&  x.username.value.length >50 ) 
	{
		alert("User Name can have maximum 50 characters.");
		setFocus(x.username);
	}
	/*else if( access == "admin" && !re1.test(x.username.value)) 
	{    
		if(x.username.value.charAt(0) >='0' && x.username.value.charAt(0) <='9')
			alert("User Name cannot start with a digit.");
		else
		   alert("User Name can have only Letters,digifts or underscore.");
		setFocus(x.username);
	}*/
	else if( access == "admin" &&  x.password.value == "" )
	{
	   alert("Empty Password field not allowed.");
	   setFocus(x.password);
	}
	else if( access == "admin" &&  x.password.value.length < 6 ) 
	{
	   alert("Password Should have at least 6 characters.");
	   setFocus(x.password);
	}
	else if(x.firstname.value =="") 
	{
	   alert("Empty First Name is not allowed.");
	   setFocus(x.lastname);
	}
	else if(x.lastname.value =="") 
	{
	   alert("Empty Last Name is not allowed.");
	   setFocus(x.lastname);
	}
	/*else if(x.street.value =="") 
	{
	   alert("Empty Street Address is not allowed.");
	   setFocus(x.street);
	}
	else if(x.city.value =="") 
	{
	   alert("Empty city field is not allowed.");
	   setFocus(x.city);
	}
	else if(x.zipcode.value =="") 
	{
	   alert("Empty Zip Code field is not allowed.");
	   setFocus(x.zipcode);
	}*/
	else if(!x.email.value.match(/^([A-Z0-9_][A-Z0-9._%-]*@[A-Z0-9_][A-Z0-9._%-]*\.[A-Z]{2,4})$/i))
	{
		alert("Invalid Parent's Email Address.");
	    setFocus(x.email);
	}
	else
	{
		x.submit();
	}
}
