

/* HLASKA ALERT */

function alert_box(id,text,tit,focus_id,fce,b_ok,b_ano,b_ne,width,height)
{
	
	/*
		ID 1 => info icon
		ID 2 => warning icon
		ID 3 => stop icon
		ID 4 => forbidden icon
		ID 5 => right icon
		ID 6 => questin icon
	*/
	
	focus_id2 = "";
	if(focus_id)
	{
		focus_id2 = "focus="+focus_id+";";
	}
	
	que = "";
	if(fce)
	{
		que = ";fce="+fce;
	}
	if(b_ok)
	{
		que += ";but_ok="+b_ok;
	}
	if(b_ano)
	{
		que += ";but_ano="+b_ano;
	}
	if(b_ne)
	{
		que += ";but_ne="+b_ne;
	}
	
	if(!width) width = 300;
	if(!height) height = 80;

	var href = "../#TB_inline?height="+height+"&amp;width="+width+"&amp;inlineId=hlaska&amp;overlay_click=0;"+focus_id2+"icon="+id+que;
	
	var title = "POZOR!";
	if(tit)
	{
		title = tit;
	}
	
	document.getElementById("hlaska").innerHTML = text;
	document.getElementById("zahlas").title=title;
	document.getElementById("zahlas").href=href;
	
	zobraz_hlasku();
}

function nic()
{
	alert_box(1,'OK.','PŘIHLÁŠENÍ');
}


/** FRAME BOX **/
function frame_box(caption,url,width,height)
{
	var url_frame = url + "&keepThis=true&TB_iframe=true&height="+height+"&width="+width;
	tb_show(caption, url_frame, false)
}


/** KOMENTAR **/
var comment_cas = null;
var comment_id_typ = null;
function comment_out()
{
	var comment = document.getElementById('comment');
	comment.style.display='none';
	
	clearInterval(comment_cas);
	
	if(comment_id_typ)
	{
		comment_id_typ.focus();
		comment_id_typ.select();
	}
	
}

function comment_box(id,text,pos,typ,delka)
{
	var obj = typeof id;	
	if(obj != "object")
	{
		id = document.getElementById(id);
	}
	
	if(!pos)
	{
		pos = 0;
	}
	
	if(!typ)
	{
		id.onblur = comment_out;
		comment_id_typ = null;	
	}
	else if(typ == 1)
	{
		document.getElementById('comment').onclick = comment_out;
		comment_id_typ = id;
	}
	
	
	
	id.onkeypress=function(e){
		if(!e)
		{
			key = event.keyCode;
		}
		else
		{
			key = e.which;
		}
		
		if(key == "27" || key=="0"){
			comment_out();
		}

	}
	
	
	
	xxx = id;
	yyy = pos;
	
	comment_cas = setInterval("comment_position(xxx,yyy)", 200);
	//comment_position(xxx,yyy);
		
	//alert_box(2,document.body.scrollWidth);
	//alert_box(5,pozice);
	
	
	
	var comment = document.getElementById('comment');
	comment.style.display='';	
	
	
	var comment_content = document.getElementById('comment_content');
	var comment_main = document.getElementById('comment');
	
	if(delka)
	{
		comment_main.style.width = delka+"px";
	}	
	
	comment_content.innerHTML = text;
	comment_content.style.textAlign = 'left';
	comment_content.style.color = 'green';	
}

function comment_position(id,pos)
{
	var comment = document.getElementById('comment');	
	var pozice = getObUpperLeft(id);
	var const_x = -10;
	var const_y = -10;
	
	
	if(pos == 0)
	{
		var h = id.offsetHeight + 2;
		var k = 0;
	}
	else if(pos == 1)
	{
		var h = 0;
		var k = id.offsetWidth + 10;		
	}
	else if(pos == 2)
	{
		var h = -(comment.offsetHeight)+18;
		var k = 0;		
	}	
		
	//alert((pozice[1] + const_y + h));
		
	comment.style.top = (pozice[1] + const_y + h)+'px';
	comment.style.left = (pozice[0] + const_x + k)+'px';	
}

function getObUpperLeft(obj) {
    var curLeft = curTop = 0;
    if (obj.offsetParent) {
        curLeft = obj.offsetLeft
        curTop = obj.offsetTop
        //alert("objName= "+obj.id+"  offsetLeft= "+obj.offsetLeft+"  offsetTop= "+obj.offsetTop+"  hasLayout= "+obj.currentStyle.hasLayout);
        while (obj = obj.offsetParent) {
            //alert("objName= "+obj.id+"  offsetLeft= "+obj.offsetLeft+"  offsetTop= "+obj.offsetTop+"  hasLayout= "+obj.currentStyle.hasLayout);
            curLeft += obj.offsetLeft
            curTop += obj.offsetTop
        }
    }   
    return [curLeft,curTop];
} 

/* OPRAVENI PNG */
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 and IE 6. 
{ 
for(var i=0; i<document.images.length; i++) 
{ 
var img = document.images[i] 
var imgName = img.src.toUpperCase() 

if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
{ 
	
var imgID = (img.id) ? "id='" + img.id + "' " : "" 
var imgClass = (img.className) ? "class='" + img.className + "' " : "" 
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 
var imgStyle = "display:inline-block;" + img.style.cssText 
if (img.align == "left") imgStyle = "float:left;" + imgStyle 
if (img.align == "right") imgStyle = "float:right;" + imgStyle 
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle 
var strNewHTML = "<span " + imgID + imgClass + imgTitle 
+ "style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" // 
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
img.outerHTML = strNewHTML
//return alert(strNewHTML);
//alert(strNewHTML); 
i = i-1 
} 
} 
} 

if(navigator.appName == "Microsoft Internet Explorer")
{
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		if (ieversion==6)
		{
			window.attachEvent("onload", correctPNG);
		}  
		else if (ieversion==5){
			window.attachEvent("onload", correctPNG);	
		}	  
	}

}
function aa(dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
}



function odkaz(id){
	window.location.href=id;
}

/* SELECT_BOX */
var select_box_active = new Array();

function select_box_show_on(id,id2)
{
	if(select_box_active[id2]!=id){
	document.getElementById("select_box_1_"+id).className = "select_box_title_left_on";
	document.getElementById("select_box_2_"+id).className = "select_box_title_text_on";
	document.getElementById("select_box_3_"+id).className = "select_box_title_text_margin_on";
	document.getElementById("select_box_4_"+id).className = "select_box_title_right_on";
	}			
}
function select_box_show_off(id,id2)
{
	if(select_box_active[id2]!=id){
	document.getElementById("select_box_1_"+id).className = "select_box_title_left_off";
	document.getElementById("select_box_2_"+id).className = "select_box_title_text_off";
	document.getElementById("select_box_3_"+id).className = "select_box_title_text_margin_off";
	document.getElementById("select_box_4_"+id).className = "select_box_title_right_off";	
	}		
}
function select_box_turn_on(id,id2)
{
	if(select_box_active[id2]!=id){
	document.getElementById("select_box_1_"+id).className = "select_box_title_left_on";
	document.getElementById("select_box_2_"+id).className = "select_box_title_text_on";
	document.getElementById("select_box_3_"+id).className = "select_box_title_text_margin_on";
	document.getElementById("select_box_4_"+id).className = "select_box_title_right_on";
	document.getElementById("select_box_3_"+id).title = "";	
	document.getElementById("select_box_content_"+id2+"_"+id).style.display = "";
	
	off = select_box_active[id2];	
	document.getElementById("select_box_1_"+off).className = "select_box_title_left_off";
	document.getElementById("select_box_2_"+off).className = "select_box_title_text_off";
	document.getElementById("select_box_3_"+off).className = "select_box_title_text_margin_off";
	document.getElementById("select_box_4_"+off).className = "select_box_title_right_off";
	document.getElementById("select_box_content_"+id2+"_"+off).style.display = "none";	
	
	select_box_active[id2] = id;
	titulek = document.getElementById("select_box_3_"+id).innerHTML;
	titulek2 = document.getElementById("select_box_3_"+off).innerHTML;
	
	document.getElementById("select_box_icon_"+id2).title = titulek;
	document.getElementById("select_box_3_"+off).title = "Zobrazit "+titulek2;	
	
	}		
}


/*
function select_box()
{
	select_box_init('div.select_box_title_left_off, div.select_box_title_right_off');
}
function select_box_init(domChunk){
	$(domChunk).mouseover(function(){

	if(this.className=="select_box_title_left_off")
	{
		this.className = "select_box_title_left_on";
	}

	return false;
	});	
}
if (window.attachEvent) 
{
 window.attachEvent("onload", select_box);

} 
else 
{
 window.addEventListener("DOMContentLoaded", select_box, false);
}
*/

/** SEARCH BOX **/
function sb_akce(id,obj)
{
	var str = "Hledat..";
    if ((obj.value==str) && (!id))
    {
		obj.value = "";
    }
    if (obj.value=="" && id)
    {
		obj.value = str;
    }
}
function sb_keypress(e)
{
    if (e.keyCode==13)
    {
		sb_check();
    }
}
function sb_check()
{
	if(document.getElementById('q').value.length > 2 && document.getElementById('q').value!="Hledat..")
	{
		
		document.getElementById('sb_form_hledat').submit();
	}
	else
	{
		alert_box(2,'Zadejte výraz, který chcete vyhledat!<br />(Minimálně 3 znaky)','Hledání','q');
		return false;
	}
}
function sb_mouseover(id)
{
	if(id==1)
	{
		document.getElementById('header_search_button').className="header_search_button2";
	}
	else
	{
		document.getElementById('header_search_button').className="header_search_button4";
	}
	
}
function sb_mouseout(id)
{
	if(id==1)
	{
		document.getElementById('header_search_button').className="header_search_button";
	}
	else
	{
		document.getElementById('header_search_button').className="header_search_button";
	}	
	
}
function sb_mousedown(id)
{
	if(id==1)
	{
		document.getElementById('header_search_button').className="header_search_button3";
	}
	
}
function sb_mouseup(id)
{
	if(id==1)
	{
		document.getElementById('header_search_button').className="header_search_button2";
	}
	
}

function otevri(url,delka,vyska,id)
{
	if(!delka) delka = 700;
	if(!vyska) vyska = 400;
	
	var screenW = 640, screenH = 480;
	if (parseInt(navigator.appVersion)>3) {
	 screenW = screen.width;
	 screenH = screen.height;
	}
	else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled()) 
	{
	 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
	 var jScreenSize = jToolkit.getScreenSize();
	 screenW = jScreenSize.width;
	 screenH = jScreenSize.height;
	}

	var levy = (screenW - delka)/2;
	var horni = (screenH - vyska)/2;
	
	var bars = "toolbar=0,resizable=1,scrollbars=1";
	
	if(id == 1)
	{
		bars = "toolbar=1,resizable=1,scrollbars=1";
	}
	
	myRef = window.open(url,'mywin','left='+levy+',top='+horni+',width='+delka+',height='+vyska+','+bars);	
	//window.open(id);
}

/** OZNACI VYBRANEJ SELECT **/
function select_vyber(id,val)
{

	var obj = document.getElementById(id);
	var selLength = obj.length;

	  for(i=selLength-1; i>=0; i--)
	  {
	  	if(obj.options[i].value==val)
	  	{
			obj.options[i].selected = true;
		}		
	  }	
	  
}

/** OZNACI VYBRANEJ CHECKBOX **/
function checkbox_vyber(id)
{

	var obj = document.getElementById(id);
	obj.checked = true;
	  
}

/** OZNACI VYBRANEJ CHECKBOX **/
function other_vyber(id,value)
{
	if(!id) return false;
	
	hodnota = value.split(";");

	if(value)	
	{
		if(id.length)
		{
			for (i = 0; i < id.length; i++)
			{
				for (j = 0; j < hodnota.length; j++)
				{
					if(id[i].value == hodnota[j])
					{
						id[i].checked = true;
					}
				}
			}
		}
		else
		{
				for (j = 0; j < hodnota.length; j++)
				{
					if(id.value == hodnota[j])
					{
						id.checked = true;
					}
				}		
		}	
	}	  
}

function onlyone()
{
	//alert(1);
	//id.value = id.value;
}


/** PRO MODUL CATEGORIES A MODULI VYUZIVAJICI TENTO MODUL **/

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOptionX(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOptionX(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function moveOptionsX(theSelFrom, theSelTo, akce, id)
{


  var selLength = theSelFrom.length;
  var ulozit = document.getElementById(id);
  var selLengthTo = theSelTo.length;
  var selLengthToMore = 0;
  var selLengthFromMore = 0; 
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;


  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
    	if(akce)
    	{
			deleteOptionX(theSelFrom, i);
			selLengthFromMore++;
			selectedCount++;
		}
		else
		{
		    selectedText[selectedCount] = text_uprav(theSelFrom.options[i].text);
		    selectedValues[selectedCount] = theSelFrom.options[i].value;		
			selectedCount++;
		}
      
    }
  }
  
   	if(!akce)
  	{ 
  		if(selLengthTo>0)
  		{
 			for(j=selectedCount-1; j>=0; j--)			
			{
				var stejny = false;
				for(i=selLengthTo-1; i>=0; i--)
				{
					if(theSelTo.options[i].value==selectedValues[j])
					{
						stejny = true
					}
					
				}				
				
				if(!stejny)
				{
					addOptionX(theSelTo, selectedText[j], selectedValues[j]);
					selLengthToMore++;
				}
				else
				{
					alert_box(2,"Položka <strong>"+selectedText[j]+"</strong> je již zvolená!","Pozor");
				}						
		    }			

		}
		else
		{
		
		  for(i=selectedCount-1; i>=0; i--)
		  {
				addOptionX(theSelTo, selectedText[i], selectedValues[i]); 
				selLengthToMore++;
		  }			
		}

    }


	var uloz = "";  	

	if(!akce)
	{
		for(i=selLengthTo+selLengthToMore-1; i>=0; i--)
		{
			uloz+=theSelTo.options[i].value + ",";			
		}			
	}
	else
	{
		for(i=selLength-selLengthFromMore-1; i>=0; i--)
		{
			uloz+=theSelFrom.options[i].value + ",";			
		}		
	}

	ulozit.value = uloz;
	categories_buttons(id);
}

function text_uprav(id)
{
	vrat = id.replace("-- ", "");
	if(vrat.match("-- "))
	{
		vrat = text_uprav(vrat);
	}	
	
	return vrat;
}

function vypln_chosen(id)
{
	values = document.getElementById(id);
	chosen = document.getElementById(id+"_chosen");
	choose = document.getElementById(id+"_choose");
	
	uloz = "";
	
	pole = values.value.split(","); 
	for(i=0;i<(pole.length-1);i++)
	{
	  for(j=choose.length-1; j>=0; j--)
	  {
	    if(choose.options[j].value==pole[i])
	    {
	    	addOptionX(chosen, text_uprav(choose.options[j].text), choose.options[j].value);
	    	uloz+=choose.options[j].value+",";
	    }
	  }	    	
	}
	values.value = uloz;
}

function categories_buttons(id)
{
	
	onlyone = document.getElementById(id+"_onlyone").value;
	button_tam = document.getElementById(id+"_button_tam");
	button_zpet = document.getElementById(id+"_button_zpet");
	chosen = document.getElementById(id+"_chosen");
	
	if(onlyone == "true" && (chosen.length*1)>0)
	{
		button_tam.disabled = true;
	}
	else
	{
		button_tam.disabled = false;
	}
	
	if(chosen.length>0)
	{
		button_zpet.disabled = false;
	}
	else
	{
		button_zpet.disabled = true;
	}
	
}

function kod_reload()
{
	var plus = Date.parse(new Date().toString());;
	document.getElementById('kod_image').src = basedir+"/antispam.php?"+plus;
}

            function over_hodnotu_odesli(hodnota,page) {            	 
                script = document.createElement('script');
                script.id = 'scriptLoader';
                script.src = basedir + '/module/'+ page +'.php?value='+hodnota;				
                Xx = document.getElementsByTagName('head')[0];                
                Xx.appendChild(script);

            }
            function over_hodnotu(id,page)
            {
            	
                var hodnota = id;
			if (hodnota.value.length == 0) return;
                over_hodnotu_odesli(hodnota.value,page);                
            }
            function over_hodnotu_value(id,page)
            {
                var hodnota = id;
			if (hodnota.length == 0) return;
                over_hodnotu_odesli(hodnota,page);               
            } 

function basename(path, suffix) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
 
    var b = path.replace(/^.*[\/\\]/g, '');
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    return b;
}

function vlozit_do_kosiku(id,produkt_id)
{	
	kus_hodnota = document.getElementById(id).value;
	kus = kus_hodnota.split(" ");
	
	if(kus[0]>0)
	{
		//tb_show(false,false,false,true);
		hodnota = produkt_id +'&ks='+ kus[0] +'&add';
		over_hodnotu_value(hodnota,'content_module/cart');		
	}
	else
	{
		alert_box(2,"Zadejte počet kusů","Nákupní košík");
	}	
	

}

function uprav_kosik(id,produkt_id)
{	
	
	kus_hodnota = document.getElementById(id).value;
	kus = kus_hodnota.split(" ");
	
	if(kus[0]>0)
	{
		//tb_show(false,false,false,true);	
		hodnota = produkt_id +'&ks='+ kus[0] +'&edit';	
		over_hodnotu_value(hodnota,'content_module/cart');
	}
	else
	{
		alert_box(2,"Zadejte počet kusů","Nákupní košík");
	}		

}

function odeber_z_kosiku(produkt_id)
{	
	hodnota = produkt_id +'&erase';	
	over_hodnotu_value(hodnota,'content_module/cart');	
}

function enter_stisk_kosik(id,produkt_id,opravit)
{
	if(document.getElementById(id))
	{
		document.getElementById(id).onkeypress= function(e){
				if(!e)
				{
					key = event.keyCode;
				}
				else
				{
					key = e.which;
				}
				
				if(key == "13"){
					if(opravit)
					{
						uprav_kosik(id,produkt_id);
					}
					else
					{
						vlozit_do_kosiku(id,produkt_id);
					}
					
				}
		}
	}	
}



function uprav_OBJkosik(id,produkt_id)
{	
	
	kus_hodnota = document.getElementById(id).value;
	kus = kus_hodnota.split(" ");
	
	if(kus[0]>0)
	{
		//tb_show(false,false,false,true);	
		hodnota = produkt_id +'&ks='+ kus[0] +'&edit';	
		over_hodnotu_value(hodnota,'content_module/objednavka_cart');
	}
	else
	{
		alert_box(2,"Zadejte počet kusů","Nákupní košík");
	}		

}

function odeber_z_OBJkosiku(produkt_id)
{	
	hodnota = produkt_id +'&erase';	
	over_hodnotu_value(hodnota,'content_module/objednavka_cart');	
}

function enter_stisk_OBJkosik(id,produkt_id,opravit)
{
	if(document.getElementById(id))
	{
		document.getElementById(id).onkeypress= function(e){
				if(!e)
				{
					key = event.keyCode;
				}
				else
				{
					key = e.which;
				}
				
				if(key == "13"){
					uprav_OBJkosik(id,produkt_id);					
				}
		}
	}	
}


/** UPRAVIT PORADI  **/

function moveUp(element) {
  for(i = 0; i < element.options.length; i++) {
    if(element.options[i].selected == true) {
      if(i != 0) {
        var temp = new Option(element.options[i-1].text,element.options[i-1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i-1] = temp2;
        element.options[i-1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function moveDown(element) {
  for(i = (element.options.length - 1); i >= 0; i--) {
    if(element.options[i].selected == true) {
      if(i != (element.options.length - 1)) {
        var temp = new Option(element.options[i+1].text,element.options[i+1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i+1] = temp2;
        element.options[i+1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function updateList(list, textBox) {
  textBox.value = '';
  for(i = 0; i < list.options.length; i++) {
    if (i == 0) {
      textBox.value += list.options[i].value;
    } else {
      textBox.value += ',' + list.options[i].value;
    }
  }
}
function swap(list) {
  var j = 0;
  for(i = 0; i < list.options.length; i++) {
    if(list.options[i].selected == true) {
      j++;
      switch (j) {
        case 1:
        var i1 = i;
        var temp = new Option(list.options[i].text, list.options[i].value);
        break;
        case 2:
        var i2 = i;
        var temp2 = new Option(list.options[i].text, list.options[i].value);
        break;
      }
    }
  }
  if (j != 2) {
    alert_box(2,"Prohodit položku můžete pouze tehdy, když máte označené dvě položky!","Chyba při obsluze aplikace");
  } else {
    list.options[i1] = temp2;
    list.options[i1].selected = true;
    list.options[i2] = temp;
    list.options[i2].selected = true;
  }
}

 function CreateBookmarkLink() { 
	title = page_title;   
	url = page_url;  
	
	if (window.sidebar) { 
	 	// Mozilla Firefox Bookmark		
		 window.sidebar.addPanel(title, url,"");	
	} 
	else if( window.external ) { 
		// IE Favorite		
		window.external.AddFavorite( url, title); 
	}	
	else if(window.opera && window.print) { 
		alert_box(1,"Pro přidání k oblíbeným stiskni CTRL + D","Přidat k oblíbeným");	 
	} 
}

