var GetElement;	
function GenerateGetElement()
{
	if (document.getElementById) return function(id) { return document.getElementById(id); }
	else if (document.all) return function(id) { return document.all[id]; }
	else if (document.layers) return function(id) { document.layers[id]; }
}
GetElement = GenerateGetElement();

function OpenWindow(type, arg)
{
    var win;
    switch(type)
    {
        case "VIEW":
            arg = new String(window.location);
            arg = arg.replace(/\/product-detail.aspx/i, "/view.aspx");
            win = window.open(arg, "ViewLarger","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=533,height=543,left=150,top=150,alwaysRaised=1");
            break;
        case "EAF":
            var url = "/shop/emailafriend.aspx?pk=" + arg;
            win = window.open(url, "EmailAFriend", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=500,height=225,left=150,top=150,alwaysRaised=1");
            break;
        case "EMPART":
            win = window.open("/shop/empart.aspx?returnUrl=" + arg, "Redirecting", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=260,height=220,left=150,top=150,alwaysRaised=1");
            break;
        case "SUPERCEDE":
            win = window.open("/shop/supercede.html", "Supercedure", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=260,height=300,left=150,top=150,alwaysRaised=1");
            break;
        case "SEARCH":
            win = window.open(arg, "CartSearch", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=260,height=305,left=150,top=150,alwaysRaised=1");
            break;
        case "SEARCH-HELP-ENGINE":
            win = window.open("/flash/help/model-search-engine.swf", "CartSearch", "toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,width=800,height=600,left=150,top=150,alwaysRaised=1");
            break;
        case "SEARCH-HELP-MURRAY":
            win = window.open("/flash/help/model-search-murray.swf", "CartSearch", "toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,width=800,height=600,left=150,top=150,alwaysRaised=1");
            break;
    }
    if(win) win.focus();
}


function OpenFlash(type, file, height, width)
{
    var win;
    switch(type)
    {
        case "FLASH":
            win = window.open("/shop/flashHolder.html?f=" + file + "&h=" + height + "&w=" + width, "flash_video", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=150,top=150,alwaysRaised=1,height=" + Math.floor(height * 1.1) + ",width=" + Math.floor(width * 1.1));
            break;
    }
    win.focus();
}

function GetQs()
{
    var objURL = new Object();

    // Use the String::replace method to iterate over each
    // name-value pair in the query string. Location.search
    // gives us the query string (if it exists).
    window.location.search.replace(
        new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),

        // For each matched query string pair, add that
        // pair to the URL struct using the pre-equals
        // value as the key.
        function( $0, $1, $2, $3 )
        {
            objURL[ $1 ] = $3;
        }
    );
    return objURL;
}

//"abc".contains("bc") returns true
//"abc".contains("cle") returns false
String.prototype.contains = function(arg)
{
    return this.indexOf(arg) >= 0;
}

function addClassName(el, className)
{
    if(!el.className.contains(className))
    {
        el.className += ' ' + className;
    }
}

function removeClassName(el, className)
{
    if(el.className.contains(className))
    {
        if(el.className.contains(' ' + className))
        {
            el.className = el.className.replace(' ' + className, '');
        }
        else if(el.className.contains(className + ' '))
        {
            el.className = el.className.replace(className + ' ', '');
        }
        else
        {
            el.className = el.className.replace(className, '');
        }
    }
}

function txtHelp(textbox, message)
{
    addClassName(textbox, 'ghostText');
    textbox.value = message;
    textbox.onclick = function()
    {
        if(this.value == message)
        {
            this.value = '';
            removeClassName(this, 'ghostText');
        }
    };
    textbox.onblur = function()
    {
        if(this.value == '')
        {
            addClassName(this, 'ghostText');
            this.value = message;
        }
    };
}