﻿var __nonMSDOMBrowser = (window.navigator.appName.toLowerCase().indexOf('explorer') == -1);

function ShowCatalogDialog(zoneID, postBackReference) {
    var features = "width=400,height=350,resizable=yes,status=no,scrollbars=yes";
    var url = dialogPage + "?postbackReference=" + postBackReference ;
    DisplayDialog(url, features, "catalogdialog") ;
}

function DisplayDialog(url, opts, name) {
	if( opts == null || opts == "undefined" )
		opts = "width=600,height=350,resizable=yes,status=no,scrollbars=yes" ;
		
	var winName = (name) ? winName : "" ;
	
	if( DisplayDialog.arguments.length >= 2 )
		opts =  DisplayDialog.arguments[1] ;
		
	var hwnd = window.open( url, winName, opts ) ;
	if( (document.window != null ) && (!hwnd.opener) )
		hwnd.opener = document.window ;
		
	hwnd.moveTo( 80, 80 ) ;
}

function CloseDialog() {
	if( window.opener ) {
		window.opener.focus() ;
		}		
	self.close() ;
}

function CloseCatalogDialog(postBackReference, returnValue) {

    if( window.opener ) {
		window.opener.DoCatalogPostBack(postBackReference, returnValue) ;
	
	    CloseDialog() ;
    }
}

function DoCatalogPostBack(postBackReference, returnValue) {
    eval(postBackReference.replace("[[WEBPART]]", returnValue));
}

function ToggleEditorDisplay( divClientID, imgClientUrl, expandImageUrl, minimizeImageUrl ) {

    var el = document.getElementById(divClientID) ;
    if( el.style.display=='none' ) {
        el.style.display='';
        document.images[imgClientUrl].src= minimizeImageUrl;
    } else {
        el.style.display='none';
        document.images[imgClientUrl].src= expandImageUrl;
    }
}

function CommitSearch( event, e ) {
	var keyCode = (event) ? event.keyCode : keyStroke.which; 
	if (keyCode == 13) {
		top.location = googleSearchUrl + e.value ;
		return false ;
	}else{
		return true ;
	}
}

function CommitSearch2( elementId ) {
	var e = document.getElementById( elementId ) ; 
	top.location = googleSearchUrl + e.value ;
}

function ToggleVisibility(elemId) {
  var ctr = document.getElementById(elemId);
  if(ctr != null) {
    if(ctr.style.display == "none") {
      ctr.style.display = "";
    }
    else {
      ctr.style.display = "none";
    }
	}
}

function ChangeVisibility(hideId, showId) {
  var hideTextLayer = document.getElementById(hideId);
  var showTextLayer = document.getElementById(showId);
  if(showTextLayer != null) {
    showTextLayer.style.display = "";
  }
  if(hideTextLayer != null) {
    hideTextLayer.style.display = "none";
  }
}

function ToggleHtml(elemId, val1, val2) {
  var ctr = document.getElementById(elemId);
  if(ctr != null) {
    if(ctr.innerHTML == val1) {
      ctr.innerHTML = val2; 
    } else {
      ctr.innerHTML = val1;
    }
  }
}

function FireDefaultButton(event, target) {
    if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {
        var defaultButton;
        if (__nonMSDOMBrowser) {
            defaultButton = document.getElementById(target);
        }
        else {
            defaultButton = document.all[target];
        }
        if (defaultButton && typeof(defaultButton.click) != "undefined") {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }
    return true;
}

function SetFocus(id) {
    var ctr = document.getElementById(id);
    if(ctr != null)
        ctr.focus();
}

function st(e,id) /*ShowTooltip*/
{
	var tooltip = (document.getElementById) ?
		 document.getElementById(id) : eval("document.all[id]");
	if (tooltip != null)
	{
	    if(tooltip.style.visibility == "visible")
	    {
	        ht(id);
	        return;
	    }
	    
	    var ch = tooltip.clientHeight;
	    if(document.all) /*IE*/
	    {
	        var scrollLeft = 0, scrollTop = 0;
	        if (document.compatMode && document.compatMode != "BackCompat")
	        {
               scrollLeft = document.documentElement.scrollLeft;
               scrollTop = document.documentElement.scrollTop;
            }
            else
            {
               scrollLeft = document.body.clientWidth;
               scrollTop = document.body.clientWidth;
            }
	        tooltip.style.left = event.clientX + scrollLeft - 50;
            tooltip.style.top = event.clientY + scrollTop - ch - 10;
        }
        else
        {
            tooltip.style.left = (e.pageX - 50) + "px";;
            tooltip.style.top = (e.pageY - ch - 10) + "px";
        }
		tooltip.style.visibility = "visible";
	}
}

function ht(id) /*HideTooltip*/
{
	var tooltip = (document.getElementById) ?
	 document.getElementById(id) : eval("document.all[id]");
	if (tooltip != null)
	{
		tooltip.style.visibility = "hidden";
	}
}

function Null()
{   return; }

function ShowT(t) {
    var activeDiv = document.getElementById("ctl00_mp_subdiv"+t);
    var activeTab = document.getElementById("ti"+t);
    
    for(i = 1; i <= 5; i++) {
        var aDiv = document.getElementById("ctl00_mp_subdiv"+i);
        var aTab = document.getElementById("ti"+i);

        if(aDiv != null && i >= t) 
            aDiv.style.display = "";
        else
        {
            if(aDiv != null)
                aDiv.style.display = "none";
            else
            {
                if(aTab != null && aTab.className != "pder1")
                    aTab.className = "pder1";
                break;
            }
        }

        if(aTab != null && aTab.className != "pder1")
            aTab.className = "pder1";
    }
    
    if(activeDiv != null) activeDiv.style.display = "";
    if(activeTab != null && activeTab.className != "pder2") activeTab.className = "pder2";
    var afC = document.getElementById("af");
    try { afC.focus(); } catch(err) {}
}

function ShowX(t) {
	var activeDiv = document.getElementById("ctl00_mp_subdiv" + t);
	var activeTab = document.getElementById("ti" + t);

	for (i = 1; i <= 5; i++) {
		var aDiv = document.getElementById("ctl00_mp_subdiv" + i);
		var aTab = document.getElementById("ti" + i);

		if (aDiv != null && i == t) 
		{
			aDiv.style.display = "";
			aDiv.style.visibility = "visible";
		}
		else {
			if (aDiv != null) 
			{
				aDiv.style.display = "none";
				aDiv.style.visibility = "hidden";
			}
			else {
				if (aTab != null && aTab.className != "pder1")
					aTab.className = "pder1";
				continue;
			}
		}

		if (aTab != null && aTab.className != "pder1")
			aTab.className = "pder1";
	}

	if (activeDiv != null) 
	{
		activeDiv.style.display = "";
		activeDiv.style.visibility = "visible"; 
	}
	if (activeTab != null && activeTab.className != "pder2") activeTab.className = "pder2";
	var afC = document.getElementById("af");
	try { afC.focus(); } catch (err) { }
}

function ShowP(w,t,c) {
    if(t == 0)
    {
        for(i = 2; i <= 100; i++) {
            var aDiv = document.getElementById("ctl00_mp_pd_ponuky1_gvProducts_wrcp_"+w+"_"+i);
            if(aDiv != null) 
                aDiv.style.display = "";
            else
                break;
        }
        document.getElementById(c + "_dp0_" + w).style.display = "none";
        document.getElementById(c + "_dp1_" + w).style.display = "";
    }
    else
    {
        for(i = 2; i <= 100; i++) {
            var aDiv = document.getElementById("ctl00_mp_pd_ponuky1_gvProducts_wrcp_"+w+"_"+i);
            if(aDiv != null) 
                aDiv.style.display = "none";
            else
                break;
        }
        document.getElementById(c + "_dp0_" + w).style.display = "";
        document.getElementById(c + "_dp1_" + w).style.display = "none";
    }
    var afC = document.getElementById("af");
    try { afC.focus(); } catch(err) {}
}

//Delete price alert
function DAP(id) {
    Search.DAP(id, DAPOnSucceeded, DAPOnFailed);
}
function DAPOnSucceeded(res) {
    cDAP();
}
function DAPOnFailed(error) {
    alert(error.get_message());
}
//Refresh price alerts
function cDAP() {
    Search.cDAP(cDAPOnSucceeded, cDAPOnFailed);
}
function cDAPOnSucceeded(res) {
    var result = eval('(' + res + ')');
    var c0 = $("#ctl00_rp_ucQuickLoginAuth_ucUserSupport1_usr_itm_ap4_header");
    var c1 = $("#ctl00_rp_ucQuickLoginAuth_ucUserSupport1_usr_itm_ap4_content");
    if (c1.length > 0) {
        c0[0].innerHTML = result.title;        
        c1[0].innerHTML = result.content;
    }
}
function cDAPOnFailed(error) {
    alert(error.get_message());
}
//Delete whishlist
function DW(produkt_id) {
    Search.DW(produkt_id, DWOnSucceeded, DWOnFailed);
}
function DWOnSucceeded(res) {
    cDW();
}
function DWOnFailed(error) {
    alert(error.get_message());
}
//Refresh whishlist
function cDW() {
    Search.cDW(cDWOnSucceeded, cDWOnFailed);
}
function cDWOnSucceeded(res) {
    var result = eval('(' + res + ')');
    var c0 = $("#ctl00_rp_ucQuickLoginAuth_ucUserSupport1_usr_itm_ap3_header");
    var c1 = $("#ctl00_rp_ucQuickLoginAuth_ucUserSupport1_usr_itm_ap3_content");
    if (c1.length > 0) {
        c0[0].innerHTML = result.title;
        c1[0].innerHTML = result.content;
    }
}
function cDWOnFailed(error) {
    alert(error.get_message());
}
