var postdishttp=false;
var sending=false;
var btnsendtext="";
function _utf8_encode(t){t = t.replace(/\r\n/g,"\n");var utftext = "";for (var n = 0; n < t.length; n++){var c = t.charCodeAt(n);if (c < 128) {utftext += String.fromCharCode(c);}else if((c > 127) && (c < 2048)) {utftext += String.fromCharCode((c >> 6) | 192);utftext += String.fromCharCode((c & 63) | 128);}else {utftext += String.fromCharCode((c >> 12) | 224);utftext += String.fromCharCode(((c >> 6) & 63) | 128);utftext += String.fromCharCode((c & 63) | 128);}}return utftext;}
function encode(t){return escape(t).replace(/\+/g,"%2B");}
function clearForm(){var f=document.forms["newmail"];f["emailfrom"].value="@";f["subject"].value="";f["emailtext"].value="";}
function sendMail(){
    if(!postdishttp)postdishttp=gethttp();
	if(sending)return true;
    var f=document.forms["newmail"];
	var emailfrom=f["emailfrom"];var subject=f["subject"];var emailtext=f["emailtext"];
	emailfrom.style.background=emailtext.style.background="White";
    var params="emailfrom="+encode(emailfrom.value)+"&subject="+encode(subject.value)+"&emailtext="+encode(emailtext.value);
    postdishttp.open("POST","email.php", true);
    postdishttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    postdishttp.setRequestHeader("Content-length", params.length);
    postdishttp.setRequestHeader("Connection", "close");
    postdishttp.onreadystatechange = function(){
	if(postdishttp.readyState == 4){
	 sendOff();sending=false;
	 if(postdishttp.status == 200){clearForm();alert("Dotaz byl úspěšně odeslán.")}
	 else{
	 alert("Nastala chyba, prosím zkontrolujte údaje a zkuste formulář odeslat znovu.");
	 var errel=document.forms["newmail"][postdishttp.statusText];errel.style.background="Red";errel.focus();
	 }	 
	}}
	sending=true;sendOn();
    postdishttp.send(params);
	return true;
}
function sendOn(){var d=document.forms["newmail"]["send"];d.style.background="url('images/wait.gif') center no-repeat white";btnsendtext=d.value;d.value="";}
function sendOff(){var d=document.forms["newmail"]["send"];d.style.background="#d0d0d0";d.value=btnsendtext;}
