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 for making ajaX request obj.
function emailValidator(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.match(emailExp)){
		return true;
	}else{
		return false;
	}
}
function checkForInt(evt) {
var charCode = ( evt.which ) ? evt.which : event.keyCode;
//alert(charCode);
return( charCode >= 48 && charCode <= 57 );
}
function enquiryValidation()
{
	var theFields=new Array("fname","email","mobile","email1","securitycode");
	var theCaption=new Array(" Name","Email","Phone No.","chat id","security Code");
	var queryString="";
	for(var i=0;i<5;i++)
	{
		var thevalue=document.getElementById(theFields[i]).value;
		thevalue=rm_trim(thevalue);
		if(thevalue==''){
			alert("Please Enter Your "+theCaption[i]);
			document.getElementById(theFields[i]).focus();
			return false;
		}
		else if(i==1 || i==3)
		{
			if(!emailValidator(thevalue))
			{
				alert("invalid email ");
				document.getElementById(theFields[i]).value="";
				document.getElementById(theFields[i]).focus();
				return false;
			}
		}
		
	}
	queryString+=getFormData('formid');
	//alert(queryString)
	//send query through ajax
	var ajaxRequest=getAjaxRequestObject();  // The variable that makes Ajax possible!
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4){
			var message= ajaxRequest.responseText.split("#@#");
			//alert(message);
			if(message[0]=="success"){
				alert(message[1]);
					clearFormData('formid');
			}
			else{
					alert(message[1]);
					//clearFormData('formid');
			}
		}
	}	
	queryString ="AjaxHandler.php?query=sendenquiry"+queryString+"&dt="+new Date().getTime();
	//alert(queryString)
	ajaxRequest.open("POST", queryString, true);
	ajaxRequest.send(null); 
	//***********/
	return false;
			 
 }
function getAjaxRequestObject()
{
	var ajaxRequest;
	try
	{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		
		return ajaxRequest;
		
	}
	catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			return ajaxRequest;
		}
		catch (e) 
		{
			try
			{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				return ajaxRequest;
			}
			catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
}
function getServerResponse(divid,url,abspath,prog){
	//alert(url);
	//document.getElementById(divid).style.display="block";
	//if(prog)
		//document.getElementById(divid).innerHTML = "<img src='images/loading.gif' border='0'>";
	
	var ajaxRequest=getAjaxRequestObject();  // The variable that makes Ajax possible!
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			var message=ajaxRequest.responseText;
			//alert(message);
			//prompt('ajax response ',message);
			document.getElementById(divid).innerHTML=message;
		}
	}
	var queryString =abspath+""+url+"&dt="+new Date().getTime();
	//alert(queryString);
	ajaxRequest.open("POST", queryString, true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Connection", "close");
	
	ajaxRequest.send(null); 
	//********
	
	return true;
}
function clearFormData(theForm)
{
   var inputtype=new Array("text","hidden","radio","checkbox","file","password");
   var urlData="";
   //checking select type
   if(document.getElementById(theForm).getElementsByTagName("select"))
   {
    	elements = document.getElementById(theForm).getElementsByTagName("select");
    	for(i=0;i<elements.length;i++){
     		elements.item(i).value="";
    	}
   }
   
   if(document.getElementById(theForm).getElementsByTagName("textarea"))
   {
   	 	elements = document.getElementById(theForm).getElementsByTagName("textarea");
    	for(i=0;i<elements.length;i++){
     		elements.item(i).value="";
    	}
   }
   for(var ti=0;ti<inputtype.length;ti++)
   {
    	elements = document.getElementById(theForm).getElementsByTagName("input");
        for(var i=0;i<elements.length;i++)
		{
     		if(elements.item(i).type == inputtype[ti])
			{
      			if (elements.item(i).type == "radio" || elements.item(i).type == "checkbox"){
       				if (elements.item(i).checked==true){ 
       				}
      			}
      		else if (elements.item(i).type == "hidden"){
     		}
       	}
      else{
		  if(elements.item(i).type !="button")
		       elements.item(i).value="";
      }
     }
    }
    
   }
function refreshCaptcha(abspath,divid){ 
document.getElementById(divid).src=abspath+"CaptchaSecurityImages.php?t=" + new Date().getTime(); 
}
function uploadres(){

   var theFields=new Array("postapplied","name","email","mobile","imagepath");
	var theCaption=new Array("Post","Name","Eamil","Mobile","Resume");

for(var i=0;i<5;i++){
	
		var thevalue=document.getElementById(theFields[i]).value;
		//alert(thevalue);
		thevalue=rm_trim(thevalue);
		
		if(thevalue==''){
			alert("Please enter "+theCaption[i]);
			document.getElementById(theFields[i]).focus();
			return false;
		}
		else if(i==2){
			if(!emailValidator(thevalue)){
				alert("invalid email ");
				document.getElementById(theFields[i]).focus();
				return false;
			}
		}
		if((i==4 )){
			if(document.getElementById(theFields[i]).value.lastIndexOf(".doc")==-1){
				alert("Please Select Valid  "+theCaption[i]+" (*.doc)");
				document.getElementById(theFields[i]).focus();
				return false;
			}
		}
	}
	return true;
			 
 }
function subValidation(id,divid,enqid)
{
	var theFields=new Array("sname","emailid","moblieid","messageid");
	var theCaption=new Array("Your Name","Your Email id","Mobile No.","Message");
	var mobile = "^[0-9]{7,15}$"; // for phone No. Validation
	var queryString="";
	for(var i=0;i<4;i++)
	{
		
		var thevalue=document.getElementById(theFields[i]).value;
		thevalue=rm_trim(thevalue);
		if(thevalue=='' || thevalue=="Name" || thevalue=="Email" || thevalue=="Mobile No." || thevalue=="Message.........")
		{
			alert("Please Enter  "+theCaption[i]);
			document.getElementById(theFields[i]).focus();
			return false;
		}
		else if(i==1)
		{
			if(!emailValidator(thevalue))
			{
				alert("Invalid  Email Id");
				document.getElementById(theFields[i]).focus();
				return false;
			}
			
		}
		else if(i==2)
		{
			if(!thevalue.match(mobile))
			{
				alert("Invalid  Phone No.");
				document.getElementById(theFields[i]).focus();
				return false;
			}
		}
		queryString+="&"+theFields[i]+"="+thevalue;
	}
	//document.getElementById(id).innerHTML="Sending Please Wait...";
	var ajaxRequest=getAjaxRequestObject();  // The variable that makes Ajax possible!
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var message= ajaxRequest.responseText.split("#@#");
			//alert(message);
			if(message[0]=="success"){
				if(divid==""){
					alert(message[1]);
					clearFormData('enqid');
				}
			}
			else{
				alert(message[1]);
				//clearFormData('enqid');
				}
			
		}
	}
	
	var queryString ="AjaxHandler.php?query=simpleenquiry"+queryString+"&dt="+new Date().getTime();
	//alert(queryString);
	ajaxRequest.open("POST", queryString, true);
	ajaxRequest.send(null); 
	//**********

	return false;
}
function onShow(id,showvalue)
{
	if(document.getElementById(id).value== "")
		document.getElementById(id).value = showvalue;
		//alert(showvalue);
}
function onhide(id,showvalue)
{
	//alert(document.getElementById(id).value);
	
	if(showvalue == "Name" || showvalue=="Email"  || showvalue=="Mobile No." || showvalue=="Message.........")
			document.getElementById(id).value = "";
	
}
function getFormData(theForm){
	//alert(theForm.name);
   var inputtype=new Array("text","hidden","radio","checkbox","file","password");
   var urlData="";
   //checking select type
  /* if(document.getElementById(theForm).getElementsByTagName("select"))
   {
    elements = document.getElementById(theForm).getElementsByTagName("select");
    for(i=0;i<elements.length;i++)
	{
     urlData+="&"+elements.item(i).name+"="+elements.item(i).value;
    }
   }*/
   
   if(document.getElementById(theForm).getElementsByTagName("textarea")){
    elements = document.getElementById(theForm).getElementsByTagName("textarea");
    for(i=0;i<elements.length;i++){
     urlData+="&"+elements.item(i).name+"="+escape(elements.item(i).value);
    }
   }
   
   for(var ti=0;ti<inputtype.length;ti++){
    elements = document.getElementById(theForm).getElementsByTagName("input");
    
    for(var i=0;i<elements.length;i++){
     if(elements.item(i).type == inputtype[ti]){
      if (elements.item(i).type == "radio" || elements.item(i).type == "checkbox"){
       if (elements.item(i).checked==true){ 
       urlData+="&"+elements.item(i).name+"="+elements.item(i).value;
       }
      }
      else if (elements.item(i).type == "hidden"){
     // alert("hidden : "+elements.item(i).name+" "+elements.item(i).value);
       if (elements.item(i).name!="basePathtxt" && elements.item(i).name!="claimbillpath" && elements.item(i).name!="finalUploadPath"){
       urlData+="&"+elements.item(i).name+"="+elements.item(i).value;
       }
      
      }
      else{
       urlData+="&"+elements.item(i).name+"="+elements.item(i).value;
      }
     }
    }
    
   }
    return(urlData);

  }
  function validate_enquiry(id,divid,formid){
	var theFields=new Array("name","mobile","emails","city","state","country","comment");
	var theCaption=new Array(" Name","Phone number.","Email","City","State","Country","Comment");
	var queryString="";
	for(var i=0;i<7;i++){
		var thevalue=document.getElementById(theFields[i]).value;
		thevalue=rm_trim(thevalue);
		if(thevalue==''){
			alert("Please Enter Your "+theCaption[i]);
			document.getElementById(theFields[i]).focus();
			return false;
		}
		else if(i==2){
			if(!emailValidator(thevalue)){
				alert("invalid email ");
				document.getElementById(theFields[i]).value="";
				document.getElementById(theFields[i]).focus();
				return false;
			}
		}
		queryString+="&"+theFields[i]+"="+thevalue;
	}
	//document.getElementById(id).innerHTML="Sending Please Wait...";
	//alert(queryString)
	//send query through ajax
	var ajaxRequest=getAjaxRequestObject();  // The variable that makes Ajax possible!
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var message= ajaxRequest.responseText.split("#@#");
			//alert(message);
			if(message[0]=="success"){
				if(divid==""){
					//document.getElementById(id).innerHTML=message[1];
					alert(message[1]);
					clearFormData('formid');
					}
			}
			else{
					alert(message[1]);
					//clearFormData('formid');
			}
			
		}
	}
	var queryString ="AjaxHandler.php?query=sendenquiry"+queryString+"&dt="+new Date().getTime();
	ajaxRequest.open("POST", queryString, true);
	ajaxRequest.send(null); 
	//**********
	return false;
			 
 }

