/* 
 * on utilise la fonction du dessous finalement
 * function $(id) { return document.getElementById(id); }
 */
function _(id) { return document.getElementById(id); }
/*
onload = function (){
	hostname = document.location.hostname;
	if (hostname == "www.heliski-welt.com" || hostname == "www.espace-heliski.com" || hostname == "heliski-welt.kena.kn") {
		logo = document.getElementsByTagName("img")[1];
		logo.style.width = "180";
		logo.style.height = "127";
		logo.src = "/images/logo_heliski.png";
	}
}
*/
function validemail(field) {
	var str = field.value;
	if (str != "") {
		if (window.RegExp) {
			var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
			var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
			var reg1 = new RegExp(reg1str);
			var reg2 = new RegExp(reg2str);
			if (!reg1.test(str) && reg2.test(str)) {
				return true;
			}
			field.focus();
			field.select();
			return false;
		} else {
			if(str.indexOf("@") >= 0)
			return true;
			field.focus();
			field.select();
			return false;
		}
	} else {
		return false; 
	}
}
function checkFormVoyage() {
	var formulaire = document.getElementById("formvoyage");
	/*
	if(formulaire.surname.value == "")	 {
		alert("Veuillez completer ce champ correctement: Nom");
		return false;
	}
	if(formulaire.firstname.value == "")	 {
		alert("Veuillez completer ce champ correctement: Prenom");
		return false;
	}
	*/

	var t = _("vol_au_depart_de");
	var v = t.options[t.selectedIndex].value;
	if (v == "")  {
			alert("Vous devez choisir votre aéroport de départ ou à défaut indiquer que vous ne souhaitez pas de vol avec la dernière option");
			return false;
	}

	var x = _("number_of_travellers");
	var nb = x.options[x.selectedIndex].value;
	if (nb == ">10") nb = 10;
	else nb = parseInt(nb);
	if (nb>4) nb = 4;
	for (var j=2;j<nb+1;j++) {
		var t1 = _("surname_"+j).value;
		var t2 = _("firstname_"+j).value;
		if (t1 == "" || t2 == "") {
			alert("Merci de compléter le nom et le prénom de la "+j+"ème personne");
			return false;
		}
	}
	/*
	if(formulaire.address.value == "")	 {
		alert("Veuillez completer ce champ correctement: Adresse");
		return false;
	}
	*/
	if(formulaire.telwork.value == "")	 {
		alert("Veuillez completer ce champ correctement: Tel. la journee");
		return false;
	}
	if(!validemail(formulaire.email)){
		alert("Veuillez completer ce champ correctement: Email");
		return false;
	}
	/*
	if(
		(formulaire.Date_Depart_day.options[formulaire.Date_Depart_day.selectedIndex].text == "Jour")
		|| (formulaire.Date_Depart_month.options[formulaire.Date_Depart_month.selectedIndex].text == "Mois") 
		|| (formulaire.Date_Depart_year.options[formulaire.Date_Depart_year.selectedIndex].text == "Annee")) {
			alert("Merci de completer la date de depart");
			return false;
	}

	if(
		(formulaire.Date_Arrivee_day.options[formulaire.Date_Arrivee_day.selectedIndex].text == "Jour")
		|| (formulaire.Date_Arrivee_month.options[formulaire.Date_Arrivee_month.selectedIndex].text == "Mois")
		|| (formulaire.Date_Arrivee_year.options[formulaire.Date_Arrivee_year.selectedIndex].text == "Annee")) {
			alert("Merci de completer la date de retour souhaitee");
			return false;
	}
	*/
	formulaire.submit();
	return true;
}
var t = 0;
function PopupImage(img) {
	titre="Agrandissement"; 
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=no'); 
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>"); 
	w.document.write("<SCRIPT language=javascript>function checksize() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+10,document.images[0].height+30); window.focus();} else { setTimeout('checksize()',250) } }</"+"SCRIPT>"); 
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
	w.document.write("<TABLE border='0' cellspacing='0' cellpadding='0' ><TR>");
	w.document.write("<TD valign='middle' align='center'><IMG src='"+img+"' border=0 alt='Mon image'>"); 
	w.document.write("</TD></TR></TABLE>");
	w.document.write("</BODY></HTML>"); 
	w.document.close(); 
}

function checkFormWithObject(form){
	if (!form) return;
	list = form.getElementsByTagName("input");
	l = list.length;
	for (i = 0;i<l;i++) {
		li = list[i];
		n = li.getAttribute("name");
		if (n && n.substring(0,5) == "send_") {
			if (n.search("email") > 0 && !validemail(li) ){
				alert("l'email saisi est incorrect");
				return;
			} else if (li.value == '') {
				fname = n.substring(5).replace(/_/g," ");
				alert("le champ "+fname+" est obligatoire");
				return false;
			}
		}
	}
	list = form.getElementsByTagName("select");
	l = list.length;
	for (i = 0;i<l;i++) {
		li = list[i];
		n = li.getAttribute("name");
		if (n && n.substring(0,5) == "send_") {
			if (li.options[li.selectedIndex].value == '0') {
				fname = n.substring(5).replace(/_/g," ");
				alert("le champ "+fname+" est obligatoire");
				return false;
			}
		}
		
	}
	form.submit();
}

function checkForm(formname){
	alert(document);
	form = document.forms["formname"];
	//form = document.all.formname;
	//form = document.getElementById(formname);
	alert("coucou test");
	if (!form) return;
	alert(form);
	list = form.getElementsByTagName("input");
	alert(form);
	l = list.length;
	for (i = 0;i<l;i++) {
		li = list[i];
		n = li.getAttribute("name");
		if (n && n.substring(0,5) == "send_") {
			if (n.search("email") > 0 && !validemail(li) ){
				alert("l'email saisi est incorrect");
				return;
			} else if (li.value == '') {
				fname = n.substring(5).replace(/_/g," ");
				alert("le champ "+fname+" est obligatoire");
				return false;
			}
		}
	}
	list = form.getElementsByTagName("select");
	l = list.length;
	for (i = 0;i<l;i++) {
		li = list[i];
		n = li.getAttribute("name");
		if (n && n.substring(0,5) == "send_") {
			if (li.options[li.selectedIndex].value == '0') {
				fname = n.substring(5).replace(/_/g," ");
				alert("le champ "+fname+" est obligatoire");
				return false;
			}
		}
		
	}
	form.submit();
}

function parsehref(val) {
	if (val.substring(0,7) == "http://") {
		val = val.substring(7);
		val = val.substring(val.search("/"));
		return val;
	} else {
		return val;
	}
}

function categorieDisplay(color) {
	if (color) dacolor = color;
        else dacolor = "#85a5b8";
	page = document.location.pathname;
	list = document.getElementsByTagName("a");
	l = list.length;
	p = ((document.location)+"").indexOf("hlsecu");
	if (p>0) {
		document.getElementById("lsecu").style.color = dacolor;
		return;
	}
	p = ((document.location)+"").indexOf("hldest");
	if (p>0) {
		document.getElementById("ldest").style.color = dacolor;
		return;
	}
	for(i=1;i<l;i++) {
		li = list[i];
		id = li.getAttribute("id");
		href0 = li.getAttribute("href");
		href = parsehref(href0);
		if (href == page || href+"/" == page || href+"/index.php" == page) {
			li.style.color = dacolor;
		} else {
			h_ = href.lastIndexOf("/");
			p_ = page.lastIndexOf("/");
			h__ = href.substring(0,h_);
			p__ = page.substring(0,p_);
			h__ = href;
			//alert(h__);
			if (h__ == p__) {
				li.style.color= dacolor;
				break;
			}
		}
		if(id) {
			if (href == page || href+"/" == page) {
				p = id.search("_");
				code = id.substring(p+1);
				div = document.getElementById("menu"+code);
				if (div) div.style.display = "block";
			}
		}
	}
}
function nothing(){
	alert("nothing");
}
