﻿function switchImage(imgName, imgSrc, holderSrc, holder) {
    var url = document.getElementById(holder);
    var imageUrl = unescape(imgSrc);
    var imageBigUrl = unescape(holderSrc);
    if (url != null) url.href = imageBigUrl;
    if (document.images) {
        if (imgSrc != "none") {
            document.images[imgName].src = imageUrl;
        }
    }
}

function switchImageWithoutLightBox(imgName, imgSrc) {
    var imageUrl = unescape(imgSrc);
    if (document.images) {
        if (imgSrc != "none") {
            document.images[imgName].src = imageUrl;
        }
    }
}

function callMenuSwitch(idElement,THIS,idDisplay) {
    document.getElementById('divCategoryNavigation').style.display = "none";
    document.getElementById('divManufacturerNavigation').style.display = "none";
    document.getElementById(idDisplay).style.display = "block";
}

function callSwitchVisibilityDropDownBoxsIe6Fix(VisibilitySwitch) {
    if (browser == "Microsoft Internet Explorer" && ieversion <= 6) {
        var TagNameSelect = document.getElementsByTagName("select");
        for (var e = 0; e < TagNameSelect.length; e++) {
            if (TagNameSelect[e].className != "selectSortDropDownList") {
                TagNameSelect[e].style.visibility = VisibilitySwitch;
            }
        }
    }
}

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
    var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
    var browser = navigator.appName;
}

var LastSelectedTabContentID = "";
var LastButtonID = "";
var LastButtonclass = "";
function callFilterSwitch(cssClass, btnHolder, idDisplay) {
    callSwitchVisibilityDropDownBoxsIe6Fix('hidden');
    var lastSelectedTabContent = document.getElementById(LastSelectedTabContentID);
    if (lastSelectedTabContent != null) {
        lastSelectedTabContent.style.display = "none";
    }

    var lastButton = document.getElementById(LastButtonID);
    var f = 0;
    var classNameString = "";
    if (lastButton != null) {

        if (browser == "Microsoft Internet Explorer" && ieversion <= 6) {
            lastButton.className = LastButtonclass;
            var spanElement = document.getElementById(LastButtonID).childNodes;
            var spanElementTotal = document.getElementById(LastButtonID).childNodes.length;
            for (f = 0; f < spanElementTotal; f++) {
                if (spanElement[f].nodeName == "SPAN") {
                    classNameString = spanElement[f].className;
                    switch (classNameString) {
                        case 'BtnLeft':
                            spanElement[f].style.background = 'url(../App_Themes/Leloo/images/BtnLeftBlack.png)';
                            break;
                        case 'BtnMiddle':
                            spanElement[f].style.background = 'url(../App_Themes/Leloo/images/BtnMiddleBlack.png)';
                            break;
                        case 'BtnRight':
                            spanElement[f].style.background = 'url(../App_Themes/Leloo/images/BtnRightBlack.png)';
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        else {
            lastButton.className = LastButtonclass;
        }
    }
    
    document.getElementById('divOver').style.display = "block";
    document.getElementById('divOver').onclick = function () {callCloseLightBoxOverflow('Filters'); };
    document.getElementById('contentFilters').style.display = "block";
    document.getElementById(idDisplay).style.display = "block";

    if (browser == "Microsoft Internet Explorer" && ieversion <= 6) {
        document.getElementById(btnHolder).className = "BtnHolder FloatLeft";
        var spanElement2 = document.getElementById(btnHolder).childNodes;
        var spanElementTotal2 = document.getElementById(btnHolder).childNodes.length;
        for (f = 0; f < spanElementTotal2; f++) {
            if (spanElement2[f].nodeName == "SPAN") {
                classNameString = spanElement2[f].className;
                switch (classNameString) {
                    case 'BtnLeft':
                        spanElement2[f].style.background = 'url(../App_Themes/Leloo/images/BtnLeftYellow.png)';
                        break;
                    case 'BtnMiddle':
                        spanElement2[f].style.background = 'url(../App_Themes/Leloo/images/BtnMiddleYellow.png)';
                        break;
                    case 'BtnRight':
                        spanElement2[f].style.background = 'url(../App_Themes/Leloo/images/BtnRightYellow.png)';
                        break;
                    default:
                        break;
                }
            }
        }
    }
    else {
        document.getElementById(btnHolder).className = "BtnHolder FloatLeft Yellow";
    }
    
    
    //document.getElementById(btnHolder).setAttribute('class', 'BtnHolder FloatLeft Yellow');
    LastSelectedTabContentID = idDisplay;
    LastButtonID = btnHolder;
    LastButtonclass = cssClass;
    
}

function callCloseLightBoxOverflow(param, flashId) {
    callSwitchVisibilityDropDownBoxsIe6Fix('visible');
    document.getElementById('divOver').style.display = "none";
    if (param != "VideoLightBox") {
        document.getElementById('contentFilters').style.display = "none";
        var lastButton = document.getElementById(LastButtonID);
        if (lastButton != null) {
            if (browser == "Microsoft Internet Explorer" && ieversion <= 6) {
                lastButton.className = LastButtonclass;
                var spanElement = document.getElementById(LastButtonID).childNodes;
                var spanElementTotal = document.getElementById(LastButtonID).childNodes.length;
                for (var f = 0; f < spanElementTotal; f++) {
                    if (spanElement[f].nodeName == "SPAN") {
                        var classNameString = spanElement[f].className;
                        switch (classNameString) {
                            case 'BtnLeft':
                                spanElement[f].style.background = 'url(../App_Themes/Leloo/images/BtnLeftBlack.png)';
                                break;
                            case 'BtnMiddle':
                                spanElement[f].style.background = 'url(../App_Themes/Leloo/images/BtnMiddleBlack.png)';
                                break;
                            case 'BtnRight':
                                spanElement[f].style.background = 'url(../App_Themes/Leloo/images/BtnRightBlack.png)';
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            else {
                lastButton.className = LastButtonclass;
            }
        }
    }
    else {
        document.getElementById('FlashLightBoxHolder').style.visibility = "hidden";
        callToActionscript(flashId, videoUrl, "StopVideo");
    }
}

function onUpdating() {
    // get the update progress div
    var updateProgressDiv = $get('updateProgressDiv');
    // make it visible
    updateProgressDiv.style.display = '';

    //  get the gridview element        
    var gridView = $get('<%= this.gvCustomers.ClientID %>');

    // get the bounds of both the gridview and the progress div
    var gridViewBounds = Sys.UI.DomElement.getBounds(gridView);
    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);

    //    do the math to figure out where to position the element (the center of the gridview)
    var x = gridViewBounds.x + Math.round(gridViewBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
    var y = gridViewBounds.y + Math.round(gridViewBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);

    //    set the progress element to this position
    Sys.UI.DomElement.setLocation(updateProgressDiv, x, y);
}

function onUpdated() {
    // get the update progress div
    var updateProgressDiv = $get('updateProgressDiv');
    // make it invisible
    updateProgressDiv.style.display = 'none';
}


var urlAddress = ""; 
var pageName = ""; 
function bookmarksite() {
    if (window.sidebar) { // Mozilla Firefox Bookmark
        //alert("Firefox");
        window.sidebar.addPanel(pageName, urlAddress, "");
    } else if (window.external && browser == "Microsoft Internet Explorer") { // IE Favorite
        //alert("IE");
        window.external.AddFavorite(urlAddress, pageName);
    }
    /*else if (window.opera && window.print) { // Opera Hotlist
    //alert("opera");
    var elem = document.createElement('a');
    elem.setAttribute('href', urlAddress);
    elem.setAttribute('title', pageName);
    elem.setAttribute('rel','sidebar');
    elem.click();
    return false;
    }*/
    else {
        alert(alertString);
    }
}

function changeSizeVideoLightBox(width, height, elementID) {
    document.getElementById(elementID).style.width = width + 'px';
    document.getElementById(elementID).style.height = height + 'px';
    document.getElementById("FlashLightBox").style.width = width + 'px';
    document.getElementById('FlashLightBoxHolder').style.visibility = "visible";
}

var videoUrl = "";
var maxWidth = "";
var maxHeight = "";
var minWidth = "";
var minHeight = "";
var flashId = "";
function callVideoLightBox(FlashId, VideoUrl, event, MaxWidth, MaxHeight, MinWidth, MinHeight) {
    callSwitchVisibilityDropDownBoxsIe6Fix('hidden');
    videoUrl = VideoUrl;
    maxWidth = MaxWidth;
    maxHeight = MaxHeight;
    minWidth = MinWidth;
    minHeight = MinHeight;
    flashId = FlashId;
    //document.getElementById(flashId).setAttribute('flashvars', 'varMaxWidth=' + MaxWidth + '&varMaxHeight=' + MaxHeight + 'varMinWidth=' + MinWidth + '&varMinHeight=' + MinHeight +'&varUrl=' + VideoUrl + '&varId=InitFlashPlayer');
    document.getElementById('divOver').style.display = 'block';
    document.getElementById('FlashLightBoxHolder').style.visibility = "visible";
    if (imUp == "ImUP") {
        document.getElementById('FlashLightBoxHolder').style.visibility = "hidden";
    }
    callToActionscript(FlashId, VideoUrl, event, MaxWidth, MaxHeight, MinWidth, MinHeight);
}

function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}

function callToActionscript(FlashId, str, event, maxWidth, maxHeight, minWidth, minHeight) {
        if (imUp == "ImUP") {
            getFlashMovie(FlashId).sendToActionscript(str, event, maxWidth, maxHeight, minWidth, minHeight);
        }
}

var imUp = "";
function sendToJavaScript(str) {
    document.getElementById('FlashLightBoxHolder').style.visibility = "hidden";
    if (imUp != "ImUP") {
        imUp = str;
        callToActionscript(flashId, videoUrl, "StartPlayer", maxWidth, maxHeight, minWidth, minHeight);
    }
}


function doClientClick(buttonName,e)
{
    var key;
    if(window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox
    
    if (key == 13)
    {
        var btn = document.getElementById(buttonName);
        if (btn != null)
        { //If we find the button click it
            btn.click();
            event.keyCode = 0
        }
    }
}

