function showAddingToCartMessage (buttonsID, txtID, messageID, max)
{
    var value = 0;
    var txtBox = document.getElementById(txtID);
    
    if (txtBox)
        value = parseInt(txtBox.value);

    if (value > 0 && value <= max)
    {
        document.getElementById(buttonsID).style.display='none';
        document.getElementById(messageID).style.display='block';
    }
}

function ValidateQuantityToCart(sender, args)
{
    try
    {
        // get the max from the error msg that is on the sender
        var txt = sender.innerHTML.substring(sender.innerHTML.lastIndexOf(' '), sender.innerHTML.length - 1);
        var max = parseInt(txt);
        var value = parseInt(args.Value);

        if (value < 1 || value > max)
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    catch(ex)
    {
        args.IsValid = false;
    }
}

function hideModalPopup()
{
    var modalPopup2 = $find('modalPopup');
    modalPopup2.hide();
    
    return true;    
} 

function hidePopupPanel()
{
    var modalPopup = $find('popupPanel');
    modalPopup.hidePopup();
}

function showPopupPanel()
{
    var modalPopup = $find('popupPanel');
    modalPopup.showPopup();
}

function hideFlagPopup()
{
    AjaxControlToolkit.PopupControlBehavior.__VisiblePopup.hidePopup(); 
    return false;
}

function getPageWidth()
{
    var size;

    if (document.documentElement && document.documentElement.clientWidth)
    {
        size = document.documentElement.clientWidth;
    }
    else if (window.innerWidth)
    {
        size = window.innerWidth;
    }
    else if (document.body.clientWidth)
    {
        size = document.body.clientWidth;
    }

    var pageWidth = size;
    
    if (size > 1024)
        pageWidth = Math.max(1024, size);
    
    return pageWidth;
}

function getHeightOffset()
{
    var offset;
    
    if (navigator.userAgent.toLowerCase().indexOf('safari') != -1)
        offset = window.pageYOffset;
    else
        offset = document.documentElement.scrollTop;
        
    return offset;
}

//Used before adding GoAz hack for color/image options - Keep if we rip this out
//function switchImage(productViewImage, galleryImage, imgZoom)
//{
//    var pvsrc = '';
//    var zmsrc = '';
//    
//    //get the url for the standard view of this thumb
//    pvsrc = document.getElementById(galleryImage).attributes["value"].value;
//    //set the new standard src
//    document.getElementById(productViewImage).src = pvsrc;
//    
//    zmsrc = document.getElementById(galleryImage).attributes["zoom"].value;
//    zmsrc = zmsrc.replace(/'/g, "\\'");
//    var funcCall = "mp_ZoomImagePopup('" + zmsrc + "')";  
//    document.getElementById(imgZoom).onclick = new Function(funcCall);
//}

function switchImage(productViewImage, galleryImage, imgZoom, zoomUrl, standardUrl) {
    var pvsrc = '';
    var zmsrc = '';
    
    //get the url for the standard view of this thumb
    if (galleryImage == "null" || galleryImage == null) {
        pvsrc = standardUrl;
        zmsrc = zoomUrl;
    }
    else {
        if (document.getElementById(galleryImage).attributes["optionValue"] != null) {
            if (document.getElementById(galleryImage).attributes["ddl"] != null) {
                GoAzOptionSwitch(document.getElementById(galleryImage).attributes["ddl"].value, document.getElementById(galleryImage).attributes["optionValue"].value);
            }
        }
        pvsrc = document.getElementById(galleryImage).attributes["value"].value;
        zmsrc = document.getElementById(galleryImage).attributes["zoom"].value;
    }
    zmsrc = zmsrc.replace(/'/g, "\\'");
    //set the new standard src
    document.getElementById(productViewImage).src = pvsrc;
    
    var funcCall = "mp_ZoomImagePopup('" + zmsrc + "')";
    document.getElementById(imgZoom).onclick = new Function(funcCall);
}

function GoAzImageSwitch(ddl) {

    //Image to display
    if (ddl.attributes["imageUrl"] != null) {
        var imageFile = ddl.attributes["imageUrl"].value;
        var zoomImageFile = ddl.attributes["zoomUrl"].value;
        var standardImage = ddl.attributes["standardID"].value;
        var zoomImage = ddl.attributes["zoomID"].value;

        document.getElementById(standardImage).src = imageFile;

        switchImage(standardImage, null, zoomImage, zoomImageFile, imageFile);
    }
}

function GoAzOptionSwitch(ddl, optionValue) {
    var ddlValue = document.getElementById(ddl);
    for (var i = 0; i < ddlValue.options.length; i++) {
        if (ddlValue.options[i].value == optionValue) {
            ddlValue.options[i].selected = true;
        }
    }
}

function mp_ZoomImagePopup(url)
{
    var win = window.open(url, 'zoomPop', 'left=20,top=20,resizable=yes,scrollbars=yes,width=610,height=600');
}
function popWindow(url, windowProperties) {

    var win = window.open(url, 'popWindow', windowProperties);
}
function popWindow2(url) {

    var win = window.open(url, 'popWindow');
}
function popFaq(faqurl)
{
	//var faqurl = '';
	//faqurl = faqurl.replace('fff', article_id);
	var win=window.open(faqurl, 'spop', 'left=20,top=20,resizable=yes,scrollbars=yes,width=610,height=620');
}

/* Text Box character counter */
function CounterSettings(){}

CounterSettings.checkCount = function(textboxToCount, counter, maxLength)
{
    if (document.getElementById(counter))
    {
        limitText(document.getElementById(textboxToCount), maxLength);
        document.getElementById(counter).innerHTML = maxLength - document.getElementById(textboxToCount).value.length + '';
    }
}

function limitText(limitField, limitNum) 
{
	if (limitField.value.length >= limitNum) 
	{
		limitField.value = limitField.value.substring(0, limitNum);
	} 
}


// Cookies
function bzCookieDomain() {
    var hname = window.location.hostname;
    var tldstart = hname.lastIndexOf('.');
    if (tldstart < 0) {
        return '.' + hname;
    }
    else {
        var dname = '';
        if (hname.lastIndexOf('.', tldstart - 1) > -1) {
            dname = hname.substr(hname.lastIndexOf('.', tldstart - 1));
        }
        else {
            dname = '.' + hname;
        }
        return dname;
    }
}
function bzSetMemCookie(name, value, years) {
    var currentDT = new Date();
    var curCookie = name + "=" + value + "; path=/; domain=" + bzCookieDomain();
    document.cookie = curCookie;
}
function bzSetCookie(name, value, years) {
    var currentDT = new Date();
    var expires = new Date(Date.parse(currentDT.getDay() + "/" + currentDT.getMonth() + "/" + (currentDT.getFullYear() + years)));
    var curCookie = name + "=" + value +
      "; expires=" + expires.toGMTString() + "; path=/; domain=" + bzCookieDomain();
    document.cookie = curCookie;
}
function bzReadCookie(name) {
    var cookiecontent = new String();
    if (document.cookie.length > 0) {
        var cookiename = name + '=';
        var cookiebegin = document.cookie.indexOf(cookiename);
        var cookieend = 0;
        if (cookiebegin > -1) {
            cookiebegin += cookiename.length;
            cookieend = document.cookie.indexOf(";", cookiebegin);
            if (cookieend < cookiebegin) {
                cookieend = document.cookie.length;
            }
            cookiecontent = document.cookie.substring(cookiebegin, cookieend);
        }
    }
    return unescape(cookiecontent);
}
function AdultHoverImageIn()
{
    var divStore = document.getElementById("ctl00_cphStoreBody_ctlProducts_adultProductImage");
    var div = document.getElementById("ctl00_ctl00_cphBody_cphBody_ctlProducts_adultProductImage");
    if(div != null)
    {
        div.className = "adultImageHover";
    }
    if(divStore != null)
    {
        divStore.className = "adultImageHover";
    }
} 

function AdultHoverImageOut()
{
   var divStore = document.getElementById("ctl00_cphStoreBody_ctlProducts_adultProductImage");
   var div = document.getElementById("ctl00_ctl00_cphBody_cphBody_ctlProducts_adultProductImage");
   if(div != null)
   {
        div.className = "adultImage";
   }
   if(divStore != null)
   {
        divStore.className = "adultImage";
   }
}

function SetShopFilterVisibility(showControl) 
{
    var brandControl = document.getElementById("ctl00_ctlFilterNavigation_divBrandFilter");
    var catalogControl = document.getElementById("ctl00_ctlFilterNavigation_divCatalogFilter");
    if (showControl == 'brand') 
    {
        brandControl.style.display = 'block';
        catalogControl.style.display = 'none';
    }
    else if (showControl == 'catalog') 
    {
        catalogControl.style.display = 'block';
        brandControl.style.display = 'none'
    }
}
function ShowTopCatalogs() 
{
    var catalogControl = document.getElementById("ctl00_ctlFilterNavigation_divCatalogFilter");
    catalogControl.style.display = 'block';
}