/**
* Human2Code Project: js/dhtml.js, v 1.0 Wed Aug 27 16:32:41 CEST 2008 @647 /Internet Time/
* @copyright JRX | jrx.palitchi.org | 2008 
*
* js aktivni skript
* ovladani cookies
*
* pouziti: templates/header.tpl
**/

/* AntiFraming */
function antiFraming() {
	if (top.length != self.length)
		top.location.href = self.location.href;
}

/* Browser Resolution */
function browserWidth() {
	if (typeof(window.innerWidth) == "number") {
		var browserWidth = window.innerWidth;
		}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		var browserWidth  = document.documentElement.clientWidth;
		}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		var browserWidth = document.body.clientWidth;
		}
	
	return browserWidth;
}

function browserHeight() {
	if (typeof(window.innerWidth) == "number") {
		var browserHeight = window.innerHeight;
		}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		var browserHeight = document.documentElement.clientHeight;
		}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		var browserHeight = document.body.clientHeight;
		}
	
	return browserHeight;
}

/* URL Encode */
function php_urlencode(str) {
	str = escape(str);
	return str.replace(/[*+\/@]|%20/g,
		function (s) {
			switch (s) {
				case "*": s = "%2A"; break;
				case "+": s = "%2B"; break;
				case "/": s = "%2F"; break;
				case "@": s = "%40"; break;
				case "%20": s = "+"; break;
			}
			return s;
		}
	)
}

/* Cookies */
function SetCookie(cookiename, cookievalue) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;

  document.cookie = cookiename + "=" + escape(cookievalue) +
    ((expires == null) ? "" 	    : ("; expires=" + expires.toGMTString())) +
    ((path    == null) ? ""	    : ("; path="    + path                 )) +
    ((domain  == null) ? "" 	    : ("; domain="  + domain               )) +
    ((secure  == true) ? "; secure" : "");

  return;

}

function GetCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;

  while (i < clen) {
    var j = i + alen;

    if (document.cookie.substring(i, j) == arg)
      return GetCookieVal(j);

    i = document.cookie.indexOf(" ", i) + 1;

    if (i == 0) 
      break; 
  }

  return null;
}

function GetCookieVal(offset) {
  var endstr = document.cookie.indexOf(";", offset);

  if (("" + endstr) == "" || endstr == -1)
    endstr = document.cookie.length;

  return unescape(document.cookie.substring(offset, endstr));
}

function ParseCookies() {
  var cookie_string;
  var cookie_name;
  var cookie_value;
  var tmpcookie = document.cookie;
  var cookie_count = 0;

  while (tmpcookie.indexOf("; ") != -1) {
    cookie_string = tmpcookie.substring(0, tmpcookie.indexOf("; "));
    cookie_name = cookie_string.substring(0, cookie_string.indexOf("="));
    cookie_value = cookie_string.substring(cookie_string.indexOf("=") + 
        "=".length, cookie_string.length);
    eval("document.Cookie_" + cookie_name + 
	" = new Cookies(cookie_name, cookie_value);");

    tmpcookie = tmpcookie.substring(tmpcookie.indexOf("; ") + "; ".length, 
        tmpcookie.length);

    cookie_count++;
  }

  cookie_name = tmpcookie.substring(0, tmpcookie.indexOf("="));
  cookie_value = tmpcookie.substring(tmpcookie.indexOf("=") + "=".length, 
        tmpcookie.length);
  eval("document.Cookie_" + cookie_name + 
	" = new Cookies(cookie_name, cookie_value);");
  cookie_count++;
  
  return cookie_count;

}

function Cookies(argname, argvalue) {
  this.name = argname;
  this.value = unescape(argvalue);

  return this;

}

function DeleteCookie(cookiename) {
  var exp = new Date();

  exp.setTime(exp.getTime() - 1);
  var cookieVal = getCookie(cookiename);
  if (cookieVal != null)
    document.cookie = name + "=" + cookieVal + "; expires=" + exp.toGMTString();

  return;

}

/* DHTML */
function objGet(x) {
	if (typeof x != 'string') return x;
	else if (Boolean(document.getElementById)) return document.getElementById(x);
	else if (Boolean(document.all)) return eval('document.all.'+x);  // pro MSIE 4
	else return null;
}

function objSetStyle (obj,prop,val) {
	var o = objGet(obj);
	if (o && o.style) {
		eval ('o.style.'+prop+'="'+val+'"');
		return true;
		}
	else return false;
	}

function objShow (obj,on) {
	return objSetStyle(obj,'visibility',(on) ? 'visible':'hidden');
	}

function objDisplay (obj,on,type) {
	if (on && !type) type = 'block';
	return objSetStyle(obj,'display',(on) ? type:'none');
	}

function openNews (n) {
	objDisplay('article_'+n+'_short',false);
	objDisplay('article_'+n+'',true);
	}

function closeNews (n) {
	objDisplay('article_'+n+'_short',true);
	objDisplay('article_'+n+'',false);
	}

function changeEshopPrice (n1,n2,n3,n4,n5) {
	objDisplay(n1,false);
	objDisplay(n2,true);
	objGet(n3).price_id.value = n4;
	objGet(n5).value = n4;
	}

/* CSS Menu */
if (navigator.userAgent.indexOf('MSIE 5.5') != -1 || navigator.userAgent.indexOf('MSIE 6') != -1) {
	function imMenuMainHover() {
		if (document.getElementById("menu") != null) {
			if (document.getElementsByTagName) {
				var oList = document.getElementById("menu").getElementsByTagName("LI"); for (var i=0; i<oList.length; i++) {
					oList[i].onmouseover=function() {this.className+=" iehover";}
					oList[i].onmouseout=function() {this.className=this.className.replace(new RegExp(" iehover\\b"), "");}
					}
				}
			}
		}
	
	imLoadList = "imMenuMainHover();";
	
	/* GreyBox OnLoad */
	AJS.AEV(window, 'load', function() {
		antiFraming();
		eval(imLoadList);
		});
	}

/* PreLoader */
function imPreloadImages(sImgNames) {
	var sNames = new Array (); sNames = sImgNames.split(","); 
	for(iList = 0 ; iList < sNames.length ; iList++) {
		var oImg = new Image(); oImg.src = sNames[iList];
		}
	}

/* Intellingent Form Fields */
function getkey(e) {
  var code;
  if (!e)
    var 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;
	}

function numeric(eX) {
  test=getkey(eX);
  if (test<48 || test>57)
    return false;
	}

// pokud ma parametr diactric hodnotu 1, jsou povolene diaktricke znaky
function alfanumeric(eX,diacritic) {
  test=getkey(eX);
  set1=(test>32 && test<48);
  set2=(test>57 && test<65);
  set3=(test>90 && test<97);
  if (diacritic == 1)
    set4=(test>122 && test<127);
  else
    set4=(test>122)
  if (set1 || set2 || set3 || set4)
    return false;
	}

function safechars(eX) {
  test=getkey(eX);
  if (test==34 || test==39)
    return false;
	}

function isEnter(evnt) {
	var Return = false;
	evnt = (evnt) ? evnt : ((event) ? event : null);
  if (evnt) {
		var charCode = (evnt.charCode || evnt.charCode == 0) ? evnt.charCode : ((evnt.keyCode) ? evnt.keyCode : evnt.which);
		if (charCode == 13) {
			Return = true;
			}
		}
	return Return;
	}

/* Check Data */
function isEmail(argvalue) {
  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;

  // arrayString = argvalue.split("@"); (works only in netscape3 and above.)
  var retSize = customSplit(argvalue, "@", "arrayString");

  if (arrayString[1].indexOf(".") == -1)
    return false;
  else if (arrayString[1].indexOf(".") == 0)
    return false;
  else if (arrayString[1].charAt(arrayString[1].length-1) == ".")
    return false;

  return true;
	}
