/*
	RELATION TECHNOLOGY
	Live Support 3.0
	Common Functions
*/

var RLSCommon = {
	
	//root: 'http://localhost/simple/livesupport/',
	root: 'http://livesupport.slideshop.com/',
	
	// Removes a script from the DOM after usage
	killScript: function(id){
		child = document.getElementById(id);
		if (child) child.parentNode.removeChild(child);
		return false;
	},
	
	// Executes a JavaScript file
	loadRequest: function(file){
		var ajaxDir = 'themes/common/';
		var newDate = new Date;
		var uniqueID = newDate.getTime();
		var id = 'rtSupport_' + uniqueID;
		var arr = file.split('?');
		var symbol = (arr.length == 1) ? '?' : '&';
		var url = RLSCommon.root + ajaxDir + file + symbol + 'scriptElementID=' + id;
		var script = document.createElement('script');
		script.src = url;
		script.type = 'text/javascript';
		script.id = id;
		document.getElementsByTagName('head')[0].appendChild(script);
		return false;
	},
	
	setSession: function(data, callback){
		var url = RLSCommon.root + "themes/common/setSession.php";
		var params = "json=" + JSON.stringify(data);
		if (window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); }
		else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		if (params) xmlhttp.send(params);
		else xmlhttp.send();
		xmlhttp.onreadystatechange = function(e){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					callback();
				}
			}
		};
		xmlDoc = xmlhttp.responseText;
	},
	
	// Google Analytics
	trackEvent: function(obj){
		if (LiveSupport.analytics && window._gaq){
			var tCategory = (obj.category ? obj.category : 'Live Support');
			var tEvent = (obj.event ? obj.event : 'No event');
			var tValue = (obj.value ? obj.value : window.location);
			window._gaq.push(function(){
				var pageTracker = window._gat._getTracker(LiveSupport.analytics);
				pageTracker._trackEvent(tCategory, tEvent, tValue);
			});
		}
	},
	
	// Dividable by
	divBy: function(number, amount){
	    var newNum = number/amount;
	    return (newNum === Math.round(newNum));
	}
	
}
