﻿function CustomerOrder() {
    this.OrderId = null;
    this.CustomerId = null;
    this.OrderTransactionId = null;
    this.Email = null;
    this.PassWord = null;
    this.Telephone = null;
    this.FirstName = null;
    this.Surname = null;
    this.Address1 = null;
    this.Address2 = null;
    this.Address3 = null;
    this.Town = null;
    this.County = null;
    this.PostCode = null;
    this.Country = null;
    this.dTelephone = null;
    this.dFirstName = null;
    this.dSurname = null;
    this.dAddress1 = null;
    this.dAddress2 = null;
    this.dAddress3 = null;
    this.dTown = null;
    this.dCounty = null;
    this.dPostCode = null;
    this.dCountry = null;
    this.OrderTypeId = null;
    this.OrderStatusId = null;
    this.OrderItems = new Array();
    this.HasCustomOakley = null;
    this.CustomOakleyOrderItem = null;

}

CustomerOrder.instance = null;
CustomerOrder.getInstance = function () {
    if (CustomerOrder.instance == null) {
        CustomerOrder.instance = new CustomerOrder();
    }
    return CustomerOrder.instance;
}
CustomerOrder.prototype.addorderitem = function (item) {
    this.OrderItems.push(item);
}

var customerorderobj = CustomerOrder.getInstance();


function LoadFontReplacement() {

    var cc = $("#CurrentCultureId").html();
    if (cc=="2" || cc == "4" || cc == "8" || cc == "9") {

    }
    else {
        Cufon.replace('h1', { fontFamily: 'Egon' });
        Cufon.replace('h7', { fontFamily: 'Egon' });
        Cufon.replace('h2', { fontFamily: 'Egon' });
        Cufon.replace('h3', { fontFamily: 'Egon' });
        Cufon.replace('h6', { fontFamily: 'Egon' });
        Cufon.replace('h5', { fontFamily: 'Egon' });
        $("ul.TopBannerLogoTextList li").each(function () {
            Cufon.replace($(this), { fontFamily: 'Egon' });
        });
        /*$("#BodyContent").each(function () {
        Cufon.replace($(this), { fontFamily: 'Egon' });
        });*/
        $(".magazineheading").each(function () {
            Cufon.replace($(this), { fontFamily: 'Egon' });
        });
        $(".magazineheading2").each(function () {
            Cufon.replace($(this), { fontFamily: 'Egon' });
        });
        $(".magazineheading3").each(function () {
            Cufon.replace($(this), { fontFamily: 'Egon' });
        });
        $(".magazineheading4").each(function () {
            Cufon.replace($(this), { fontFamily: 'Egon' });
        });
        $(".magazineheading5").each(function () {
            Cufon.replace($(this), { fontFamily: 'Egon' });
        });
        $(".magazineheading6").each(function () {
            Cufon.replace($(this), { fontFamily: 'Egon' });
        });
        $(".sunshop").each(function () {
            Cufon.replace($(this), { fontFamily: 'Egon' });
        });
        $(".spOverlayHeader").each(function () {
            Cufon.replace($(this), { fontFamily: 'Egon' });
        });
        $(".spOverlayContent").each(function () {
            Cufon.replace($(this), { fontFamily: 'Egon' });
        });

    }

}

function ChangeProductViewSort() {
    location.replace(location.href.replace(/\?.*$/, '') + '?sortby=' + $("#cbsort").val());
}

function LoadNavigationMenu() {
    var SelfLocation = window.location.href.split('?');
    switch (SelfLocation[1]) {
        case "justify_right":
            $(".megamenu").megamenu({ 'justify': 'right', 'show_method': 'simple' });
            break;
        case "justify_left":
            break;
        default:
            $(".megamenu").megamenu({'show_method':'simple'});
    }

    //jQuery("ul.megamenu li:first").trigger('mouseover');
}


function LoadBrandProductNamesFromSelector() {
    var brandid = null;
  
    var id = $("input[@name=brandselector]:checked").attr('id');
    brandid = $("#" + id).val();
    var cultureid = $("#bpcultureid").html();

    var dataStr = "brandid=" + brandid + "&cultureid=" + cultureid;

    var req = $.ajax({
        type: "POST",
        url: "/SiteHandler.ashx?op=getproductnameoptions",
        data: dataStr,
        error: function (req, json) {

            alert(json);
        },
        success: function (html) {
            $("#BrandProductNameSearchList").html(html);
            PreLoadBrandProductNameSelector();
            return;
        }
    });
}

function GetBrandProductNameUrl() {

    var brandid = null;
    var bid = $("input[@name=brandselector]:checked").attr('id');
    brandid = $("#" + bid).val();

    var cultureid = $("#bpcultureid").html();

    var pb = null;
    var var_name = $("input[name=brandproductnameselector]:checked").val();
    pb = var_name;
    /*$("#BrandProductNameSearchList li input").each(function () {
        var id = $(this).attr('id');
        var var_name = $("input[name=brandproductnameselector]:checked").val();
        pb = var_name;

    });*/
    var dataStr = "brandid=" + brandid + "&pb=" + pb + "&cultureid=" + cultureid;
   
    var req = $.ajax({
        type: "POST",
        url: "/SiteHandler.ashx?op=getbrandproducturl",
        data: dataStr,
        error: function (req, json) {

            alert(json);
        },
        success: function (html) {
            //alert(html);
            document.location.href = html;
            return;
        }
    });
}


function PreLoadBrandProductNameSelector() {
    $("input").change(function () {
        var name = $(this).attr('name');
        switch (name) {
            case "brandselector":
                LoadBrandProductNamesFromSelector();
                break;
            case "brandproductnameselector":
                GetBrandProductNameUrl();
                break;
        }
    });
}


function LoadCornerz() {
    
    $('#BrandSearchBoxContainer').cornerz({ radius: 10, corners: "tl tr bl br", borderWidth: 0, background: '#ffffff', fixIE: 'true' });
    $('#BrandProductNameSearchBoxContainer').cornerz({ radius: 10, corners: "tl tr bl br", borderWidth: 0, background: '#ffffff', fixIE: 'true' });
    $("#CelebrityViewListContainer ul li").each(function () {
        $(this).cornerz({ radius: 10, corners: "tl tr bl br", borderWidth: 0, background: '#ffffff', fixIE: 'true' });
    });
}


function GetGoogleCheckoutRedirect() {
    var pid = $("#CurrentProductId").html();

    var dataStr = "pid=" + pid;

    var req = $.ajax({
        type: "POST",
        url: "/SiteHandler.ashx?op=getgooglecheckout",
        data: dataStr,
        error: function (req, json) {

            alert(json);
        },
        success: function (html) {
            var url = "/Gateway.aspx?pid=" + pid + "&pg=google&url=" + encodeURIComponent(html);
            document.location.href = html;
            return;
        }
    });
}

function RedirectToPayPal() {
    var url = "https://www.paypal.com/cgi-bin/webscr";

    $("#form1").attr("action", url);
    alert($("#form1").attr("action"));
    $("#form1").submit();


}

function ViewCurrencyChanger() {
   
    tb_show("Change Currency", "/SiteHandler.ashx?op=viewcurrencychanger&height=500&width=500&modal=false", null);
}

function SetCurrency(cultureid) {

    var dataStr = "cultureid=" + cultureid;
    var req = $.ajax({
        type: "POST",
        url: "/SiteHandler.ashx?op=setcurrentcurrency",
        data: dataStr,
        error: function (req, json) {

            //alert(json);
        },
        success: function (html) {
            //tb_remove();
            document.location.href = html;

            return;
        }
    });
}


function SearchKeywords(url) {
    var text = $("#searchtext").val();
    
    if (text != " Search/Code/Keyword") {
        var link = url + "?q=" + encodeURIComponent(text);
        document.location.href = link;
    }
}

function PleaseCallToOrder(msg) {
    alert(msg);
}




function AddToCart() {
    var pid = $("#CurrentProductId").html();
    var cid = $("#CurrentCultureId").html();
    tb_show("Add to Cart", "/SiteHandler.ashx?op=getordercustomerdetails&pid=" + pid + "&cid=" + cid + "&height=500&width=600&modal=false", null);
    
}

function SaveOrderCookie() {
    var cookieobj;
    var name = "SunglassesShopOrder";
    var cval = $("#ordercookieinfo").val();
    cookieobj = eval('cookieobj = ' + cval);
    $.JSONCookie(name, cookieobj, { path: '/' });
}

function AddToCartWithId(pid) {

    var cid = $("#CurrentCultureId").html();
    tb_show("Add to Cart", "/SiteHandler.ashx?op=getordercustomerdetails&pid=" + pid + "&cid=" + cid + "&height=500&width=600&modal=false", null);
    
}

function GoToCheckout() {
    var cid = $("#CurrentCultureId").html();
    var oid = $("#currentorderid").val();
    //var base = $.base64Encode("oid=" + oid + "&cid=" + cid); 
    tb_show("Checkout", "/SiteHandler.ashx?op=getorderconsumercheckout&oid=" + oid + "&cid=" + cid + "&height=500&width=600&modal=false", null);

}

function GoToCheckoutFromTopBar(oid, cid) {

    tb_show("Checkout", "/SiteHandler.ashx?op=getorderconsumercheckout&oid=" + oid + "&cid=" + cid + "&height=500&width=600&modal=false", null);

}

function GoToCheckoutFromTopBar2(url) {

    //tb_show("Checkout", "/SiteHandler.ashx?op=getorderconsumercheckout&oid=" + oid + "&cid=" + cid + "&height=500&width=600&modal=false", null);
    
    document.location.href = url;
}


function RemoveFromBag(oitemid) {

    var dataStr = "oitemid=" + oitemid;
    var req = $.ajax({
        type: "POST",
        url: "/SiteHandler.ashx?op=removefrombag",
        data: dataStr,
        error: function (req, json) {

            //alert(json);
        },
        success: function (html) {
            /*$("#" + oitemid).remove();
            var cid = $("#CurrentCultureId").html();
            var oid = $("#currentorderid").val();
            GoToCheckoutFromTopBar(oid, cid);*/
            var link = $.jqURL.url();
            document.location.href = link;
            return;
        }
    });
}

function ChangeQuantity(method, oitemid) {

    var dataStr = "oitemid=" + oitemid + "&method=" + method;
    var req = $.ajax({
        type: "POST",
        url: "/SiteHandler.ashx?op=changebagquantity",
        data: dataStr,
        error: function (req, json) {

            //alert(json);
        },
        success: function (html) {
           
            var link = $.jqURL.url();
            document.location.href = link;
            return;
        }
    });
}

function ContinueShopping() {
    tb_remove();
    var link = $.jqURL.url();
    document.location.href = link;

}

function FireAlert(message) {
    alert(message);
}

function isValidField(id) {
    var isValid = false;
    var length = $("#" + id).val().length;
    if (length > 0) {
        isValid = true;
    }
    return isValid;

}

// JavaScript Document
function isEmailAddr(email) {
    var result = false;
    var theStr = new String(email);
    var index = theStr.indexOf("@");
    if (index > 0) {
        var pindex = theStr.indexOf(".", index);
        if ((pindex > index + 1) && (theStr.length > pindex + 1))
            result = true;
    }
    return result;
}

function validRequired(formField, fieldLabel) {
    var result = true;
    if (formField.value == "") {
        alert('Please enter a value for the "' + fieldLabel + '" field.');
        formField.focus();
        result = false;
    }
    return result;
}

function validDropDown(formField, fieldLabel) {
    var result = true;
    if (formField.value < 1) {
        alert('Please enter a value for the "' + fieldLabel + '" field.');
        formField.focus();
        result = false;
    }
    return result;
}

function validCheck(formField, fieldLabel) {
    var result = true;
    if (!formField.checked) {
        alert('Please enter a value for the "' + fieldLabel + '" field.');
        result = false;
    }
    return result;
}

function minLength(formField, fieldLabel) {
    var result = true;
    var char_count = formField.value.length;
    var fullStr = formField.value + " ";
    var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
    var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
    var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
    var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
    var splitString = cleanedStr.split(" ");
    var word_count = splitString.length - 1;
    if (word_count < 150) {
        alert('Sorry the ' + fieldLabel + ' field is too short, you need to write at least 150 words.');
        formField.focus();
        result = false;
    }
    return result;
}

function validEmailTwice(formField, formField2, fieldLabel) {
    var result = true;
    if (formField.value != formField2.value) {
        alert('You did not enter the "' + fieldLabel + '" fields twice.  Try again.');
        result = false;
    }
    return result;
}

function allDigits(str) {
    return inValidCharSet(str, "0123456789");
}

function inValidCharSet(str, charset) {
    var result = true;
    // Note: doesn't use regular expressions to avoid early Mac browser bugs	
    for (var i = 0; i < str.length; i++)
        if (charset.indexOf(str.substr(i, 1)) < 0) {
            result = false;
            break;
        }
    return result;
}

function validEmail(formField, fieldLabel, required) {
    var result = true;
    if (required && !validRequired(formField, fieldLabel))
        result = false;
    if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value))) {
        alert("Please enter a complete email address in the form: yourname@yourdomain.com");
        formField.focus();
        result = false;
    }
    return result;
}

function validNum(formField, fieldLabel, required) {
    var result = true;
    if (required && !validRequired(formField, fieldLabel))
        result = false;
    if (result) {
        if (!allDigits(formField.value)) {
            alert('Please enter a number for the "' + fieldLabel + '" field.');
            formField.focus();
            result = false;
        }
    }
    return result;
}


function validInt(formField, fieldLabel, required) {
    var result = true;
    if (required && !validRequired(formField, fieldLabel))
        result = false;
    if (result) {
        var num = parseInt(formField.value, 10);
        if (isNaN(num)) {
            alert('Please enter a number for the "' + fieldLabel + '" field.');
            formField.focus();
            result = false;
        }
    }

    return result;
}

function validFloat(formField, fieldLabel, required) {
    var result = true;
    if (required && !validRequired(formField, fieldLabel))
        result = false;
    if (result) {
        var num = parseFloat(formField.value, 10);
        if (isNaN(num)) {
            alert('Please enter a number for the "' + fieldLabel + '" field.');
            formField.focus();
            result = false;
        }
    }

    return result;
}

function validDate(formField, fieldLabel, required) {
    var result = true;
    if (required && !validRequired(formField, fieldLabel))
        result = false;
    if (result) {
        var elems = formField.value.split("/");
        result = (elems.length == 3); // should be three components
        if (result) {
            var month = parseInt(elems[0], 10);
            var day = parseInt(elems[1], 10);
            var year = parseInt(elems[2], 10);
            result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
					 allDigits(elems[1]) && (day > 0) && (day < 32) &&
					 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
        }
        if (!result) {
            alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel + '" field.');
            formField.focus();
        }
    }
    return result;
}





function VerifyCustomer() {
    $("#OrderVerificationDisplay").hide();
    var totalfilled = 0;
    if (isValidField('emailstr') && isEmailAddr($("#emailstr").val())) {
        totalfilled += 1;
        $("#emailstr").removeClass('FormFieldError');
    }
    else {
        $("#emailstr").addClass('FormFieldError');
    }
    if (isValidField('postcodestr') && $("#postcodestr").val().length <= 9) {
        totalfilled += 1;
        $("#postcodestr").removeClass('FormFieldError');
    }
    else {
        $("#postcodestr").addClass('FormFieldError');
    }
    if (totalfilled < 2) {
        $("#OrderVerificationDisplay").show();
    }
    else {
        var cid = $("#CurrentCultureId").html();
        var oid = $("#orderid").val();

        var dataStr = "cid=" + cid + "&oid=" + oid + "&email=" + encodeURIComponent($("#emailstr").val().replace(",", ".")) + "&postcode=" + encodeURIComponent($("#postcodestr").val()) + "&voucher=" + encodeURIComponent($("#voucherstr").val());
        var req = $.ajax({
            type: "POST",
            url: "/SiteHandler.ashx?op=verifycustomer",
            data: dataStr,
            error: function (req, json) {

            },
            success: function (html) {
                document.location.href = html;
                return;
            }
        });

    }

}

function ChangeDeliveryUsage() {

    
    $("#dTelephone").val($("#Telephone").val());
    $("#dFirstName").val($("#FirstName").val());
    $("#dSurname").val($("#Surname").val());
    $("#dAddress1").val($("#Address1").val());
    $("#dAddress2").val($("#Address2").val());
    $("#dAddress3").val($("#Address3").val());
    $("#dCity").val($("#City").val());
    $("#dState").val($("#State").val());
    $("#dPostCode").val($("#PostCode").val());
    $("#ddlDeliveryCountry").val($("#ddlBillingCountry").val());
}

function CheckCountry(element) {
    var id = $(element).attr('id');
    if (id == "ddlBillingCountry") {
        if ($("#" + id).val() == "US") {
            $("#StateRow").show();
        }
    }
    else if (id == "ddlDeliveryCountry") {
        if ($("#" + id).val() == "US") {
            $("#dStateRow").show();
        }
    }
}

function VerifyOrder() {
    var optout = $('#chkOptOut').attr('checked');
    var culturalpath = $("#CulturePath").val();
    $("#OrderVerificationDisplay").hide();
    var totalfilled = 0;
    if (isValidField('Email')  && isEmailAddr($("#Email").val())) {
        totalfilled += 1;
        $("#Email").removeClass('FormFieldError');
    }
    else {
        $("#Email").addClass('FormFieldError');
    }
    
    if (isValidField('Telephone') && allDigits($("#Telephone").val().replace(" ","").replace("+",""))) {
        totalfilled += 1;
        $("#Telephone").removeClass('FormFieldError');
    }
    else {
        $("#Telephone").addClass('FormFieldError');
    }

    if (isValidField('dTelephone') && allDigits($("#dTelephone").val().replace(" ", "").replace("+", ""))) {
        totalfilled += 1;
        $("#dTelephone").removeClass('FormFieldError');
    }
    else {
        $("#dTelephone").addClass('FormFieldError');
    }

    if (isValidField('FirstName')) {
        totalfilled += 1;
        $("#FirstName").removeClass('FormFieldError');
    }
    else {
        $("#FirstName").addClass('FormFieldError');
    }
    if (isValidField('dFirstName')) {
        totalfilled += 1;
        $("#dFirstName").removeClass('FormFieldError');
    }
    else {
        $("#dFirstName").addClass('FormFieldError');
    }

    if (isValidField('Surname')) {
        totalfilled += 1;
        $("#Surname").removeClass('FormFieldError');
    }
    else {
        $("#Surname").addClass('FormFieldError');
    }
    if (isValidField('dSurname')) {
        totalfilled += 1;
        $("#dSurname").removeClass('FormFieldError');
    }
    else {
        $("#dSurname").addClass('FormFieldError');
    }

    if (isValidField('Address1')) {
        totalfilled += 1;
        $("#Address1").removeClass('FormFieldError');
    }
    else {
        $("#Address1").addClass('FormFieldError');
    }
    if (isValidField('dAddress1')) {
        totalfilled += 1;
        $("#dAddress1").removeClass('FormFieldError');
    }
    else {
        $("#dAddress1").addClass('FormFieldError');
    }

    if (isValidField('City')) {
        totalfilled += 1;
        $("#City").removeClass('FormFieldError');
    }
    else {
        $("#City").addClass('FormFieldError');
    }
    if (isValidField('dCity')) {
        totalfilled += 1;
        $("#dCity").removeClass('FormFieldError');
    }
    else {
        $("#dCity").addClass('FormFieldError');
    }

    if (isValidField('PostCode') && $("#PostCode").val().length<=9) {
        totalfilled += 1;
        $("#PostCode").removeClass('FormFieldError');
    }
    else {
        $("#PostCode").addClass('FormFieldError');
    }
    if (isValidField('dPostCode') && $("#dPostCode").val().length <= 9) {
        totalfilled += 1;
        $("#dPostCode").removeClass('FormFieldError');
    }
    else {
        $("#dPostCode").addClass('FormFieldError');
    }

    if (totalfilled < 13) {
        $("#OrderVerificationDisplay").show();
    }
    else {
        var cid = $("#CurrentCultureId").html();
        customerorderobj.OrderId = $("#currentorderid").val();
        customerorderobj.Email = $("#Email").val().replace(",", ".");
        
        customerorderobj.Telephone = $("#Telephone").val().replace(' ', '').replace("+", "");
        customerorderobj.FirstName = $("#FirstName").val();
        customerorderobj.Surname = $("#Surname").val();
        customerorderobj.Address1 = $("#Address1").val();
        customerorderobj.Address2 = $("#Address2").val();
        customerorderobj.Address3 = $("#Address3").val();
        customerorderobj.Town = $("#City").val();
        customerorderobj.County = $("#State").val();
        customerorderobj.PostCode = $("#PostCode").val();
        customerorderobj.Country = $("#ddlBillingCountry").val();
        customerorderobj.dTelephone = $("#dTelephone").val().replace(' ', '').replace("+", "");
        customerorderobj.dFirstName = $("#dFirstName").val();
        customerorderobj.dSurname = $("#dSurname").val();
        customerorderobj.dAddress1 = $("#dAddress1").val();
        customerorderobj.dAddress2 = $("#dAddress2").val();
        customerorderobj.dAddress3 = $("#dAddress3").val();
        customerorderobj.dTown = $("#dCity").val();
        customerorderobj.dCounty = $("#dState").val();
        customerorderobj.dPostCode = $("#dPostCode").val();
        customerorderobj.dCountry = $("#ddlDeliveryCountry").val();
        customerorderobj.OrderTypeId = 4;
        customerorderobj.OrderStatusId = 1;
        customerorderobj.addorderitem($("#productid").val());

        var item = JSON.stringify(customerorderobj);
        var dataStr = "cid=" + cid + "&optout=" + optout + "&items=" + encodeURIComponent(item);

        //tb_show("Verify order", "/SiteHandler.ashx?op=verifycustomerdetails&items=" + encodeURIComponent(item) + "&height=500&width=300&modal=false", null);
        var req = $.ajax({
            type: "POST",
            url: "/SiteHandler.ashx?op=verifycustomerdetails",
            data: dataStr,
            error: function (req, json) {

                //alert(json);
            },
            success: function (html) {
                if (culturalpath.length > 1) {
                    var url = html + culturalpath + "/Gateway.aspx?cid=" + cid + "&oid=" + customerorderobj.OrderId + "&pg=sage";

                    document.location.href = url;
                }
                else {
                    var url = html + culturalpath + "Gateway.aspx?cid=" + cid + "&oid=" + customerorderobj.OrderId + "&pg=sage";

                    document.location.href = url;
                }
                

                return;
            }
        });
    }

}

function PrintOrderReturn() {
    $(".OrderReturnFormContainer").print();
}

function SaveOrderReturn() {

    var cultureid = "cultureid=" + $("#cultureid").val();
    var reason = "&reason=" + encodeURIComponent($("#reason").val());
    var fault_desc = "&fault_desc=" + encodeURIComponent($("#fault_desc").val());
    var like = "&like=" + encodeURIComponent($("#like").val());
    var name = "&name=" + encodeURIComponent($("#name").val());
    var phone = "&phone=" + encodeURIComponent($("#phone").val());
    var email = "&email=" + encodeURIComponent($("#email").val());
    var worldpay = "&worldpay=" + encodeURIComponent($("#worldpay").val());
    var orderno = "&orderno=" + encodeURIComponent($("#orderno").val());
    var exchange = "&exchange=" + encodeURIComponent($("#exchange").val());

    var dataStr = cultureid + reason + fault_desc + like + name + phone + email + worldpay + orderno + exchange;

    var req = $.ajax({
        type: "POST",
        url: "/SiteHandler.ashx?op=saveorderreturn",
        data: dataStr,
        error: function (req, json) {

            //alert(json);
        },
        success: function (html) {
            $("#OrderReturnFormContainer").html(html);
        }
    });


}


function ConfirmOrder(orderId, SageAction, VPSProtocol, TxType, Vendor, Crypt) {
    var dataStr = "orderid=" + orderId;
    var req = $.ajax({
        type: "POST",
        url: "/SiteHandler.ashx?op=confirmorder",
        data: dataStr,
        error: function (req, json) {

            //alert(json);
        },
        success: function (html) {
            CreateSageForm(SageAction, VPSProtocol, TxType, Vendor, Crypt);
            tb_remove();
        }
    });


}



function CreateSageForm(SageAction, VPSProtocol, TxType, Vendor, Crypt) {
    var str = '<form id="form2" method="post" action="' + SageAction + '" target="_blank">';
    str += '<input type="hidden" name="VPSProtocol" value="' + VPSProtocol + '" />';
    str += '<input type="hidden" name="TxType" value="' + TxType + '" />';
    str += '<input type="hidden" name="Vendor" value="' + Vendor + '" />';
    str += '<input type="hidden" name="Crypt" value="' + Crypt + '" />';
    str += '</form>';
    $("#form1").after(str);
    $("#form2").submit();
}


function LoadBrandDirectory() {
    $("#BrandDirectoryContainer ul li").each(function () {
        var title = $(this).attr('btitle');
        var desc = $(this).attr('bdesc');
        var burl = $(this).attr('burl');
        //burl = burl;
        desc += '<p><a href="' + burl + '">CLICK HERE FOR MORE</a></p>';
        var id = $(this).attr('id');
        var position = $(this).position();
       

        $(this).bind('mouseover', function () {
            $("#BrandDirectoryDescription h1").html(title);
            $("#BrandDirectoryDescBox").html(desc);
            $("#BrandDirectoryDescription").css({ 'left': (position.left + 140), 'top': position.top });

            Cufon.replace($("#BrandDirectoryDescription h1"), { fontFamily: 'Egon' });
            Cufon.replace($("#BrandDirectoryDescription"), { fontFamily: 'Egon' });
            $("#BrandDirectoryDescription").show();

        });
    });
}

function LoadShoppingDirectory() {
    $("#ShoppingDirectoryContainer ul li").each(function () {
        var title = $(this).attr('stitle');
        var desc = $(this).attr('steaser');
        var burl = $(this).attr('surl');
        
        desc += '<p><a href="' + burl + '">CLICK HERE FOR MORE</a></p>';
        var id = $(this).attr('id');
        var position = $(this).position();

        $(this).bind('mouseover', function () {
            $("#ShoppingDirectoryDescription h1").html(title);
            $("#ShoppingDirectoryDescBox").html(desc);
            $("#ShoppingDirectoryDescription").css({ 'left': (position.left + 220), 'top': position.top });

            Cufon.replace($("#ShoppingDirectoryDescription h1"), { fontFamily: 'Egon' });
            Cufon.replace($("#ShoppingDirectoryDescription"), { fontFamily: 'Egon' });
            $("#ShoppingDirectoryDescription").show();

        });
    });


}

function LoadStyleSelectorDirectory() {
    $("#StyleSelectorDirectoryContainer ul li").each(function () {
        var title = $(this).attr('stitle');
        var desc = $(this).attr('steaser');
        var burl = $(this).attr('surl');

        desc += '<p><a href="' + burl + '">CLICK HERE FOR MORE</a></p>';
        var id = $(this).attr('id');
        var position = $(this).position();

        $(this).bind('mouseover', function () {
            $("#StyleSelectorDirectoryDescription h1").html(title);
            $("#StyleSelectorDirectoryDescBox").html(desc);
            $("#StyleSelectorDirectoryDescription").css({ 'left': (position.left + 320), 'top': position.top });

            Cufon.replace($("#StyleSelectorDirectoryDescription h1"), { fontFamily: 'Egon' });
            Cufon.replace($("#StyleSelectorDirectoryDescription"), { fontFamily: 'Egon' });
            $("#StyleSelectorDirectoryDescription").show();

        });
    });


}

function ChangeSize() {
    var href = $("#cbChangeSize").val();
    document.location.href = href;
}

function LiveChat(domain) {
    var link = "";
    if (domain == "") {
        link = 'http://77.68.68.167/chat/chatstart.aspx?domain=www.sunglassesshop.com';
    }
    else {
        link = 'http://77.68.68.167/chat/chatstart.aspx?domain=www.sunglassesshop.com/' + domain;
    }
    $.jqURL.loc(link,
				{ w: 500, h: 400, wintype: '_blank' });
}

function LoadSocial() {
    var html = $("#SharedText");
    if (html.length > 0) {
        var pageurl = $.jqURL.url();
        $("#share").fShare(
						{
						    shareText: $("#SharedText").html(),
						    shareTitle: $("#SharedTitle").html(),
						    shareUrl: decodeURIComponent(pageurl)
						}
					);
    }
}

function LoadAQPaging(elementid, totalpages, selectedpage, displaytotal) {
    $('#' + elementid).aqPaging({ current: selectedpage, pages: totalpages, cb: function(p){ 
                var sport = $.jqURL.get('sport');
                 var q = $.jqURL.get('q');
                var url = $.jqURL.strip();
                url = url + "?start=" + p;
                
                if(sport!=null && sport.length>0)
                {
                    url += "&sport=" + sport;
                }
                if(q!=null && q.length>0)
                {
                    url += "&q=" + q;
                }
                document.location.href = url;
         } 
         });
}



function LoadNewsletterSignUp(type, gender, parameter) {
    var dataStr = "type=" + type + "&gender=" + gender + "&email=" + encodeURIComponent($("#email").val()) + "&parameter=" + parameter;
    var req = $.ajax({
        type: "POST",
        url: "/SiteHandler.ashx?op=savenewslettersignup",
        data: dataStr,
        error: function (req, json) {

            //alert(json);
        },
        success: function (html) {
            alert(html);
        }
    });

}

function LoadNewsTicker() {
    var jsnews = $("#js-news").height();
    if (jsnews != null) {
        var title = $("#TickerTitle").html();
        $('#js-news').ticker({
            speed: 0.10,
            fadeInSpeed: 600,
            titleText: title
        });
    }

}

function FixPaginationSingular() {
    var jsnews = $("#PagerContentListContainer").height();
    if (jsnews != null) {
        var total = $("#PagerContentListContainer span").size();
        if (total == 1) {
            $("#PagerContentListContainer").hide();
        }
    }
}

$(document).ready(function () {
    //LoadNavigationMenu();
    LoadFontReplacement();
    LoadCornerz();
    PreLoadBrandProductNameSelector();

    $('input').keypress(function (e) {
        var code = null;
        code = (e.keyCode ? e.keyCode : e.which);
        return (code == 13) ? false : true;
    });
    LoadSocial();
    LoadNewsTicker();
    FixPaginationSingular();


});
