function newWindow(fileURL,width,height) {
	w = width;
	h = height+110;
	options='width='+w+',height='+h;
	okno=window.open(fileURL,'',options);
}

	var value=0;

	function addF(fId,iType,iName,iValue,resitele) {
	
		var f = document.getElementById(fId);
		value++;
		var div = document.createElement('div');
		div.setAttribute('id',iName+value);
		if (iType == "select") {
		
			var i = document.createElement('select');
			i.setAttribute('name',iName);
			var option = document.createElement('option');
			option.setAttribute("value",0);
			var text = document.createTextNode('Bez řesitele');
			option.appendChild(text);
			i.appendChild(option);
			for ( x=0;x<resitele.length;x++) {
				var option = document.createElement('option');
				option.setAttribute("value",x+1);
				var text = document.createTextNode(resitele[x]);
				option.appendChild(text);
				i.appendChild(option);
			}
		} else {
			var i = document.createElement('input');
			i.setAttribute('type',iType);
			i.setAttribute('name',iName);
			i.setAttribute('value',iValue);
		}
		var a = document.createElement('a');
		a.setAttribute('href','javascript:removeF(\"'+fId+'\",\"'+iName+value+'\")');	
		var linkText = document.createTextNode('Odebrat');
		
		a.appendChild(linkText);
		div.appendChild(i);
		div.appendChild(document.createTextNode(" "));
		div.appendChild(a);
		f.appendChild(div);
		document.getElementById('footer').style.top = document.getElementById("page").scrollHeight+"px";
	}
	function removeF(fId,id) {
		var f = document.getElementById(fId);
		var el = document.getElementById(id);
		if (el) f.removeChild(el);
	}
	
	/**
	 * Vytvori novy radek pro velikost
	 * @param fId nove vytvorene divy se budou vkladat do elementu s id=fId
	 * @param iName nazev inputu v novem divu (napr. 'hodnota[]')
	 * @param hodnota1 velikost.hodnota1
	 * @param hodnota2 velikost.hodnota2
	 * @param poznamka velikost.poznamka
	 * @param ceny velikost.cena = pole cen (ceny[idCenoveTridy] = hodnota)
	 * @param regiony pole s nadpisy regionu (regiony[idRegionu] = nadpis)
	 * @param active checkbox pro aktivni/neaktivni velikost
	 * @param velId id velikosti
	 */
	function addVelikost(fId,iName,hodnota1,hodnota2,poznamka,ceny,regiony,active,velId) {
		var f = $(fId);
		if(velId==null)
			velId = 'new'+value;
		value++;
		var div = document.createElement('div');
		div.setAttribute('id',iName+value);
		
		// odkaz pro smazani
		var a = document.createElement('a');
		a.setAttribute('href','javascript:removeF(\"'+fId+'\",\"'+iName+value+'\")');
		a.setAttribute('class','butDelete');
		var span = document.createElement('span');
		var linkText = document.createTextNode('Smazat');
		span.appendChild(linkText);
		a.appendChild(span);
		

		var h1 = document.createElement('input');
		h1.setAttribute('type','text');
		h1.setAttribute('name','hodnota1_'+iName+'['+velId+']');
		h1.setStyle('float','left');
		h1.setStyle('display','block');
		if(h1!=null)	h1.setAttribute('value',hodnota1);
		
		var h2 = document.createElement('input');
		h2.setAttribute('type','text');
		h2.setAttribute('name','hodnota2_'+iName+'['+velId+']');
		h2.setStyle('float','left');
		h2.setStyle('display','block');
		if(hodnota2!=null)	h2.setAttribute('value',hodnota2);
		
		var p = document.createElement('input');
		p.setAttribute('type','text');
		p.setAttribute('name','poznamka_'+iName+'['+velId+']');
		p.setStyle('float','left');
		p.setStyle('display','block');
		if(poznamka!=null)	p.setAttribute('value',poznamka);

		// vygenerujeme pole s text inputy pro ceny vsech jazykovych verzi (aktualni a puvodni cena)
		var c = Array();
		for (var i = 1; i < 2 * regiony.length - 1; i++) {
			c[i] = document.createElement('input');
			c[i].setAttribute('type','text');
			c[i].setAttribute('name','cena_'+iName+'['+velId+']'+'['+i+']');
			c[i].setStyle('float','left');
			c[i].setStyle('display','block');
			if(ceny!=null && ceny[i]!=null)	c[i].setAttribute('value',ceny[i]);
		}

		var checkbox = document.createElement('input');
		checkbox.setAttribute('type','checkbox');
		checkbox.setStyle('float','left');
		checkbox.setStyle('display','block');
		checkbox.setStyle('width','14px');
		checkbox.setStyle('margin','0 5px');
		checkbox.setStyle('margin-top','2px');
		if(active==1 || hodnota1==null || hodnota2==null || poznamka==null) checkbox.setAttribute('checked','checked');
		checkbox.name='check_'+iName+'['+velId+']';
		
		div.appendChild(h1);
		div.appendChild(h2);
		div.appendChild(p);
		div.appendChild(checkbox);
		div.appendChild(a);
		div.appendChild(new Element('div', {'class': 'cl', html: '&nbsp;'}));
		for (var i = 1; i < c.length; i++) {
			if (i % 2 == 1)	div.appendChild(new Element('span', {html: regiony[Math.round(i/2)] + ': '}));
			div.appendChild(c[i]);
			//if (i % 2 == 0)	div.appendChild(new Element('span', {html: '&nbsp;/&nbsp;'}));
			//else			div.appendChild(new Element('span', {html: '&nbsp;'}));
			if (i % 6 == 0)	div.appendChild(new Element('div', {'class': 'cl', html: '&nbsp;'}));
		}
		div.appendChild(new Element('div', {'class': 'cl', html: '&nbsp;'}));
		f.appendChild(div);
		document.getElementById('footer').style.top = document.getElementById("page").scrollHeight+"px";
	}

	// old
	/*
	function addVelikost(fId,iName,hodnota1,hodnota2,poznamka,cenaCz,cenaEu,active,velId) {
	//function addVelikost(fId,iName,hodnota,cenaCz,cenaEu,active,velId) {
		var f = $(fId);
		if(velId==null)
			velId = 'new'+value;
		value++;
		var div = document.createElement('div');
		div.setAttribute('id',iName+value);
		
		// odkaz pro smazani
		var a = document.createElement('a');
		a.setAttribute('href','javascript:removeF(\"'+fId+'\",\"'+iName+value+'\")');
		a.setAttribute('class','butDelete');
		var span = document.createElement('span');
		var linkText = document.createTextNode('Smazat');
		span.appendChild(linkText);
		a.appendChild(span);
		
		var h1 = document.createElement('input');
		h1.setAttribute('type','text');
		h1.setAttribute('name','hodnota1_'+iName+'['+velId+']');
		h1.setStyle('float','left');
		h1.setStyle('display','block');
		if(h1!=null)	h1.setAttribute('value',hodnota1);
		
		var h2 = document.createElement('input');
		h2.setAttribute('type','text');
		h2.setAttribute('name','hodnota2_'+iName+'['+velId+']');
		h2.setStyle('float','left');
		h2.setStyle('display','block');
		if(hodnota2!=null)	h2.setAttribute('value',hodnota2);
		
		var p = document.createElement('input');
		p.setAttribute('type','text');
		p.setAttribute('name','poznamka_'+iName+'['+velId+']');
		p.setStyle('float','left');
		p.setStyle('display','block');
		if(poznamka!=null)	p.setAttribute('value',poznamka);

		var cenaCzk = document.createElement('input');
		cenaCzk.setAttribute('type','text');
		cenaCzk.setAttribute('name','cena_czk_'+iName+'['+velId+']');
		cenaCzk.setStyle('float','left');
		cenaCzk.setStyle('display','block');
		if(cenaCz!=null)cenaCzk.setAttribute('value',cenaCz);
		
		var cenaEur = document.createElement('input');
		cenaEur.setAttribute('type','text');
		cenaEur.setAttribute('name','cena_eur_'+iName+'['+velId+']');
		cenaEur.setStyle('float','left');
		cenaEur.setStyle('display','block');
		if(cenaEu!=null)cenaEur.setAttribute('value',cenaEu);

		var checkbox = document.createElement('input');
		checkbox.setAttribute('type','checkbox');
		checkbox.setStyle('float','left');
		checkbox.setStyle('display','block');
		checkbox.setStyle('width','14px');
		checkbox.setStyle('margin','0 5px');
		checkbox.setStyle('margin-top','2px');
		if(active==1 || hodnota1==null || hodnota2==null || poznamka==null) checkbox.setAttribute('checked','checked');
		checkbox.name='check_'+iName+'['+velId+']';
		
		div.appendChild(h1);
		div.appendChild(h2);
		div.appendChild(p);
		div.appendChild(cenaCzk);
		div.appendChild(cenaEur);
		div.appendChild(checkbox);
		div.appendChild(document.createTextNode(" "));
		div.appendChild(a);
		div.appendChild(new Element('div', { 'class': 'cl', html: '&nbsp;'}));
		f.appendChild(div);
		document.getElementById('footer').style.top = document.getElementById("page").scrollHeight+"px";
	}
	*/
	
	var val=0;
	
	function cloneSelect (fId, iName, elementId, selectedId) {
	
		var f = document.getElementById(fId);
		
		var div = document.createElement('div');
		div.setAttribute('id',iName+val);
		
		var obj = document.getElementById(elementId).cloneNode(true);
		
		obj.name = iName;
		obj.setAttribute('id',iName+val);
		obj.style.display = 'inline';
		if(selectedId!="") obj.options[selectedId].selected  =true;
		else obj.options[0].selected  =true;
		//alert(selectedId);
		
		var a = document.createElement('a');
		a.setAttribute('href','javascript:removeF(\"'+fId+'\",\"'+iName+val+'\")');	
		//var linkText = document.createTextNode(""  border=\"0\" alt=\"\">");
		var oImg=document.createElement("img");
		oImg.setAttribute('src', "/imgs/admin/user_delete.png");
		oImg.setAttribute('alt', "Přidat dalši");
		oImg.setAttribute('border', '0');
		oImg.style.position = 'relative';
		oImg.style.top = '5px';
		oImg.style.marginLeft = '4px';
		a.appendChild(oImg);
		//a.appendChild(linkText);
		
		div.appendChild(obj);
		div.appendChild(a);
		f.appendChild(div);
		document.getElementById('footer').style.top = document.getElementById("page").scrollHeight+"px";
		
		val++;
	}

	function hideTab(id){
		object = document.getElementById(id);
		object.style.display='none';
		$(id+'Tab').set('class',"");
	}


	function showTab(id){
		object = document.getElementById(id);
		object.style.display='';
		$(id+'Tab').set('class',"active");
	}

	function SetChecked(val,chkName) {
	    dml=document.forms[form];
	    len = dml.elements.length;
	    var i=0;
	    for( i=0 ; i<len ; i++) {
	        if(dml.elements[i].disabled!=1){        
	            dml.elements[i].checked=val;
	        }
	    }
	}

	function multicheck(classname, checked) {
		$$('.' + classname).each(function(el) {el.checked = checked == 1 ? true : false;});
	}

	function addToCart(idZbozi,pocet){
		new Request.HTML({url:'/carthandler',data: {'pridat_do_kosiku' : idZbozi,'pocet':pocet}, update:'ajaxCartFrame',link:'chain'}).post();
		
	}
	
	function showHide(id){
		object = document.getElementById(id);
		if (object.style.display == "none"){
		object.style.display='';
		}else{
		object.style.display='none';}
	}

	
	function fadeout(div){
		$(div).fade('out');
	}
	
