

  function controller()
  {
	  var name = document.getElementById('txt_name').value;
	  var designation = document.getElementById('txt_desgn').value;
	  var org = document.getElementById('txt_org').value;
	  var email_id = document.getElementById('txt_mail').value;
	  var phone = document.getElementById('txt_phone').value;
	  var city = document.getElementById('txt_city').value;
	  var state = document.getElementById('txt_state').value;
	  var pin = document.getElementById('txt_pincode').value;
	  var country = document.getElementById('cbx_country').value;
	  var description = document.getElementById('txt_desc').value; 
	
			  
 	/* validating Name */
	if(name == '')
	 {
	 alert("please enter Name");
	 document.getElementById('txt_name').focus();
	 return false;
	 }
	 
	 /* validating City */
	 else  if(city == '')
	 {
	 alert("please enter City");
	 document.getElementById('txt_city').focus();
	 return false;
	 }
	 /* validating State */
	 else  if(state == '')
	 {
	 alert("please enter State");
	 document.getElementById('txt_state').focus();
	 return false;
	 }
   	 
	 /*validating EmailId */
	 else  if(email_id == '')
	 {
	 alert("please enter emailID");
	 document.getElementById('txt_mail').focus();
	 return false;
	 }
	 else if (email_id.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
	 {
	 alert("please enter valid EmailId like name@apiicltd.com");
	 document.getElementById('txt_mail').focus();
	 return false;
	 }
	
	  /* validating Country */
   	 else if(country == '' || country == '-select-')
	 {
	 alert("please select Country");
	 document.getElementById('cbx_country').focus();
	 return false;
	 }
	  else if(description == '')
	 { 	alert('Please Provide your description in brief');
	 	document.getElementById('txt_desc').focus();
	 	return false;
	 } 
	 
	 else 
	 {
	    // alert("navig_fb: "+navig_fb+" content_fb: "+content_fb);
	  	document.contact_form.btnsubmit.disabled =true;
	    document.getElementById('ld_create').style.display='block'; 
	 	var action = "ContactFormAction?name="+name+"&designation="+designation+"&org="+org+"&email_id="+email_id
	 				+"&phone="+phone+"&city="+city+"&state="+state+"&pin="+pin+"&country="+country
	 				+"&description="+description+"&mode=save";
	 	
	 	ajaxFunction(action);
	 }
	
	
  }
  
 		
  function ajaxFunction(action)
   {
  		var xmlHttp;
		try
		  {
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp=new XMLHttpRequest();
		  }
		catch (e)
		  {
		  // Internet Explorer
		  try
		    {
		    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		    }
		  catch (e)
		    {
		    try
		      {
		      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		      }
		    catch (e)
		      {
		      alert("Your browser does not support AJAX!");
		      return false;
		      }
		    }
		  }
		  xmlHttp.onreadystatechange=function()
		    {
		    document.getElementById('err').innerHTML = 'Please wait, Operation in process...';
		    if(xmlHttp.readyState==4)
		      {
		      	document.getElementById('err').innerHTML = '';
		      	var resp = xmlHttp.responseText;
		      	document.contact_form.btnsubmit.disabled =false;
		      	document.getElementById("ld_create").style.display="none";
		      	
		      if(resp == 'null_value'){
		      
		      		document.getElementById('err').innerHTML = 'Operation Failed !! Please try again.';
		      		document.getElementById('err').style.color="red";
		       }
		      
		       else if(resp == 'add_success')
		      	{
		      		document.getElementById('err').innerHTML = 'Your details have been submitted to APIIC succesfully..! <br> Our people will contact you on your mail ID.';
		      		document.getElementById('err').style.color="Green";
      				document.getElementById('contact_form_div').style.display="none";
		      	}
		      	else if(resp=='add_failed')
		      	{
		      		document.getElementById('err').innerHTML = 'Operation Failed !! Please try again.';
		      		document.getElementById('err').style.color="red";
		      	}
		      }
		    }
		  xmlHttp.open("POST",action,true);
		  xmlHttp.send(null);
		  			
}
		 