
// ignore les erreurs
//window.onerror=function () {
  //return true;
//}

//  barre de Statut
window.defaultStatus="E-Admin Hangar17";

// --- Fonctions ---

//*********** Affichage des infos des comptes ****************************
tab_affichage_detail= new Array();

function Affichage(champ,message){
 if(document.getElementById)
    document.getElementById(champ).innerHTML = message;
}


function RecupRef(ref,varpass){
	var variables="";
	var ref=""+ref+"";
	if(varpass!=""){
		window.open('actions.php?'+varpass+'&action=info_compte&ref='+ref, 'passvar');
		setTimeout("RecupRef('"+ref+"','');",500);
	}
	else{
		
		if(window.parent.frames["passvar"].ref==ref){
			variables=window.parent.frames["passvar"].RecupRef();
			if(variables!="undefined"){ 
				Affichage(ref,variables); 
				return(variables);
			}
			else{setTimeout("RecupRef('"+ref+"','')",500);}
		}
		else{setTimeout("RecupRef('"+ref+"','')",500);}
	}

	
}

function AfficheDetail(champ,varpass){

  // affichage et effacement du message.
  if(tab_affichage_detail[""+champ+""]!="ouvert"){
		document.images['i'+champ].src="data/ico-FlecheOver.gif"
		tab_affichage_detail[""+champ+""]="ouvert";		
		RecupRef(champ,varpass);
	}
  else{
		document.images['i'+champ].src="data/ico-FlecheOut.gif"
		tab_affichage_detail[""+champ+""]="";
		Affichage(champ,"");
	}
	
 }


//********************************
function Deconnexion(Vardeco){
	window.open("deconnexion.php?"+Vardeco,"deconection", "toolbar=NO,scrollbars=NO,location=NO,statusbar=NO,menubar=NO,resizable=NO,width=200,height=40,left=100,top=100");
}

function SupprFichier(ref,fichier_name){
	if (!window.confirm('Etes vous sur de vouloir supprimer le fichier '+fichier_name+'.\nCette action est iréverssible.'))return;	
	document.forms['form_categ'].elements['ref_suppr'].value=ref;
	document.forms['form_categ'].elements['action'].value	="supprimer";
	document.forms['form_categ'].submit();	
}


function FicheProduit(ref_fiche,username,sessionid){
	eval("ficheproduit = window.open('page.php?page=devis&action=ficheproduit&username="+username+"&sessionid="+sessionid+"', 'ficheproduit', 'toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=yes,width=600,height=600,left = 100,top = 100');");
	
}

function VERIF_CHAMP(formulaire,form_element,message){
	if(document.forms[formulaire].elements[form_element].value==""){ 
	   alert(message);
	   return(false);
	 }
	else return(true);
}

function VERIF_FORM(formulaire,action_form){
	 //alert('Verif form = '+formulaire+'\nAction Formulaire='+action_form);
	 switch(action_form){
		 case"ajouter_comptes":
		 	if(!VERIF_CHAMP(formulaire,'civilite','Vous devez indiquer une Civilité'))return;
			if(!VERIF_CHAMP(formulaire,'nom','Vous devez indiquer un Nom'))return;
			if(!VERIF_CHAMP(formulaire,'prenom','Vous devez indiquer un Prénom'))return;
			if(!VERIF_CHAMP(formulaire,'date_naiss_jour','Date de naissance. \nVous devez séléctionner un Jour'))return;
			if(!VERIF_CHAMP(formulaire,'date_naiss_mois','Date de naissance. \nVous devez séléctionner un Mois'))return;
			if(!VERIF_CHAMP(formulaire,'date_naiss_annee','Date de naissance. \nVous devez séléctionner un Année'))return;
			if(!VERIF_CHAMP(formulaire,'adresse','Vous devez indiquer une Adresse'))return;
			if(!VERIF_CHAMP(formulaire,'cp','Vous devez indiquer un Code Postal'))return;
			if(!VERIF_CHAMP(formulaire,'ville','Vous devez indiquer une Ville'))return;
			if(!VERIF_CHAMP(formulaire,'pays','Vous devez indiquer un Pays'))return;
			if(!VERIF_CHAMP(formulaire,'tel','Vous devez indiquer un n° de Téléphonne'))return;
			if(!VERIF_CHAMP(formulaire,'email','Vous devez indiquer une Adresse Email'))return;
			if(document.forms[formulaire].elements["droit"]!=undefined){
				if(!VERIF_CHAMP(formulaire,'droit','Vous devez sélectionner Le droit d\'accé pour ce compte'))return;
			}
		 break;
		 case"emailling":
			  var a=0;
			  document.forms[formulaire].elements["action"].value="visualiser";
			  saveForm(formulaire);
			
		 break; 
		  case"emailling_send":
			  var a=0;
			  
			  if(document.forms[formulaire].elements["mailling_on"].checked==true)a++;
			  if(document.forms[formulaire].elements["mailling_onoff"].checked==true)a++;
			  if(document.forms[formulaire].elements["mailling_extranet"].checked==true)a++;
			  if(document.forms[formulaire].elements["mailling_admextra"].checked==true)a++;
			  if(document.forms[formulaire].elements["mailling_tous"].checked==true)a++;
		  
			  if(a<1){
				  alert("Vous devez sélectionner un groupe de destinataire: a="+a);
				  return;
			  }
			  else{
				  if(!VERIF_CHAMP(formulaire,'mailling_object','Vous devez indiquer l\'object de votre Emailling'))return;
				  document.forms[formulaire].elements["action"].value="envoyer";
				  saveForm(formulaire);
			  }
		 break; 
		 case"distributeur":
			 if(!VERIF_CHAMP(formulaire,'pays','Vous devez séléctionner un pays/continent'))return;
		 break;
		 case"synchro_marque":
		 	 if(!VERIF_CHAMP(formulaire,'marque','vous devez séléctionner une marque'))return;
		 break;
		 case"ProduitAjouter":	 	
			//if(!VERIF_CHAMP(formulaire,'marque','Vous devez séléctionner une Marque'))return;
			if(!VERIF_CHAMP(formulaire,'reference','Vous devez indiquer une Référence'))return;
			if(!VERIF_CHAMP(formulaire,'famille','Vous devez séléctionner une Famille'))return;
			if(!VERIF_CHAMP(formulaire,'designation_fra','Vous devez indiquer au minimum une Désignation (français)'))return;
			if(!VERIF_CHAMP(formulaire,'prix_ttc','Vous devez indiquer un Prix Unitaire HT'))return;
		 break;
		 
		 default:
		  return;
		 break;
	 }//End Switch
	 document.forms[formulaire].submit();
}


function VIDE(){
	
}

function Aff_Photo_Recherche(photomini,photobig)
{
	photoimage = new Image(); photoimage.src=photomini;
	photolien = new Image(); photolien.src=photobig;
	parent.document.all.ici.innerHTML="<a href=\""+ photolien.src + "\" target=_blank><img src=\"" + photoimage.src + "\" border='0'></a>";
}

function SUB_SEARCH(recherche,lang)
{
	//var motif=/+/;
	//alert(recherche);
	tableau=recherche.split("\+");
	var i=0;
	if(tableau.length>1){
		while(i<tableau.length){
		tmprecherche=tableau[i]+"\\\+";
			if(i==0){newrecherche=tmprecherche;}
			else{newrecherche+=tmprecherche;}
		i=i+1;
		}
	}
	else{newrecherche=recherche;}
	document.getElementById("iframe").innerHTML="<iframe src='iframe.php?from=recherche_nom&recherche="+newrecherche+"&lang="+lang+"' height='300' width='400' frameborder='1'  scrolling='auto'></iframe>";

}

function UPDATE(lang)
{
	document.getElementById("iframe").innerHTML="<iframe src='iframe.php?from=update&lang="+lang+"' height='360' width='550' frameborder='1'  scrolling='auto'></iframe>";
}
function SUB_FORM(formulaire,name_action,value_action,debug){
  
	//===================  Action definit ====================

	switch(name_action){
		
		case("_self"):
			document.forms[formulaire].elements["action"].value=value_action;
		break;
		case("_synchro"):
			document.forms[formulaire].elements["etape_synchro"].value=value_action;
		break;
		case("_edite_fiche"):
			document.forms[formulaire].elements["action"].value="editer";
			document.forms[formulaire].elements["ref_fiche"].value=value_action;
		break;
		case("_suppr_fiche"):
			document.forms[formulaire].elements["action"].value="supprimer";
			document.forms[formulaire].elements["ref_fiche"].value=value_action;
		break;
		case("_identifiants"):
			document.forms[formulaire].elements["action"].value="";
			if(document.forms[formulaire].elements["bdd"]!= undefined)document.forms[formulaire].elements["bdd"].value="";
		break;
		case("_Supprimer_nuance"):
			document.forms[formulaire].elements["supprimer_nuance"].value=value_action;
			document.forms[formulaire].elements["action"].value='ajouter';
		break;
		case("_Sup_photo_diapo"):
			document.forms[formulaire].elements["supprimer_photo"].value=value_action;
			document.forms[formulaire].elements["action"].value='ajouter';
		break;
	}//End switch(name_action)

	//===================  Debugeur ==========================
	if(debug == true ){
		var aff
		aff="\n";
		//document.forms[formulaire].elements["action"].value=value_action;
		aff= aff+"If name_action ="+name_action+" \nvalue_action ="+value_action+"\n";
		aff= aff+"nom: \""+document.forms[formulaire].elements["action"].name+"\" value :"+document.forms[formulaire].elements["action"].value+"  \n";
		for (var i=0; i<document.forms[formulaire].elements.length; i++) {
			aff= aff+" num= "+i+"  nom: \""+document.forms[formulaire].elements[i].name+"\" value :"+document.forms[formulaire].elements[i].value+"  \n";
		}	
		alert(aff);
	}//End if(debug == true )

	//===================  Soumission ========================
	//document.forms[formulaire].submit();
	switch(document.forms[formulaire].elements["type"].value){
		case("docu"):
			document.getElementById("iframe").innerHTML="<iframe src='iframe.php?from=docu&categorie="+document.forms[formulaire].elements["id_categ"].value+"&lang="+document.forms[formulaire].elements["lang"].value+"' height='360' width='550' frameborder='1'  scrolling='auto'></iframe>";
			break;
		case("extranet"):
			document.getElementById("iframe").innerHTML="<iframe src='iframe.php?from=extranet&categorie_produit="+document.forms[formulaire].elements["categorie_produit"].value+"&lang="+document.forms[formulaire].elements["lang"].value+"' height='300' width='400' frameborder='1'  scrolling='auto'></iframe>";
			break;
		case("prod"):
			document.getElementById("iframe").innerHTML="<iframe src='iframe.php?from=recherche&categorie="+document.forms[formulaire].elements["id_categ"].value+"&lang="+document.forms[formulaire].elements["lang"].value+"' height='300' width='400' frameborder='1'  scrolling='auto'></iframe>";
			break;
	}
}


function AFF_IMG(id_img,rep_photo,src_img,var_pass,action,ref) {
	   if(src_img=='')src_img='photo-diaporama-defaut.jpg';
       document.images['p'+id_img].src=rep_photo+"mini_"+src_img;
	   //alert('actions.php?'+var_pass+'&action='+action+'&id_img='+id_img+'&src_img='+src_img+'&ref='+ref, 'passvar');
	   window.open('actions.php?'+var_pass+'&action='+action+'&id_img='+id_img+'&src_img='+src_img+'&ref='+ref, 'passvar'); 	   	   
   }


function AFF_IMG2(id_img,rep_photo,src_img) {
	   if(src_img=='')src_img='photo-diaporama-defaut.jpg';
       document.images[id_img].src=rep_photo+"mini_"+src_img;
	   //alert('actions.php?'+var_pass+'&action='+action+'&id_img='+id_img+'&src_img='+src_img+'&ref='+ref, 'passvar');
	   //window.open('actions.php?'+var_pass+'&action='+action+'&id_img='+id_img+'&src_img='+src_img+'&ref='+ref, 'passvar'); 	   	   
   }
   

function AFF_NUA(id_img,rep_photo,src_img,var_pass,action,ref) {
	   if(src_img=='')src_img='photo-diaporama-defaut.jpg';
       document.images['n'+id_img].src=rep_photo+"mini_"+src_img;
	   //alert('actions.php?'+var_pass+'&action='+action+'&id_img='+id_img+'&src_img='+src_img+'&ref='+ref, 'passvar');
	   window.open('actions.php?'+var_pass+'&action='+action+'&id_img='+id_img+'&src_img='+src_img+'&ref='+ref, 'passvar'); 	   	   
   }

function PaletteCouleur(path,varform,code)
{
  var code;
  var varform;
  var path;
  window.open(path+'/palette.php?varform='+varform+'&couleur='+code,'palette','toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=200,height=150')
}

function mouseMove (evt) { 
		var x=0; var y=0;
		if (document.layers) {
			x=evt.x; y=evt.y;
		} 
		if (document.all) {
			x=event.clientX; y=event.clientY;
		} else {
			if (document.getElementById) {
				x=evt.clientX; y=evt.clientY; 
			}
		}
		document.x=x; 
		document.y=y ;
	
}


	//if (document.layers) 
	//document.captureEvents(Event.MOUSEMOVE); 
	//if (document.layers || document.all) 
	//document.onmousemove = mouseMove; 
	//if (document.addEventListener) 
	//document.addEventListener('mousemove', mouseMove, true); 

function historique(url,Varform){
	window.open(url+'?'+Varform, 'Historique', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes,width=420,height=300,left=100,top=100');
}

function POPUP(URL,Width,Height,Varform,Toolbar,Scrollbars,Location,Statusbar,Menubar,Resizable,Left,Top) {
day = new Date();
id = day.getTime();

if(Width=='')      {Width=400;}
if(Height=='')     {Height=20;}
if(Toolbar=='')    {Toolbar=0;}
if(Scrollbars=='') {Scrollbars=0;}
if(Location=='')   {Location=0;}
if(Statusbar=='')  {Statusbar=0;}
if(Menubar=='')    {Menubar=0;}
if(Resizable=='')  {Resizable=0;}


Left=document.x;
Top=document.y;
	
if(Left=='')  {Left=100;}
if(Top =='')  {Top=100;}

eval("page" + Varform + " = window.open(URL, '" + Varform + "', 'toolbar="+Toolbar+",scrollbars="+Scrollbars+",location="+Location+",statusbar="+Statusbar+",menubar="+Menubar+",resizable="+Resizable+",width="+Width+",height="+Height+",left = 100,top = 100');");
}

function IMG_CHANGE(IdImg,SrcImg){
	document.images[IdImg].src=SrcImg;
}

// Fonction du choix de l'application
function application(formulaire,nbr){

   var aff;
   var pass_var="";
   document.forms[formulaire].target="visualisation"
   document.forms[formulaire].action.value="visualiser"
  POPUP('popup.php','540','450','visualisation','no','yes','no','yes','no','yes','0','0');
  document.forms[formulaire].submit();
  document.forms[formulaire].target="_self"
  document.forms[formulaire].action.value="enregistrement"
    
}

//effecer un formulaire

function RAS(formulaire)
{
 for (var i=0; i<formulaire.elements.length; i++) {
      document.AVIS.elements[i].value="";
      //formulaire.elements[i].value="";
    }
}

//verificateur formulaire indentifi entreprise
 function verifForm(formulaire){

		 
	 if( formulaire.siret.value == "")
         alert('Le champ siret est vide !!!');
	
	 else if( formulaire.naf.value == "")
         alert(' Le champ Naf est vide !!!');
		 
	 else if( formulaire.dirigeant_age.value == "")
         alert(' Le champ --  Dirigeant -- Age est vide !!!');
		 
	 //else if( formulaire.cp.value == "")
        // alert(' Le champ -- Entreprise : Adresse et Note  -- Code Postal est vide !!!');
		 
	 else if( formulaire.cc.value == "")
         alert(' Le champ -- Entreprise : Adresse et Note  -- Code Commune est vide !!!');	 
	
	 else if( formulaire.email.value == "")
         alert(' Le champ -- Entreprise : Adresse et Note  -- Email est vide !!!');
		 
     else
    formulaire.submit();
    }


//verificateur formulaire indentifi administration
 function verifForm2(formulaire){

	 if( formulaire.adresse.value == "")
         alert(' Le champ Adresse est vide !!!');
		 
	 else if( formulaire.ville.value == "")
         alert(' Le champ Ville est vide !!!');
		 
	 else if( formulaire.cp.value == "")
         alert(' Le champ Code Postal est vide !!!');
	
	 else if( formulaire.tel.value == "")
         alert(' Le champ Tél est vide !!!');	 
	 
     else
    formulaire.submit();
    }

// Fonction de reroutage des formulaires
function MM_jumpMenu(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function Champs_jump(url,varpass,value){
  var url;
  var varpass;
  document.location.replace(url+'?'+value.name+'='+value.value+'&'+varpass);
}

// affiche une boite de dialogue de confirmation et retourne la reponse choisie
function Confirm(message) {
  if (!message) { message="Confirmation"; }
  return (window.confirm(message));
} // fin dialogueConfirm(message)


// affiche une boite de dialogue d'information
function Info(message) {
  if (!message) { message="Information"; }
  window.alert(message);
  return true;
} // fin dialogueInfo(message)

/*
variables ="<table width='570' border='0' cellspacing='0' cellpadding='0'> " ;
		variables+="<tr> " ;
		variables+="<td colspan='4' class='Tab-BackgrColor3-2'><img src='data/spacer.gif' width='570' height='5'></td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td colspan='4'><img src='data/spacer.gif' width='10' height='10'></td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td width='170'><table width='170' border='0' cellspacing='0' cellpadding='0'> " ;
		variables+="<tr> " ;
		variables+="<td width='150'><div align='right' class='Tab-TexteIntituleGras'>Administrateur : </div></td> " ;
		variables+="<td width='20'><div align='center'><img src='data/compte-actif-on.gif' width='16' height='16'></div></td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td width='150'><div align='right' class='Tab-TexteIntituleGras'>Extranet : </div></td> " ;
		variables+="<td width='20'><div align='center'><img src='data/compte-actif-off.gif' width='16' height='16'></div></td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td><div align='right' class='Tab-TexteIntituleGras'>Produits : </div></td> " ;
		variables+="<td><div align='center'><img src='data/compte-actif-off.gif' width='16' height='16'></div></td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td width='150'><div align='right' class='Tab-TexteIntituleGras'>S.A.V : </div></td> " ;
		variables+="<td width='20'><div align='center'><img src='data/compte-actif-off.gif' width='16' height='16'></div></td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td width='150'><div align='right' class='Tab-TexteIntituleGras'>Compte Multi Utilisateur : </div></td> " ;
		variables+="<td width='20'><div align='center'><img src='data/compte-actif-on.gif' width='16' height='16'></div></td> " ;
		variables+="</tr> " ;
		variables+="</table></td> " ;
		variables+="<td width='20' align='left' valign='top'>&nbsp;</td> " ;
		variables+="<td width='361' align='left' valign='top'><table width='360' border='0' cellspacing='0' cellpadding='0'> " ;
		variables+="<tr> " ;
		variables+="<td><div align='right' class='Tab-TexteIntituleGras'>Derni&egrave;re Connection : </div></td> " ;
		variables+="<td><div align='left' class='Tab-TexteIntitule'>&nbsp;Samedi 21/05/2004</div></td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td width='160'><div align='right' class='Tab-TexteIntituleGras'>T&egrave;l&egrave;phonne : </div></td> " ;
		variables+="<td width='200'><div align='left'>&nbsp;<span class='Tab-TexteIntitule'>05 46 49 85 75</span></div></td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td width='160'><div align='right' class='Tab-TexteIntituleGras'>Mobile : </div></td> " ;
		variables+="<td width='200'><div align='left'>&nbsp;<span class='Tab-TexteIntitule'>05 46 49 85 75</span></div></td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td width='160'><div align='right' class='Tab-TexteIntituleGras'>Email : </div></td> " ;
		variables+="<td width='200'><div align='left'>&nbsp;<a href='mailto:info@hangar17.com' class='Tab-TexteIntitule'>info@hangar17.com</a></div></td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td><div align='right' class='Tab-TexteIntituleGras'>Historique des connections : </div></td> " ;
		variables+="<td>&nbsp;<a href='javascript:popup' class='Tab-TexteIntitule'>Voir l'historique</a></td> " ;
		variables+="</tr> " ;
		variables+="</table></td> " ;
		variables+="<td width='19'>&nbsp;</td> " ;
		variables+="</tr> " ;
		variables+="<tr> " ;
		variables+="<td>&nbsp;</td> " ;
		variables+="<td align='left' valign='top'>&nbsp;</td> " ;
		variables+="<td align='left' valign='top'>&nbsp;</td> " ;
		variables+="<td>&nbsp;</td> " ;
		variables+="</tr> " ;
		variables+="</table> " ;
		*/
