// JavaScript Document
// ========================= DISPLAY/HIDE SPECIFIC DIV ============================
//<div id="show_pass" style="display:none" >
function displayDiv(which) {
if (document.getElementById(which).style.display == String('none'))
	{
	document.getElementById(which).style.display = String ('block');
	}
else
	{
	document.getElementById(which).style.display = String ('none');
	}

return false;
}

function showDiv(whichdiv) {
	document.getElementById(whichdiv).style.display = String ('block');
	return false;
	}

function hideDiv(whichdiv) { 
	document.getElementById(whichdiv).style.display = String ('none'); 
	return false;
} 

function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      alert ("");
	  return false;
   }
   else { return false; }
}	

function disableIt(whichform, whichfields){
	es = whichfields.split(';');
	for(i=0;i<es.length;i++){
		currE = eval("document.getElementById(whichform)."+es[i]);
		currE.disabled = true;
		currE.style.backgroundColor = '#b2b5cb';
	}
}

function uncheckIt(whichform, whichfields){
	es = whichfields.split(';');
	for(i=0;i<es.length;i++){
		currE = eval("document."+whichform+"."+es[i]);
		currE.checked = false;
		currE.style.backgroundColor = 'transparent';
	}
}

function checkIt(whichform, whichfields){
	es = whichfields.split(';');
	for(i=0;i<es.length;i++){
		currE = eval("document."+whichform+"."+es[i]);
		currE.checked = true;
		currE.style.backgroundColor = 'transparent';
	}
}

function enableAll(whichform){
	for(i=0;i<document.getElementById(whichform).elements.length;i++){
		document.getElementById(whichform).elements[i].disabled=false;
		document.getElementById(whichform).elements[i].style.backgroundColor = 'white';
	}
}

function checkEmail() 
{
if (document.email_form.newemail.value.length >0) 
	{
	 i=document.email_form.newemail.value.indexOf("@")
	 j=document.email_form.newemail.value.indexOf(".",i)
	 k=document.email_form.newemail.value.indexOf(",")
	 kk=document.email_form.newemail.value.indexOf(" ")
	 jj=document.email_form.newemail.value.lastIndexOf(".")+1
	 len=document.email_form.newemail.value.length

	if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3))
		{
			if(checkChars())
				{
				return true;
				}
			else
				{
				return false;
				}
		}
	else 
		{
		alert("L'adresse E-mail est invalide. \nMerci de la corriger.");
		document.email_form.newemail.select(); 
		return false;
		}
	}
else 
	{
	alert("Le champ E-mail est vide. \nVous devez obligatoirement le remplir.");
	document.email_form.newemail.select(); 
	return false;
	}
}


// =============================== VERIFICATIONS AVANT UN SUBMIT ===========================
var errEmptyFields = 0;

function formValidation(whichform, whichfields){
	errEmptyFields = 0;
	formfields = whichfields.split(";");
	totalfields = formfields.length;
	for (i = 0; i < totalfields; i++) {
		thisfield = eval("document."+whichform+"."+formfields[i]);
		notEmpty(thisfield);
	}
	if (errEmptyFields>0) {
	alert("Veuillez remplir tous les champs obligatoires(*).");
	return false;
	}
}

function notEmpty(elem){
	var str = elem.value;
	if ((str.length == 0) || (str==null)) {
		errEmptyFields++
	}
	else {
		return true;
	}
}

function searchValidation(){

	var dosearch = false;
	var theform = document.forms['tickerForm'];
	var form_motcle = theform.elements['motcle'].value;
	var form_codepro = theform.elements['codeproduit'].value;
	var form_codefour = theform.elements['codefournisseur'].value;
	
	
	if(theform.elements['mc'].checked)	{
		if (form_motcle == "" || form_motcle == null || form_motcle.charAt(0) == ' ') {
			dosearch = false;
		}	else	{
			dosearch = true;	
		}
	}
	if(theform.elements['cp'].checked)	{		
		if (form_codepro == "" || form_codepro == null || form_codepro.charAt(0) == ' ') {
			dosearch = false;
		}	else	{
			dosearch = true;	
		}
		
	}
	if(theform.elements['cf'].checked)	{
		if (form_codefour == "" || form_codefour == null || form_codefour.charAt(0) == ' ') {
			dosearch = false;
		}	else	{
			dosearch = true;	
		}
	}
	
	if(dosearch)	{
		theform.submit();
		return true;	
	} else {
		alert('Merci de saisir un code produit, une référence fournisseur ou un mot-clé pour effectuer une recherche.');
		return false;
	}
	
}
