/********************************************************
*  FONCTION POPUP POUR LA NEWSLETTER
********************************************************/

function PopupCentrerNl(page,nom,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,nom,'top='+top+',left='+left+',width='+largeur+',height='+hauteur+','+options);
}

function go(){
	PopupCentrerNl('','popup',500,300,'menubar=no,scrollbars=no,statusbar=no');
	document.forms['newsletter'].submit();
}

/********************************************************
*  FONCTION POUR OUVRIR LE MENU
********************************************************/
function openDiv(id, pref)
{
	for(i=1; i<5; i++)
	{
		var myElement = document.getElementById(pref+i);
		if(myElement)myElement.style.display = "none";
	}
	var myElement = document.getElementById(pref+id);
	if(myElement)myElement.style.display = "block";
}


/********************************************************
*  FONCTION PERMETTANT DE VERIFIER LES CHAMP D'UN FORMULAIRE
********************************************************/
/*
function verifForm(formobj, fieldRequired, fieldDescription){
	
	// intro des messages de la boite de dialogue
	var alertMsg = "Vous devez completer :\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].value == "rien"){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;

			case "checkbox":
					alert(obj.checked);
					if (obj.checked == false){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;

			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
					obj.className = "contactErreur";
				}else{
					obj.className = "contact";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		var field = formobj.elements["email"];
		if(field.value != null && field.value != ""){
			if(!checkmail(field.value)){
					alert("votre email est incorrect");
					field.className = "contactErreur";
					return false;
			}else{
				field.className = "contact";
				return true;
			}
		}else{
			return true;
		}
	}else{
		alert(alertMsg);
		return false;
	}
}
*/


function checkmail(email) {
         var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/
         return (reg.exec(email)!=null)
}


/*
* Fonction resizePopUp
* permet d'ouvrir une image en popup centrée sans avoir à declarer ses dimensions
* ex : <a href="#" onClick='resizePopUp("image.jpg","commentaire");'></a>
*/

function resizePopUp(monImage, monTitre)
{
    
  w = window.open('','chargement','width=10,height=10');
  w.document.write( "<html><head><title>"+monTitre+"</title>\n" ); 
  w.document.write( "<script language='JavaScript'>\n"); 
  w.document.write( "IE5=NN4=NN6=false;\n"); 
  w.document.write( "if(document.all)IE5=true;\n"); 
  w.document.write( "else if(document.getElementById)NN6=true;\n"); 
  w.document.write( "else if(document.layers)NN4=true;\n"); 
  w.document.write( "function autoSize() {\n"); 
  w.document.write( "if(IE5) self.resizeTo(document.images[0].width+10,document.images[0].height+31)\n"); 
  w.document.write( "else if(NN6) self.sizeToContent();\n");
  w.document.write( "else window.resizeTo(document.images[0].width,document.images[0].height+20)\n"); 
  w.document.write( "self.focus();\n"); 
  
  // debut modification par franck pour le centrage
  w.document.write( "autoMove();\n"); 
  w.document.write( "}\n"); 
  w.document.write( "function autoMove() {\n"); 
  w.document.write( "var h = document.images[0].width;\n"); 
  w.document.write( "var l = document.images[0].height;\n"); 
  w.document.write( "var PosX = ( screen.availWidth - h ) / 2;\n"); 
  w.document.write( "var PosY = ( screen.availHeight - l ) / 2;\n"); 
  w.document.write( "window.moveTo(PosX, PosY);\n"); 
  // fin modification pour le centrage
  
  w.document.write( "}\n</scri");
  w.document.write( "pt>\n"); 
  w.document.write( "</head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad='javascript:autoSize();'>" );
  w.document.write( "<a href='javascript:window.close();'><img src='"+monImage+"' border=0 alt='"+monTitre+"'></a>" ); 
  w.document.write( "</body></html>" );
  w.document.close(); 
}



function validForm(f_form){   
	form = new ValidForm(f_form);
	//
	form.text('type', '', 'minimum', 1, ERR_CONF["type"]);
	form.number('poids_maxi', '', 'minimum', 1, true, ERR_CONF["poids_maxi"]);
	form.numberVal('poids_maxi', '', '<=', 20000, ERR_CONF["poids_maxi_limite"]);
	
	form.text('diam_ext', '', 'minimum', 1, ERR_CONF["diam_ext"] );
	form.text('diam_int', '', 'minimum', 1, ERR_CONF["diam_int"] );
	form.compFields('diam_int', 'diam_ext', '', '', '<', ERR_CONF["diam_comp"]);
	//
	form.ereg('larg_mini', '^[0-9]{1,}([\.][0-9]{1,2})?$', ERR_CONF["form_larg_mini"], true, ERR_CONF["input_larg_mini"]);
	form.ereg('larg1_maxi', '^[0-9]{1,}([\.][0-9]{1,2})?$', ERR_CONF["form_larg1_maxi"], true, ERR_CONF["input_larg1_maxi"]);
	form.numberVal('larg1_maxi', '', '<=', 2200, ERR_CONF["larg1_maxi_limite"]);
	form.compFields('larg_mini', 'larg1_maxi', '', '', '<', ERR_CONF["larg1_comp"]);
	form.ereg('ep1_maxi', '^[0-9]{1,}([\.][0-9]{1,2})?$', ERR_CONF["form_ep1_maxi"], true, ERR_CONF["input_ep1_maxi"]);
	form.compFields('ep_mini', 'ep1_maxi', '', '', '<=', ERR_CONF["ep1_comp"]);
	form.numberVal('ep1_maxi', '', '<=', 14, ERR_CONF["ep1_maxi_limite"]);
	//
	form.ereg('ep_mini', '^[0-9]{1,}([\.][0-9]{1,2})?$', ERR_CONF["form_ep_mini"], true, ERR_CONF["input_ep_mini"]);
	form.numberVal('ep_mini', '', '>', 0, ERR_CONF["ep_mini_limite"]);
	form.ereg('ep2_maxi', '^[0-9]{1,}([\.][0-9]{1,2})?$', ERR_CONF["form_ep2_maxi"], true, ERR_CONF["input_ep2_maxi"]);
	form.compFields('ep_mini', 'ep2_maxi', '', '', '<', ERR_CONF["ep2_comp"]);
	form.compFields('larg_mini', 'larg2_maxi', '', '', '<=', ERR_CONF["larg2_comp"]);
	form.ereg('larg2_maxi', '^[0-9]{1,}([\.][0-9]{1,2})?$', ERR_CONF["form_larg2_maxi"], true, ERR_CONF["input_larg2_maxi"]);
	form.numberVal('larg2_maxi', '', '<=', 2200, ERR_CONF["larg2_maxi_limite"]);
	form.numberVal('ep2_maxi', '', '<=', 14, ERR_CONF["ep2_maxi_limite"]);
	//
	form.compFields('larg2_maxi', 'larg1_maxi', '', '', '<=', ERR_CONF["larg1_maxi_comp"]);
	form.compFields('ep2_maxi', 'ep1_maxi', '', '', '>=', ERR_CONF["ep1_maxi_comp"]);
	
	form.displayError();
	
	if(form.verification) form.form.submit();
}
	
function helpForm(f_cont, f_type, f_value)
{
	var div= document.getElementById(f_cont);
	if(f_type == "text")
	{
		div.innerHTML = f_value;
	}else if(f_type == "image")
	{
		div.innerHTML = "<img src='images/interface/"+f_value+"' alt='' border='0' />";
	}
}
