


var stateDiv="";
function GetPackageCategoryDetails(id,divID)
{
       stateDiv=divID;
        var URL="MainService.asmx/GetPackageCategoryDetails?tm="+new Date().getTime();
        var values= '{"_id":"'+id+'"}';
        AjaxCall(URL,values,ONS_GetPackageCategoryDetails);
    
}
function ONS_GetPackageCategoryDetails()
{


    if (xmlHttp.readyState == 4)
    {
	    if (xmlHttp.status == 200)
	    {
	        var data = eval('('+xmlHttp.responseText+')');
	        if(data.d != null)
            {           
                $get(stateDiv).innerHTML = data.d;   
              // stateDiv.innerHTML = data.d;   
              // document.getElementById(stateDiv).innerHTML = data.d;             
               
            }
	    }
    }
}
function $get(obj) { return document.getElementById(obj); }
function AjaxCall(URL,values,OnSuccessFunctionName)
{    
    xmlHttp = getXMLHTTPRequest();
    if(xmlHttp != null)
    {
        xmlHttp.onreadystatechange = OnSuccessFunctionName;
        xmlHttp.open("POST",URL,true);
        xmlHttp.setRequestHeader("Content-type", "application/json");
        xmlHttp.send(values); 
    }
}

var xmlHttp=null;
function getXMLHTTPRequest()
{
	var xRequest=null;
	if (window.XMLHttpRequest)
	{
		xRequest = new XMLHttpRequest();
	}
	else if (typeof ActiveXObject != "undefined")
	{
		xRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xRequest;
}

 var disDiv="";
function GetPackageDetails(id,divID,pid)
{
        disDiv=divID;
        var URL="MainService.asmx/GetPackageDetails?tm="+new Date().getTime();
        var values= '{"_id":"'+id+'","pid":"'+pid+'"}';
        AjaxCall(URL,values,ONS_GetPackageDetails);
    
}
function ONS_GetPackageDetails()
{
    if (xmlHttp.readyState == 4)
    {
	    if (xmlHttp.status == 200)
	    {
	        var data = eval('('+xmlHttp.responseText+')');
	        if(data.d != null)
            {
               $get(disDiv).innerHTML = data.d;           
               
            }
	    }
    }
}

//=========================================================================================

function SendQuickMessage()
  {
    
    var qvalid;
    qvalid = ValidateQPage();
    if(qvalid==true)
    { 
        var qname=document.getElementById("qname").value;
        var qmail=document.getElementById("qmail").value; 
        var qph=document.getElementById("qphone").value; 
         var qmessage=document.getElementById("qmessage").value; 
         xmlHttp=getXMLHTTPRequest();
    
         if(xmlHttp!=null)
            {  
                xmlHttp.onreadystatechange = ONS_SendQMessage;    
                var URL="MainService.asmx/SendQuickMessage?tm="+new Date().getTime();
                var values= '{"name":"'+qname+'","email":"'+qmail+'","phone":"'+qph+'","commnts":"'+qmessage+'"}';
                
                xmlHttp.open("POST",URL,true);
                xmlHttp.setRequestHeader ("Content-type", "application/json");
                xmlHttp.send(values);  
                return false;   
            }
    }          
    else{
             return false;
        }   
   return false;
  }
  
  function ONS_SendQMessage()
    {
    if(xmlHttp.readyState == 4)
    {
        if (xmlHttp.status == 200)
            {
                var data = eval('('+xmlHttp.responseText+')');
                if(data.d != null)
                {
                    alert(data.d);
                    document.getElementById("qname").value="";
                    document.getElementById("qmail").value="";                
                    document.getElementById("qmessage").value="";
                    document.getElementById("qphone").value="";                   
                    return false;  
                }
            }
     } 
}



function ValidateQPage()
{
        if (document.getElementById("qname").value == "" )
                {
                    alert("Please fill in the ' Name'." );
		            document.getElementById("qname").focus();
                    return false;		        
                } 
        if (document.getElementById("qmail").value.length== "" )
                 {
		             alert("Please Enter your Email ID")
		             document.getElementById("qmail").focus();
		             return false;	
	              }
	   if (echeck(document.getElementById("qmail").value)==false)
	              {
		                document.getElementById("qmail").value=""
		                document.getElementById("qmail").focus();
		               return false;		 
	              }	
	              if (document.getElementById("qphone").value.length== "") 
                 {
                     alert("Please enter Phone number.");
                    document.getElementById("qphone").focus();
                      valid = false;
		             return valid;
                  } 
      else if (chkNumeric(document.getElementById("qphone").value) == false) 
                  {
                      alert("Please check - non numeric value!");
                      document.getElementById("qphone").focus();
                      document.getElementById("qphone").value=""
                      valid = false;
		             return valid;
                  } 
	   if (document.getElementById("qmessage").value == "" )
                {
                    alert("Please fill in the ' Message'." );
		            document.getElementById("qmessage").focus();
                    return false;		        
                } 
	               return true;		
}
function chkNumeric(strString)  //  check for valid numeric strings	
 {
               var strValidChars = "0123456789.-";
               var strChar;
               var blnResult = true;

               if (strString.length == 0) return false;

               //  test strString consists of valid characters listed above
               for (i = 0; i < strString.length && blnResult == true; i++)
                  {
                  strChar = strString.charAt(i);
                  if (strValidChars.indexOf(strChar) == -1)
                     {
                     blnResult = false;
                     }
                  }
               return blnResult;
 }     
      
 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					
	}







