﻿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() {
	var oMenu = document.getElementById("menuHorizontal").getElementsByTagName("LI");
	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);
    }
}

function getkey(e) {
	var code;
	if (!e)
		e = window.event; // nastaveni pro IE
	if (e.keyCode)
		code = e.keyCode; // IE a Mozilla
	else
		if (e.which)
		code = e.which; // NN4
	return code;
}

String.Format = function(text) {
	if (arguments.length <= 1) { return text; }
	var tokenCount = arguments.length - 2;
	for (var token = 0; token <= tokenCount; token++) { text = text.replace(new RegExp('\\{' + token + '\\}', 'gi'), arguments[token + 1]); }
	return text;
};

String.IsNullOrEmpty = function(text) {
	if (text == null || text == '') { return true } { return false };
}

String.prototype.Trim = function(chars) {
	return this.RTrim(chars).LTrim(chars);
}
String.prototype.LTrim = function(chars) {
	chars = chars || "\\s";
	return this.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
String.prototype.RTrim = function(chars) {
	chars = chars || "\\s";
	return this.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}