
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;
}

//=========================================================================================

function SendQuickMessage()
  {    
    
     var qvalid = ValidateQPage();
    if(qvalid==true)
    { 
  
        var qname=$get("qname").value;        
        var qmail=$get("qmail").value; 
        var qph=$get("qphone").value; 
        var qcon=$get("qcountry").value; 
        var qcity=$get("qcity").value; 
         var qmessage=$get("qmessage").value; 
         var pid=$get("package").value; 
         xmlHttp=getXMLHTTPRequest();
    
         if(xmlHttp!=null)
            {  
                xmlHttp.onreadystatechange = ONS_SendQMessage;    
                var URL="MainService.asmx/SendEnquiryMessage?tm="+new Date().getTime();
                var values= '{"name":"'+qname+'","email":"'+qmail+'","phone":"'+qph+'","commnts":"'+qmessage+'","country":"'+qcon+'","city":"'+qcity+'","pid":"'+pid+'"}';
                
                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);
                    $get("qname").value="";
                    $get("qmail").value="";                
                    $get("qmessage").value="";
                    $get("qphone").value=""; 
                    $get("qcountry").value=""; 
                    $get("qcity").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					
	}

//==================================================
function SendMessage()
  {    
   
     var qvalid = ValidatePage();
    if(qvalid==true)
    { 
      var name= $get("name").value;
      var email= $get("email").value;
      var phone= $get("phone").value; 
      var address=$get("Address").value; 
      var arrival=$get("Arrival").value; 
      var departure=$get("Departure").value;  
      var duration=$get("Duration").value; 
      var adults=$get("Adults").value; 
      var comments=$get("comments").value;
         
         xmlHttp=getXMLHTTPRequest();
    
         if(xmlHttp!=null)
            {  
                xmlHttp.onreadystatechange = ONS_SendContactMessage;    
                var URL="MainService.asmx/SendContactMessage?tm="+new Date().getTime();
                var values= '{"name":"'+name+'","email":"'+email+'","phone":"'+phone+'","address":"'+address+'","arrival":"'+arrival+'","departure":"'+departure+'","duration":"'+duration+'","adults":"'+adults+'","comments":"'+comments+'"}';
                
                xmlHttp.open("POST",URL,true);
                xmlHttp.setRequestHeader ("Content-type", "application/json");
                xmlHttp.send(values);  
                return false;   
            }
    }          
    else{
             return false;
        }   
   return false;
  }
  
  function ONS_SendContactMessage()
    {
    if(xmlHttp.readyState == 4)
    {
        if (xmlHttp.status == 200)
            {
                var data = eval('('+xmlHttp.responseText+')');                
                if(data.d != null)
                {
                    alert(data.d);
                    $get("name").value="";
                    $get("email").value="";
                    $get("phone").value=""; 
                    $get("Address").value=""; 
                    $get("Arrival").value=""; 
                    $get("Departure").value="";  
                    $get("Duration").value=""; 
                    $get("Adults").value=""; 
                    $get("comments").value="";           
                    return false;  
                }
            }
     } 
}



function ValidatePage()
{
        if (document.getElementById("name").value == "" )
                {
                    alert("Please fill in the ' Name'." );
		            document.getElementById("name").focus();
                    return false;		        
                } 
        if (document.getElementById("email").value.length== "" )
                 {
		             alert("Please Enter your Email ID")
		             document.getElementById("email").focus();
		             return false;	
	              }
	   if (echeck(document.getElementById("email").value)==false)
	              {
		                document.getElementById("email").value=""
		                document.getElementById("email").focus();
		               return false;		 
	              }	
	              if (document.getElementById("phone").value.length== "") 
                 {
                     alert("Please enter Phone number.");
                    document.getElementById("phone").focus();
                      valid = false;
		             return valid;
                  } 
      else if (chkNumeric(document.getElementById("phone").value) == false) 
                  {
                      alert("Please check - non numeric value!");
                      document.getElementById("phone").focus();
                      document.getElementById("phone").value=""
                      valid = false;
		             return valid;
                  } 
	   if (document.getElementById("comments").value == "" )
                {
                    alert("Please fill in the ' Message'." );
		            document.getElementById("comments").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					
	}

//=======================================================================
    function GetIndexPagePackages()
    {
            var URL="MainService.asmx/GetIndexPagePackages?tm="+new Date().getTime();
            var values= '{"_id":"'+1+'"}';
            AjaxCall(URL,values,ONS_GetIndexPagePackages);
            return false;
        
    }
function ONS_GetIndexPagePackages()
{
    if(xmlHttp.readyState == 4)
    {
        if (xmlHttp.status == 200)
            {
                var data = eval('('+xmlHttp.responseText+')');                
                if(data.d != null)
                { 
                  // document.getElementById("packagesDiv").innerHTML=data.d.Package; 
                   document.getElementById("leftMenu").innerHTML=data.d.PackageList; 
                    return false;  
                }
            }
     } 
}

//===========================================================


function SendNewsLetter()
  {   
   
     var qvalid = ValidateSendNewsLetter();
    if(qvalid==true)
    { 
  
        var nname=$get("nname").value;        
        var nemail=$get("nemail").value;         
         xmlHttp=getXMLHTTPRequest();
    
         if(xmlHttp!=null)
            {  
                xmlHttp.onreadystatechange = ONS_SendNewsLetter;    
                var URL="MainService.asmx/SendNewsLetter?tm="+new Date().getTime();
                var values= '{"name":"'+nname+'","email":"'+nemail+'"}';
                
                xmlHttp.open("POST",URL,true);
                xmlHttp.setRequestHeader ("Content-type", "application/json");
                xmlHttp.send(values);  
                return false;   
            }
    }          
    else{
             return false;
        }   
   return false;
  }
  
  function ONS_SendNewsLetter()
    {
    if(xmlHttp.readyState == 4)
    {
        if (xmlHttp.status == 200)
            {
                var data = eval('('+xmlHttp.responseText+')');                
                if(data.d != null)
                {
                    alert(data.d);
                    $get("nname").value="";
                    $get("nemail").value="";               
                                
                    return false;  
                }
            }
     } 
}



function ValidateSendNewsLetter()
{
        if ((document.getElementById("nname").value == "Name" )&&(document.getElementById("nname").value == "" ))
                {
                    alert("Please fill in the ' Name'." );
		            document.getElementById("nname").focus();
                    return false;		        
                } 
        if (document.getElementById("nemail").value.length== "" )
                 {
		             alert("Please Enter your Email ID")
		             document.getElementById("nemail").focus();
		             return false;	
	              }
	   if (echeck(document.getElementById("nemail").value)==false)
	              {
		                document.getElementById("nemail").value=""
		                document.getElementById("nemail").focus();
		               return false;		 
	              }		    
	    return true;		
}


