function Weblink_Tracking(acX){
	var that  = this;
	var activeX = acX;
	var key;
	var actionID = 1;
	this.process = {};
	setBasicInfo();
	var trackingID;
	
	function setBasicInfo(){
		var currentTime = new Date();
		var second = currentTime.getSeconds();
		var minute = currentTime.getMinutes();
		var hour = currentTime.getHours();

		that.process['startingTime'] = hour+":"+minute+":"+second;
		that.process['Browser']=$.browser.name+" "+ $.browser.version;
		that.process['OS']= window.navigator.platform;
	}
	
	function jsonToString(){
		var stringProcess="{";
		for(x in that.process)
			stringProcess +="\""+x+"\""+": "+"\""+that.process[x]+"\""+",";
		return stringProcess.substring(0, stringProcess.length-1)+"}";
	}
	function getPlugInUserID(){
		$.ajax({
			url: '/weblink/updater/get-plugin-user-id',
			data: {
				key: key
			},
			type: "GET",
			dataType: "html",
			cache: false,
			success: function(data){
				trackingID = data;
			}
		});
	}
	function addKey(){
		$.ajax({
			url: '/weblink/updater/add-plugin-user',
			data:{
				prefix: "ADS-"
			},
			type: "GET",
			dataType: "html",
			cache: false,
			success: function(data){
				if(data != "error"){
					key = activeX.authKey = data;
					getPlugInUserID();
				}

				/**
				 * else do some error handler
				 */
			},
			error: function(){
				//TODO some error handler
			}
		});
	}
	
	this.setKey = function(){
		try{
			key = activeX.authKey;
			getPlugInUserID();
		}
		catch(e){
			addKey();
		}
		
	};
	
	this.addDeviceInfo = function(serial){
		$.ajax({
			url: '/weblink/updater/get-info',
			data:{
				serial: serial
			},
			type: "GET",
			dataType: 'json',
			cache: false,
			success: function(data){
				that.process['Series'] = data['CategoryName'];
				that.process['Product'] = data['ProductName'];
				that.process['Hardware'] = data['HardwareName'];
				that.process['Serial'] = data['Serial'];
				if(typeof(data['FirmwareName']) != 'undefined' )
					that.process['Current Firmware'] = data['FirmwareName'];
			}
		});
	};
	
	this.addInfo = function(value){
		that.process[actionID] = value;
		actionID++;

	};
	
	this.storeInfo = function(){
		$.ajax({
			url:'/weblink/updater/store-process-info',
			data:{
				info: jsonToString()
			},
			type: "POST",
			dataType: "html",
			cache: false,
			success: function(data){
				numcheck = /\d/;
				if(numcheck.test(data)){
					if(typeof(livehelp) =="undefined"){
						livehelp = new ADS_LiveHelp();
						livehelp.openWindow(data);
					}
				}
				else
					alert(data);
			},
			error: function(){
				//TODO some error handler
			}
		});
	};
	
	this.addFirmwareTracking = function(current){
		$.ajax({
			url:'/weblink/updater/add-firmware-tracking',
			data: {
				firmwareid: current.firmware.id,
				carid: current.vehicle.id,
				deviceid: current.device.get('id'),
				key: trackingID
			},
			type: "POST",
			dataType: "html",
			cache: false,
			success: function(data){
				if(data != "success")
					alert(data);
			},
			error: function(){
				//TODO some error handler
			}
		});
	};
	
	this.sendIssue = function(){
		$.ajax({
			url:'/weblink/updater/send-issue',
			data: that.process,
			type: "POST",
			dataType: "html",
			cache: false,
			success: function(data){
			},
			error: function(){
				//TODO some error handler
			}
		});
	};
		
		
}
