function showHideSmileys() {
	var smileyDiv = document.getElementById("smileysDiv");
	var smileyLink = document.getElementById("smileysLink");
	if (smileyDiv && smileyDiv.style && smileyLink && smileyLink.innerHTML) {
		if (smileyDiv.style.display == "none") {
				smileyDiv.style.display = "block";
				smileyLink.innerHTML = js_MasquerSmileys;
		}
		else {
			smileyDiv.style.display = "none";
			smileyLink.innerHTML = js_VoirSmileys;
		}
	}
}

function addSmiley(smileyTxt) {
	var message = document.getElementById("message");
	if (message) {
		message.value = message.value+smileyTxt;
	}
}

image1 = new Image();
image1.src = '../images/icones/star_over.gif';
function replace(img_name,img_src){
	document[img_name].src=img_src;
}

/**
* This function is used when a visitor votes for a portrait.
* It is called on the 'onclick' event of the notes stars.
* It makes an Ajax call and then updates the info on the page.
* @param idPortrait (int)
* @param language (fr, en)
*/
function votePortrait(idPortrait, lang) {
	// This token is useful to force the ajax request not to use the browser's cache
	var token = randomString(8);
	var noteSpan = document.getElementById("noteText");
	try {
		if(texte = file(domainUrl+'/modules/ajax/note-portrait.php?lang='+lang+'&idPortrait='+idPortrait+'&token='+token)) {
			if(texte.indexOf(".php</b>")>0) {
				if (noteSpan) noteSpan.innerHTML = "<span class='error'>"+js_erreurNote+"</span>";
			}
			else {
				eval(texte);
				pause(10);
				if (confirmTxt!='' && newNbNotes!='' && newTextNote!='') {
					// Update text
					if (noteSpan)
						noteSpan.innerHTML = newTextNote+"<br /><span class='confirmation'>"+js_merciNote+"</span>";
					// Update star
					var	star = document.getElementById("star1");
					star.src = "../images/skins/common/star_off.gif";
					var linkStar = document.getElementById("linkStar1");
					linkStar.title = newTextNote;
					linkStar.onmouseover = "";
					linkStar.onmouseout = "";
					linkStar.onclick = "";
					
				}
				else if (error!='') {
					if (noteSpan) noteSpan.innerHTML = "<span class='error'>"+js_erreurNote+"</span>";
				}

			}
			aVote(idPortrait);
		}
	} catch(exception) {
			if (noteSpan) noteSpan.innerHTML = "<span class='error'>"+js_erreurNote+"</span>";
	}
}

function pause(millis) {
	date = new Date();
	var curDate = null;
	
	do { var curDate = new Date(); } 
	while(curDate-date < millis);
} 

var haveClicked = false;

function replyComment(idComment, text) {
	// Set hidden field
	document.getElementById("reply").value = idComment;
	
	// Remove old Reply style
	var commentsDiv = document.getElementById("commentsDiv");
	if (commentsDiv) {
		for (var i=0; i<commentsDiv.childNodes.length; i++) {
			if (commentsDiv.childNodes[i].className=="commentaireReply") {
				commentsDiv.childNodes[i].className="commentairePortrait";
				break;
			}
		}
	}
	// Set new Reply style
	document.getElementById("comment-"+idComment).className = "commentaireReply";
	
	// Add text to form
	document.getElementById("textReply").innerHTML = text;
	
	// Move form
	var newPosition = document.getElementById("comment-"+idComment).offsetTop;
	if (newPosition==-1 && !haveClicked) {
		haveClicked = true;
		setTimeout('document.getElementById("replyLink-'+idComment+'").click()',1);
	}
	
	//var windowTopOffset = document.body.scrollTop;
	var commentFormDiv = document.getElementById("commentFormDiv");
	
	if (newPosition > document.getElementById("commentFormDiv").offsetTop) 
		direction = 1;
	else direction = -1;
	moveDiv("commentFormDiv",direction,newPosition);
}

function cancelReply() {
	// Set hidden field
	document.getElementById("reply").value = "";
	
	// Remove old Reply style
	var commentsDiv = document.getElementById("commentsDiv");
	if (commentsDiv) {
		for (var i=0; i<commentsDiv.childNodes.length; i++) {
			if (commentsDiv.childNodes[i].className=="commentaireReply") {
				commentsDiv.childNodes[i].className="commentairePortrait";
				break;
			}
		}
	}
	
	// Remove text to form
	document.getElementById("textReply").innerHTML = "";
	
	// Move form
	var commentFormDiv = document.getElementById("commentFormDiv");
	commentFormDiv.style.top="0px";
	//moveDiv("commentFormDiv",-1,0);
	
}

/*function moveDiv(divId, direction, endOffsetTop) {
	var curOffset = document.getElementById(divId).offsetTop;
	document.getElementById(divId).style.top = curOffset+(direction*25);
	
	if (direction==1 && curOffset<endOffsetTop) {
		setTimeout("moveDiv('"+divId+"',1,"+endOffsetTop+")",30);
	}
	else if (direction==-1 && curOffset>endOffsetTop) {
		setTimeout("moveDiv('"+divId+"',-1,"+endOffsetTop+")",30);
	}
}*/

function moveDiv(divId, direction, endOffsetTop) {
	document.getElementById(divId).style.top = endOffsetTop;
}

/**
* The "reply" links are displayed near each comment on the portrait.
* If the visitor is not logged, the page will call this function in order to hide the "reply" link.
* It walks for all the "a" nodes and puts a display:none on all those nodes having id starting with "replyLink-"
*/
function hideReplyLinks() {
	var linkArrays = document.getElementsByTagName("a");
	var length=linkArrays.length;
	for (var i=0;i<length;i++) {
		var a = linkArrays[i];
		if (a && a.id && a.id.length>10 && a.id.substring(0,10)=="replyLink-") {
			a.style.display="none";
		}
	}
}













