window.onload = function() {
	if( $('sidebar_left')){
		new PeriodicalExecuter(Timer, 5);
	}
	if( $('sidebar_left4')){
		new PeriodicalExecuter(Timer2, 5);
	}
}

var gImageId = '2';
var gImageId2 = '4';
var gActivatedMenu = 0;
var gPhone = 0;
var gFaq = 0;

function ShowPhone(id){
	var phone = $('phone'+id);
	var buy = $('buy');
	var btbuy = $('btbuy');
	if( phone){
		phone.src= "images/sphone"+id+".jpg";
		gPhone = id;
	}
	if( buy){
		buy.style.visibility = 'visible';
	}
	if( id==2){
		buy.href = 'http://www.orange.fr/bin/frame.cgi?u=http%3A//estore.orange.fr/stores/prospects/ma_selection.jhtml%3FpProcess%3DprocessTOF%26pTerminalProdId%3Dprod4700005%26pFormuleProdId%3Dprod4730002%26pFormuleSkuId%3Dsku4240002%26pDureeEngagement%3Dsku4240002%26pDirectCart%3Dtrue2/';
		btbuy.src = 'images/bt_buynow2.png';
	} else {
		buy.href = 'http://estore.orange.fr/stores/prospects/ma_selection.jhtml?pProcess=processTOF&pTerminalProdId=prod4700005&pFormuleProdId=prod4730002&pFormuleSkuId=sku4240002&pDureeEngagement=sku4240002&pDirectCart=true';
		btbuy.src = 'images/bt_buynow.png';
	}
	alert(btbuy.src);
}

function HidePhone(id){
	var activatePhone = $('phone'+id);
	if( activatePhone){ 
		activatePhone.src= "images/inactive_phone.jpg";
	}
}

function txtDisplayer( txt, cible){
	$(cible).innerHTML = txt;
}

function Timer() {
	$('sidebar_left').style.background = "url('images/preview_phone"+gImageId+".jpg')";
  $('sidebar_left').style.backgroundRepeat = "no-repeat";
  $('sidebar_left').style.backgroundPosition = "top";
  gImageId = (gImageId == '2') ? '1' : '2';
}
 
 function Timer2() {
	$('sidebar_left4').style.background = "url('images/preview_phone"+gImageId2+".jpg')";
  $('sidebar_left4').style.backgroundRepeat = "no-repeat";
  $('sidebar_left4').style.backgroundPosition = "top";
  gImageId2 = (gImageId2 == '3') ? '4' : '3';
}

function ShowMenu(id) {
	var menu = $('smenu'+id);
	if( menu != null){
		menu.style.display = 'block';
	}
	$('menu'+id).src='images/menu_'+id+'_hover.jpg';
	gActivatedMenu = id;
}

function showFAQ(id) {
	
	if( id != null){
		var menu1 = $('line_'+id);
		if($('line_'+gFaq)){
			var menu2 = $('line_'+gFaq);
			menu2.style.display = 'none';
		}
		menu1.style.display = 'block';
	}
	gFaq = id;
}

function HideMenu(currentMenu) {
	var menu = $('smenu'+gActivatedMenu);
	if( menu != null){ 
		menu.style.display = 'none';
	}
	if(currentMenu != gActivatedMenu){
		$('menu'+gActivatedMenu).src='images/menu_'+gActivatedMenu+'.jpg';
	}
	gActivatedMenu = 0;
}


function checkMail(){
	var fromName = $('fromname');
	var fromEmail = $('fromemail');
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]­{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

	if( fromName.value == ""){
		alert('Veuillez saisir votre prénom.');
		return false;
	}
	
	if( fromEmail.value == ""){
		alert('Veuillez saisir votre adresse email.');
		return false;
	}
	
	if( !reg.test( fromEmail.value)){
		alert('Votre adresse email est incorrecte.');
		return false;
	}
	return true;
}