


function noneblock(id){
	//alert(document.getElementById(id).style.display);
	if (document.getElementById(id).style.display == "block") 	{document.getElementById(id).style.display = "none";}
	else 																												{document.getElementById(id).style.display = "block";}
	}



function npol(parent,hodnota){
	var nova;
	nova = document.getElementById("pocet["+parent+"]").value * 1 + hodnota;
	if (nova<0)  {nova=0 ;}
	document.getElementById("pocet["+parent+"]").value = nova;
	document.getElementById("pocet["+parent+"]").focus();
	
	}


function chpoz(id){
	document.getElementById("poz["+id+"]").checked=true;
	}


function cenadph(){
	cena 	= document.getElementById("cena").value;
	dph 	= document.getElementById("dph").value;
	
	cena_s_dph = Math.round( cena * (dph/100+1)) ;
	
	document.getElementById("sdph").innerHTML  = cena_s_dph;
	
	if(cena_s_dph > 0) document.getElementById("eshop_z").checked  = true;
	}




function dopr_clear(id){
	document.getElementById("doprava["+id+"][zpusob]").value="";
	document.getElementById("doprava["+id+"][cena]").value="";
	document.getElementById("doprava["+id+"][vaha_do]").value="";
	document.getElementById("doprava["+id+"][dobirka]").checked  	= false;
	document.getElementById("doprava["+id+"][zobrazit]").checked  = false;
	}


function doprava_change(zpusob,cena){
	document.getElementById("doprava[zpusob]").value	=	zpusob;
	document.getElementById("doprava[cena]").value		=	cena;
	celkcena();
	$.colorbox.close();
	}



function celkcena(){
	var cena_dopravy, cena_zbozi, celkova_cena; 
	cena_dopravy 	= document.getElementById("doprava[cena]").value * 1;  
	cena_zbozi 		= document.getElementById("celkem_zbozi").value * 1;  
	celkova_cena 	=   cena_zbozi + cena_dopravy ;
	document.getElementById("celkem_s_dopravou").innerHTML = celkova_cena+"&nbsp;Kč";
	} 




function disab(id){
	document.getElementById(id).disabled = true;
	} 

function enab(id){
	document.getElementById(id).disabled = false;
	} 


function dnone(id){
	if(el = document.getElementById(id)) el.style.display = "none";
	} 

function dblock(id){
	if(el = document.getElementById(id)) el.style.display = "block";
	} 


function dnone_all(){
	disab('foto_file');
	dnone('foto_pc');
	dnone('foto_url');
	dnone('foto_varovani');
	} 


function dblock_sel(id){
	dnone_all();
	if(id){
		document.getElementById(id).style.display = "block";
		document.getElementById('foto_varovani').style.display = "block";		
		if(id='foto_pc') document.getElementById('foto_file').disabled = false;
		}
	} 
	


function chall(odid,doid,co){
	for(i=odid;i<=doid;i++){
		if(el = document.getElementById("foto["+i+"][del]")) el.checked = co ? true : false;
		}
	}



function checkid(id){
	document.getElementById(id).checked  	= true;
	}





function areah(co, min_h){
	//min_height_a = 30;
	if(!min_h) min_h = 30;
	var el_a = document.getElementById(co);
	scrollHeight_a = el_a.scrollHeight + 20;
	if (scrollHeight_a > min_h) el_a.style.height = scrollHeight_a+"px";

	}




function disp(co,kam){
	var i = 0;
	var max = 9;

	if(kam == "binar"){
		max = 1;
		while(el = document.getElementById("dis["+co+"]["+i+"]")){
			if(el.style.display != "block")  { kam = i+1; break;} 
			i++;
			}
		if(kam > 1) kam = 0;	
		}
	else if(kam == "rotor"){
		while(el = document.getElementById("dis["+co+"]["+i+"]")){
			if(el.style.display != "block")  { kam = i+3; break;} 
			i++;
			}
		if(kam > 9) kam = 0;	
		}
	
	if(sipka = document.getElementById("img_r_"+co))	{
		if(kam >= max )		sipka.src = "obr/d_zabalit.gif";
		else 							sipka.src = "obr/d_rozbalit.gif";	
		} 
	
	i = 0;
	while(el = document.getElementById("dis["+co+"]["+i+"]")){
		if(kam>i) el.style.display = "block";
		else			el.style.display = "none";
		i++;
		}
	}



function dst(id){
	// alert(document.body.scrollTop);
	document.getElementById(id).value = document.documentElement.scrollTop;
	}
	
	

function sct(top)	{
	document.documentElement.scrollTop = top;
	}









/*  bb tagy  */

function insert_text(open, close)	{		// není potřeba, ale je přehlednější. možná časem dopíšeme

 // afocus 				je id formuláře. 		změněno na  	odst_form
 // req_message		je name  textarea. 	změněno na   	text
 
	msgfield = (document.all) ? document.all.text : ((document.getElementById('odst_form') != null) ? (document.getElementById('odst_form').text) : (document.getElementsByName('text')[0]));

	if (document.selection && document.selection.createRange)		{			// IE support
		msgfield.focus();
		sel = document.selection.createRange();
		sel.text = open + sel.text + close;			// tady je jediný původní 'text'
		msgfield.focus();
		}
	else if (msgfield.selectionStart || msgfield.selectionStart == '0')		{		// Moz support
		var startPos = msgfield.selectionStart;
		var endPos = msgfield.selectionEnd;
		var old_top = msgfield.scrollTop;
		msgfield.value = msgfield.value.substring(0, startPos) + open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
		msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length;
		msgfield.scrollTop = old_top;
		msgfield.focus();
		}
	else		{		// Fallback support for other browsers
		msgfield.value += open + close;
		msgfield.focus();
		}
	}

// ############################








/*   fugující z minibb */

function insertTag(tag) {
	var parovy = (tag != "hr");
	var  zalomit = "";
	if(tag == "ul" )  	zalomit = "\n";
	if(tag == "tab" )  	zalomit = "\n";
	
	var startTag = "[" + tag + "]"+zalomit;
	var endTag = zalomit+("[/" + tag + "]").replace(/(\[\/(?:pre|font))[^\]]+(\])|\[\/hr\]/gi, "$1$2");

	var selectionType = tag.match(/^pre|hr|mod/i) ? "" : "word";
	var selectionTrim = tag.match(/^pre|hr|mod/i) ? /^\n+|\n+$/g : /^\s+|\s+$/g;

	var tac = getTextareaSelection({ context: true, type: selectionType, trim: selectionTrim });
	var tagText = tac[1];


	// vytvoření textu pro vložení		
	var text2insert = startTag + tagText + endTag;

	var cursor = (tagText ? text2insert.length : startTag.length);
	insertText(text2insert, cursor);
}



function insertLink() {

	var tac = getTextareaSelection({ context: true, type: "url", expand: true, trim: /^\s+|\s+/g });
	var cursor = tac[4];
	var text2insert = tac[1] || getTextareaSelection({ type: "word", trim: /^\s+|\s+/g });

	m = text2insert.match(/^(\[url=[^\]]+\])(.*)\[\/url\]$/i);
	if(m && !m[2].match(/\[url=[^\]]+\]|\[\/url\]/i))	{
		cursor[0] -= m[1].length;
		if(cursor[0] < 0)		{
			cursor[1] = Math.max(cursor[0] + cursor[1], 0);
			cursor[0] = 0;
			}
		if(cursor[0] > m[2].length)		{
			cursor[0] = m[2].length;
			cursor[1] = 0;
			}
		if(cursor[0] + cursor[1] > m[2].length) cursor[1] = m[2].length - cursor[0];
		insertText(m[2], cursor);
		return;
		}
	m = text2insert.match(/^\s*\[img(?:left|right)?\](.*)\[\/img\]\s*$/i);
	if(m && !m[1].match(/\[img(?:left|right)?\]|\[\/img\]/i))	{
		insertText("[url=" + m[1] + "]Obrázek[/url]", [m[1].length + 6, 7]);
		return;
		}

	var uris = [], unpack = false;
	text2insert = text2insert.replace(/\[url=([^\]]+)\](.*?)\[\/url\]|(\s*https?\:\/\/(?:["‚„“‘\)\.…,:;]*[^\s"‚„“‘\)\.…,:;]+)+\s*)|(\s*www\.(?:["‚„“‘\)\.…,:;]*[^\s"‚„“‘\)\.…,:;]+)+\s*)/gi, function(m, m1, m1t, m2, m3)
	{
		if(m1) unpack = true;
		uris.push((m1 || m2 || "http://" + m3).trim());
		return m1 ? m1t : "";
	});
	if(!uris.length) 	{
		insertText("[url=http://www.example.com]" + (text2insert || "Odkaz") + "[/url]", [5, 22]);
		return;
	}
	
	if(unpack) 	{
		text2insert = text2insert + " " + uris.join(" ");
		insertText(text2insert, [0, text2insert.length]);
		return;
		}
		
		
	if(uris.length == 1) 	{
		if(text2insert)		{
			insertText("[url=" + uris[0] + "]" + text2insert + "[/url]", 12 + uris[0].length + text2insert.length);
			}
		else 		{
			text2insert = uris[0].replace(/^http\:\/\/www/, "www");
			insertText("[url=" + uris[0] + "]" + text2insert + "[/url]", [6 + uris[0].length, text2insert.length]);
			}
		return;
		}
	uris = uris.reverse();
	text2insert = text2insert.replace(/([-_a-z0-9áäéëěíóöôúůüýčďňŕřšťžĺľ]+|\[[^\]]+\])/gi, function(m)
	{
		var uri = uris.pop();
		return uri ? "[url=" + uri + "]" + m + "[/url]" : m;
	}).trim();
	for(var i = 1, uri; uri = uris.pop(); i++) 	{
		text2insert += (text2insert ? ", " : "") + "[url=" + uri + "]" + i + "[/url]";
		}
	insertText(text2insert, [0, text2insert.length]);
}




function insertText(inserted, cursor) {
	try { // textarea může být neviditelná, to pak hází chybu, ale špatně se to testuje

	if(inserted != null)	{
		inserted = inserted.toString().replace(/\r\n?/g, "\n");
		if(typeof cursor == "undefined") cursor = inserted.length;
		}

	var textarea = document.forms["odst_form"].elements["text"];
	if(textarea.readOnly) return;
	var scrollTop 		= textarea.scrollTop;
	var scrollHeight 	= textarea.scrollHeight;
	textarea.focus();
	
	if(typeof textarea.selectionStart != "undefined")
	{
		var sel = [], st = textarea.value.substr(0, textarea.selectionStart).replace(/\r\n?/g, "\n");
		sel[0] = Math.max(st.length + ((typeof cursor != "number") ? cursor[0] : cursor), 0);
		st += (inserted != null) ? inserted + textarea.value.substr(textarea.selectionEnd).replace(/\r\n?/g, "\n") : textarea.value.substr(textarea.selectionStart).replace(/\r\n?/g, "\n");
		sel[1] = Math.min(sel[0] + ((typeof cursor != "number") ? cursor[1] : 0), st.length);

		if(window.opera)		{
			// Opera převádí \n na \r\n, kurzor by se netrefil.
			for(var i = 0; i < 2; i++){
				var p = st.substr(0, sel[i]);
				sel[i] += p.length - p.replace(/\n/g, "").length;
				}
			}

		if(inserted != null) textarea.value = st;
		textarea.selectionStart = sel[0];
		textarea.selectionEnd = sel[1];
	}
	else if(typeof document.selection != "undefined") 	{
		var range = document.selection.createRange();
		var start = 0, end = 0;
		if(inserted != null)
		{
			start = end = -inserted.length;
			range.text = inserted;
		}
		else
		{
			end = -range.text.replace(/\r\n?/g, "\n").length;
		}
		
		// nastavení kurzoru na spravné místo / vybrání požadovaného textu
		if(typeof cursor != "number") 	{
			range.moveStart("character", start + cursor[0]);
			range.moveEnd("character", end + cursor[0] + cursor[1]);
			}
		else	{
			if(start + cursor) range.move("character", start + cursor);
			}
		range.select();
		}
	} catch(exc) {};
	if(window.netscape) 	{
		textarea.scrollTop = scrollTop + (textarea.scrollHeight - scrollHeight);
		}
}



function getTextareaSelection(options) {
	try { // může být neviditelná, to pak hází chybu, ale špatně se to testuje

	var textarea = document.forms["odst_form"].elements["text"];

	textarea.focus();

	var complete = options && (options.context || options.type || options.trim);
	var parts = [];

	if(typeof textarea.selectionStart != "undefined")
	{
		var pos = [textarea.selectionStart, textarea.selectionEnd];
		if(complete) pos = [0, pos[0], pos[1], textarea.value.length];
		for(var i = 1; i < pos.length; i++)
		{
			parts.push(textarea.value.substring(pos[i - 1], pos[i]).replace(/\r\n?/g, "\n"));
		}
		if(!complete) return parts[0];
	}
	else if(document.selection)
	{
		var range = [];
		range[2] = document.selection.createRange().duplicate();
		for(var i = (complete ? 0 : 2); i <= 2; i++)
		{
			if(i != 2)
			{
				range[i] = document.body.createTextRange();
				range[i].moveToElementText(textarea);
				range[i].setEndPoint(["EndToStart", "StartToEnd"][i], range[2]);
			}
			var text = range[i].text, lf = "";
			while(range[i].compareEndPoints("StartToEnd", range[i]))
			{
				range[i].moveEnd("character", -1);
				if(text == range[i].text) lf += "\n"; else break;
			}
			parts[{0:0, 1:2, 2:1}[i]] = text.replace(/\r\n?/g, "\n") + lf;
		}
		if(!complete) return parts[1];
	}
	else
	{
		if(!complete) return "";
		parts = ["", "", ""];
	}
	} catch(exc) {};

	if(options.trim)
	{
		var pt0 = "", pt2 = "";
		var pt1 = parts[1].replace(options.trim, function(m, index)
		{
			if(index == 0)
			{
				pt0 = m;
				return "";
			}
			if(index + m.length == parts[1].length)
			{
				pt2 = m;
				return "";
			}
			return m;
		});

		if(pt1 != parts[1])
		{
			changeSelection([pt0.length, pt1.length]);
			parts = [parts[0] + pt0, pt1, pt2 + parts[2]];
		}
	}

	if(options.type && ((!parts[1].length && !options.allowEmpty) || (parts[1].length && options.expand)))
	{
		if(options.type == "word" || options.type == "line")
		{
			var p0, p2;
			if(options.type == "word")
			{
				p0 = (parts[0].match(/[-_a-z0-9áäéëěíóöôúůüýčďňŕřšťžĺľ]+$/i) || [""])[0];
				p2 = p0.length ? (parts[2].match(/^[-_a-z0-9áäéëěíóöôúůüýčďňŕřšťžĺľ]+/i) || [""])[0] : "";
			}
			else
			{
				p0 = parts[0].substr(("\n" + parts[0]).lastIndexOf("\n"));
				p2 = parts[2].substr(0, (parts[2] + "\n").indexOf("\n"));
			}
			if(p0 || p2)
			{
				var p1 = parts[1];
				changeSelection([-p0.length, p0.length + p1.length + p2.length]);
				parts = [parts[0].substr(0, parts[0].length - p0.length), p0 + p1 + p2, parts[2].substr(p2.length)];
			}
		}
		else if(options.type = "url")
		{
			var text = textarea.value.replace(/\r\n?/g, "\n");
			var pos1 = parts[0].length, pos2 = pos1 + parts[1].length, uri = "";
			text.replace(/(?:\r?\n|^)•\s+\[url=([^\]]+)\].*?\[\/url\]|\[url=([^\]]+)\].*?\[\/url\]|\[img(?:left|right)?\](.*?)\[\/img\]|(https?\:\/\/(?:["‚„“‘\)\.…,:;]*[^\s"‚„“‘\)\.…,:;]+)+)|(www\.(?:["‚„“‘\)\.…,:;]*[^\s"‚„“‘\)\.…,:;]+)+)/gi, function(m, m1, m2, m3, m4, m5, index)
			{
				if(uri || index > pos1 || index + m.length < pos2) return m;
				changeSelection([-pos1 + index, m.length]);
				uri = m1 || m2 || m3 || m4 || ("http://" + m5);
				var cursor = [pos1 - index, pos2 - pos1];
				parts = [text.substr(0, index), text.substr(index, m.length), text.substr(index + m.length), uri, cursor];
				return m;
			});
		}
	}

	return (options.context ? parts : (parts[3] || parts[1]));
}


function changeSelection(cursor) {
	insertText(null, cursor);
}



if(!"".trim) String.prototype.trim = function(){
	return this.replace(/^\s+|\s+$/g, "");
};


/* xxx bb tagy  */












