﻿function picsFunction(url,page,pic,first_pic,last_pic,type) {
  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;
      }
    }
  }
    if (pic=='a') {
		pic=parseFloat(document.getElementById("last_pic").value)+1;
		if (pic>last_pic)
			pic=first_pic;
	}
	if (pic=='b') {
		pic=parseFloat(document.getElementById("last_pic").value)-1;
		if (pic<first_pic)
			pic=last_pic;
	}
	var post_params="id="+page+"&pic="+pic+"&tour="+document.getElementById("tour").value+"&type="+type;
    var url="ajax/"+url+".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) {
					swich_h("server_update2");
					document.getElementById("server_response2").innerHTML=xmlHttp.responseText;
					document.getElementById("last_pic").value=pic;
					swich_s("server_response2");
			}
			else
			document.getElementById("server_update2").innerHTML="קיימת שגיאה בעדכון הנתונים <br /> status!=200";
		}
		else if(xmlHttp.readyState==1 || xmlHttp.readyState==2 || xmlHttp.readyState==3) {
			swich_s("server_update2");
			swich_h("server_response2");
		}
		else
			document.getElementById("server_update2").innerHTML="קיימת שגיאה בעדכון הנתונים <br /> readyState!=4";
	}
}
