function swap_text(id, text, style, on_style)
{
    e = document.getElementById(id);
    e.className = on_style;
    if (e.value == '' || e.value == text) {
        e.value = '';
    };
    e.onblur = new Function("e = document.getElementById('"+id+"');if (e.value == '') {e.className = '"+style+"';e.value='"+text+"'}");
}

function hide_objects()
{
    els = document.getElementsByTagName('select');
    for (i in els) {
        if (els[i] && els[i].style) {
            els[i].style.visibility = "hidden";
        }
    }
}

function show_objects()
{
    els = document.getElementsByTagName('select');
    for (i in els) {
        if (els[i] && els[i].style) {
            els[i].style.visibility = "visible";
        }
    }
}

function trackLink(url, event) {
    urchinTracker(event);
    self.location = url;
}

function dollar_format(amount) {
    amount = parseFloat(amount);
    var sign = amount < 0 ? '-' : '';
    return sign + '$' + Math.abs(amount).toFixed(2);
}

function noDoubleClick(id,url, text)
{
    if (text == null) {
        text = "Processing, please wait...";
    }
    e = document.getElementById(id);
    e.innerHTML = "<span id=\""+id+"\">"+text+"</span>";
    //javascript redirect is required by ie.
    if(url)
        window.location = url;
    return true;
}

//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        oldonload();
        func();
        }
    }

}

function WinOpen(mypage, myname, w, h, winl, wint, scroll) {
    var wint = (screen.height - h) / 2;
    if (winl = 0 ){
        var winl = (screen.width - w) / 2 + winl;
    } else {
        var winl = (screen.width - w) / 2;
    }

    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl
       + ',scrollbars='+scroll+',resizable=no, horizontalscrollbar=no, screenX='
       +winl+',screenY='+wint+'';
    win = window.open(mypage, myname, winprops);
    if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus();
    }
}

// hides shopping shortcuts
function hideShoppingShortcuts(){
    var attributes = {
        height: { to: 0}
    };
    var anim = new YAHOO.util.Anim('shopping_shortcuts_content', attributes, 0.5, YAHOO.util.Easing.easeOut);
    anim.animate();
    document.getElementById('shopping_shortcuts_menu').innerHTML = "<a href='#' id='shopping_shortcuts_btn' onclick='showShoppingShortcuts();return false;'>" + "<img src='/images/shopping_shortcuts/show.jpg' id='shopping_shortcuts_btnimg' /></a>'";
}

// shows shopping shortcuts
function showShoppingShortcuts(){
    var attributes = {
        height: { to: 70}
    };
    var anim = new YAHOO.util.Anim('shopping_shortcuts_content', attributes, 0.5, YAHOO.util.Easing.easeOut);
    anim.animate();
    document.getElementById('shopping_shortcuts_menu').innerHTML = "<a href='#' id='shopping_shortcuts_btn' onclick='hideShoppingShortcuts();return false;'>" + "<img src='/images/shopping_shortcuts/hide.jpg' id='shopping_shortcuts_btnimg' /></a>'";
}

//for static top nav
function switchImage(id){
    if(id=='wishlist'){
        document.getElementById('wishlist').src="/images/layout/header/wishlist-on.gif";
    } else if(id=='gwof'){
        document.getElementById('gwof').src="/images/layout/header/gwof-on.jpg";
    } else if(id=='gcards'){
        document.getElementById('gcards').src="/images/layout/header/gift-cards-on.jpg";
    } else if(id=='bday'){
        document.getElementById('bday').src="/images/layout/header/monkey-on.jpg";
    } else{
        if(id=='limitedtoo'){
        document.getElementById(id).style.backgroundImage="url('/images/layout/wrapper/"+id+".gif')";
        } else{
        document.getElementById(id).style.backgroundImage="url('/images/layout/wrapper/"+id+".gif')";
        }
    }
}
function switchImageBack(id){
    if(id=='wishlist'){
        document.getElementById('wishlist').src="/images/layout/header/wishlist-off.gif";
    } else if(id=='gwof'){
        document.getElementById('gwof').src="/images/layout/header/gwof-off.jpg";
    } else if(id=='gcards'){
        document.getElementById('gcards').src="/images/layout/header/gift-cards-off.jpg";
    } else if(id=='bday'){
        document.getElementById('bday').src="/images/layout/header/monkey-off.jpg";
    } else{
        if(id=='limitedtoo'){
        document.getElementById(id).style.backgroundImage="url('/images/layout/wrapper/limitedtoo_default.gif')";
        } else{
        document.getElementById(id).style.backgroundImage="url('/images/layout/wrapper/blank.gif')";
        }
    }
}

function close_sl() {
    document.getElementById('sl_popup').style.display='none';
}

function open_sl() {
    document.getElementById('sl_popup').style.display='block';
}

//order tracking popup
var order_track_panel;
function loadOrderTrackPanel(){
    var width = 394;
    var height = 172;
    var x = (document.documentElement.clientWidth - width)/2;
    order_track_panel = new YAHOO.widget.Panel("order_track_base", {
        visible: false,
        y: 50,
        x: x,
        zIndex: 250,
        width: width+"px",
        height: height+"px",
        modal: false,
        close: false,
        draggable: false,
        underlay: "none"
    });
    order_track_panel.render(document.body);
}

function showTrackPanel() {
    order_track_panel.show();
    order_track_panel.cfg.setProperty("zIndex",50);
}

function trackInputFocus(input) {
    if(input.value == "enter your order number") input.value = "";
}

YAHOO.util.Event.onContentReady("order_track_base", loadOrderTrackPanel);

