﻿function BookHotel(){		
            var fmonth = getObj("arrivalMonthYear").value.substring(4,6);
            var fyear = getObj("arrivalMonthYear").value.substring(0,4);

            var tmonth = getObj("departureMonthYear").value.substring(4,6);
            var tyear = getObj("departureMonthYear").value.substring(0,4);
            if (fmonth.substring(0,1) == "0"){
            fmonth = fmonth.substring(1,2);
            }
            fmonth=parseFloat(fmonth)+1;

            if(fmonth<10)
            {
            fmonth="0"+fmonth;
            }

            if (tmonth.substring(0,1) == "0"){
            tmonth = tmonth.substring(1,2);
            }

		    tmonth=parseFloat(tmonth)+1;

            if(tmonth<10){
            tmonth="0"+tmonth;
            }

            hotelValue= getObj("nhotel").value;
		
            hotelValue= getObj("nhotel").value;

            if(hotelValue=="1")//Acclaim Hotel Calgary
            {
             getObj("hotel_dropdown1").style.border='solid 1px transparent';
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?hotelid=15468&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults="+getObj("nadult").value+"&children="+getObj("nchild").value+"&length="+getObj("txtNights").value+"&rooms="+getObj("nrooms").value);
            }
            else if(hotelValue=="2")
            {
             getObj("hotel_dropdown1").style.border='solid 1px transparent';
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?&HotelID=12457&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults="+getObj("nadult").value+"&children="+getObj("nchild").value+"&length="+getObj("txtNights").value+"&rooms="+getObj("nrooms").value);
            }

            else if(hotelValue=="3")
            {
             getObj("hotel_dropdown1").style.border='solid 1px transparent';
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?&HotelID=73125&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults="+getObj("nadult").value+"&children="+getObj("nchild").value+"&length="+getObj("txtNights").value+"&rooms="+getObj("nrooms").value);
            }
            else if(hotelValue=="4")
            {
             getObj("hotel_dropdown1").style.border='solid 1px transparent';
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?&HotelID=74385&languageid=1&&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults="+getObj("nadult").value+"&children="+getObj("nchild").value+"&length="+getObj("txtNights").value+"&rooms="+getObj("nrooms").value);
            }
            else
            {           
            getObj("hotel_dropdown1").style.border='solid 1px red';
            return false;
            }
			
			SendMail(hotelValue);
}


            function BookHotelRoom(hotelId)
			{
			

            var fmonth = getObj("arrivalMonthYear").value.substring(4,6);
            var fyear = getObj("arrivalMonthYear").value.substring(0,4);

            var tmonth = getObj("departureMonthYear").value.substring(4,6);
            var tyear = getObj("departureMonthYear").value.substring(0,4);
            if (fmonth.substring(0,1) == "0"){
            fmonth = fmonth.substring(1,2);
            }
            fmonth=parseFloat(fmonth)+1;

            if(fmonth<10)
            {
            fmonth="0"+fmonth;
            }


            if (tmonth.substring(0,1) == "0"){
            tmonth = tmonth.substring(1,2);
            }

            tmonth=parseFloat(tmonth)+1;

            if(tmonth<10)
            {
            tmonth="0"+tmonth;
            }

            hotelValue= hotelId;	


            if(hotelValue=="1")//Acclaim Hotel Calgary
            {
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?hotelid=15468&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults="+getObj("nadult").value+"&children="+getObj("nchild").value+"&length="+getObj("txtNights").value+"&rooms="+getObj("nrooms").value);
            }
            else if(hotelValue=="2")//Falcon Crest Lodge Canmore
            {
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?&HotelID=12457&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults="+getObj("nadult").value+"&children="+getObj("nchild").value+"&length="+getObj("txtNights").value+"&rooms="+getObj("nrooms").value);
            }

            else if(hotelValue=="3")//Copperstone Resort Canmore
            {
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?&HotelID=73125&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults="+getObj("nadult").value+"&children="+getObj("nchild").value+"&length="+getObj("txtNights").value+"&rooms="+getObj("nrooms").value);
            }
            else if(hotelValue=="4")//Stoneridge Resort Canmore
            {
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?&HotelID=74385&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults="+getObj("nadult").value+"&children="+getObj("nchild").value+"&length="+getObj("txtNights").value+"&rooms="+getObj("nrooms").value);
            }
            else
            {
            return false;
            }

			
			SendMail(hotelValue);
			
	}
	
	
	function BookHotelCustomPackages(hotelId)
	{
	   hotelValue= hotelId;	
	   
	       if(hotelValue=="2")//Falcon Crest Lodge Canmore
            {
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?hotelid=12457&ProdID=330447&killcookie=1&LanguageID=1");
            }

            else if(hotelValue=="3")//Copperstone Resort Canmore
            {
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?HotelID=73125&ProdID=330428&killcookie=1&LanguageID=1");
            }
            else if(hotelValue=="4")//Stoneridge Resort Canmore
            {
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?hotelid=74385&ProdID=330388&killcookie=1&LanguageID=1");
            }
             else
            {
            return false;
            }
            
            SendMail(hotelValue);
	
	}
	
	
	function BookHotelPromotion(hotelId,PromoID)
	{
	
	        var fmonth = getObj("arrivalMonthYear").value.substring(4,6);
            var fyear = getObj("arrivalMonthYear").value.substring(0,4);

            var tmonth = getObj("departureMonthYear").value.substring(4,6);
            var tyear = getObj("departureMonthYear").value.substring(0,4);
            if (fmonth.substring(0,1) == "0"){
            fmonth = fmonth.substring(1,2);
            }
            fmonth=parseFloat(fmonth)+1;

            if(fmonth<10)
            {
            fmonth="0"+fmonth;
            }

            if (tmonth.substring(0,1) == "0"){
            tmonth = tmonth.substring(1,2);
            }

		    tmonth=parseFloat(tmonth)+1;

            if(tmonth<10){
            tmonth="0"+tmonth;
            }

            hotelValue= getObj("nhotel").value;
		
            hotelValue= getObj("nhotel").value;

	
	
	   hotelValue= hotelId;	
	      if(hotelValue=="1")//Acclaim Hotel Calgary
            {
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?hotelid=15468&ProdID="+PromoID+"&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults=1&children=0&length=1&rooms=1");             
            }	   
	       else if(hotelValue=="2")//Falcon Crest Lodge Canmore
            {           
            iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?hotelid=12457&ProdID="+PromoID+"&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults=1&children=0&length=1&rooms=1");
            }

            else if(hotelValue=="3")//Copperstone Resort Canmore
            { 
             iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?hotelid=73125&ProdID="+PromoID+"&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults=1&children=0&length=1&rooms=1");
            }
            else if(hotelValue=="4")//Stoneridge Resort Canmore
            { 
           iRet = window.open("https://booking.ihotelier.com/istay/istay.jsp?hotelid=74385&ProdID="+PromoID+"&languageid=1&datein="+fmonth+"/"+getObj("arrivalDay").value +"/"+ fyear+"&adults=1&children=0&length=1&rooms=1");
            }
             else
            {
            return false;
            }
            
            SendMail(hotelValue);
	
	}





	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 RelativePathBook()
{

    // 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  = 'clique.ca/';

    
    if(url.lastIndexOf(local) > 1)
        path = "http://localhost/CliqueHotel/";
    else if(url.lastIndexOf(live) > 1)
        path = "http://www.clique.ca/";
    
    return path; 
    
  
}
	
	    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(hotelValue)
    {  
    	


              
        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",RelativePathBook()+ "BookAjax.aspx",  true); 
	         this.XmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')                		
	         //Sends the request to server	       
	         XmlHttp.setRequestHeader("Connection", "close");  
	         
	         XmlHttp.send("hotelValue="+hotelValue);    
           }   
     }


    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." );
		}
	 }
    }
