chrgdebut = new Date;
chrgdebut = chrgdebut.getTime();
function tempschargement()
{
	fin = new Date;
	fin = fin.getTime();
	secondes = (fin-chrgdebut)/1000;
	window.status= secondes;
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------
function popupAlert(idAgence) {
	window.open('/entreagences/fo/consult/popupUnUpdatedGoods.asp?id=' + idAgence, 'popupUnUpdatedGoods_window', 'resizable=yes, scrollbars=yes, width=800, height=350');
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------


function closeAdmin(){
	document.form.frmMenu.submit();
}

var Contactproprio = new Array(0);
var Contactnotaire = new Array(0);

function defineContactproprio(id,cabinet,nom ,prenom ,adresse, dep, ville, codepostal, pays, tel, fax, portable, bureau, email, autres, genre, origine, typesociete, portable2){
	Contactproprio[Contactproprio.length] = new Array(id,cabinet,nom ,prenom ,adresse, dep, ville, codepostal, pays, tel, fax, portable, bureau, email, autres, genre, origine, typesociete, portable2);
}

function defineContactnotaire(id,cabinet,nom ,prenom ,adresse, dep, ville, codepostal, pays, tel, fax, portable, bureau, email, autres, genre){
	Contactnotaire[Contactnotaire.length] = new Array(id,cabinet,nom ,prenom ,adresse, dep, ville, codepostal, pays, tel, fax, portable, bureau, email, autres, genre);
}

function selectContact(champ){
	var typecontact = document.form1.typecontact.value;
	//var field = eval('document.form1.selNom' + champ);
	//var i = field.options[field.selectedIndex].value;
	var sindex = document.getElementById("selNom" + champ).selectedIndex;
	var i = document.getElementById("selNom" + champ)[sindex].value;
	if (i!=''){
		eval('document.form1.fld_id_' + champ + '.value=Contact'+champ+'['+i+'][0]');
		eval('document.form1.fld_nom_' + champ + '.value=unescape(Contact'+champ+'['+i+'][2])');
		eval('document.form1.fld_prenom_' + champ + '.value=unescape(Contact'+champ+'['+i+'][3])');
		eval('document.form1.fld_adresse_' + champ + '.value=unescape(Contact'+champ+'['+i+'][4])');
		eval('document.form1.fld_codedepartement_' + champ +'.value=Contact'+champ+'['+i+'][5]');
		eval('document.form1.fld_ville_' + champ + '.value=Contact'+champ+'['+i+'][6]');
		eval('document.form1.fld_ville_' + champ + 'libelle.value=unescape(Contact'+champ+'['+i+'][6])');
		eval('document.form1.fld_codepostal_' + champ + '.value=Contact'+champ+'['+i+'][7]');
		eval('document.form1.fld_codepays_' + champ +'.value=Contact'+champ+'['+i+'][8]');
		eval('document.form1.fld_tel_' + champ + '.value=Contact'+champ+'['+i+'][9]');
		eval('document.form1.fld_fax_' + champ + '.value=Contact'+champ+'['+i+'][10]');
		eval('document.form1.fld_portable_' + champ + '.value=Contact'+champ+'['+i+'][11]');
		eval('document.form1.fld_bureau_' + champ + '.value=Contact'+champ+'['+i+'][12]');
		eval('document.form1.fld_email_' + champ + '.value=Contact'+champ+'['+i+'][13]');
		eval('document.form1.fld_autre_' + champ + '.value=unescape(Contact'+champ+'['+i+'][14])');
		eval('document.form1.fld_portable2_' + champ + '.value=unescape(Contact'+champ+'['+i+'][18])');
		SelectValueInSelect(eval('document.form1.fld_genre_' + champ),eval('Contact'+champ+'['+i+'][15]'));		
		eval('document.form1.fld_cabinet_' + champ + '.value=unescape(Contact'+champ+'['+i+'][1])');
		if (typecontact==1)
		{
			eval('document.form1.fld_typesociete_' + champ + '.value=unescape(Contact'+champ+'['+i+'][17])');
		}
		if (typecontact==1 || typecontact==2)
		{
			SelectValueInSelect(eval('document.form1.fld_origine_' + champ),eval('Contact'+champ+'['+i+'][16]'));
		}
		if (champ=='contact')
		{
			document.form1.fld_codedepartement_contactlibelle.value=eval('unescape(Contactcontact[i][19])');
		}
	}else{
		eval('document.form1.fld_id_' + champ + '.value=\'\'');
		eval('document.form1.fld_nom_' + champ + '.value=\'\'');
		eval('document.form1.fld_prenom_' + champ + '.value=\'\'');
		eval('document.form1.fld_adresse_' + champ + '.value=\'\'');
		eval('document.form1.fld_codedepartement_' + champ +'.value=\'\'');
		eval('document.form1.fld_ville_' + champ + '.value=\'\'');
		eval('document.form1.fld_ville_' + champ + 'libelle.value=\'\'');
		eval('document.form1.fld_codepostal_' + champ + '.value=\'\'');
		eval('document.form1.fld_codepays_' + champ +'.value=\'FR\'');
		eval('document.form1.fld_tel_' + champ + '.value=\'\'');
		eval('document.form1.fld_fax_' + champ + '.value=\'\'');
		eval('document.form1.fld_portable_' + champ + '.value=\'\'');
		eval('document.form1.fld_bureau_' + champ + '.value=\'\'');
		eval('document.form1.fld_email_' + champ + '.value=\'\'');
		eval('document.form1.fld_autre_' + champ + '.value=\'\'');
		eval('document.form1.fld_portable2_' + champ + '.value=\'\'');
		SelectValueInSelect(eval('document.form1.fld_genre_' + champ),'');
		eval('document.form1.fld_cabinet_' + champ + '.value=\'\'');
		if (typecontact==1)
		{
			eval('document.form1.fld_typesociete_' + champ + '.value=\'\'');
		}
		if (typecontact==1 || typecontact==2)
		{
			SelectValueInSelect(eval('document.form1.fld_origine_' + champ),'');
		}
		if (champ == 'contact')
		{
			document.form1.fld_codedepartement_contactlibelle.value="";
		}
	}
}


function SelectValueInRadio(champ, val)
{
	for(var j=0;j < champ.length;j++){
		if (champ[j].value==val) {
			champ[j].checked= true;
			break;
		}else{
			champ[j].checked= false;
		}
	}
}

function GetRadioValue(champ)
{
	for(var j=0;j < champ.length;j++){
		if (champ[j].checked){
			return champ[j].value;
		}
	}	
}

function SelectValueInSelect(champ, val)
{
//	alert(val + champ.length); 
	champ.selectedIndex=0;
	for(var j=0;j < champ.length;j++){
		//alert(val +"/"+ champ.options[j].text); 
		if ((champ.options[j].value==val)||(champ.options[j].text==unescape(val))) {
			champ.selectedIndex=j;
			break;
		}
	}
}



function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit)
	{
		field.value = field.value.substring(0, maxlimit);
        alert("Vous avez saisi plus de 255 caractères !");
        return false;
	}
	else
	{
		countfield.value = maxlimit - field.value.length;	
	}
}

function form_modif(){
	document.form1.form_modifier.value="1";
}

function reinit_dep(){
	document.form1.fld_codedepartement.value="";
	document.form1.fld_codedepartementlibelle.value="";
}

function selectNomProprio(){
	var Nom = document.form1.selNom;
	if (Nom.options[Nom.selectedIndex].value!="%%"){
		var val = Nom.options[Nom.selectedIndex].value;
		val = val.split("%%");		
		//document.form1.fld_nom_proprio.value = unescape(val[0]);
		document.form1.fld_id_proprio.value = val[1];
	}else{
		//document.form1.fld_nom_proprio.value = "";
		document.form1.fld_id_proprio.value = "";
	}
}

function AfficheHtmlToTag(Tag,  html){
	eval('TagIe='+ Tag + 'Ie');
	eval('TagNs='+ Tag + 'Ns');
	if (document.all){
	TagIe.innerHTML=html;
	}
	else if (document.layers){
	document.TagNs.document.write(html)
	document.TagNs.document.close()
	}
}


function affichelisteville(idListe,ValDefault){
	var liste = eval('document.form1.' + idListe);
	for (i = liste.length - 1; i >= 0; i--){
		liste.options[i]=null;
	}
	liste.options[0] = new Option("","")
	cnt = 1;
	for (var i=0; i < VilleArray.length; i++) {
			if (ValDefault.toUpperCase()==VilleArray[i][1].toUpperCase()){ index_ValDefault= cnt;}
			liste.options[cnt] = new Option(unescape(VilleArray[i][1]), VilleArray[i][1]);
			cnt++;
	}
}

function selVille(val,idListe,ValDefault,champ) {
	var cnt, index_ValDefault;
	var rechercheexpression
	index_ValDefault = 0;
	var liste = eval('document.form1.' + idListe);
	for (i = liste.length - 1; i >= 0; i--){
		liste.options[i]=null;
	}

	liste.options[0] = new Option("","")
	cnt = 1;
//	alert("toto");
	for (var i=0; i < VilleArray.length; i++) {
		if(val == VilleArray[i][0]){
//			alert(ValDefault.toUpperCase());
			if (ValDefault.toUpperCase()==VilleArray[i][1].toUpperCase()){ index_ValDefault= cnt;}
			liste.options[cnt] = new Option(unescape(VilleArray[i][1]), VilleArray[i][1]+'%%'+VilleArray[i][2]);
			cnt++;
		}
	}

	if (ValDefault!=""){
		liste.selectedIndex=index_ValDefault;
		if (liste.selectedIndex==0){
			cnt = 1;
			eval('rechercheexpression = /' + ValDefault.toUpperCase() +'/i;');            //Créer le modèle d'expression régulière.
			//alert (ValDefault.toUpperCase());
			for (var i=0; i < VilleArray.length; i++) {
				if(val == VilleArray[i][0]){
					r = VilleArray[i][1].toUpperCase().search(rechercheexpression);            
					if (r!=-1){
						//alert(cnt);
						liste.selectedIndex= cnt
						document.form1.form_modifier.value=1;
						if (champ!=undefined){
							eval('document.form1.fld_ville_' + champ + '.value=VilleArray[i][1]');
							AfficheHtmlToTag('dynamic_' + champ +'_','<img src="/images/prio_haute.gif" width="7" height="14" alt="Donnée recuperer par le logiciel mais peut etre inexacte !!!" border="0">');
						}else{
							document.form1.fld_ville.value = VilleArray[i][1];
							AfficheHtmlToTag('dynamic','<img src="/images/prio_haute.gif" width="7" height="14" alt="Donnée recuperer par le logiciel mais peut etre inexacte !!!" border="0">');
						}
						break;
					}else{
						if (champ!=undefined){
							AfficheHtmlToTag('dynamic_' + champ +'_','');
						}
					}
				cnt++;
				}
			}
		}else{
			if (champ!=undefined){
				AfficheHtmlToTag('dynamic_' + champ +'_','');
			}
		}
	}else{
		liste.selectedIndex=0;
	}
} 

var VilleArray = new Array(0);

function defineVille(Ville, Departement, CP){
	VilleArray[VilleArray.length] = new Array(Departement,Ville, CP);
}

function selCP(val, fieldVille, fieldCP){
	var fieldVille = eval('document.form1.' + fieldVille);
	var fieldCP = eval('document.form1.' + fieldCP);
	if(val!=""){
		val = val.split('%%');
		fieldVille.value= val[0];
		fieldCP.value= val[1];
	}else{
		fieldVille.value = "";
		fieldCP.value = "";
	}
}


function nettoyage(){
	for ( var i = 0 ; i<VilleArray.length ; i++ ){
		delete VilleArray[i];
	}
	if(popup!=null){
		if(!popup.closed)
			popup.close();
	} 
	
}

window.onunload=nettoyage;

function getinfosProspect(){
	var Infos = document.form1.SelExistant;
	//alert('Infos:'+Infos+':'+Infos.options[Infos.selectedIndex].value+':');
	if (Infos.options[Infos.selectedIndex].value!=""){
		var val = Infos.options[Infos.selectedIndex].value;
		val = val.split("%%");		
		document.form1.fld_IDPROSPECT.value = val[0];
		document.form1.fld_nom.value = unescape(val[1]);
		document.form1.fld_prenom.value = unescape(val[2]);
		document.form1.fld_adresse.value = unescape(val[3]);
		document.form1.fld_codepostal.value = val[4];
		document.form1.fld_ville.value = unescape(val[5]);
		document.form1.fld_codedepartement.value = val[12];
		document.form1.fld_codedepartementlibelle.value = val[13];
		document.form1.fld_villelibelle.value = unescape(val[5]);
		document.form1.fld_codepays.value = val[6];
		document.form1.fld_tel.value = val[7];
		document.form1.fld_fax.value = val[8];
		document.form1.fld_portable.value = val[9];
		document.form1.fld_portable2.value = val[15];
		document.form1.fld_bureau.value = val[10];
		document.form1.fld_email.value = val[11];
		SelectValueInSelect(document.form1.fld_genre,val[14]);
		document.form1.fld_cabinet.value = unescape(val[16]);
		SelectValueInSelect(document.form1.fld_origine,val[17]);
		SelectValueInSelect(document.form1.fld_proprio,val[18]);
	}else{
		document.form1.reset();
	}
	
	//alert('document.form1.fld_IDPROSPECT.value : [' + document.form1.fld_IDPROSPECT.value + ']');
}

// --------------------------------------------------------------
// FONCTIONS AFFICHAGE 
// --------------------------------------------------------------
function fullwin(){
	window.open(window.location,"","fullscreen=0,scrollbars=1,toolbar=1,menubar=0");
	window.close();
}

function affiche_NS(champ,LIBELLE){
//		var LIBELLE = 'COUCOU';
		var lyr = self.document.layers[ champ + 'gereaff'];
		lyr.document.open();
		lyr.document.write('<div class="shade"><font class=titre>' + LIBELLE + '</font></div>');
		lyr.document.write('<div class="texte"><font class=titre>' + LIBELLE + '</font></div>');
		lyr.document.close();
}

function affiche_IE(champ, LIBELLE){
	var buffer;
//	var LIBELLE = 'COUCOU';
	buffer = '<div class="shade" align="center"><font class=titre>' + LIBELLE + '</font></div>';
	buffer += '<div class="texte" align=center><font class=titre>' + LIBELLE + '</font></div>';
	if (!document.getElementById){
		self.document.all(champ + 'infoIE').innerHTML = buffer;
	}else{
		document.getElementById(champ +'infoIE').innerHTML=buffer;
	}
}

var function_affiche = affiche_IE;
var CHAMP_AFFICHAGE = new Array();
var CHAMP_AFFICHAGE_LIBELLE = new Array();

function GereAffichage(){
	for (i=0;i<CHAMP_AFFICHAGE.length;i++){
		function_affiche(CHAMP_AFFICHAGE[i],CHAMP_AFFICHAGE_LIBELLE[i]);
	}
}

// --------------------------------------------------------------
// FONCTIONS DIVERS
// --------------------------------------------------------------
<!-- 
//tmtC_winOpen 
var popup; 
var popup2; 
//tmtC_winOpenEnd 
//winOpen(theURL,winName,features,1)
function winOpen(u,id,f,df){ 
//alert('debug');
if(eval(id)==null||eval(id+".closed")){ 
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");
	eval(id+".focus()");
} else if(df){
	eval(id+".focus()");
} else {
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");
	eval(id+".focus()");} 
} 
//--> 

/*function popupdeppays(code_pays,style,dep,vil, champ)
{
	theURL = "/commun/modules/popdep.asp?code_pays=" + code_pays + "&style=" + style + "&dep=" + dep + "&vil=" + vil + "&c=" + champ;
	winName = "popup";
	features = "width=320,height=450,resizable=no"
  	winOpen(theURL,winName,features,1);
}*/

function rechvillepays(code_pays,style,vil, champ)
{
	if(vil == ""){
		alert("veuillez saisir un debut de nom de ville");
	}else{
		theURL = "/commun/modules/rechville.asp?code_pays=" + code_pays + "&style=" + style + "&vil=" + vil + "&c=" + champ;
		winName = "popup";
		features = "width=320,height=450,resizable=no,scrollbars=yes"
  		winOpen(theURL,winName,features,1);
	}
}

function popupdep(pays, dep, vil, champ)
{
	theURL = "/commun/modules/popville.asp?pays=" + pays + "&dep=" + dep + "&vil=" + vil + "&c=" + champ;
	winName = "popup";
	features = "width=320,height=450,resizable=no"
  	winOpen(theURL,winName,features,1);
}

function euro1(v_form,v_field)
{
	var cSearchValue=showModalDialog("euro.asp?frm_name=" + v_form + "&fld_name=" + v_field ,0,"dialogwidth=298px;dialogheight=280px");
	if (cSearchValue != -1 && cSearchValue != null && cSearchValue != "")
	{
		document.all.DATE.value = cSearchValue;
	}
}

function envoievers(ref,id){
	theURL = "correspondance.asp?ref=" + ref + "&id=" + id;
	winName = "popup";
	features = "width=300,height=150,resizable=yes"
  	winOpen(theURL,winName,features,1);
}


function euro(v_form,v_field) { 
//	alert(v_form);
	theURL = "euro.asp?frm_name=" + v_form + "&fld_name=" + v_field;
	winName = "popup";
	features = "width=300,height=150"
  	window.open(theURL,winName,features);
}
function quartier(v_form,v_field) { 
	theURL = "quartiers.asp?frm_name=" + v_form + "&fld_name=" + v_field;
	winName = "popup";
	features = "width=300,height=120,resizable=yes"
  	window.open(theURL,winName,features);
}
/*function rue(v_form,v_field) { 
	theURL = "rues.asp?frm_name=" + v_form + "&fld_name=" + v_field;
	winName = "popup";
	features = "width=500,height=150"
  	window.open(theURL,winName,features);
}*/
function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
  //winOpen(theURL,"popup",features,1);
}
var Max_image_height = 650;
var Max_image_width = 550;
function wclose(){
		close();
}

function wprint(){
    	window.print() ;  
}
	
function verifetailleimage(){
	if (self.document.photo){
		for (i=0;i<self.document.photo.length;i++){
			image_height = self.document.photo(i).height;
			image_width = self.document.photo(i).width;
			msg= image_width +"*"+image_height+"\n";
			if(image_width>Max_image_width){
				image_height = (image_height*Max_image_width/image_width);
				image_width = Max_image_width;
				msg= msg+image_width +"*"+image_height+"\n";
			}
			if (image_height>Max_image_height){
				image_width = (image_width*Max_image_height/image_height);
				image_height = Max_image_height;
				msg= msg+image_width +"*"+image_height+"\n";
			}
			self.document.photo(i).width = image_width;
			self.document.photo(i).height = image_height;
			//alert(msg);
		}
	}
}

function resizepop(ValMax_image_width, ValMax_image_height){
	if (ValMax_image_width!="" && ValMax_image_height!=""){
		Max_image_width = ValMax_image_width
		Max_image_height = ValMax_image_height
	}else{
		Max_image_width = screen.availWidth
		Max_image_height = screen.availHeight
	}	


	if (self.document.photo){
		image_height = self.document.photo.height;
		image_width = self.document.photo.width;
		
		msg= "Taille de l'image : "+ image_width +"*"+image_height+"\n";
		if(image_width>Max_image_width){
			image_height = (image_height*(Max_image_width-50))/image_width;
			image_width = Max_image_width-50;
			msg= "1"+msg+image_width +"*"+image_height+"\n";
		}
		if (image_height<Max_image_height){
			Max_image_height = image_height+60
			//image_width = (image_width*Max_image_height/image_height);
			//image_height = Max_image_height;
			msg= Max_image_height + '/'+image_width +"*"+image_height+"\n";
		}else{
			Max_image_height = screen.availHeight-50;
		}
		//self.document.photo.width = image_width;
		//self.document.photo.height = image_height;
		window.resizeTo(Max_image_width,Max_image_height)
	}
}

function resizepopPhoto(){
	if (self.document.photo){
		image_height = self.document.photo.height;
		image_width = self.document.photo.width;
		
		msg= "Taille de l'image : "+ image_width +"*"+image_height+"\n";
		if(image_width>Max_image_width){
			image_height = (image_height*(Max_image_width-50))/image_width;
			image_width = Max_image_width-50;
			msg= "1"+msg+image_width +"*"+image_height+"\n";
		}
		if (image_height<Max_image_height){
			Max_image_height = image_height+60
			//image_width = (image_width*Max_image_height/image_height);
			//image_height = Max_image_height;
			msg= Max_image_height + '/'+image_width +"*"+image_height+"\n";
		}else{
			Max_image_height = screen.availHeight-50;
		}
		//self.document.photo.width = image_width;
		//self.document.photo.height = image_height;
		window.resizeTo(Max_image_width,Max_image_height)
	}
}

function redimImage(inImg, inMW, inMH, champ)
{
  // Cette function recoit 3 parametres
  // inImg : Chemin relatif de l'image
  // inMW  : Largeur maximale
  // inMH   : Hauteur maximale
  var maxWidth = inMW;
  var maxHeight = inMH;
  // Declarations des variables "Nouvelle Taille"
  var dW = 0;
  var dH = 0;
  // Declaration d'un objet Image
  var oImg = new Image();
  // Affectation du chemin de l'image a l'objet
  oImg.src = inImg;
  // On recupere les tailles reelles
  var h = dH = oImg.height;
  var w = dW = oImg.width;
  // Si la largeur ou la hauteur depasse la taille maximale
  if ((h >= maxHeight) || (w >= maxWidth)) {
    // Si la largeur et la hauteur depasse la taille maximale
    if ((h >= maxHeight) && (w >= maxWidth)) {
      // On cherche la plus grande valeur
      if (h > w) {
        dH = maxHeight;
        // On recalcule la taille proportionnellement
        dW = parseInt((w * dH) / h, 10);
      } else {
        dW = maxWidth;
        // On recalcule la taille proportionnellement
        dH = parseInt((h * dW) / w, 10);
      }
    } else if ((h > maxHeight) && (w < maxWidth)) {
      // Si la hauteur depasse la taille maximale
      dH = maxHeight;
        // On recalcule la taille proportionnellement
      dW = parseInt((w * dH) / h, 10);
    } else if ((h < maxHeight) && (w > maxWidth)) {
      // Si la largeur depasse la taille maximale
      dW = maxWidth;
        // On recalcule la taille proportionnellement
      dH = parseInt((h * dW) / w, 10);
    }
  }
  // On ecrit l'image dans le document
  //document.writeln("<img src=\"" + inImg + "\" width=\"" + dW + "\" height=\"" + dH + "\" border=\"0\">");
  champ.src = inImg;
  champ.style.width = dW;
  champ.style.height = dH;
};

//arrondi à 2 chiffres après le virgule
function arrondi(number)
{
	var retour;
	retour = number;
	if ((number != "") && !(isNaN(number)))
	{
				retour = retour*100;
				retour = Math.round(retour);
				retour = retour/100;	
	}
	return retour;
}

function http_file(fichier)
{
     if(window.XMLHttpRequest) // FIREFOX
	 {
     	xhr_object = new XMLHttpRequest();
	 }
     else 
	 {
	 	if(window.ActiveXObject) // IE
		{
	        xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
	    else
		{
			return(false); 
		}
	 }
     xhr_object.open("GET", fichier, false);
     xhr_object.send(null); 
     if(xhr_object.readyState == 4) return(xhr_object.responseText);
     else return(false);
}

//fonction qui compte le nbre d'occurence d'un caractère dans une chaine
function compteOccurence(caractere, chaine)
{
	var nbocc, i, pos;
	nbocc=0;
	pos=0;
	while (pos>=0)
	{
		pos=chaine.indexOf(caractere,pos+1);
		if (pos>=0) {
			nbocc++;
		}
	}
	return nbocc;
}
