function getElementName(sName)
{
	return MASTER_PAGE_PREFIX + sName;	
}

String.prototype.format = function()
{
    var str = this;
    for(var i=0, j = arguments.length; i < j; i++)
    {
        var re = new RegExp('\\{' + (i) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

function setClearInstructionalTextEvent(sBoxId, bIsDotNetControl)
{
    if (bIsDotNetControl)
    {
        sBoxId = getElementName(sBoxId);
    }
    
    $("#" + sBoxId).focus(
        function()
        {
            var oBox = $(this);
		        if (oBox.val() == oBox.attr("title"))
		        {
		            oBox.val("");
		        }
        }
    );
}

function clearDotNetControlInstructionalText(oBox)
{
    if (oBox.value == oBox.title)
    {
        oBox.value = "";
    }
}

function resetInstructionalTextEvent(sBoxId, bIsDotNetControl)
{
    if (bIsDotNetControl)
    {
        sBoxId = getElementName(sBoxId);
    }
    var oBox = $("#" + sBoxId);
    if (oBox.val() == "")
    {
        oBox.val(oBox.attr("title"));
    }
}

function showBg(oControl, sImageUrl) {
	if (oControl.value == '') { oControl.style.backgroundImage = URL_ROOT + sImageUrl; }
}
function hideBg(oControl) {
	oControl.style.backgroundImage = 'none';
}

/* Sidebar Accordion */
var Sidebar = {
	init: function()
	{
		$("div#book-a-flight h1").click(Sidebar.swapPanels);
	},
	
	swapPanels: function()
	{		
		Sidebar.doSwap(this.id);
	},
	
	doSwap: function(sId)
	{
		var sSpeed = "slow";
		var sHeadClass = "withBackground";
		
		if (sId == "bookAFlightHead")
		{
			$("div#quickQuoteBox").slideUp(sSpeed);
			$("div#bookAFlightBox").slideDown(sSpeed);
			$("#bookAFlightHead").removeClass(sHeadClass);
			$("#quickQuoteHead").addClass(sHeadClass);
		}
		
		if (sId == "quickQuoteHead")
		{
			$("div#bookAFlightBox").slideUp(sSpeed);
			$("div#quickQuoteBox").slideDown(sSpeed);
			$("#quickQuoteHead").removeClass(sHeadClass);
			$("#bookAFlightHead").addClass(sHeadClass);
		}
	}
};

$(document).ready(Sidebar.init);