/* USE
		
		var _o_stats = new Stats();
		
		_o_stats.sendStat(
				'www.3cat.cat', //domain
				'web', //origin: web,forum,xat,blog
				'visit', //type: visit,sendtofriend,print
				'text', //subtype: audio,video,text,image
				'NOT_NOTICIA', //item: NOT_NOTICIA, DTY_VIDEO_MM, ETC.
				'10', //id
				null, //categories: home, catalunya, etc.
				'url',
				'titol'
		);
		
		_o_stats.sendRating(
				'www.3cat.cat', //domain
				'web', //origin: web,forum,xat,blog
				'text', //subtype: audio,video,text,image
				'NOT_NOTICIA', //item: NOT_NOTICIA, DTY_VIDEO_MM, ETC.
				'10', //id				
				null, //categories: home, catalunya, etc.
				'5', // Valoracio ítems amb puntuació del 0 al 10
				'url',
				'titol'
		);		
		
*/		

function Stats() {
		var paramList = "domain,origin,type,subtype,item,id,cat,rating,title,url";
		var paramNames = paramList.split(",");
		var urlstatsbase = "http://ratings.ccrtvi.com";
		var urlnotify = urlstatsbase + "/collector.php";
		
		Stats.prototype.serializeParams = function(parameters){				
				var ret = "";					
				for (var i=0;i<paramNames.length;i++) {
					var value = eval('parameters.'+paramNames[i]);
					if (value!=null && value!='') ret += (i>0?"&":"") + paramNames[i] + '=' + escape( eval('parameters.'+paramNames[i]) );
				}
				return ret;
		}
		
		Stats.prototype.addImage = function(parameters) {
			var serializedParams = this.serializeParams(parameters);
			if (serializedParams!=null && serializedParams!='') {
				var __url = urlnotify 
					+ "?rnd=" + new Date().getTime() //random
					+ "&" + serializedParams;//parameters				
					var _ctrlStats = document.getElementById("_divStats_");
				if (_ctrlStats) {//protect not loaded body... script must be located inside body!
					_ctrlStats.innerHTML = "<img src='" + __url +  "' alt=''/>";
					/* IE 6 problems!!!
					var newimagecreated = document.createElement('img'); 
					newimagecreated.setAttribute("alt","");		
					newimagecreated.setAttribute("style","visibility:hidden;display:none;");					
					newimagecreated.src = __url;
					_ctrlStats.appendChild(newimagecreated);										
					*/
				} else {
					document.write("<img src='" + __url +  "' alt=''/>");
				}
			}
		}
		
		Stats.prototype.sendInfo = function(domain, origin, type, subtype, item, id, cat, rating, url, title){
			this.addImage(
				{	"domain":(domain==null?document.domain:domain) , 
					"origin" : origin, 
					"type": type, 
					"subtype": subtype,
					"item": item , 
					"id" : id, 
					"cat": cat, 
					"rating": rating,
					"url":(url==null?document.location:url) , 
					"title":(title==null?document.title:title)
				}
			);
		} 		
		
		// ----------------------------------------------------------------------- USEFULL METHODS ...

		Stats.prototype.sendRating = function(domain, origin, subtype, item, id, cat, rating, url, title){
			this.sendInfo(domain, origin, 'rating', subtype, item, id, cat, rating, url, title);
		} 
		
		Stats.prototype.sendStat = function(domain, origin, type, subtype, item, id, cat, url, title){
			this.sendInfo(domain, origin, type, subtype, item, id, cat, null, url, title);
		} 

}

var _statsdomain = null;
var _statsorigin = null;
var _statstype = null;
var _statssubtype = null;	
var _statsitem = null;
var _statsid = null;
var _statscat = null;
var _statsurl = null;
var _statstitle = null;
	
function sendStat(__domain, __origin, __type, __subtype, __item, __id, __cat, __url, __title) {	
	if (typeof(Stats)!='undefined') {//stats js loaded???
		//send visit...
		new Stats().sendStat(
				(__domain!=null?__domain:_statsdomain) /*domain*/, 
				(__origin!=null?__origin:_statsorigin) /* origin: web,forum,xat,blog */, 
				(__type!=null?__type:_statstype) /* type: visit,sendtofriend,print*/,
				(__subtype!=null?__subtype:_statssubtype) /* subtype: audio,video,text,image */, 
				(__item!=null?__item:_statsitem) /* item: NOT_NOTICIA, DTY_VIDEO_MM, ETC. */, 
				(__id!=null?__id:_statsid) /* ID */, 
				(__cat!=null?__cat:_statscat) /*categories: home, catalunya, etc. */, 
				(__url!=null?__url:_statsurl) /* url */, 
				(__title!=null?__title:_statstitle) /* title */
		);
	}
}

function sendRating(val, __domain, __origin, __subtype, __item, __id, __cat, __url, __title) {
		if (val!=null && val!='') {
				if (typeof(Stats)!='undefined') {//stats js loaded???
					//send visit...
					new Stats().sendRating(
							(__domain!=null?__domain:_statsdomain) /*domain*/, 
							(__origin!=null?__origin:_statsorigin) /* origin: web,forum,xat,blog */,
							(__subtype!=null?__subtype:_statssubtype) /* subtype: audio,video,text,image */, 
							(__item!=null?__item:_statsitem) /* item: NOT_NOTICIA, DTY_VIDEO_MM, ETC. */, 
							(__id!=null?__id:_statsid) /* ID */, 
							(__cat!=null?__cat:_statscat) /*categories: home, catalunya, etc. */, 
							val,
							(__url!=null?__url:_statsurl) /* url */, 
							(__title!=null?__title:_statstitle) /* title */
					);
					return true;
				}
		}
		return false;
}

document.write("<div id='_divStats_'></div>");