jQuery(document).ready(function() {
    try {
        jQuery('img.tooltip').cluetip({ splitTitle: '|', cluetipClass: 'wctip' });
        //alert("1");
        jQuery('a.tooltip').cluetip({ showTitle: false, dropShadow: false, splitTitle: '|', cluetipClass: 'wctip', width: '150px' });
        jQuery('span.tooltip').cluetip({ showTitle: false, dropShadow: false, splitTitle: '|', cluetipClass: 'wctip' });
        jQuery('#minicartex').cluetip({
            local: true,
            hideLocal: true,
            cursor: 'pointer',
            closePosition: 'top',
            showTitle: false,
            positionBy: 'mouse',
            dropShadow: true,
            dropShadowSteps: '3',
            closePosition: 'top',
            closeText: '<div align="right"><img src="/images/close.gif" alt="" style="border:none;" /></div>',
            mouseOutClose: false,
            sticky: true,
            mouseOutClose: true
        });
    }
    catch (err) { alert(err) }
});

function changeModuleTitle(id, title) 
{
	try
	{
    	//jQuery("#"+id+"_dnnTITLE_lblTitle").get()[0].innerHTML = title;
	}
	catch(err){}
}

function ExpandAllRows(id)
{ 
    var ctrl = jQuery("a", jQuery("#"+id)).get()
    
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].className == "expander")
            TglRow(ctrl[i]);
    } 
}

function CollapseAllRows(id)
{
    var ctrl = jQuery("a", jQuery("#"+id)).get()
    
    for(var i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].className == "collapser")
            TglRow(ctrl[i]);
    }
}

function encodeMyHtml(ctrlFromID, ctrlToID) 
{
    try{
        // save to hiden filed
        jQuery('#'+ctrlToID).val(htmlEncode(jQuery('#'+ctrlFromID).val()));
        // clear textbox
        jQuery('#'+ctrlFromID).val("");
        return true;
    }
    catch(err)
    {
        return false;
    }
    return true;
} 
function decodeMyHtml(ctrlFromID, ctrlToID) 
{       
    jQuery('#'+ctrlToID).val(htmlDecode(jQuery('#'+ctrlFromID).val()));
} 
function htmlEncode(s) {
        var str = new String(s);
        str = str.replace(/&/g, "&amp;");
        str = str.replace(/</g, "&lt;");
        str = str.replace(/>/g, "&gt;");
        str = str.replace(/"/g, "&quot;");
        return str;
}
function htmlDecode(s) {
        var str = new String(s);
        str = str.replace("&amp;", "&" );
        str = str.replace("&lt;", "<" );
        str = str.replace("&gt;", ">" );
        str = str.replace("&quot;", "\"" );
        return str;
}
function encodeStaticTextInLanguageEditor(containerID)
{
    var inputs = jQuery("textarea", jQuery('#'+containerID)).get();
    for(var i=0;i<inputs.length;i++)
    {
        try{
            inputs[i].value = htmlEncode(inputs[i].value);
        }
        catch(er){
            alert(er)
            break;
        }
    }
}

function changePriceWay(ctrlShow, ctrlHide)
{
    jQuery("#"+ctrlShow).css("display", "block");
    jQuery("#"+ctrlHide).css("display", "none");
}


// hide module if it shouldn't be visible
function hideModule(ctrlModule, show)
{
    if (show.toLowerCase() == "false")
    {
       var div = jQuery("#"+ctrlModule).parents("div.wcInfoContainer").get();
       jQuery(div).css("display", "none");
    }
}

function showDiv(source, id) {
    jQuery(id).css('display', 'block');
    jQuery(source).css('cursor', 'default');
    //jQuery(source).attr('href', 'javascript:hideDiv('+source+','+id+')');
}

function hideDiv(source, id) {
    jQuery(id).css('display', 'block');
    //jQuery(source).attr('href', 'javascript:showDiv(' + source + ',' + id + ')');
}

function openOtherCountry(ddl) {
    location.href = jQuery('#'+ddl).val();
}

function showLostPassword() {
    jQuery.get("/Default.aspx?tabid=57&ctl=SendPassword", function(data) {
        var div = jQuery("#lostPassword"); 
        var lostPasswordContentID = ".containercontent_white";
        div.html(jQuery(lostPasswordContentID, data).html());
        div.css("display", "block");
        jQuery("#lostPasswordMessage").css("display", "none");
        jQuery("#lostPasswordMessageError").css("display", "none");
    });
}

function sendLostPassword(user) {
    jQuery.get("/Default.aspx?tabid=57&ctl=SendPassword&user=" + user, function(data) {
        jQuery("#lostPassword").css("display", "none");
        if (user.trim() != "" && jQuery("#dnn_ctr_ctl00_lblMessage", data).html() == null)
            jQuery("#lostPasswordMessage").css("display", "block");
        else if (user.trim() != "")
            jQuery("#lostPasswordMessageError").css("display", "block");
    });
}

function hideItemsInMiniCart() {
    //jQuery.get("/Default.aspx?tabid=177&hideContent=minicart", function(data) {
        
    //});
}


/* menu [START] */
var timeout;
var menus = Array();
//var $j = jQuery.noConflict();
var isIE = jQuery.browser.msie;
var pageLoaded = false;

if (window.addEventListener)
    window.addEventListener("load", pageLoad, false);
else if (window.attachEvent)
    window.attachEvent("onload", pageLoad);

function pageLoad() {
    pageLoaded = true;
    if (isIE) {
        // Finesse IE into not displaying "Click to activate and use this control"
        objects = document.getElementsByTagName("object");
        for (var i = 0; i < objects.length; i++) {
            objects[i].outerHTML = objects[i].outerHTML;
        }
    }
}
function DOMBrowser() {
    return document.body && document.body.style && document.getElementById;
}
function getX(elem) {
    var x = 0;
    if (elem.offsetParent)
        x = getX(elem.offsetParent);
    return x + elem.offsetLeft;
}
function getY(elem) {
    var y = 0;
    if (elem.offsetParent)
        y = getY(elem.offsetParent);
    return y + elem.offsetTop;
}
var lastMenu;
function enterMenu(elem, below) {
    if (DOMBrowser()) {
        parentDiv = elem.offsetParent.id;
        hideMenus(parentDiv, elem);
        showSubmenu(elem, below);
        if (timeout)
            clearTimeout(timeout);
    }
    return true;
}
function leaveMenu(elem) {
    if (DOMBrowser()) {
        lastMenu = "";
        if (elem)
            lastMenu = elem.offsetParent.id;
        timeout = setTimeout("hideMenus()", 500);
    }
    return true;
}
function getXPos(elem, child, below) {
    child.visible = false;
    // Temporarily set the display to block so that we can calculate offsetWidth/Height
    child.style.display = "block";
    parentX = getX(elem);
    if (below)
        x = parentX + 5;
    else
        x = parentX + elem.offsetWidth - 5;
    if (x + child.offsetWidth > document.body.clientWidth + document.body.scrollLeft) { // If the menu would appear offscreen:
        if (parentX - child.offsetWidth - document.body.scrollLeft + 5 > 0) { // If there's room to the left of the parent menu:
            x = parentX - child.offsetWidth + document.body.scrollLeft + 5;
        } else { // Fit as much in as possible:
            availSpace = (document.body.clientWidth - elem.offsetWidth) / 2;
            x = document.body.clientWidth + document.body.scrollLeft - child.offsetWidth;
            if (parentX > availSpace)
                x = 0;
            //Don't overlap the parent:
            if (x == parentX) x -= 5;
        }
    }
    child.style.display = "none";
    return x;
}
function getYPos(elem, child, below) {
    child.visible = false;
    // Temporarily set the display to block so that we can calculate offsetWidth/Height
    child.style.display = "block";
    parentY = getY(elem);
    if (below)
        y = parentY + elem.offsetHeight - 5;
    else
        y = parentY + 5;
    if (y + child.offsetHeight > document.body.clientHeight + document.body.scrollTop) { // If the menu would appear offscreen:
        if (parentY - child.offsetHeight - document.body.scrollTop + 20 > 0) { // If there's room above the parent menu:
            y = parentY - child.offsetHeight + document.body.scrollTop + 20;
        } else { // Fit as much in as possible:
            y = document.body.clientHeight + document.body.scrollTop - child.offsetHeight - 5;
            if (y < 0) y = 0;
        }
    }
    child.style.display = "none";
    return y;
}
function showSubMenu(id) { }
function showSubmenu(elem, below) {
    var id = elem.id + "_submenu";
    menu = document.getElementById(id);
    if (menu && lastMenu != id) {
        // Reset display so that browsers are not confused when we postion (Opera in particular)
        // No longer needed?  11/30/05 MO
        //menu.style.display = "none";

        //menu.style.top = getYPos(elem, menu, below);
        jQuery(menu).css("top", getYPos(elem, menu, below));
        //menu.style.left = getXPos(elem, menu, below);
        jQuery(menu).css("left", getXPos(elem, menu, below));
        //menu.style.zIndex = 1000;
        jQuery(menu).css("zIndex", 1000);
        //menu.style.display = "block";
        jQuery(menu).css("display", "block");

        tab = document.getElementById(elem.id + "_img");
        if (tab)
            tab.src = tab.src.replace(/(.*)_off\.(.*)/, "$1_on.$2");
        // Only create the iframe element if the page has been loaded.  Otherwise, 
        // "Operation aborted" messages appear and the page won't load.
        if (isIE && pageLoaded) {
            var ifr = document.createElement("IFRAME");
            if (ifr) {
                document.body.appendChild(ifr);
                ifr.style.position = "absolute";
                ifr.style.width = menu.offsetWidth;
                ifr.style.height = menu.offsetHeight;
                ifr.style.top = menu.style.top;
                ifr.style.left = menu.style.left;
                ifr.style.zIndex = menu.style.zIndex - 1;
                ifr.style.display = "block";
                menu.iframe = ifr;
            }
        }
        menus.push(menu);
    }
}
function hideMenus(elemID, currentTarget) {
    if (currentTarget) {
        var nextChild = document.getElementById(currentTarget.id + "_submenu");
        // If we're about to re-show the currently displayed menu, bail early to
        // avoid flickering
        if (nextChild && nextChild.id == lastMenu)
            return;
    }
    // Hide up to the passed element:
    var elem;
    if (elemID)
        elem = document.getElementById(elemID);
    while (men = menus.pop()) {
        if (elem && men.id == elem.id) {
            menus.push(men); // Put the match back into the array
            return;
        } else {
            men.style.display = "none";
            if (isIE && men.iframe)
                document.body.removeChild(men.iframe);
            tab = document.getElementById(men.id.replace(/(.*)_submenu/, "$1") + "_img");
            if (tab)
                tab.src = tab.src.replace(/(.*)_on\.(.*)/, "$1_off.$2");
        }
    }
}     
/* menu [END] */