﻿
 function RelativePath()
{

    // Remove any frames
//    if (top.location != self.location) {
//      top.location = self.location;
//    }

    var url = self.location.href;
    url = url.toLowerCase();
    var path = '';
    
    // determine the server   
    var local = 'localhost/';
    var server = 'server/';
    var live  = 'bwduncanville.com/';

    
    if(url.lastIndexOf(local) > 1)
        path = "http://localhost/duncanville/";
    else if(url.lastIndexOf(server) > 1)
        path = "http://server/duncanville/";   
    else if(url.lastIndexOf(live) > 1)
        path = "http://www.bwduncanville.com/";

    
    return path;
}

function Get_Cookie( name ) {

    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) &&( name != document.cookie.substring( 0, name.length ) ) )
    {
    return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ";", len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}

function BookHotel(page){
  if(valueformat==0)
  {

        //getObj("selectHotelForm").target="_blank";
	  //  getObj("selectHotelForm").action="http://book.bestwestern.com/bestwestern/priceAvail.do?propertyCode=44607&disablenav=true&sob=P645";		
        if ( Get_Cookie( 'PPCCookies' ) )
        {
       
        //  getObj("selectHotelForm").action="http://book.bestwestern.com/bestwestern/priceAvail.do?propertyCode=44607&disablenav=true&sob=P2240";
        getObj("selectHotelForm").action="http://book.bestwestern.com/bestwestern/priceAvail.do?resumeSearch=true&propertyCode=44607&suppressSSLPopup=true&disablenav=true&sob=P2240";
        }
        else
        {
     
        //  getObj("selectHotelForm").action="http://book.bestwestern.com/bestwestern/priceAvail.do?propertyCode=44607&disablenav=true&sob=P645";	
        getObj("selectHotelForm").action="http://book.bestwestern.com/bestwestern/priceAvail.do?resumeSearch=true&propertyCode=44607&suppressSSLPopup=true&disablenav=true&sob=P645";		
          
        } 
	 
  }
  else
  {  
        var fmonth = getObj("arrivalMonthYear").value.substring(4,6);
        var tmonth = getObj("departureMonthYear").value.substring(4,6);
        if (fmonth.substring(0,1) == "0"){
            fmonth = fmonth.substring(1,2);
         }
        if (tmonth.substring(0,1) == "0"){
           tmonth = tmonth.substring(1,2);
         }
        iRet = window.open("http://www.choicehotels.ca/hotels/roomRates?hotel=CN181" +
        "&srp=" + getObj("srp").value + 
        "&minisrp=" + getObj("minisrp").value + 
        "&day=" + getObj("arrivalDay").value + 
        "&month=" + fmonth + 
        "&depart_day=" + getObj("departureDay").value + 
        "&depart_month=" + tmonth + 
        "&nadult=" + getObj("nadult").value + 
        "&nchild=" + getObj("nchild").value + 
        "&destination=Vancouver" );
  }

//  var pagename=page+"?Visitor=1"
//  window.parent.location.href=pagename;	
// 
 // return true;
 
  SendMail();
}

function BookHotel2(page){
  if(valueformat==0)
  {

        //getObj("selectHotelForm").target="_blank";
	    getObj("selectHotelForm").action="http://book.bestwestern.com/bestwestern/priceAvail.do?disablenav=true&suppressSSLPopup=true&propertyCode=44607&corpid=01455800";		 
	 
  }
  else
  {  
        var fmonth = getObj("arrivalMonthYear").value.substring(4,6);
        var tmonth = getObj("departureMonthYear").value.substring(4,6);
        if (fmonth.substring(0,1) == "0"){
            fmonth = fmonth.substring(1,2);
         }
        if (tmonth.substring(0,1) == "0"){
           tmonth = tmonth.substring(1,2);
         }
        iRet = window.open("http://www.choicehotels.ca/hotels/roomRates?hotel=CN181" +
        "&srp=" + getObj("srp").value + 
        "&minisrp=" + getObj("minisrp").value + 
        "&day=" + getObj("arrivalDay").value + 
        "&month=" + fmonth + 
        "&depart_day=" + getObj("departureDay").value + 
        "&depart_month=" + tmonth + 
        "&nadult=" + getObj("nadult").value + 
        "&nchild=" + getObj("nchild").value + 
        "&destination=Vancouver" );
  }

  var pagename=page+"?Visitor=1"
  window.parent.location.href=pagename;	
 
  return true;
}


	function Validate1()
	{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		
		if(getObj("Name").value=='')
		{
			alert("Please enter your name");
			getObj("RequiredFieldValidator1").style.visibility="hidden";
			getObj("RequiredFieldValidator3").style.visibility="visible";
			 getObj("Name").focus();
			return false;
		}
		
		if(getObj("FromEmail").value=='')
		{
			alert("Please enter your valid email address");
			getObj("RequiredFieldValidator3").style.visibility="hidden";
			getObj("RequiredFieldValidator1").style.visibility="visible";
			 getObj("FromEmail").focus();
			return false;
		}
		if (!filter.test(getObj("FromEmail").value))
		{
			alert("Please enter your valid email address");
			getObj("RequiredFieldValidator1").style.visibility="hidden";
			getObj("RegularExpressionValidator1").style.visibility="visible";
				 getObj("FromEmail").focus();
			return false;
		}

        if(getObj("ToEmail").value=='')
		{
			alert("Please enter a valid email address of the recipient");
			getObj("RequiredFieldValidator2").style.visibility="visible";
			 getObj("ToEmail").focus();
			return false;
		}
		
		if (!filter.test(getObj("ToEmail").value))
		{
			alert("Please enter a valid email address of the recipient");
			getObj("RegularExpressionValidator2").style.visibility="visible";
			 getObj("ToEmail").focus();
			return false;
		}
		
		if(getObj("Subject").value=='')
		{
			alert("Please enter a subject line for the email");
			getObj("RequiredFieldValidator4").style.visibility="visible";
			 getObj("Subject").focus();
			return false;
		}

     var ok = 0;
	  if(confirm('Your email has been sent!  Would you like to subscribe to our hotel e-newsletter to receive updates on specials happening in and around our hotel?'))
	  {
	        ok = 1
    	  //window.getObj("hidMail").value = 1;
	  }        
	 
	 window.getObj("hidMail").value = ok;
	  
		return true;
	}

	function Validate2()
	{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

		if(getObj("FromEmail").value=='')
		{
			alert("Please enter your valid email address");
			getObj("RequiredFieldValidator3").style.visibility="hidden";
			getObj("RequiredFieldValidator1").style.visibility="visible";
			getObj("FromEmail").focus();
			return false; 
		}
		if (!filter.test(getObj("FromEmail").value))
		{
			alert("Please enter your valid email address");
			getObj("RequiredFieldValidator1").style.visibility="hidden";
			getObj("RequiredFieldValidator3").style.visibility="hidden";
			getObj("RegularExpressionValidator1").style.visibility="visible";
			getObj("FromEmail").focus();
			return false;
		}

        window.getObj("hidMail").value = 1;
	    return true;
	}
	
	function ValSubscribe()
	{
	    
	    ValidatorEnable(getObj("RequiredFieldValidator3"), true);
	    ValidatorEnable(getObj("RequiredFieldValidator1"), true);
	    ValidatorEnable(getObj("RegularExpressionValidator1"), true);
	}
	
	function ValUnSubscribe()
	{
	    ValidatorEnable(getObj("RequiredFieldValidator3"), false);
	     ValidatorEnable(getObj("RequiredFieldValidator1"), true);
	    ValidatorEnable(getObj("RegularExpressionValidator1"), true);
	}
	
	
	
	  var XmlHttp;    
     //Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
     function CreateXmlHttp()
     {
           //netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");

	      //Creating object of XMLHTTP in IE
	      try
	      {
		    XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	      }
	      catch(e) 
	      {
		    try
		    {
			    XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		    } 
		    catch(oc)
		    {
		        XmlHttp = null;
		    }
	      }
	      //Creating object of XMLHTTP in Mozilla and Safari 
	      if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	      {
		    XmlHttp = new XMLHttpRequest();
	      }
      }
    
  
    
    function SendMail()
    {  
    	

              
        CreateXmlHttp();
       
            // If browser supports XMLHTTPRequest object
          if(XmlHttp)
          {  
	         //Setting the event handler for the response	  
	         XmlHttp.onreadystatechange = HandleResponseSendMail;  
             //Initializes the request object with GET (METHOD of posting), 
	         //Request URL and sets the request as asynchronous.
	       
	         
	         XmlHttp.open("POST",RelativePath()+ "BookAjax.aspx",  true); 
	         this.XmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')                		
	         //Sends the request to server	       
	         XmlHttp.setRequestHeader("Connection", "close");  
	         
	         XmlHttp.send("Book=yes");    
           }   
     }


    function HandleResponseSendMail()
   { 
	// To make sure receiving response data from server is completed	
	if(XmlHttp.readyState == 4)
	{	 // To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{		  // alert('Thank you for contacting Perimeter Reservations'); 
 	    }
		else
		{
//		  alert("There was a problem retrieving data from the server." );
		}
	 }
    }
   