﻿try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

document.getElementById("header").firstChild.nodeValue = "";
if (document.getElementById("EN"))
	document.getElementById("EN").firstChild.nodeValue = "";
else
	document.getElementById("FR").firstChild.nodeValue = "";
		
function show_it(the_li, sub) {
//window.alert("the_ul="+the_ul+"&the_li="+the_li);
	var menu_children2 = document.getElementById("menu").childNodes;
	for (i=0;i<menu_children2.length;i++) {
		if (menu_children2[i].nodeName=='LI') {
			menu_children2[i].getElementsByTagName('A')[0].style.backgroundColor='#983222';
			for (j=0;j<menu_children2[i].childNodes.length;j++) {
				if (menu_children2[i].childNodes[j].nodeName=='UL')
					menu_children2[i].childNodes[j].style.display='none';
			}
		}
	}
	if (the_li != -1) {
		menu_children2[the_li].getElementsByTagName('A')[0].style.backgroundColor='#7A221B';
		if (typeof sub == 'undefined') {
			for (j=0;j<menu_children2[the_li].childNodes.length;j++) {
				if (menu_children2[the_li].childNodes[j].nodeName=='UL') {
					menu_children2[the_li].childNodes[j].style.display='block';
				}
			}
		}
	}
}
function hover_it() {
	found_li = -1;
	var heading_url = location.href.substring(location.href.lastIndexOf("/")+1);
	if (heading_url == "contact.asp") submitForm(0, 'showErrors', 11);
	else if (heading_url.substring(0, 12) == "commande.asp") {
		if ((heading_url.indexOf("ModifAdrF", 0)) != -1) submitForm(0, 'showErrors', 0, 1, 2, 4, 6, 7, 10);
		else {
			submitForm(0, 'showErrors', 0, 1);
			submitForm(2, 'showErrors', 0, 1, 2, 3, 5, 7, 8, 11, 14, 15, 16, 18);
		}
	}
	else if (heading_url.substring(0, 18) == "form_livraison.asp") submitForm(0, 'showErrors', 0, 1, 2, 3, 5, 7, 8, 11, 14);
	else if (heading_url.substring(0, 18) == "recap_commande.asp") submitForm(0, 'showErrors', 2);
	if (location.href.substring(location.href.substring(7).indexOf("/") + 8).indexOf("/") == "-1") return;
	//alert(location.href.substring(location.href.substring(7).indexOf("/") + 11).indexOf("/"));
	//Modif Thomas 23/01/2009 pour menu EN
	if (location.href.substring(location.href.substring(7).indexOf("/") + 11).indexOf("/") == "-1") return;
	var menu_children = document.getElementById("menu").childNodes;
	for (i=0;i<menu_children.length;i++) {
		if (found_li != -1)
			break;
		if (menu_children[i].nodeName=='LI') {
			for (j=0;j<menu_children[i].childNodes.length;j++) {
				if (menu_children[i].childNodes[j].nodeName=='A') {
					the_anchor = menu_children[i].childNodes[j]+'';
					the_anchor = the_anchor.substring(the_anchor.lastIndexOf("/")+1);
					if (heading_url == the_anchor) found_li = i;
				}
				if (found_li != -1) break;
			}
		}
	}
	for (i=0;i<menu_children.length;i++) {
		if (menu_children[i].nodeName=='LI') {
			var a_function = new Function('', 'show_it('+i+');');
			var a_function2 = new Function('', 'show_it('+found_li+', \'a_sub\');');
			if (window.addEventListener) {
				menu_children[i].addEventListener('mouseover', a_function, false);
				menu_children[i].addEventListener('mouseout', a_function2, false);
			}
			else if (window.attachEvent) {
				menu_children[i].attachEvent('onmouseover', a_function);
				menu_children[i].attachEvent('onmouseout', a_function2);
			}
		}
	}
	if (found_li != -1) {
//		window.alert("found_li="+found_li);
		show_it(found_li, 'no_sub');
	}
}

var W3CDOM = (document.getElementsByTagName && document.createElement);

function submitForm (theForm, showErrors) {
	elements2check = '';
	for (i=2; i<submitForm.arguments.length; i++) {
		elements2check = elements2check + submitForm.arguments[i] + ',';
	}
	elements2check = elements2check.substring(0, elements2check.length - 1);
	chaine = 'document.forms['+ theForm +'].onsubmit = function () { return validate(' + theForm +',\'' + showErrors +'\', ' + elements2check + ') }';
//	window.alert(chaine);
	eval (chaine);
}
function validate(theForm, showErrors) {
	validForm = true;
	firstError = null;
	errorstring = '';
	var x = document.forms[theForm].elements;
	for (var i=2; i<validate.arguments.length; i++) {
		if (!x[validate.arguments[i]].value) {
			writeError(x[validate.arguments[i]],'incomplet', showErrors);
		}
		else if (x[validate.arguments[i]].id == "EMAIL") {
			//var exp=new RegExp("^[a-zA-Z0-9\.\-_]+[^\.]@[^\.][a-zA-Z0-9\.\-_]{1,}[.][a-z]{2,4}$","g"); Modif Thomas 23-02-2009
			var exp=new RegExp("^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$");
			if (!(exp.test(x[validate.arguments[i]].value))) {
				writeError(x[validate.arguments[i]],'L\'adresse email n\'est pas valide', showErrors);
			}
		}
		else if (x[validate.arguments[i]].type == "checkbox") {
			if (!x[validate.arguments[i]].checked) {
				if (x[validate.arguments[i]].id == "age") writeError(x[validate.arguments[i]],'âge mini', showErrors);
				else if (x[validate.arguments[i]].id == "cv") writeError(x[validate.arguments[i]],'requises', showErrors);
			}
		}
	}
	if (!W3CDOM)
		alert(errorstring);
	if (firstError)
		firstError.focus();
	if (validForm)
		return true;
	return false;
}
function writeError(obj,message,the_errors) {
	validForm = false;
	if (!firstError)
		firstError = obj;
	if (obj.hasError) return;
	if (W3CDOM) {
		obj.className += ' error';
		obj.onchange = removeError;
		if (writeError.arguments[2] != '') {
			var sp = document.createElement('span');
			sp.className = 'error float_left';
			sp.appendChild(document.createTextNode(message));
			obj.parentNode.appendChild(sp);
		}
		obj.hasError = sp;
	}
	else {
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
}
function removeError() {
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onchange = null;
}

if (window.addEventListener) {
	window.addEventListener('load', hover_it, false);
}
else if (window.attachEvent) {
	window.attachEvent('onload', hover_it);
}
