// the user tracker consists of two parts. 
// setting the x & y coords in 



// this object is included
// at the bottom of everypage that 
// requires user tracking

function bswUserTrackerSetter(){
	
	// clear cookie to make sure we get new goods
	bswBrowser.setCookie("c","null");
	this.setHandler();	

}

bswUserTrackerSetter.prototype.setHandler = function(){

	// create an onclick handler for every 
	// anchor link on the site. If a onclick
	// event is already defined, modify the
	// onclick  to include the new functionality 

	var anchors = document.getElementsByTagName("A");

	var o = this;	
	for(a = 0;a < anchors.length;a++){
		
		if(anchors[a].onclick != null){
			
			// create object containing preexisting onlclick  functions....
			anchors[a].predefined = new Object({e:anchors[a].onclick});
			// redefine onclick event... 
			anchors[a].onclick = function(evt){			
				if(evt == null){					
					evt = event;				
				}
				o.plantCookie(o.mx(evt),o.my(evt));							
				this.predefined.e();
				return true;
			}		
		} else { 
				anchors[a].onclick = function(evt){
				if(evt == null){					
					evt = event;				
				}
				o.plantCookie(o.mx(evt),o.my(evt));
				return true;
			}
		}
		
	}
	
}
bswUserTrackerSetter.prototype.plantCookie = function (mouse_x,mouse_y){

	var toPlant = "";
		toPlant += "mx:" + mouse_x + ",";
		toPlant += "my:" + mouse_y + ",";
		toPlant += "cw:" + bswBrowser.base_x() + ",";
		toPlant += "ch:" + bswBrowser.base_y() + ",";
		bswBrowser.setCookie("c",toPlant);
	return true;
}


bswUserTrackerSetter.prototype.mx = function(evt){
	
			var x;
			
			if(x = evt.pageX){
				return x;				
			} else if (x = evt.clientX) {
				return x;		
			
			}
			
			return null;
}
	
bswUserTrackerSetter.prototype.my = function(evt){
	
			var y;
			
			if(y = evt.pageY){
				return y;				
			} else if (y = evt.clientY) {
				return y;		
			}
			
			return null;
}






// 



function bswPage(){
	

	this._trackingDomain = null;
	this._siteID = null;
	this._selectedCat = null;
	this._url = escape(document.location);
	this._page_title = escape(document.title);
	this._listViewItems = new Array();
	this._detailViewItems = new Array();
	this._bannerItems = new Array();
	this._catListView = new Array();
	this._referralControlID = null;
	this._session_id = null;
	this._guid = null;
	this._user_id = null;
	this._referring_control = null;
	this._track_user = false;	
	
	
	
}


// add banner id to banner array
bswPage.prototype.addBanner =  function (id){
	this._bannerItems.push(id);
}
// add cat id to category array
bswPage.prototype.addCatListView =  function (id){
	this._catListView.push(id);
}

// add detail item id to array
bswPage.prototype.addDetailView =  function (id){
	this._detailViewItems.push(id);
}
// add list view item (content list)
bswPage.prototype.addListView =  function (id){
	this._listViewItems.push(id);
}
// return banner array as string
bswPage.prototype.getBanner =  function (id){
	return  this._bannerItems.toString();
}
// return category list as string
bswPage.prototype.getCatListView =  function (){
	return  this._catListView.toString();
}
// return detail view list as a string
bswPage.prototype.getDetailView =  function (){
	return  this._detailViewItems.toString();
}
// return user guid
bswPage.prototype.getGUID =  function (){
	return this._guid;
}
// return list items as a string
bswPage.prototype.getListView =  function (){
	return  this._listViewItems.toString();
}
// return selected cat
bswPage.prototype.getSelectedCat =  function (){
	return this._selectedCat;
}
// return session id
bswPage.prototype.getSessionID =  function (){
	return this._session_id;
}
// return user id
bswPage.prototype.getSID =  function (){
	return this._user_id;
}
bswPage.prototype.getSiteID =  function (){
	return this._siteID;
}
bswPage.prototype.getTrackingDomain =  function (){
	return this._trackingDomain;
}
bswPage.prototype.getReferringControl =  function (){
	return this._referring_control;
}
bswPage.prototype.getWindowHeight = function(){
	var y;
	if(document.all){
		y = document.body.clientHeight;
	} else {
		y = window.innerHeight;
	}	
	return y;
}
bswPage.prototype.getWindowWidth = function(){
	var x;
	if(document.all){
		x = document.body.clientWidth;
	} else {
		x = window.innerWidth;
	}	
	return x;
}
bswPage.prototype.setGUID =  function (id){
	this._guid = id;
}
bswPage.prototype.setSessionID =  function (id){
	this._session_id = id;
}
bswPage.prototype.setSelectedCat =  function (id){
	this._selectedCat = id;
}
bswPage.prototype.getPageTitle =  function (){
	return this._page_title;
}
bswPage.prototype.getURL =  function (){
	return this._url;
}
// return user agents
bswPage.prototype.getUserAgent = function(){
	return navigator.userAgent;
}



bswPage.prototype.setSID =  function (id){
	this._user_id = id;
}
bswPage.prototype.setSiteID =  function (id){
	this._siteID = id;
}
bswPage.prototype.setTrackingDomain =  function (s){
	this._trackingDomain = s;
}
bswPage.prototype.setTrackUser =  function (b){
	this._track_user = b;
}

bswPage.prototype.setReferringControl =  function (s){
	this._referring_control = s;
}


bswPage.prototype.getTracker = function(){
	
	// d = tracking domains

	var qstring = "?";
		// qstring += "UID=" + this.getSID();
		// qstring += "&SES=" + this.getSessionID();
		// qstring += "&GUID=" + this.getGUID();
		qstring += "SELECTCATID=" + this.getSelectedCat();
		qstring += "&CL=" + this.getListView();
		qstring += "&DL=" + this.getDetailView();
		qstring += "&CATS=" + this.getCatListView();
		qstring += "&BAN=" + this.getBanner();
		qstring += "&REF=" + this.getReferringControl();
		qstring += "&WH=" + this.getWindowHeight();
		qstring += "&WW=" + this.getWindowWidth();
		
		if(this._track_user){
			document.write(qstring);
		
			document.write("<img src=\"" + this.getTrackingDomain() + "/track_image.aspx" + qstring + "\" width=\"1\" height=\"1\">");
		}

}


var page_request = new bswPage();









