var mxmlhttp;
var vid;
var targ;

window.onload=function(){
	document.onmouseup=stopDrag;
};

function actDrag(e){
	e= e || window.event;
	x1=e.clientX;
	y1=e.clientY;
	targ=e.target?e.target:e.srcElement;
	targ.onmousemove=startDrag;
	document.onmousemove=startDrag;
	coordX=targ.offsetLeft-x1;
	coordY=targ.offsetTop-y1;
}

function startDrag(e){
	e= e || window.event;
	targ.style.left=coordX+e.clientX+'px';
	targ.style.top=coordY+e.clientY+'px';
}
function stopDrag(e){
	if(targ != null){
	targ.onmousemove=null;
	}
	document.onmousemove=null;
}

function createDiv(id, html, width, height, left, top,bg) {
 var newdiv = document.createElement('div');
   newdiv.setAttribute('id', id);
   
   if (width) {
       newdiv.style.width = width;
   }
   
   if (height) {
       newdiv.style.height = height;
   }
   
   if ((left || top) || (left && top)) {
       newdiv.style.position = "absolute";
       
       if (left) {
           newdiv.style.left = left;
       }
       
       if (top) {
           newdiv.style.top = top;
       }
   }
   newdiv.style.zIndex = 20;
   newdiv.style.backgroundImage = bg;
   newdiv.onmousedown=actDrag;
   newdiv.onmouseup=stopDrag;
   newdiv.style.cursor="auto";
   newdiv.position="absolute";
   
   if (html) {
       newdiv.innerHTML = html;
   } else {
       newdiv.innerHTML = "";
   }
   
   document.body.appendChild(newdiv);
   //document.getElementById('container').appendChild(newdiv);
}


function XMLFetch(url,method,variables,callback)
{
mxmlhttp=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  mxmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  mxmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (mxmlhttp!=null)
  {
	mxmlhttp.onreadystatechange=callback;
	mxmlhttp.open(method,url,true);
 	if(method=="POST"){
		mxmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  		mxmlhttp.setRequestHeader("Content-length", variables.length);
  		mxmlhttp.setRequestHeader("Connection", "close");
		mxmlhttp.send(variables);
	}
	else{
		mxmlhttp.send(null);
	}
  	
  }
else
	{
		alert("Your browser is not supported, please use Internet Explorer,Firefox,Opera or Chrome. If you are already using one of them make sure you have the latest version");
	}
}

function lsc2(){
	if (mxmlhttp.readyState==4)
  {// 4 = "loaded"
  if (mxmlhttp.status==200)
    {// 200 = "OK"
			if(mxmlhttp.responseText != "none")
			{
			var x = 250;
			var y = 250;
			x += Math.floor(Math.random()*250);
			y += Math.floor(Math.random()*250);
			createDiv('_' + vid, mxmlhttp.responseText,'250px','350px',x+'px',y+'px','url(PM_bg.png)');
			vid=0;
			}
    }
  else
    {
    alert('A server side error occured');
    }
  }	
	
}
function fetchMail(id){
				var content = "mode=M"  + "&id=" + encodeURIComponent(id);
				XMLFetch("msgpop.asp?c=" + Math.floor(Math.random()*999),"POST",content,lsc2);
				vid = id;
}


function fsc(){
	if (mxmlhttp.readyState==4)
  {// 4 = "loaded"
  if (mxmlhttp.status==200)
    {// 200 = "OK"
			if(mxmlhttp.responseText != "none")
			{
				if(document.getElementById('_' + vid) == null){
				var x = 250;
				var y = 250;
				x += Math.floor(Math.random()*250);
				y += Math.floor(Math.random()*250);
				createDiv('_' + vid, mxmlhttp.responseText,'350px','150px',x+'px',y+'px','url(fq_bg.png)');
				vid=0;
				}
			}
    }
  else
    {
    alert('A server side error occured');
    }
  }	
	
}

function upr(){
	if (mxmlhttp.readyState==4)
  {// 4 = "loaded"
  if (mxmlhttp.status==200)
    {// 200 = "OK"
			var rt = mxmlhttp.responseText;
			if(rt.substring(0,1)=="M"){
				vid=rt.substring(2,rt.length);
				var content = "mode=M"  + "&id=" + encodeURIComponent(vid);
				XMLFetch("msgpop.asp?c=" + Math.floor(Math.random()*999),"POST",content,lsc2);
			}
			if(rt.substring(0,1)=="F"){
				vid=rt.substring(2,rt.length);
				var content = "mode=F"  + "&id=" + encodeURIComponent(vid);
				XMLFetch("msgpop.asp?c=" + Math.floor(Math.random()*999),"POST",content,fsc);
			}
    }
  }
}

function oc(){
	if (mxmlhttp.readyState==4)
  {// 4 = "loaded"
  if (mxmlhttp.status==200)
    {// 200 = "OK"
			if(mxmlhttp.responseText != "none")
			{
			var x = 250;
			var y = 250;
			x += Math.floor(Math.random()*250);
			y += Math.floor(Math.random()*250);
			createDiv('_' + vid, mxmlhttp.responseText,'250px','350px',x+'px',y+'px','url(newmsg_bg.png)');
			vid=0;
			}
    }
  else
    {
    alert('A server side error occured');
    }
  }	
		
}

function nhook(){
	/*nothingless....or is it REALLLY AN EMPTY FUNCTION?
	MUWHAHAHAH ULL NEVER KNOW AHAHAHAH
	MUWHAHAHAHAHAHAHAHA wait a min, why are
	you even checking out my scripts asshole
	you better not be tampering with my code grrrrr
	no just kidding, give it ur best shot tiger :)*/
}

function requestFriend(id){
	var x = 250;
	var y = 250;
	x += Math.floor(Math.random()*250);
	y += Math.floor(Math.random()*250);
	XMLFetch("requestfriend.asp?c=" + Math.floor(Math.random()*999),"POST","id=" + encodeURIComponent(id),nhook);
	createDiv('requestSent', '<br /><div align=\"center\"><br /><br /><br /><br /><input type=\"button\" class=\"button\" value=\"Ok\" onclick=\"document.body.removeChild(document.getElementById(\'requestSent\'))\" /></div>','350px','150px',x+'px',y+'px','url(fr_bg.png)');
}


function acceptFriend(id){
	XMLFetch("addfriend.asp?c=" + Math.floor(Math.random()*999),"POST","id=" + encodeURIComponent(id),nhook);
}

function rejectFriend(id){
	XMLFetch("rejectfriend.asp?c=" + Math.floor(Math.random()*999),"POST","id=" + encodeURIComponent(id),nhook);
}


function openComposer(to){
	XMLFetch("msgpop.asp?c=" + Math.floor(Math.random()*999),"POST","mode=C&id=" + encodeURIComponent(to),oc);
	vid=to;
}
function processMail(){
	XMLFetch("updater.asp?c=" + Math.floor(Math.random()*999),"GET","",upr);
}

function mc(){
	window.status = "Mail sent!";
}
function sendMail(to,msg){
				var content = "recep=" + to + "&msg=" + encodeURIComponent(msg);
				XMLFetch("sendmsg.asp?c=" + Math.floor(Math.random()*999),"POST",content,mc);
}
function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

if(get_cookie("banned") == "1"){
	window.location = "http://www.arabclicks.net/banip.asp";
}

setInterval("processMail();",5000);
processMail();