//-------- Centrer une Popup -------------------
function lire_wave() 
{
	eval("document.wave.play();");
}
//-------- Centrer une Popup -------------------
function centrer_popup(url,nom,largeur,hauteur,options) 
{	
	//alert("largeur="+largeur+" hauteur="+hauteur);
	//alert("screen.height="+screen.height+" screen.width="+screen.width);
	var haut=(screen.height-hauteur)/2-10;
	var gauche=(screen.width-largeur)/2;
	var w=window.open(url,nom,"top="+haut+",left="+gauche+",width="+largeur+",height="+hauteur+","+options);
	//alert("haut="+haut+" gauche="+gauche);
	w.document.close();
	w.focus();
}

//----------- Ouverture fenêtre Callback --------------
function ouvrir_call($ref,$sujet,$agence)
{
	var hauteur = 500;
	var largeur = 700;
	var haut=(screen.height-hauteur)/2;
	var Gauche=(screen.width-largeur)/2;
	var w=window.open("callback.php?ref="+$ref+"&sujet="+$sujet+"&agence="+$agence,"call","top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+"menubar=no,scrollbars=no,statusbar=no");
	w.document.close();
	w.focus();
}

//----------- Ouverture fenêtre Callback --------------
function ouvrir_agence($id)
{
	var hauteur = 500;
	var largeur = 700;
	var haut=(screen.height-hauteur)/2;
	var Gauche=(screen.width-largeur)/2;
	var w=window.open("agence.php?id="+$id,"agence","top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+"menubar=no,scrollbars=no,statusbar=no");
	w.document.close();
	w.focus();
}

//----------- Ouverture fenêtre Annonce --------------
function ouvrir_annonce($id)
{
	var largeur = 850;
	var hauteur = 650;
	var haut=(screen.height-hauteur)/2-40;
	var Gauche=(screen.width-largeur)/2;
	var w=window.open("annonce.php?id="+$id,"annonce","top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+"menubar=no,scrollbars=yes,statusbar=yes");
	w.document.close();
	w.focus();
}

//----------- Ouverture fenêtre Annonce Directe --------------
function ouvrir_annonce_directe($ref)
{
	var largeur = 850;
	var hauteur = 650;
	var haut=(screen.height-hauteur)/2-40;
	var Gauche=(screen.width-largeur)/2;
	var w=window.open("annonce.php?ref="+$ref,"annonce","top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+"menubar=no,scrollbars=yes,statusbar=yes");
	w.document.close();
	w.focus();
}

//----------- Confirmation suppression mandat --------------
function mail(user,domaine,ext,lien)
{
	document.write("<a href='mailto:");
	document.write(user+"@"+domaine+"."+ext);
	document.write("'>"+lien+"</a>");
}

//----------- Confirmation suppression mandat --------------
function supprimer_mandat(man_id,man_ref)
{
	if (confirm("Voulez-vous supprimer le mandat "+man_ref+" ?"))
	{
		document.location="mandat_suppr.php?man_id="+man_id;
	}
}

//----------- Confirmation suppression utilisateur --------------
function supprimer_utilisateur(uti_id)
{
	var new_user = prompt("Numéro du remplaçant :", "");
	if (confirm("Voulez-vous supprimer l'utilisateur "+uti_id+" et affecter ses mandat à l\'utilisateur "+new_user+" ?"))
	{
		document.location="utilisateur_suppr.php?uti_id="+uti_id+"&new_user="+new_user;
	}
}

//----------- Confirmation suppression contact --------------
function supprimer_contact(man_id,con_id)
{
	if (confirm("Voulez-vous supprimer ce contact ?"))
	{
		//document.location="contact_suppr.php?man_id="+man_id+"&con_id="+con_id;
		var w=window.open("contact_suppr.php?con_id="+con_id,"annonce","width=1,height=1");
		//w.close();
	}
}

//----------- Confirmation suppression piece --------------
function supprimer_piece(man_id,pie_id)
{
	if (confirm("Voulez-vous supprimer cette pièce ?"))
	{
		//document.location="piece_suppr.php?man_id="+man_id+"&con_id="+con_id;
		var w=window.open("piece_suppr.php?pie_id="+pie_id,"annonce","width=1,height=1");
		//w.close();
	}
}

//----------- Confirmation suppression photo --------------
function supprimer_photo(pho_id)
{
	if (confirm("Voulez-vous supprimer la photo ?"))
	{
		document.location="photo_suppr.php?pho_id="+pho_id;
	}
}

//----------- Confirmation archivage call --------------
function archiver_call(call_id)
{
	if (confirm("Voulez-vous archiver ce call ?"))
	{
		document.location="callback_archiver.php?call_id="+call_id;
	}
}

//----------- Redimension d'une image avec hauteur maxi --------------
function resize_hauteur (image , haut)
{
	if (image.height > haut)
	{
		image.width = image.width * haut / image.height;
		image.height = haut;
	}
}

//----------- Test format Email --------------
function isEmail(email)
{
     if ( ( email.indexOf("@") == -1 ) 
	   || ( email.indexOf("@") == 0 ) 
	   || ( email.indexOf("@") != email.lastIndexOf("@") ) 
	   || ( email.indexOf(".") == email.indexOf("@")-1 ) 
	   || ( email.indexOf(".") == email.indexOf("@") +1 ) 
	   || ( email.indexOf("@") == email.length -1 ) 
	   || ( email.indexOf (".") == -1 ) 
	   || ( email.lastIndexOf (".") == email.length -1 ) )
         return false;
      else
         return true;
}

//----------- Test format Téléphone français --------------
function isTelephone(num_tel) 
{ 
    // Definition du motif a matcher 
    var regex = new RegExp(/^(01|02|03|04|05|06|07|08)[0-9]{8}/gi); 
     
    // Definition de la variable booleene match 
    var match = false; 
     
    // Test sur le motif 
    if(regex.test(num_tel)) 
    { 
        match = true; 
    } 
     else 
    { 
        match = false; 
    } 
     
    // On renvoie match 
    return match; 
} 

//----------- Date du jour --------------
function date() 
{
   var ladate = new Date();
   var annee = ladate.getYear();
   var jour;
   var journ = ladate.getDate();
   
   if (navigator.appName == "Netscape") 
	annee = annee + 1900;
      
   switch (ladate.getDay())
   {   
   		case 0 : jour = "Dimanche"; break;   
		case 1 : jour = "Lundi"; break;   
		case 2 : jour = "Mardi"; break;
		case 3 : jour = "Mercredi"; break;
		case 4 : jour = "Jeudi"; break;
		case 5 : jour = "Vendredi"; break;
		case 6 : jour = "Samedi"; break;
		default: jour = "jour inconnu";
   }
	
   switch (ladate.getMonth())
   {   
   		case 0  : mois = "Janvier"; break;   
		case 1  : mois = "Février"; break;   
		case 2  : mois = "Mars"; break;
		case 3  : mois = "Avril"; break;
		case 4  : mois = "Mai"; break;
		case 5  : mois = "Juin"; break;
		case 6  : mois = "Juillet"; break;
		case 7  : mois = "Août"; break;
		case 8  : mois = "Septembre"; break;
		case 9  : mois = "Octobre"; break;
		case 10 : mois = "Novembre"; break;
		case 11 : mois = "Décembre"; break;	
		default : jour = "mois inconnu";
   }   	 
	
   return jour + " " + journ + " " + mois + " " + annee;
}
