/// close messageBox
function closeBox(){
	document.getElementById('fondBox').style.display="none";
	document.getElementById('messageBox').style.display="none";
}

/// print reponse
 function PSR_imprimer () {
       var PSR_f1 = null;
      var PSR_content=document.getElementById('reponse').innerHTML;
       //var PSR_title=document.getElementsByTagName('title')[0].innerText;
       if (PSR_f1) {if(!PSR_f1.closed) PSR_f1.close();}
       PSR_f1 = window.open ('',"PSR_f1", "height=500,width=800,menubar=yes,scrollbars=yes,resizable=yes,,left=10,top=10"); ;
       PSR_f1.document.open();
	    var text = PSR_content.toString() ;
		var maReg = new RegExp( 'Search results', "gi") ;
		var resultat = text.replace( maReg, 'Components Source Directory on www.componentssource.com' ) ;
       PSR_f1.document.write("<html><head><title>Components Source directory</title><style>#reponseTable{width:100%;vertical-align:top;}#reponseTable td{vertical-align:top;font-size:10px;width:50%}.inter{color:grey;margin-left:80px;width:100%}.titre{color:red;font-weight:bold} UL{font-size:12px;list-style-type:none}BODY{top:0px}LEGEND{font-size:14px;font-weight:bold;}</style></head><body onLoad='window.print();' style='font-size:11px;'>"+resultat+"<script>document.getElementById(\"printer\").style.visibility=hidden;</script></body></html>");
       PSR_f1.document.close();
      PSR_f1.document.getElementById('printer').style.visibility='hidden';
       ///PSR_f1.document.getElementById('PSR_print').style.display='none';
       PSR_f1.focus();
   }

  
/// remplace les "&" par ":::" pour ?viter d'etre vu comme un parametre d'url
function cleanStr( text, stringToFind, stringRemplacement, champDeSortie ){
var text = text.toString() ;
var maReg = new RegExp( stringToFind, "gi") ;
var resultat = text.replace( maReg, stringRemplacement ) ;
return resultat;
}

/// remplace search results par components source directory www.componentssource.com/directory/
function cleanStr( text, stringToFind, stringRemplacement, champDeSortie ){
var text = text.toString() ;
var maReg = new RegExp( stringToFind, "gi") ;
var resultat = text.replace( maReg, stringRemplacement ) ;
return resultat;
}

//// montre ou cache un div
function switchDIV(id) {
var obj = document.getElementById(id);
if (obj){
	if (obj.style.display == "block"){
		obj.style.display = "none";
	}else{
		 obj.style.display = "block";
	
	}
}
}

//// montre ou cache un div
function switchDIVfromSelect(id, selectedValue) {
var obj = document.getElementById(id);
if (obj){
	if (selectedValue == -1){
		obj.style.display = "none";
	}else{
		 obj.style.display = "block";
	
	}
}
}

// dans un input : rend un champs <select obligatoire>
function filtreIdObligatoire(id, id_obligatoire){
var obj = document.getElementById(id);
var objObligatoire = document.getElementById(id_obligatoire);
if (objObligatoire){
	if (objObligatoire.value == -1){
		alert("Please select a country first");
		objObligatoire.focus();
	}
}
}

function disabledRestElementsDistr(id_ok){
/// id_ok est l'?l?ment qui  reste disponible
/// les autres sont d?sactiv?s
	if (id_ok == 'mod1' ){
		document.getElementById('paysDistr').disabled = false;
		document.getElementById('autocomplete').disabled = false;
		document.getElementById('search1').disabled = false;
		document.getElementById('familleProduit').value = '-1';
		document.getElementById('categoriesProduits').innerHTML = '';
		document.getElementById('familleProduit').disabled = true;
		document.getElementById('paysDistr2').disabled = true;
		document.getElementById('autocomplete2').disabled = true;
		document.getElementById('search2').disabled = true;
	}
	if (id_ok == 'mod2' ){
		//document.getElementById('familleProduit').disabled = true;
		document.getElementById('paysDistr').disabled = true;
		document.getElementById('paysDistr2').disabled = true;
		document.getElementById('autocomplete').disabled = true;
		document.getElementById('autocomplete').value = '';
		document.getElementById('paysDistr').value = '-1';
		document.getElementById('autocomplete2').disabled = true;
		document.getElementById('autocomplete2').value = '';
		document.getElementById('paysDistr2').value = '-1';
		document.getElementById('search2').disabled = true;
		document.getElementById('search1').disabled = true;
		document.getElementById('familleProduit').disabled = false;
	}
	if (id_ok == 'mod3' ){
		document.getElementById('familleProduit').disabled = true;
		document.getElementById('familleProduit').value = '-1';
		document.getElementById('categoriesProduits').innerHTML = '';
		document.getElementById('paysDistr').disabled = true;
		document.getElementById('autocomplete').disabled = true;
		document.getElementById('autocomplete').value = '';
		document.getElementById('paysDistr').value = '-1';
		document.getElementById('search1').disabled = true;
		document.getElementById('paysDistr2').disabled = false;
		document.getElementById('autocomplete2').disabled = false;
		document.getElementById('search2').disabled = false;
	}
}

function disabledRestElementsFabr(id_ok){
/// id_ok est l'?l?ment qui  reste disponible
/// les autres sont d?sactiv?s
	if (id_ok == 'mod1' ){
		document.getElementById('search').disabled = false;
		document.getElementById('autocomplete').disabled = false;
		document.getElementById('familleProduit').value = '-1';
		document.getElementById('categoriesProduits').innerHTML = '';
		document.getElementById('familleProduit').disabled = true;

	}
	if (id_ok == 'mod2' ){
	    document.getElementById('familleProduit').disabled = false;
		document.getElementById('autocomplete').value = '';
		document.getElementById('search').disabled = true;
		document.getElementById('autocomplete').disabled = true;

	}
}

function MailFaux(ValeurInput)
{
  if (ValeurInput!='')
  {
	  dotPos = ValeurInput.indexOf('.');
	  if (dotPos>0)
	  {
		  if (dotPos <= (ValeurInput.length - 3))
		  {
			  var Regex = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");		  
	    	  var Result = Regex.test(ValeurInput);
			  if (Result) {return false;}
			  else {return true;}
		   }	  
		   else 
		  {
		  	  return true;
		  }				
		}
		else 
		{
			return true;
		}
	}
}


/// verif formulaire
function verifForm(theForm){

  if (theForm.nom.value == ""){
    alert("Please enter a value for the \"Name\" field.");
    theForm.nom.focus();
    return (false);
  }

  if (theForm.nom.value.length < 1){
    alert("Please enter at least 1 characters in the \"Name\" field.");
    theForm.nom.focus();
    return (false);
  }

  if (theForm.fonction.value == "") {
    alert("Please enter a value for the \"Job Title\" field.");
    theForm.fonction.focus();
    return (false);
  }

  if (theForm.fonction.value.length < 1){
    alert("Please enter at least 1 characters in the \"Job Title\" field.");
    theForm.fonction.focus();
    return (false);
  }

  if (theForm.email.value == "") {
    alert("Please enter a value for the \"Email\" field.");
    theForm.email.focus();
    return (false);
  }

  if (MailFaux(theForm.email.value) == true){
    alert("Please enter a valid  Email address.");
    theForm.email.focus();
    return (false);
  }
  
  
	  if (theForm.compagnie.value == "") {
	    alert("Please enter a value for the \"Company\" field.");
	    theForm.compagnie.focus();
	    return (false);
	  }
	
	  if (theForm.compagnie.value.length < 2){
	    alert("Please enter at least 2 characters in the \"Company\" field.");
	    theForm.compagnie.focus();
	    return (false);
	  }


  if (theForm.ville.value == ""){
    alert("Please enter a value for the \"City\" field.");
    theForm.ville.focus();
    return (false);
  }

  if (theForm.ville.value.length < 2){
    alert("Please enter at least 2 characters in the \"City\" field.");
    theForm.ville.focus();
    return (false);
  }
  
   if (theForm.pays.value == "-1"){
    alert("Please select your country.");
    theForm.pays.focus();
    return (false);
  }
  
   if ((theForm.pays.value == 999) ){
    	if (theForm.otherCountry.value.length < 2){
			alert("Please indicate an other country.");
			theForm.otherCountry.focus();
			return (false);
		}
  }

  if (theForm.telephone_compagnie.value == ""){
    alert("Please enter a value for the \"Phone\" field.");
    theForm.telephone_compagnie.focus();
    return (false);
  }

  if (theForm.telephone_compagnie.value.length < 3){
    alert("Please enter a correct phone number.");
    theForm.telephone_compagnie.focus();
    return (false);
  }

  if (theForm.fax_compagnie.value == ""){
    alert("Please enter a value for the \"Fax\" field.");
    theForm.fax_compagnie.focus();
    return (false);
  }

  if (theForm.fax_compagnie.value.length < 3) {
    alert("Please enter more characters in the \"Fax\" field.");
    theForm.fax_compagnie.focus();
    return (false);
  }
  
  if (theForm.statusAtAddress.value == "-1"){
  	alert("Please indicate the status of your company.");
    theForm.statusAtAddress.focus();
    return (false);
  }
  
  if (theForm.mainActivity.value == "-1"){
  	alert("Please indicate your main activity.");
    theForm.mainActivity.focus();
    return (false);
  }


  if ( (theForm.order[0].checked == false) && (theForm.order[1].checked == false) ){
	alert("Please check your order.");
	return (false);
  }
	  
  if (theForm.order[0].checked == true){
   		if (theForm.Shipping_Mode.value == "-1"){
			alert("Please select a delivery cost for the printed version.");
			theForm.Shipping_Mode.focus();
			 return (false);
		}else{
			if (theForm.Shipping_Mode.value == "own_express_mail"){
				if (theForm.mailAccountNumber.value == '' ){
					alert("Please indicate your express mail account number.");
					theForm.mailAccountNumber.focus();
			 		return (false);
			 	}
			 	if (theForm.ExpressCy.value == '-1' ){
					alert("Please indicate your express mail company.");
					theForm.ExpressCy.focus();
			 		return (false);
			 	}
			 	
			 }
		}
   }
	
  return (true);
}


/////////////////////////////// ajoute ou supprime des index dans un select /////////////////////
	function supprimer(l1,l2) {
		if (l1.options.selectedIndex>=0) {
			cut = l1.options[l1.options.selectedIndex].value;
			cutForRetour = cut.split('->');
			
			o=new Option(cutForRetour[1],l1.options[l1.options.selectedIndex].value, "selected");
			l2.options[l2.options.length]=o;
			l1.options[l1.options.selectedIndex]=null;
		}else{
			alert("Please select a product to add or to delete");
		}		
	}
	
	function ajouter(l1,l2) {
		if (l1.options.selectedIndex>=0) {
			o=new Option(l1.options[l1.options.selectedIndex].value,l1.options[l1.options.selectedIndex].value, "selected");
			l2.options[l2.options.length]=o;
			l1.options[l1.options.selectedIndex]=null;
		}else{
			alert("Please select a product to add or to delete");
		}		
	}
