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);
	}
	
	
	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 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');
	}
	
	
	function selectToAutocomplete(selectId) {
    var maxHints = 10;
    if (selectId == null || document.getElementById(selectId) == null || document.getElementById(selectId).options == null) return false;
    select = document.getElementById(selectId);
    select.style.display = 'none';
    var dataList = [];
    for (var i = 0; i < select.options.length; i++) {
        dataList[i] = select.options[i].text;
    }
    var searchInput = document.createElement('input');
    searchInput.setAttribute('name', 'searchFor' + selectId);
    // pridej inputu onpress
    var resultsList = document.createElement('div');
    resultsList.setAttribute('id', 'resultsFor' + selectId);
    resultsList.setAttribute('class', 'autocompleteSelect');
    resultsList.style.display = 'none';
    searchInput.setAttribute('autocomplete', 'off');
	searchInput.setAttribute('class','autocompleteField');
	/*searchInput.onblur = function() {
		 var resultDiv = document.getElementById('resultsFor' + selectId);
        resultDiv.style.display = 'none';
	}*/
	
	searchInput.onfocus = function() {
		 var resultDiv = document.getElementById('resultsFor' + selectId);
        if (searchInput.value) {
            resultDiv.style.display = 'block';
            return;
        }
	}
	
    searchInput.onkeyup = function () {
        var results = document.createElement('div');
        var resultDiv = document.getElementById('resultsFor' + selectId);
        if (!searchInput.value) {
            resultDiv.innerHTML = '';
            resultDiv.style.display = 'none';
            return;
        }
        searchPattern = searchInput.value;
        re = new RegExp(searchPattern, "gi");
		select.selectedIndex = i; 
        var numShown = 0;
        for (i = 1; i < dataList.length; i++) {
            if (dataList[i].search(re) != -1) {
                var result = document.createElement('p');
                result.onclick = function (val, i) { return function () { searchInput.value = val; select.selectedIndex = i; resultDiv.style.display = 'none'; }; } (dataList[i], i);
                result.innerHTML = dataList[i];
                results.appendChild(result);
                numShown++;
            }
            if (numShown == maxHints) {
                break;
            }
        }

        resultDiv.innerHTML = '';
        resultDiv.appendChild(results);

        resultDiv.style.display = 'block';
    }
    select.parentNode.appendChild(searchInput);
    select.parentNode.appendChild(resultsList);
}
