﻿

// JScript File
 
function get_ExpediaUrl(hotelid) {
    var adults = $("div#bookingTab_" + hotelid + " #slAdults").val();
    var children = $("div#bookingTab_" + hotelid + " #slYoungsters").val();
    var seniors = $("div#bookingTab_" + hotelid + " #slSeniors").val();
    var departdate = $("#hiddepartDate").val();
    var Returndate = $("#HidReturnDate").val();
    var country = $("#HidCountry").val();
    var destination = $("#hidDestination").val();
    var Expediaid = $("#hidExpediaID_" + hotelid).val();
    var url = $("#hidUrlBase_" + hotelid).val() + '&OVRD=3&GOTO=PKGHOTDETAILS&PackageType=6'
        + "&FrAirport=" + country + "&DestID=" + destination + "&FromDate=" + departdate + "&ToDate=" + Returndate
        + "&NumAdult=" + adults + "&NumChild=" + children + "&NumSenior=" + seniors + "&HotelID=" + Expediaid + "&lid=TripPlanner";
        
    sc_trackEvent('Booking', 'PACKAGE', country, destination); // link-tracking via omniture
    window.open(url);
}

//Returns browser independant XMLHttp object
function GetXmlHttp()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		return new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
}

var canClear = true;
//Deletes on client side the content of a textbox
function ClearField(field) {
    if (canClear)
        field.value = "";
    canClear = false;
}

function MozillaLinkClick(plnkNode)
{
	// Emulate click on Mozilla
	var bolFollowLink = true;
	var strTarget = null;

	// Run the link onClick event.
	if (plnkNode.onclick)
	{
		if (plnkNode.onclick() == false)
		{
			bolFollowLink = false;
		}
	}
	// Get the link target.
	if (plnkNode.target)
	{
		strTarget = plnkNode.target;
	}    
	if (bolFollowLink)
	{
		if (strTarget == null)
		{
			// Open using the default target if not set on the link.
			window.open(plnkNode.href);
		} else {
			// Open using the link target.
			window.open(plnkNode.href, strTarget);
		}
	}
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

 function SearchWebControl(search)
 {
    var control = SearchWebControlGetID(search);
    if (control == null)
        return null;
    else
        return $get(control);
 }
 
 var WebControlSearchCache = new Array();
 function SearchWebControlGetID(search)
 {
    var retValue;

    if (WebControlSearchCache[search] == null)
    {
        if ($("#" + search)[0] != null)
        {
            retValue = $("#" + search)[0].id;
        }
        else
        {
            $( "div div, div div div p input, div a, div div p input, div#SearchGeneral p input" ).each(
                function(){
                    if ($(this)[0].id.toLowerCase().indexOf(search.toLowerCase()) >= 0 )
                        retValue = $(this)[0].id;
                }
            );
        }
        WebControlSearchCache[search] = retValue;
    }
    else
    {
        retValue = WebControlSearchCache[search];
    }
    
    return retValue;
 }

//**** Scripts used by the AjaxControlKit AnimationExtender. The Cover function controls the flow of the popup. ****//
// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
 bottom = SearchWebControl(bottom);
 top = SearchWebControl(top)
 if ((bottom == null) || (top == null))
 {
    alert("Webcontrol not found, specify the correct control id...");
    return;
 }
 var trigger = bottom;
 var location = Sys.UI.DomElement.getLocation(trigger);

 top.style.position = 'absolute';
 top.style.top = location.y + 'px';
 top.style.left = location.x + 'px';

 if (!ignoreSize) {
     top.style.height = bottom.offsetHeight + 'px';
     top.style.width = bottom.offsetWidth + 'px';
     }
 }
 
 //This function catches all enter keypresses for all input = "text" fields on a web form.
 //In this particular method you can specify the handler for each keypress.
document.onkeypress = function(e)
{
    var evt=(e)?e:(window.event)?window.event:null;
    if(evt)
    {
        var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0));
        if(key=="13")
        {
            x = e||window.event;
            t = x.target||x.srcElement;
            if ($(t).is('#txtAddressSearchInput'))
            {
                $("#btnAddressSearch").click();
                return false;
            }
            else if ( ($(t).is('#' + SearchWebControlGetID('txtEmail'))) || ($(t).is('#' + SearchWebControlGetID('txtPassword')))) 
            {
                $("#" + SearchWebControl("cmdSubmitCredentials").id).click();
                return false;
            }
        }
    }
}

function initializeRedirectCountdown(url) {
    setTimeout('performRedirect(\'' + url.replace('\'', '\\\'') + '\');', 5000);
}

function performRedirect(url) {
    window.location = url;
}    
