// JavaScript Document
function $(id) { return document.getElementById(id); }
	
function isEmail(strEmail) {
	if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}

function check_vj() {
	if($('f_i_type_e').checked) {
		$('tr_entreprise').style.display = '';
	} else {
		$('tr_entreprise').style.display = 'none';	
	}
}

function verif_form_insc(formu) {
	var err = "<span class=\"blanc\">Veuillez entrer :</span><br/>";
	var err_init = err;
	
	if($('f_i_nom').value == "" || $('f_i_prenom').value == "" || $('f_i_postaldata').value == "" || $('f_i_codepostal').value == "" || $('f_i_ville').value == "") {
		err += " - votre nom, votre prénom et votre adresse complète<br/>";
	}
	
	if($('f_i_email').value == "") {
		err += " - une adresse email<br/>";
	} else if (isEmail($('f_i_email').value) == false) {
		err += " - une adresse email valide<br/>";
	}
	
	if($('f_i_type_e').checked && $('f_i_entreprise').value == "") {
		err += "  - un nom d'entreprise<br/>";
	}
	
	if($('f_i_password').value == "") {
		err += " - un mot de passe<br/>";
	} else if ($('f_i_password').value != $('f_i_password2').value) {
		err += " - un mot de passe identique dans les deux champs<br/>";
	}
	
	if(err != err_init) {
		$('err_insc').innerHTML = err+"<br/>";
	} else {
		formu.submit();
	}
}

function verif_form_connex(formu) {
	err = "";
	
	if($('f_c_email').value == "" || $('f_c_password').value == "") {
		err = "Veuillez entrer votre adresse e-mail et votre mot de passe";
	}
	
	if(err != "") {
		$('err_login').innerHTML = "Veuillez entrer votre adresse e-mail et votre mot de passe";
		$('hrlog').style.marginBottom = "8px"; //IE6Fix
	} else {
		formu.submit();
	}
}

function verif_form_notes(form) {
	if ($('f_n_note').value != "") {
		form.submit();
	}
}

var ck_email = false;
var ck_pass  = false;

function clear_input(elem) {
	switch(elem.name) {
		case "email":
			if(!ck_email) {
				ck_email = true;
				elem.value = "";
			}
			break;
		case "pass":
			if(!ck_pass) {
				ck_pass = true;
				elem.style.display = "none";
				elem = $('f_c_password');
				elem.style.display = "";
				elem.focus();
				$('hrlog').style.marginBottom = "8px"; //IE6Fix
			}
			break;
	}
}

var historoll = 0;

function rollhisto(minLeft, maxLeft, step) {
	var curLeft = parseInt($('roll_histo').style.left.replace("px", ""));
	$('roll_histo').style.zIndex = "100";
	
	if(curLeft <= minLeft || historoll == 1) {
		historoll = 1;
		$('roll_histo').style.backgroundPosition = "100% 100%";
		curLeft += step;
		
		if(curLeft >= maxLeft) {
			$('roll_histo').style.left = maxLeft+"px";
			historoll = 0;
			$('trigger_histo').title = "Masquer l'historique"
		} else {
			$('roll_histo').style.left = curLeft+"px";
			setTimeout("rollhisto("+minLeft+","+maxLeft+", "+step+")", 10);
		}
	} else if(curLeft >= maxLeft || historoll == -1) {
		historoll = -1;
		curLeft -= step;
		
		if(curLeft <= minLeft) {
			$('roll_histo').style.backgroundPosition = "100% 0";
			$('roll_histo').style.left = minLeft+"px";
			$('trigger_histo').title = "Afficher l'historique"
			historoll = 0;
		} else {
			$('roll_histo').style.left = curLeft+"px";
			setTimeout("rollhisto("+minLeft+","+maxLeft+", "+step+")", 10);
		}
	}
}

function clicindice() {
	if($('pop_indices').style.display == "none") {
		$('pop_indices').style.display = "";
		$('notes_wrapper').style.display = "none";
	} else {
		outindice();
	}
		
}
function outindice() {
	$('pop_indices').style.display = "none";
	$('notes_wrapper').style.display = "";
}
