﻿//function getCookie(name) {
//    if (document.cookie.length > 0 && document.cookie.indexOf(name) != -1) {
//        var cookies = document.cookie;
//        var startpos = cookies.indexOf(name) + name.length + 1;
//        var endpos = cookies.indexOf(";", startpos) - 1;
//        if (endpos == -2) endpos = cookies.length;
//        return unescape(cookies.substring(startpos, endpos));
//    }
//    else {
//        return null;
//    }
//}

//function clearCookie(name) {
//    expires = new Date();
//    expires.setYear(expires.getYear() - 1);
//    document.cookie = name + '=null' + '; expires=' + expires;
//}

//function setCookie(name, value, days) {
//    if (name != '') {
//        var date = new Date();
//        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
//        var expiration = date.toGMTString();
//        document.cookie = name + "=" + value + "; expires=" + expiration + "; path=/";
//    }
//}

//function checkCookie() {
//    var cookie = getCookie("CarsonDellosa_m10);
//    if (cookie == null) {
//        try {
//            var x = $find('ModalPopupFirstTimeUser2');
//            if (x != null) {
//                x.show();
//            }
//            setCookie("CarsonDellosa_m10", "CarsonDellosa_m10", 1);
//        }
//        catch (err) {
//        }
//    }
//}

function SelectOneRadio(rdo) {
    /* Getting an array of all the "INPUT" controls on the form.*/

    all = document.getElementsByTagName("input");
    for (i = 0; i < all.length; i++) {
        if (all[i].type == "radio")/*Checking if it is a radio button*/
        {
            /*I have added '__ctl' ASP.NET adds '__ctl' to all 
            the controls of DataGrid.*/
            var count = all[i].id.indexOf('Shipping_ShippingMethodsRepeater');
            if (count != -1) {
                all[i].checked = false;
            }
        }
    }
    rdo.checked = true; /* Finally making the clicked radio button CHECKED */
}  

function ShowContent(id, event, e) {
    var divTag = document.getElementById(id);
    var posX = 0;
    var posY = 0;
    if (!event) var event = window.event;
    if (event.pageX || event.pageY) {
        posX = event.pageX;
        posY = event.pageY;
    }
    else if (event.clientX || event.clientY) {
        posX = event.clientX + document.body.scrollLeft
		                + document.documentElement.scrollLeft;
        posY = event.clientY + document.body.scrollTop
		                + document.documentElement.scrollTop;
    }
    divTag.style.top = posY + "px";
    divTag.style.left = posX + "px";
    divTag.style.display = "block";
}
function HideContent(id) {
    var divTag = document.getElementById(id);
    divTag.style.display = "none";
}

function PrintThisPage() {
    var sOption = "toolbar=yes,location=no,directories=yes,menubar=yes,";
    sOption += "scrollbars=yes,width=700,height=600,left=100,top=25";
    var header = "<div  align=center><img alt=\" Carson Dellosa\" border=\"0\" src=\"/cd2/Images/header.gif\" width=\"630\" ><br /><br /> </div>"
    var footer = " <div align=center><br /><br /><img alt=\" Carson Dellosa\" border=\"0\" src=\"/cd2/images/footer_03.gif\" width=\"630\" ></div>"
    var sWinHTML = document.getElementById('printContentStart').innerHTML;
    sWinHTML = sWinHTML.replace("h3", "div")
    sWinHTML = sWinHTML.replace("H3", "div")
    sWinHTML = sWinHTML.replace("</h3>", "</div>")
    sWinHTML = sWinHTML.replace("</H3>", "</div>")
    sWinHTML = sWinHTML.replace("display: inline-block; width: 510px", "")
    sWinHTML = sWinHTML.replace("DISPLAY: inline-block; WIDTH: 510px", "")
    sWinHTML = sWinHTML.replace("class=Dear", "class=dear")
    var winprint = window.open("", "", sOption);
    winprint.document.open();
    winprint.document.write('<html><LINK href=/cd2/App_Themes/Default/hrl.css rel=Stylesheet><body>');
    winprint.document.write(header);
    winprint.document.write(sWinHTML);
    winprint.document.write(footer);
    winprint.document.write('</body></html>');
    winprint.document.close();
    winprint.focus();
}

function HideContent(id) {
    var divTag = document.getElementById(id);
    divTag.style.display = "none";
    divTag.style.visibility = "hidden";
}

function HideModal() {
    $find('ModalPopupFirstTimeUser2').hide();
     window.location.reload();
 }
 function HideProductQtyValidatorPopup() {
     $find('ctl00_ctl00_LeftNavMainContent_MainContent_ValidateQuantityPopupE').hide();
 }

 function ddlShowItemsListOnChange(source) {
     //alert($find('ctl00_ctl00_LeftNavMainContent_MainContent_ProductsListViewCtrl_ProductsList_ShowItemsList').val());
     if (source != null && source.value.length > 0) {
         var sb = new StringBuilder();
         var Request_URL_HOST = document.location.host;
         var Request_PATHNAME = document.location.pathname;
         var Request_QUERYSTRING = document.location.search;
         if (Request_QUERYSTRING.length > 0) {
             Request_QUERYSTRING = Request_QUERYSTRING.replace("?", "");
             var qsParams = Request_QUERYSTRING.split("&");

             for (i = 0; i < qsParams.length; i++) {
                 if (qsParams[i].indexOf("rows=") < 0 && qsParams[i].indexOf("start=") < 0) {
                     if (sb.toString().length > 0) {
                         sb.append("&");
                     }
                     sb.append(qsParams[i]);
                 }
             }
         }
         if (sb.toString().length > 0) {
             sb.append("&");
         }

         sb.append("{0}={1}".format("rows", source.value));

         var redirectPath = ("http://{0}{1}?{2}".format(Request_URL_HOST, Request_PATHNAME, sb.toString()));

         document.location = redirectPath;
     }
 }


    function StringBuilder(value) {
        this.strings = new Array("");
        this.append(value);
    }

    // Appends the given value to the end of this instance.

    StringBuilder.prototype.append = function (value) {
        if (value) {
            this.strings.push(value);
        }
    }

    // Clears the string buffer

    StringBuilder.prototype.clear = function () {
        this.strings.length = 1;
    }

    // Converts this instance to a String.

    StringBuilder.prototype.toString = function () {
        return this.strings.join("");
    }

    String.prototype.format = function () {
        var formatted = this;
        for (arg in arguments) {
            formatted = formatted.replace("{" + arg + "}", arguments[arg]);
        }
        return formatted;
    };



    /// ===========================================================================
    /// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
    /// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    /// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
    /// PURPOSE.
    /// ===========================================================================
    /// 
    /// Project:        MOSS Faceted Search
    /// Company:        Microsoft Services
    /// Date:           12/29/2007  Version:        2.0
    ///
    /// ===========================================================================

    function switchFooter(obj, name, totalResults) {
        try {
            var table = getFacetTableByObj(obj, name);
            if (table) {
                var re = /DLMIN.gif/;
                var img = obj.children[0];
                var expanded = re.test(img.src);
                if (expanded) { // then collapse
                    img.src = img.src.replace(/DLMIN.gif/, "DLMAX.gif");
                } else {
                    img.src = img.src.replace(/DLMAX.gif/, "DLMIN.gif");
                }

                setFacetTable(table, expanded, totalResults);
            }
        } catch (e) { }
        finally { return false; }
    }

    function setFacetTable(table, expanded, maxResults) {
        var total = table.rows.length;
        if (expanded) {// then collapse and show last row with ...
            table.rows[total - 1].style.display = "block";
        } else {
            table.rows[total - 1].style.display = "none";
        }

        for (var i = parseInt(maxResults) + 1; i < total - 1; i++) {
            var row = table.rows[i];
            if (expanded) {// then collapse and hide all rows
                row.style.display = "none";
            } else {
                row.style.display = "block";
            }
        }
    }

    function getFacetTableByObj(obj, name) {
        var parent = obj.parentElement;
        if (parent == null && navigator.appName == "Netscape") {
            parent = obj.parentNode;
        }
        while ((parent != null) && (parent.tagName != "Table")) {

            if (parent.parentElement == null && navigator.appName == "Netscape") {
                parent = parent.parentNode;
            }
            else {
                parent = parent.parentElement;
            }

            if (parent.getAttribute("facet") == name) {
                return parent;
            }
        }
    }

    function getFacetTableByName(name) {
        var tables = document.body.getElementsByTagName("Table");
        for (var i = 0; i < tables.length; i++) {
            var table = tables[i];
            if (table.getAttribute("facet") == name) {
                return table;
            }
        }
    }

    function processFacetTables() {
        var tables = document.body.getElementsByTagName("Table");
        for (var i = 0; i < tables.length; i++) {
            var table = tables[i];
            if (table.getAttribute("facet")) {
                var count = table.getAttribute("count");
                var totalresults = table.getAttribute("totalresults");
                setFacetTable(table, true, totalresults);
            }
        }
    }
    function initFacetTables() {
        try {
            if (arFacetTables != undefined) {
                for (var i = 0; i < arFacetTables.length; i++) {
                    var name = arFacetTables[i];
                    var totalResults = arTotalResults[i];
                    var table = getFacetTableByName(name);
                    setFacetTable(table, true, totalResults)
                }
            }
        } catch (e) {

        }
    }

    //*********** 2nd call ****************//  

    function setProgress(url) {
        var images = document.images;
        for (var i = 0; i < images.length; i++) {
            var img = images[i];
            if (img.progress != null) {
                img.src = url;
            }
        }
    }

    function switchElement(id, toShow) {
        var el = document.getElementById(id);
        if (el != null) {
            if (toShow) {
                el.style.display = "inline";
            } else {
                el.style.display = "none";
            }
        }
    }


    function setElAttribute(id, attName, attValue) {
        var el = document.getElementById(id);
        el[attName] = attValue;
    }

    function addMatch(facetName, facetDisplayName, qs) {
        var match = prompt('Add additional match for ' + facetDisplayName, '[type the value]');
        if (!match) return false;
        var url = qs + ' ' + facetName + ':"' + encodeURI(match) + '"';
        GoToPageRelative(url);
    }
    function RetrieveSceneImg(imgCtrl, productId, imageType) {
        imgCtrl.onload = null;
        imgCtrl.src = 'AsyncLoadImage.ashx?productId=' + productId + '&imageType=' + imageType;
    }
    function popUp(URL) {
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=575,height=420');");
    }

    function VerifyPromotion() {
        var promoCodeValue = document.getElementById('<%=PromoCodeTextBox.ClientID%>').value.replace(/^\s*|\s*$/g, "");
        if (promoCodeValue.length > 0) {
            if (confirm('Do you wish to proceed without activating your promotion code? If you wish to activate your promotion code please hit the cancel button and click on Activate Promotions button.'))
                return true;
            else
                return false;
        }
    }

    function valSubmit() {
        return true;
    }
    function popUp(URL, isCorrelation) {
        day = new Date();
        id = day.getTime();
        if (!isCorrelation)
            eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=550');");
        else
            eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=900,height=900');");
    }   

