﻿function openDialogWindow(cUrl, nWidth, nHeight, lFullScreen) {
    var nTop;
    var nLeft;
    
	if (lFullScreen) {
	    nWidth = screen.width - 8;
	    nHeight = screen.height - 80;
	    nTop = 0;
	    nLeft = 0;
	} else {
	    if (!nWidth) nWidth = 600;
	    if (!nHeight) nHeight = 250;
	    nTop = (screen.height / 2) - (nHeight / 2);
	    nLeft = (screen.width / 2) - (nWidth / 2);
	}
	window.open(cUrl,'','width='+nWidth+',height='+nHeight+',top='+nTop+',left='+nLeft+',status=1,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0');
	return false;
}

function left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0,n);
}

function openWindow(cURL) {
    window.open(cURL, '_blank', '');
}

function getDocumentHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function getDocumentWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  } else if (obj.x)
  curleft += obj.x;
  return curleft;
}

function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  } else if (obj.y)
  curtop += obj.y;
return curtop;
}

function addOnLoadEvent(func) {
    var oldOnLoad = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldOnLoad) {
                oldOnLoad();
            }
            func();
        }
    }
}

/********************* menu **************************/
var oPrevSelectedMenu;

/* for horizontal menu only - collapse submenu on mouseover */
menuHover = function() {
    // TODO - otestovat existenci - lita do chyby
    var oMenu = document.getElementById("menuHorizontal");
    if (oMenu) {
        oMenu = document.getElementById("menuHorizontal").getElementsByTagName("LI");
        if (oMenu) {
	        for (var i=0;i<oMenu.length;i++) {
		        oMenu[i].onmouseover=function() {
			        this.className += " menuHover";
		        }
		        oMenu[i].onmouseout=function() {
			        this.className = this.className.replace("menuHover", "");
		        }
	        }
	    }
    }
}

function showSubMenu(oThis) {
	if (oPrevSelectedMenu) {
		oPrevSelectedMenu.className = oPrevSelectedMenu.className.replace(' displaySubMenu', '');
	};
	if (oThis) {
		oThis.className = oThis.className + ' displaySubMenu';
		oPrevSelectedMenu = oThis;
	};
}

function setCss(lChecked, theClass, theStyle, theValue) {
   var CSSRules;

   if (!lChecked) {
	 theValue = '';
   }

   if (document.all) {
     CSSRules = 'rules'
   } else if (document.getElementById) {
     CSSRules = 'cssRules'
   }

   for (var i = 0; i < document.styleSheets[0][CSSRules].length; i++) {
     if (document.styleSheets[0][CSSRules][i].selectorText == theClass) {
       document.styleSheets[0][CSSRules][i].style[theStyle] = theValue;
     }
   }
}

/********************* shop **************************/
function confirmation(langConfirmation) {
	return window.confirm(langConfirmation);
}

function addToBasket(oHref, cInputAmountID) {
    window.location = oHref + '&amount=' + window.document.getElementById(cInputAmountID).value;
    return false;
}

/********************* SWF object - Support function **************************/
//checks to see if target element is an object or embed element
function isObject(targetID) {
    var isFound = false;
    var el = document.getElementById(targetID);

    if (el && (el.nodeName === "OBJECT" || el.nodeName === "EMBED")) {
        isFound = true;
    }
    return isFound;
}

//creates an empty element to replace embedded SWF object
function replaceSwfWithEmptyDiv(targetID) {
    var el = document.getElementById(targetID);

    if (el) {
        var div = document.createElement("div");
        el.parentNode.insertBefore(div, el);
        //Remove the SWF
        swfobject.removeSWF(targetID);
        //Give the new DIV the old element's ID
        div.setAttribute("id", targetID);
    }
}

