/********************************************
* developped by Arnaud Binard www.wikio.com *
* merci de ne pas enlever ce commentaire    *
* please don't remove this comment          *
********************************************/
top.liveZone = top.document.getElementById("mbody");
function getLastChild(oNode){	while(oNode.nodeType != 1) oNode = oNode.previousSibling; return oNode;}
function live(){this.obj = this; top.liveArray = new Array(); top.liveRefresh = -1; top.liveid = null; top.livets = null; top.sendlive = null;}
live.prototype.newLive = function(){
	this.mainTr = top.document.createElement("TR");
	this.url = this.siteName = this.author = this.date = this.catidx = this.categ = null;
	this.poll(); this.insert();
	top.liveArray.addElement(this.mainTr);
}
live.prototype.insert = function(){
	this.toptd = top.document.createElement("TD");
	this.toptd.className = "insert";
	effectTABLE = top.document.createElement("TABLE"); setTable(effectTABLE);
	this.toptd.appendChild(effectTABLE);
	effectTBODY = top.document.createElement("TBODY");
	effectTABLE.appendChild(effectTBODY);
	effectTR = top.document.createElement("TR");
	effectTBODY.appendChild(effectTR);
	this.insertTD = top.document.createElement("TD");
	this.prez = top.document.createElement("DIV");
	this.prez.className = "commentlive"; this.prez.style.display = "none"; 
	this.insertTD.appendChild(this.prez);
	effectTR.appendChild(this.insertTD);
	this.mainTr.appendChild(this.toptd);
}
live.prototype.poll = function(){
	this.pollTD = top.document.createElement("TD");
	this.pollTD.className = "poll";
	this.sprez = top.document.createElement("DIV");
	this.sprez.className = "commentlive"; this.sprez.style.display = "none";
	this.sprez.appendChild(top.document.createTextNode(" "));
	this.pollTD.appendChild(this.sprez);
	this.pollNote = top.document.createElement("DIV");
	this.pollVote = top.document.createElement("DIV");
	this.pollTD.appendChild(this.pollNote);
	this.pollTD.appendChild(this.pollVote);
	this.mainTr.appendChild(this.pollTD);
}
live.prototype.newComment = function(){
	this.mainTr = top.document.createElement("TR");
	this.url = this.siteName = this.author = this.date = this.catidx = this.categ = null;
	this.mainTr.appendChild(this.spacer()); this.insertCmt();
	top.liveArray.addElement(this.mainTr);
}
live.prototype.insertCmt = function(){
	this.commenttd = top.document.createElement("TD");
	this.commenttd.className = "insert";
	effectTABLE = top.document.createElement("TABLE"); setTable(effectTABLE);
	this.commenttd.appendChild(effectTABLE);
	effectTBODY = top.document.createElement("TBODY");
	effectTABLE.appendChild(effectTBODY);
	effectTR = top.document.createElement("TR");
	effectTBODY.appendChild(effectTR);
	this.insertComment = top.document.createElement("TD");
	this.commentAuthorDiv = top.document.createElement("DIV");
	this.insertComment.appendChild(this.commentAuthorDiv);
	bubble = top.document.createElement("TABLE");
	setTable(bubble); bubble.style.margin = "5px";
	bubbleTBODY = top.document.createElement("TBODY");
	bubble.appendChild(bubbleTBODY);
	bubTop = top.document.createElement("TR");
	bubbleTBODY.appendChild(bubTop);
	bubTop.appendChild(this.bubbleCorner(false,"dbubtl0"));
	bubTop.appendChild(this.bubbleCorner("dbubt","bubb"));
	bubTop.appendChild(this.bubbleCorner(false,"dbubtr"));
	bubMain = top.document.createElement("TR");
	bubbleTBODY.appendChild(bubMain);
	bubMain.appendChild(this.bubbleCorner("dbubl","bubb"));
	insertZone = top.document.createElement("TD");
	insertZone.id = "comment"; insertZone.className = "dbubc"
	insertZone.style.width = "100%"; insertZone.style.paddingBottom = "3px";
	bubbleTable = top.document.createElement("TABLE");
	setTable(bubbleTable,true);
	this.iBubble = top.document.createElement("TBODY");
	bubbleTable.appendChild(this.iBubble);
	insertZone.appendChild(bubbleTable);
	bubMain.appendChild(insertZone);
	bubMain.appendChild(this.bubbleCorner("dbubr","bubb"));
	bubBottom = top.document.createElement("TR");
	bubbleTBODY.appendChild(bubBottom);
	bubBottom.appendChild(this.bubbleCorner(false,"dbubbl"));
	bubBottom.appendChild(this.bubbleCorner("dbubb","bubb"));
	bubBottom.appendChild(this.bubbleCorner(false,"dbubbr"));		
	this.insertComment.appendChild(bubble);						
	effectTR.appendChild(this.insertComment);
	this.mainTr.appendChild(this.commenttd);
}
live.prototype.bubbleCorner = function(cssClass,imgClass){
	corner = top.document.createElement("TD");
	if (cssClass) corner.className = cssClass;
	if (imgClass){ img = top.document.createElement("IMG");
		img.src = top.clearImg; img.className = imgClass;	img.setAttribute("width",0); img.setAttribute("height",0); img.setAttribute("border",0);
		corner.appendChild(img);
	}
	return corner;
}
live.prototype.spacer = function(){
	this.spacerTD = top.document.createElement("TD");
	this.spacerTD.className = "pz";
	return this.spacerTD;
}
live.prototype.analyse = function(parentTagName,node){
	var hasValue = (node.childNodes[0] && node.childNodes[0].nodeValue)? true : false;
	switch(node.nodeName.toLowerCase()){
		case "news" : 
			this.newLive();
			var icon = ""; var txt = "";
			if(node.getAttribute("type")){
			this.liveType = node.getAttribute("type");
				switch (node.getAttribute("type")){
					case "0" : icon = "web"; break;
					case "1" : icon = "vote"; txt = top._votedfor; break;
					case "3" : icon = "article"; txt = top._published; break;
				}
			}
			if(node.getAttribute("date")) this.mainTr.setAttribute("date",node.getAttribute("date"));
			if(node.getAttribute("author")){
				if(node.getAttribute("authorid")){
					voterLink = top.document.createElement("A"); voterLink.className = "info normal s1";
					voterLink.href = "/user"+node.getAttribute("authorid");
					voterLink.appendChild(top.document.createTextNode(node.getAttribute("author")));
					this.prez.appendChild(voterLink);
				}
				else this.prez.appendChild(top.document.createTextNode(node.getAttribute("author")));
				this.prez.appendChild(top.document.createTextNode(txt));
				this.prez.style.backgroundImage = "url(/shared/gui/live/"+icon+".gif)";
				this.prez.style.display = ""; this.sprez.style.display = "";
			}
			else if(node.getAttribute("capture")){
				this.prez.appendChild(top.document.createTextNode(node.getAttribute("capture")));
				this.prez.style.backgroundImage = "url(/shared/gui/live/"+icon+".gif)";
				this.prez.style.display = ""; this.sprez.style.display = "";
			}
			else if(node.getAttribute("type") == 1){
				this.prez.appendChild(top.document.createTextNode(top._anonymous));
				this.prez.appendChild(top.document.createTextNode(txt));
				this.prez.style.backgroundImage = "url(/shared/gui/live/"+icon+".gif)";
				this.prez.style.display = ""; this.sprez.style.display = "";
			}
		break;
		case "comment" : this.newComment();	break;
		case "liveid" : if(hasValue) top.liveid =  node.childNodes[0].nodeValue; break;
		case "id" : if(hasValue) this.id = node.childNodes[0].nodeValue; break;
		case "timestamp" :	if(hasValue) top.livets = node.childNodes[0].nodeValue; break;
		case "refresh" : if(hasValue) this.refreshPeriod =  node.childNodes[0].nodeValue; break;
		case "url" : if(hasValue) this.url =  node.childNodes[0].nodeValue; break;
		case "sitename" : if(hasValue) this.siteName = node.childNodes[0].nodeValue; break;
		case "author" : if(hasValue) this.author =  node.childNodes[0].nodeValue; break;
		case "date" : if(hasValue) this.date =  node.childNodes[0].nodeValue; break;
		case "catidx" : this.catidx = (hasValue)? node.childNodes[0].nodeValue : "u"; break;
		case "poll" : 
		this.pollNote.appendChild(top.document.createTextNode(node.childNodes[0].nodeValue));
		this.pollNote.note = node.childNodes[0].nodeValue;
		this.pollNote.className = "note n"+this.catidx;
		this.pollNote.id = "sc"+this.id;
		if(node.getAttribute("voted") && node.getAttribute("voted") == "true") {
			this.pollVote.appendChild(top.document.createTextNode(top._hasvoted));
			this.pollVote.className = "vote v"+this.catidx+"1";
			this.pollNote.vote = false;
		}
		else{
			this.pollVote.appendChild(top.document.createTextNode(top._dovote));
			this.pollVote.className = "vote v"+this.catidx; this.pollVote.tgtid = this.id; this.pollVote.obj = this;
			this.pollVote.vote = true; this.pollVote.note = node.childNodes[0].nodeValue;
			if(window.attachEvent){this.pollVote.attachEvent("onclick",top.vote,true);}
			else if(window.addEventListener){this.pollVote.addEventListener("click",top.vote,true);}	
		}
		break;
		case "image":
			if(node.childNodes[0]){
				this.image = top.document.createElement("IMG")
				this.image.src = node.childNodes[0].nodeValue; this.image.className = "newsimg bord"+this.catidx;
				if(this.image.getAttribute("width") && parseInt(this.image.getAttribute("width")) > 75){
					r = (75/parseInt(this.image.getAttribute("width")));
					this.image.style.width = "75px";
					if(this.image.getAttribute("width")) this.image.style.height = (parseInt(this.image.getAttribute("height"))* r)+"px";
				}
				this.image.title = "";
				if(this.siteName) this.image.title += " - "+this.siteName;
				if(this.author) this.image.title += " - "+this.author;
				}
				if(this.url){
					this.imageHref = top.document.createElement("A");
					this.imageHref.target = "_blank"; this.imageHref.href = this.url;
					this.imageHref.appendChild(this.image);
				}
			break;
			case "live": top.liveRefresh = (node.childNodes.length > 15)? 0 : 15;	break;
			case "title":
			if(hasValue){
				this.newsTitle = top.document.createElement("H2");
				this.newsTitleLink = top.document.createElement("A");
				if (this.url) this.newsTitleLink.href = this.url;
				this.newsTitleLink.className = "title "+this.catidx;	this.newsTitleLink.setAttribute("name","infotitle"); this.newsTitleLink.name = "infotitle"; this.newsTitleLink.target = "_blank";
				this.newsTitleLink.appendChild(top.document.createTextNode(node.childNodes[0].nodeValue));
				this.newsTitle.appendChild(this.newsTitleLink);
				this.insertTD.appendChild(this.newsTitle);
			}
			
			if(this.author || this.date){
				authorLine = top.document.createElement("TABLE"); setTable(authorLine);
				authorBody = top.document.createElement("TBODY");
				authorLine.appendChild(authorBody);
				this.authorTR = top.document.createElement("TR");
				authorBody.appendChild(this.authorTR);
				authorTD = top.document.createElement("TD");
				authorTD.className="baseline";
				this.authorTR.appendChild(authorTD);
				this.infoLine = top.document.createElement("H3");
				this.infoLine.className="author s1";
				if(this.author){
					this.infoSource = top.document.createElement("A");
					this.infoSource.className = "info normal s1";	this.infoSource.name = "infotext";
					this.infoSource.appendChild(top.document.createTextNode(this.author));
					this.infoLine.appendChild(this.infoSource);
				}
				if(this.date){
					this.infoDate = (this.author) ? top.document.createTextNode(" - "+this.date) :top.document.createTextNode(this.date);
					this.infoLine.appendChild(this.infoDate);
				}
				if(this.siteName && this.liveType == 0){
					this.infoSource = top.document.createTextNode(this.siteName+ " - ");
					this.infoLine.insertBefore(this.infoSource,this.infoLine.childNodes[0]);
				}
				authorTD.appendChild(this.infoLine);
				this.insertTD.appendChild(authorLine);
			}
			break;
			case "summary":
			var summary = "";
			for(i = 0 ; i < node.childNodes.length; i++) { if(node.childNodes[i].nodeType == 4) summary = node.childNodes[i].nodeValue;}
			if(summary.length > 0){
				this.sumUp = top.document.createElement("P");
				this.sumUp.className = "infotext";
				this.sumUp.innerHTML = this.parseSummary(summary,150);
				this.insertTD.appendChild(this.sumUp)
			}
			break;
			case "nfocomments":
			var nbComments = parseInt(node.getAttribute("posted"));
			cmdLine = top.document.createElement("TABLE"); setTable(cmdLine);
			cmdBody = top.document.createElement("TBODY");
			cmdLine.appendChild(cmdBody);
			this.cmdTR = top.document.createElement("TR");
			cmdBody.appendChild(this.cmdTR);
			this.commentTD = top.document.createElement("TD")
			this.commentTD.className = "comments"; this.commentTD.setAttribute("noWrap",true);
			this.comments = top.document.createElement("A");
			this.comments.href = "/comments?infoid="+this.id;this.comments.name = "infotext"; this.comments.className = "info "+this.catidx+" s1";
			this.commentTD.appendChild(this.comments);		
			var text = (nbComments && nbComments > 0)?" "+top._seelastcomments_before+ "+nbComments+" +top._seelastcomments_after : top._docomment;
			this.comments.appendChild(top.document.createTextNode(text));
			this.cmdTR.appendChild(this.commentTD);
			this.insertTD.appendChild(cmdLine)
			break;
			case "related":
			this.relatedTD = top.document.createElement("TD");
			this.relatedTD.className = "spaced sps s1";
			this.authorTR.appendChild(this.relatedTD);
			break;
			case "cauthor":
			this.commentAuthorDiv.className = "commentlive";
			this.commentAuthorDiv.style.backgroundImage = "url(/shared/gui/live/comment.gif)";
			if (node.getAttribute("id")){
				authorLink = top.document.createElement("A");
				authorLink.className = "info normal s1"; authorLink.href="/user"+node.getAttribute("id");
				authorLink.appendChild(top.document.createTextNode(node.childNodes[0].nodeValue+ " "+top._commented));
				this.commentAuthorDiv.appendChild(authorLink);
			}
			else { this.commentAuthorDiv.appendChild(top.document.createTextNode(node.childNodes[0].nodeValue));	}
			break;
			case "cdate":	if (hasValue) this.commentAuthorDiv.appendChild(top.document.createTextNode(" - "+node.childNodes[0].nodeValue));	break;
			case "infotitle":
			if (hasValue){
				titleTR = top.document.createElement("TR");
				titleTD = top.document.createElement("TD");
				titleTD.className = "commenttitle"; titleTD.style.width = "100%";
				titleTR.appendChild(titleTD);
				if (node.getAttribute("href")){
					titleLink = top.document.createElement("A");
					titleLink.className = "winfo"; titleLink.name="infotitle"; titleLink.href= node.getAttribute("href");
					titleLink.appendChild(top.document.createTextNode(node.childNodes[0].nodeValue));
					titleTD.appendChild(titleLink);
					titleSpan = top.document.createElement("SPAN"); titleSpan.style.fontWeight = "normal";
					titleSpan.appendChild(top.document.createTextNode("(voir l'article)"));
					titleTD.appendChild(titleSpan);
				}
				else { titleTD.appendChild(top.document.createTextNode(node.childNodes[0].nodeValue));	}
				this.iBubble.appendChild(titleTR);
				}
			break;
			case "infotxt":
			if (hasValue){
				txtTR = top.document.createElement("TR");
				txtTD = top.document.createElement("TD");
				txtTD.className = "commenttext"; txtTD.style.width = "100%";
				txtTR.appendChild(txtTD);
				txtTD.appendChild(top.document.createTextNode(node.childNodes[0].nodeValue));
				this.iBubble.appendChild(txtTR);
				}
			break;
			case "categ":
			if (this.categ) this.relatedTD.appendChild(top.document.createTextNode(", "));
			else this.relatedTD.appendChild(top.document.createTextNode("Tags : "));
			this.categ = top.document.createElement("A");
			this.categ.className = "info normal s1"; this.categ.name = "infotext"; this.categ.target = "_self";
			if(node.getAttribute("url")) this.categ.href = node.getAttribute("url");
			if (hasValue) this.categ.appendChild(top.document.createTextNode(node.childNodes[0].nodeValue));
			this.relatedTD.appendChild(this.categ);
			break;
			case "timer": top.alive = null; if (top.liveRefresh < 0 && node.childNodes[0].nodeValue) top.liveRefresh = node.childNodes[0].nodeValue; break;
		}
}
live.prototype.parseSummary = function(content,l){
	tmpNode = document.createElement("DIV");
	tmpNode.innerHTML = content;
	rsNode = document.createElement("DIV");
	for(tmp = 0; tmp < tmpNode.childNodes.length && rsNode.innerHTML.length < l; tmp++){
		remains = l - rsNode.innerHTML.length;
		tmpTxt = tmpNode.childNodes[tmp].nodeValue;
		if(tmpNode.childNodes[tmp].nodeType == 3){
			if (tmpTxt.indexOf(" ",150) > 0) rsNode.appendChild(document.createTextNode(tmpTxt.substring(0,tmpTxt.indexOf(" ",l))+ "..."));
			else rsNode.appendChild(document.createTextNode(tmpTxt));
		}
		else if(tmpNode.childNodes[tmp].nodeType == 1 && tmpNode.childNodes[tmp].nodeName== "A"){
			var cl = tmpNode.childNodes[tmp].cloneNode(true);
			rsNode.appendChild(cl);
		}
	}
	return rsNode.innerHTML;
}
live.prototype.send = function(){ top.liveIt();}
function setTable(e,w){	e.setAttribute("cellPadding","0");e.setAttribute("cellSpacing","0");e.setAttribute("border","0");	if (w) e.style.width = "100%";}