﻿<!--

function getQueryString(param) {
    var queryParams = window.location.search.toQueryParams();
    return queryParams[param];
}

// Provides an array of form element ids that remove the name mangling associated with dot net.
function buildDotNetFormReference(formID) {
    if (!formID) { formID = 'aspnetForm'; }  
    var elements = $(formID).getElements();
    var form     = new Array();
    
    elements.each(function(element) {
        form[element.id.substr(element.id.indexOf("_ux") + 1, element.id.length)] = element.id;
    });
    
    return form;
}

// Specified the selected list item in a drop down list, based on the value.
// Returns if the selected index of the drop down list was updated.
function setSelectedValue(dropDownID, value) {
    for (var i = 0; i < $(dropDownID).options.length; i++) {
        if ($(dropDownID).options[i].text == value) {
            $(dropDownID).selectedIndex = i;
            return true;
        }
    }
    
    return false;
}

function setDotNetSelectedValue(dropDownID, value) {                  
    for (var i = 0; i < $(f[dropDownID]).options.length; i++) {
        if ($(f[dropDownID]).options[i].value == value) {
            $(f[dropDownID]).selectedIndex = i;
            return true;
        }
    }
    
    return false;
}

function getDotNetSelectedValue(dropDownID) {                  
    var dropdown = $(f[dropDownID]);
    if (dropdown) {
        return dropdown.options[dropdown.selectedIndex].value;
    } else {
        return false
    }    
}

// Used when a new element is displayed after being hidden on page render.
// If this is not done, netscape will not adjust the position of absolute elements to match the new height or width of a page.
function causeNetscapeRedraw() {
    if (navigator.userAgent.indexOf('Netscape') > -1) {
        $('container-main').hide();
        $('container-main').show();
    }
}

var $NET = function(id, formID) {
    if (!formID) { formID = 'aspnetForm'; }  
    var elements = $(formID).getElements();
    
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].id.endsWith(id)) {
             return elements[i];
        } 
    }
    
    return null;
}

var $FNET = function(id, formID) {
    return $F($NET(id, formID).id);
}

// Hides broken images from the user.
function hideBrokenImages() {
    $A(document.images).each(function(img) {
        if (!isImageLoaded(img)) {
            img.style.visibility = "hidden";
        }
    });
}


// Determines if an image has loaded correctly.
function isImageLoaded(img) {

    // During the onload event, IE correctly identifies any images that
    // weren't downloaded as not complete. Others should too. Gecko-based
    // browsers act like NS4 in that they report this incorrectly.
    if (!img.complete) {
        return false;
    }

    // However, they do have two very useful properties: naturalWidth and
    // naturalHeight. These give the true size of the image. If it failed
    // to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }

    // No other way of checking: assume it's ok.
    return true;
}

// Some browsers do not correctly adjust the position of absolute elements, this makes certain that 
// position is correct.
function adjustAbsolutePosition() {
    if (navigator.userAgent.indexOf('Netscape') > -1 || navigator.userAgent.indexOf('MSIE 6') > -1) {
		if ($('container-main') != null) {
			var elements = $A($('container-main').getElementsByTagName('DIV'));
	        
			for (var i = 0; i < elements.length; i++) {
				var element = elements[i];
	            
				if (element.style.position == "absolute") {
					element.style.position = "relative";
					element.style.position = "absolute";
				}
			}
		}
    }
}

// Due to NET using a single form for all forms, this makes certain the correct form is submitted
// by determining the form object that has focus and submitting the form by clicking the first button
// found after the user presses the enter key.
function submitFormByCorrectButton(e) {
    var caller = getEventCaller(e);
    
    if (getEventKeyCode(e) == 13 && caller.type.toLowerCase() != "textarea") {
        var elements    = $('aspnetForm').getElementsBySelector('SELECT', 'INPUT');
        var callerFound = false;
        
        for (var i = 0; i < elements.length; i++) {
            var element = elements[i];
            var type    = element.readAttribute("type");
        
            if (element.id == caller.id) { callerFound = true; }
            if (type)                    { type        = type.toLowerCase(); }
            
            if (callerFound && (type == "image" || type == "submit")) {
                buttonNotClicked = false;
                element.click();
                break;
            }
        }
        
        return false;
    }
    
    return true;
}

function getEventKeyCode(e) {
    if (window.event) {
        return e.keyCode;
    } else if (e.which) {
        return e.which;
    }
}

function getEventCaller(e) {
    if (window.event) {
        return e.srcElement;
    } else if (e.which) {
        return e.target;
    }
}

function getZeros(str, desiredLength) {
    var zeros = "";
    
    for (var i = str.length + 1; i <= desiredLength; i++) {
        zeros += "0";
    }
    
    return zeros;
}

function getWindowWidth() {
    var myWidth = 0;
           
    if (typeof( window.innerWidth ) == 'number') {
        myWidth  = window.innerWidth;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        myWidth  = document.documentElement.clientWidth;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        myWidth  = document.body.clientWidth;
    }
    
    return myWidth;
}

function getWindowHeight() {
    var myHeight = 0;
           
    if (typeof( window.innerWidth ) == 'number') {
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        myHeight = document.body.clientHeight;
    }
    
    return myHeight;
}

function getMousePosition(e) {
    var posx    = 0;
	var posy    = 0;	
	var content = new Array();

    if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY) {
		posx = e.clientX;
		posy = e.clientY;
		
		if (unavigator.userAgent.indexOf("MSIE") > -1) {
			posx += document.body.scrollLeft;
			posy += document.body.scrollTop;
	    }
    }
    
    content["x"] = posx;
    content["y"] = posy;
    
    return content;
}

function processCurrency(num) {
    num += "";

    if (num.indexOf(".") == -1) {
        num = num + ".00";
    } else {
        var preDecimal  = num.substring(0, num.indexOf("."));
        var postDecimal = num.substring(num.indexOf(".") + 1);
        postDecimal     = postDecimal + getZeros(postDecimal, 2);
    
        num = preDecimal + "." + postDecimal;
    }
    
    return "$" + CommaFormatted(num);
}

function CommaFormatted(amount)
{
	var delimiter = ","; 
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}

function onMouseOverButton(sender, mouseOverImage) {
    sender.originalImage = sender.src;
    sender.src = pathOffWebRoot + mouseOverImage;
}

function onMouseOutButton(sender) {
    sender.src = sender.originalImage;
}

function showTooltip(item, tooltipId, e) { 
    var pos = Position.cumulativeOffset(item);
    
    pos[0] += 14;
    pos[1] -= parseInt($(tooltipId).getHeight())+ 6;
    
    $(tooltipId).show();
    $(tooltipId).style.top  = pos[1] + "px";
    $(tooltipId).style.left = pos[0] + "px";
}

function hideTooltip(tooltipId, e) {
    $(tooltipId).hide();
}

var openCalendar = null;

function closeOpenCalendar() {
    if (openCalendar != null) {  
        openCalendar.hide();
    }
}

function adjustPositionOfCalendar(sender, args) {
    
    // If there is a calendar already open, close it.
    if (openCalendar != null) {
        if (openCalendar.get_id() != sender.get_id()) {
            openCalendar.hide();
        }
        
        openCalendar = null;
    }

    var calendar = $(sender.get_id() + "_popupDiv");
    var icon     = sender.get_button();
    
    var offset = Position.cumulativeOffset(icon);
    var y      = offset[1];
    var x      = offset[0] + parseInt(icon.width) + 2;

    calendar.style.top = y + "px";
    calendar.style.left = x + "px";
    
    openCalendar = sender;
}

function getDaysInDate(m, y) {
    if (m == 2) {
        return daysInFebruary(y);
    } else {
        return ((m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) ? 31 : 30);
    }
}

function daysInFebruary(year) {
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function submitForm(validationGroup) {
    if (!Page_ClientValidate(validationGroup)) {
		alert("One or more errors have occured. Please check your form and try again.");
		return false;
	}
	return true;
}

function fixPredictiveTextList(args) {
	var dropDownList = $(args._element.id + "AutoComplete_completionListElem");
	
	// Since MSIE 6 does not display anything over select boxes, the predictive text is unuseable, so hide it.
	if (navigator.userAgent.indexOf('MSIE 6') > -1) {
		dropDownList.hide();
	
	} else {
		var items = dropDownList.childElements();
		
		var i      = 1;
		var height = 0;
		
		items.each(function(item) {
			if (i % 2 == 0) { item.className = "even"; }
			
			if (item.innerHTML.trim() == "") {
				item.hide();
			} else {
				item.show();
				height += item.getHeight();
			}
			
			i = i + 1;
		});
		
		if (dropDownList.className.indexOf("booking-engine") > -1) {
			var offset = args._element.positionedOffset();
			var y      = offset[1];
			
			dropDownList.style.top = (y + 16) + "px";
		}
		
		dropDownList.style.height = height + "px";
	}
}

//-->