// In The Name of Allah, The Most Gracious, The Most Merciful
/*
Powered for VWDEV.com
*/

var HomeAddress = "..";

//var HomeAddress = "http://local-domain";
//var HomeAddress = "http://internet-domain/";

var MiscTrackURL = HomeAddress + "/stater/stater.php";
var CounterPositionURL = HomeAddress + "/stater/stater.php?place";
var CounterImageSource = '';
var CounterWidth = 72;
var CounterHeight = 18;
var CounterPosition = 3;
var CounterPositionatEnd = true;
var CounterVisibility = true;

var DocumentText = '';

var RequestResponse;

// ------------- Public Vars --------------------------
var Starts, End;
var isIE, isNS, isOpers;
var isWinOS, isMacOS;
var addStatBar = false;
var DocumentLoaded = false;

// ----------------------
nullfunction = function(){};
var PrevOnReadyStateChange;

function SetCookie(CookieName, CookieValue, CookieExpire /* Duration : In Hour Scale */)
{
	ExpireDate = new Date();
	ExpireDate.setTime(ExpireDate.getTime() + (CookieExpire * 3600 * 1000));
	document.cookie = CookieName + "=" + escape(CookieValue) + "; path=/" + ((CookieExpire == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function GetCookie(CookieName)
{
	if (document.cookie.length > 0)
	{
		Start = document.cookie.indexOf(CookieName + "=");
		if (Start != -1)
		{
			Start += CookieName.length + 1; 
			End = document.cookie.indexOf(";", Start);

			if (End == -1)
				End = document.cookie.length;

			return unescape(document.cookie.substring(Start, End));
		}
		return null; 
	}
	return null; 
}

function DetectIEPlugIns(plugin)
{
	var plugin_ = new Array(
		"Shockwave Flash",
		"Shockwave for Director",
		"RealPlayer",
		"QuickTime",
		"VivoActive",
		"LiveAudio",
		"VRML",
		"Dynamic HTML Binding",
		"Windows Media Services"
	);

	var pluginsid = new Array(
		"D27CDB6E-AE6D-11CF-96B8-444553540000",
		"2A202491-F00D-11CF-87CC-0020AFEECF20",
		"23064720-C4F8-11D1-994D-00C04F98BBC9",
		"",
		"",
		"",
		"90A7533D-88FE-11D0-9DBE-0000C0411FC3",
		"9381D8F2-0288-11D0-9501-00AA00B911A5",
		"22D6F312-B0F6-11D0-94AB-0080C74C7E95"
	);


	for(var i = 0; (i < plugin_.length) && (plugin_[i].toLowerCase() != plugin.toLowerCase()); i++);

	pl = plugin.toLowerCase();
	//alert(pl);

	var l = 0;
	
	
	if (plugin_[i])
	{
		l = i;
	}
	else if (plugin_[i-1])
	{
		l = i - 1;
	}
	else
	{l = -1;}

	if (l > -1)
	{
		var db = document.body;
		db.addBehavior("#default#clientcaps");
		if(db.isComponentInstalled("{"+pluginsid[l]+"}","componentid"))
		{result = 'y';}
		else
		{result = 'n';}
	}
	else
	{
		result = 'n';
	}

	return result;
}

function DetectNSPlugIns(plugin)
{
	var result = 'n';
	var plugin_ = new Array(
		"Shockwave Flash",
		"Shockwave for Director",
		"RealPlayer",
		"QuickTime",
		"VivoActive",
		"LiveAudio",
		"VRML",
		"Dynamic HTML Binding",
		"Windows Media Services"
	);

	var db = navigator.plugins;
	for(var i = 0; i < db.length; i++)
	{
		if(db[i].name.toLowerCase().indexOf(plugin.toLowerCase()) >= 0)
		{
			return 'y';
		}
		else
		{
			result = 'n';
		}
	}

	return result;
}

function StatisticsBarFunction(options)
{
	var PersistClose=0;
	var startX = 0;
	var startY = 0;
	var VerticaPos="frombotton";
	var HorizontalPos = "left";
	
	switch (CounterPosition)
	{
		case 15 :
			VerticaPos = "fromtop";
			HorizontalPos = "left";
			break;
		case 16 :
			VerticaPos = "fromtop";
			HorizontalPos = "center";
			break;
		case 17 :
			VerticaPos = "fromtop";
			HorizontalPos = "right";
			break;
		case 25 :
			VerticaPos = "frombotton";
			HorizontalPos = "left";
			break;
		case 26 :
			VerticaPos = "frombotton";
			HorizontalPos = "center";
			break;
		case 27 :
			VerticaPos = "frombotton";
			HorizontalPos = "right";
			break;
	}

	function iecompattest()
	{
		//return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
		return document.body
	}

	function CloseStatBar()
	{
		if (PersistClose)
			SetCookie("remainclosed", 1, 1);

		xVisibility("StatisticsBar", false);
	}

	function statbar()
	{
		barheight=xGetElementById("StatisticsBar").offsetHeight;
		barwidth=xGetElementById("StatisticsBar").offsetWidth;

		var ns = isNS || isOpera;

		var d = document;

		function ml(id)
		{
			var el=d.getElementById(id);
			if (!PersistClose || PersistClose && GetCookie("remainclosed")=="")
				el.style.visibility = "visible"

			if(d.layers)
				el.style=el;

			el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};

			el.x = startX;

			if (VerticaPos=="fromtop")
				el.y = startY;
			else
			{
				el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
				el.y -= startY;
			}

			return el;
		}
		window.FixStatbarPosition = function()
			{
				if (VerticaPos=="fromtop")
				{
					var pY = ns ? pageYOffset : iecompattest().scrollTop;
					ftlObj.y += (pY + startY - ftlObj.y)/8;
				}
				else
				{
					var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
					ftlObj.y += (pY - startY - ftlObj.y)/8;
				}
	
				if (HorizontalPos == "left")
				{
					var pX = 0;
					ftlObj.x += (pX + startX - ftlObj.x)/8;
				}
				else if (HorizontalPos == "center")
				{
					var pX = ns ? (innerWidth - barwidth) / 2: (iecompattest().clientWidth - barwidth) / 2;
					ftlObj.x += (pX - ftlObj.x)/8;
				}
				else if (HorizontalPos == "right")
				{
					var pX = ns ? innerWidth - barwidth: iecompattest().clientWidth - barwidth;
					ftlObj.x += (pX - startX - ftlObj.x)/8;
				}
	
				ftlObj.sP(ftlObj.x, ftlObj.y);
				setTimeout("FixStatbarPosition()", 10);
			}

		ftlObj = ml("StatisticsBar");
		FixStatbarPosition();
	}
	statbar();
}

function Stater(uuid,/*pageid,*/ /*position, */options)
{
	//alert('Stater(' + pageid + ')');
	var USRScreen, USRWinSize, USRCdi, hasJava, hasSHK, hasSVG, hasFLA, USRNSe;
	var hasRP, hasMOV, hasWMA, hasPDF, USRPDFVer, UserID, SessionID;
	var Now;

	if (CounterPosition==1 || CounterPosition==0)
	{CounterPosition = 5;}

	Now = new Date();
	USRScreen = screen.width + "x" + screen.height;

	if (navigator.appName != "Netscape"){ USRCdi = screen.colorDepth; }
	else {USRCdi = screen.pixelDepth};

	hasJava = navigator.javaEnabled();

	UserID = GetCookie("SETUSER_ID");
	SessionID = GetCookie("SETSESSION_ID");
	var RandomNumber=Math.floor(Math.random()*10000);
	if (UserID == null || (UserID == "")) { UserID = "setuser_id" + Now.getTime() +"u"+ RandomNumber; }
	if (SessionID == null || (SessionID == "")) { SessionID = "setsession_id" + Now.getTime() +"v"+ RandomNumber; }
	SetCookie("SETUSER_ID", UserID, 10000);
	SetCookie("SETSESSION_ID", SessionID, 1);
	UserID = ""; UserID = GetCookie("SETUSER_ID");
	SessionID = ""; SessionID = GetCookie("SETSESSION_ID");

	var NavText = navigator.appName.toLowerCase();     // "internet explorer" or "netscape"
	var AgentText = navigator.userAgent.toLowerCase();   // "msie...", "mozilla...", "firefox..."

	var isWinOS  = ((AgentText.indexOf("win")!=-1) || (AgentText.indexOf("32bit")!=-1));
	var isMacOS  = (AgentText.indexOf("mac")!=-1);

	var OS = "";
	var OSVer = "Unknown"

	if (isWinOS)
		{ OS="Windows";}
	else if (isMacOS)
		{OS = "Macintosh";}
	else
		{OS = "Unknown";}

	var NavName = "";
	var isNS = (NavText.indexOf("netscape") != -1);
	var isOpera = (NavText.indexOf("opera") != -1);
	var isIE = (AgentText.indexOf("msie") != -1);

	if (isNS)
		{NavName = "Netscape";}
	else if (isOpera)
		{NavName = "Opera";}
	else if (isIE)
		{NavName = "Msie";}
	else 
		{NavName = "Unknown";}

	if (document.documentElement && document.documentElement.clientWidth)
		USRWinSize = document.documentElement.clientWidth + 'x' + document.documentElement.clientHeight;
	else if (document.body && document.body.clientWidth)
		USRWinSize = document.body.clientWidth + 'x' + document.body.clientHeight;
	else
		USRWinSize = window.innerWidth + 'x' + window.innerHeight;

	if (isIE && isWinOS)
	{
		hasshk = DetectIEPlugIns("Shockwave for Director");
		hassvg = DetectIEPlugIns("Adobe.SVGCtl");
		hasfla = DetectIEPlugIns("Shockwave Flash");
		hasrp  = DetectIEPlugIns("RealPlayer");
		hasmov = DetectIEPlugIns("QuickTime");
		haswma = DetectIEPlugIns("Windows Media Services");
		haspdf = 'n'; USRPDFVer='';
	}

	if (isNS || !isIE)
	{
		USRNSe = "";
		for (var i = 0; i < navigator.mimeTypes.length; i++)
			USRNSe += navigator.mimeTypes[i].type.toLowerCase();

		hasSHK = DetectNSPlugIns("Shockwave for Director");
		//TRKsvg = /* DetectNSPlugIns("image/svg+xml","" */);
		hasSVG = DetectNSPlugIns("image/svg+xml");
		if (document.implementation.hasFeature("org.w3c.dom.svg", "")) {hasSVG = "y"; }
		hasFLA = DetectNSPlugIns("Shockwave Flash");
		hasRP  = DetectNSPlugIns("RealPlayer");
		hasMOV = DetectNSPlugIns("QuickTime");
		hasWMA = DetectNSPlugIns("Windows Media Services");
		hasPDF = 'n'; //DetectNSPlugIns("application/pdf");
		USRPDFVer = '';
	}

	if (typeof window.document.referrer != 'undefined')
	{
		var Referer = window.document.referrer;
	}
	else
	{
		var Referer = '';
	}

	var imgsrc1 = MiscTrackURL + '?' + 'uuid=' + uuid;
	var CounterAddress = '';
	var imgsrc2 = '&counterfile=' + CounterAddress;
	var imgsrc3 = '&os=' + OS + '&osver=' + OSVer + '&nav=' + escape(NavName);
	var imgsrc4 = '&screen=' + USRScreen + '&win=' + USRWinSize + '&cdi=' + USRCdi;
	var imgsrc5 = '&java=' + hasJava + '&shk=' + hasSHK + '&svg=' + hasSVG + '&fla=' + hasFLA + '&rp=' + hasRP + '&mov=' + hasMOV + '&wma=' + hasWMA + '&pdf=' + hasPDF;
	var imgsrc6 = '&uid=' + UserID + '&sid=' + SessionID;
	var imgsrc7 = '&addr=' + escape(window.location) + '&httpr=' + escape(Referer);

	CounterImageSource =imgsrc1+imgsrc2+imgsrc3+imgsrc4+imgsrc5+imgsrc6+imgsrc7;

	if ((document.readyState == 'loaded')||(document.readyState == 'complete'))
	{
		SetStatsCheck();	
	}
	else
	{
		d = document;
		if(d.attachEvent)
		{
			d.attachEvent('onreadystatechange', SetStatsCheck, false);
		}
		else if(window.navigator.userAgent.toLowerCase().indexOf('firefox') != -1)
		{
			window.addEventListener('load', SetStatsCheck, false);
			d._readyState_ = 'loaded';
		}
		else if(d.addEventListener)
		{
			d.addEventListener('load', SetStatsCheck, false);
		}
		else
		{
			var o=d['onreadystatechange'];
			d['onreadystatechange'] = typeof o=='function' ? function(v) { o(v); SetStatsCheck(v);} : SetStatsCheck;
		}
	}
}

function SetStatsCheck()
{
	d = document;
	if ( d.readyState == 'loaded' || d.readyState == 'complete' || d._readyState_ == 'loaded')
	{
		//DocumentLoaded = true;
		if (((CounterPosition>=15) && (CounterPosition<=17)) || ((CounterPosition>=25) && (CounterPosition<=27)))
		{
			CounterPositionatEnd = false;
			CounterVisibility = true;
			CreateSetStatsIECounterObject();
			StatisticsBarFunction();
		}
		else if (CounterPosition == 3)
		{
			CounterVisibility = true;
			CounterPositionatEnd = true;
			CreateSetStatsCounterObject();
		}
		else if (CounterPosition == 2)
		{
			CounterPositionatEnd = true;
			CounterVisibility = false;
			CreateSetStatsCounterObject();
		}

		d.onreadystatechange = null;
	}
}

function CreateSetStatsCounterObject()
{
	Img = document.getElementById('StaterImg');
	Img.src = CounterImageSource;
}
