﻿// Ajax Engine
if ( typeof XMLHttpRequest != "undefined" )
	{
	var Ajax	=	new XMLHttpRequest();	
	}
else if ( window.ActiveXObject )
	{
		var aVersions = ["MSXML2.XMLHTTP.5.0","MSXML.XMLHTTP.4.0","MSXML.XMLHTTP.3.0","MSXML.XMLHTTP","Microsoft.XMLHTTP"];
		for ( var i = 0 ; i < aVersions.length; i++ )
			{
			try {
				var Ajax = new ActiveXObject(aVersions[i])	;
				} catch (oError) { }
			}
	}
if ( !Ajax )
	{
	alert("The Ajax Cannot install. Please Set The Ajax Settings. Powered By Mehrdad Design");
	} 

function randnumber(){
randstr = parseInt(Math.random()*(9999999999999))
return randstr
}

var $_L = function(div)
{
document.getElementById(div).innerHTML	=	"لطفا صبر کنید ...";
}

function getcontent(div,url){
$_L(div);
Ajax.open("GET",url+"&rand="+randnumber(),true);
Ajax.onreadystatechange = function()
	{
	if ( Ajax.readyState == 4 )
		{
			if ( Ajax.status == 200 )
				{
					document.getElementById(div).innerHTML = Ajax.responseText ;
				}
		}
	}
	Ajax.send(null);
}

/* AutoMatic - Don't Change */
function getformcontent(oForm,randnumber)
{
var aParams = new Array();
for (var i = 0 ; i < oForm.elements.length; i++ )
	{
		var sParam = encodeURIComponent(oForm.elements[i].name);
		sParam += "=" ;
		sParam += encodeURIComponent(oForm.elements[i].value);
		aParams.push(sParam);
	}
	return aParams.join("&");
}
/* AutoMatic - Don't Change */

function sendcontent(oForm,div)
{
//var oForm = document.forms[0] ;
var sBody = getformcontent(oForm,randnumber());
$_L(div);
Ajax.open("POST",oForm.action+"&randnumber="+randnumber(),true);
Ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
Ajax.onreadystatechange = function()
	{
		if ( Ajax.readyState == 4 )
			{
			 if ( Ajax.status == 200 )
			 	{
				document.getElementById(div).innerHTML = Ajax.responseText ;
				}
			else
				{
				document.getElementById(div).innerHTML = "<font color='#FF0000'>صفحه اي كه در اكشن فرم وارد شده موجود نمي باشد.</font>" ;
				}
			}
	}
	Ajax.send(sBody);
}

function openurl(div,url){
$_L(div);
Ajax.open("GET",url+"?rand="+randnumber(),true);
Ajax.onreadystatechange = function()
	{
	if ( Ajax.readyState == 4 )
		{
			if ( Ajax.status == 200 )
				{
				document.getElementById(div).innerHTML = Ajax.responseText ;
				}
			else
				{
				document.getElementById(div).innerHTML = "<font color='#FF0000'>آدرس داده شده موجود نمي باشد.</font>" ;
				}
				
		}
	}
	Ajax.send(null);
}

function delete_item(div,url,id)
{
$_L("delete_"+div);
Ajax.open("GET",url+"?id="+id+"&rand="+randnumber(),true);
Ajax.onreadystatechange = function()
	{
	if ( Ajax.readyState == 4 )
		{
			if ( Ajax.status == 200 )
				{
				document.getElementById(div).style.display ="none" ;
				}
			else
				{
				document.getElementById("delete_"+div).innerHTML = "خطا !" ;
				document.getElementById(div).className = "mtitleover" ;		
				}
				
		}
	}
	Ajax.send(null);
}

function edit_item(id,url,describe,title)
{
document.getElementById("title_mtitle_"+id).innerHTML	=	"<form name=\"form\" action=\"links.edit.submit.php?\" onsubmit=\"sendcontent(form,'title_mtitle_"+id+"');\">\
<input type='hidden' name='id' value='"+id+"' /><input type='text' name='title' value='"+title+"' class='input' /><br /><input type='text' name='describe' value='"+describe+"' class='input' /><br /><input type='text' name='url' value='"+url+"' class='input' style='direction: ltr ; text-align: left' /><br /><input type='submit' value='ويرايش' class='button' />&nbsp;<input type='reset' onclick='recover_link("+id+");' value='انصراف'class='button' /></form>";
// <form name="form" action="links.edit.submit.php?" onsubmit="sendcontent(form,\'title_mtitle_'+id+'\');">safd
}

function recover_link(id)
{
var url = document.getElementById("url").value ;
var title = document.getElementById("title").value ;
var describe = document.getElementById("describe").value ;
document.getElementById("title_mtitle_"+id).innerHTML	=	"<a href="+url+" target='_blank' >"+title+"</a>";
}

function accept_link(id,group)
{
$_L("accept_"+id);
Ajax.open("GET","links.accept.submit.php?id="+id+"&group="+group+"&rand="+randnumber(),true);
Ajax.onreadystatechange = function()
	{
	if ( Ajax.readyState == 4 )
		{
			if ( Ajax.status == 200 )
				{
				document.getElementById("mtitle_"+id).style.display ="none" ;
				}
			else
				{
				document.getElementById("accept_"+id).innerHTML = "خطا !" ;
				}
				
		}
	}
	Ajax.send(null);
}

function blacklist(id)
{
$_L("blacklist_"+id);
Ajax.open("GET","links.blacklist.submit.php?id="+id+"&rand="+randnumber(),true);
Ajax.onreadystatechange = function()
	{
	if ( Ajax.readyState == 4 )
		{
			if ( Ajax.status == 200 )
				{
				document.getElementById("mtitle_"+id).style.display ="none" ;
				}
			else
				{
				document.getElementById("blacklist_"+id).innerHTML = "خطا !" ;
				}
				
		}
	}
	Ajax.send(null);
}