// JavaScript Document

/*
Fonction de traitement des balises pour la mise en forme de texte
*/

function storeCaret(text)
{ // voided
}

function AddText(startTag,defaultText,endTag,champ) 
{

 if (champ.createTextRange) 
 {
  var text;
  champ.focus(champ.caretPos);
  champ.caretPos = document.selection.createRange().duplicate();
  if(champ.caretPos.text.length>0)
  {
   champ.caretPos.text = startTag + champ.caretPos.text + endTag;
  }
  else
  {
   champ.caretPos.text = startTag+defaultText+endTag;
  }
 }
 else champ.value += startTag+defaultText+endTag;
}

function chcolor(color,champ)
{

 if (champ.createTextRange) 
 {
	Selection = document.selection.createRange().text;
 	champ.focus(champ.caretPos);
  champ.caretPos = document.selection.createRange().duplicate();
 if(champ.caretPos.text.length>0)
  {
   champ.caretPos.text = "[" + color + "]"+ champ.caretPos.text + "[/" + color + "]";
  }
  else
  {
   champ.caretPos.text = "[" + color + "] votre texte "+ Selection + "[/" + color + "]";
  }
}
else
champ.value += "[" + color + "]"+ Selection + "[/" + color + "]";
document.form1.color.options[0].selected=true;
}

/*
Fonction d'activation/desactivation de zone texte
*/

function disable_enable(zone_texte){
if (document.all || document.getElementById){
if (zone_texte.disabled==true) {
zone_texte.disabled=false
}
else {
zone_texte.disabled=true
zone_texte.value=''
}
}
}

function rempli_vide(){
if (document.f.cre_cook.value=='vide') {
document.f.cre_cook.value='creation'
}
else {
document.f.cre_cook.value='vide'
}
}

function selectionner()
{
document.form1.contenu.select();
}

function limitcar(texte, nb, maxi) {
 if (texte.value.length > maxi)
   texte.value = texte.value.substring(0, maxi);
 else 
   nb.value = maxi - texte.value.length;
}

function remplissage()
{

if(document.form1.idem.checked) {

var radio, radio1
radio = document.form1.titre
radio1 = document.form1.titre_livraison

for (var i=0; i<radio.length;i++) {
	if (radio[i].checked) {
		radio1[i].checked=true;
		}
    }

document.form1.prenom_livraison.value = document.form1.prenom.value;
document.form1.nom_livraison.value = document.form1.nom.value;
document.form1.societe_livraison.value = document.form1.societe.value;
document.form1.adresse_livraison.value = document.form1.adresse.value;
document.form1.code_postal_livraison.value = document.form1.code_postal.value;
document.form1.ville_livraison.value = document.form1.ville.value;
}

else {

document.form1.titre_livraison[0].checked=true;
document.form1.titre_livraison.value = "";
document.form1.prenom_livraison.value = "";
document.form1.nom_livraison.value = "";
document.form1.societe_livraison.value = "";
document.form1.adresse_livraison.value = "";
document.form1.code_postal_livraison.value = "";
document.form1.ville_livraison.value = "";
}

}

/*
Fonction de Dreamweaver modifiée pour vérifier la validité des champs dans un formulaire
*/
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Format_Tel(NumTel){
  var Tel;
  var i = 0;
  while (i < NumTel.length-1)
    {
    if ((NumTel.charAt(i) == ".")||(NumTel.charAt(i) == ",")||(NumTel.charAt(i) == "/")||(NumTel.charAt(i) == "-")||(NumTel.charAt(i) == " "))
      {
      Tel = NumTel.substring(0,i) + NumTel.substring(i+1,NumTel.length);
          NumTel = Tel; 
      }
      else{
      i++;
      }
    }
  return (NumTel);
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- Le champs '+nm+' doit contenir une adresse email valide.\n';
      } 

		else if ((test.charAt(0) == 'U')||(test.charAt(1) == 'U')) {
			
			if (val.substring(0,7)!='') {	
			if (val.substring(0,7)!='http://') {
            //alert("Pour continuer votre inscription, vous devez accepter le règlement !")
			//document.MM_returnValue = ('');
			errors += '- Le champs '+nm+' doit contenir un lien correct (http://).\n';
												}  
										}
										}
										
		else if (test.charAt(0) == 'T') {
			
			var Tel;
			Tel = Format_Tel(val);
			
				if ((Tel.length != 10)||isNaN(Tel)||((Tel.substring(0,2)!='01')&&(Tel.substring(0,2)!='02')&&(Tel.substring(0,2)!='03')&&(Tel.substring(0,2)!='04')&&(Tel.substring(0,2)!='05')&&(Tel.substring(0,2)!='06')&&(Tel.substring(0,2)!='08'))) { errors+='- Le champs '+nm+' doit contenir un numero de téléphone valide'; }

										}
										
		else if (test.charAt(0) == 'F') {
			
			var Fax;
			Fax = Format_Tel(val);
			
			if (Fax != '') {
				
				if ((Fax.length != 10)||isNaN(Fax)||((Fax.substring(0,2)!='01')&&(Fax.substring(0,2)!='02')&&(Fax.substring(0,2)!='03')&&(Fax.substring(0,2)!='04')&&(Fax.substring(0,2)!='05')&&(Fax.substring(0,2)!='06')&&(Fax.substring(0,2)!='08'))) { errors+='-Le champs '+nm+' doit contenir un numero de fax valide.\n'; }

							}
										 }
		
		else if ((test.charAt(0) == 'C')&&(test.charAt(1) == 'P')) {
			
			if ((val.length != 5)||(isNaN(val))||val=='') { errors+='- Le champs code postal doit contenir un code postal valide (5 chiffres).\n'; }

																	}

	  else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- Le champs '+nm+' est obligatoire.\n'; 
	
			
			}
  } 
  
  
  if (errors) alert('Erreur(s) rencontré(s) :\n\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->

<!--
/*
Fonction de fermeture d'un popup et raffraichissement de la fenetre mere
*/
  function refresh(url){
  opener.location.href=url;
  self.close();
  };
//-->

function validbutton1(dd)
{
	window.open("calendrier/calendrier.asp?origine="+dd,"calendrier","width=215,height=170,top=120,left=120");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function afficheVignette(cheminVignette,cheminMaxi)
	{
	document.write('<A HREF="javascript:afficheMaxi(\''+cheminMaxi+'\')"><IMG SRC="'+cheminVignette+'" HSPACE=0 VSPACE=0 BORDER=0 ALT="cliquez ici pour voir en grand"></A>');
	}
function afficheMaxi(chemin)
	{
	i1 = new Image;
	i1.src = chemin;
	html = '<HTML><HEAD><TITLE>Groupe Valloire</TITLE></HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER><IMG SRC="'+chemin+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+30,document.imageTest.height+61)"></CENTER></BODY></HTML>';
	popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1');
	popupImage.document.open();
	popupImage.document.write(html);
	popupImage.document.close()
	};
	
var DateValue = ""
var DateInputID = ""
var ObjInput
function CalendarInput(oInput){
	ObjInput = oInput
	DateValue = oInput.value
	showModelessDialog("../fonctions/calendar.html",window,"status:no;dialogLeft:" + event.screenX + ";dialogTop:" + event.screenY + ";dialogWidth:181px;dialogHeight:220px;resizable:no;scroll:no");
}
function DateUpdate() {ObjInput.value = DateValue}

