﻿// stores the reference to the XMLHttpRequest object

var TWSHxmlHttp = null;
var TWSHhistory = {"-10": "", "-9": "", "-8": "", "-7": "", "-6": "", "-5": "", "-4": "", "-3": "", "-2": "", "-1": "", "0":"index2.php?"+TWSHpagequery, "1":"", "2":"", "3":"", "4":"", "5":"", "6":"", "7":"", "8":"", "9":"", "10":""};
// retrieves the XMLHttpRequest object
function TWSHcreateXmlHttpRequestObject()
{
	// if running Internet Explorer
	if(window.ActiveXObject)
	{
		try
		{
			TWSHxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			TWSHxmlHttp = false;
		}
	}
	// if running Mozilla or other browsers
	else
	{
		try
		{
			TWSHxmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			TWSHxmlHttp = false;
		}
	}
	return TWSHxmlHttp;
}
var TWSHnavigatebutton , TWSHbackwardbutton , TWSHforwardbutton = false;
// make asynchronous HTTP request using the XMLHttpRequest object
function TWSHprocess(inc)
{
	document.getElementById("ajaxcontent").innerHTML = "<img src=\"templates/"+TWSHtemplate+"/images/loading.gif\" style=\"border:0px\"/><br/>در حال بارگذاری لطفاً صبر کنید...";
	location.href = '#TOP';
	TWSHcreateXmlHttpRequestObject();
	if(TWSHxmlHttp != null)
	{
		// alert(inc + '&rand=' + Math.random());
		var rand = Math.random()*10;
		TWSHxmlHttp.open("GET", inc + '&rand=' + rand, true);
		if(!TWSHnavigatebutton){
			if(TWSHhistory[-9] != "")TWSHhistory[-10] = TWSHhistory[-9];
			if(TWSHhistory[-8] != "")TWSHhistory[-9] = TWSHhistory[-8];
			if(TWSHhistory[-7] != "")TWSHhistory[-8] = TWSHhistory[-7];
			if(TWSHhistory[-6] != "")TWSHhistory[-7] = TWSHhistory[-6];
			if(TWSHhistory[-5] != "")TWSHhistory[-6] = TWSHhistory[-5];
			if(TWSHhistory[-4] != "")TWSHhistory[-5] = TWSHhistory[-4];
			if(TWSHhistory[-3] != "")TWSHhistory[-4] = TWSHhistory[-3];
			if(TWSHhistory[-2] != "")TWSHhistory[-3] = TWSHhistory[-2];
			if(TWSHhistory[-1] != "")TWSHhistory[-2] = TWSHhistory[-1];
			TWSHhistory[-1] = TWSHhistory[0];
			TWSHhistory[0] = inc + '&rand=' + rand;
				TWSHhistory[1] = TWSHhistory[2] = TWSHhistory[3] = TWSHhistory[4] = TWSHhistory[5] = TWSHhistory[6] = TWSHhistory[7] = TWSHhistory[8] = TWSHhistory[9] = TWSHhistory[10] = "";
		}
		else{
			if(TWSHforwardbutton){
				//alert('gh');
				TWSHhistory[-10] = TWSHhistory[-9];
				TWSHhistory[-9] = TWSHhistory[-8];
				TWSHhistory[-8] = TWSHhistory[-7];
				TWSHhistory[-7] = TWSHhistory[-6];
				TWSHhistory[-6] = TWSHhistory[-5];
				TWSHhistory[-5] = TWSHhistory[-4];
				TWSHhistory[-4] = TWSHhistory[-3];
				TWSHhistory[-3] = TWSHhistory[-2];
				TWSHhistory[-2] = TWSHhistory[-1];
				TWSHhistory[-1] = TWSHhistory[0];
				TWSHhistory[0] = inc + '&rand=' + rand;
				TWSHhistory[1] = TWSHhistory[2];
				TWSHhistory[2] = TWSHhistory[3];
				TWSHhistory[3] = TWSHhistory[4];
				TWSHhistory[4] = TWSHhistory[5];
				TWSHhistory[5] = TWSHhistory[6];
				TWSHhistory[6] = TWSHhistory[7];
				TWSHhistory[7] = TWSHhistory[8];
				TWSHhistory[8] = TWSHhistory[9];
				TWSHhistory[9] = TWSHhistory[10];
			}
			if(TWSHbackwardbutton){
				//alert('gh');
				TWSHhistory[10] = TWSHhistory[9];
				TWSHhistory[9] = TWSHhistory[8];
				TWSHhistory[8] = TWSHhistory[7];
				TWSHhistory[7] = TWSHhistory[6];
				TWSHhistory[6] = TWSHhistory[5];
				TWSHhistory[5] = TWSHhistory[4];
				TWSHhistory[4] = TWSHhistory[3];
				TWSHhistory[3] = TWSHhistory[2];
				TWSHhistory[2] = TWSHhistory[1];
				TWSHhistory[1] = TWSHhistory[0];
				TWSHhistory[0] = inc + '&rand=' + rand;
				TWSHhistory[-1] = TWSHhistory[-2];
				TWSHhistory[-2] = TWSHhistory[-3];
				TWSHhistory[-3] = TWSHhistory[-4];
				TWSHhistory[-4] = TWSHhistory[-5];
				TWSHhistory[-5] = TWSHhistory[-6];
				TWSHhistory[-6] = TWSHhistory[-7];
				TWSHhistory[-7] = TWSHhistory[-8];
				TWSHhistory[-8] = TWSHhistory[-9];
				TWSHhistory[-9] = TWSHhistory[-10];

			}
		}
		//alert(TWSHhistory[-1]]);
		// define the method to handle server responses
		TWSHxmlHttp.onreadystatechange = TWSHhandleServerResponse;
		// make the server request
		TWSHxmlHttp.send(null);
		TWSHnavigatebutton = false;
		TWSHbackwardbutton = false;
		TWSHforwardbutton = false;
	}
	else
	window.alert('مرورگر شما از تکنولوژي ای ژاکس پشتیباني نمي کند');
	return false;
}
// executed automatically when a message is received from the server
function TWSHhandleServerResponse()
{
	// move forward only if the transaction has completed
	if (TWSHxmlHttp.readyState == 4)
	{
		// status of 200 indicates the transaction completed successfully
		if (TWSHxmlHttp.status == 200)
		{
			// extract the XML retrieved from the server
			//response = "" + TWSHhistory.backurl + "" + TWSHxmlHttp.responseText;
			var navigates = "<p style=\"text-align:center\"><div class=\"icopanel\" style=\"width: 145px; text-align:center;\" >";
			if(TWSHhistory[1] != "")	 navigates += "<img src=\"templates/"+TWSHtemplate+"/images/forward.png\" onclick=\"TWSHnavigatebutton = true; TWSHforwardbutton = true; return TWSHprocess('" + TWSHhistory[1] + "');\" style=\"cursor: pointer;\" title=\"برگه جلویی\" />";
			else navigates += "<img src=\"templates/"+TWSHtemplate+"/images/forwardbw.png\" />";
				navigates += "&nbsp;&nbsp;<img src=\"templates/"+TWSHtemplate+"/images/reload.png\" onclick=\"TWSHnavigatebutton = true; return TWSHprocess('" + TWSHhistory[0] + "');\" style=\"cursor: pointer;\"  title=\"بارگذاری دوباره\" />";
			if(TWSHhistory[-1] != "")	 navigates += "&nbsp;&nbsp;<img src=\"templates/"+TWSHtemplate+"/images/backward.png\" onclick=\"TWSHnavigatebutton = true; TWSHbackwardbutton = true;return TWSHprocess('" + TWSHhistory[-1] + "');\"  style=\"cursor: pointer;\"  title=\"برگه پیشین\" />";
			else navigates += "&nbsp;&nbsp;<img src=\"templates/"+TWSHtemplate+"/images/backwardbw.png\" />";
			navigates += "</div></p><br/>";
			response = navigates + TWSHxmlHttp.responseText;
			// update the client display using the data received from the server
			document.getElementById("ajaxcontent").innerHTML = response;
			// restart sequence
			//setTimeout('process()', 1000);
		}
		// a HTTP status different than 200 signals an error
		else
		{
			alert("There was a problem accessing the server: " + TWSHxmlHttp.status);
		}
	}
}