// fonction permettant ecrire flash
function flash_object(url,anim,width,height,num,link){
	
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">')
	document.write('<param name="movie" value="'+url+'flash/'+anim+'.swf?url='+url+'&num='+num+'&link='+link+'">')
	document.write('<param name="quality" value="high">')
	document.write('<param name="wmode" value="transparent">')
	document.write('<embed src="'+url+'flash/'+anim+'.swf?url='+url+'&num='+num+'&link='+link+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="transparent">')
	document.write('</embed></object>')
}

function flash_object_film(url,anim,width,height){
	
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">')
	document.write('<param name="movie" value="'+url+'hypodis/'+anim+'.swf?url='+url+'">')
	document.write('<param name="quality" value="high">')
	document.write('<param name="wmode" value="transparent">')
	document.write('<embed src="'+url+'hypodis/'+anim+'.swf?url='+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="transparent">')
	document.write('</embed></object>')
}

// popup simple => 1 ou 0 pr le scroll
function popup(page, nom, largeur, hauteur, scrol) {
  window.open(page, ""+nom+"", "scrollbars="+ scrol +",menubar=no,toolbar=no,resizable=yes,width="+ largeur + ",height=" + hauteur);
}
// changement de couleur au survol des lignes
function change_color_ligne(id,defaut,txt){
	document.getElementById(id).style.backgroundColor=defaut;
	// si on mouseover col=#FF8000 sinon col=#000000
	var col = (txt) ? "#000000" : "#494949";	
	// on change la couleur de la police pr les 5 <td>
	document.getElementById(id+'1').style.color=col;
	document.getElementById(id+'2').style.color=col;
	document.getElementById(id+'3').style.color=col;
	document.getElementById(id+'4').style.color=col;
	document.getElementById(id+'5').style.color=col;
}

// fonction ajout aux favoris et marque-page  
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

/*************** paires pour les formulaires ********************/

// remet la couleur dans l'input 
function couleur(obj) {
     obj.style.backgroundColor = "#FFFFFF";
}
// regarde si les champs sont vides
function check() {
	var msg = "";
	var color = "#FFFF99";
if (document.form_paiement.nature.value == "")   {
      msg += "Veuillez choisir la nature du paiement\n";
      document.form_paiement.nature.style.backgroundColor = color;
   }
if (document.form_paiement.montant.value == "")   {
      msg += "Veuillez saisir un montant\n";
      document.form_paiement.montant.style.backgroundColor = color;
   }
if (document.form_paiement.reference.value == "")   {
      msg += "Veuillez saisir une r&eacute;f&eacute;rence du dossier\n";
      document.form_paiement.reference.style.backgroundColor = color;
   }
if (document.form_paiement.nom.value == "")   {
      msg += "Veuillez saisir votre nom\n";
      document.form_paiement.nom.style.backgroundColor = color;
   }
if (document.form_paiement.ville.value == "")   {
      msg += "Veuillez saisir la ville du siège social\n";
      document.form_paiement.ville.style.backgroundColor = color;
   }
if (msg == "") return(true);
   else   {
      alert(msg);
      return(false);
   }
}

/* ouverture pop up conseiller a un  ami */
// popup centre
function popupcentre(page,largeur,hauteur,scrol) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+",menubar=no,toolbar=no,resizable=yes,scrollbars="+ scrol);
}

//################## pour le paiement  #####################################################

// vide les champs et desactive les boutons radio ou checkbox
function desactiver(btn) {
	switch(btn) {
		case 'modalite':
		document.form_paiement.montant1.value = "";
		document.form_paiement.montant2.value = "";
		document.form_paiement.montant3.value = "";
 		document.form_paiement.nb_echeance[0].checked = false;
		document.form_paiement.nb_echeance[1].checked = false;
		document.form_paiement.mt_egal.checked = false;
		break;
		case 'echeance':
		document.form_paiement.montant1.value = "";
		document.form_paiement.montant2.value = "";
		document.form_paiement.montant3.value = "";
		break;
	}
}

// divise le montant global en 2 ou 3 fois identiques et rempli les champs
function calcul() {
	var mtg = document.form_paiement.montant.value;
	var reg = new RegExp("^[0-9]+\\.[0-9]{2}$", "i"); // test du format xx.xx
	
	if(document.form_paiement.mt_egal.checked == false){ // si on décoche on vide les champs
		document.form_paiement.montant1.value = "";
		document.form_paiement.montant2.value = "";
		document.form_paiement.montant3.value = "";
	}else{ // si on coche on remplit
		if(mtg != "") { // si le montant n'est pas vide
		
			if (reg.test(mtg)) {
		
				if(document.form_paiement.nb_echeance[0].checked){ // si 2 echéances
				
				mt1 = Math.round((mtg/2)*100); // passge en centimes 15.30 => 1530
				mt2 = Math.round( (mtg*100)-mt1);
				mt1 = mt1.toString(); // passage en string
				mt2 = mt2.toString(); 
				var point1 = mt1.length - 2; // 2 decimales
				var point2 = mt2.length - 2;
				if (point1 >= 0) mt1 = mt1.substring(0, point1) + "." + mt1.substring(point1); // formatage montant => 15=15.00 ou 15.3=15.30
				if (point2 >= 0) mt2 = mt2.substring(0, point2) + "." + mt2.substring(point2); 
				document.form_paiement.montant1.value = mt1;
				document.form_paiement.montant2.value = mt2;
				
				}else if(document.form_paiement.nb_echeance[1].checked){ // si 3 échéances
				
				mt1 = Math.round(mtg/3*100);
				mt2 = Math.round((mtg*100)-(mt1*2));
				mt1 = mt1.toString(); // passage en string
				mt2 = mt2.toString(); 
				var point1 = mt1.length - 2; // 2 decimales
				var point2 = mt2.length - 2;
				if (point1 >= 0) mt1 = mt1.substring(0, point1) + "." + mt1.substring(point1); // formatage montant => 15=15.00 ou 15.3=15.30
				if (point2 >= 0) mt2 = mt2.substring(0, point2) + "." + mt2.substring(point2); 
				document.form_paiement.montant1.value = mt1;
				document.form_paiement.montant2.value = mt1;
				document.form_paiement.montant3.value = mt2;
				}
		
			}else{ 
				alert("Le format du montant global n\'est pas valide (cf.exemple)");
				document.form_paiement.montant.focus();
				document.form_paiement.mt_egal.checked = false;
			}
		}else if(mtg == "") { // si le montant est vide
			alert("Le champ montant global est vide (cf.exemple)");
			document.form_paiement.montant.focus();
			document.form_paiement.mt_egal.checked = false;		
		}
	}
}

// permet d'afficher/masquer le paiement en plusieurs fois
function affich(lst){	
 var div=document.getElementById("div_modalite");
 var div1=document.getElementById("div_condition");
 var div2=document.getElementById("div_echeance");
 var div3=document.getElementById("div_mt3"); 
 if (lst.selectedIndex == 1)
  div.style.display="inline";
 else
  div.style.display="none";
  div1.style.display="none";
  div2.style.display="none";
  div3.style.display="none";
	document.form_paiement.modalite[0].checked = false;
	document.form_paiement.modalite[1].checked = false;
}

// regarde si les champs sont vides ///////////

// remet la couleur dans l'input 
function couleur(obj) {
     obj.style.backgroundColor = "#FFFFFF";
}

function check() {
	var msg = "";
	var color = "#FFFF99";
if (document.form_paiement.nature.value == "")   {
      msg += "Veuillez choisir la nature du paiement\n";
      document.form_paiement.nature.style.backgroundColor = color;
   }
if (document.form_paiement.montant.value == "")   {
      msg += "Veuillez saisir un montant\n";
      document.form_paiement.montant.style.backgroundColor = color;
   }
if (document.form_paiement.reference.value == "")   {
      msg += "Veuillez saisir une référence du dossier\n";
      document.form_paiement.reference.style.backgroundColor = color;
   }
if (document.form_paiement.nom.value == "")   {
      msg += "Veuillez saisir votre nom\n";
      document.form_paiement.nom.style.backgroundColor = color;
   }
if (document.form_paiement.ville.value == "")   {
      msg += "Veuillez saisir la ville du siège social\n";
      document.form_paiement.ville.style.backgroundColor = color;
   }
if (msg == "") return(true);
   else   {
      alert(msg);
      return(false);
   }
}
//################## fin pour le paiment  #####################################################"

/**************************/

