﻿var livesec = 0;
var livestart = 0;
var livestop = 1;
var fadecount = 0;
var fadestep = 0;


var objXMLHTTP = null;
var objXMLHTTPpop = null;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			objXMLHTTP = new XMLHttpRequest();
			objXMLHTTPpop = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) { // IE
		try
		{
			objXMLHTTP = new ActiveXObject ("Msxml2.XMLHTTP");
			objXMLHTTPpop = new ActiveXObject ("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				objXMLHTTP = new ActiveXObject ("Microsoft.XMLHTTP");
				objXMLHTTPpop = new ActiveXObject ("Microsoft.XMLHTTP");
			}
			catch(e1)
			{
				objXMLHTTP = null;
				objXMLHTTPpop = null;
			}
		}
	}
	
	var objXMLHTTPL = null;
var objXMLHTTPpopL = null;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			objXMLHTTPL = new XMLHttpRequest();
			objXMLHTTPpopL = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) { // IE
		try
		{
			objXMLHTTPL = new ActiveXObject ("Msxml2.XMLHTTP");
			objXMLHTTPpopL = new ActiveXObject ("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				objXMLHTTPL = new ActiveXObject ("Microsoft.XMLHTTP");
				objXMLHTTPpopL = new ActiveXObject ("Microsoft.XMLHTTP");
			}
			catch(e1)
			{
				objXMLHTTPL = null;
				objXMLHTTPpopL = null;
			}
		}
	}
		

function checkLogin() {
	document.getElementById('divSummary').innerHTML = '<br><br><IMG src="pic/loadbig.gif"><br><br>در حال دريافت اطلاعات ...<br>لطفا صبر کنيد';
	AjaxWGStat('stat=stat&pwd='+document.getElementById('statpwd').value,'صفحه نخست گزارشات','ajaxstat');
	return false;
}

function AjaxWGStat(stat, title, divid) {

	document.getElementById('loadBox').style.display='';

	var strOutput;
    strOutput='Error';
    
    objXMLHTTP.open("GET", 'engine1.aspx?code=' + code + '&' + stat + '&rnd=' + Math.random());
    objXMLHTTP.onreadystatechange = function() {
        if (objXMLHTTP.readyState == 4 && objXMLHTTP.status == 200) {
            strOutput = objXMLHTTP.responseText;
            var inputs = strOutput.split("(||)");
            if (inputs[0]=='2') {document.getElementById('divSummary').innerHTML = inputs[1];}
            document.getElementById(divid).innerHTML = inputs[2];
            if (title != 'no') {document.getElementById('divtitle').innerHTML = title;};
			document.getElementById('loadBox').style.display='none';
			document.getElementById('ajaxstat').style.display='';
			document.getElementById('ajaxlive').style.display='none';
			document.getElementById('divcity').style.display='none';
			livestop=1;
			
		}
    }
    objXMLHTTP.send(null);	
}


function startLive() {
	if (livestop==1) {
		livestart=1;
		livestop=0;
		AjaxLive();
		document.getElementById('divtitle').innerHTML = 'نمايش زنده گزارشات سايت' ;
	}
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function fadeLive() {
	
	for (var i = 1; i <= (fadecount) ; i++) {
		if (fadestep==1){document.getElementById('live'+i).style.backgroundColor='fdc085';}
		if (fadestep==2){document.getElementById('live'+i).style.backgroundColor='fdc793';}
		if (fadestep==3){document.getElementById('live'+i).style.backgroundColor='fccda0';}
		if (fadestep==4){document.getElementById('live'+i).style.backgroundColor='fbd3ae';}
		if (fadestep==5){document.getElementById('live'+i).style.backgroundColor='fbd9bb';}
		if (fadestep==6){document.getElementById('live'+i).style.backgroundColor='fae0c9';}
		if (fadestep==7){document.getElementById('live'+i).style.backgroundColor='f9e6d6';}
		if (fadestep==8){document.getElementById('live'+i).style.backgroundColor='f8ece4';}
		if (fadestep==9){document.getElementById('live'+i).style.backgroundColor='f8f3f1';}
		if (fadestep==10){document.getElementById('live'+i).style.backgroundColor='f7f9ff';}
	}
	
	if (fadestep!=10){window.setTimeout(fadeLive,120);}
	fadestep=fadestep+1;
}

function controlLive(action){

	if (action==1 && livestop==1){
		document.getElementById('livePause').src='pic/lpause-on.gif';
		document.getElementById('liveStart').src='pic/lstart-off.gif';
		livestop=0;
		AjaxLive();
	}

	if (action==0 && livestop==0){
		document.getElementById('livePause').src='pic/lpause-off.gif';
		document.getElementById('liveStart').src='pic/lstart-on.gif';
		livestop=1;
	}

}

function AjaxLive() {

try
	{

if(livestart==1){
	livestart=0;
	livestop=0;
	livesec=0;
	document.getElementById('ajaxstat').style.display='none';
	document.getElementById('ajaxlive').style.display='';
	document.getElementById('divcity').style.display='none';
	for (var i = 1; i <= 20 ; i++) {
		document.getElementById('live'+i).style.display='none';
		document.getElementById('live'+i).innerHTML='';
	}
	document.getElementById('liveload').style.display='';
	document.getElementById('livePause').src='pic/lpause-on.gif';
	document.getElementById('liveStart').src='pic/lstart-off.gif';
}

if (livestop==0){
	var strOutput;
    strOutput='Error';
    
    objXMLHTTPL.open("GET", 'engine1.aspx?code=' + code + '&stat=live&sec='+livesec+'&rnd=' + Math.random());
    objXMLHTTPL.onreadystatechange = function() {
        if (objXMLHTTPL.readyState == 4 && objXMLHTTPL.status == 200) {
            strOutput = objXMLHTTPL.responseText;
           	           	
           	var inputs = strOutput.split("(||)");
			var count = inputs[0];
			var referrer;
						
			if (count=='pass') {
				livestop=1;
				document.getElementById('ajaxlive').style.display='none';
				document.getElementById('ajaxstat').style.display='';
				document.getElementById('ajaxstat').innerHTML='<form onsubmit="return checkLogin();"><br><br><img src=pic/lock.jpg style="vertical-align:middle" />&nbsp; دسترسی به آمار اين سايت خصوصی می باشد.<br> لطفا برای مشاهده آن رمز عبور را وارد کنيد. <br><br><input type=password class=txtboxes style=width:200px id=statpwd /><br><br><input type=submit id=submit class=btn-blue value="مشاهده آمار" onmousemove="this.style.backgroundPosition=\'0px -33px\';" onmouseout="this.style.backgroundPosition=\'0px 0px\';" /></form><br><br>';
			}
			else{
			
			livesec=inputs[1];
			
			if (count!='0') {
			
				for (var i = 1; i <= 20 ; i++) {
					document.getElementById('live'+i).style.display='none';
				}
				
				document.getElementById('liveload').style.display='none';	
						
				for (var i = 0; i <= (19-count) ; i++) {
					document.getElementById('live'+(20-i)).innerHTML=document.getElementById('live'+((20-i)-count)).innerHTML;
					document.getElementById('live'+(20-i)).style.backgroundColor='f7f9ff';
					if(document.getElementById('live'+(20-i)).innerHTML!=''){document.getElementById('live'+(20-i)).style.display='';}
				}
			
				var inputformat = '<div class=dlr><img title="#1#" style="cursor:pointer" onclick="LC(/#3#/,event)" src=flags/#2#[1].gif border=0 width=20 height=14>  #3# -- زمان: <b>#4#</b><div class=dlu><b>لينک دهنده:</b> <span dir=ltr><a href="http://#5#" title="http://#5#" target=_blank>#referrer#</a></span><br><b>ورود به:</b> <a href="http://#6#" title="http://#6#" target=_blank>#7#</a></div></div><div class=dll><IMG src="pic/#8#.gif">&nbsp;<IMG src="pic/#9#.gif"><br>#10#<br>#11# بازديد</div><div class=dlc><!-- --></div>'
			
				for (var i = 1; i <= (count) ; i++) {
					var values = inputs[i+1].split("###");
					referrer=values[4];
					if ( referrer.length > 50 ){referrer=Left(referrer,40)+'...';}
					
					document.getElementById('live'+i).innerHTML= inputformat.replace(/#referrer#/g,referrer).replace(/#1#/g,values[0]).replace(/#2#/g,values[1]).replace(/#3#/g,values[2]).replace(/#4#/g,values[3]).replace(/#5#/g,values[4]).replace(/#6#/g,values[5]).replace(/#7#/g,values[6]).replace(/#8#/g,values[7]).replace(/#9#/g,values[8]).replace(/#10#/g,values[9]).replace(/#11#/g,values[10]);
					document.getElementById('live'+i).style.display='';
					document.getElementById('live'+i).style.backgroundColor='feba78';
				}

			}
			
			fadecount=count;
			fadestep=0;
			fadeLive();
			
			window.setTimeout(AjaxLive,3000)
			
			}
		}
    }
    objXMLHTTPL.send(null);	
    
}

	}
catch(err)
	{
		window.setTimeout(AjaxLive,3000)
	}
}

	
function LC(ip,e){ // LoadCity

	if (document.all?true:false) { // grab the x-y pos.s if browser is IE
	  tempX = event.clientX + document.body.scrollLeft;
	  tempY = event.clientY + document.body.scrollTop;
	} else {  // grab the x-y pos.s if browser is NS
	  tempX = e.pageX;
	  tempY = e.pageY;
	}  

	document.getElementById('divcity').innerHTML='<table border="1" width="360" id="table1" cellspacing="0" cellpadding="0" height="240" bordercolor="#000000" style="border-collapse: collapse; border-width: 0px" background="PIC/worldmap.gif"><tr><td align=center valign=middle style="border-width:0px"><div align="background-color:white;width:120px"><img src="pic/loading.gif"></div></td></tr></table><div dir="rtl" style="font-family:tahoma;font-size:8pt;padding:5px"><a href="#city" onclick="LoadCityClose()">[x بستن]</a>&nbsp;&nbsp;&nbsp;در حال جستجو ...</b></div>';
	document.getElementById('divcity').style.display='';
	document.getElementById('divcity').style.top=tempY-divcity.offsetHeight-5;
	document.getElementById('divcity').style.left=tempX-divcity.offsetWidth-5;

    objXMLHTTPpop.open("GET", 'engine1.aspx?code=123&stat=city&ip=' + ip + '&rnd=' + Math.random());
    objXMLHTTPpop.onreadystatechange = function() {
        if (objXMLHTTPpop.readyState == 4 && objXMLHTTPpop.status == 200) {
            strOutput = objXMLHTTPpop.responseText;
            document.getElementById('divcity').innerHTML = strOutput;
        }
    }
    objXMLHTTPpop.send(null);

}
	
function LoadCityClose(){
	document.getElementById('divcity').style.display='none';
}

