﻿var myInterval,xmlHttp,xmlHttp1,xmlHttp2,xmlHttp3,xmlHttp4,xmlHttp5,HitHttp,fpHttp;

function LoadRightSideMenu()
{
	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp1==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="ajax.php";
	var parameters ="type=loadrightside";
	xmlHttp1.onreadystatechange=RightSideStateChanged;
	xmlHttp1.open("POST",url,true);
	xmlHttp1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp1.setRequestHeader("Content-length", parameters.length);
	xmlHttp1.setRequestHeader("Connection", "close");
	xmlHttp1.send(parameters);
}

function LoadLeftSideMenu()
{
	xmlHttp2=GetXmlHttpObject();
	if (xmlHttp2==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="ajax.php";
	var parameters ="type=loadleftside";
	xmlHttp2.onreadystatechange=LeftSideStateChanged;
	xmlHttp2.open("POST",url,true);
	xmlHttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp2.setRequestHeader("Content-length", parameters.length);
	xmlHttp2.setRequestHeader("Connection", "close");
	xmlHttp2.send(parameters);
}

function LoadTopLinkBar()
{
	xmlHttp3=GetXmlHttpObject();
	if (xmlHttp3==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="ajax.php";
	var parameters ="type=toplinkbar";
	xmlHttp3.onreadystatechange=TopLinkbarStateChanged;
	xmlHttp3.open("POST",url,true);
	xmlHttp3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp3.setRequestHeader("Content-length", parameters.length);
	xmlHttp3.setRequestHeader("Connection", "close");
	xmlHttp3.send(parameters);
}

function LoadTopAds()
{
	xmlHttp4=GetXmlHttpObject();
	if (xmlHttp4==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="ajax.php";
	var parameters ="type=loadtopads";
	xmlHttp4.onreadystatechange=TopAdsStateChanged;
	xmlHttp4.open("POST",url,true);
	xmlHttp4.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp4.setRequestHeader("Content-length", parameters.length);
	xmlHttp4.setRequestHeader("Connection", "close");
	xmlHttp4.send(parameters);
}

function LoadBottomAds()
{
	xmlHttp5=GetXmlHttpObject();
	if (xmlHttp5==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="ajax.php";
	var parameters ="type=loadbottomads";
	xmlHttp5.onreadystatechange=BottomAdsStateChanged;
	xmlHttp5.open("POST",url,true);
	xmlHttp5.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp5.setRequestHeader("Content-length", parameters.length);
	xmlHttp5.setRequestHeader("Connection", "close");
	xmlHttp5.send(parameters);
}

function MenuClicked(mid, subm)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	if (typeof subm == "undefined") {
		subm = '1';
	}
	if (subm != '3' && document.getElementById('linkid' + mid).innerHTML != '')
	{
		RemoveAll('linkid' + mid);
		return;
	}
	ShowLoading();
	var url="ajax.php";
	var parameters ="type=menuclicked&mid=" + mid + "&sub=" + subm;
	xmlHttp.onreadystatechange=MenuClickedStateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function LinkClicked(link)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	ShowLoading();
	var url="ajax.php";
	var parameters ="type=linkclicked&link=" + link;
	xmlHttp.onreadystatechange=StateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function LoadNews(pg)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	window.scrollTo(0,0);
	document.getElementById('main-work').innerHTML = '<center><div align="center"><p>در حال بارگزاری...</p><img src="images/loading1.gif"></div></center>';
	var url="ajax.php";
	var parameters ="type=loadnews&pg=" + pg;
	xmlHttp.onreadystatechange=StateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function LoadDownloadPage(pg)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	window.scrollTo(0,0);
	document.getElementById('main-work').innerHTML = '<center><div align="center"><p>در حال بارگزاری...</p><img src="images/loading1.gif"></div></center>';
	var url="ajax.php";
	var parameters ="type=loaddownload&pg=" + pg;
	xmlHttp.onreadystatechange=StateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function LoadsxePage(pg)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	window.scrollTo(0,0);
	document.getElementById('main-work').innerHTML = '<center><div align="center"><p>در حال بارگزاری...</p><img src="images/loading1.gif"></div></center>';
	var url="ajax.php";
	var parameters ="type=loadsxe&pg=" + pg;
	xmlHttp.onreadystatechange=StateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function DoSearch(id)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	window.scrollTo(0,0);
	document.getElementById('main-work').innerHTML = '<center><div align="center"><p>در حال بارگزاری...</p><img src="images/loading1.gif"></div></center>';
	var url="ajax.php";
	var parameters ="type=dosearch&tid=" + id;
	xmlHttp.onreadystatechange=StateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function LoadContinueDownload(did)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	ShowLoading();
	var url="ajax.php";
	var parameters ="type=loadcontinuedownload&did=" + did;
	xmlHttp.onreadystatechange=ContinueDownloadStateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function LoadContinueSxe(did)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	ShowLoading();
	var url="ajax.php";
	var parameters ="type=loadcontinuesxe&did=" + did;
	xmlHttp.onreadystatechange=ContinueDownloadStateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function LoadBuyServer(pg)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	window.scrollTo(0,0);
	document.getElementById('main-work').innerHTML = '<center><div align="center"><p>در حال بارگزاری...</p><img src="images/loading1.gif"></div></center>';
	var url="ajax.php";
	var parameters ="type=loadbuyserver&pg=" + pg;
	xmlHttp.onreadystatechange=StateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function Order(sid, pid)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	document.getElementById('order'+sid).innerHTML = '<center><div align="center"><p>در حال بارگزاری...</p><img src="images/loading1.gif"></div></center>';
	var url="ajax.php";
	var parameters ="type=showorder&sid=" + sid + "&pid=" + pid;
	xmlHttp.onreadystatechange=OrderStateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function AddOrder(sid, pid)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="ajax.php";
	var p ="type=saveorder&sid=" + sid + "&pid=" + pid;
	p += "&fullname=" + document.getElementById('fullname').value;
	p += "&email=" + document.getElementById('email').value;
	p += "&tel=" + document.getElementById('tel').value;
	document.getElementById('order'+sid).innerHTML = '<center><div align="center"><p>در حال بارگزاری...</p><img src="images/loading1.gif"></div></center>';
	xmlHttp.onreadystatechange=OrderStateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", p.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(p);
}

function SetHit()
{
	HitHttp=GetXmlHttpObject();
	if (HitHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="ajax.php";
	var parameters ="type=gethits";
	HitHttp.onreadystatechange=HitStateChanged;
	HitHttp.open("POST",url,true);
	HitHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	HitHttp.setRequestHeader("Content-length", parameters.length);
	HitHttp.setRequestHeader("Connection", "close");
	HitHttp.send(parameters);
}

function MainPageLoad(pid, nid)
{
	fpHttp=GetXmlHttpObject();
	if (fpHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	ShowLoading();
	var url="ajax.php";
	var parameters ="type=loadmainpage&pageid=" + pid + "&id=" + nid;
	fpHttp.onreadystatechange=MainPageStateChanged;
	fpHttp.open("POST",url,true);
	fpHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	fpHttp.setRequestHeader("Content-length", parameters.length);
	fpHttp.setRequestHeader("Connection", "close");
	fpHttp.send(parameters);
}
function RegisterTeam()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
window.scrollTo(0,300);
	var url="ajax.php";
	var p ="type=registerteam";
	p += "&teamname1=" + document.getElementById('teamname1').value;
	p += "&teamname2=" + document.getElementById('teamname2').value;
	p += "&clantag=" + document.getElementById('clantag').value;
	p += "&email=" + document.getElementById('email').value;
	p += "&fishnum=" + document.getElementById('fishnum').value;
	p += "&leadername=" + document.getElementById('leadername').value;
	p += "&leaderaddress=" + document.getElementById('leaderaddress').value;
	p += "&player1=" + document.getElementById('player1').value;
	p += "&player2=" + document.getElementById('player2').value;
	p += "&player3=" + document.getElementById('player3').value;
	p += "&player4=" + document.getElementById('player4').value;
	p += "&player5=" + document.getElementById('player5').value;
	p += "&player6=" + document.getElementById('player6').value;
	p += "&player7=" + document.getElementById('player7').value;
	document.getElementById('tourregcont').style.display = "none";
	document.getElementById('tourregloader').style.display = "block";
	xmlHttp.onreadystatechange=RegisterTeamStateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", p.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(p);
}






function StateChanged() 
{ 
	if (xmlHttp.readyState==4) {
		if (xmlHttp.status == 200) {
			SetHit();
			var sp = xmlHttp.responseText.split('©©©');
			document.getElementById("main-work").innerHTML=sp[0];
			if (typeof(sp[1]) != "undefined") { document.title = sp[1]; }
			HideLoading();
		} else { alert('There was a problem with the request.'); }
	}
}

function MainPageStateChanged() 
{
	if (fpHttp.readyState==4) {
		if (fpHttp.status == 200) {
			SetHit();
			var sp = fpHttp.responseText.split('©©©');
			document.getElementById("main-work").innerHTML=sp[0];
			if (typeof(sp[1]) != "undefined") { document.title = sp[1]; }
			HideLoading();
		} else { alert('There was a problem with the request.'); }
	}
}

function RightSideStateChanged()
{ 
	if (xmlHttp1.readyState==4) {
		if (xmlHttp1.status == 200) {
			SetHit();
			document.getElementById("right-side-bar").innerHTML=xmlHttp1.responseText;
		} else { alert('There was a problem with the request.'); }
	}
}

function LeftSideStateChanged()
{ 
	if (xmlHttp2.readyState==4) {
		if (xmlHttp2.status == 200) {
			SetHit();
			document.getElementById("left-side-bar").innerHTML=xmlHttp2.responseText;
		} else { alert('There was a problem with the request.'); }
	}
}

function TopLinkbarStateChanged()
{ 
	if (xmlHttp3.readyState==4) {
		if (xmlHttp3.status == 200) {
			SetHit();
			document.getElementById("top-linkbar").innerHTML=xmlHttp3.responseText;
		} else { alert('There was a problem with the request.'); }
	}
}

function TopAdsStateChanged()
{ 
	if (xmlHttp4.readyState==4) {
		if (xmlHttp4.status == 200) {
			SetHit();
			document.getElementById("top-ads").innerHTML=xmlHttp4.responseText;
		} else { alert('There was a problem with the request.'); }
	}
}

function BottomAdsStateChanged()
{ 
	if (xmlHttp5.readyState==4) {
		if (xmlHttp5.status == 200) {
			SetHit();
			document.getElementById("bottom-ads").innerHTML=xmlHttp5.responseText;
		} else { alert('There was a problem with the request.'); }
	}
}

function MenuClickedStateChanged()
{ 
	if (xmlHttp.readyState==4) {
		if (xmlHttp.status == 200) {
			SetHit();
			var sp = xmlHttp.responseText.split('©©©');
			document.getElementById(sp[0]).innerHTML=sp[1];
			if (typeof(sp[2]) != "undefined") {
				document.title = sp[2];
				HideLoading();
				return;
			}
			HideLoading2();
		} else { alert('There was a problem with the request.'); }
	}
}

function ContinueDownloadStateChanged() 
{ 
	if (xmlHttp.readyState==4) {
		if (xmlHttp.status == 200) {
			SetHit();
			var sp = xmlHttp.responseText.split('©©©');
			document.getElementById("dl-cont" + sp[0]).innerHTML=sp[1];
			document.getElementById("dl-down-link" + sp[0]).innerHTML=sp[2];
			HideLoading();
		} else { alert('There was a problem with the request.'); }
	}
}

function OrderStateChanged() 
{ 
	if (xmlHttp.readyState==4) {
		if (xmlHttp.status == 200) {
			SetHit();
			var sp = xmlHttp.responseText.split('©©©');
			document.getElementById("order" + sp[0]).innerHTML=sp[1];
		} else { alert('There was a problem with the request.'); }
	}
}

function RegisterTeamStateChanged() 
{ 
	if (xmlHttp.readyState==4) {
		if (xmlHttp.status == 200) {
			SetHit();
			var sp = xmlHttp.responseText.split('©©©');
			if (sp[0] == '1')
			{
				document.getElementById("register_team").innerHTML=sp[1];
			} else {
				document.getElementById("regstatus").innerHTML=sp[1];
				document.getElementById('regstatus').style.display = "block";
				document.getElementById('tourregcont').style.display = "block";
				document.getElementById('tourregloader').style.display = "none";
			}
		} else { alert('There was a problem with the request.'); }
	}
}

function HitStateChanged() 
{ 
	if (HitHttp.readyState==4) {
		if (HitHttp.status == 200) {
			document.getElementById("hits").innerHTML=HitHttp.responseText;
			//HideLoading();
		} else { alert('There was a problem with the request.'); }
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function ShowLoading()
{
	myInterval = setInterval("ShowLoadingDiv()",1)
}

function ShowLoadingDiv()
{
	var div=document.getElementById('main-loading');
	var el=document.getElementById('loading');
	div.style.visibility = 'visible';
	div.style.display = 'block';
	div.style.top = FromTop() + "px";
	el.style.visibility = 'visible';
	el.style.display = 'block';
	el.style.top = FromTop() + 340 + "px";
	el.style.left = ScreenWidth() / 2 - 55 + "px";
}

function HideLoading()
{
	clearInterval(myInterval);
	var div=document.getElementById('main-loading');
	var el=document.getElementById('loading');
	div.style.visibility = 'hidden';
	div.style.display = 'none';
	el.style.visibility = 'hidden';
	el.style.display = 'none';
	window.scrollTo(0,0);
}

function HideLoading2()
{
	clearInterval(myInterval);
	var div=document.getElementById('main-loading');
	var el=document.getElementById('loading');
	div.style.visibility = 'hidden';
	div.style.display = 'none';
	el.style.visibility = 'hidden';
	el.style.display = 'none';
}

function FromTop()
{
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
	    if (window.pageYOffset)
	        ScrollTop = window.pageYOffset;
	    else
	        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	return ScrollTop;
}

function ScreenWidth() {
	var result = 2000;

	if (window.innerWidth) {
		// all except Explorer
		result = parseInt(window.innerWidth);
	} else if (document.documentElement && document.documentElement.clientWidth) {
		// Explorer 6 Strict Mode
		result = parseInt(document.documentElement.clientWidth);
	} else if (document.body) {
		// other Explorers
		result = parseInt(document.body.clientWidth);
	}
	if (isNaN(result)) {
		result = 2000;
	}
	return result;
}

function RemoveAll(id)
{
	var element = document.getElementById(id);
	while (element.firstChild) {
		element.removeChild(element.firstChild);
	}
}