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;
}

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 mp_ZoomImagePopup(url)
{
    var win = window.open(url, 'zoomPop', 'left=20,top=20,resizable=yes,scrollbars=yes,width=610,height=600');
}  

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";
   }
} 