
// Check if Cookie is enable in browser or not
// OCCFirst is the cookie that set to capture
// the first session id of the user/browser
var cookie_set;
if (document.cookie)
{
	if (document.cookie.indexOf('OCCFirst') != -1)
		cookie_set=true;
	else
		cookie_set=false;
}
// End Check if Cookie is enable in browser or not


// Capture Mouse Postion 
// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    }
    
 
}
// End Mouse Postion Capture


// Page Size
// Global Variables
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page
    if (document.layers) {
    	// Netscape
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
    	// IE
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
// End Page Size

var Ref=document.referrer;
var eventNo = 0;
var eventFocus = 0;
if (typeof(parent.document)!="unknown")
{
	var F=parent.document.URL;
	if (document.referrer==F) Ref=parent.document.referrer;
}
var S="type=PGIMGLOAD";
var GA_Url=window.document.URL;
S+="&url="+escape(GA_Url).substring(0,800);
S+="&referer="+escape(Ref).substring(0,800);
S+="&cookie="+cookie_set;
if(typeof(screen)=="object")
{
	S+="&resolution="+screen.width+"x"+screen.height;
	S+="&availresolution="+screen.availWidth+"x"+screen.availHeight;
	S+="&color="+screen.colorDepth;
	S+="&pixeldepth="+screen.pixelDepth;
}
S+="&pageSize="+xMousePosMax+"x"+yMousePosMax;
S+="&historyLength="+window.history.length;

S+="&Tips="+Math.random();
document.write("<img border=0 src='ImageTracking?"+S+"'>");


function stloga()
{
//	alert("hello");
	window.focus();
	if (window.status)
	{
		bug = new Image();
		bug.src = 'ImageTracking?type=GOOGLEAS&clickPosition='+xMousePos+'x'+yMousePos+'&exit=Adsense->' + escape(window.status)+ '&Tips=' + Math.random();
	}
	else{
		var click='Ad Clicked';
		bug = new Image();
		bug.src = 'ImageTracking?type=GOOGLEAS&clickPosition='+xMousePos+'x'+yMousePos+'&exit=Adsense->' + escape(click)+ '&Tips=' + Math.random();
	}
}


function stlogc()
{
	var temp=window.location.href.split("/");
	var domain=temp[2];
	var click
	var clickText;
	if (this.href)
	{
		click = this.href;
		clickText = this.innerHTML;
	}
	else
	{
		click = window.event.srcElement.href;
		clickText = window.event.srcElement.innerHTML;
	}	
	if (click.indexOf(domain) == -1)
	{
	  bug = new Image();
	  bug.src = 'ImageTracking?type=LINKCLICK&clickPosition='+xMousePos+'x'+yMousePos+'&exit='+escape(click)+ '&linkText='+clickText+'&Tips=' + Math.random();
	}
}

// For Google Ad Sense
var elements;
if(document.getElementsByTagName)
{
	elements = document.body.getElementsByTagName("iframe");
}
else if (document.body.all)
{
	elements = document.body.all.tags("iframe");
}
else
{
	elements = array();
}
for (var i = 0; i < elements.length; i++)
{
	if (elements[i].src.indexOf('googlesyndication.com') > -1)
	{
//		elements[i].onfocus = stloga;
		if (elements[i].addEventListener)
			elements[i].addEventListener('focus',stloga,false);
		else if (elements[i].attachEvent)
			elements[i].attachEvent('onfocus',stloga);
	}
}




// For External Links
if(document.getElementsByTagName)
{
	elements = document.body.getElementsByTagName("a");
}
else if (document.body.all)
{
	elements = document.body.all.tags("a");
}
else
{
	elements = array();
}
for (var i = 0; i < elements.length; i++)
{
//    elements[i].onclick = stlogc;
//	var old = (elements[i].onclick) ? elements[i].onclick : function () {};
//	elements[i].onclick = function () {stlogc(); old();};
	if (elements[i].addEventListener)
		elements[i].addEventListener('click',stlogc,false);
	else if (elements[i].attachEvent)
		elements[i].attachEvent('onclick',stlogc);
}

function stlogblur()
{
	if (eventNo != 5)
	{
		bug = new Image();
		bug.src = 'ImageTracking?type=PGWINBLUR&exit=windowblur' + '&Tips=' + Math.random();
	}
	eventNo = 5;
}

function stlogwinfocus()
{
	if (eventNo == 0 || eventNo != 15)
	{
		bug = new Image();
		bug.src = 'ImageTracking?type=PGWINFOCUS&exit=windowfocus' + '&Tips=' +  Math.random();
	}
	eventNo = 15;
}

// function stlogclose()
// {
// bug = new Image();
//   bug.src = 'ImageTracking?type=PGWINCLOSE&exit=windowclose' + '&Tips=' + Math.random();
// }

// function stlogdocdeactivate()
// {
//   bug = new Image();
//   bug.src = 'ImageTracking?type=DOCDEACTIVATE&exit=windowdocdeactivate' + '&Tips=' +  Math.random();
// }

// function stlogdocunload()
// {
//   bug = new Image();
//   bug.src = 'ImageTracking?type=PAGECLOSE&exit=pageclose' + Math.random();
// }

window.onblur = stlogblur;
window.onfocus = stlogwinfocus;
//window.onbeforeunload = stlogclose;
//document.onunload = stlogdocunload;
//document.onbeforedeactivate = stlogdocdeactivate;

