﻿// JScript File

resetTimer();
var cartCtrl;
var cartProduct;
var cartRequest = false;
var tID = ' ';
var xmlHttp;
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var isFirefox = (navigator.userAgent.indexOf("Firefox/") != -1);
var bVersion = 0;
var RepriceIt = false;
var cellHighLight = 'yellow';
var ajaxReady = false;
var version = '';
var clientBase = 'ctl00_ctl00_ctl00_cphSite_';

if (!document.all) {
    bVersion = navigator.userAgent;
}
else {
    bVersion = navigator.userAgent;
    var MSIEOffset = bVersion.indexOf("MSIE ");
    if (MSIEOffset != -1) {
        bVersion = parseFloat(bVersion.substring(MSIEOffset + 5, bVersion.indexOf(";", MSIEOffset)));
    }


}


//function onKeySignin() {
//    if (window.event.keyCode == 13) {
//        document.getElementById('<%=_buttonSignin.ClientID%>').focus();
//        document.getElementById('<%=_buttonSignin.ClientID%>').click();
//    }
//}


//function XBrowserAddHandler(target, eventName, handlerName) {
//    if (target.addEventListener)
//        target.addEventListener(eventName, handlerName, false);
//    else if (target.attachEvent)
//        target.attachEvent("on" + eventName, handlerName);
//    else
//        target["on" + eventName] = handlerName;
//}



function ValidQtyEntry(field) {
    var err = '';
    var Value = $get(field).value;

    if (isNumeric(Value) == false) {
        err = "Quantity Must be Numeric";
    }
    else if (Value < 0 || Value >= 1000) {
        err = "Quantity Must be Between 0 and 999"
    }
    if (err.length > 0) {
        $get(field).value = 1;
        alert(err);
        return false;
    }
    else {
        return true;
    }

}

function ValidQty(field) {
    var err = '';
    var Value = $get(field).value;
    if (Value.length == 0) {
        err = "Must Enter A Quantity";
    }
    else if (isNumeric(Value) == false) {
        err = "Quantity Must be Numeric";
    }
    else if (Value < 0 || Value >= 100) {
        err = "Quantity Must be Between 0 and 99"
    }
    if (err.length > 0) {
        alert(err);
        return false;
    }
    else {
        return true;
    }

}

function GetImage(txtName, imageName) {
    var MyText = $get(txtName);
    var MyImage = $get(imageName);
    var w = window.open('AdminImageViewer.aspx?FormName=' + document.forms[0].name + '&txtName=' + txtName + '&imageName=' + imageName + '&StartVal=' + MyText.value, "Images", "width=975,height=975,top=200,left=200,toolbars=no,scrollbars=yes,status=no,resizable=yes");
}

function ImageLarge(ID) {
    window.open('ImageLarge.aspx?ID=' + ID, "_blank", "width=800,height=800,top=200,left=200,toolbars=no,scrollbars=yes,status=no,resizable=yes");
}

function QtyxPrice(ctrl, Price, Qty) {
    var newPrice;
    newPrice = Price.substring(1) * Qty;
    ctrl.innerHTML = '$' + newPrice.toFixed(2);
}

function isNumeric(sText) {
    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;

}




var FavItem = '';
var FavLocation = '';
function addFav(Item, Location) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request. Please Use Internet Explorer version 6+ or Firefox.");
        return;
    }
    FavItem = Item;
    FavLocation = Location;
    var url = SiteRoot + "/ASHX/ManageFavs.ashx?Item=" + Item + "&Add=1";

    xmlHttp.onreadystatechange = UpdateFavs;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}



function UpdateFavs() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        var rspText = xmlHttp.responseText;
        var add = $get('tagFavorite' + FavItem);
        var added = $get('imgFavorite' + FavItem);
        var added2 = $get('textFavorite' + FavItem);
        if (rspText == '1') {
            added2.style.display = 'inline';
            added.style.display = 'inline';
            add.style.display = 'none';

        }
        else if (rspText == '0') {
            window.location.href = SiteRoot + '/login.aspx?Msg=favorites&Location=' + escape(FavLocation);

        }
    }

}



function HeaderButtonsOver(buttonID, Image) {

    var location = '/Images/header/';

    var ctrl = $get(buttonID);
    ctrl.style.cursor = 'pointer';
    var index;
    index = ctrl.style.backgroundImage.indexOf("Active");
    if (index == -1) {
        if (document.images != null) {
            ctrl.style.backgroundImage = 'url(' + eval(Image).src + ')';
        }
        else {
            ctrl.style.backgroundImage = 'url(' + location + Image + '.gif)';
        }


    }

}

function HeaderButtonsOut(buttonID, Image) {

    var location = '/Images/header/';

    var ctrl = $get(buttonID);
    ctrl.style.cursor = 'default';
    var index;
    index = ctrl.style.backgroundImage.indexOf("Active");
    if (index == -1) {
        if (document.images != null) {
            ctrl.style.backgroundImage = 'url(' + eval(Image).src + ')';
        }
        else {
            ctrl.style.backgroundImage = 'url(' + location + Image + '.gif)';
        }

    }

}

__addClickToA = function(cid) {
    var a = $get(cid);
    if (a) {
        a.click = function() {
            var start = this.href.indexOf('javascript:');
            start = (start == -1 ? 0 : start + 'javascript:'.length);
            eval(unescape(this.href.substring(start, this.href.length)));
        }
    }
}







function GetXmlHttpObject(handler) {
    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { }
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { }
    try { return new XMLHttpRequest(); } catch (e) { }
    alert("XMLHttpRequest not supported");
    return null;

}

function resetTimer(e) {

    clearTimeout(tID); // reset the timer
    tID = setTimeout('executeTimer()', 3600000); //3600000
}

function executeTimer() {

    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1).toLowerCase();

    if (sPage != 'sessionexpired.aspx' && sPage != 'login.aspx') {
        if (window.location.protocol.indexOf('https:') == 0) {
            location.href = '/sessionexpired.aspx';
        }
    }

}




function addIframe(oCtrl) {

    oCtrl.zIndex = 1000;
    var childFrame = oCtrl._hideWindowedElementsIFrame;
    if (!childFrame) {
        childFrame = document.createElement("iframe");
        childFrame.src = "javascript:'<html></html>';";
        childFrame.style.position = "absolute";
        childFrame.style.display = "none";
        childFrame.scrolling = "no";
        childFrame.frameBorder = "0";
        childFrame.tabIndex = "-1";
        childFrame.style.left = oCtrl.style.left;
        childFrame.style.top = oCtrl.style.top;
        childFrame.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
        oCtrl.parentNode.insertBefore(childFrame, oCtrl);
        oCtrl._hideWindowedElementsIFrame = childFrame;
    }

    childFrame.style.display = oCtrl.style.display;
    if (oCtrl.currentStyle && oCtrl.currentStyle.zIndex) {
        childFrame.style.zIndex = oCtrl.currentStyle.zIndex;
    }
    else if (oCtrl.style.zIndex) {
        childFrame.style.zIndex = oCtrl.style.zIndex;
    }


}

function removeIframe(oCtrl) {
    if (oCtrl._hideWindowedElementsIFrame) {
        oCtrl._hideWindowedElementsIFrame.style.display = 'none';
    }
}


function ccSameBilling() {

    var chkSame = $get(clientBase + 'cphContent_cphContent_chkSame');
    var sAddr1 = $get(clientBase + 'cphContent_cphContent_txtSAddr1');
    var sAddr2 = $get(clientBase + 'cphContent_cphContent_txtSAddr2');
    //var sAddr3 = $get(clientBase + 'cphContent_cphContent_txtSAddr3');
    var sCity = $get(clientBase + 'cphContent_cphContent_txtSCity');
    //var sZip = $get(clientBase + 'cphContent_cphContent_txtSZip');

    if (chkSame.checked == 1) {
        sAddr1.value = $get(clientBase + 'cphContent_cphContent_txtAddr1').value;
        sAddr2.value = $get(clientBase + 'cphContent_cphContent_txtAddr2').value;
        //sAddr3.value = $get(clientBase + 'cphContent_cphContent_txtAddr3').value;
        sCity.value = $get(clientBase + 'cphContent_cphContent_txtCity').value;
        //sZip.value = $get(clientBase + 'cphContent_cphContent_txtZip').value;

    }
    else {
        sAddr1.value = '';
        sAddr2.value = '';
        //sAddr3.value = '';
        sCity.value = '';
        //sZip.value = '';
    }



}


function GetDate(CtrlName) {
    var MyControl = $get(CtrlName);

    ChildWindow = window.open(SiteRoot + '/Calendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName + '&StartVal=' + MyControl.value, "PopUpCalendar", "width=270,height=300,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no");
}


function disableMe(id) {
    $get(id).disabled = true;
}


function isEnterKey(e) {
    // process only the Enter key
    if (e.keyCode == 13) {

        //Stop the current event from occuring and return true so we can do the event we want to do
        //if IE
        if (window.event) {
            window.event.returnValue = false;
            window.event.cancel = true;
        }
        //if FF
        else if (e && e.preventDefault) {
            e.preventDefault();
        }

        return true;
    }
    else {

        return false;
    }
}

function processHomeSearch(event) {
    if (isEnterKey(event)) {
        HomeSearchGo();
    }
}

function HomeSearchGo() {
    if (clearTextEntered('ctl00_ctl00_ctl00_cphSite_txtSearch', 'Product Search', 'No search entered')) {

        document.location.href = '/Products.aspx?search=' + escape($get('ctl00_ctl00_ctl00_cphSite_txtSearch').value);
    }
}

//function processEnterKey(event, buttonID) {
//    if (isEnterKey(event)) {
//        obj = $get(buttonID);
//        if (obj) {
//            obj.click();
//        }
//    }
//}



function getddlValue(ctrl) {
    var c = $get(ctrl);
    var iReturn;
    iReturn = c.options[c.selectedIndex].value;
    return iReturn;
}


function clearText(id, text) {
    if ($get(id).value == text) {
        $get(id).value = '';
        $get(id).style.color = '#000000';
        $get(id).style.fontStyle = "normal";
    }
}

function clearTextEntered(id, text, msg) {
    if ($get(id).value != text) {
        return true;
    }
    else {
        alert(msg);
        return false;
    }

}



function IsNumeric(sText) {
    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;

}




function reviewValidate(comment, rating) {
    if ($get(rating).selectedIndex > 0 && $get(comment).value.length == 0) {
        alert('Please leave a short comment with your rating');
        return false;
    }
    else if ($get(rating).selectedIndex == 0) {
        alert('Please select a rating');
        return false;
    }
    else {
        return true
    }


}

function getElement(strElement) {

    if ($get(strElement)) {
        return document.getElementById(strElement);
        // IE
    }
    else if (document.all) {
        return document.all[strElement];
        // Netscape
    }
    else if (document.layers) {
        return document[strElement];
    }
}




function MakeRequest() {
    var http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
    return http_request;
}



function getSilverlightVersion() {
    var version = '';
    var container = null;
    try {
        var control = null;
        if (window.ActiveXObject) {
            control = new ActiveXObject('AgControl.AgControl');
        }
        else {
            if (navigator.plugins['Silverlight Plug-In']) {
                container = document.createElement('div');
                document.body.appendChild(container);
                container.innerHTML = '<embed type="application/x-silverlight" src="data:," />';
                control = container.childNodes[0];
            }
        }
        if (control) {
            if (control.isVersionSupported('2.0')) { version = 'Silverlight/2.0'; }
            else if (control.isVersionSupported('1.0')) { version = 'Silverlight/1.0'; }
        }
    }
    catch (e) { }
    if (container) {
        document.body.removeChild(container);
    }
    return version;
}




function showMenu(item) {
    var mnu = $get('mnu' + item);
    var tmnu = $get('tmnu' + item);
    mnu.style.display = 'block';

    if ((mnu.clientWidth + tmnu.style.posLeft) > 996) {
        mnu.style.left = (996 - mnu.clientWidth) + 'px';
    }
    else {
        mnu.style.left = tmnu.style.left;
    }



}

function NoMenu() {
    try {
        for (var x = 1; 7; x++) {
            $get('mnu' + x).style.display = 'none';
        }
    } catch (e) { }


}


function showAllSizesAndFlavors() {

    var tbl = $get('ctl00_ctl00_ctl00_cphSite_cphContent_cphContent_FormView1_divSizesFlavors');
    var lnk = $get('flavorsizeLink');


    if (tbl.style.display == 'block') {
        tbl.style.display = 'none';
        lnk.innerHTML = 'Other Sizes & Flavors';

    } else {
        tbl.style.display = 'block';
        lnk.innerHTML = 'Hide Sizes & Flavors';
    }



}


