﻿/// <reference path="jquery-1.2.6-intellisense.js" />

Shadowbox.loadSkin('classic', '/includes/shadowbox/skin');
Shadowbox.loadLanguage('en', '/includes/shadowbox/lang');
Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], '/includes/shadowbox/player');

var options = {
    animSequence: "sync",
    initialHeight: 320,
    initialWidth: 320
};

$(document).ready(function () {

    Shadowbox.init(options); 
    
    
    if($.browser.msie){
    // IE Doesnt like fading PNG's
        $("#fancyright").mouseover(function() {
            $("select").hide();
            $("#CartContents").show();
        });

        $("#CartContents").hover(function() {
            $("#CartContents").stop().show();
        }, function() {
            $("select").show();
            $("#CartContents").hide();
        });



    }else{
        $("#fancyright").mouseover(function() {
            $("#CartContents").fadeIn("slow");
        });

        $("#CartContents").hover(function() {
            $("#CartContents").stop().show();
        }, function() {
            $("#CartContents").fadeOut("slow");
        });

    }    
    

    $("#level2Nav li,#level2Nav dt").mouseover(function(){
        $(this).addClass("over");
    }).bind("mouseout",function(){
        $(this).removeClass('over');
    });

    
});
   

// Used to set radiobutton in repeaters
function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;

}


function SetSearchInput(objInput) {
    if (objInput.value == 'Enter keyword(s)') {
        objInput.className = 'formInput inuse';
        objInput.value = '';
    }
}

function ReSetSearchInput(objInput) {
    if (objInput.value == '') {
        objInput.className = 'formInput';
        objInput.value = 'Enter keyword(s)';
    }
}

function PrintPage() {
    if (window.print()) {
        window.print();
    }
}



/* display the help rollover thing */
function DisplayHelp(objRow, helpText, leftOffset) {
    if (helpText != "") {
        var posArray = findPos(objRow);
        $("#helpText").css("left",posArray[0] - 200 - leftOffset + "px");
        $("#helpText").css("top", posArray[1] + 25 + "px");
        $("#helpMain").html(helpText);
        $("#helpText").show();
    }
}

function HideHelp(objRow, helpText) {
    $("#helpText").hide();
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}

/* 
Updates the quantity of items in the basket. 
Called from code behind ShopingBasket and ProductDetails controls.
*/
function SetBasketItems(count, basketTable) {
    if (count == "") count = 0;
    if ($(".litOrderItems")) {
        $(".litOrderItems").html(count);

        if (basketTable != "") {
            $(".cartInner").html(basketTable);
            $(".checkoutButton").show();
            showBasket();
        }
        else if ($(".checkoutButton")) {
            // hide the checkout button if nothing in the basket
            $(".cartInner").html("&#160;You have no items in your basket");
            $(".checkoutButton").hide();
        }
    }
}

function HideBasket() {
    if ($("CartContents")) {
        $("#CartContents").html('');
    }
    if ($("basketLink")) {
        $("#basketLink").html('');
    }
}

function showBasket() {


   if($.browser.msie){
        $("select").hide();    
        $("#CartContents").show();
        setTimeout(function() { $("#CartContents").hide(); $("select").show();}, 5000);
   }else{
        $("#CartContents").fadeIn("slow");
        setTimeout(function() { $("#CartContents").fadeOut("slow"); }, 5000);
   }


}

function hideBasket() {
    $("#CartContents").hide();
}


// Use to detect if cookie ar enabled
function OpenPrintOrderForm(url) {
    window.open(url, "PrintOrderForm", "", "");
}

function GetCookie() {
    var strName = "varCook";
    if (document.cookie.indexOf(strName) == -1) {
        return false;
    }
    else {
        cookieStart = document.cookie.indexOf(strName);
        cookieValStart = (document.cookie.indexOf("=", cookieStart) + 1);
        cookieValEnd = document.cookie.indexOf(";", cookieStart);
        if (cookieValEnd == -1) {
            cookieValEnd = document.cookie.length;
        }
        cookieValue = document.cookie.substring(cookieValStart, cookieValEnd);
    }
    if (cookieValue = "True") {
        return ("True");
    }
}

function SetCookie(name, value, expires, path, domain, secure) {
    var strDNS = GetDNS();
    document.cookie = name + "=" + escape(value) +
	        ((expires) ? ";expires=" + expires.toGMTString() + 1000 * 60 * 20 : "") +
        	((path) ? ";path=" + path : "") +
    //( (domain) ? ";domain=" + domain : "") +
        	((domain) ? ";domain=" + strDNS : "") +
	        ((secure) ? ";secure" : "");
    return true
}

function GetDNS() {
    cookieDomain = document.location.hostname;
}

function UpdateAddress(){
    var updateExp = /\update/;
    var otherExp = /\?/;
    var parentURL = parent.location.href;
    if(parentURL.search(updateExp) > 0){
        parent.location.reload();
    }else{
        if(parentURL.search(otherExp) > 0){
            parent.location.href = parent.location.href + "/update/success";
        }else{
            parent.location.href = parent.location.href + "/update/success";        
        }    
    }
}
