function pluskniha(num, max) {
	num = parseInt(num);
	var item = "item_" + num;
	var plus = "plus_" + (num - 1);
	var minus = "minus_" + (num - 1);
	
	var new_row = document.createElement("div");
	new_row.id = item;
	
	// SELECT boxy
	var boxy = new Array("kniha", "pocet");
	var selects = new Array();
	
	for (var i = 0; i < boxy.length; i++) {
		selects[i] = document.createElement("select");
		selects[i].name = boxy[i] + "[]";
		selects[i].id = boxy[i] + "_" + num;
		
		var vzor = boxy[i] + "_0";
		for (var j = 0;j < document.getElementById(vzor).options.length ; j++) 
		{
		    var option = document.createElement("option");
		    option.value = document.getElementById(vzor).options[j].value;
		    var innertext = document.getElementById(vzor).options[j].text;
		    option.appendChild(document.createTextNode(innertext));
		    selects[i].appendChild(option);
		}
		
		new_row.appendChild(selects[i]);
	}
	var ks = document.createTextNode(" ks ");
	new_row.appendChild(ks);
	
	var kotva = document.createElement("a");
	kotva.id = "minus_" + num;
	kotva.href = "#";
	kotva.title = "Odebrat titul";
	kotva.innerHTML = "[odebrat]";
	kotva.onclick = function () { minuskniha(num); return false};
	
	new_row.appendChild(kotva);
	
	if ( num < (max - 1)) {
		var kotva = document.createElement("a");
		kotva.id = "plus_" + num;
		kotva.href = "#";
		kotva.title = "Další titul";
		kotva.innerHTML = "[další]";
		poc = parseInt(num);
		poc++;
		kotva.onclick = function () { pluskniha(poc, max); return false};
		
		new_row.appendChild(kotva);
	}
	
	document.getElementById('knihy').appendChild(new_row);
	
	document.getElementById(item).style.display = "block";
	document.getElementById(plus).style.display = "none";
	if ( num > 1 )document.getElementById(minus).style.display = "none";
	
}
function minuskniha(num, max)
{
	var item = "item_" + num;
	var plus = "plus_" + (num - 1);
	var minus = "minus_" + (num - 1);
	string = "";
	document.getElementById(item).style.display = "none";
	for (var i = 0; i < document.getElementById('knihy').childNodes.length; i++) {
		var element = document.getElementById('knihy').childNodes[i];
		if ((element.id == item) && (item != "item_0")) {
			document.getElementById('knihy').removeChild(element);
		}
	}
	
	document.getElementById(plus).style.display = "inline";
	if ( num > 1 )document.getElementById(minus).style.display = "inline";
}
function plus(parent, num, max) {
	var kotva = document.createElement("a");
	kotva.id = "plus_"+num;
	kotva.href = "#";
	kotva.title = "Další titul ";
	kotva.innerHTML = "[další]";
	poc = parseInt(num);
	poc++;
	kotva.onclick = function () { pluskniha(poc, max); return false};
	
	document.getElementById(parent).appendChild(kotva);
}
function kontrolazpravy(f) {
	if (f["from"].value == "") {
		f["from"].focus();
		alert ("Zadejte e-mail.");
		return false;
	}
	if (!is_email(f["from"].value)) {
		f["from"].focus();
		alert ("Špatně zadaný e-mail.");
		return false;
	}
	if (f["body"].value == "") {
		f["body"].focus();
		alert ("Napište text zprávy.");
		return false;
	}
		
}
function kontrolaobjednavky(f) {
	var nutne = new Array("jmeno", "ulice", "mesto", "psc", "phone");
	for (var i = 0; i < nutne.length; i++) {
		if (f[nutne[i]].value == "") {
			f[nutne[i]].focus();
			alert ("Zadejte údaj.");
			return false;
		}
	}
	if (!is_email(f["mail"].value)) {
		f["mail"].focus();
		alert ("Špatně zadaný e-mail.");
		return false;
	}
}
function objednavkaZpet(e) {
	e['odeslano'].disabled = true;
	e.submit();
	return false;
}
function odeslatObjednavku(e) {
	return true;
}
function is_email(str) {

	var at = "@";
	var dot = ".";
	var space = " ";
	
	var len = str.length;
	var at_pos = str.indexOf(at);
	var dot_pos = str.indexOf(dot);
	var space_pos = str.indexOf(space);
	
	if (at_pos == -1 || at_pos == 0 || at_pos == (len - 1)){
		return false;
	}

	if (dot_pos == -1 || dot_pos == 0 || dot_pos == (len - 1)){
		return false;
	}

	if (str.indexOf(at,(at_pos + 1)) != -1){
		return false;
	}

	if (str.substring(at_pos - 1, at_pos) == dot || str.substring(at_pos + 1, at_pos + 2) == dot){
		return false;
	}

	if (str.indexOf(dot,(at_pos + 2)) == -1){
		return false;
	}
	
	if (space_pos != -1){
		return false;
	}

	return true;
}