var hideTimer, fadeTimer;
var _appRoot = "";

function chkSearchValue(input) {
    if (input.value == input.defaultValue) { input.value = ''; }
    else if (input.value == '') { input.value = input.defaultValue; }
}

function searchHilite(btn, hilite) {
    btn.src = _appRoot + '/images/static/' + (hilite ? 'cmdGoOver.gif' : 'cmdGo.gif');
}

function onSearchSubmit(searchForm, evt) {    
    var f = searchForm.elements["q"];
    if (f.value == f.defaultValue) { cancelEvent(evt); return false; }    
}
function cancelEvent(e) {
    if (e.returnValue) { e.returnValue = false; e.cancelBubble = true; }
    if (e.preventDefault) { e.preventDefault(); e.stopPropagation(); }
}


// PREVENT ERROR MESSAGES
try { window.onerror = function() { return false; } } catch (e) { }


function youtube_popup(id, w, h) {
    if (w == null) { w = 560; }
    if (h == null) { h = 340; }
    
    var url = 'http://www.youtube.com/v/' + id + '&hl=en&fs=1';
    var html = '<embed src="' + url + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + w + '" height="' + h + '"></embed>';

    doHtmlPopup(html, w + 40, h + 70);
}

function flv_popup(url, w, h, mainWindowClass) {
    if (w == null) { w = 560; }
    if (h == null) { h = 340; }    
    
    var html = '<embed src="http://www.laerdal.com/script/flv_player/player_flv_maxi.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + w + '" height="' + h + '"'
             + ' FlashVars="flv=' + escape(url) + '&amp;autoplay=1&amp;margin=0&amp;videobgcolor=000000&amp;volume=75&amp;showstop=1&amp;showvolume=1&amp;showtime=1&amp;showfullscreen=1"></embed>';
                                    
    doHtmlPopup(html, w+40, h+70, mainWindowClass);
}



function doHtmlPopup(html, w, h, mainWindowClass) {
    if (!mainWindowClass) {
        mainWindowClass = 'cbMovieBox';
    }
    
    var fc = $("#popup_container1");
    if (fc.length == 0) {
        fc = $('<div id="popup_container1" style="display: none" />');        
        $(document.body).append(fc);
    }
    fc.html('<div id="popup_container2">' + html + '</div>');

    var args = { href: '#popup_container2', inline: true, open: true, mainWindowClass: mainWindowClass, opacity: 0.4 };    
    if (w) { args["width"] = w; }
    if (h) { args["height"] = h; }        
    
    $.fn.colorbox(args);
}

function openPopup(url, w, h, mainWindowClass) {
    var args = { href: url, iframe: true, open: true, opacity: 0.4, transition: 'none' };

    if (!mainWindowClass) { args['mainWindowClass'] = mainWindowClass; }
    if (w) { args["width"] = w; }
    if (h) { args["height"] = h; }

    $.fn.colorbox(args);
}

function slideshow3() {
    $("a[rel=SlideShow]:first").click();
}   
function setLanguage(lang) {
    window.location.href="?setLang=" + lang;
}

function closePopup() {
    $.fn.colorbox.close();
}

function addItemToCart2($qty,$btn,itemNo)
{ 
    $btn.hide();
    var $loadImg = $('<img src="' + _appRoot + '/images/static/ajax-loader.gif" />');
    $btn.after($loadImg);

    var handler1 = function(o) {
        $loadImg.remove();
        $btn.show();
        $("#cartPopup").html(o.ResponseHTML);
        var args = { href: '#cartPopup', inline: true, open: true, opacity: 0.3, height: 300, width: 500, transition: 'none' };
        $.fn.colorbox(args);
    }

    var args = { "method": "add", "partId": itemNo, "qty": parseInt($qty.val()), "source": "shop" };
    $.ajax({ url: _appRoot + "/Services/Cart.ashx", type: "POST", dataType: "json", data: args, success: handler1, error: handler1 });
}