function jazyk(s) { if(!s)s="Change language:";document.getElementById("jazyk").innerHTML = s; }

function zmen(radek) {
  tedecka = radek.getElementsByTagName("td");
  for (i=0; i < tedecka.length; i++) {
    tedecka[i].className+=' w';
  }
}

function vrat(radek) {
  for (i=0; i < tedecka.length; i++) {
    tedecka[i].className=tedecka[i].className.substring(0,1);
  }
}

/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/	
	
var currentlyActiveInputRef = false;
var currentlyActiveInputClassName = false;

function highlightActiveInput()
{
	if(currentlyActiveInputRef){
		currentlyActiveInputRef.className = currentlyActiveInputClassName;
	}
	currentlyActiveInputClassName = this.className;
	this.className = 'inputHighlighted';
	//this.select();
	currentlyActiveInputRef = this;	
}

function blurActiveInput()
{
	this.className = currentlyActiveInputClassName;
	
	
}


function initInputHighlightScript()
{
	var tags = ['INPUT','TEXTAREA'];
	
	for(tagCounter=0;tagCounter<tags.length;tagCounter++){
		var inputs = document.getElementsByTagName(tags[tagCounter]);
		for(var no=0;no<inputs.length;no++){
			if(inputs[no].className && ( inputs[no].className=='doNotHighlightThisInput' || inputs[no].className=="pridejpoznamku" ) )continue;
			
			if(inputs[no].tagName.toLowerCase()=='textarea' || (inputs[no].tagName.toLowerCase()=='input' && inputs[no].type.toLowerCase()=='text')){
				inputs[no].onfocus = highlightActiveInput;
				inputs[no].onblur = blurActiveInput;
			}
		}
	}
}

function poziceWait() {
  document.getElementById("wait").style.left = (document.body.clientWidth/2-171/2) + "px";//(document.body.clientWidth/2-171/2) + "px";
  document.getElementById("wait").style.top = "20px";//(document.body.clientHeight/2-54/2) + "px";
  document.getElementById("black").style.width = document.body.clientWidth + "px";//(document.body.clientWidth/2-171/2) + "px";
  //alert();
}

function cekani(b) {
  poziceWait();
  /*if ( b == true ) {
    document.getElementById("wait").style.display = "";
    document.getElementById("black").style.display = "";
  } else {*/
    document.getElementById("wait").style.display = "none";
    document.getElementById("black").style.display = "none";
  //}
}

function ajaxStartEval(url) {
  //poziceWait();
  if (url != 0) {
    //if ( document.getElementById("wait") ) cekani(true);
    if (window.ActiveXObject) {
      httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      httpRequest = new XMLHttpRequest();
    }
    httpRequest.open("GET", url, true);
    httpRequest.onreadystatechange= function () { ajaxStartEval2(url); } ;
    httpRequest.send(null);
  } else {
    alert("Chyba: Chybí URL.");
  }
}

function ajaxStartEval2(url) {
  //poziceWait();
  if (httpRequest.readyState == 4) {
    if(httpRequest.status == 200) {
      eval(httpRequest.responseText);
    } else {
        alert("Chyba pri nacitani stanky\n"+ httpRequest.status +": "+ httpRequest.statusText + "\n\n["+url+"]");
    }
  }
  if ( document.getElementById("wait") ) setTimeout('cekani(false);', 1000);
}

function WRajaxStartEval(url, id) {
  //poziceWait();
  if (url != 0) {
    //if ( document.getElementById("wait") ) cekani(true);
    if (window.ActiveXObject) {
      httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      httpRequest = new XMLHttpRequest();
    }
    httpRequest.open("GET", url, true);
    httpRequest.onreadystatechange= function () { WRajaxStartEval2(url, id); } ;
    httpRequest.send(null);
  } else {
    alert("Chyba: Chybí URL.");
  }
}

function WRajaxStartEval2(url, id) {
  poziceWait();
  if (httpRequest.readyState == 4) {
    if(httpRequest.status == 200) {
      document.getElementById(id).innerHTML = httpRequest.responseText;
    } else {
        alert("Chyba pri nacitani stanky\n"+ httpRequest.status +": "+ httpRequest.statusText + "\n\n["+url+"]");
    }
  }
  if ( document.getElementById("wait") ) setTimeout('cekani(false);', 1000);
}

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 || test==46||test==8||test==9)
    return false;
}

function mena(eX, obj)
{
  test=getkey(eX);
  //window.status = test;
  obj.onchange = function() { obj.value = obj.value.replace(",", "."); }
  //obj.onkeydown = function() { obj.value = obj.value.replace(",", "."); }
  if ( test >= 48 && test <= 57 ) return true;
  if ( test == 46 ) return true;
  if ( test == 44 ) { return true; }
  if ( test == 45 ) { return true; }
  if ( test == 8 ) { return true; }
  if ( test == 9 ) { return true; }
  else return false;
}

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;
}

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

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;
    }

}

function okno(url) {
  oknobig(url);
  //if ( !window.open(url, "_blank", "toolbar=no, location=no, address=yes, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, left="+(20+screen.width/2-1024/2)+", top="+(20+screen.height/2-700/2)+", width=1024, height=700") ) alert("Okno se nepodařilo otevřít.");
}

function oknobig(url) {
  if ( screen.width > 1100 && screen.height > 800 ) {
    if ( !window.open(url, "_blank", "toolbar=no, location=yes, address=yes, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=1200, height=900, left="+(screen.width/2-1200/2)+", top="+(screen.height/2-50-900/2)) ) alert("Okno se nepodařilo otevřít.");
  } else {
    if ( !window.open(url, "_blank", "toolbar=no, location=yes, address=yes, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, left="+(screen.width/2-1024/2)+", top="+(screen.height/2-700/2)+", width=1024, height=700") ) alert("Okno se nepodařilo otevřít.");
  }
}

function showOrHide(id) {
  el = document.getElementById(id);
  if ( el.style.display == "none" ) el.style.display = "";
  else el.style.display = "none";
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100);
    object.MsOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")";
}

function vizitka(id) {
  window.open(URL_ROOT+"vizitka.php?id="+id, "vizitka", "width=450px, height=250px, top="+(20+screen.height/2-250/2)+", left="+(20+screen.width/2-450/2));
}

function email(id, typ, addons) {
  if ( typ == "" ) typ = "zakazka";
  if ( addons == "" ) addons = "";
  window.open(URL_ROOT+"email.php?id="+id+"&typ="+typ+"&"+addons, "_blank", "status=yes, width=600px, height=450px, top="+(screen.height/2-450/2)+", left="+(screen.width/2-600/2));
}

var globalCursorPos; // global variabe to keep track of where the cursor was

//sets the global variable to keep track of the cursor position
function setCursorPos(obj) {
 globalCursorPos = getCursorPos(obj);
 //window.status = globalCursorPos;
}

//This function returns the index of the cursor location in
//the value of the input text element
//It is important to make sure that the sWeirdString variable contains
//a set of characters that will not be encountered normally in your
//text
function getCursorPos(textElement) {
 //save off the current value to restore it later,
 var sOldText = textElement.value;

//create a range object and save off it's text
 var objRange = document.selection.createRange();
 var sOldRange = objRange.text;

//set this string to a small string that will not normally be encountered
 var sWeirdString = '#%~';

//insert the weirdstring where the cursor is at
 objRange.text = sOldRange + sWeirdString; objRange.moveStart('character', (0 - sOldRange.length - sWeirdString.length));

//save off the new string with the weirdstring in it
 var sNewText = textElement.value;

//set the actual text value back to how it was
 objRange.text = sOldRange;

//look through the new string we saved off and find the location of
//the weirdstring that was inserted and return that value
 for (i=0; i <= sNewText.length; i++) {
   var sTemp = sNewText.substring(i, i + sWeirdString.length);
   if (sTemp == sWeirdString) {
     var cursorPos = (i - sOldRange.length);
     return cursorPos;
   }
 }
}

//this function inserts the input string into the textarea
//where the cursor was at
function insertString(stringToInsert, obj) {
 var firstPart = obj.value.substring(0, globalCursorPos);
 var secondPart = obj.value.substring(globalCursorPos, obj.value.length);
 obj.value = firstPart + stringToInsert + secondPart;
}

function rozmery(obj) {
  window.open('load.php?s=vyberrozmer&return='+obj, 'kalkulacka', 'width=200, height=700, status=no');
}

function maleokno(obj) {
  window.open(obj, '_blank', 'width=500, height=600, status=yes, scrollbars=1, left='+(screen.width/2-500/2)+', top='+(screen.height/2-600/2));
}

function mokno(url, w, h) {
  window.open(url, "_blank", "status=yes, width="+w+"px, height="+h+"px, top="+(screen.height/2-h/2)+", left="+(screen.width/2-w/2));
}

/**
 * http://www.openjs.com/scripts/events/keyboard_shortcuts/
 * Version : 2.01.B
 * By Binny V A
 * License : BSD
 */
shortcut = {
	'all_shortcuts':{},//All the shortcuts are stored in this array
	'add': function(shortcut_combination,callback,opt) {
		//Provide a set of default options
		var default_options = {
			'type':'keydown',
			'propagate':false,
			'disable_in_input':false,
			'target':document,
			'keycode':false
		}
		if(!opt) opt = default_options;
		else {
			for(var dfo in default_options) {
				if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
			}
		}

		var ele = opt.target;
		if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
		var ths = this;
		shortcut_combination = shortcut_combination.toLowerCase();

		//The function to be called at keypress
		var func = function(e) {
			e = e || window.event;
			
			if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
				var element;
				if(e.target) element=e.target;
				else if(e.srcElement) element=e.srcElement;
				if(element.nodeType==3) element=element.parentNode;

				if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
			}
	
			//Find Which key is pressed
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
			var character = String.fromCharCode(code).toLowerCase();
			
			if(code == 188) character=","; //If the user presses , when the type is onkeydown
			if(code == 190) character="."; //If the user presses , when the type is onkeydown

			var keys = shortcut_combination.split("+");
			//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
			var kp = 0;
			
			//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
			var shift_nums = {
				"`":"~",
				"1":"!",
				"2":"@",
				"3":"#",
				"4":"$",
				"5":"%",
				"6":"^",
				"7":"&",
				"8":"*",
				"9":"(",
				"0":")",
				"-":"_",
				"=":"+",
				";":":",
				"'":"\"",
				",":"<",
				".":">",
				"/":"?",
				"\\":"|"
			}
			//Special Keys - and their codes
			var special_keys = {
				'esc':27,
				'escape':27,
				'tab':9,
				'space':32,
				'return':13,
				'enter':13,
				'backspace':8,
	
				'scrolllock':145,
				'scroll_lock':145,
				'scroll':145,
				'capslock':20,
				'caps_lock':20,
				'caps':20,
				'numlock':144,
				'num_lock':144,
				'num':144,
				
				'pause':19,
				'break':19,
				
				'insert':45,
				'home':36,
				'delete':46,
				'end':35,
				
				'pageup':33,
				'page_up':33,
				'pu':33,
	
				'pagedown':34,
				'page_down':34,
				'pd':34,
	
				'left':37,
				'up':38,
				'right':39,
				'down':40,
	
				'f1':112,
				'f2':113,
				'f3':114,
				'f4':115,
				'f5':116,
				'f6':117,
				'f7':118,
				'f8':119,
				'f9':120,
				'f10':121,
				'f11':122,
				'f12':123
			}
	
			var modifiers = { 
				shift: { wanted:false, pressed:false},
				ctrl : { wanted:false, pressed:false},
				alt  : { wanted:false, pressed:false},
				meta : { wanted:false, pressed:false}	//Meta is Mac specific
			};
                        
			if(e.ctrlKey)	modifiers.ctrl.pressed = true;
			if(e.shiftKey)	modifiers.shift.pressed = true;
			if(e.altKey)	modifiers.alt.pressed = true;
			if(e.metaKey)   modifiers.meta.pressed = true;
                        
			for(var i=0; k=keys[i],i<keys.length; i++) {
				//Modifiers
				if(k == 'ctrl' || k == 'control') {
					kp++;
					modifiers.ctrl.wanted = true;

				} else if(k == 'shift') {
					kp++;
					modifiers.shift.wanted = true;

				} else if(k == 'alt') {
					kp++;
					modifiers.alt.wanted = true;
				} else if(k == 'meta') {
					kp++;
					modifiers.meta.wanted = true;
				} else if(k.length > 1) { //If it is a special key
					if(special_keys[k] == code) kp++;
					
				} else if(opt['keycode']) {
					if(opt['keycode'] == code) kp++;

				} else { //The special keys did not match
					if(character == k) kp++;
					else {
						if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
							character = shift_nums[character]; 
							if(character == k) kp++;
						}
					}
				}
			}
			
			if(kp == keys.length && 
						modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
						modifiers.shift.pressed == modifiers.shift.wanted &&
						modifiers.alt.pressed == modifiers.alt.wanted &&
						modifiers.meta.pressed == modifiers.meta.wanted) {
				callback(e);
	
				if(!opt['propagate']) { //Stop the event
					//e.cancelBubble is supported by IE - this will kill the bubbling process.
					e.cancelBubble = true;
					e.returnValue = false;
	
					//e.stopPropagation works in Firefox.
					if (e.stopPropagation) {
						e.stopPropagation();
						e.preventDefault();
					}
					return false;
				}
			}
		}
		this.all_shortcuts[shortcut_combination] = {
			'callback':func, 
			'target':ele, 
			'event': opt['type']
		};
		//Attach the function with the event
		if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
		else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
		else ele['on'+opt['type']] = func;
	},

	//Remove the shortcut - just specify the shortcut and I will remove the binding
	'remove':function(shortcut_combination) {
		shortcut_combination = shortcut_combination.toLowerCase();
		var binding = this.all_shortcuts[shortcut_combination];
		delete(this.all_shortcuts[shortcut_combination])
		if(!binding) return;
		var type = binding['event'];
		var ele = binding['target'];
		var callback = binding['callback'];

		if(ele.detachEvent) ele.detachEvent('on'+type, callback);
		else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
		else ele['on'+type] = false;
	}
}

function getObjX(objElm) {
  iReturnValueX = 0;
  iReturnValueY = 0;
  elementid = objElm;
  while( elementid != null ){
    iReturnValueX += elementid.offsetLeft;
    iReturnValueY += elementid.offsetTop;
    elementid = elementid.offsetParent;
  }
  return iReturnValueX;
  //return iReturnValueY+objElm.clientHeight+4;
}

function getObjY(objElm) {
  iReturnValueX = 0;
  iReturnValueY = 0;
  elementid = objElm;
  while( elementid != null ){
    iReturnValueX += elementid.offsetLeft;
    iReturnValueY += elementid.offsetTop;
    elementid = elementid.offsetParent;
  }
  //return iReturnValueX;
  return iReturnValueY+objElm.clientHeight+4;
}

function moveElementTo(fromobj, toobj, plusx, plusy) {
  document.getElementById(toobj).style.left = getObjX(fromobj)+plusx;
  document.getElementById(toobj).style.top = getObjY(fromobj)+plusy;
}

// Naseptavac

function jeanWhisperLocate(objElm) {
  obj = document.getElementById("jeanWhisper");
  obj.style.display = "";
  sirka = objElm['offsetWidth'];
  if ( sirka < 100 ) sirka = 100;
  obj.style.width = sirka+" px";
  // Pozice
  iReturnValueX = 0;
  iReturnValueY = 0;
  elementid = objElm;
  while( elementid != null ){
    iReturnValueX += elementid.offsetLeft;
    iReturnValueY += elementid.offsetTop;
    elementid = elementid.offsetParent;
  }
  obj.style.left = (iReturnValueX)+" px";
  obj.style.top = (iReturnValueY+objElm.clientHeight+4)+" px";
}
function fJeanWhisper(eve, obj, url) {
  jeanWhisperLocate(obj);
  tlacitko = getkey(eve);
  //window.status = url;
  obj.onmouseover = function() { fDontHideJeanWhisper(); }
  obj.onmouseout = function() { fHideJeanWhisper(); }
  if ( tlacitko == 40 ) {
    document.getElementById("aJeanWhisper[0]").focus();
    //document.getElementById("aJeanWhisper[0]").className = "activeWhisper";
  }
  else ajaxStartEval(url);
}

var vJeanWhisper;
function fHideJeanWhisper() { vJeanWhisper = setTimeout("document.getElementById('jeanWhisper').style.display='none'", 1000); }
function fHideJeanWhisperNow() { clearTimeout(vJeanWhisper); document.getElementById('jeanWhisper').style.display='none'; }
function fDontHideJeanWhisper() { clearTimeout(vJeanWhisper); }
