﻿$(document).ready(function() {

    $('#jqModalTellFriend').jqm({ trigger: document.getElementById("btnModalTellFriendEdit"), modal: true });
    //Get the height of the sub-panel
    var panelheight = $($(this).attr('href')).height();

    //Set class for the selected item
    $('a[rel=panel]').removeClass('selected');
    $(this).addClass('selected');

    //Get the height of the first item
    $('#mask').css({ 'height': $('#panel-1').height() });

    //Calculate the total width - sum of all sub-panels width
    //Width is generated according to the width of #mask * total of sub-panels
    $('#panel').width(parseInt($('#mask').width() * $('#panel div').length));

    //Set the sub-panel width according to the #mask width (width of #mask and sub-panel must be same)
    $('#panel div').width($('#mask').width());

    //Get all the links with rel as panel
    $('a[rel=panel]').click(function() {

        document.getElementById(this.getAttribute("panel-id").toString()).innerHTML = "<img src=\"Content/Images/ajax-loader1.gif\" />";

        if (this.getAttribute("tab") != null && this.getAttribute("panel-id") != null) {
            $.ajax({
                type: "POST",
                url: "ResultPanel.ashx?tab=" + this.getAttribute("tab") + "&panel-id=" + this.getAttribute("panel-id") + "&image-id=" + this.firstChild.id + "&sid=" + this.getAttribute("sid") + "&isp=" + this.getAttribute("isp") + "&pid=" + this.getAttribute("pid"),
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {

                    document.getElementById(msg.panelid).innerHTML = msg.content;
                    if (document.getElementById(msg.imageid1) != null)
                        document.getElementById(msg.imageid1).src = msg.imagesrc1;
                    if (document.getElementById(msg.imageid2) != null)
                        document.getElementById(msg.imageid2).src = msg.imagesrc2;
                    if (document.getElementById(msg.imageid3) != null)
                        document.getElementById(msg.imageid3).src = msg.imagesrc3;
                    if (document.getElementById(msg.imageid4) != null)
                        document.getElementById(msg.imageid4).src = msg.imagesrc4;
                    if (document.getElementById(msg.imageid5) != null)
                        document.getElementById(msg.imageid5).src = msg.imagesrc5;
                    if (document.getElementById(msg.imageid6) != null)
                        document.getElementById(msg.imageid6).src = msg.imagesrc6;

                    /*if (document.getElementById(msg.hideHrefId) != null)
                    document.getElementById(msg.hideHrefId).style.display = "none";
                    if (document.getElementById(msg.hidePanelId) != null)
                    document.getElementById(msg.hidePanelId).style.display = "none"
                    if (document.getElementById(msg.hideFilterId) != null)
                    document.getElementById(msg.hideFilterId).style.display = "none"*/
                    
                    if (msg.divSize == "large") {
                        document.getElementById("scroller-body").removeAttribute('class');
                        document.getElementById("scroller-body").setAttribute('class', 'divcontent');
                        document.getElementById("scroller-body").children[0].style.height = "1200px";
                    }
                    else if (msg.divSize == "hightlarge1") {
                        document.getElementById("scroller-body").removeAttribute('class');
                        document.getElementById("scroller-body").setAttribute('class', 'divcontenthight1');
                        document.getElementById("scroller-body").children[0].style.height = "2090px";
                    }
                    else if (msg.divSize == "hightlarge2") {
                        document.getElementById("scroller-body").removeAttribute('class');
                        document.getElementById("scroller-body").setAttribute('class', 'divcontenthight2');
                        document.getElementById("scroller-body").children[0].style.height = "2990px";
                    }
                    else {
                        document.getElementById("scroller-body").removeAttribute('class');
                        document.getElementById("scroller-body").setAttribute('class', 'divcontentsmall');
                        document.getElementById("scroller-body").children[0].style.height = "700px";
                    }


                    $('#sortingTD').html(msg.sorting);


                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {


                }
            });


        }





        //Resize the height
        $('#mask').animate({ 'height': panelheight }, { queue: false, duration: 500 });

        //Scroll to the correct panel, the panel id is grabbed from the href attribute of the anchor
        $('#mask').scrollTo($(this).attr('href'), 800);

        //Discard the link default behavior
        return false;
    });
});

function ShowTellFriendAll() {

    document.getElementById("ctl00_mainBody_txtFriendName").value = "";
    document.getElementById("ctl00_mainBody_txtNote").value = "";
    document.getElementById("ctl00_mainBody_txtFriendEmail").value = "";
    document.getElementById("ctl00_mainBody_txtUserName").value = "";
    document.getElementById("ctl00_mainBody_txtYourEmail").value = "";
    document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = ""
    document.getElementById("ctl00_mainBody_btnTellaFriend").disabled = false;
    $('#jqModalTellFriend').jqmShow();

}

function SendTellFriendAll(sender) {

    if (document.getElementById("ctl00_mainBody_txtFriendName").value == '') {
        document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = "Please provide Friend's name";
        return false;
    }
    if (document.getElementById("ctl00_mainBody_txtNote").value == '') {
        document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = "Please provide note";
        return false;
    }
    if (document.getElementById("ctl00_mainBody_txtFriendEmail").value == '') {
        document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = "Please provide Friend's email";
        return false;
    }
    if (document.getElementById("ctl00_mainBody_txtUserName").value == '') {
        document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = "Please provide your name";
        return false;
    }
    if (document.getElementById("ctl00_mainBody_txtYourEmail").value == '') {
        document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = "Please provide your email";
        return false;
    }

    document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = "<img src=\"Content/Images/ajax-loader1.gif\" />";
    document.getElementById("ctl00_mainBody_btnTellaFriend").disabled = true;

    $.ajax({
        type: "POST",
        url: "retailmall.aspx/SendEmail",
        data: "{ friendName:'" + document.getElementById("ctl00_mainBody_txtFriendName").value
                + "', note:'" + document.getElementById("ctl00_mainBody_txtNote").value
                + "', friendEmail:'" + document.getElementById("ctl00_mainBody_txtFriendEmail").value
                + "', yourName:'" + document.getElementById("ctl00_mainBody_txtUserName").value
                + "', yourEmail:'" + document.getElementById("ctl00_mainBody_txtYourEmail").value
                + "', pid:'" + sender.getAttribute("pid") + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            document.getElementById("ctl00_mainBody_btnTellaFriend").disabled = false;
            if (msg.d == '')
                document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = "Email was sent to friend.";
            else
                document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = msg.d;
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            document.getElementById("ctl00_mainBody_btnTellaFriend").disabled = false;
            var start = XMLHttpRequest.responseText.indexOf("11error11") + 9;
            var end = XMLHttpRequest.responseText.indexOf("22error22");
            if (start > 0 && end > 0)
                document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = "Error" + " - " + XMLHttpRequest.responseText.substring(start, end);
            else
                document.getElementById("ctl00_mainBody_lblTellaFriendError").innerHTML = "Error";
        }
    });




}

function HideTellFriendAll() {

    $('#jqModalTellFriend').jqmHide();

}


function ValidationSearch(sender) {
    var txtId = sender.getAttribute("txt-id").toString();
    var txtElement = document.getElementById(txtId);

    if (txtElement.value == 'STE’s Advanced Search Technology' && txtElement.value != '')
        return false;
    else
        return true;
}


function clearSearchBox(sender) {
    if (sender.value == 'STE’s Advanced Search Technology') {
        sender.value = '';
        sender.style.color = 'Black'
    }
    else if (sender.value != '' && sender.value != 'STE’s Advanced Search Technology') {
        sender.style.color = 'Black'
    }
}

function fillSearchBox(sender) {
    if (sender.value == '') {
        sender.value = 'STE’s Advanced Search Technology';
        sender.style.color = 'Gray'
    } else if (sender.value != '') {
        sender.style.color = 'Black'
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function MM_jumpMenu(targ, selObj, restore) { //v3.0
    eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
    if (restore) selObj.selectedIndex = 0;
}
