function findObj(n, d) {  
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { 
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} 
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document); 
  if(!x && document.getElementById) x=document.getElementById(n); return x; 
} 


function replaceText(node, text)
{
    while (node.hasChildNodes()) {
        node.removeChild(node.firstChild);
    }
    node.appendChild(document.createTextNode(text));
}


function innerXHTML(node, html)
{
    while (node.hasChildNodes()) {
        node.removeChild(node.firstChild);
    }
    
    _doInnerXHTML(node, html)
}


function _doInnerXHTML(node, html)
{
    /* Pokud je v textu značka */
    if ((index = html.indexOf('<')) != -1) {
        /* Pokud je před značkou ještě nějaký text */
        if (index != 0) {
            text = html.substring(0, index);
            node.appendChild(document.createTextNode(text));
            html = html.substr(index);
//            alert('text:"'+text+'" html:"'+html+'"');
        }

        /* Teď by měl text začínat "<" */
        if ((index = html.indexOf('>')) != -1) {            
            /* Do prom. tag si uložim celou značku bez špič. závorek */
            tag = html.substring(1, index);
            /* V textu nechám zbytek po tagu */
            html = html.substr(index + 1);
            
//            alert('tag:"'+tag+'" html:"'+html+'"');
            /* Pokud jde o ukončovací tag */
            if (tag.charAt(0) == '/') {
                endTag = true;
                if (html.length > 0) {
                    _doInnerXHTML(node.parentNode, html);
                }
            } else {
                endTag = false;
                /* Pokud jde o prázdný element */
                if (tag.charAt(tag.length - 1) == '/') {
                    empty = true;
                    tag = tag.substr(0, tag.length - 1);
                /* Pokud jde o počáteční tag */
                } else {
                    empty = false;
                }

                /* Rozdělim na části oddělené mezerou */
                /* Tohle je chyba - mezery můžou být i v hodnotách atributů.
                Ale zatim se mi nedaří to udělat líp.
                */
                tagParts = tag.split(/\s+/);
                
                if (tagParts[tagParts.length - 1] == "") {
                    tagParts.pop();
                }
            
                /* Vytvořím požadovaný element (na atributy zatím dlabu) */
                newElement = node.appendChild(document.createElement(tagParts[0]));
                
                /* Naplním element atributy */
                for (i=1; i<tagParts.length; i++) { // Projdeme všechny prvky kromě názvu
                    attrib = tagParts[i]
                    attrName = attrib.replace(/^([^=]+)(=.+)?$/, "$1");
                    if (attrib.indexOf("=") != -1) {
                        attrValue = attrib.replace(/^[^=]+="?([^"]*)"?$/, "$1");
                    } else {
                        attrValue = "";
                    }
                    newElement.setAttribute(attrName, attrValue);
//                    alert('name:"'+attrName+'" value:"'+attrValue+'"');
                }

                /* Pokud ještě zbývá nějaký text */
                if (html.length > 0) {
                    if (empty) {
                        _doInnerXHTML(node, html);
                    } else {
                        _doInnerXHTML(newElement, html);
                    }
                }
            }
        }
    } else {
        /* Pokud ještě v textu zbyl nějaký text */
        if (html.length > 0) {
            node.appendChild(document.createTextNode(html));
        }
    }

}

function number_format(  number,  laenge, sep, th_sep ) {

  number = Math.round( number * Math.pow(10, laenge) ) / Math.pow(10, laenge);
  str_number = number+"";
  arr_int = str_number.split(" ");
  if(!arr_int[0]) arr_int[0] = "0";
  if(!arr_int[1]) arr_int[1] = "";
  if(arr_int[1].length < laenge){
    nachkomma = arr_int[1];
    for(i=arr_int[1].length+1; i <= laenge; i++){  nachkomma += "0";  }
    arr_int[1] = nachkomma;
  }
  if(th_sep != "" && arr_int[0].length > 3){
    Begriff = arr_int[0];
    arr_int[0] = "";
    for(j = 3; j < Begriff.length ; j+=3){
      Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
      arr_int[0] = th_sep + Extrakt +  arr_int[0] + "";
    }
    str_first = Begriff.substr(0, (Begriff.length % 3 == 0)?3:(Begriff.length % 3));
    arr_int[0] = str_first + arr_int[0];
  }
  return arr_int[0]+sep+arr_int[1];
}




	function get_radio_value (radio_array) {
	
		var i;
		for (i = 0; i < radio_array . length; ++ i)
		if (radio_array [i] . checked)
			return radio_array [i] . value;
			return null;

	}


	function zmenaDopravy() {
	
		if (get_radio_value(document.kosikform.doprava)=="profibalik") {			
			var cena="119";
			
		}
		if (get_radio_value(document.kosikform.doprava)=="ppl") {
			
			var cena="119";
			
		}
		if (get_radio_value(document.kosikform.doprava)=="ravi") {
			var cena="140";
		}
		if (get_radio_value(document.kosikform.doprava)=="osobniodber") {
			var cena="0";
		}
		var mystring=number_format(cena,  0, "", " " )+" Kč";
	/*	if (document.layers){
					document.layers.dopravacenadotabulky.document.write(mystring)
					document.layers.dopravacenadotabulky.document.close()
				}
				else if (document.all) dopravacenadotabulky.innerHTML=mystring
*/
	
		var mystring2=number_format(((cena*10)/10)+((document.kosikform.cenacelkem.value*10)/10),  0, "", " " )+" Kč";
		/*if (document.layers){
					document.layers.cenacelkemdotabulky.document.write(mystring2)
					document.layers.cenacelkemdotabulky.document.close()
				}
				else if (document.all) cenacelkemdotabulky.innerHTML=mystring2; */
		replaceText(document.getElementById('cenacelkemdotabulky'), mystring2);
		replaceText(document.getElementById('dopravacenadotabulky'), mystring);
		document.udaje.dopravavyber.value=get_radio_value(document.kosikform.doprava);	
		document.udaje.dopravavybercena.value=cena;	
	}

	function zmenaUhrady() {
	
/*		if (get_radio_value(document.kosikform.uhrada)=="multiservis") {
			document.kosikform.doprava[0].disabled=true;
			document.kosikform.doprava[1].disabled=true;
			document.kosikform.doprava[2].disabled=false;
			document.kosikform.doprava[2].checked=true;
			document.kosikform.doprava[3].disabled=false;
			
		}*/

	if (get_radio_value(document.kosikform.uhrada)=="dobirka") {

			
			document.kosikform.doprava[0].disabled=false;
			/*document.kosikform.doprava[1].disabled=false;			*/
			document.kosikform.doprava[1].disabled=true;
			document.kosikform.doprava[0].checked=true;
			
		}
	
		if (get_radio_value(document.kosikform.uhrada)=="proforma") {
			document.kosikform.doprava[0].disabled=true;
			if (document.kosikform.doprava[0].checked==true) document.kosikform.doprava[1].checked=true;
			document.kosikform.doprava[1].disabled=false;			
			document.kosikform.doprava[2].disabled=false;
			
		}
		
		if (get_radio_value(document.kosikform.uhrada)=="hotove") {
			document.kosikform.doprava[0].disabled=true;			
			/* document.kosikform.doprava[1].disabled=true; */
			
			document.kosikform.doprava[1].disabled=false;
			document.kosikform.doprava[1].checked=true;
			
		}
		document.udaje.formavyber.value=get_radio_value(document.kosikform.uhrada);

		
		zmenaDopravy();
	}
	
function searchTest() {
	if (document.vyhledavani.search.value.length<3) {
		alert("Řetězec musí obsahovat alespoň tři znaky");
		return false;
	}
	return true;
}

function dotazTest() {
	if (document.dotaz.mail.value.length<7) {
		alert("Musíte vyplnit email !");
		return false;
	}
	return true;
}

function openOdkazForm(produkt) {
	window.open("odkaz.php?produkt="+produkt,"spytarkdotaz","width=400,height=385,status=no,scrollbars=no,resizable=no,toolbar=no,menubar=no");
}

function addBookmark(title,url) { 
if (window.sidebar) { 
window.sidebar.addPanel(title, url,""); 
} else if( document.all ) { 
window.external.AddFavorite( url, title); 
} else if( window.opera && window.print ) { 
return true; 
} 
} 