
function onKeyDown(form, event){
	if(event.keyCode == 13 && !document.getElementById('as_searchField')
			&& verifValid()) {
		form.submit();	
	} 
	else{
		document.getElementById('typeObj').value = '';
		document.getElementById('numObj').value  = '';
	} 
}

function verifValid(){
	var champ = document.getElementById('searchField');
	var resPropre = champ.value.replace(/(?:^\s+|\s+$)/g, "");
	if(resPropre == ''){
		champ.value = '';
		return false;
	}
	else return true;
}

function getColorFromClass(maClass){
	if (!document.styleSheets) return -1;
	var regles=new Array();
	if (document.styleSheets[0].cssRules) regles = document.styleSheets[0].cssRules;
	else if (document.styleSheets[0].rules) regles = document.styleSheets[0].rules;
	else return -1;
	
	for (var i=0; i<regles.length; i++){
        if(regles[i].selectorText == maClass){ 
            return RGB2HTML(regles[i].style.color); 
        } 
    } 
    return -1;
}
function RGB2HTML(rgb)
{
	tab = rgb.substr(4, (rgb.length-5));
	tablo = tab.split(',');
	
    return String(str_pad(dec2hex(tablo[0]),2,"0",0)) 
		   + String(str_pad(dec2hex(tablo[1]),2,"0",0)) 
		   + String(str_pad(dec2hex(tablo[2]),2,"0",0));
}

function dec2hex(dec) {
  var hexa="0123456789ABCDEF";
  var hex="";
  while (dec>15) {
    tmp=dec-(Math.floor(dec/16))*16;
    hex=hexa.charAt(tmp)+hex;
    dec=Math.floor(dec/16);
  }
  hex=hexa.charAt(dec)+hex;
  return(hex);
}

function str_pad(chaine, taille, elem, sens) { // 0 = left , 1 = right, 2 = center
var orientation = 0;
while(chaine.length < taille) {
 if( (sens == 0 || sens == 2) && orientation == 0) {
    chaine = elem + chaine;
  }
  if( (sens == 1 || sens == 2) && orientation == 1) {
    chaine = chaine + elem;
  }
  orientation = 1 - orientation;
}
return chaine.substr(0,taille);
}

function checkEmail() 
{ 	
    var email = document.form_newsletter.FORM_EMAIL.value; 
    
    if (email.search(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/) == -1)
    { 
        alert ('entrez une adresse Email valide'); 
        document.form_newsletter.form_email.value="";
        document.form_newsletter.form_email.focus(); 
        return false; 
    } 
       	
	 document.form_newsletter.submit();
}

function convertKeyCode(charCode){
			var charactere = "";
			 if (charCode == 8) charactere = "backspace"; //  backspace
			 if (charCode == 9) charactere = "tab"; //  tab
			 if (charCode == 13) charactere = "enter"; //  enter
			 if (charCode == 16) charactere = "shift"; //  shift
			 if (charCode == 17) charactere = "ctrl"; //  ctrl
			 if (charCode == 18) charactere = "alt"; //  alt
			 if (charCode == 19) charactere = "pause/break"; //  pause/break
			 if (charCode == 20) charactere = "caps lock"; //  caps lock
			 if (charCode == 27) charactere = "escape"; //  escape
			 if (charCode == 33) charactere = "page up"; // page up, to avoid displaying alternate character and confusing people	         
			 if (charCode == 34) charactere = "page down"; // page down
			 if (charCode == 35) charactere = "end"; // end
			 if (charCode == 36) charactere = "home"; // home
			 if (charCode == 37) charactere = "left arrow"; // left arrow
			 if (charCode == 38) charactere = "up arrow"; // up arrow
			 if (charCode == 39) charactere = "right arrow"; // right arrow
			 if (charCode == 40) charactere = "down arrow"; // down arrow
			 if (charCode == 45) charactere = "insert"; // insert
			 if (charCode == 46) charactere = "delete"; // delete
			 if (charCode == 91) charactere = "left window"; // left window
			 if (charCode == 92) charactere = "right window"; // right window
			 if (charCode == 93) charactere = "select key"; // select key
			 if (charCode == 96) charactere = "numpad 0"; // numpad 0
			 if (charCode == 97) charactere = "numpad 1"; // numpad 1
			 if (charCode == 98) charactere = "numpad 2"; // numpad 2
			 if (charCode == 99) charactere = "numpad 3"; // numpad 3
			 if (charCode == 100) charactere = "numpad 4"; // numpad 4
			 if (charCode == 101) charactere = "numpad 5"; // numpad 5
			 if (charCode == 102) charactere = "numpad 6"; // numpad 6
			 if (charCode == 103) charactere = "numpad 7"; // numpad 7
			 if (charCode == 104) charactere = "numpad 8"; // numpad 8
			 if (charCode == 105) charactere = "numpad 9"; // numpad 9
			 if (charCode == 106) charactere = "multiply"; // multiply
			 if (charCode == 107) charactere = "add"; // add
			 if (charCode == 109) charactere = "subtract"; // subtract
			 if (charCode == 110) charactere = "decimal point"; // decimal point
			 if (charCode == 111) charactere = "divide"; // divide
			 if (charCode == 112) charactere = "F1"; // F1
			 if (charCode == 113) charactere = "F2"; // F2
			 if (charCode == 114) charactere = "F3"; // F3
			 if (charCode == 115) charactere = "F4"; // F4
			 if (charCode == 116) charactere = "F5"; // F5
			 if (charCode == 117) charactere = "F6"; // F6
			 if (charCode == 118) charactere = "F7"; // F7
			 if (charCode == 119) charactere = "F8"; // F8
			 if (charCode == 120) charactere = "F9"; // F9
			 if (charCode == 121) charactere = "F10"; // F10
			 if (charCode == 122) charactere = "F11"; // F11
			 if (charCode == 123) charactere = "F12"; // F12
			 if (charCode == 144) charactere = "num lock"; // num lock
			 if (charCode == 145) charactere = "scroll lock"; // scroll lock
			 if (charCode == 186) charactere = ";"; // semi-colon
			 if (charCode == 187) charactere = "="; // equal-sign
			 if (charCode == 188) charactere = ","; // comma
			 if (charCode == 189) charactere = "-"; // dash
			 if (charCode == 190) charactere = "."; // period
			 if (charCode == 191) charactere = "/"; // forward slash
			 if (charCode == 192) charactere = "`"; // grave accent
			 if (charCode == 219) charactere = "["; // open bracket
			 if (charCode == 220) charactere = "\\"; // back slash
			 if (charCode == 221) charactere = "]"; // close bracket
			 if (charCode == 222) charactere = "'"; // single quote
			 if (charCode == 65) charactere = "a";
			 if (charCode == 66) charactere = "b";
			 if (charCode == 67) charactere = "c";
			 if (charCode == 68) charactere = "d";
			 if (charCode == 69) charactere = "e";
			 if (charCode == 70) charactere = "f";
			 if (charCode == 71) charactere = "g";
			 if (charCode == 72) charactere = "h";
			 if (charCode == 73) charactere = "i";
			 if (charCode == 74) charactere = "j";
			 if (charCode == 75) charactere = "k";
			 if (charCode == 76) charactere = "l";
			 if (charCode == 77) charactere = "m";
			 if (charCode == 78) charactere = "n";
			 if (charCode == 79) charactere = "o";
			 if (charCode == 80) charactere = "p";
			 if (charCode == 81) charactere = "q";
			 if (charCode == 82) charactere = "r";
			 if (charCode == 83) charactere = "s";
			 if (charCode == 84) charactere = "t";
			 if (charCode == 85) charactere = "u";
			 if (charCode == 86) charactere = "v";
			 if (charCode == 87) charactere = "w";
			 if (charCode == 88) charactere = "x";
			 if (charCode == 89) charactere = "y";
			 if (charCode == 90) charactere = "z";
		return charactere;
		}

function getStations(charPush){
			document.getElementById('listeStationsChar').innerHTML = '';	// div des resultats a  affiche apres le click d'une lettre : initialise
			var arrayChar 	= new Array();
			var a 			= 0;											// compteur
	
			var stations 	= document.getElementById('listeStation');    // span de ALL liste Stations (chacun mis dans des span)
			var inStations 	= stations.innerHTML;						// ALL liste Statiom: HTML
			
			// yossef: bug de Ie: un truc de fou ! A cause de la casse l'ecriture de span !!!
			if(navigator.appName == "Microsoft Internet Explorer"){
				var arraySpans 	= inStations.split("</SPAN>"); // tous les <span >Nom de stations {sans le tags </span>}
			}
			else{
				var arraySpans 	= inStations.split("</span>"); // tous les <span >Nom de stations {sans le tags </span>}
			}
			
			var spans 		= stations.getElementsByTagName('span');
			
		
			for(var i=0; i<spans.length; i++){
				var smallChaine = spans[i].innerHTML.toLowerCase();
				if(charPush == smallChaine.charAt(0)){
					arrayChar[a] = spans[i];     // array de Span + onclick , mais sans le Nom et ssans la fermeture dyu span !!!
					a++;
				}
			}
			// jusqu'a la , tout est  OK !
		
			for(i=0; i<arrayChar.length; i++){
				for(r=0; r<arraySpans.length; r++){
						
					$TEMPOS = 	arraySpans[r].split('>');
					if($TEMPOS[1] == arrayChar[i].innerHTML){
						//console.info(arraySpans[r] + " MATCH " + arrayChar[i].innerHTML);	
						var loc = arraySpans[r]+"</span>";
					}
					else{
					}
				}
				
				document.getElementById('listeStationsChar').innerHTML += loc;
				
			}
			stations.style.display = 'none';
			document.getElementById('listeStationsChar').style.display = 'block';
			//alert(document.getElementById('listeStationsChar').innerHTML);
		}
function openSearch(checker){
	var selectRegion = document.getElementById('selectRegion');
	var selectStation = document.getElementById('selectStation');
	var selectCure = document.getElementById('selectCure');
	var selectPrix = document.getElementById('selectPrix');
	var selectDuree = document.getElementById('selectDuree');
		if(checker == 0){
			jQuery('#listeRegion').hide();
			jQuery('#listeStation').hide();
			jQuery('#listeCure').hide();
			jQuery('#listeDuree').hide();
			jQuery('#listeStationsChar').hide();
		}
		if(checker == 1){
			if(!selectRegion){ return }
			else{
					var toOpen = document.getElementById('listeRegion');
					if(toOpen.style.display == 'none'){
						toOpen.style.display = 'block';
						jQuery('#listeStation').hide();
						jQuery('#listeStationsChar').hide();
						jQuery('#listeCure').hide();
						jQuery('#listeDuree').hide();
					}
					else{
						jQuery('#listeRegion').hide();
					}
			}
		}
		if(checker == 2){
			if(!selectStation){ return }
			else{
					var toOpen2 = document.getElementById('listeStation');
					if(toOpen2.style.display == 'none' ){
						toOpen2.style.display = 'block';
						jQuery('#listeRegion').hide();
						jQuery('#listeCure').hide();
						jQuery('#listeDuree').hide();
						
						document.getElementById('listeStationsChar').style.display = 'none';
						document.onkeydown=function(e){
							
							//yossef:AJOUT D'une condition: a t il clicker sur une touche qui m'interesse
							if((e||window.event).keyCode >=65    && (e||window.event).keyCode  <=90 ){
								var charactere = convertKeyCode((e||window.event).keyCode);
							
								getStations(charactere);								
							}

						}
					}
					else{
						jQuery('#listeStation').hide();
						jQuery('#listeStationsChar').hide();
						document.onkeydown='';
					}
				}
		}
		if(checker == 3){
		if(!selectCure){ return }
			else{
					var toOpen = document.getElementById('listeCure');
					if(toOpen.style.display == 'none'){
						toOpen.style.display = 'block';
						jQuery('#listeStation').hide();
						jQuery('#listeStationsChar').hide();
						jQuery('#listeRegion').hide();
						jQuery('#listeDuree').hide();
					}
					else{
						jQuery('#listeCure').hide();
					}
			}
		}
		if(checker == 4){
		if(!selectDuree){ return }
			else{
					var toOpen = document.getElementById('listeDuree');
					if(toOpen.style.display == 'none'){
						toOpen.style.display = 'block';
						jQuery('#listeStation').hide();
						jQuery('#listeStationsChar').hide();
						jQuery('#listeRegion').hide();
						jQuery('#listeCure').hide();
					}
					else{
						jQuery('#listeDuree').hide();
					}
			}
		}
}

function remplirHidden(type,num)
{
	if(type == 'station')
	{
		document.getElementById('numStation').value = num;
		document.getElementById('numFiche').value = num;
	}
	else if((type == 'duree'))
	{
		if(num == "33") {hiddenCode = "6442";}
		if(num == "34") {hiddenCode = "6443";}
		if(num == "35") {hiddenCode = "6444";}	
	
		document.getElementById('type_sejour_code').value = hiddenCode;
	}
}
