﻿function CheckSearch() {
    if (window.event.keyCode == 13) {
        return searchProducts()
    }
}

function setFilter(FilterID, FilterValue) {
    var qURL = "";
    if (FilterValue != '') {
        if (location.href.indexOf("?") == "-1") {
            qURL = '?&f' + FilterID + '=' + FilterValue;
        }
        else {
            qURL = '&f' + FilterID + '=' + FilterValue;
        }
        location.href = location.href + qURL;
    }
}

function urlencode(str) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson

    var hexStr = function (dec) {
        return '%' + dec.toString(16).toUpperCase();
    };

    var ret = '',
            unreserved = /[\w.-]/;
    str = (str + '').toString();

    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            if (code === 32) {
                ret += '+';
            }
            else if (code < 128) {
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) {
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048 && code < 65536) {
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 65536) { // 4 bytes
                ret += hexStr((code >> 18) | 0xF0);
                ret += hexStr(((code >> 12) & 0x3F) | 0x80);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;

}

function ShowThumb(varThumb) {
    var Image1;
    var Image2;
    Image1 = document.getElementById("imgMain").src;
    Image2 = document.getElementById(varThumb.id).src.replace("_Small", "_Large");
    document.getElementById("imgMain").src = Image2;
    document.getElementById(varThumb.id).src = Image1.replace("_Large", "_Small");
}

function showhide(id) {
    if (document.getElementById) {
        obj = document.getElementById(id);
        if (obj.style.display == "none") {
            obj.style.display = "";
            document.getElementById("Arrow").src = '/userpages/images/buttons/Basket_ArrowUp.png';
        }
        else {
            obj.style.display = "none";
            document.getElementById("Arrow").src = '/userpages/images/buttons/Basket_Arrow.png';
        }
    }
}
function ValidateLogin() {
    alert("validation here");
}

function setShipping(varID) {
    self.location.href = "/basket/basket.aspx?ShippingID=" + varID;
}

function SetShippingWrapper(varID) {
try {
    document.getElementById("ShippingDisplayInfo_" + varID).style.display = "";
    document.getElementById("ShippingWrapper_" + varID).setAttribute("class", "ShippingWrapperBorder");
} catch(e)
{}
}

function popUp(URL, width, height, scroll) {
    var settings
    settings = "width=" + width + ",height=" + height + ",scrollbars=" + scroll + ",toolbar=no";
    popwin = window.open(URL, "FAFSPORT", settings);
    popwin.focus();
}

function ShowChangePasswords() {
    if (document.getElementById("ctl00_ContentPlaceHolder1_ChangePassword").checked == true) {
        document.getElementById("ChangePassword").style.display = 'block';
        document.getElementById("ChangePasswordC").style.display = 'block';
    } else {
        document.getElementById("ChangePassword").style.display = 'none';
        document.getElementById("ChangePasswordC").style.display = 'none';
    }
}

function ValidateEditMyDetails() {
    var sMsg = '';
    if (document.getElementById("ctl00_ContentPlaceHolder1_TitleEdit").value == '') { sMsg = sMsg + 'Please enter your title.\n'; }
    if (document.getElementById("ctl00_ContentPlaceHolder1_FirstName").value == '') { sMsg = sMsg + 'Please enter your first name.\n'; }
    if (document.getElementById("ctl00_ContentPlaceHolder1_Surname").value == '') { sMsg = sMsg + 'Please enter your surname.\n'; }
    if (document.getElementById("ctl00_ContentPlaceHolder1_Address1").value == '') { sMsg = sMsg + 'Please enter the first line of your address.\n'; }
    if (document.getElementById("ctl00_ContentPlaceHolder1_Town").value == '') { sMsg = sMsg + 'Please enter your town/city.\n'; }
    if (document.getElementById("ctl00_ContentPlaceHolder1_Postcode").value == '') { sMsg = sMsg + 'Please enter your postcode.\n'; }
    if (document.getElementById("ctl00_ContentPlaceHolder1_Email").value == '') { sMsg = sMsg + 'Please enter your email address.\n'; }
    if (document.getElementById("ctl00_ContentPlaceHolder1_Telephone").value == '') { sMsg = sMsg + 'Please enter your telephone number.\n'; }
    if (sMsg == '') { return true; } else { alert(sMsg); return false; }
}

function ShowOther() {
    if (document.getElementById("ctl00_ContentPlaceHolder1_TitleEdit").value == 'Other') {
        document.getElementById("OtherDescription").style.display = 'block';
    } else {
        document.getElementById("OtherDescription").style.display = 'none';
    }
}

function ShowIntrests() {
    if (document.getElementById("ctl00_ContentPlaceHolder1_CheckBox1").checked == true) {
        document.getElementById("Intrests").style.display = 'block';
    } else {
        document.getElementById("Intrests").style.display = 'none';
    }
}

function ValidateNewsletter() {
    var sMsg = '';
    if (document.getElementById("Email").value == '') { sMsg = sMsg + 'Please enter your Email.\n'; }
    if (isValidEmail(document.getElementById("Email").value) == false) { sMsg = sMsg + "Invalid email address\n"; }

    if (sMsg == '') { return true; } else { alert(sMsg); return false; }
}

function isValidEmail(str) {
    return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}

function searchProducts() {
    var URL;

    URL = "/productlist.aspx?searchstring=" + document.getElementById("SearchBox").value;
    location.href = URL;

    return false;
}
function searchBrands() {
    location.href = "/productlist.aspx?f2=" + document.getElementById("Brands").value;
    return false;
}

/****************left nav*****************/

function ShowLeftMenu(varID) {
    try {
        document.getElementById(varID).style.display = 'block';
    }
    catch (e) { }
}

function HideLeftMenu(varID) {
    try {
        document.getElementById(varID).style.display = 'none';
    }
    catch (e) { }
}

/*********PRODS PER PAGE**********/

function SetProdsPerPage(varValue) {
    var qURL = "";
    if (varValue != '') {
        if (location.href.indexOf("?") == "-1") {
            qURL = '?&PP' + varValue;
        }
        else {
            qURL = '?&PP' + varValue;
        }
        location.href = location.href + qURL;
    }
}

function RemoveQuery(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    var URL = "";
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0].toString().toLowerCase() != variable.toString().toLowerCase()) {
            URL = URL + '&' + pair[0] + '=' + pair[1];
        }
    }
    if (URL.toString().substring(0, 1) == '&') {
        URL = '?' + URL.toString().substring(1, URL.toString().length);
    }
    if (URL == "?=undefined") {URL = "";}
    return URL;
}


function SetSortBy(varSortValue) {
    var strPrefix = "?";
    var URL = RemoveQuery("SortBy");
    if (URL.substring(0, 1) == "?") { strPrefix = "&"; }
    location.href = document.location.href + URL + strPrefix + 'SortBy=' + varSortValue;
}

function RemoveFilter(filter) {
    var URL = String(document.location.href);
    var LastChar;
    var regex = new RegExp("\\?" + filter + "=[^&]*&?", "gi");

    URL = URL.replace(regex, '?');
    regex = new RegExp("\\&" + filter + "=[^&]*&?", "gi");
    URL = URL.replace(regex, '&');
    URL = URL.replace(/(\?|&)$/, '');
    regex = null;

    LastChar = URL.charAt(URL.length - 1);
    if (LastChar == "?") { URL = URL.slice(0, URL.length - 1); }

    location.href = URL;
}

function ViewAllProducts() {
    var strPrefix = "?";
    var URL = RemoveQuery("PP");
    var varValue = "96";
    if (URL.substring(0, 1) == "?") { strPrefix = "&"; }
    location.href = URL + strPrefix + 'PP=' + varValue;
}

/*************PERSONALIDATION****************/

function ShowPersonalisation(varID) {
    if (document.getElementById) {
        obj = document.getElementById(varID);
        if (obj.style.display == "none") {
            obj.style.display = "";
        }
        else {
            obj.style.display = "none";
        }
    } 
}

/* ************************************ QUICK SHOP ************************************* */
function moveOption(fromID, toID, idx) {
    if (isNaN(parseInt(idx))) {
        var i = document.getElementById(fromID).selectedIndex;
    }
    else {
        var i = idx;
    }

    var o = document.getElementById(fromID).options[i];
    var theOpt = new Option(o.text, o.value, false, false);
    document.getElementById(toID).options[document.getElementById(toID).options.length] = theOpt;
    document.getElementById(fromID).options[i] = null;
}

function GetDetails(RowCount) {
    var replacedfirst = false;
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            document.getElementById("ProductName_" + RowCount + "").innerHTML = document.getElementById("QuickOrderCheckProductName").value;
            document.getElementById("RRP_" + RowCount + "").innerHTML = document.getElementById("QuickOrderCheckProductRRP").value;
            document.getElementById("Price_" + RowCount + "").innerHTML = document.getElementById("QuickOrderCheckProductSelling").value;
            document.getElementById("Stock_" + RowCount + "").innerHTML = document.getElementById("QuickOrderCheckStockLevel").value;
            document.getElementById("cboQty_" + RowCount + "").disabled = false;

            document.getElementById("ColourID_" + RowCount + "").options.length = 0;
            AddOptions2(document.getElementById("ColourID_" + RowCount + ""), "Select Colour", "Select Colour");
            for (var x = document.getElementById("QuickOrderCheckProductColour").options.length - 1; x >= 0; x--) { moveOption("QuickOrderCheckProductColour", "ColourID_" + RowCount + "", x); }

            document.getElementById("ColourID_" + RowCount + "").disabled = false;

        }
    }
    xmlhttp.open("GET", "quickshoplookup.aspx?PID=" + document.getElementById("ProdCode_" + RowCount + "").value + "", true);
    xmlhttp.send();
}

function QuckShop_UpdateColour(RowCount, ColourID) {
        var replacedfirst = false;
        xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;

                document.getElementById("SizeID_" + RowCount + "").options.length = 0;
                AddOptions2(document.getElementById("SizeID_" + RowCount + ""), "Select Size", "Select Size");
                for (var x = document.getElementById("Stock_QuickOrderCheckProductSize").options.length - 1; x >= 0; x--) { moveOption("Stock_QuickOrderCheckProductSize", "SizeID_" + RowCount + "", x); }

                document.getElementById("SizeID_" + RowCount + "").disabled = false;
            }
        }
        if (ColourID != 'Select Colour') {
            xmlhttp.open("GET", "QuickShopLookupSize.aspx?PID=" + document.getElementById("ProdCode_" + RowCount + "").value + "&ColourID=" + ColourID + "", true);
            xmlhttp.send();
        } else {
            document.getElementById("SizeID_" + RowCount + "").options.length = 0;
            AddOptions2(document.getElementById("SizeID_" + RowCount + ""), "Select Size", "Select Size");
            document.getElementById("SizeID_" + RowCount + "").disabled = true;
        }
}

function QuckShop_UpdateStock(RowCount, SizeID) {
    var ColourID = document.getElementById("ColourID_" + RowCount + "").value;
    var replacedfirst = false;
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            document.getElementById("Price_" + RowCount + "").innerHTML = document.getElementById("UpdateStock_QuickOrderCheckProductSelling").value;
            document.getElementById("Stock_" + RowCount + "").innerHTML = document.getElementById("UpdateStock_QuickOrderCheckStockLevel").value;
            document.getElementById("StockID_" + RowCount + "").value = document.getElementById("UpdateStock_QuickOrderCheckStockID").value;
        }
    }
    xmlhttp.open("GET", "QuickShopLookupStock.aspx?PID=" + document.getElementById("ProdCode_" + RowCount + "").value + "&ColourID=" + ColourID + "&SizeID=" + SizeID + "", true);
    xmlhttp.send();
}

function AddOptions2(sel, text, value) {
    var opt = new Option(text, value);
    sel.options[sel.options.length] = opt;
}

function ValidateQuickShop(){
    var sMsg = '';
    var i = 1;
    for (i = 1; i <= 10; i++) {
        if (document.getElementById("StockID_" + i).value != "") {
            if (document.getElementById("ColourID_" + i + "").value == 'Select Colour') { sMsg = sMsg + 'Please select a colour for line ' + i + '.\n'; }
            if (document.getElementById("SizeID_" + i + "").value == 'Select Size') { sMsg = sMsg + 'Please select a size for line ' + i + '.\n'; }
            if (document.getElementById("cboQty_" + i + "").value == '') { sMsg = sMsg + 'Please enter a quantity for line ' + i + '.\n'; }
            if (document.getElementById("cboQty_" + i + "").value == '0') { sMsg = sMsg + 'Please enter a quantity for line ' + i + '.\n'; }
        }
    }
    if (sMsg == '') { return true; } else { alert(sMsg); return false; }
}

/* ************************************ PRODUCT REVIEW ************************************* */

function AddProductReview() {
    document.getElementById("ProductAddReview").style.display = "";
    window.location.hash = "Reviews";
}

function AjaxGetDataProductReview(url, responseHandler) {
    if (window.XMLHttpRequest) {        
        reqMail = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {          
        reqMail = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (reqMail) {
        reqMail.onreadystatechange = responseHandler;
        reqMail.open('get', url, true);
        reqMail.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
        reqMail.setRequestHeader("Cache-Control", "no-cache");
        reqMail.setRequestHeader("content-type", "application/x-www-form-urlencoded");
        reqMail.send('');
    }
    else { alert('Your browser does not seem to support XMLHttpRequest.'); }
}

function AjaxHandler_ProductReview() {
    try { 
        if (reqMail.readyState == 4 ||
            reqMail.readyState == 'complete') {
            document.getElementById('ProductReviewResponse').innerHTML = reqMail.responseText;
            document.getElementById('ProductReviewResponse').style.display = 'block';
            document.getElementById('ProductAddReview').style.display = 'none';
            alert("Thank you for submitting a product review.")
        }
    }
    catch (e) {
        alert('Error in Ajax respone:' + reqMail.readyState);
    }

}

function SubmitProductReview() {
    var Message = "";
    var Action = "";
    var Code = document.getElementById("ProductCode").value;
    var Name = document.getElementById("ProductReviewName").value;
    var Email = document.getElementById("ProductReviewEmail").value;
    var Rating = document.getElementById("ProductReviewRating").value;
    var Review = document.getElementById("ProductReview").value;

    if (Name == "") { Message = Message + "Please enter your Name\n"; }
    if (Rating == "" || Rating == "0") { Message = Message + "Please enter your Rating\n"; }
    if (Review == "") { Message = Message + "Please enter your Review\n"; }
    if (Message == "") { Action = "True"; } else { Action = "False"; }
    if (Action == "True") { AjaxGetDataProductReview("/productreviewsave.aspx?Code=" + Code + "&Name=" + Name + "&Rating=" + Rating + "&Email=" + Email + "&Review=" + Review, AjaxHandler_ProductReview); } else { alert(Message); }
}


/* ************************************ LEFT NAVIGATION ************************************* */

function CheckMailing() {
    if (window.event.keyCode == 13) {
        MailingConfirm()
    }
}

function AjaxGetDataMail(url, responseHandler) {
    if (window.XMLHttpRequest) {          
        reqMail = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {        
        reqMail = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (reqMail) {
        reqMail.onreadystatechange = responseHandler;
        reqMail.open('get', url, true);
        reqMail.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
        reqMail.setRequestHeader("Cache-Control", "no-cache");
        reqMail.setRequestHeader("content-type", "application/x-www-form-urlencoded");
        reqMail.send('');
    }
    else { alert('Your browser does not seem to support XMLHttpRequest.'); }
}

function AjaxHandler_Mailing() {
    try {
        if (reqMail.readyState == 4 ||
            reqMail.readyState == 'complete') {
            document.getElementById('MailingListResponse').innerHTML = reqMail.responseText;
            document.getElementById('MailingListResponse').style.display = 'block';
        }
    }
    catch (e) {
        alert('Error in Ajax respone:' + reqMail.readyState);
    }

}

function MailingConfirm() {
    var Message = "";
    var Action = "";
    var Email = document.getElementById("MailingList").value;

    if (Email == "") { Message = Message + "Please enter your Email Address\n"; }
    if (Message == "") { Action = "True"; } else { Action = "False"; }
    if (Action == "True") { AjaxGetDataMail("/userpages/MailingSave.aspx?Email=" + Email, AjaxHandler_Mailing); } else { alert(Message); }
}


/* ************************************ RIGHT NAVIGATION ************************************* */

function EmailaFriend() {
    AjaxGetData("/userpages/emailfriendsend.aspx", AjaxHandler_EmailFriend)
}
function EmailaFriendConfirm() {
    var Name = document.getElementById("ProductEmail_txtName").value;
    var Email = document.getElementById("ProductEmail_txtEmail").value;
    var FriendName = document.getElementById("ProductEmail_FriendtxtName").value;
    var FriendEmail = document.getElementById("ProductEmail_FriendtxtEmail").value;
    var Code = document.getElementById("ProductEmail_Code").value;
    var Action;
    var Message = "";

    if (Name == "") { Message = Message + "Please enter your Name\n"; }
    if (Email == "") { Message = Message + "Please enter your Email Address\n"; }
    if (FriendName == "") { Message = Message + "Please enter your Friends Name\n"; }
    if (FriendEmail == "") { Message = Message + "Please enter your Friends Email Address\n"; }

    if (Message == "") { Action = "True"; } else { Action = "False"; }

    if (Action == "True") { AjaxGetData("/userpages/emailfriendconfirm.aspx?Name=" + Name + "&Email=" + Email + "&FriendName=" + FriendName + "&FriendEmail=" + FriendEmail + "&ProductCode=" + Code + "", AjaxHandler); } else { alert(Message); }
}
function AjaxHandler_EmailFriend() {
    try {
        //readyState of 4 or 'complete' represents  
        //that data has been returned  
        if (req.readyState == 4 || req.readyState == 'complete') {
            EmailaFriendConfirm();
        }
    }
    catch (e) {
        alert('Error in Ajax respone:' + req.readyState);
    }
}
function EmailFriend() {
    document.getElementById("ProductDetail_EmailFriend").style.display = 'block';
}
function GetEmailFriend(ProductCode) {
    AjaxGetData("/userpages/emailfriend.aspx?Code=" + ProductCode + "", AjaxHandler);
}
function AjaxGetData_MiniBasket(url, MiniresponseHandler) {
    if (window.XMLHttpRequest) {
        // browser has native support for XMLHttpRequest object          
        Minireq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // try XMLHTTP ActiveX (Internet Explorer) version          
        Minireq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (Minireq) {
        Minireq.onreadystatechange = MiniresponseHandler;
        Minireq.open('get', url, true);
        Minireq.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
        Minireq.setRequestHeader("Cache-Control", "no-cache");
        Minireq.setRequestHeader("content-type", "application/x-www-form-urlencoded");
        Minireq.send('');
    }
    else { alert('Your browser does not seem to support XMLHttpRequest.'); }
}
function AjaxGetData(url, responseHandler) {
    if (window.XMLHttpRequest) {
        // browser has native support for XMLHttpRequest object          
        req = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // try XMLHTTP ActiveX (Internet Explorer) version          
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (req) {
        req.onreadystatechange = responseHandler;
        req.open('get', url, true);
        req.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
        req.setRequestHeader("Cache-Control", "no-cache");
        req.setRequestHeader("content-type", "application/x-www-form-urlencoded");
        req.send('');
    }
    else { alert('Your browser does not seem to support XMLHttpRequest.'); }
}
function AjaxHandler() {
    try {
        //readyState of 4 or 'complete' represents  
        //that data has been returned  
        if (req.readyState == 4 ||
            req.readyState == 'complete') {
            document.getElementById('EmailFriend').innerHTML = req.responseText;
        }
    }
    catch (e) {
        alert('Error in Ajax respone:' + req.readyState);
    }
}
function AjaxHandler_MiniBasket() {
    try {
        //readyState of 4 or 'complete' represents  
        //that data has been returned  
        if (Minireq.readyState == 4 ||
            Minireq.readyState == 'complete') {
            document.getElementById('MiniBasket').innerHTML = Minireq.responseText;
        }
    }
    catch (e) {
        alert('Error in Ajax respone:' + Minireq.readyState);
    }

}
function GetMiniBasket() {
    AjaxGetData_MiniBasket("/userpages/basketwebservice.aspx", AjaxHandler_MiniBasket);
}
function CloseEmailFriend() {
    document.getElementById("EmailFriend").style.display = "none";
}

function ShowThumb(varThumb) {
    var Image1;
    var Image2;
    var Image3;
    Image1 = document.getElementById("imgMain").src;
    Image2 = document.getElementById(varThumb.id).src.replace("_Small", "_Large");
    Image2 = Image2.replace("_small", "_large");
    document.getElementById("imgMain").src = Image2;
    Image3 = Image1.replace("_Large", "_Small");
    Image3 = Image3.replace("_large", "_small");
    document.getElementById(varThumb.id).src = Image3
}

/*===============================Filters*/
function ShowRemoveFilters(obj) {
    //loops through queryString and builds up links to remove each Filter if applied
    var queryString = unescape(location.search);
    var spanRF = document.getElementById("RemoveFilters"); //RemoveFilters <span>
    var f1, f2, f3, f4, f5, f6; //filter values
    var CatID = 0;
    var RemoveString = ''; //string that appears within <span>

    //if no querystring (homepage etc.) then exit
    if (!queryString) {
        return {};
    }

    //remove the ?
    queryString = queryString.substring(1);

    //split querystring into key/value pairs
    var pairs = queryString.split("&");

    //load the pairs into a collection to get selected Filter values
    for (var i = 0; i < pairs.length; i++) {
        //split into key/value pair by splitting on =
        var keyValuePair = pairs[i].split("=");

        //if Filter, then assign to var
        if (keyValuePair[0] == 'f1') { f1 = keyValuePair[1] }
        if (keyValuePair[0] == 'f2') { f2 = keyValuePair[1] }
        if (keyValuePair[0] == 'f3') { f3 = keyValuePair[1] }
        if (keyValuePair[0] == 'f4') { f4 = keyValuePair[1] }
        if (keyValuePair[0] == 'f5') { f5 = keyValuePair[1] }
        if (keyValuePair[0] == 'f6') { f6 = keyValuePair[1] }

        //if Category, then hide filters
        if (keyValuePair[0] == 'catid') {
            CatID = keyValuePair[1];
            //alert(CatID);
            HideFilters(CatID);
        }
    }

    //check if Filter exists and include a link to remove it
    if (f2 != null) { RemoveString += '<li><a href="javascript:RemoveFilter(\'f2\');">Manufacturer (' + f2 + ')</a></li>' } //Brand
    if (f3 != null) { RemoveString += '<li><a href="javascript:RemoveFilter(\'f3\');">Size (' + f3 + ')</a></li>' } //Refill
    if (f4 != null) { RemoveString += '<li><a href="javascript:RemoveFilter(\'f4\');">Colour (' + f4 + ')</a></li>' } //Range
    if (f5 != null) { RemoveString += '<li><a href="javascript:RemoveFilter(\'f5\');">Price</a></li>' } //Price

    //add a prefix to Remove Filters and <ul>, if applicable
    if (RemoveString != '') {
        RemoveString = '<div>Remove Filter: <a class="FilterRight" href="javascript:void(0)" onclick="ClearFilters()">clear all</a></div><ul>' + RemoveString + '</ul>';
    }
    try {
        //display RemoveFilter links
        spanRF.style.display = 'block';
        spanRF.innerHTML = RemoveString;
    } catch (err) { }
}

function ClearFilters() {
    var NewURL;
    NewURL = RemoveFilterNoRedirect(document.location.href, 'f1');
    NewURL = RemoveFilterNoRedirect(NewURL, 'f2');
    NewURL = RemoveFilterNoRedirect(NewURL, 'f3');
    NewURL = RemoveFilterNoRedirect(NewURL, 'f4');
    NewURL = RemoveFilterNoRedirect(NewURL, 'f5');
    location.href = NewURL
}

function RemoveFilterNoRedirect(URL, filter) {
    var URL = String(URL);
    var LastChar;
    var regex = new RegExp("\\?" + filter + "=[^&]*&?", "gi");

    URL = URL.replace(regex, '?');
    regex = new RegExp("\\&" + filter + "=[^&]*&?", "gi");
    URL = URL.replace(regex, '&');
    URL = URL.replace(/(\?|&)$/, '');
    regex = null;

    LastChar = URL.charAt(URL.length - 1);
    if (LastChar == "?") { URL = URL.slice(0, URL.length - 1); }

    return URL;
}



function GetAdditionalProducts(StockID) {
    var Qty = 1

    AjaxGetData("/basket/addmultipletobasket.aspx?StockID=" + StockID + '&Stock_Qty=' + Qty, AjaxHandler_AddToBasket);
    setTimeout('document.getElementById("ProductAdded").style.display = "block"', 2000);
}

function AjaxHandler_AddToBasket() {
    try {
        if (req.readyState == 4 || req.readyState == 'complete') {
            try {
            }
            catch (ex) { }
            GetMiniBasketTopNav2();
        }
    }
    catch (e) {
        alert('Error in Ajax respone:' + req.readyState);
    }

}

function GetAdditionalProducts1(StockID) {
    var Qty = 1
    var counter = 0;
    var i = 0;
    var url = '';
    var input_obj = document.getElementsByTagName('input');
    for (i = 0; i < input_obj.length; i++) {
        if (input_obj[i].type == 'checkbox' && input_obj[i].checked == true) {
            counter++;
            url = url + ', ' + input_obj[i].value;
        }
    }
    if (counter > 0) {
        // remove first '&' from the generated url string
        url = url.substr(1);
        // display final url string
        setTimeout(function () {
            window.location = '/basket/addmultipletobasket.aspx?StockID=' + StockID + '&Stock_Qty=' + Qty + '&AddProductID=' + url
        }, 0);
    } else {
        //FIREFOX DOES NOT LIKE &AMP;
        setTimeout(function () {
            window.location = '/basket/addmultipletobasket.aspx?StockID=' + StockID + '&Stock_Qty=' + Qty;
        }, 0);

    }

}


/* ************************************ TOP NAV MINIBASKET ************************************* */

function AjaxGetData_MiniBasketTopNav(url, MiniresponseHandler) {
    if (window.XMLHttpRequest) {
        // browser has native support for XMLHttpRequest object          
        Minireq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // try XMLHTTP ActiveX (Internet Explorer) version          
        Minireq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (Minireq) {
        Minireq.onreadystatechange = MiniresponseHandler;
        Minireq.open('get', url, true);
        Minireq.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
        Minireq.setRequestHeader("Cache-Control", "no-cache");
        Minireq.setRequestHeader("content-type", "application/x-www-form-urlencoded");
        Minireq.send('');
    }
    else { alert('Your browser does not seem to support XMLHttpRequest.'); }
}

function AjaxHandler_MiniBasketTopNav() {
    try {  
        if (Minireq.readyState == 4 ||
            Minireq.readyState == 'complete') {
            document.getElementById('MiniBasketTopNav').innerHTML = Minireq.responseText;
        }
    }
    catch (e) {
        alert('Error in Ajax respone:' + Minireq.readyState);
    }

}

function GetMiniBasketTopNav2() {
    AjaxGetData_MiniBasketTopNav("/userpages/basketwebservicetopnav.aspx", AjaxHandler_MiniBasketTopNav);
}

function GetMiniBasketTopNav() {
    AjaxGetData_MiniBasketTopNav("/userpages/basketwebservicetopnav.aspx", AjaxHandler_MiniBasketTopNav);
}
function popup(mylink, windowname) {
    if (!window.focus) return true;
    var href;
    if (typeof (mylink) == 'string')
        href = mylink;
    else
        href = mylink.href;
    window.open(href, windowname, 'width=980,height=700,scrollbars=yes');
    return false;
}
