﻿

function QS() {
    this.qs = {};
    var s = location.search.replace(/^\?|#.*$/g, '');
    if (s) {
        var qsParts = s.split('&');
        var i, nv;
        for (i = 0; i < qsParts.length; i++) {
            nv = qsParts[i].split('=');
            this.qs[nv[0]] = nv[1];
        }
    }
}
QS.prototype.add = function(name, value) {
    if (arguments.length == 1 && arguments[0].constructor == Object) {
        this.addMany(arguments[0]);
        return;
    }
    this.qs[name] = value;
}
QS.prototype.addMany = function(newValues) {
    for (nv in newValues) {
        this.qs[nv] = newValues[nv];
    }
}
QS.prototype.remove = function(name) {
    if (arguments.length == 1 && arguments[0].constructor == Array) {
        this.removeMany(arguments[0]);
        return;
    }
    delete this.qs[name];
}
QS.prototype.replace = function(name, value) {
    this.remove(name);
    this.add(name, value);
    return;
}
QS.prototype.removeMany = function(deleteNames) {
    var i;
    for (i = 0; i < deleteNames.length; i++) {
        delete this.qs[deleteNames[i]];
    }
}
QS.prototype.getQueryString = function() {
    var nv, q = [];
    for (nv in this.qs) {
        q[q.length] = nv + '=' + this.qs[nv];
    }
    return q.join('&');
}
QS.prototype.toString = QS.prototype.getQueryString





function ShowProductDetails(page, categoryID, productID) {
    var qy = new QS();
    var vx = '';

    if (qy.qs['vx'] && qy.qs['vx'] != '') {
        vx = qy.qs['vx'];
    }

    var frmEle = eval("document.shopcart");
    window.location.href = page + '.aspx?cid=' + categoryID + '&pid=' + productID + '&WidthInches=' + frmEle.WidthInchesDisplay.value + '&Width8ths=' + frmEle.Width8thsDisplay.value + '&HeightInches=' + frmEle.HeightInchesDisplay.value + '&Height8ths=' + frmEle.Height8thsDisplay.value + '&vx=' + vx;
}

function showHide(elementid) {
    if (document.getElementById(elementid).style.display == 'none') {
        document.getElementById(elementid).style.display = 'block';
    }
    else {
        document.getElementById(elementid).style.display = 'none';
    }
}

function showShippingQuoteEnter(e, page) {
    if (window.event) {
        if (window.event.keyCode == 13) {
            showShippingQuote(page);
        }
    }
    else {
        if (e.which == 13) {
            showShippingQuote(page);
        }
    }
}
function showShippingQuote(page) {
    if (document.getElementById('ShipToZip').value == '') {
        alert('Please enter Your Zipcode.');
    }
    else {
        var so = get_radio_value(document.getElementsByName('ShippingOptions'));
        var url = page
            + '&ShipToZip=' + document.getElementById('ShipToZip').value
            + '&ShipFromZip=' + document.getElementById('ShipFromZip').value
            + '&LeadTime=' + document.getElementById('leadtime').value
            + '&Overnight=' + so
            + '&Rate=' + document.getElementById('ShippingEstimateRate').value;

        window.location.href = url;
    }
}

function get_radio_value(element) {
    for (var i = 0; i < element.length; i++) {
        if (element[i].checked) {
            return element[i].value;
        }
    }
}

function resetShippingEstimate() {
    switchViews('divEstimates', 'divEstimatsShown');
    $('#shipesterror').removeClass('show').addClass('hide');
}

function switchViews(objToShow, objToHide) {
    $(objToShow).removeClass('hide').addClass('show');
    $(objToHide).removeClass('show').addClass('hide');
}

function selectProductInfoMenu(paneToShow, scrollPage) {

    //alert(paneToShow);

    if (scrollPage == null) scrollPage = false;
    $('#ColorTab').removeClass('selectedTab').addClass('normal');
    $('#ReviewTab').removeClass('selectedTab').addClass('normal');
    $('#ProductInfoTab').removeClass('selectedTab').addClass('normal');
    $('#ShippingProductionTab').removeClass('selectedTab').addClass('normal');
    $('#MeasureInstallTab').removeClass('selectedTab').addClass('normal');
    $('#ColorPane').removeClass('show').addClass('hide');
    $('#ReviewPane').removeClass('show').addClass('hide');
    $('#ProductInfoPane').removeClass('show').addClass('hide');
    $('#ShippingProductionPane').removeClass('show').addClass('hide');
    $('#MeasureInstallPane').removeClass('show').addClass('hide');

    $('#' + paneToShow + 'Tab').removeClass('normal').addClass('selectedTab');
    $('#' + paneToShow + 'Pane').removeClass('hide').addClass('show');

    if (scrollPage) window.location.hash = paneToShow + 's';
}

//This is for forwarding to the appropriate tab when hashed to do so.
$(document).ready(function () {

    //alert(window.location.hash);

    var hash = window.location.hash;

    if (hash != "" && hash.length > 1) {

        hash = hash.substr(1);

        //alert(hash);

        if (hash.lastIndexOf("s") == hash.length - 1) {
            //alert(hash);
            hash = hash.substr(0, hash.length - 1);
        }

        selectProductInfoMenu(hash, false);
    }
});
