/*---------------------------------------------------------------------------------------------------
$ // Raccourci pour avoir document.getElementById
---------------------------------------------------------------------------------------------------*/
function $(id){
	return document.getElementById(id);
}


/*---------------------------------------------------------------------------------------------------
createLinkToThisPost
---------------------------------------------------------------------------------------------------*/
function createLinkToThisPost(){
	var permaLink = document.URL;
	var title = document.title; 
	html = "";
	html += "<p class='linktext'><b>Link to this post...</b><br/>If you found this page useful, consider linking to it. <br />Simply copy and paste the code below into your web site (<code>Ctrl</code>+<code>C</code> to copy)<br />It will look like this: <a href='"+permaLink+"'>"+title+"</a></p>";
	html += "<p><textarea cols='60' rows='3' class='linktextarea' onmouseover='this.focus()' onfocus='this.select()' onclick='this.select()'>&lt;a href=&quot;"+permaLink+"&quot;&gt;"+title+"&lt;/a&gt;</textarea></p>";
	$('linkToThisPost').innerHTML = html;
}

/*---------------------------------------------------------------------------------------------------
Verification des champs
---------------------------------------------------------------------------------------------------*/
function checkField(field){

	var valueToCheck = field.value;
	var checkIt="" + valueToCheck;
	if (checkIt!=""){
		for(var y = 0; y < checkIt.length;y++){
			var char = checkIt.substring(y,y+1);
				if(char != ''){
					return true;
				}
		}
	}
	return false;
}

/*---------------------------------------------------------------------------------------------------
Verification du mail
---------------------------------------------------------------------------------------------------*/
function checkEmail(email){
	with (email)
	{
	apos=value.indexOf("@")
	dotpos=value.lastIndexOf(".")
	if (apos<1||dotpos-apos<2||value.charAt(dotpos+2)==''){
		//alert(value.charAt(dotpos+2));
		return false;
	}
	else {return true}
	}
}

/*---------------------------------------------------------------------------------------------------
Verification des champs du formulaire
---------------------------------------------------------------------------------------------------*/
function checkForm(){
	var error = '';

	if (!checkField($('comment'))) {

		error = 'comment';
	}else{
		changeClass($('comment'),"inputRequired","inputValid");
	}

	if (!checkEmail($('email'))) {

		error = 'email';
	}else{
		changeClass($('email'),"inputRequired","inputValid");
	}
	
	if (!checkField($('author'))) {
		error = 'author';
	}else{
		changeClass($('author'),"inputRequired","inputValid");
	}
	
	if (error !=''){
		changeClass($(error),"inputValid","inputRequired");
		return false;
	}else{
		return true;	
	}
	
}

/*---------------------------------------------------------------------------------------------------
changeClass // Change une classe en une autre classe
---------------------------------------------------------------------------------------------------*/
function changeClass(el,startClass,endClass) {
	//alert('el: '+el+', class:'+startClass+', newClass:'+endClass);
	var classNameString = el.className;
	var newClassName = classNameString.replace(startClass,endClass);
	el.className = newClassName;
}


/*---------------------------------------------------------------------------------------------------
addLoadEvent // Ajoute une fonction à la liste de fonction à executé lors de l'événement onload
---------------------------------------------------------------------------------------------------*/
/*function addToFavorite() { 

	url = "http://www.canpages.ca/blog/"; 
	var title = "Canpages Blog"; 
	
if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}*/
