function varToEmail(){
	var vAr = document.getElementsByTagName('var');
	var len = vAr.length;
	for (var i=0 ; i < len ; i++){
		var content = vAr[i].innerHTML.split(",");
		var email = "";
		if(content.length == 3){
			email = stripSpaces(content[0]) + "@" + stripSpaces(content[1]) + "." + stripSpaces(content[2]);
			
		}
		vAr[i].innerHTML = "<a href='mailto:"+ email +"'>" + email + "</a>";
	}
}
function stripSpaces(myString){
	var expr = new RegExp(/^\s*(.+)\s*$/i);
	expr.exec( myString );
	return RegExp.lastParen;
}
function popup(){
	var url = this.href;    
	window.open(url, 'popup', 'directories=0,resizable=1,scrollbars=yes,location=0,menubar=0,status=0,toolbar=0,top=0,left=0,width=800,height=450');
	return ( false );
}

function linkToPopup(){
	var link = document.getElementById("sendFriendLink");
	if(link){
		link.onclick=popup;
		
		
	}
}
function initFormFocus(){
	var inputs = document.getElementsByTagName("input");
	var textareas = document.getElementsByTagName("textarea");
	var myCollection = new Array();
	for(var i=0 ; i< inputs.length ; i++){
		if( inputs[i].type.toLowerCase() == "text" ){
			myCollection.push(inputs[i]);
		}
	}
	for(var i=0 ; i< textareas.length ; i++){
			myCollection.push(textareas[i]);
	}
	for(var i=0 ; i< myCollection.length ; i++){
			myCollection[i].oldBg = myCollection[i].style.backgroundColor;
			myCollection[i].onblur=removeFocus;
			myCollection[i].onfocus=setFocus;
	}
}


var colorFocus = "#cfe1ff";
function removeFocus(){
	this.style.backgroundColor = this.oldBg;
	this.className=this.className.replace("notValid","");
}
function setFocus(){
	this.style.backgroundColor = colorFocus;
}

function checkEmailRegex(email) {
   var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/i;
   return (reg.exec(email)!=null)
}
function overline(item){
	item.className = item.className + " notValid";
}


function checkFormByCSS(f){
	var returnValue=true;
	var e = f.elements;
	for(var i = 0 ; i < e.length ; i++){
		var item = e[i];
		item.className=item.className.replace("notValid", "");
		var notNull = item.className.match("checkNotNull");
		var email = item.className.match("checkMail");
		if	(notNull || email){
			var value;
			try{
				value = item.value;
				}catch(er){}
			if(value == undefined && item.innerHTML){
				value = item.innerHTML;
			}
			value = stripSpaces(value);
				if (
					notNull && value.match(/^\s*$/gi)
					|| email &&  !checkEmailRegex(value)
					)
					{
						overline(item);
						returnValue=false;
					}
			
			
			
		}
	}
	if(!returnValue) document.getElementById("alert").style.visibility="visible";
	return returnValue;
}







function addToFavorites() {	
	var url="http://www.changetavoix.com";
	var titre="ChangeTaVoix";
	if (navigator.appName != 'Microsoft Internet Explorer' ) {
		window.sidebar.addPanel(titre,url,'');
	} else {
		window.external.AddFavorite(url, titre);
	}
}

function initFavorites(){
	var bt = document.getElementById("addFavorites");
	if(bt){
		bt.onclick = addToFavorites;
	}
}











function init(){
	linkToPopup();
	varToEmail();
	initFormFocus();
	initFavorites();
}
window.onload = init;
