$(document).ready(function() {
	var cookie = checkCookie();
	if((cookie != null) && cookie.indexOf('#') == -1 && cookie.indexOf('true') == -1){
		sendData(cookie);
	} else {
		getUid();
	}
});
sendData = function(cook){
	$.postExt("/T01", {
			 cookie: cook,
			 path: window.location.href,
			 referrer: document.referrer
			 },
			 function(data) {
				
        	}, function() {
            	setTimeout('getUid()',4000);
        	}, "text");
}
visitPage = function(url,sourceType){
	var cook = checkCookie();
	if(cook == null){
		cook = 'nocookie';
	}
	//alert('visit page called');
	$.postExt("/T01", {
			 page: url,
			 cookie: cook,
			 referrer: window.location.href,
			 type: sourceType
			 },
			 function(data) {
				//TBD - callback for referrer stats
        	}, function() {
            	
        	}, "text");
}
getUid = function(){
	$.postExt("/T01", {
			 getUid: 'true'
			 },
			 function(data) {
				setCookie(data);
				if(checkCookie() == null){
					sendData("nocookie");
				} else {
					sendData(data);
				}
        	}, function() {
            	setTimeout('getUid()',1000);
        	}, "text");

}
checkCookie = function(){
	var COOKIE_NAME = 'cookwowd';
    var cookie = $.cookie(COOKIE_NAME);
	return cookie;
}
setCookie = function(cookie){
	var COOKIE_NAME = 'cookwowd';
	var options = { path: '/', expires: 1000 };
    $.cookie(COOKIE_NAME, cookie, options);
}
