// JavaScript Document
/*function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}*/


function checkEmail(ev) {
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return filter.test(ev)
}
/* -----------============   INSTANT CALL AJAX SERVICE   ===============------------------ */


	var cName, cPhone, cEmail, c4Serv, imProc, bCall;

// Get the HTTP Object
function getHTTPObject(){
   if (window.ActiveXObject) 
       return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
       return new XMLHttpRequest();
   else {
      alert("Your browser does not support AJAX.");
      return null;
   }
}

// Implement business logic    
function callInstantly(){    
    var shouldSend = true;
	cName = document.getElementById('CallerName');
    cPhone = document.getElementById('CallerPhone');
    cEmail = document.getElementById('CallerEmail');
    c4Serv = document.getElementById('Called4Service');
	imProc = document.getElementById('imgProcess');
	bCall = document.getElementById('btnCall');
	
	var vMes = "<h3>Your query couldn't be sent because:</h3><br/>";

        if (cName.value==''){
        shouldSend = false;
        vMes= vMes + "<li>Name is Empty!</li>";
    	} 
    	if (cEmail.value==''){
			shouldSend = false;
			vMes = vMes + "<li>Email Address not entered!</li>";
    	} else {
			if (checkEmail(cEmail.value) == false) {
				shouldSend=false;
				vMes = vMes + "<li>Email Address not valid!</li>";
			} 
        }
        if (cPhone.value==''){
        shouldSend = false;
        vMes= vMes + "<li>Contact is Empty!</li>";
    	}
		if (c4Serv.selectedIndex==0) {
        shouldSend=false;
        vMes = vMes + "<li>Service / Purpose not selected!</li>";
    	}
 

 		if (shouldSend) {
			bCall.style.display='none';
			imProc.style.display='';			
			httpObject = getHTTPObject();
			var cURL = "callInstantly.php?cName=" + cName.value + "&cEmail=" + cEmail.value  + "&cPhone=" + cPhone.value + "&c4Service=" + c4Serv.options[c4Serv.selectedIndex].value;
		   if (httpObject != null) {
				 httpObject.open("GET",cURL,true);
				httpObject.send(null); 
				httpObject.onreadystatechange = setOutput;
			}
		} else {
			$.prompt(vMes)
		}
}

function setOutput(){
    if(httpObject.readyState == 4){
//        document.getElementById('outputText').value 
//            = httpObject.responseText;
	$.prompt('<h3>Query Sent!</h3><br/>Thanks for your query,<br/><p> We will contact you very soon.</p>');
	cName.value ='';
	cEmail.value='';
	cPhone.value='';
	c4Serv.selectedIndex=0;
	bCall.style.display='';
	imProc.style.display='none';	
	}
}

/*   END OF INSTANT CALL    */
