function popup(mylink, windowname)
{
	alert("hijcak ");
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=175,height=150,scrollbars=yes,left=80,top=50');
return false;
}
function rm_trim(inputString){
	if (typeof inputString != "string") { return inputString;}

	var temp_str = '';
	temp_str = inputString.replace(/[\s]+/g,"");
	if(temp_str == '')
		return "";
	
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " "){
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " "){
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1){
	  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
	}
	return retValue;
}

function isEmail(str){
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var ldot=str.indexOf(dot);
	var lstr=str.length;
	var extBody = str.split('.')

	if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}
	if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}
	if(str.indexOf(" ")!=-1){
		return false;
	}
	if(str.indexOf(at,(lat+1))!=-1){
		return false;
	}
	if(str.indexOf(dot,(lat+2))==-1){
		return false;
	}
	if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}
	if(extBody[1] == ''){
		return false;
	}
	return true;
}

function validPhone(theInput){
	  var theInput=theInput;
	  var theLength=theInput.length;
	  var goodphone=true;
	  //if(theLength !=11 && theLength != 0){ goodphone=false;}		  

	 // if(theLength==11){
		   for(var j=0;j<theLength;j++)
		   {
	    	  var theChar=theInput.substring(j,j+1);
		      if(theChar < "0" || theChar > "9"){goodphone=false;}
           }
	 // }
	  return goodphone;
	
}
function checkForInt(evt) {
var charCode = ( evt.which ) ? evt.which : event.keyCode;
//alert(charCode);
return( ( charCode >= 48 && charCode <= 57 ) || (charCode >= 65 && charCode <= 90) || ( charCode >=97 && charCode <=122) || charCode == 32 || charCode == 45);
}
function checkzero(thefield){
	var val=thefield.value
	if(isNaN( val) || val<=0){
		document.getElementById(thefield.name).value='';
		document.getElementById(thefield.name).focus();
		alert("Please enter valid amoutn.");
	}
}

function validName(theField)
{
	var theInput=theField.value;
	//alert("your nameggggg : "+theInput);
	var theLength=theInput.length;
	var goodname=true;
	
	if(theField.value==""){goodname=false;}
	if(theLength<3 && theLength!="0"){goodname=false;}
	 
	for(var j=0;j<theLength;j++)
	{
	  var theChar=theInput.substring(j,j+1);
	  var theChar2=theInput.substring(j+1,j+2);
		
 	  if((theChar < "a"  && theChar !=" ") && (theChar < "A" && theChar !=" ")){goodname=false;}

	  if((theChar > "z" && theChar !=" ") && (theChar > "z" && theChar !=" ")){goodname=false;}

	  if(theChar== " " && theChar2==" " ){goodname=false;}

	  if(theChar== " " && j<1){goodname=false;}
	
	  if(theChar== "^"){goodname=false;}
        
        }

	return goodname;
	/*if(goodname==false)
	{
	   alert("Invalid Name String"); 
	   return false;
	}*/
}

function checkRequiredRegister(theForm){

	var str  ="";
var theFields=new Array("register_for","institute_name","teacher_name","address","city","state","pincode","phone1","educational_qualification","class_teach","subject","teaching_experience","user_id","password","repassword","profile","logo");
var theCaption=new Array("Register For","Institute Name","Name","Address","City","State","Pincode","Phone1","Educational Qualification","Class Teach","Subject","Teaching Experience","E-Mail","Password","Re Password","Porfile PDF","Logo Image");

	for(var i=0;i<17;i++){

	var thevalue=document.getElementById(theFields[i]).value;
	//alert("update");
	thevalue=rm_trim(thevalue);
	if(thevalue=='' && i!=15 && i!=16){
		str 	+= "Please enter "+theCaption[i];
		alert(str);
		//document.getElementById("error_div").innerHTML=str;
		document.getElementById(theFields[i]).focus();
		return false;
	}
	if(i==15 && thevalue!=''){
		if(document.getElementById(theFields[i]).value.lastIndexOf(".pdf")==-1){
			str += "Please Select PDF file only for profile";
			alert(str);
			//document.getElementById("error_div").innerHTML=str;
			document.getElementById(theFields[i]).focus();
			return false;
		}
	}
	
	if(i==16 && thevalue!=''){
		if(document.getElementById(theFields[i]).value.lastIndexOf(".gif")==-1 && document.getElementById(theFields[i]).value.lastIndexOf(".jpg")==-1 && document.getElementById(theFields[i]).value.lastIndexOf(".png")==-1){
			str += "Please Select image file only for Logo";
			alert(str);
			//document.getElementById("error_div").innerHTML=str;
			document.getElementById(theFields[i]).focus();
			return false;
		}
	}
}
	if(theForm.password.value!=theForm.repassword.value){
		str 	= "Password Not Matched";
		alert(str);

		theForm.password.focus();
//		document.getElementById(theFields[i]).focus();
		return false;
	}
	var avlcheck=document.getElementById("email_div").innerHTML;
	if(avlcheck=="<b>Not Available</b>" || avlcheck=="<B>Not Available</B>"){
		str 	= "E-Mail Not Available";
		alert(str);
		document.getElementById("user_id").focus();
		return false;
	}
return true;	
}

//validate enquiry
function validateFeedback(){
var str="<img src='images/error_image.gif' border='0'>&nbsp;&nbsp;";
	var theFields=new Array("txtname","phone","email","message","scode");
	var theCaption=new Array("Name","Phone No.","E-Mail","Message","Security Code");
	var url="";
		for(var i=0;i<5;i++){
	
		var thevalue=document.getElementById(theFields[i]).value;
		//alert("update");
		thevalue=rm_trim(thevalue);
		url+="&"+theFields[i]+"="+thevalue;
		if(thevalue==''){
			str 	+= "Please enter "+theCaption[i];
			//alert(str);
			document.getElementById("error_div").innerHTML=str;
			document.getElementById(theFields[i]).focus();
			return false;
		}
		if(i==2){
			var goodemail=isEmail(thevalue);
			if(!goodemail){
				str 	+= "Please enter valid "+theCaption[i];
	//			alert(str);
				document.getElementById("error_div").innerHTML=str;
				document.getElementById(theFields[i]).focus();
				return false;
			}
		}
	}
	url="ajaxhandler.php?query=sendcontactus"+url;
	//alert(url);
	ajaxtHandler("contact_div","error_div","contactus",url)
	return true;	
}

//********* send enquiry
function validateSendEnquiry(){

var str="<img src='images/error_image.gif' border='0'>&nbsp;&nbsp;";
	var theFields=new Array("txt_name","txt_email","txt_City","sct_Country","txt_Phone","sct_InterestedIn","txta_Queries","scode_enquiry");
	var theCaption=new Array("Name","E-Mail","City","Country","Phone/Mobile","Your Interest","Queries","Security Code");
	var url="";
		for(var i=0;i<8;i++){
	
		var thevalue=document.getElementById(theFields[i]).value;
		//alert("update");
		thevalue=rm_trim(thevalue);
		url+="&"+theFields[i]+"="+thevalue;
		if(thevalue==''){
			str 	+= "Please enter "+theCaption[i];
			//alert(str);
			document.getElementById("error_div_enquiry").innerHTML=str;
			document.getElementById(theFields[i]).focus();
			return false;
		}
		if(i==1){
			var goodemail=isEmail(thevalue);
			if(!goodemail){
				str 	+= "Please enter valid "+theCaption[i];
	//			alert(str);
				document.getElementById("error_div_enquiry").innerHTML=str;
				document.getElementById(theFields[i]).focus();
				return false;
			}
		}
	}
	url="ajaxhandler.php?query=sendenquiry"+url;
	//alert(url);
	ajaxtHandler("enquiry_main_div","error_div_enquiry","sendenquiry",url)
	return true;	
}
//********* end send enquiry




//************************** Ajax Calling **************************
var global_main_divid="";
var global_title_divid="";
var global_what_to_do="";

function ajaxtHandler(main_divid,title_divid,what_to_do,urlToBeCalled){
	global_main_divid=main_divid;
	global_title_divid=title_divid;
	global_what_to_do=what_to_do;
	if(global_what_to_do=="contactus" || global_what_to_do=="sendenquiry")
		document.all(global_title_divid).innerHTML="Please Wait&nbsp;<img src='images/progressbar_dot.gif' border='0'>";
		
//	alert('urlToBeCalled : '+urlToBeCalled);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
			alert ('Your browser does not support AJAX!');
	    	return;
	 } 

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open('POST',urlToBeCalled,true);
	xmlHttp.send();
	//return SERVER_RESPONSE;
}
		    	
function stateChanged(){ 

   if(xmlHttp.readyState==4 || xmlHttp.readyState=='complete'){ 
   		alert(xmlHttp.responseText);	
   		var result=xmlHttp.responseText.split("||");

		if(global_what_to_do=="contactus" || global_what_to_do=="sendenquiry"){
			if(result[0]=="success"){
				document.all(global_main_divid).innerHTML="<img src='images/status_on.gif' border='0'>&nbsp;"+result[1];
			}
			else if(result[0]=="failure"){
				document.all(global_title_divid).innerHTML="<img src='images/error_icon.gif' border='0'>&nbsp;"+result[1];
			}
			else{
				alert("no response : "+result[0]);
			}
		}
   }		                	
}
			   
function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){
	   // Internet Explorer
	   try{
		xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
	   }
		catch (e){
		xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
	return xmlHttp;
 }
	//end ajax 
//************************** End Ajax Calling **********************