﻿
function contact()
{
	if(!document.cform.mail.value){
		document.cform.mail.focus();
		document.getElementById("mailerr").innerHTML="задължителен";
		return false;
	}
	else{
		if(document.cform.mail.value.search(/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ig)==-1){
			document.getElementById("mailerr").innerHTML="невеналиден";
			return false;
		}
		else document.getElementById("mailerr").innerHTML="";
	}
	
	if(!document.cform.message.value){
		document.cform.message.focus();
		document.getElementById("messageerr").innerHTML="Напиши нещо :)";
		return false;
	}
	else document.getElementById("messageerr").innerHTML="";
	
	if(!document.cform.antispam.value){
		document.cform.antispam.focus();
		document.getElementById("antispamerr").innerHTML="Бъди човечен, попълни :)";
		return false;
	}
	else document.getElementById("antispamerr").innerHTML="";
	
	var xmlhttp;
	if(window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();
	if(window.ActiveXObject) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	if(xmlhttp){
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4){
				if (xmlhttp.status==200){
					if(xmlhttp.responseText=="1"){
						clearCaution();
						$("#messageSent").show("slow");
						window.setTimeout('$("#messageSent").hide("slow");',5000);
						document.cform.reset();
						document.getElementById("antispamImg").src="hristof/antispam/index/"+Math.floor(Math.random()*99000)+"/"+Math.floor(Math.random()*99000)
						document.cform.name.focus();
					}
					if(xmlhttp.responseText=="2"){
						showCaution("Грешен антиспам код, опитайте пак.");
					}
				}
				else{
					showCaution("Съжалявам, съобщението не може да бъде изпратено. Може да пишете на е-mail-a ми.");			
				}
			}
		}					
	xmlhttp.open("POST","hristof/about",true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send("name="+encodeURIComponent(document.cform.name.value)+"&mail="+encodeURIComponent(document.cform.mail.value)+"&message="+encodeURIComponent(document.cform.message.value)+"&antispam="+encodeURIComponent(document.cform.antispam.value));
	}
	return false;
}

function showCaution(message)
{
	document.getElementById('caution').innerHTML=message;
	document.getElementById('caution').style.display="block";
}

function clearCaution(){document.getElementById('caution').style.display="none";}