var IE = (document.all?true:false);

function gE(el){
    return document.getElementById(el);
}
  
function ShowLocalImage(imgname,obj) {
	imgname = imgname.replace(/\\/g,"/");
	imgname = imgname.replace(/\'/g,"\\'");
	content = "<img src=\"" + String(imgname) + "\" border=\"0\" height=\"130\" width=\"130\">";
	eval('gE(obj).innerHTML=content');
	gE(obj).style.display = 'block'; // na WWW nefunguje proto tento radek zakomentovan
}
  
  function hit(i,url,tbl){
      cspath=url+"c.php";
      if (i){
        obj_obr=new Image;
        obj_obr.src=""+cspath+"?i="+i+"&t="+tbl+"&r="+Math.random();
      }
      for (x=0;x<100000;x++){}
      return true;
  }
  
  function CheckOnNumber(hodnota)					//kontrola zda je hodnota ciselna
	{
		if (hodnota==""){
		return false;
		}
		for (i=0;i<hodnota.length;i++){
		  if ( hodnota.charAt(i) != '.' && hodnota.charAt(i) != ','  ){
  			if (hodnota.charAt(i)<'0'){
  			return false;
  			}
  			if (hodnota.charAt(i)>'9'){
  			return false;
  			}
			}
		}
		return true;
	} 
	
	function CheckInput(typ,val){
    if ( typ == 'number' ){
      if ( !CheckOnNumber(val) && val != '' ){
        alert('Vkládaná hodnota musí být číslo.');
        return false;
      }
    
    }
  }
	
	function CheckOnEmail(email)
	{
		invalidChars='/:,;ěščřžýáíéúů';			//vytvoreni promene se znaky ktere se nesmeji v adrese objevit
		for (i=0;i<invalidChars.length;i++){	//smicka proveruje zda se jeden ze znaku nevyskytuje v adrese
			badChar=invalidChars.charAt(i)
				if (email.indexOf(badChar,0)>-1){
				return false;
				}
		}
		atPos = email.indexOf('@',1)
		if (atPos==-1){
		return false;
		}
		if (email.indexOf('@',atPos+1)>-1){		//od mista nalezu prvniho @ se pokousime hledat @ (dva nelze)
		return false;
		}
		periodPos=email.indexOf('.',atPos)
		if (periodPos==-1){
		return false;
		}
		if (periodPos+3>email.length){
		return false;
		}
		return true;
	}
	
      function CheckLength(id,field,max,txt){
      			retezec = document.getElementById(id).value;
      			strlength=retezec.length;
      				if (strlength > max ) 
      				{
      	                alert(txt);           
      	                document.getElementById(id).value=retezec.substring(0,max);
      				}
      				else{
      			   document.getElementById(field).innerText = max - retezec.length;
      				}
      }
	
  function RoundNumber(num, dec) {
  	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
  	return result;
  }


        /*obsluha stisknuti klavesy napr textarea*/
        function HandleKeyDown(obj,action) {
           if ( action == 'tab' ){ // pokud v textarea pouziji TAB odskoci kurzor jako v editoru  nikoliv na dalsi pole ve FORMu
             var tabKeyCode = 9;
             if (event.keyCode == tabKeyCode && event.srcElement == obj) {
                obj.selection = document.selection.createRange();
                obj.selection.text = String.fromCharCode(tabKeyCode);
                event.returnValue = false;
             }
           }
        }

	
function AlertStay(){
  clearInterval(BD);
}
	
function AlertCheck(){
	if ( gE('alert') ){
		BD=window.setTimeout("AlertOff('100')",4000);
	}
}

function AlertOff(opc){
  clearInterval(BD);
		var ie5=(document.getElementById && document.all);
		var ns6=(document.getElementById && !document.all);
		nPlus = 20   //the % of fading for each step
		speed = 50  //the speed
		    if(document.getElementById){
		       imgs = gE('alert');
				opacity = opc-nPlus;
				opc = opacity;
				
		    	if(opacity>-30){
					if(ie5){
				        imgs.style.filter="alpha(opacity=0)";
						imgs.filters.alpha.opacity = opacity;
					}
					
					if(ns6){
		        		imgs.style.MozOpacity = 0;
						imgs.style.MozOpacity = opacity/100;
		    		}
					tmr=setTimeout('AlertOff('+opc+')',speed);
		    	}else{
					clearInterval(tmr);
					gE('alert').style.display='none';
				}
		  }
}

function CookieCreate(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function CookieRead(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function CookieErase(name) {
	CookieCreate(name,"",-1);
}

function ColorPickerShow(id,ac,margin_top,margin_left){
  gE(id).style.display=ac;
  if (margin_top) gE(id).style.marginTop=margin_top;
  if (margin_left) gE(id).style.marginLeft=margin_left;
}

function ColorPickerSelect(color,tri){
  gE('color_picker_value'+tri).value=color;
  gE('color_picker_test_area'+tri).style.backgroundColor=color;
  gE('color_picker'+tri).style.display='none';
  
}

function ColorPickerManual(color){
  if (color.length>2) gE('color_picker_test_area').style.backgroundColor=color;
}

function ColorPickerOver(color,tri){
  var val = color.title;
  gE('color_picker_test_area'+tri).style.backgroundColor=val;
  //alert();
}


var globalCursorPos;
var globalCursorObj;

function CursorPos(obj) {
 globalCursorPos = getCursorPos(obj);
 globalCursorObj = obj;
}
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 CursorPosInsert(stringToInsert) {
  if ( globalCursorPos && globalCursorObj ){
 // alert(globalCursorPos+' -aa- '+globalCursorObj);
 var firstPart = globalCursorObj.value.substring(0, globalCursorPos);
 var secondPart = globalCursorObj.value.substring(globalCursorPos, globalCursorObj.value.length);
 globalCursorObj.value = firstPart + stringToInsert +  secondPart;
 }
 else{
  alert('Nastavte kurzor do textového pole do kterého chcete vložit. ');
 }
}



//if (!IE) document.captureEvents(Event.MOUSEMOVE);
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
   // tempX = event.clientX + document.body.scrollLeft
   // tempY = event.clientY + document.body.scrollTop
   tempX = event.x;
   tempY = event.y;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  return true
}




///////////////////// AJAX /////////////////////
////////////////////////////////////////////////
   var http_request = false;
   function AjaxPostRequest(url, parameters,ret) {

      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Nelze vytvořit XMLHTTP instanci.');
         return false;
      }
      
     // http_request.onreadystatechange = AjaxReturnContent;
      http_request.open('POST', url, true);
      //http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  //http_request.setRequestHeader("Content-type", "text/html; charset=UTF-8");
	  //  http_request.overrideMimeType('text/xml; charset=iso-8859-2'); 
	    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-2");
	     //http_request.setRequestHeader("Transfer-Encoding", "chunked");
      http_request.setRequestHeader("Content-length", parameters.length);
	 // http_request.setRequestHeader("Accept-Charset", "ISO-8859-2;q=0.7,*;q=0.7");
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
      
	  
	  http_request.onreadystatechange = function(){

		if ( http_request.readyState == 4 ){
		    if (http_request.status == 200) {
					//alert(http_request.responseText);
		      result = http_request.responseText;
		      if ( result!="" && ret!="" && (gE(ret).value=="" || gE(ret).value)  ) {
            gE(ret).value = result;
            gE(ret).style.backgroundColor='#d5ecd5'; // zvyrazneni INPUT, pokud byl upraven
          }
					else if (result!="" && ret!="") gE(ret).innerHTML = result;   
					else if (result!="") gE('ajax_return').innerHTML = result;
	        if ( ret == 'ret_basket' )  alert('Zboží bylo přidáno do nákupního košíku.');
					return true;          
	      } else {
	        alert('Nastal problém s návratem žádosti. Stav není 200.'+ http_request.status);
	        return false;
	      }
		}
	  }
	  
   }

   function AjaxReturnContent() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            if (result!="") gE('ajax_return').innerHTML = result;            
         } else {
            alert('Nastal problém s návratem žádosti. Stav není 200.');
         }
      }
   }
   
   ////////////////// AJAX END //////////////////////
   
   
   
   
   ///////////// PRO SHORTCUT //////////
   function addEvent(elm,evType,fn,capture) {if(!capture)var capture=true;if(elm.addEventListener){elm.addEventListener(evType, fn, capture);return true;}else if(elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType]=fn;}}
   function $(id){return document.getElementById(id);}
   

  	var ie5=(document.getElementById && document.all);
		var ns6=(document.getElementById && !document.all);
		nPlus = 20   //the % of fading for each step
		speed = 50  //the speed
		var tmr = 0;
		
  	function over_mnu(obj,opc){
			if ( d.getElementById('car') ) d.getElementById('car').style.visibility='hidden';

			document.getElementById(obj).style.display='block';
			if (opc==1) tmr=setTimeout('opacity_mnu(\''+obj+'\','+opc+')',500);;
		}
  
    function mnu_layer(obj,ac,opc){
        clearInterval(tmr);
        
        if ( ac == 'show' ){
          if (opc==1) tmr=setTimeout('opacity_mnu(\'mnlay_'+obj+'\',0)',500); //opacity_mnu('mnu_layer_'+obj,0);
        }
        else if ( ac == 'stay'){
          document.getElementById('mnlay_'+obj).style.display = 'block';
        }
        else if ( ac == 'hide' ) {
          document.getElementById('mnlay_'+obj).style.display = 'none';
        }
    }
    
		function opacity_mnu(obj,opc){
		    if(document.getElementById){
		      document.getElementById(obj).style.display = 'block';
		      imgs = document.getElementById(obj);
				  opacity = opc+nPlus;
				  opc = opacity;
				
		    	if(opacity<120){
  					if(ie5){
  				    imgs.style.filter="alpha(opacity=0)";
  						imgs.filters.alpha.opacity = opacity;
  					}
  					
  					if(ns6){
  		        imgs.style.MozOpacity = 0;
  						imgs.style.MozOpacity = opacity/100;
  		    		}
  					tmr=setTimeout('opacity_mnu(\''+obj+'\','+opc+')',speed);
		    	}
          else{
					 clearInterval(tmr);
				  }
		  	}
		}
    



