function isIE6() {
	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
	return strChMid.indexOf("MSIE 6") != -1 ? 1 : 0;
}
var ie6 = isIE6();

function ShowHide(id) {
	document.getElementById(id).style.display = document.getElementById(id).style.display == 'block'?'none':'block';
}

/*
Prime : No Flash is currently available
*/

/*
Normal : No Flash is currently available
*/
function showHideFlash(args) {
	//		var time = 0;
	//		if(millis != NULL)
	//			time = millis;
	if(args!='flash_promo-ete-2008-2'){
		document.getElementById(args).style.display = 'none';
	}else{
		if(document.getElementById('flash_promo-ete-2008-2').style.visibility = 'hidden') {
//			document.getElementById('flash_promo-ete-2008-2').style.visibility = 'visible';
			HideSelect();
		} else {
//			sleep(time);
//			document.getElementById('flash_promo-ete-2008-2').style.visibility = 'hidden';
			ShowSelect();
		}
	}
}
function showFlash() {
	document.getElementById('flash_promo-ete-2008-2').style.marginTop = '113px';
}
function activateFlash() {
	document.getElementById('flash_promo-ete-2008-2').style.visibility = 'visible';
}
function deactivateFlash() {
	document.getElementById('flash_promo-ete-2008-2').style.visibility = 'hidden';
}

function hideFlash() {
	document.getElementById('flash_promo-ete-2008-2').style.marginTop = '-4000px';
}
hideSelect = function() {
	if(ie6 == 1) {
		oSelects = document.getElementsByTagName('SELECT');
		if (oSelects.length > 0) {
			for (i = 0; i < oSelects.length; i++) {
				oSelects[i].style.visibility = 'hidden';
			}
		}
	}
}
showSelect = function() {
	if(ie6 == 1) {
		oSelects = document.getElementsByTagName('SELECT');
		if (oSelects.length > 0) {
			for (i = 0; i < oSelects.length; i++) {
				oSelects[i].style.visibility = 'visible';
			}
		}
	}
}
function isIE6() {
	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
	return strChMid.indexOf("MSIE 6") != -1 ? 1 : 0;
}

function recupAnimation( pAnim ) {
	if (navigator.appName.indexOf("Microsoft") != -1)
		return window[pAnim];
	return document[pAnim];
}
function declencheFonctionActionScript ( )
{
	recupAnimation("anim01").isIE6();
}

function ShowHide(id) {
	document.getElementById(id).style.display = document.getElementById(id).style.display == 'block'?'none':'block';
}

function ShowHideRame(id1,id2) {
	document.getElementById(id1).style.display = "block";
	document.getElementById(id2).style.display = "none";
	if(document.getElementById('nouvelle_rames').style.display =="block"){
		document.getElementById('onglets').className = "left_actif";
	}else{
		document.getElementById('onglets').className = "right_actif";
	}
}
/*
Prime : No Flash is currently available
*/

/*
Normal : No Flash is currently available
*/

function run_adflash(path, width, height, lang, country, dns, time) {
	document.write('<object type="application/x-shockwave-flash"');
	document.write(' data="'+path+'"');
	document.write(' width="'+width+'" height="'+height+'">\n\t');
	document.write('<param name="movie" value="'+path+'" />\n\t');
	document.write('<param name="flashvars" value="lg='+lang+'&country='+country+'&dns='+dns+'" />');
	//	document.write('<param name=\"flashvars\" value=\"time="+time+"\" />'");
	document.write('<param name="wmode" value="transparent" />');
	document.write('</object>');
}

function printPage(){
	window.print();
}
function openPopUp() {
	msgWindow = window.open (arguments[0], "window1", "toolbar=1,menubar=no,height=" + arguments[2] + ",width=" + arguments[1] + ",status=no,resizable=no,location=no,directories=no,scrollbars=no");
}


function isArray(variable)
{
	return variable instanceof Array;
}

function emptyArray(a, len)
{
	for (var i = 0; i <= len; i++) {
		a[i] = null;
	}
	a.length = 0;
	return a;
}

function synchronizeStations(f,defaultTo)
{
	var selectValue;
	var optFrom = document.getElementById("fromstation").options;
	var optTo = document.getElementById("tostation").options;

	optTo = emptyArray(optTo, optTo.length);
	if(optFrom.selectedIndex >= 0) {
		fromStation = optFrom[optFrom.selectedIndex].value;
		toStations = stationsMap[fromStation];

		optIndex = 0;
//		opt = new Option(label_tostation, "");
		opt = new Option(utf8_decode (label_tostation), "");
		optTo[optIndex++] = opt;

		if(isArray(toStations))
		{
			if(toStations.length == 1) optIndex = 0;
			for (var i = 0; i < toStations.length; i++) {
				toStation = toStations[i];
//				alert(toStation);
				opt = new Option(stations[toStation], toStation);
				optTo[optIndex++] = opt;
				if (toStation == defaultTo) {
					optTo.selectedIndex = optIndex-1;
				}
			}
		}
	}

	if (document.getElementById("d_hidden")){
		var optTo	= document.getElementById("tostation").options;
		var dest	= document.getElementById("d_hidden").value;
		for(var i=0;i<optTo.length;i++){
			if (optTo[i].value == dest){
				optTo[i].setAttribute ("selected","selected");
				break;
			}
		}
	}
}

function synchronizeStationsSeason(f,defaultTo)
{
	if(document.getElementById("fromstationSeason"))
	{
		var selectValue;
		var optFrom = document.getElementById("fromstationSeason").options;
		var optTo = document.getElementById("tostationSeason").options;

		optTo = emptyArray(optTo, optTo.length);
		if(optFrom.selectedIndex >= 0) {
			fromStation = optFrom[optFrom.selectedIndex].value;
			toStations = booking_stationsMap[fromStation];

			optIndex = 0;
			//		opt = new Option(label_tostation, "");
			opt = new Option(utf8_decode (label_tostation), "");
			optTo[optIndex++] = opt;

			if(isArray(toStations))
			{
				if(toStations.length == 1) optIndex = 0;
				for (var i = 0; i < toStations.length; i++) {
					toStation = toStations[i];
					if(toStation == 'TGB')continue;
					//				 alert(toStation);
					opt = new Option(booking_stations[toStation], toStation);
					optTo[optIndex++] = opt;
					if (toStation == defaultTo) {
						optTo.selectedIndex = optIndex-1;
					}
				}
			}
		}

		if (document.getElementById("d_hidden")){
			var optTo	= document.getElementById("tostationSeason").options;
			var dest	= document.getElementById("d_hidden").value;
			for(var i=0;i<optTo.length;i++){
				if (optTo[i].value == dest){
					optTo[i].setAttribute ("selected","selected");
					break;
				}
			}
		}
	}
}


function showPrintButton(span_id){

	span = document.getElementById(span_id);
	code = '<a href="javascript:printPage()"><img src="'+th_IMG_DOMAIN_NAME+'/btn/impression.png"  alt="'+label_print+'" /></a>';

	span.innerHTML = code;

}

//conditions d'utilisation//
function showhidden(idshow,idhidden,idhidden2){
	document.getElementById(idshow+"_b").className = 'actif';
	document.getElementById(idshow+"_visu").style.display = 'block';
	document.getElementById(idshow).style.display = 'block';

	document.getElementById(idhidden+"_b").className = 'none';
	document.getElementById(idhidden+"_visu").style.display = 'none';
	document.getElementById(idhidden).style.display = 'none';
	if((idhidden2 != "_") && (idhidden2 != "") && ("undefined" != typeof(idhidden2))){
		document.getElementById(idhidden2+"_b").className = 'none';
		document.getElementById(idhidden2+"_visu").style.display = 'none';
		document.getElementById(idhidden2).style.display = 'none';
	}
}

function showhide(id)	{

	if (document.getElementById(id).style.display =="none") {
		document.getElementById(id).style.display = 'block';
	}
	else if (document.getElementById(id).style.display =="block") {
		document.getElementById(id).style.display = 'none';
	}
}

function showhidewifi(btn,id)	{

	if (document.getElementById(id).style.display =="none") {
		document.getElementById(id).style.display = 'block';
		document.getElementById(btn).style.backgroundPosition = '0px -26px';
	}
	else if (document.getElementById(id).style.display =="block") {
		document.getElementById(id).style.display = 'none';
		document.getElementById(btn).style.backgroundPosition = 'left top';
	}
}
/***** A SOLUTIONNER AUTREMENT *****/

function IE_CorrectAlpha_PNG(){
	for(i=0; i<document.images.length; i++){
		img    = document.images[i];
		imgExt  = img.src.substring(img.src.length-3, img.src.length);
		imgExt  = imgExt.toUpperCase();
		if (imgExt == "PNG"){
			if(img.id == 'onglet_right' || img.id == 'onglet_left') {
				imgID    = (img.id) ? "id='" + img.id + "' " : "";
				imgClass= (img.className) ? "class='" + img.className + "' " : "";
				imgTitle= (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				imgStyle= "display:inline-block;" + img.style.cssText;
				if (img.align == "left") { imgStyle = "float:left;"  + imgStyle; } else if (img.align == "right"){ imgStyle = "float:right;" + imgStyle; }
				if (img.parentElement.href)   { imgStyle = "cursor:hand;" + imgStyle; }
				strNewHTML    = '<span '+imgID+imgClass+imgTitle+' style="width:'+img.width+'px; height:'+img.height+'px;'+imgStyle+';'+'filter:  progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+img.src+'\', sizingMethod=\'scale\')"></span>';
				img.outerHTML = strNewHTML;
				i = i-1;
			}
		}
	}
}
var userAgent=navigator.userAgent;
if (userAgent.indexOf('MSIE') != -1) {
	window.attachEvent("onload", IE_CorrectAlpha_PNG);
}
/***********************************/

function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray = versionStr.split(" "); // ["WIN", "2,0,0,11"]
			tempString = tempArray[1]; // "2,0,0,11"
			versionArray = tempString.split(","); // ['2', '0', '0', '11']
		} else { versionArray = versionStr.split(".");
		}
		var versionMajor = versionArray[0];
		var versionMinor = versionArray[1];
		var versionRevision = versionArray[2];

		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
			return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
				return true;
			}
		}
		return false;
	}
}
function detectFlashVerDisplay(flash, largeur, hauteur, langue ,pays, time) {
	var hasReqestedVersion= DetectFlashVer(9, 0, 28);
	if (hasReqestedVersion) {
		// EMBED the SWF
		run_adflash (flash, largeur, hauteur, langue, pays, time);
		return true;
	} else {
		// Instruct the user to install the player, start Player Product Install,
		// or show alternate content
		return false;
	}

}



function redimBkg(){




	var screenHeight	=	alertSize();

	if(document.getElementById("bkg").offsetHeight<screenHeight)
	document.getElementById("bkg").style.height = screenHeight+"px";

}

function alertSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}


function synchroDateOD(jour,mois,annee,quit){
	if(selName=="date_trip_dispo_ret"){
		addToInput(jour, mois, annee, quit);
		return true;
	}
	lien = document.getElementById("a_date_trip_dispo_ret");
	input = document.getElementById("date_trip_dispo_ret");

	href = lien.href;
	expression = new RegExp("showcalendar\((.*)\)","i");
	result = expression.exec(href);
	if(result[1]) result = result[1];
	else result = "";
	if(result.substr(0,1)=="(")result = result.substr(1,result.length-1);
	if(result.substr(result.length-1,1)==")")result = result.substr(0,result.length-1);
	result = result.split(",");

	var jour2 = jour;
	var mois2 = mois + 1;
	if(jour<10) jour2 = "0" + jour;
	if(mois2<10) mois2 = "0" + mois2;


	nouvelle_date = jour2 + "/" + mois2 + "/" + annee;
	ancienne_date = input.value;
	if(ancienne_date!=""){
		utc_new = Date.UTC(nouvelle_date.substr(6,4),nouvelle_date.substr(3,2),nouvelle_date.substr(0,2));
		utc_old = Date.UTC(ancienne_date.substr(6,4),ancienne_date.substr(3,2),ancienne_date.substr(0,2));
		if(utc_old<utc_new)input.value= nouvelle_date;
	}
	var fonction = "showCalendar(";
	for (var i in result){
		if(typeof(result[i]) == 'function') continue;
		if(i!=7) fonction=fonction + result[i] + ",";
		else fonction=fonction + "'"+ nouvelle_date + "',";
	}
	if(fonction.substr(fonction.length-1,1)==",")fonction = fonction.substr(0,fonction.length-1);

	fonction += ')';

	lien.href = "javascript:"+fonction;

	addToInput(jour, mois, annee, quit);
}

function dispoUpdateDate(){
	date1 = document.getElementById("date_trip_dispo").value;
	date2 = document.getElementById("date_trip_dispo_ret").value;

	expression = new RegExp("^([0-9]{2})/([0-9]{2})/([0-9]{4}$)","i");

	if(expression.test(date1)){
		result = expression.exec(date1);
		document.getElementById("input_date_trip_dispo_day").value = result[1];
		document.getElementById("input_date_trip_dispo_month").value = result[2];
		document.getElementById("input_date_trip_dispo_year").value = result[3];
	}


	if(expression.test(date2)){
		result = expression.exec(date2);
		document.getElementById("input_date_trip_dispo_ret_day").value = result[1];
		document.getElementById("input_date_trip_dispo_ret_month").value = result[2];
		document.getElementById("input_date_trip_dispo_ret_year").value = result[3];
	}

	//document.getElementById("booking_reservation").submit();

}

switchFontSize = function(val){
	var body = document.getElementsByTagName('body')[0];
	var fontsize = document.getElementById('fontsize').value;
	if(fontsize == 'NaN') fontsize = 100;
	var newfs = fontsize;
	switch (val) {
		case 'more':
		if(fontsize == 130) {
			newfs = 130;
		} else {
			newfs = parseInt(fontsize)+10;
			body.style.fontSize = ''+newfs+'%';
		}
		break;
		case 'less':
		if(fontsize == 100) {
			newfs = 100;
		} else {
			newfs = parseInt(fontsize)-10;
			body.style.fontSize = ''+newfs+'%';
		}
		break;
		default:
		body.style.fontSize = '100%';
		newfs = 100;

	}
	document.getElementById('fontsize').value = newfs;
	if(newfs == 'NaN') newfs = 100;
	var da = new Date();
	var d = new Date( Date.parse(da) + ( 1000*60*60*24*365 ) );
	document.cookie = 'fontThalys' + '=' + newfs + ';expires=' + d.toGMTString() + ';path=/;' ;

}

function imageBankForm(){
	document.getElementById("inscription").style.display="block";
}

function formContactCheck(){

	var valid = true;

	//Verif du theme
	checked = false;
	if(document.getElementById("theme_internet")){
		themes = document.getElementsByName("theme");
		checked = false;
		for(i=0;i<themes.length;i++){
			if(themes[i].checked)checked = true;
		}
		//theme internet
		if(document.getElementById("theme_internet").checked==true){
			var sub = false;
			for(i=0;i<5;i++){
				if(document.getElementById("theme_internet"+i).checked==true)sub=true;
			}
		}
	}else{
		themes = document.getElementsByName("theme");
		checked = false;
		for(i=0;i<themes.length;i++){
			if(themes[i].checked)checked = true;
		}
	}



	//	else checked = true;
	if(checked == false){
		if(document.getElementById("div_theme").className!="border_red"){
			document.getElementById("div_theme").className="border_red";
			document.getElementById("span_error_theme").style.display="block";
		}
		valid = false;
	}
	else{
		document.getElementById("div_theme").className="";
		document.getElementById("span_error_theme").style.display="none";
	}
	if(document.getElementById("div_sous_theme")){
		if(sub == false){
			if(document.getElementById("div_sous_theme").className!="border_red"){
				document.getElementById("div_sous_theme").className="border_red";
				document.getElementById("error_sous_theme").style.display="block";
			}
			valid = false;
		}
		else{
			document.getElementById("div_sous_theme").className="";
			document.getElementById("error_sous_theme").style.display="none";
		}
	}

	//Concerne
	if(document.getElementById("for_concerne_1")){
		if(document.getElementById("for_concerne_1").checked==false && document.getElementById("for_concerne_2").checked==false){
			if(document.getElementById("div_concerne").className!="border_red"){
				document.getElementById("div_concerne").className="border_red";
				document.getElementById("error_concerne").style.display="block";
			}
			valid = false;
		}
		else{
			document.getElementById("div_concerne").className="";
			document.getElementById("error_concerne").style.display="none";
		}
	}

	//message
	if(document.getElementById("message_area")){
		if(document.getElementById("message_area").value==""){
			if(document.getElementById("message_area").className !="error_textarea"){
				document.getElementById("message_area").className ="error_textarea";
				document.getElementById("error_message_area").style.display="block";
			}
			valid = false;
		}
		else{
			document.getElementById("message_area").className ="";
			document.getElementById("error_message_area").style.display="none";
		}
	}

	//Coordonnées
	var select_salut = document.getElementById("for_salutations");
	var value = select_salut.options[select_salut.selectedIndex].value;

	if((value=="0" || value=="")){
		if(select_salut.className != "error_select"){
			document.getElementById("error_salutations").style.display="block";
			select_salut.className = "error_select";
		}
		valid = false;
	}
	else{
		document.getElementById("error_salutations").style.display="none";
		select_salut.className = "";
	}

	if(document.getElementById("for_nom").value==""){
		if(document.getElementById("for_nom").className!="error_input"){
			document.getElementById("for_nom").className="error_input";
			document.getElementById("error_nom").style.display="block";
		}
		valid = false;
	}
	else{
		document.getElementById("for_nom").className="";
		document.getElementById("error_nom").style.display="none";
	}

	if(document.getElementById("for_prenom").value==""){
		if(document.getElementById("for_prenom").className!="error_input"){
			document.getElementById("for_prenom").className="error_input";
			document.getElementById("error_prenom").style.display="block";
		}
		valid = false;
	}
	else{
		document.getElementById("for_prenom").className="";
		document.getElementById("error_prenom").style.display="none";
	}

	if(document.getElementById("for_adrmail").value==""){
		if(document.getElementById("for_adrmail").className!="error_input"){
			document.getElementById("for_adrmail").className="error_input";
			document.getElementById("error_email").style.display="block";
			document.getElementById("error_email_structure").style.display="none";
		}
		valid = false;
	}
	else{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{2,4})+$/;
    	if(filter.test(document.getElementById("for_adrmail").value)==false){
    		document.getElementById("for_adrmail").className="error_input";
			document.getElementById("error_email_structure").style.display="block";
			document.getElementById("error_email").style.display="none";
			valid = false;
    	}
    	else{
			document.getElementById("for_adrmail").className="";
			document.getElementById("error_email").style.display="none";
			document.getElementById("error_email_structure").style.display="none";
    	}
	}
	if(valid){
		if(document.getElementById("choixtheme")){
			document.getElementById("choixtheme").submit();
		}
		if(document.getElementById("infowifi")){
			document.getElementById("infowifi").submit();
		}

	}
	else{
		setTitleError();
		return false;
	}
}

function verifEmailSyntax(email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{2,4})$/;
	return filter.test(email);
}

function insertAfter(new_node, existing_node) {
	// if the existing node has a following sibling, insert the current
	// node before it. otherwise appending it to the parent node
	// will correctly place it just after the existing node.

	if (existing_node.nextSibling) {
		// there is a next sibling. insert before it using the mutual
		// parent's insertBefore() method.
		existing_node.parentNode.insertBefore(new_node, existing_node.nextSibling);
	} else {
		// there is no next sibling. append to the end of the parent's
		// node list.
		existing_node.parentNode.appendChild(new_node);
	}

} // insertAfter()


function setTitleError(){
	var title = document.title;
	var regexp = new RegExp (label_error_title,"i");
	if(! regexp.test(title)){
		document.title = document.title + " - "+label_error_title;
	}
}


function utf8_decode ( str_data ) {
	// http://kevin.vanzonneveld.net
	// +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
	// +      input by: Aman Gupta
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: Norman "zEh" Fuchs
	// +   bugfixed by: hitwork
	// +   bugfixed by: Onno Marsman
	// *     example 1: utf8_decode('Kevin van Zonneveld');
	// *     returns 1: 'Kevin van Zonneveld'

	var tmp_arr = [], i = ac = c1 = c2 = c3 = 0;

	str_data += '';

	while ( i < str_data.length ) {
		c1 = str_data.charCodeAt(i);
		if (c1 < 128) {
			tmp_arr[ac++] = String.fromCharCode(c1);
			i++;
		} else if ((c1 > 191) && (c1 < 224)) {
			c2 = str_data.charCodeAt(i+1);
			tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
			i += 2;
		} else {
			c2 = str_data.charCodeAt(i+1);
			c3 = str_data.charCodeAt(i+2);
			tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}
	}

	return tmp_arr.join('');
}

function trim (myString){
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
}

function in_array(needle,haystack){
	for (var i=0;i<haystack.length;i++){
		if (needle == haystack[i]){
			return true;
		}
	}
	return false;
}

function addRemoveCorresp (arg){
	if (arg == "del"){
		if (count > init_count){
			document.getElementById("nom_"+count).style.display = "none";
			document.getElementById("mail_"+count).style.display = "none";
			document.getElementById("br_"+count).style.display = "none";
			count--;
		}
	}
	if (arg == "add"){
		if (parseInt(count) < 16){

			count++;
			document.getElementById("nom_"+count).style.display = "block";
			document.getElementById("mail_"+count).style.display = "block";
			document.getElementById("br_"+count).style.display = "block";
		}
	}
}

function hideCorresp (){
	for (var i=(count+1);i<=16;i++){
		document.getElementById("nom_"+i).style.display = "none";
		document.getElementById("mail_"+i).style.display = "none";
		document.getElementById("br_"+i).style.display = "none";
	}
}

function checkFormSendToFriends (){
	var valid = true;
	var sendname = document.getElementById("sendname");
	var sendmail = document.getElementById("sendmail");
	var message  = document.getElementById("message");

	var span = document.createElement("span");
	span.className = "error";
	span.innerHTML = labelChampsOblig;

	/*********TRAITEMENT sendName **************/
	if (sendname.value == ""){
		valid = false;
		var span = document.createElement("span");
		span.className = "error";
		span.innerHTML = labelChampsOblig;
		span.id = "span_sendname";
		if (!document.getElementById("span_sendname")){
			sendname.parentNode.insertBefore (span,sendname);
		}
		sendname.className = "error_input";
	}
	else{
		if (document.getElementById("span_sendname")){
			sendname.parentNode.removeChild(document.getElementById("span_sendname"));
		}
		sendname.className = "";
		sendname.value = trim (sendname.value);
	}
	/*********TRAITEMENT sendMail **************/
	if (sendmail.value == ""){
		if (document.getElementById("span_sendmail")){
			sendmail.parentNode.removeChild(document.getElementById("span_sendmail"));
		}
		valid = false;
		var span = document.createElement("span");
		span.className = "error";
		span.innerHTML = labelChampsOblig;
		span.id = "span_sendmail";
		if (!document.getElementById("span_sendmail")){
			sendmail.parentNode.insertBefore (span,sendmail);
		}
		sendmail.className = "error_input";
	}
	else{
		if (document.getElementById("span_sendmail")){
			sendmail.parentNode.removeChild(document.getElementById("span_sendmail"));
		}
		sendmail.value = trim (sendmail.value).toLowerCase();
		if (!verifEmailSyntax(sendmail.value)){
			valid = false;
			var span = document.createElement("span");
			span.className = "error";
			span.innerHTML = labelEmailInvalid;
			span.id = "span_sendmail";
			if (!document.getElementById("span_sendmail")){
				sendmail.parentNode.insertBefore (span,sendmail);
			}
			sendmail.className = "error_input";
		}
		else{
			if (document.getElementById("span_sendmail")){
				sendmail.parentNode.removeChild(document.getElementById("span_sendmail"));
			}
			sendmail.className = "";
		}
	}
	/*********TRAITEMENT Message **************/
	if (message.value == ""){
		valid = false;
		var span = document.createElement("span");
		span.className = "error";
		span.innerHTML = labelChampsOblig;
		span.id = "span_message";
		if (!document.getElementById("span_message")){
			message.parentNode.insertBefore (span,message);
		}
		message.className = "error_input";
	}
	else{
		if (document.getElementById("span_message")){
			message.parentNode.removeChild(document.getElementById("span_message"));
		}
		message.className = "";
		message.value = trim (message.value);
	}
	/*********TRAITEMENT Destinataire **************/
	for (var i=1; i<= 16;i++){
		var name = document.getElementById("destname_"+i);
		var mail = document.getElementById("destmail_"+i);

		if (i== 1 || name.value != "" || mail.value != ""){
			if (name.value == ""){
				valid = false;
				var span = document.createElement("span");
				span.className = "error";
				span.innerHTML = labelChampsOblig;
				span.id = "span_destname_"+i;
				if (!document.getElementById("span_destname_"+i)){
					name.parentNode.insertBefore (span,name);
				}
				name.className = "error_input";
			}
			else{
				if (document.getElementById("span_destname_"+i)){
					name.parentNode.removeChild(document.getElementById("span_destname_"+i));
				}
				name.className = "";
				name.value = trim (name.value);
			}

			if (mail.value == ""){
				if (document.getElementById("span_sendmail_"+i)){
					mail.parentNode.removeChild(document.getElementById("span_sendmail_"+i));
				}
				valid = false;
				var span = document.createElement("span");
				span.className = "error";
				span.innerHTML = labelChampsOblig;
				span.id = "span_sendmail_"+i;
				if (!document.getElementById("span_sendmail_"+i)){
					mail.parentNode.insertBefore (span,mail);
				}
				mail.className = "error_input";
			}
			else{
				if (document.getElementById("span_sendmail_"+i)){
					mail.parentNode.removeChild(document.getElementById("span_sendmail_"+i));
				}
				mail.value = trim(mail.value).toLowerCase();
				if (!verifEmailSyntax(mail.value)){
					valid = false;
					var span = document.createElement("span");
					span.className = "error";
					span.innerHTML = labelEmailInvalid;
					span.id = "span_sendmail_"+i;
					if (!document.getElementById("span_sendmail_"+i)){
						mail.parentNode.insertBefore (span,mail);
					}
					mail.className = "error_input";
				}
				else{
					if (document.getElementById("span_sendmail_"+i)){
						mail.parentNode.removeChild(document.getElementById("span_sendmail_"+i));
					}
					mail.className = "";
					mail.value = trim (mail.value);
				}
			}
		}
		else{
			if (document.getElementById("span_destname_"+i)){
				name.parentNode.removeChild(document.getElementById("span_destname_"+i));
			}
			name.className = "";
			if (document.getElementById("span_sendmail_"+i)){
				mail.parentNode.removeChild(document.getElementById("span_sendmail_"+i));
			}
			mail.className = "";
			continue;
		}

	}


	return valid;
}


function wichNavigator (){
	if(navigator.appName == "Microsoft Internet Explorer"){
		return "IE";
	}
	else{
		return "OTHERS";
	}
}


function showCorrespondance(args){
	if(args == 'avant'){
		document.getElementById('avant_coresp').style.display = 'block';
		document.getElementById('apres_coresp').style.display = 'none';
		document.getElementById('onglet_modi').className = 'avant';
	}else{
		document.getElementById('avant_coresp').style.display = 'none';
		document.getElementById('apres_coresp').style.display = 'block';
		document.getElementById('onglet_modi').className = 'apres';
	}
}

function afficheBankAccount(){
	var mode2 = document.getElementById("mode_2");

	if (mode2.checked == true){
		document.getElementById("div_bank_account").style.display = 'block';
	}
	else{
		document.getElementById("div_bank_account").style.display = 'none';
	}
}

newwindow=false;
function popitup(url,width, height, scrollbars) {
	if(scrollbars == ''){
		scrollbars = 0;
	}

	if(newwindow!=false)newwindow.close();
	newwindow=window.open(url,'name','height='+height+',width='+width+',scrollbars='+scrollbars);
	if (window.focus) {newwindow.focus()}
	return false;
}


function alertTaille(type) {

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}


	if(type == 'height'){
		return pageHeight;
	}else{
		return pageWidth;
	}
}
function showModeEmploi(){
	updateSizeFlash();
	calculateTop();
	if(ie6){
		$('switch_country').style.display = 'none';
	}
	$('bkg_flash').style.display = 'block';
	new Effect.Appear('bkg_flash', {
		duration: 0.7,
		from: 0,
		to: 0.6,
		afterFinish: function() {
			$('global_flash_mode_emploi').style.display = 'block';
		}
	});


}
function previewEcard2010(){
	updateSizeFlash();
	calculateTopEcard2010();
	if(ie6){
		$('switch_country').style.display = 'none';
	}
	$('bkg_flash').style.display = 'block';
	new Effect.Appear('bkg_flash', {
		duration: 0.7,
		from: 0,
		to: 0.6,
		afterFinish: function() {
			$('global_flash_mode_emploi').style.display = 'block';
		}
	});


}
function closeModeEmploi(){
	if(ie6){
		$('switch_country').style.display = 'inline';
	}
	$('global_flash_mode_emploi').style.display = 'none';
	$('bkg_flash').style.display = 'none';
	$('bkg_flash').style.opacity = '0.0';
	$('bkg_flash').style.filter = 'alpha(opacity=0)';
}
function updateSizeFlash(){
	myHeight = alertTaille('height')+'px';
	myWidth = alertTaille('width')+'px';
	$('bkg_flash').style.height = myHeight;
	$('bkg_flash').style.width = myWidth;
	$('global_flash_mode_emploi').style.height = myHeight;
	$('global_flash_mode_emploi').style.width = myWidth;

}
function calculateTop(){
	var arrayPageScroll = document.viewport.getScrollOffsets();
	var divTop = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	$('flash_mode_emploi').style.top = divTop+'px';
}
function calculateTopEcard2010(){
	var arrayPageScroll = document.viewport.getScrollOffsets();
	var divTop = arrayPageScroll[1] + (document.viewport.getHeight() / 60);
	$('flash_mode_emploi').style.top = divTop+'px';
}
function btnValiderDisabled(){
	document.getElementById('btn_valider').disabled = true;
}

function ecoComparatorUpdateDest (){
	var orig = document.getElementById('ecoComparatorOrig').value;

	var url = basePathAbs+'?ajax=ecoComparatorUpdateDest';
	var param = "orig="+orig+"&lg="+langue;
	$('labelOdEcoComparator').innerHTML = "";
	$('ecoComparatorImgAir').style.display = "block";
	$('ecoComparatorTrain').morph("height:2px;");
	$('ecoComparatorCar').morph("height:2px;");
	$('ecoComparatorAir').morph("height:2px;");
	$('thalys_kg').innerHTML = "-";
	$('car_kg').innerHTML = "-";
	$('air_kg').innerHTML = "-";
	$('car_diff').innerHTML = "-";
	$('air_diff').innerHTML = "-";

	new Ajax.Request(url, {
		method: 'post',
		parameters: param,
		evalJS: 'force',
		asynchronous: true,
		onSuccess: function(transport) {
//			transport.responseText;
		}
	});
}

function emptySelect (what){
	if (document.getElementById(what)){
		var count = document.getElementById(what).options.length;
		count = count-1;
		for (var i=count; i>=0;i--){
			document.getElementById(what).options[i] = null;
		}
	}
}

function ecoComparatorUpdateGraph(){
	document.getElementById("ecoComparatorImgAjax").style.display = "block";
	var orig = document.getElementById("ecoComparatorOrig").value;
	var dest = document.getElementById("ecoComparatorDest").value;
	if (dest != ""){
		var label = labelEcoComparator.replace(/VilleOrigine/, $("ecoComparatorOrig").options[$("ecoComparatorOrig").selectedIndex].text);
		label = label.replace(/VilleArrivee/, $("ecoComparatorDest").options[$("ecoComparatorDest").selectedIndex].text);
		$('labelOdEcoComparator').innerHTML = label;

		var url = basePathAbs+'?ajax=ecoComparatorUpdateGraph';
		var param = "orig="+orig+"&dest="+dest;
		var baseMulti = 225/100;
		var train = ""; var car = ""; var air = "";

		new Ajax.Request(url, {
			method: 'post',
			parameters: param,
			asynchronous: true,
			onSuccess: function(transport) {
				//utilisation des variables reçue via AJAX (train, car, air)
				eval(transport.responseText);
				car = parseFloat(car);
				train = parseFloat(train);
				air = parseFloat(air);
				ecoComparatorUpdateTab(train, car, air);
				var hauteurCar	= "height:"+Math.round(baseMulti * car)+"px;";
				var hauteurTrain= "height:"+Math.round(baseMulti * train)+"px;";
				var hauteurAir	= "height:"+Math.round(baseMulti * air)+"px;";
				if (hauteurAir == "height:0px;"){
					$('ecoComparatorImgAir').style.display = "none";
				}
				else{
					$('ecoComparatorImgAir').style.display = "block";
				}
				$('ecoComparatorTrain').morph(hauteurTrain);
				$('ecoComparatorCar').morph(hauteurCar);
				$('ecoComparatorAir').morph(hauteurAir);
				document.getElementById("ecoComparatorImgAjax").style.display = "none";
			}
		});
	}
	else{
		$('labelOdEcoComparator').innerHTML = "";
		$('ecoComparatorImgAir').style.display = "block";
		$('ecoComparatorTrain').morph("height:2px;");
		$('ecoComparatorCar').morph("height:2px;");
		$('ecoComparatorAir').morph("height:2px;");
		$('thalys_kg').innerHTML = "-";
		$('car_kg').innerHTML = "-";
		$('air_kg').innerHTML = "-";
		$('car_diff').innerHTML = "-";
		$('air_diff').innerHTML = "-";
		$('labelOdEcoComparator').innerHTML = "";
		document.getElementById("ecoComparatorImgAjax").style.display = "none";
	}
}

function ecoComparatorUpdateTab(train, car, air){
	var diffCar = (car / train) * 100;
	var diffAir = "-";
	if (air == 0){
		air = "-";
	}
	else{
		diffAir = Math.round((air / train) * 100);
		diffAir= "+"+diffAir+"%";
	}
	$('thalys_kg').innerHTML = train;
	$('car_kg').innerHTML = car;
	$('air_kg').innerHTML = air;
	$('car_diff').innerHTML = "+"+Math.round(diffCar)+"%";
	$('air_diff').innerHTML = diffAir;

}

var txtSplited = new Array();

function checkNbCharCV2K10(){
	var texte = $('message_text').value;
	var nb_char = texte.length;
	var nbrMaxByLine = 39;

	if(nb_char >= 300){
		$('message_text').value = texte.substr(0,300);
		$('message_text').scrollTop = $('message_text').scrollHeight;
	}else{
//MAG:2009-12-23 : Verification par rapport au Nbr de lignes maximum autorisé.
		var txtSplit = texte.split('\n');
		txtSplited = new Array();
		for (var id in txtSplit){
			if (typeof(txtSplit[id]) == "function") continue;
			splitLigne(nbrMaxByLine, txtSplit[id]);
		}
		if (txtSplited.length > 12){
			while (txtSplited.length > 12){
				//tant qu'il y a plus que 12 lignes, on supprime les lignes supplémentaires.
				txtSplited.pop();
			}
		}
		texte = txtSplited.join("\n");
		$('message_text').value = texte;
	}

}

function splitLigne(max,txt){
	if (txt.length > max){
		if (txt.charAt(max-1) != " "){		//on verifie si le dernier caractère autorisé de la chaine n'est pas un espace
			if (txt.charAt(max) != " "){	//on vérifie si le dernier caractère autorisé est suivi d'une lettre (fait partie d'un mot)
				strTmp = txt.substr(0,max);
				var lastIdSpace = strTmp.lastIndexOf(" ");
				if (lastIdSpace != -1){
					txtSplited[txtSplited.length] = txt.substr(0,lastIdSpace);
					txtTmp = txt.substr(lastIdSpace+1,max);
				}
				else{
					txtSplited[txtSplited.length] = txt.substr(0,(max-1))+"-";
					txtTmp = txt.substr(max-1, (txt.length - (max - 1)));
				}
				splitLigne(max,txtTmp);
			}
			else{
				txtSplited[txtSplited.length] = txt.substr(0,max);
				txtTmp = txt.substr(max+1, (txt.length - max));
				splitLigne(max,txtTmp);
			}
		}
		else{
			txtSplited[txtSplited.length] = txt.substr(0,max-1);
			txtTmp = txt.substr(max+1, (txt.length - max));
			splitLigne(max,txtTmp);
		}
	}
	else{
		txtSplited[txtSplited.length] = txt;
	}
}

function  update_dest(){

	var select = document.getElementById('nb_dest');

	var nb_dest = select.options[select.selectedIndex].value;

	for(var i=0;i<10;i++){
		var table = document.getElementById('destinataire_'+i);
		if(i<nb_dest){
			table.style.display = 'block';
		}
		else{
			table.style.display = 'none';
		}
	}
}

function bookingSynchronizeStationsSeason(f,defaultTo)
{
	//var selectValue;
	if(document.getElementById("fromstation_id") &&document.getElementById("tostation_id"))
	{
		var optFrom = document.getElementById("fromstation_id").options;
		var optTo = document.getElementById("tostation_id").options;
		var lstTo = document.getElementById("tostation_id");

		if(optFrom.selectedIndex >= 0) {
			fromStation = optFrom[optFrom.selectedIndex].value;
			toStations = booking_stationsMap[fromStation];

			if(isArray(toStations))
			{
				var selectD = document.getElementById("tostation_id");
				//			alert(toStations.length);

				if(toStations.length == 1){
					optTo = emptyArray(optTo, optTo.length);
					toStation = toStations[0];
					insertListe(lstTo,booking_stations[toStation],toStation,0);
				}
				if(toStations.length > 1) {
					optTo = emptyArray(optTo, optTo.length);
					insertListe(lstTo,utf8_decode (label_tostation),"",0);
					optIndex = 1;
					for (var i = 0; i < toStations.length; i++) {
						toStation = toStations[i];
						if(toStations[i]!="TGB")insertListe(lstTo,booking_stations[toStation],toStation,optIndex);
					}

					//optIndex = 1;
					optTo = document.getElementById("tostation_id").options;
					for (var i = 0; i < optTo.length; i++) {
						toStation = optTo[i].value;
						if (toStation == defaultTo) {
							//alert(defaultTo);
							optTo.selectedIndex = i;
							break;
						}
						//optIndex++;
					}
				}
			}
		}
	}
}