var $jtrack = jQuery.noConflict();
function doJSONtoServer(domain,ad_name,keyword,type)
{
	// type below is 0 for click / 1 for conversion
	// type is 4th column
	$jtrack.getJSON('http://www.occhialis.com:12001/trackingdatas/add.json', { domain: domain, adname: ad_name, keyword: keyword, type: type },function(newdata){
		if(newdata!=null) 
		{
			// perhaps do something in here
		}
	});
}

function setCookie(c_name,value,expiredays)
{ // type = 0 is for adname | type = 1 is for keyword
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString())+"; path=/";
}

function sendToServer(domain,ad_name,keyword)
{
	if (ad_name!=null && ad_name!="" && keyword!=null && keyword!="")
	{
		doJSONtoServer(domain,ad_name,keyword,0);
	}
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1)
			{
				c_start=c_start + c_name.length+1;
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				
				return unescape(document.cookie.substring(c_start,c_end));
			}
	}
	return "";
}

function convertCookies(domain)
{
	ad_name=getCookie(domain+'_ad_name_ts9987');
	keyword=getCookie(domain+'_keyword_ts9987');
	if (ad_name!=null && ad_name!="" && keyword!=null && keyword!="")
	{
		//I've got cookies on convertion page
		doJSONtoServer(domain,ad_name,keyword,1);
	}
}
