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 E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
function trimtext(lstring) 
{
     for (var i=0;i<=lstring.length;i++) 
	{
          if ((lstring.substring(i,i+1)>="a" && lstring.substring(i,i+1)<="z") || (lstring.substring(i,i+1)>="A" && lstring.substring(i,i+1)<="Z"))
			break;
     } 
	lstring = lstring.substring(i,lstring.length);
	return lstring;
}

	function valipmc(t) 
	{
		if (t.First_Name.value=="")
		{
			alert("Please specify First Name....");
			t.First_Name.focus();
			return false;
		}
		
		if (t.Last_Name.value=="")
		{
			alert("Please specify Last Name....");
			t.Last_Name.focus();
			return false;
		}
		
		if (!t.Gender[0].checked && !t.Gender[1].checked)
		{
			alert("Please specify Gender....");
			return false;
		}
		Itemd=t.dob_day.selectedIndex;
		Resultd=t.dob_day.options[Itemd].value;
		
		if (Resultd=="")
		{
			alert("Please specify Date of Birth....");
			t.dob_day.focus();
			return false;
		}
		
		Itemm=t.dob_month.selectedIndex;
		Resultm=t.dob_month.options[Itemm].value;
		if (Resultm=="")
		{
			alert("Please specify Month of Birth....");
			t.dob_month.focus();
			return false;
		}
		
		Itemy=t.dob_yr.selectedIndex;
		Resulty=t.dob_yr.options[Itemy].value;		
		if (Resulty=="")
		{
			alert("Please specify Year of Birth....");
			t.dob_yr.focus();
			return false;
		}

		if (t.Father_Husband_Name.value=="")
		{
			alert("Please specify Father/ Husband Name....");
			t.Father_Husband_Name.focus();
			return false;
		}
		
		if (t.Street.value=="")
		{
			alert("Please specify your Postal Address....");
			t.Street.focus();
			return false;
		}
		
		if (t.City.value=="")
		{
			alert("Please specify your City....");
			t.City.focus();
			return false;
		}
		if (t.State.value=="")
		{
			alert("Please specify your State....");
			t.State.focus();
			return false;
		}
		if (t.Country.value=="")
		{
			alert("Please specify your Country....");
			t.Country.focus();
			return false;
		}
		
		if (t.Residence_Phone.value=="")
		{
			alert("Please specify your Residence Phone Number....");
			t.Residence_Phone.focus();
			return false;
		}

		
	var emailID=t.Email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
		
		if (t.Education.value=="")
		{
			alert("Please specify your Education....");
			t.Education.focus();
			return false;
		}
		
		if (t.Profession.value=="")
		{
			alert("Please specify your Professional Details....");
			t.Profession.focus();
			return false;
		}

		if (t.Language.value=="")
		{
			alert("Please specify Languages known....");
			t.Language.focus();
			return false;
		}

		if (t.Past_Attend.value=="")
		{
			alert("Please specify details of your previous attendance of this Camp, type NA if attending first time....");
			t.Past_Attend.focus();
			return false;
		}
		if (t.Refer.value=="")
		{
			alert("How did you came to know about this International Preksha Meditation Camp....");
			t.Refer.focus();
			return false;
		}
		
		if (t.Special_Request.value=="")
		{
			alert("Please specify your Special Request if any, type None for no special requests....");
			t.Special_Request.focus();
			return false;
		}

		if (t.Objective.value=="")
		{
			alert("Please specify your Objectives in attending this Camp....");
			t.Objective.focus();
			return false;
		}
		t.submit();
		return true;
	}


	function valnewcamp(t) 
	{
		if (t.camptitle.value=="")
		{
			alert("Please specify Camp Title....");
			t.camptitle.focus();
			return false;
		}
		//if(chktextdate(t.campstartdate,"Please specify valid camp start date...")==0)
		//	return 0;
		//if(chktextdate(t.campenddate,"Please specify valid camp end date...")==0)
		///	return 0;
		if (t.campvenue.value=="")
		{
			alert("Please specify Camp Venue....");
			t.campvenue.focus();
			return false;
		}
		if (t.trainerdetails.value=="")
		{
			alert("Please specify Camp Trainer Information....");
			t.trainerdetails.focus();
			return false;
		}
		if (t.contactphones.value=="")
		{
			alert("Please specify Camp Key Contact Information....");
			t.contactphones.focus();
			return false;
		}
		if (t.strCAPTCHA.value=="")
		{
			alert("Please specify Registration Authorisation code shown above....");
			t.strCAPTCHA.focus();
			return false;
		}
		t.submit();
		return true;
	}	
	
	/* Function - ValPrekshaVahini
		Date added - 06th September 2010 */

	function valprekshavahini(t) 
	{
		if (chkblank(t.First_Name,"Please specify your First Name....")==0)
			return 0;
		if (chkblank(t.Last_Name,"Please specify your Last Name....")==0)
			return 0;
		
		if (!t.Gender[0].checked && !t.Gender[1].checked)
		{
			alert("Please specify Gender....");
			t.Gender[0].focus();
			return false;
		}

		if (chkblank(t.Father_Husband_Name,"Please specify your Father/ Husband Name....")==0)
			return 0;
		
		Itemd=t.dob_day.selectedIndex;
		Resultd=t.dob_day.options[Itemd].value;
		
		if (Resultd=="")
		{
			alert("Please specify Date of Birth....");
			t.dob_day.focus();
			return false;
		}
		
		Itemm=t.dob_month.selectedIndex;
		Resultm=t.dob_month.options[Itemm].value;
		if (Resultm=="")
		{
			alert("Please specify Month of Birth....");
			t.dob_month.focus();
			return false;
		}
		
		Itemy=t.dob_yr.selectedIndex;
		Resulty=t.dob_yr.options[Itemy].value;		
		if (Resulty=="")
		{
			alert("Please specify Year of Birth....");
			t.dob_yr.focus();
			return false;
		}

	if (chkselect(t.bloodgroup,"Please specify Blood Group...")==0)
		return 0;
	if (chkselect(t.maritalstatus,"Please specify marital status...")==0)
		return 0;
	if (chkselect(t.education,"Please specify educational qualification...")==0)
		return 0;
	if (chkselect(t.profession,"Please specify your profession...")==0)
		return 0;

		if (chkblank(t.Street,"Please specify your Permanent Address....")==0)
			return 0;
		if (chkblank(t.City,"Please specify your City....")==0)
			return 0;
		if (chkblank(t.State,"Please specify your State....")==0)
			return 0;
		if (chkblank(t.Country,"Please specify your Country....")==0)
			return 0;

		if(t.office_address.value!="")
		{
			if (chkblank(t.oCity,"Please specify office city...")==0)
				return 0;
			if (chkblank(t.oState,"Please specify office State...")==0)
				return 0;
			if (chkblank(t.oCountry,"Please specify office Country...")==0)
				return 0;
		}
		
		if (t.Residence_Phone.value=="" && t.Office_Phone.value=="" && t.mobile.value=="")
		{
			alert("Please specify your at least one contact number....");
			t.mobile.focus();
			return false;
		}

		
	var emailID=t.Email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.focus();
		return false;
	}
		
	if (chkblank(t.branchname,"Please specify Preksha Vahini Branch that you wish to Join...")==0)
		return 0;
	if (chkblank(t.totcamps,"Please specify number of Preksha Camps you have attended in past...")==0)
		return 0;
	if (chkblank(t.dailypreksha,"Please specify daily Preksha Meditation time you practice!...")==0)
		return 0;

		if (!t.magazine[0].checked && !t.magazine[1].checked)
		{
			alert("Please specify whether you get PrekshaDhyan Magazine regularly?");
			t.magazine[0].focus();
			return false;
		}

		t.submit();
		return true;
	}

	// check date input in text field
function chktextdate(datestring,msg)
{
	syscomp=1;
	dt=datestring.value;
	dd=dt.substring(0,2);
	mm=dt.substring(3,5);
	yy=dt.substring(6,10);

	// date length check
	tl=dt.length;
	if (tl<10)
	{
		alert("Please specify valid date in DD/MM/YYYY format");
		datestring.focus();
		return 0;
	}
	//mm part check
	if (mm<1 || mm>12)
	{
		alert("Please specify valid month...");
		datestring.focus();
		return 0;
	}
	//dd part check
	if (dd<1 || dd>31)
	{
		alert("Please specify valid day...");
		datestring.focus();
		return 0;
	}
	if((mm==4 || mm==6 || mm==9 || mm==11) && dd>30)
	{
		alert("Please specify valid day...");
		datestring.focus();
		return 0;
	}
	
	if (mm==2 && dd>29)
	{
		alert("Please specify valid day...");
		datestring.focus();
		return 0;
	}
	//yy check
	if(syscomp==1)
	{
		var mydate=new Date();
		if(dt<mydate)
		{
			alert("No back dated entries allowed...");
			datestring.focus();
			return 0;
		} 
	}
	else
		if(yy<1950 || yy>2050)
		{
			alert("Please specify valid year...");
			datestring.focus();
			return 0;
		}
	return 1;
}

function CheckNumber(input)
{
	var str = input.value;
	for (var i = 0; i < str.length; i++) 
	{
        	var ch = str.substring(i, i + 1)
	        if ((ch < "0" || "9" < ch) && ch != '.'  && ch!=",") 
			{
			input.value=0;
        	      	alert("Please Enter Numeric Value...");
			input.focus();
		        return false;
	    	}
	}
	return true;
}

//Blank textfield validation
function chkblank(t,msg)
{
	if (t.value=="")
	{
		alert(msg);
		t.focus();
		return 0;
	}
	return true;
}

//validation for selection list
function chkselect(t,msg)
{
	selno = t.selectedIndex; 
	
	selvalue = t.options[selno].value; 
	if (selvalue==0)
	{
		alert(msg);
		t.focus();
		return 0;
	}
	return true;
}

function chkradio(r,msg)
{
myOption = -1;
	
	for (i=r.length-1; i > -1; i--) {
	if (r[i].checked) {
		myOption = i; i = -1;
	}
	}
	if (myOption == -1) {
	alert(msg);
	return 0;
	}
}

//validation for phone/mobile
function phnocheck(input)
{
	var str = input.value;
	if (str!="")
	{
		for (var i = 0; i < str.length; i++) 
		{
        	var ch = str.substring(i, i + 1)
	        if (ch < "0" || "9" < ch) 
			{
			input.value=""
        	alert("Invalid Phone number...");
			input.focus();
		    return false;
	    	}
		}
	}
	return true;
}

function mobcheck(input)
{
	var str = input.value;
	if (str.length!=10)
	{
		alert("Invalid Phone number...");
		input.focus();
	    return false;
	}
	if (str.substring(1,0)!="9" && str.substring(1,0)!="8")
	{
		alert("Invalid Phone number...");
		input.focus();
	    return false;
	}
	for (var i = 0; i < str.length; i++) 
	{
        	var ch = str.substring(i, i + 1)
	        if (ch < "0" || "9" < ch) 
			{
			input.value=""
        	alert("Invalid Phone number...");
			input.focus();
		    return false;
	    	}
	}
	return true;
}

function chkseldate(dy,mth,yrs,msg)
{
	td=dy.selectedIndex;
	td=dy.options[td].value;
	if (td==0)
	{
		alert("Please specify date!");
		dy.focus();
		return 0;
	}
	tm=mth.selectedIndex;
	tm=mth.options[tm].value;
	if (tm==0)
	{
		alert("Please specify Month!");
		mth.focus();
		return 0;
	}
	ty=yrs.selectedIndex;
	ty=yrs.options[ty].value;
	if (ty==0)
	{
		alert("Please specify Year!");
		yrs.focus();
		return 0;
	}
	md=monthdays(tm,ty);
	if (td>md)
	{
		alert(msg);
		dy.focus();	
		return 0;
	}
	else
	
		return 1;
}

/* Function to validate New Meditation Trainer entry
	Date: 30th September 2011 */
	function valtrainer(t) 
	{
		if (t.fullname.value=="")
		{
			alert("Please specify your Full Name starting with first name....");
			t.fullname.focus();
			return false;
		}
		if (t.caddress.value=="")
		{
			alert("Please specify your Correspondence/ Communication Address....");
			t.caddress.focus();
			return false;
		}
		if (t.city.value=="")
		{
			alert("Please specify your Place/ City name....");
			t.city.focus();
			return false;
		}
		if (t.statename.value=="")
		{
			alert("Please specify your State/ Area name....");
			t.statename.focus();
			return false;
		}
		if (t.country.value=="")
		{
			alert("Please specify your Country name....");
			t.city.focus();
			return false;
		}
		if (t.contactphones.value=="")
		{
			alert("Please specify Camp Key Contact Information....");
			t.contactphones.focus();
			return false;
		}
		var emailID=t.contactemail;
		
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter your Email ID");
			emailID.focus();
			return false;
		}
		if (echeck(emailID.value)==false){
			emailID.value="";
			emailID.focus();
			return false;
		}

		Itemd=t.traininglevel.selectedIndex;
		Resultd=t.traininglevel.options[Itemd].value;
		
		if (Resultd=="-Select-")
		{
			alert("Please specify Preksha Meditation Training Level you have completed/ achieved.....");
			t.traininglevel.focus();
			return false;
		}
		if (t.languages.value=="")
		{
			alert("Please specify Languages you can use for Preksha Meditation Training ....");
			t.languages.focus();
			return false;
		}
		if (t.strCAPTCHA.value=="")
		{
			alert("Please specify Registration Authorisation code shown above....");
			t.strCAPTCHA.focus();
			return false;
		}
		t.submit();
		return true;
	}	

function verifysearch(t)
{
		Itemd=t.levelname.selectedIndex;
		Resultd=t.levelname.options[Itemd].text;
		
		if (Resultd=="---Specify---")
		{
			alert("Please specify Preksha Meditation Training Level you wish to search for.....");
			t.levelname.focus();
			return false;
		}
		if (t.textvalue.value=="")
		{
			alert("Please specify either desired City/ State/ Country/ Language you wish to search for - you may type first few characters for ease of search....");
			t.textvalue.focus();
			return false;
		}
		/*
		if (t.strCAPTCHA.value=="")
		{
			alert("Please specify Capture Code shown in left....");
			t.strCAPTCHA.focus();
			return false;
		}
	*/
		t.submit();
		return true;
}

	/* Jaipur Camp */
	function valjaipur(t) 
	{
		if (t.First_Name.value=="")
		{
			alert("Please specify your full Name....");
			t.First_Name.focus();
			return false;
		}
		
		if (!t.Gender[0].checked && !t.Gender[1].checked)
		{
			alert("Please specify Gender....");
			return false;
		}
		Itemd=t.dob_day.selectedIndex;
		Resultd=t.dob_day.options[Itemd].value;
		
		if (Resultd=="")
		{
			alert("Please specify Date of Birth....");
			t.dob_day.focus();
			return false;
		}
		
		Itemm=t.dob_month.selectedIndex;
		Resultm=t.dob_month.options[Itemm].value;
		if (Resultm=="")
		{
			alert("Please specify Month of Birth....");
			t.dob_month.focus();
			return false;
		}
		
		Itemy=t.dob_yr.selectedIndex;
		Resulty=t.dob_yr.options[Itemy].value;		
		if (Resulty=="")
		{
			alert("Please specify Year of Birth....");
			t.dob_yr.focus();
			return false;
		}

		if (t.paddress.value=="")
		{
			alert("Please specify your Correspondence Address....");
			t.paddress.focus();
			return false;
		}
		
		if (t.City.value=="")
		{
			alert("Please specify your City....");
			t.City.focus();
			return false;
		}
		if (t.Residence_Phone.value=="")
		{
			alert("Please specify your Mobile Phone Number....");
			t.Residence_Phone.focus();
			return false;
		}

		
	var emailID=t.Email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
		
		if (t.Refer.value=="")
		{
			alert("How did you came to know about this Preksha Meditation Camp....");
			t.Refer.focus();
			return false;
		}
		
		t.submit();
		return true;
	}

