function StartingSpecialCharCheck(str)
{
nstart="@#$%^&*()+=-[]\\;,/{}|:<>._\"\'?! "
var sflag=0

if((nstart.indexOf(str.charAt(0)))!=-1)
sflag=1

return sflag

}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid email id")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email id")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid email id")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email id")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid email id")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email id")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email id")
		    return false
		 }

 		 return true					
	}
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 6;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
function alpha(e) {
     var k;
     document.all ? k = e.keyCode : k = e.which;
     return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k==32 || k==46 || k==16 || k==0);
}
function alpha1(e) {
     var k;
     document.all ? k = e.keyCode : k = e.which;
     return ((k > 64 && k < 91) || (k > 96 && k < 123) || k==32 || k == 8 || k==0);
}
function phone(e) {
     var k;
	 //alert(e.which);
     document.all ? k = e.keyCode : k = e.which;
     return ((k > 47 && k < 58)  || k==8 || k==0 || k==45);
}
function ValidateMe()
{
	var emailID=document.frm.email;
	//var class=document.frm.Class.value;
	var section=document.frm.section.value;
	var parentname=document.frm.parent_name.value;
	var studname=document.frm.student_name.value;
	var Phone=document.frm.contact;
	var message=document.frm.message.value;
	if(parentname=="")
	{
	alert("Please enter the parent's name");
			document.frm.parent_name.focus();
			return false;
	}
	if(parentname!="")
	{
	var flag=StartingSpecialCharCheck(parentname);
	if(flag==1)
	{
	alert("Name should start with an alphabet");
	document.frm.parent_name.focus();
	return false;
	}
	}
	if(dot(parentname))
	{
	alert("Please enter a valid name");
	document.frm.parent_name.focus();
	return false;
		}
if(studname=="")
	{
	alert("Please enter the student's name");
			document.frm.student_name.focus();
			return false;
	}
	if(studname!="")
	{
	var flag=StartingSpecialCharCheck(studname);
	if(flag==1)
	{
	alert("Name should start with an alphabet");
	document.frm.student_name.focus();
	return false;
	}
	}
	if(dot(studname))
	{
	alert("Please enter a valid name");
	document.frm.student_name.focus();
	return false;
		}
	var myindex=document.frm.Class.selectedIndex;
if (myindex==0) {
alert("Please select the class");
return false;
}
	/* if(class!="")
	{
	var flag=StartingSpecialCharCheck(class);
	if(flag==1)
	{
	alert("Name should start with an alphabets");
	document.frm.Class.focus();
	return false;
	}
	} */
	if(section=="")
	{
	alert("Please enter the section");
			document.frm.section.focus();
			return false;
	}
		
	if(section!="")
	{
	var flag=StartingSpecialCharCheck(section);
	if(flag==1)
	{
	alert("Name should start with an alphabet");
	document.frm.section.focus();
	return false;
	}
	}
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please enter your phone number")
		document.frm.contact.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Phone number must be atleast 6 digits long")
		document.frm.contact.select()
		document.frm.contact.focus()
		return false
	}
	
	 if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email id")
		emailID.focus()
		return false
	}
	/* if (echeck(emailID.value)==false){
		emailID.focus()
		emailID.select()
		return false
	}
	 */
	 if(!checkEmail(emailID.value))
 {
  alert("Please enter a valid email id");
  emailID.select()
		return false
    }
	
		if(message=="")
	{
	alert("Please enter the message");
			document.frm.message.focus();
			return false;
	}
	if(message!="")
	{
	var flag=StartingSpecialCharCheck(message);
	if(flag==1)
	{
	alert("Message should start with an alphabet");
	document.frm.message.focus();
	return false;
	}
	}

return true
}

function checkEmail(myForm) {
if (/^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/.test(myForm)){
return true
}

}
 function dot(str)
{
 var  a = str.lastIndexOf(".");
 if(a>1)
 {
  return true;
 }
 else
 {
  return false;
 }
}
