
function wu_createRequestObject() {
    var xmlhttp;
    try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
    catch(e) {
        try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
        catch(f) { xmlhttp=null; }
    }
    if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
        xmlhttp=new XMLHttpRequest();
    }

   return  xmlhttp;
}

// object for getting query string key-value pairs
var Query = function()
{
	var q = document.location.search;
   	q = q.substring(1, q.length).split('&');
   	for (var i = 0; i < q.length; i++) 
   	{
   		q[i] = q[i].split('=');
   		this[q[i][0]] = (q[i][1] ? q[i][1] : true);
	}
} 

// returns true or false if cookies are enabled in the browser
function wu_cookiesEnabled()
{
	document.cookie="CookieTestPers=success; expires= Tue, 25-Dec-2012 12:34:55 GMT";
	return( document.cookie.indexOf("CookieTestPers=success") != -1);
}

// ajax call to log IP address for referral infos
function wu_logIPAddress(rootUrl, websiteId, domainId)
{
	var referrer = this.document.referrer;	    
    if (domainId == undefined)
        domainId = 0;
	var cookiesEnabled = (wu_cookiesEnabled()) ? 1 : 0;	
	
	var cachebust = new Date();
	var queryString = 'action=logipaddress&websiteid=' + websiteId 
		+ '&referrer=' + referrer + '&domain_id=' + domainId + '&cookies=' + cookiesEnabled + '&cache=' + cachebust.getTime();
	queryString =  rootUrl +  'cdeprofile/ajax_webmasteruser_facade.php?' + queryString;		

	//alert(queryString);
	
	// @todo: this should be a POST call
	var xmlhttp = wu_createRequestObject();
	xmlhttp.open('GET', queryString, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			// we actually don't really need to process the returned values
			//alert(xmlhttp.responseText);
		}
	};	
	
	
	
	xmlhttp.send(null);
}

// ajax call to log users (link them to IP addresses)
function wu_logUser(rootUrl, websiteId, userId, disableCookies, setWebmasterToDefault)
{
//	var cookiesEnabled = 1;
//	if ( disableCookies == undefined ) {
		cookiesEnabled = (wu_cookiesEnabled()) ? 1 : 0;
//	}	
			
		
	if (setWebmasterToDefault == undefined) {
		setWebmasterToDefault = 0;
	}

	
	var cachebust = new Date();
	var queryString = 'action=loguser&websiteid=' + websiteId + '&userid=' + userId
		+ '&cookies=' + cookiesEnabled + '&setwebmastertodefault=' + setWebmasterToDefault + '&cache=' + cachebust.getTime();
	queryString = rootUrl + 'cdeprofile/ajax_webmasteruser_facade.php?' + queryString;
	
	//alert(queryString);
	
	// @todo: this should be a POST call
	var xmlhttp = wu_createRequestObject();
	xmlhttp.open('GET', queryString, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			// we actually don't really need to process the returned values
			//alert(xmlhttp.responseText);
		}
	};	
	xmlhttp.send(null);
}




	function wu_logPlayedGame(rootUrl, websiteId)
	{
        var cachebust = new Date();

	var queryString = 'action=logGamePlay&websiteid=' + websiteId  + '&cache=' + cachebust.getTime();;
	queryString = rootUrl + 'cdeprofile/ajax_webmasteruser_facade.php?' + queryString;	
	//alert(queryString);
	
	// @todo: this should be a POST call
	var xmlhttp = wu_createRequestObject();
	xmlhttp.open('GET', queryString, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			// we actually don't really need to process the returned values
		//	alert(xmlhttp.responseText);
		}
	};	
	xmlhttp.send(null);		
	}

	
	function wu_canPlayGame(rootUrl, websiteId )
	{
        var cachebust = new Date();

	var queryString = 'action=canPlayGame&websiteid=' + websiteId  + '&cache=' + cachebust.getTime();;
	queryString = rootUrl + 'cdeprofile/ajax_webmasteruser_facade.php?' + queryString;
	
	//alert(queryString);
	
	// @todo: this should be a POST call
	var xmlhttp = wu_createRequestObject();
	xmlhttp.open('GET', queryString, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			// we actually don't really need to process the returned values
			//alert(xmlhttp.responseText);
			if( xmlhttp.responseText == 0 ) showNoGamePopUp();			
		}
	};	
	xmlhttp.send(null);		
	}

	
	
	function wu_initGamePlay(rootUrl, websiteId)
	{
        var cachebust = new Date();

	var queryString = 'action=initGamePlay&websiteid=' + websiteId  + '&cache=' + cachebust.getTime();
;
	queryString = rootUrl + 'cdeprofile/ajax_webmasteruser_facade.php?' + queryString;

	//alert(queryString);
	
	// @todo: this should be a POST call
	var xmlhttp = wu_createRequestObject();
	xmlhttp.open('GET', queryString, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			// we actually don't really need to process the returned values
		//	alert(xmlhttp.responseText);
		}
	};	
	xmlhttp.send(null);		
	}

	
