﻿function check_empty() {
	var name=document.getElementById("name").value;
	var phone=document.getElementById("phone").value;
	var message_post=document.getElementById("user_post").innerHTML;
	var i=0;
	if (name=="" || name=="שמך" || name=="כתוב את שמך") {
		document.getElementById("name").value="כתוב את שמך";
		document.getElementById("name").className = 'inputstyle_wrn';
		i=1;
	}
	if (phone=="" || phone=="מספר טלפון" || phone=="הכנס מספר טלפון") {
		document.getElementById("phone").value="הכנס מספר טלפון";
		document.getElementById("phone").className = 'inputstyle_wrn';
		i=1;
	}
	if (message_post=="" || message_post=="הודעתך" || message_post=="כתוב הודעתך") {
		document.getElementById("user_post").innerHTML="כתוב הודעתך";
		document.getElementById("user_post").className = 'inputstyle_wrn';
		i=1;
	}
	if (i==0) {
		document.getElementById("name").style.display="none";
		document.getElementById("phone").style.display="none";
		document.getElementById("user_post").style.display="none";
		document.getElementById("button").style.display="none";
		contactFunction(i,name,phone,message_post,"");
	}
}
function check_empty2() {
	var name=document.getElementById("name2").value;
	var phone=document.getElementById("phone2").value;
	var message_post=document.getElementById("user_post2").value;
	var i=0;
	if (name=="" || name=="שמך" || name=="כתוב את שמך") {
		document.getElementById("name2").value="כתוב את שמך";
		document.getElementById("name2").className = 'inputstyle_wrn';
		i=1;
	}
	if (phone=="" || phone=="מספר טלפון" || phone=="הכנס מספר טלפון") {
		document.getElementById("phone2").value="הכנס מספר טלפון";
		document.getElementById("phone2").className = 'inputstyle_wrn';
		i=1;
	}
	if (message_post=="" || message_post=="הודעתך" || message_post=="כתוב הודעתך") {
		document.getElementById("user_post2").innerHTML="כתוב הודעתך";
		document.getElementById("user_post2").className = 'inputstyle_wrn';
		i=1;
	}
	if (i==0) {
		document.getElementById("name2").style.display="none";
		document.getElementById("phone2").style.display="none";
		document.getElementById("user_post2").style.display="none";
		document.getElementById("button2").style.display="none";
		contactFunction(i,name,phone,message_post,2);
	}
}
function contactFunction(isempty,name,phone,message_post,a) {
  var xmlHttp;
  try {
    xmlHttp=new XMLHttpRequest();
  }
  catch (e) {
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {
        alert("שגיאה! הדפדפן אינו תומך ב-AJAX!");
        return false;
      }
    }
  }
    
	var post_params="name="+name+"&phone="+phone+"&message_post="+message_post+"&isempty="+isempty;
    var url="ajax_contact.php";
	xmlHttp.open("POST", url, true);

	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", post_params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.onreadystatechange=process;
	xmlHttp.send(post_params);
    
	function process() {
		if(xmlHttp.readyState==4) {
			if(xmlHttp.status==200) {
					document.getElementById("server_update"+a).innerHTML=xmlHttp.responseText;
			}
			else
			document.getElementById("server_update"+a).innerHTML="קיימת שגיאה בשליחת ההודעה <br /> status!=200";
		}
		else if(xmlHttp.readyState==1 || xmlHttp.readyState==2 || xmlHttp.readyState==3)
			document.getElementById("server_update"+a).innerHTML="<h2>שולח, אנא המתן...</h2>";
		else
			document.getElementById("server_update"+a).innerHTML="קיימת שגיאה בשליחת ההודעה <br /> readyState!=4";
	}
}
