//--------------------------------------Void-------------------------------------------------------------
function Ajax()
{
pary='ajax';
}


function tst_text(id_champ,val_min,val_max,val_actuel)
{
pary='ajax';

/*
var val=document.getElementById(id).value;
var val_manque=document.getElementById('nb_manque').value;
var new_val_maque=parseInt(val_manque);
			if ((val_actuel>=val_min) && (val_actuel<=val_max))
			{
				if((val.length<=val_min) || (val.length>=val_max))
				{
				new_val_maque=parseInt(val_manque)+1;
				}
			}else{
				if((val.length>=val_min) && (val.length<=val_max))
				{
				new_val_maque=parseInt(val_manque)-1;
				}
			}
document.getElementById('nb_manque').value=new_val_maque;

alert("salut");*/
}

function sendMultiData1()
{
			var param = '';
			var n_argument=sendMultiData1.arguments.length;
			for (var i=0; i <n_argument; i=i+3)
			{
			para = sendMultiData1.arguments[i];
			placy = sendMultiData1.arguments[i+1];
	//		document.getElementById(placy).innerHTML = 'salut' ;
			fction = sendMultiData1.arguments[i+2];
			j=i+3;
			param = param + para + '&place'+j + '='+placy + '&myfunction'+j+'='+fction;
			}
			var n_ajax_fct=n_argument+3;
			param = 'id_langue='+val_id('id_langue')+'&nmd5_user='+val_id('nmd5_user')+'&type_autentif='+val_id('type_autentif')+'&place0=authentif&myfunction0=test_user&'+param+'&n_ajax_fct='+n_ajax_fct;
			//var places = 'place2';
			//var contents=document.getElementById('corp');
			//contents.innerHTML = param;
			sendData1(param);
}

	function sendData1(param)
	{
		page = 'function.php';
		if(document.all)
		{
			//Internet Explorer
			var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
		}//fin if
		else
		{
		    //Mozilla
			var XhrObj = new XMLHttpRequest();
		}//fin else

		//définition de l'endroit d'affichage:
		//var place = 'place5';
		//var content = document.getElementById(place);
		
		XhrObj.open("POST", page);

		//Ok pour la page cible
		XhrObj.onreadystatechange = function()
		{
			if (XhrObj.readyState == 4 && XhrObj.status == 200)
			{
			//récupération de la chaine : place1##resultat_fct1##place2##resultat_fct2
			var chaine = XhrObj.responseText;
			
			//découper la chaine selon la méthode Split
			var MyTable = chaine.split('##');
				//var place = 'place5';
				//var content = document.getElementById(place);
				//content.innerHTML = chaine;
			//Afficher résultat_fct1 dans la place1, resultat_fct2 sur la place2...
				for (j=0; j<MyTable.length; j=j+2)
				{
				var place = MyTable[j];
				var contenu = MyTable[j+1];
				var content = document.getElementById(place);
				content.innerHTML = contenu;
				}
			document.getElementById("load1").style.visibility='hidden';
			active_menu();
			
			}
		}

		XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		XhrObj.send(param);
		param=null;
		
	}//fin fonction SendData

function active_menu()
{
var Accordion1 = new Spry.Widget.Accordion("Accordion1");	
}
//------------------------------------ Text de l'existance d'une valeur  
		function exist(mychamp,zone_hiden,message)
		{
		var val = document.getElementById(zone_hiden).innerHTML;
		pary= val.indexOf("coucou");
			if (pary!=-1)
			{
			rouge_control(mychamp,'rouge');
			alert(message);		
			return 'walou';
			}else{
			return 'yes';
			}
		}
//------------------------------------ Text de l'existance d'une valeur  
		function yes_or_no(mychamp,message)
		{
		var val = document.getElementById(mychamp).value;
			if (val!='yes')
			{
			alert(message);		
			return 'walou';
			}else{
			return 'yes';
			}
		}

function coche_case (place,myvalue) {
if (myvalue=='on')
{
next_value='off';
send_value='yes';
}else{
next_value='on';
send_value='no';
}
message="<a href=# OnClick=\"coche_case('promo_case','"+next_value+"')\"><img src=\"img/star_"+myvalue+".gif\" border=0></a>&nbsp;&nbsp;Promotions<input type=hidden id=\"promo\" value=\""+send_value+"\">";
document.getElementById(place).innerHTML = message;
}
function ikona(type)
{
if(type=='voiture')
{
selected1="<img src=\"img/s1.gif\" width=62 height=30 border=0>"; 
}else{
selected1="<img src=\"img/d1.gif\" width=62 height=30 name=b1 border=0>";
}
//-------------------------------------------------------------------------
if(type=='moto')
{
selected2="<img src=\"img/s2.gif\" width=68 height=30 border=0>"; 
}else{
selected2="<img src=\"img/d2.gif\" width=68 height=30 name=b2 border=0></a>";
}
//--------------------------------------------------------------------------
if(type=='camion'){
selected3="<img src=\"img/s3.gif\" width=68 height=30 border=0>"; 
}else{
selected3="<img src=\"img/d3.gif\" width=68 height=30 name=b3 border=0>";
}
//---------------------------------------------------------------------------
if(type=='bateau')
{
selected4="<img src=\"img/s4.gif\" width=68 height=30 border=0>"; 
}else{
selected4="<img src=\"img/d4.gif\" width=68 height=30 name=b4 border=0>";
}

if(type=='autre')
{
selected5="<img src=\"img/s5.gif\" width=62 height=30 border=0>"; 
}else{
selected5="<img src=\"img/d5.gif\" width=62 height=30 name=b5 border=0>";
}

mon_tableau="<table width=328 border=0 cellspacing=0 cellpadding=0><tr><td width=62>"+selected1+"</td><td width=68>"+selected2+"</td><td width=68>"+selected3+"</td><td width=68>"+selected4+"</td><td width=62>"+selected5+"</td></tr></table>";
document.getElementById('viw1').innerHTML = "";
document.getElementById('viw2').innerHTML = "";
document.getElementById('viw3').innerHTML = "";
document.getElementById('viw4').innerHTML = "";
document.getElementById('viw5').innerHTML = "";
document.getElementById('nb_annonces').innerHTML = "";
document.getElementById('place_marque').innerHTML = "";
document.getElementById('ikona').innerHTML = mon_tableau;
}
function chk(name)
{
	if(document.getElementById(name).checked == true)
	{
		document.getElementById(name+'_h').value = 1;
	}
	else
	{
		document.getElementById(name+'_h').value = 0;
	}
}
function val_check(name)
{
	if(document.getElementById(name).checked == true)
	{
	return'yes';
	}else{
	return'no';
	}
}
	
function val_check_num(name)
{
	if(document.getElementById(name).checked == true)
	{
	return parseInt('1');
	}else{
	return parseInt('0');
	}
}

function chk_case(name)
{
	if(document.getElementById(name).checked == true)
	{
		document.getElementById('h'+name).value = 1;
	}
	else
	{
		document.getElementById('h'+name).value = 0;
	}
}


function st_last_tab(objet,type_rub,bg_tab0,text_tab0,bg_tab1,text_tab1) {
if (type_rub==0)
{
document.getElementById(objet).style.background=bg_tab0;
document.getElementById(objet).style.color=text_tab0;
}

if (type_rub==1)
{
document.getElementById(objet).style.background=bg_tab1;
document.getElementById(objet).style.color=text_tab1;
}

}

function st_tab(objet,bg_tab,text_tab) {
if (objet!=0)
{
document.getElementById(objet).style.background=bg_tab;
document.getElementById(objet).style.color=text_tab;
}
}

function st_tab_control(objet,bg_tab,text_tab) {
	if (val_id('if_select')!=objet)
	{
	document.getElementById(objet).style.background=bg_tab;
	document.getElementById(objet).style.color=text_tab;
	}
}

function st_tab_affect(objet,bg_tab,text_tab) {
	if (val_id('niveau_affect')!=objet)
	{
	document.getElementById(objet).style.background=bg_tab;
	document.getElementById(objet).style.color=text_tab;
	}
}
function change_val_id(id_champ,myvalue){
document.getElementById(id_champ).value=myvalue;
}


function openpdf(text,name,titre) {
 mafenetre =
 window.open("pdf.php?text="+text+"&name="+name+"&titre="+titre, "null", "width=500,height=400,screenX=200,screenY=200,top=300,left=300");
 mafenetre.focus();
}
function openprint(titre,text,auteur,date) {
 mafenetre =
 window.open("print.php?titre="+titre+"&text="+text+"&date="+date+"&auteur="+auteur, "null", "width=800,height=600,screenX=200,screenY=200,top=300,left=300");
 mafenetre.focus();
}
function openamis(titre,text,auteur,date) {
 mafenetre =
 window.open("amis.php?titre="+titre+"&text="+text+"&date="+date+"&auteur="+auteur, "null", "width=500,height=400,screenX=200,screenY=200,top=300,left=300");
 mafenetre.focus();
}
function openpop(id,w,h,nmd5) {
 mafenetre =
 window.open("form_articles.php?id="+id+"&nmd5_user="+nmd5, "null", "width="+w+",height="+h+",screenX=200,screenY=200,top=300,left=300,scrollbars=1");
 mafenetre.focus();
}
function openpop_n(w,h,nmd5,langue) {
 mafenetre =
 window.open("form_articles.php?nmd5_user="+nmd5+"&langue="+langue, "null", "width="+w+",height="+h+",screenX=200,screenY=200,top=300,left=300,scrollbars=1");
 mafenetre.focus();
}
	/**
	 * Permet d'envoyer des données en GET ou POST en utilisant les XmlHttpRequest
	 */

	function sendData(param)
	{
		page = 'function.php';
		if(document.all)
		{
			//Internet Explorer
			var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
		}//fin if
		else
		{
		    //Mozilla
			var XhrObj = new XMLHttpRequest();
		}//fin else

		//définition de l'endroit d'affichage:
		//var place = 'place5';
		//var content = document.getElementById(place);
		
		XhrObj.open("POST", page);

		//Ok pour la page cible
		XhrObj.onreadystatechange = function()
		{
			if (XhrObj.readyState == 4 && XhrObj.status == 200)
			{
			//récupération de la chaine : place1##resultat_fct1##place2##resultat_fct2
			var chaine = XhrObj.responseText;
			
			//découper la chaine selon la méthode Split
			var MyTable = chaine.split('##');
				//var place = 'place5';
				//var content = document.getElementById(place);
				//content.innerHTML = chaine;
			//Afficher résultat_fct1 dans la place1, resultat_fct2 sur la place2...
				for (j=0; j<MyTable.length; j=j+2)
				{
				var place = MyTable[j];
				var contenu = MyTable[j+1];
				var content = document.getElementById(place);
				content.innerHTML = contenu;
				}
			document.getElementById("load1").style.visibility='hidden';
			}
		}

		XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		XhrObj.send(param);
		param=null;
	}//fin fonction SendData
	
		function loadMultiData()
		{
			var param = '';
			for (var i=0;i<loadMultiData.arguments.length; i=i+3)
			{
			para = loadMultiData.arguments[i];
			placy = loadMultiData.arguments[i+1];
		//	document.getElementById(placy).innerHTML = 'salut' ;
			fction = loadMultiData.arguments[i+2];
			param = param + para + '&place'+i + '='+placy + '&myfunction'+i+'='+fction;
			}
			var n_ajax_fct = loadMultiData.arguments.length ;
			param = param+'&n_ajax_fct='+n_ajax_fct;
			//var places = 'place2';
			//var contents = document.getElementById(places);
			//contents.innerHTML = param ;
			sendData(param);
		}
		
function sendMultiData()
{
			var param = '';
			var n_argument=sendMultiData.arguments.length;
			for (var i=0; i <n_argument; i=i+3)
			{
			para = sendMultiData.arguments[i];
			placy = sendMultiData.arguments[i+1];
	//		document.getElementById(placy).innerHTML = 'salut' ;
			fction = sendMultiData.arguments[i+2];
			j=i+3;
			param = param + para + '&place'+j + '='+placy + '&myfunction'+j+'='+fction;
			}
			var n_ajax_fct=n_argument+3;
			param = 'id_langue='+val_id('id_langue')+'&nmd5_user='+val_id('nmd5_user')+'&type_autentif='+val_id('type_autentif')+'&place0=authentif&myfunction0=test_user&'+param+'&n_ajax_fct='+n_ajax_fct;
			//var places = 'place2';
			//var contents=document.getElementById('corp');
			//contents.innerHTML = param;
			sendData(param);
}

		function controlMultiData()
		{
			var param = '';
			var initial = 0;
			var n_argument=controlMultiData.arguments.length;
			for (var i=0; i < n_argument; i=i+3)
			{
			var para = controlMultiData.arguments[i];
			var pary= para.indexOf("walou");
				if(pary!=-1)
				{
				initial = initial+1;
				}
	
			placy = controlMultiData.arguments[i+1];
			fction = controlMultiData.arguments[i+2];
			j=i+3;
			param = param + para + '&place'+j + '='+placy + '&myfunction'+j+'='+fction;
			}
			var n_ajax_fct=n_argument+3;
			param = 'id_langue='+val_id('id_langue')+'&nmd5_user='+val_id('nmd5_user')+'&type_autentif='+val_id('type_autentif')+'&place0=authentif&myfunction0=test_user&'+param+'&n_ajax_fct='+n_ajax_fct;
			
				if(initial==0)
				{
				//alert('Mail invalide');
				sendData(param);
				end_zone(5000);
				}else{
				//document.getElementById('layer_load').style.visibility ='hidden';
				}
		}

//--------------------------------------SONDAGE----------------------------------------------
function control_sondage()
{
	if (val_check('choix1')=='no' && val_check('choix2')=='no' && val_check('choix3')=='no')
	{
	alert('Vous devez choisir une option !');		
	return 'walou';
	}else{
	return 'yes';
	}
}
//------------------------------------ Authentifaction demandé-------------------------------
function connect ()
{
	if (val_id('nmd5_user')==0)
	{
			rouge_control('login','rouge');
			rouge_control('passe','rouge');
			alert('Veuillez vous inscrire/authentifier pour accéder !');		
			return 'walou';
	}else{
			return 'yes';
	}
}
//------------------------------------text minimal
		function caract(mychamp,number_caract,message)
		{
		var val = document.getElementById(mychamp).value;
			if (val.length<number_caract)
			{
			rouge_control(mychamp,'rouge');
			alert(message);		
			return 'walou';
			}else{
			return val;
			}
		}
function must_different(mychamp,different_value,message)
{
	var val = document.getElementById(mychamp).value;
	if (val==different_value)
	{
	alert(message);		
	return 'walou';
	}else{
	return val;
	}
}
		
		function navigation()
		{
			if(document.all)
			{
			return 'ie';
			}else{
			return 'ff';
			}
		
		}
	function val_id(id_champ){
	var valeur = document.getElementById(id_champ).value;
	return valeur ;
	}
	
	function val_extern_id(win_name,id_champ){
	var valeur = window.frames[win_name].document.getElementById(id_champ).value;
	return valeur ;
	}

	function val_edit(id_champ,my_value){
	document.getElementById(id_champ).value=my_value;
	}
	
	function edit_zone(id_zone,my_value){
	document.getElementById(id_zone).innerHTML=my_value;
	}

	
	function control_nb_photo(frame,id_champ,nb_max)
	{
	nb_photo=parseInt(val_extern_id(frame,id_champ));
	
		if(nb_max<nb_photo)
		{
		alert('Nombre de photos ne doit pas dépasser '+nb_max+' !'); 
		return 'walou';
		}else{
			if(nb_photo==0)
			{
			alert('Aucune photo n\'a été chargée pour cette annonce, Veillez rectifier (Parcourir puis charger) !');
			return 'walou';
			}else{
			return 'yes';
			}
		}
	
	}

	function edit_extern_zone(win_name,id_zone,my_value){
    window.frames[win_name].document.getElementById(id_zone).innerHTML=my_value;
	}

function Test_Checked(id_champ)
{
     if(document.getElementById(id_champ).checked==false)
     {  //pas coché!
        return false;
     }
	 else
	 {
	 return id_champ;
	 }
}
function roll_list(id_zone,style_zone)
{
	if (style_zone=='normal')
	{
	//document.getElementById(id_zone).class='item_list';url(img/barre_annonce.jpg)
	document.getElementById(id_zone).style.border='1px solid #F0F0F0';
	document.getElementById(id_zone).style.background='#FBFBFB';
	document.getElementById(id_zone).style.padding='1px';
	}
	if (style_zone=='normal2')
	{
	//document.getElementById(id_zone).class='item_list';url(img/barre_annonce.jpg)
	document.getElementById(id_zone).style.border='1px solid #F0F0F0';
	document.getElementById(id_zone).style.background='#EDEEF8';
	document.getElementById(id_zone).style.padding='1px';
	}
	if (style_zone=='light')
	{
	//document.getElementById(id_zone).class='item_list';url(img/barre_annonce.jpg)
	document.getElementById(id_zone).style.border='2px solid #FFEE8B';
	document.getElementById(id_zone).style.background='url(img/barre_annonce.jpg)';
	document.getElementById(id_zone).style.padding='0px';
	}
	
	if (style_zone=='edit_light')
	{
	//document.getElementById(id_zone).class='item_list';url(img/barre_annonce.jpg)
	document.getElementById(id_zone).style.border='2px solid #FFEE8B';
	document.getElementById(id_zone).style.background='#FFFDDE';
	document.getElementById(id_zone).style.padding='0px';
	}

	if (style_zone=='selecty')
	{
	document.getElementById(id_zone).style.border='2px solid #F0F0F0';
	document.getElementById(id_zone).style.background='#FFFFFF';
	document.getElementById(id_zone).style.padding='0px';
	}
}

function select_comparer(id_select)
{
value_select=val_check('compar'+id_select);
scomparer1=document.getElementById('comparer1').value;
scomparer2=document.getElementById('comparer2').value;
if(value_select=='yes')
{
	if(scomparer1=='0')
	{
	document.getElementById('comparer1').value=id_select;
	}else{
		if(scomparer2=='0')
		{
		document.getElementById('comparer2').value=id_select;
		}else{
		document.getElementById('compar'+scomparer1).checked=false;
		document.getElementById('comparer1').value=scomparer2;
		document.getElementById('comparer2').value=id_select;
		}
	}
}else{
	if (id_select==scomparer1)
	{
	document.getElementById('comparer1').value=scomparer2;
	document.getElementById('comparer2').value='0';
	}
	if (id_select==scomparer2)
	{
	document.getElementById('comparer2').value='0';
	}
}

}

function open_zone(largeur,hauteur,titre) {

var flash='<table width=90% height=80% border=0 cellspacing=0 cellpadding=0><tr><td align=center valign=middle>Chargement</td></tr></table>';

var content1=document.getElementById('zone_message');
content1.innerHTML=flash;
/*
nb_select=document.getElementsByTagName("select").length;
for (var i=0; i < nb_select; i=i+1)
{
document.getElementsByTagName("select")[i].style.visibility='hidden';
}
*/
motie=parseInt(largeur/2);
motie_h=parseInt(hauteur/2);
htop=300-motie_h;
left=512-motie;
pas_top=parseInt(motie_h/10);
pas_left=parseInt(motie/10);
pas_width=largeur/10;
pas_height=hauteur/10;
	document.getElementById('box_message').style.visibility='visible';
	document.getElementById('zone_message').style.visibility='hidden';
	document.getElementById('box_message').style.width=pas_width;
	document.getElementById('titre_zone').style.width=pas_width;
	document.getElementById('box_message').style.height=pas_height;
	document.getElementById('box_message').style.left=512;
	document.getElementById('box_message').style.top=300;
zone_plus(pas_top,pas_left,pas_width,pas_height,htop,left,largeur,hauteur,titre);
}

function zone_plus(pas_top,pas_left,pas_width,pas_height,fi_top,fi_left,fi_width,fi_height,titre)
{
	if(parseInt(document.getElementById('box_message').style.width)<fi_width)
	{
	var sal="plus_zone('"+pas_top +"','"+ pas_left +"','"+ pas_width +"','"+ pas_height +"','"+ fi_top +"','"+ fi_left +"','"+ fi_width +"','"+ fi_height +"','"+ titre+"')";
	//var content1 = document.getElementById('zone_message');
	//content1.innerHTML = sal;
	setTimeout ("plus_zone("+pas_top +","+ pas_left +","+ pas_width +","+ pas_height +","+ fi_top +","+ fi_left +","+ fi_width +","+ fi_height +",'"+ titre+"')",1);
	}else{
	document.getElementById('titre_zone').style.width=fi_width;	
	document.getElementById('box_message').style.width=fi_width;
	document.getElementById('box_message').style.height=fi_height;
	document.getElementById('box_message').style.left=fi_left;
	document.getElementById('box_message').style.top=fi_top;
	document.getElementById('zone_message').style.visibility='visible';
	} 
}

function plus_zone(pas_top,pas_left,pas_width,pas_height,fi_top,fi_left,fi_width,fi_height,titre)
{
	var content1 = document.getElementById('zone_titre');
	content1.innerHTML = titre;
document.getElementById('titre_zone').style.width=parseInt(document.getElementById('titre_zone').style.width)+pas_width;
document.getElementById('box_message').style.width=parseInt(document.getElementById('box_message').style.width)+pas_width;
document.getElementById('box_message').style.height=parseInt(document.getElementById('box_message').style.height)+pas_height;
document.getElementById('box_message').style.left=parseInt(document.getElementById('box_message').style.left)-pas_left;
document.getElementById('box_message').style.top=parseInt(document.getElementById('box_message').style.top)-pas_top;

zone_plus(pas_top,pas_left,pas_width,pas_height,fi_top,fi_left,fi_width,fi_height,titre);
}

function loadat(zone) {
var flash='<table width=100% height=165 border=0 cellspacing=0 cellpadding=0><tr><td align=center valign=middle><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=\"30\" height=\"30\"><param name=\"movie\" value=\"load2.swf\"><param name=\"wmode\" value=\"transparent\"></param><param name=\"quality\" value=\"high\"><embed src=\"load2.swf\" wmode=\"transparent\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"30\" height=\"30\"></embed></object></td></tr></table>';
var content3 = document.getElementById(zone);
content3.innerHTML = flash;
}

function edit_zone(largeur,hauteur,titre) {
var flash='<table width=90% height=80% border=0 cellspacing=0 cellpadding=0><tr><td align=center valign=middle><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=\"30\" height=\"30\"><param name=\"movie\" value=\"load2.swf\"><param name=\"wmode\" value=\"transparent\"></param><param name=\"quality\" value=\"high\"><embed src=\"load2.swf\" wmode=\"transparent\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"30\" height=\"30\"></embed></object></td></tr></table>';

var content3 = document.getElementById('zone_message');
content3.innerHTML = flash;
motie=largeur/2;
left=512-motie;
motie_hauteur=hauteur/2;
htop=330-motie_hauteur;
document.getElementById('box_message').style.width=largeur;
document.getElementById('titre_zone').style.width=largeur;
document.getElementById('box_message').style.height=hauteur;
document.getElementById('box_message').style.left=left;
document.getElementById('box_message').style.top=htop;
var content1 = document.getElementById('zone_titre');
content1.innerHTML = titre;
}

function end_div(after,id_zone)
{
setTimeout ("visiblite('',id_zone,'hidden')",after); 
}

function end_zone(after)
{
setTimeout ("colse_zone()",after); 
}

function colse_zone()
{
var content = document.getElementById('zone_titre');
content.innerHTML = '';
var content2 = document.getElementById('zone_message');
content2.innerHTML = '';
document.getElementById('box_message').style.visibility='hidden';

nb_select=document.getElementsByTagName("select").length;
for (var i=0; i < nb_select; i=i+1)
{
document.getElementsByTagName("select")[i].style.visibility='visible';
}
}

function to_listing_profil()
{
visiblite('','lecontenu_profil','hidden');
visiblite('','lecontenu','visible');
}

function to_detail_profil()
{

}


function visiblite(control,objet,valeur) {
		if (valeur=='visible')
		{
		document.getElementById(objet).style.visibility='visible';
		}else{
		document.getElementById(objet).style.visibility ='hidden';
		}
}

function visiblite1(control,objet,valeur) {
	if (control=='')
	{
	document.getElementById(objet).style.width=5;
    document.getElementById(objet).style.height=5;

	}else{
		if (valeur=='visible')
		{
		document.getElementById(objet).style.width=815;
    	document.getElementById(objet).style.height=500;
		}
		else 
		{
		document.getElementById(objet).style.width=5;
    	document.getElementById(objet).style.height=5;
		}
	}
}

//-----------------------------------------
function control_login(id_champ,message)
{
var val = document.getElementById(id_champ).value;
var mycontrol=/^[A-Za-z\ ]+$/;
if ((!mycontrol.test(val)) && (val.length<2))
{
rouge_control(id_champ,'rouge');
alert(message);		
return 'walou';
}else{
return val;
}
}
function control_passe(id_champ,message)
{
var valeur= document.getElementById(id_champ).value;
if(valeur=='') 
{
rouge_control(id_champ,'rouge');
alert(message);
return 'walou';
}else{
return valeur;
}
}
//------------------------------------Password
		function passe(passe,passe1,message,message1)
		{
		var val = document.getElementById(passe).value;
		var val1 = document.getElementById(passe1).value;
			if (val.length<5)
			{
			rouge_control(passe,'rouge');
			rouge_control(passe1,'rouge');
			alert(message);		
			return 'walou';
			}else{
				if (val!=val1)
				{
				rouge_control(passe,'rouge');
				rouge_control(passe1,'rouge');
				alert(message1);		
				return 'walou';
				}else{
				return val;
				}
			}
		}
//------------------------------------Confirmation d'email
		function mail_conforirm(mail,mail1,message)
		{
		var val = document.getElementById(mail).value;
		var val1 = document.getElementById(mail1).value;
				if (val!=val1)
				{
				rouge_control(mail,'rouge');
				rouge_control(mail1,'rouge');
				alert(message);		
				return 'walou';
				}else{
				return val;
				}
		
		}
//----------------------------------------
function control_nom(id_champ,message)
{
var val = document.getElementById(id_champ).value;
		   var mycontrol=/^[A-Za-z\ ]+$/;
			if ((!mycontrol.test(val)) && (val.length<2))
			{
			rouge_control(id_champ,'rouge');
			alert(message);		
			return 'walou';
			}else{
			return val;
			}
}
//----------------------------------------
function ville(id_champ)
{
var val = document.getElementById(id_champ).value;
		   var mycontrol=/^[A-Za-z\ ]+$/;
			if ((!mycontrol.test(val)) && (val.length<2))
			{
			rouge_control(id_champ,'rouge');
			alert('Ville invalid!');		
			return 'walou';
			}else{
			return val;
			}
}
//-------------------------------------------------------------
function control_prenom(id_champ,message)
		{
		var val = document.getElementById(id_champ).value;
		   var mycontrol=/^[A-Za-z\ ]+$/;
			if ((!mycontrol.test(val)) && (val.length<2))
			{
			rouge_control(id_champ,'rouge');
			alert(message);		
			return 'walou';
			}else{
			return val;
			}
		}
//-------------------------------------------------------------

//-----------------------------------Check box

function control_check(id_check,message) {	
	if(document.getElementById(id_check).checked){
	return 'yes' ;
	}else{
	rouge_control(id_check,'rouge');
	alert(message);
	return 'walou' ;
	
	}
}
//------------------------------------Id ANNONCE
		function id_annonce(id_champ)
		{
		var val = document.getElementById(id_champ).value;
		   var mycontrol=/^[amvcbAMVCB]+-+[0-9]+$/;
			if (!mycontrol.test(val))
			{
			rouge_control(id_champ,'rouge');
			alert('Id Annonce invalid !');		
			return 'walou';
			}else{
			return val;
			}
		}
//------------------------------------Mail
		function mail(id_champ,message)
		{
		var val = document.getElementById(id_champ).value;
		   var mycontrol=/^[a-zA-Z0-9]+[a-zA-Z0-9\.\-\_]+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
			if (!mycontrol.test(val))
			{
			rouge_control(id_champ,'rouge');
			alert(message);		
			return 'walou';
			}else{
			return val;
			}
		}
		//---------------------------------Tel
		function control_tel(id_champ,message)
		{
		var val_tel = document.getElementById(id_champ).value;
		   var tela=/^[0-9\ +]+$/;
			if (!tela.test(val_tel))
			{
			rouge_control(id_champ,'rouge');
			alert(message);		
			return 'walou';
			}else{
			montel=val_tel.replace(' ','');
			return montel;
			}
		}
//------------------------------------text minimal
		function caract_num(mychamp,number_caract,message)
		{
		var val = document.getElementById(mychamp).value;
		   var cara=/^[0-9\ +]+$/;
			if (!cara.test(val) || val.length<number_caract)
			{
			rouge_control(mychamp,'rouge');
			alert(message);		
			return 'walou';
			}else{
			monval=val.replace(' ','');
			return monval;
			}
		}
//------------------------------------text minimal
		function caract_numbre(mychamp,number,message)
		{
		var val = document.getElementById(mychamp).value;
		   var cara=/^[0-9\ +]+$/;
			if (!cara.test(val) || parseInt(val)<number)
			{
			rouge_control(mychamp,'rouge');
			alert(message);		
			return 'walou';
			}else{
			monval=val.replace(' ','');
			return monval;
			}
		}
		//---------------------------------Annee
		function annee(id_champ)
		{
		var val_annee = document.getElementById(id_champ).value;
		   var anneea=/^[0-9\ +]+$/;
			if (!anneea.test(val_annee) || val_annee.length!=4)
			{
			rouge_control(id_champ,'rouge');
			alert('Année invalid');		
			return 'walou';
			}else{
			monannee=val_annee.replace(' ','');
			return monannee;
			}
		}
		//---------------------------------Prix
		function prix(id_champ)
		{
		var val_prix = document.getElementById(id_champ).value;
		   var prixa=/^[0-9\ ]+$/;
			if (!prixa.test(val_prix))
			{
			rouge_control(id_champ,'rouge');
			alert('Prix invalid');		
			return 'walou';
			}else{
			monprix=val_prix.replace(' ','');
			return monprix;
			}
		}
//----------------------------------------------------------

//------------------------------------------------------------------
function rouge_control(id_control,color)
{
if(color=='rouge')
{
document.getElementById(id_control).style.border='1px solid #DE753D';
	}else{
	document.getElementById(id_control).style.border='1px solid #000000';
	}
}
// +------------------------------------------------------------+
// |                   Popup Calendar(Window)                   |
// +------------------------------------------------------------+
// | Last Modified:                  22-Dec-2005                |
// | Web Site:                       http://www.yxscripts.com   |
// | EMail:                          m_yangxin@hotmail.com      |
// +------------------------------------------------------------+
// |       Copyright 2002  Xin Yang   All Rights Reserved.      |
// |           This version featured on Dynamic Drive           |
// |               (http://www.dynamicdrive.com)                |
// +------------------------------------------------------------+

// default settings
var fontFace="verdana";
var fontSize=9;

var titleWidth=90;
var titleMode=1;
var dayWidth=12;
var dayDigits=1;

var titleColor="#cccccc";
var daysColor="#cccccc";
var bodyColor="#ffffff";
var dayColor="#ffffff";
var currentDayColor="#333333";
var footColor="#cccccc";
var borderColor="#333333";

var titleFontColor = "#333333";
var daysFontColor = "#333333";
var dayFontColor = "#333333";
var currentDayFontColor = "#ffffff";
var footFontColor = "#333333";

var calFormat = "yyyy/mm/dd";

var weekDay = 0;
// ------

// codes
var calWidth=200, calHeight=200, calOffsetX=-200, calOffsetY=16;
var calWin=null;
var winX=0, winY=0;
var cal="cal";
var cals=new Array();
var currentCal=null;

var yxMonths=new Array("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre");
var yxDays=new Array("Dimanche", "Lundi", "Marid", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche");
var yxLinks=new Array("[close]", "[clear]");

var nav=navigator.userAgent.toLowerCase();;
var isOpera=(nav.indexOf("opera")!=-1)?true:false;
var isOpera5=(nav.indexOf("opera 5")!=-1 || nav.indexOf("opera/5")!=-1)?true:false;
var isOpera6=(isOpera && parseInt(navigator.appVersion)>=6)?true:false;
var isN6=(nav.indexOf("gecko")!=-1);
var isN4=(document.layers)?true:false;
var isMac=(nav.indexOf("mac")!=-1);
var isIE=(document.all && !isOpera && (!isMac || navigator.appVersion.indexOf("MSIE 4")==-1))?true:false;

if (isN4) {
  fontSize+=2;
}

var span2="</span>";

function span1(tag) {
  return "<span class='"+tag+"'>";
}
function spanx(tag, color) {
  return "."+tag+" { font-family:"+fontFace+"; font-size:"+fontSize+"px; color:"+color+"; }\n";
}

function a1(tag) {
  return "<a class='"+tag+"' href=";
}

function ax(tag, color) {
  return "."+tag+" { text-decoration:none; color:"+color+"; }\n";
}

function calOBJ(name, title, field, form) {
  this.name = name;
  this.title = title;
  this.field = field;
  this.formName = form;
  this.form = null
}

function setFont(font, size) {
  if (font != "") {
    fontFace=font;
  }
  if (size > 0) {
    fontSize=size;

    if (isN4) {
      fontSize+=2;
    }
  }
}

function setWidth(tWidth, tMode, dWidth, dDigits) {
  if (tWidth > 0) {
    titleWidth=tWidth;
  }
  if (tMode == 1 || tMode == 2) {
    titleMode=tMode;
  }
  if (dWidth > 0) {
    dayWidth=dWidth;
  }
  if (dDigits > 0) {
    dayDigits=dDigits;
  }
}

function setColor(tColor, dsColor, bColor, dColor, cdColor, fColor, bdColor) {
  if (tColor != "") {
    titleColor=tColor;
  }
  if (dsColor != "") {
    daysColor=dsColor;
  }
  if (bColor != "") {
    bodyColor=bColor;
  }
  if (dColor != "") {
    dayColor=dColor;
  }
  if (cdColor != "") {
    currentDayColor=cdColor;
  }
  if (fColor != "") {
    footColor=fColor;
  }
  if (bdColor != "") {
    borderColor=bdColor;
  }
}

function setFontColor(tColorFont, dsColorFont, dColorFont, cdColorFont, fColorFont) {
  if (tColorFont != "") {
    titleFontColor=tColorFont;
  }
  if (dsColorFont != "") {
    daysFontColor=dsColorFont;
  }
  if (dColorFont != "") {
    dayFontColor=dColorFont;
  }
  if (cdColorFont != "") {
    currentDayFontColor=cdColorFont;
  }
  if (fColorFont != "") {
    footFontColor=fColorFont;
  }
}

function setFormat(format) {
  calFormat = format;
}

function setSize(width, height, ox, oy) {
  if (width > 0) {
    calWidth=width;
  }
  if (height > 0) {
    calHeight=height;
  }

  calOffsetX=ox;
  calOffsetY=oy;
}

function setWeekDay(wDay) {
  if (wDay == 0 || wDay == 1) {
    weekDay = wDay;
  }
}

function setMonthNames(janName, febName, marName, aprName, mayName, junName, julName, augName, sepName, octName, novName, decName) {
  if (janName != "") {
    yxMonths[0] = janName;
  }
  if (febName != "") {
    yxMonths[1] = febName;
  }
  if (marName != "") {
    yxMonths[2] = marName;
  }
  if (aprName != "") {
    yxMonths[3] = aprName;
  }
  if (mayName != "") {
    yxMonths[4] = mayName;
  }
  if (junName != "") {
    yxMonths[5] = junName;
  }
  if (julName != "") {
    yxMonths[6] = julName;
  }
  if (augName != "") {
    yxMonths[7] = augName;
  }
  if (sepName != "") {
    yxMonths[8] = sepName;
  }
  if (octName != "") {
    yxMonths[9] = octName;
  }
  if (novName != "") {
    yxMonths[10] = novName;
  }
  if (decName != "") {
    yxMonths[11] = decName;
  }
}

function setDayNames(sunName, monName, tueName, wedName, thuName, friName, satName) {
  if (sunName != "") {
    yxDays[0] = sunName;
    yxDays[7] = sunName;
  }
  if (monName != "") {
    yxDays[1] = monName;
  }
  if (tueName != "") {
    yxDays[2] = tueName;
  }
  if (wedName != "") {
    yxDays[3] = wedName;
  }
  if (thuName != "") {
    yxDays[4] = thuName;
  }
  if (friName != "") {
    yxDays[5] = friName;
  }
  if (satName != "") {
    yxDays[6] = satName;
  }
}

function setLinkNames(closeLink, clearLink) {
  if (closeLink != "") {
    yxLinks[0] = closeLink;
  }
  if (clearLink != "") {
    yxLinks[1] = clearLink;
  }
}

function addCalendar(name, title, field, form) {
  cals[cals.length] = new calOBJ(name, title, field, form);
}

function findCalendar(name) {
  for (var i = 0; i < cals.length; i++) {
    if (cals[i].name == name) {
      if (cals[i].form == null) {
        if (cals[i].formName == "") {
          if (document.forms[0]) {
            cals[i].form = document.forms[0];
          }
        }
        else if (document.forms[cals[i].formName]) {
          cals[i].form = document.forms[cals[i].formName];
        }
      }

      return cals[i];
    }
  }

  return null;
}

function getDayName(y,m,d) {
  var wd=new Date(y,m,d);
  return yxDays[wd.getDay()].substring(0,3);
}

function getMonthFromName(m3) {
  for (var i = 0; i < yxMonths.length; i++) {
    if (yxMonths[i].toLowerCase().substring(0,3) == m3.toLowerCase()) {
      return i;
    }
  }

  return 0;
}

function getFormat() {
  var calF = calFormat;

  calF = calF.replace(/\\/g, '\\\\');
  calF = calF.replace(/\//g, '\\\/');
  calF = calF.replace(/\[/g, '\\\[');
  calF = calF.replace(/\]/g, '\\\]');
  calF = calF.replace(/\(/g, '\\\(');
  calF = calF.replace(/\)/g, '\\\)');
  calF = calF.replace(/\{/g, '\\\{');
  calF = calF.replace(/\}/g, '\\\}');
  calF = calF.replace(/\</g, '\\\<');
  calF = calF.replace(/\>/g, '\\\>');
  calF = calF.replace(/\|/g, '\\\|');
  calF = calF.replace(/\*/g, '\\\*');
  calF = calF.replace(/\?/g, '\\\?');
  calF = calF.replace(/\+/g, '\\\+');
  calF = calF.replace(/\^/g, '\\\^');
  calF = calF.replace(/\$/g, '\\\$');

  calF = calF.replace(/dd/i, '\\d\\d');
  calF = calF.replace(/mm/i, '\\d\\d');
  calF = calF.replace(/yyyy/i, '\\d\\d\\d\\d');
  calF = calF.replace(/day/i, '\\w\\w\\w');
  calF = calF.replace(/mon/i, '\\w\\w\\w');

  return new RegExp(calF);
}

function getDateNumbers(date) {
  var y, m, d;

  var yIdx = calFormat.search(/yyyy/i);
  var mIdx = calFormat.search(/mm/i);
  var m3Idx = calFormat.search(/mon/i);
  var dIdx = calFormat.search(/dd/i);

  y=date.substring(yIdx,yIdx+4)-0;
  if (mIdx != -1) {
    m=date.substring(mIdx,mIdx+2)-1;
  }
  else {
    var m = getMonthFromName(date.substring(m3Idx,m3Idx+3));
  }
  d=date.substring(dIdx,dIdx+2)-0;

  return new Array(y,m,d);
}

function hideCal() {
  calWin.close();
  calWin = null;
  window.status = "";
}

function getLeftIE(x,m) {
  var dx=0;
  if (x.tagName=="TD"){
    dx=x.offsetLeft;
  }
  else if (x.tagName=="TABLE") {
    dx=x.offsetLeft;
    if (m) { dx+=(x.cellPadding!=""?parseInt(x.cellPadding):2); m=false; }
  }
  return dx+(x.parentElement.tagName=="BODY"?0:getLeftIE(x.parentElement,m));
}
function getTopIE(x,m) {
  var dy=0;
  if (x.tagName=="TR"){
    dy=x.offsetTop;
  }
  else if (x.tagName=="TABLE") {
    dy=x.offsetTop;
    if (m) { dy+=(x.cellPadding!=""?parseInt(x.cellPadding):2); m=false; }
  }
  return dy+(x.parentElement.tagName=="BODY"?0:getTopIE(x.parentElement,m));
}

function getLeftN4(l) { return l.pageX; }
function getTopN4(l) { return l.pageY; }

function getLeftN6(l) { return l.offsetLeft; }
function getTopN6(l) { return l.offsetTop; }

function lastDay(d) {
  var yy=d.getFullYear(), mm=d.getMonth();
  for (var i=31; i>=28; i--) {
    var nd=new Date(yy,mm,i);
    if (mm == nd.getMonth()) {
      return i;
    }
  }
}

function firstDay(d) {
  var yy=d.getFullYear(), mm=d.getMonth();
  var fd=new Date(yy,mm,1);
  return fd.getDay();
}

function dayDisplay(i) {
  if (dayDigits == 0) {
    return yxDays[i];
  }
  else {
    return yxDays[i].substring(0,dayDigits);
  }
}

function calTitle(d) {
  var yy=d.getFullYear(), mm=yxMonths[d.getMonth()];
  var s;

  if (titleMode == 2) {
    s="<tr align='center' bgcolor='"+titleColor+"'><td colspan='7'>\n<table cellpadding='0' cellspacing='0' border='0'><tr align='center' valign='middle'><td align='right'>"+span1("title")+"<b>"+a1("titlea")+"'javascript:if(window.opener && !window.opener.closed && window.opener.moveYear) window.opener.moveYear(-10)'>&nbsp;&#171;</a>&nbsp;"+a1("titlea")+"'javascript:if(window.opener && !window.opener.closed && window.opener.moveYear) window.opener.moveYear(-1)'>&#139;&nbsp;</a></b>"+span2+"</td><td width='"+titleWidth+"'><b>"+span1("title")+yy+span2+"</b></td><td align='left'>"+span1("title")+"<b>"+a1("titlea")+"'javascript:if (window.opener && !window.opener.closed && window.opener.moveYear) window.opener.moveYear(1)'>&nbsp;&#155;</a>&nbsp;"+a1("titlea")+"'javascript:if (window.opener && !window.opener.closed && window.opener.moveYear) window.opener.moveYear(10)'>&#187;&nbsp;</a></b>"+span2+"</td></tr><tr align='center' valign='middle'><td align='right'>"+span1("title")+"<b>"+a1("titlea")+"'javascript:if (window.opener && !window.opener.closed && window.opener.prepMonth) window.opener.prepMonth("+d.getMonth()+")'>&nbsp;&#139;&nbsp;</a></b>"+span2+"</td><td width='"+titleWidth+"'><b>"+span1("title")+mm+span2+"</b></td><td align='left'>"+span1("title")+"<b>"+a1("titlea")+"'javascript:if (window.opener && !window.opener.closed && window.opener.nextMonth) window.opener.nextMonth("+d.getMonth()+")'>&nbsp;&#155;&nbsp;</a></b>"+span2+"</td></tr></table>\n</td></tr><tr align='center' bgcolor='"+daysColor+"'>";
  }
  else {
    s="<tr align='center' bgcolor='"+titleColor+"'><td colspan='7'>\n<table cellpadding='0' cellspacing='0' border='0'><tr align='center' valign='middle'><td>"+span1("title")+"<b>"+a1("titlea")+"'javascript:if(window.opener && !window.opener.closed && window.opener.moveYear) window.opener.moveYear(-1)'>&nbsp;&#171;</a>&nbsp;"+a1("titlea")+"'javascript:if (window.opener && !window.opener.closed && window.opener.prepMonth) window.opener.prepMonth("+d.getMonth()+")'>&#139;&nbsp;</a></b>"+span2+"</td><td width='"+titleWidth+"'><nobr><b>"+span1("title")+mm+" "+yy+span2+"</b></nobr></td><td>"+span1("title")+"<b>"+a1("titlea")+"'javascript:if (window.opener && !window.opener.closed && window.opener.nextMonth) window.opener.nextMonth("+d.getMonth()+")'>&nbsp;&#155;</a>&nbsp;"+a1("titlea")+"'javascript:if(window.opener && !window.opener.closed && window.opener.moveYear) window.opener.moveYear(1)'>&#187;&nbsp;</a></b>"+span2+"</td></tr></table>\n</td></tr><tr align='center' bgcolor='"+daysColor+"'>";
  }

  for (var i=weekDay; i<weekDay+7; i++) {
    s+="<td width='"+dayWidth+"'>"+span1("days")+dayDisplay(i)+span2+"</td>";
  }

  s+="</tr>";

  return s;
}

function calHeader() {
  return "<head>\n<title>"+currentCal.title+"</title>\n<style type='text/css'>\n"+spanx("title",titleFontColor)+spanx("days",daysFontColor)+spanx("foot",footColor)+spanx("day",dayFontColor)+spanx("currentDay",currentDayFontColor)+ax("titlea",titleFontColor)+ax("daya",dayFontColor)+ax("currenta",currentDayFontColor)+ax("foota",footFontColor)+"</style>\n</head>\n<body>\n<table align='center' border='0' bgcolor='"+borderColor+"' cellspacing='0' cellpadding='1'><tr><td>\n<table cellspacing='1' cellpadding='3' border='0'>";
}

function calFooter() {
  return "<tr bgcolor='"+footColor+"'><td colspan='7' align='center'>"+span1("foot")+"<b>"+a1("foota")+"'javascript:if (window.opener && !window.opener.closed && window.opener.hideCal) window.opener.hideCal()'>"+yxLinks[0]+"</a>&nbsp;&nbsp;"+a1("foota")+"'javascript:if (window.opener && !window.opener.closed && window.opener.clearDate) window.opener.clearDate()'>"+yxLinks[1]+"</a></b>"+span2+"</td></tr></table>\n</td></tr></table>\n</body>";
}

function calBody(d,day) {
  var s="", dayCount=1, fd=firstDay(d), ld=lastDay(d);

  if (weekDay > 0 && fd == 0) {
    fd = 7;
  }

  for (var i=0; i<6; i++) {
    s+="<tr align='center' bgcolor='"+bodyColor+"'>";
    for (var j=weekDay; j<weekDay+7; j++) {
      if (i*7+j<fd || dayCount>ld) {
        s+="<td>"+span1("day")+"&nbsp;"+span2+"</td>";
      }
      else {
        var bgColor=dayColor;
        var fgTag="day";
        var fgTagA="daya";
        if (dayCount==day) { 
          bgColor=currentDayColor; 
          fgTag="currentDay";
          fgTagA="currenta";
        }
        
        s+="<td bgcolor='"+bgColor+"'>"+span1(fgTag)+a1(fgTagA)+"'javascript: if (window.opener && !window.opener.closed && window.opener.pickDate) window.opener.pickDate("+dayCount+")'>"+(dayCount++)+"</a>"+span2+"</td>";
      }
    }
    s+="</tr>";
  }

  return s;
}

function moveYear(dy) {
  cY+=dy;
  var nd=new Date(cY,cM,1);
  changeCal(nd);
}

function prepMonth(m) {
  cM=m-1;
  if (cM<0) { cM=11; cY--; }
  var nd=new Date(cY,cM,1);
  changeCal(nd);
}

function nextMonth(m) {
  cM=m+1;
  if (cM>11) { cM=0; cY++;}
  var nd=new Date(cY,cM,1);
  changeCal(nd);
}

function changeCal(d) {
  var dd = 0;

  if (currentCal != null) {
    var calRE = getFormat();

    if (currentCal.form[currentCal.field].value!="" && calRE.test(currentCal.form[currentCal.field].value)) {
      var cd = getDateNumbers(currentCal.form[currentCal.field].value);
      if (cd[0] == d.getFullYear() && cd[1] == d.getMonth()) {
        dd=cd[2];
      }
    }
    else {
      var cd = new Date();
      if (cd.getFullYear() == d.getFullYear() && cd.getMonth() == d.getMonth()) {
        dd=cd.getDate();
      }
    }
  }

  var calendar=calHeader()+calTitle(d)+calBody(d,dd)+calFooter();

  calWin.document.open();
  calWin.document.write(calendar);
  calWin.document.close();
}

function markClick(e) {
  if (isIE || isOpera6) {
    winX=event.screenX;
    winY=event.screenY;
  }
  else if (isN4 || isN6) {
    winX=e.screenX;
    winY=e.screenY;

    document.routeEvent(e);
  }

  if (isN4 || isN6) { 
    document.routeEvent(e); 
  } 
  else { 
    event.cancelBubble=false; 
  } 

  return true;
}

function showCal(name) {
  var lastCal=currentCal;
  var d=new Date(), hasCal=false;

  currentCal = findCalendar(name);

  if (currentCal != null && currentCal.form != null && currentCal.form[currentCal.field]) {
    var calRE = getFormat();

    if (currentCal.form[currentCal.field].value!="" && calRE.test(currentCal.form[currentCal.field].value)) {
      var cd = getDateNumbers(currentCal.form[currentCal.field].value);
      d=new Date(cd[0],cd[1],cd[2]);

      cY=cd[0];
      cM=cd[1];
      dd=cd[2];
    }
    else {
      cY=d.getFullYear();

      cM=d.getMonth();
      dd=d.getDate();
    }

    var calendar=calHeader()+calTitle(d)+calBody(d,dd)+calFooter();

    if (calWin != null && typeof(calWin.closed)!="undefined" && !calWin.closed) {
      hasCal=true;
      calWin.moveTo(winX+calOffsetX,winY+calOffsetY);
    }

    if (!hasCal) {
      if (isIE || isOpera6) {
        calWin=window.open("","cal","toolbar=0,width="+calWidth+",height="+calHeight+",left="+(winX+calOffsetX)+",top="+(winY+calOffsetY));
      }
      else {
        calWin=window.open("","cal","toolbar=0,width="+calWidth+",height="+calHeight+",screenx="+(winX+calOffsetX)+",screeny="+(winY+calOffsetY));
      }
    }

    calWin.document.open();
    calWin.document.write(calendar);
    calWin.document.close();

    calWin.focus();
  }
  else {
    if (currentCal == null) {
      window.status = "Calendar ["+name+"] not found.";
    }
    else if (!currentCal.form) {
      window.status = "Form ["+currentCal.formName+"] not found.";
    }
    else if (!currentCal.form[currentCal.field]) {
      window.status = "Form Field ["+currentCal.formName+"."+currentCal.field+"] not found.";
    }

    if (lastCal != null) {
      currentCal = lastCal;
    }
  }
}

function get2Digits(n) {
  return ((n<10)?"0":"")+n;
}

function clearDate() {
  currentCal.form[currentCal.field].value="";
  hideCal();
}

function pickDate(d) {
  hideCal();
  window.focus();

  var date=calFormat;
  date = date.replace(/yyyy/i, cY);
  date = date.replace(/mm/i, get2Digits(cM+1));
  date = date.replace(/MON/, yxMonths[cM].substring(0,3).toUpperCase());
  date = date.replace(/Mon/i, yxMonths[cM].substring(0,3));
  date = date.replace(/dd/i, get2Digits(d));
  date = date.replace(/DAY/, getDayName(cY,cM,d).toUpperCase());
  date = date.replace(/day/i, getDayName(cY,cM,d));

  currentCal.form[currentCal.field].value=date;
  // IE5/Mac needs focus to show the value, weird.
  currentCal.form[currentCal.field].focus();
}
// ------

// user functions
function checkDate(name) {
  var thisCal = findCalendar(name);

  if (thisCal != null && thisCal.form != null && thisCal.form[thisCal.field]) {
    var calRE = getFormat();

    if (calRE.test(thisCal.form[thisCal.field].value)) {
      return 0;
    }
    else {
      return 1;
    }
  }
  else {
    return 2;
  }
}

function getCurrentDate() {
  var date=calFormat, d = new Date();
  date = date.replace(/yyyy/i, d.getFullYear());
  date = date.replace(/mm/i, get2Digits(d.getMonth()+1));
  date = date.replace(/dd/i, get2Digits(d.getDate()));

  return date;
}

function compareDates(date1, date2) {
  var calRE = getFormat();
  var d1, d2;

  if (calRE.test(date1)) {
    d1 = getNumbers(date1);
  }
  else {
    d1 = getNumbers(getCurrentDate());
  }

  if (calRE.test(date2)) {
    d2 = getNumbers(date2);
  }
  else {
    d2 = getNumbers(getCurrentDate());
  }

  var dStr1 = d1[0] + "" + d1[1] + "" + d1[2];
  var dStr2 = d2[0] + "" + d2[1] + "" + d2[2];

  if (dStr1 == dStr2) {
    return 0;
  }
  else if (dStr1 > dStr2) {
    return 1;
  }
  else {
    return -1;
  }
}

function getNumbers(date) {
  var calRE = getFormat();
  var y, m, d;

  if (calRE.test(date)) {
    var yIdx = calFormat.search(/yyyy/i);
    var mIdx = calFormat.search(/mm/i);
    var m3Idx = calFormat.search(/mon/i);
    var dIdx = calFormat.search(/dd/i);

    y=date.substring(yIdx,yIdx+4);
    if (mIdx != -1) {
      m=date.substring(mIdx,mIdx+2);
    }
    else {
      var mm=getMonthFromName(date.substring(m3Idx,m3Idx+3))+1;
      m=(mm<10)?("0"+mm):(""+mm);
    }
    d=date.substring(dIdx,dIdx+2);

    return new Array(y,m,d);
  }
  else {
    return new Array("", "", "");
  }
}
// ------

if (isN4 || isN6) {
  document.captureEvents(Event.CLICK);
}
document.onclick=markClick;
//Define calendar(s): addCalendar ("Unique Calendar Name", "Window title", "Form element's name", Form name")
addCalendar("Calendar1", "Calendrier", "de", "sampleform");
addCalendar("Calendar2", "Calendrier", "a", "sampleform");
addCalendar("Calendar3", "Calendrier", "date_debut", "sampleform");
addCalendar("Calendar4", "Calendrier", "date_fin", "sampleform");
// default settings for English
// Uncomment desired lines and modify its values
// setFont("verdana", 9);
 setWidth(90, 1, 15, 1);
// setColor("#cccccc", "#cccccc", "#ffffff", "#ffffff", "#333333", "#cccccc", "#333333");
// setFontColor("#333333", "#333333", "#333333", "#ffffff", "#333333");
// setFormat("yyyy/mm/dd");
// setSize(200, 200, -200, 16);

// setWeekDay(0);
// setMonthNames("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
// setDayNames("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
// setLinkNames("[Close]", "[Clear]");