﻿/*globals $,document,ActiveXObject,XMLHttpRequest*/

//PAGE SETUP
function pageSetup()
{
try
    {
    }
catch(err)
    {
        this.window.alert(err);
    }  
} 
    
//PAGE LOAD
$(document).ready(function() 
{
    try
    {
        pageSetup();
    }
    catch(err)
    {
        //Handle errors here
        this.window.alert(err);
    }
});


//LOAD JSON
function loadJSON(json,successUrl)
{
    var myObject = eval('(' + json + ')');
    if (myObject.status == "False")
    {
        this.window.alert(myObject.error);
    }
    else
    {
        document.location.href = successUrl; 
    }
}

//ALERT CONTENTS
function alertContents(httpRequest,successUrl) 
{
	//alert(httpRequest.readyState)
    if (httpRequest.readyState == 4) 
    {
        if (httpRequest.status == 200) 
            { loadJSON(httpRequest.responseText,successUrl); } 
        else 
            { this.window.alert(httpRequest.status + httpRequest.responseText + '\nThere was a problem with the handler request.');}
    }
}

//MAKE REQUEST     
function makeRequest(handlerUrl,successUrl)
{
    var httpRequest;
    if (this.window.XMLHttpRequest) 
    { // Mozilla, Safari, ...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) 
        {
            httpRequest.overrideMimeType('text/plain');
            // See note below about this line
        }
    } 
    else if (this.window.ActiveXObject) 
    { // IE
        try 
        {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (ex1) 
        {
            try 
            {
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (ex2) {}
        }
    }

    if (!httpRequest) 
    {
        this.window.alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    httpRequest.onreadystatechange = function() { alertContents(httpRequest,successUrl); };
    httpRequest.open('GET', handlerUrl, true);
    httpRequest.send('');
}
        
//CLEAR ALL 
function ClearAll(successUrl)
{
    //CLEAR CART BY RESETTING INVOICE ID
    var handlerUrl = "handlers/emptycart.ashx";
    makeRequest(handlerUrl,successUrl);
}

//CHECK AVAILABILTY
function checkAvailability(hotelId)
    {
    //CLEAR CART BY RESETTING INVOICE ID
    var strURL = "Availability.aspx?id=" + hotelId;
    document.location = strURL;  
    } 
function makeEnquiry(hotelId)
    {
    //CLEAR CART BY RESETTING INVOICE ID
    var strURL = "Enquiry.aspx?id=" + hotelId;
    document.location = strURL;  
    } 
function makeConferenceEnquiry(hotelId)
    {
    //CLEAR CART BY RESETTING INVOICE ID
    var strURL = "ConferenceEnquiry.aspx?id=" + hotelId;
    document.location = strURL;  
    } 

