//function menu(id)
//{
//	alert(id);
//$(document).ready(function() {
//  $('span.demo'+id+'').contextMenu('myMenu1'+id+'', {
//	bindings: {
//	  'open': function(t) {
//		alert('Trigger was '+t.id+'\nAction was Open');
//	  },
//	  'email': function(t) {
//		alert('Trigger was '+t.id+'\nAction was Email');
//	  },
//	  'save': function(t) {
//		alert('Trigger was '+t.id+'\nAction was Save');
//	  },
//	  'delete': function(t) {
//		alert('Trigger was '+t.id+'\nAction was Delete');
//	  }
//	}
//  });
//});
function focus_jquery()
{
document.getElementById('focus_jquery').focus();	
}
function dialog_erreur_new(texte)
{
document.getElementById('dialog_erreur').innerHTML=texte;
	$("#dialog_erreur").dialog(
	{
	modal:true,
	resizable:false,
	closeOnEscape:false,
	width:400,
	height:150,
	title:'Erreur',
		buttons:
		{
			Corriger:function()
			{
			$(this).dialog('destroy');
			}
		}
	});
focus_jquery();
}
function dialog_erreur_ajustable(texte)
{
document.getElementById('dialog_erreur').innerHTML=texte;
	$("#dialog_erreur").dialog(
	{
	modal:true,
	resizable:false,
	closeOnEscape:false,
	width:400,
	title:'Erreur',
		buttons:
		{
			Corriger:function()
			{
			$(this).dialog('destroy');
			}
		}
	});
focus_jquery();
}
function dialog_erreur()
{
$("#dialog").dialog("destroy");
	$("#dialog_erreur").dialog(
	{
	modal:true,
	resizable:false,
	closeOnEscape:false,
	width:400,
	title:'Erreur',
		buttons:
		{
			Corriger:function()
			{
			$(this).dialog('destroy');
			}
		}
	});
focus_jquery();
}
function dialog_confirmation_message_type()
{
	$("#dialog_confirmation_message_type").dialog(
	{
	modal:true,
	resizable:false,
	closeOnEscape:false,
	width:400,
	title:'Confirmation',
		buttons:
		{
			Fermer:function()
			{
			$(this).dialog('destroy');
			}
		}
	});
}
function dialog_envoi(id,client,type)
{
var height=570;
	if(type=='facture')
	{
	var titre='Envoi d\'une facture par e-mail';	
	}
	else if(type=='devis')
	{
	var titre='Envoi d\'un devis par e-mail';	
	}
	else if(type=='attestation_fiscale')
	{
	var titre='Envoi d\'une attestation fiscale par e-mail';	
	var height=530;	
	}
	else if(type=='toutes_les_attestations_fiscales')
	{
	var height=480;	
	var titre='Envoi de toutes les attestations fiscales par e-mail';	
	}
ajax('../ajax/ajax_envoi_mails.php?envoi_jquery&id='+id+'&client='+client+'&type='+type+'','dialog_envoi');
$("#dialog_envoi").dialog('destroy');// Pour permettre la réouverture de la fenêtre même après le clic sur la croix Fermer
	$("#dialog_envoi").dialog(
	{
	modal:true,
	resizable:false,
	closeOnEscape:false,
	width:475,
	height:height,
	title:titre,
		buttons:
		{
			Envoyer:function()
			{
				if(document.getElementById('envoi_mail_message').value=='')
				{
					$("#dialog_message_manquant").dialog(
					{
					modal:true,
					resizable:false,
					closeOnEscape:false,
					width:400,
					title:'Erreur',
						buttons:
						{
							Fermer:function()
							{
							$(this).dialog('destroy');
							}
						}
					});
				}
				else
				{
					if(type=='facture')
					{
					ajax_post('../ajax/ajax_envoi_mails.php','','envoi_mail_facture');
					}
					else if(type=='devis')
					{
					ajax_post('../ajax/ajax_envoi_mails.php','','envoi_mail_devis');
					}
					else if(type=='attestation_fiscale')
					{
					ajax_post('../ajax/ajax_envoi_mails.php','','envoi_mail_attestation_fiscale');
					}
					else if(type=='toutes_les_attestations_fiscales')
					{
					ajax_post('../ajax/ajax_envoi_mails.php','','envoi_mail_toutes_les_attestations_fiscales');
					}
				$(this).dialog('destroy');
				$("#dialog_envoi").dialog('destroy');// Pour permettre la réouverture de la fenêtre même après le clic suir la croix Fermer
					$("#dialog_envoi_confirmation").dialog(
					{
					modal:true,
					resizable:false,
					closeOnEscape:false,
					width:400,
					title:'Confirmation',
						buttons:
						{
							Fermer:function()
							{
							$(this).dialog('destroy');
							}
						}
					});
				}
			},
			Annuler:function()
			{
			$(this).dialog('destroy');
			}
		}
	});
focus_jquery();
}
function afficher(element)
{
	if (document.getElementById && document.getElementById(element) != null)
	{
	document.getElementById(element).style.display='block';
	}
}
function afficher_inline(element)
{
	if (document.getElementById && document.getElementById(element) != null)
	{
	document.getElementById(element).style.display='inline';
	}
}
function masquer_inline(element)
{
	if (document.getElementById && document.getElementById(element) != null)
	{
	document.getElementById(element).style.display='none';
	}
}
function afficher_2(element,element_2)
{
	if (document.getElementById && document.getElementById(element) != null)
	{
	document.getElementById(element).style.display='block';
	document.getElementById('calendrier_pop_up_titre').innerHTML=element_2;
	}
}
function afficher_inline(element)
{
	if(document.getElementById && document.getElementById(element) != null)
	{
	document.getElementById(element).style.display='inline';
	}
}
function masquer(element)
{
	if(document.getElementById && document.getElementById(element) != null)
	{
	document.getElementById(element).style.display='none';
	}
}
function effacer(element)
{
document.getElementById(element).value='';
}
function effacer_html(element)
{
document.getElementById(element).innerHTML='';
}
function inserer(variable1,variable2)
{
document.getElementById(variable1).value=variable2;
}
function inserer_html(variable1,variable2)
{
document.getElementById(variable1).innerHTML=variable2;
}
function inserer_loading(cadre)
{
document.getElementById(cadre).innerHTML='<br /><img src="../images/loading.gif" /><br /><br />';
}
function inserer_plus(variable1,variable2)
{
document.getElementById(variable1).value+=variable2;
}
function adresse_e_mail_1()
{
	if (document.getElementById('identification_e_mail').value=='votre adresse e-mail')
	{
	document.getElementById('identification_e_mail').value='';
	}
}
function adresse_e_mail_2()
{
	if (document.getElementById('identification_e_mail').value=='')
	{
	document.getElementById('identification_e_mail').value='votre adresse e-mail';
	}
}
function desactiver(element)
{
	if (document.getElementById && document.getElementById(element) != null)
	{
	document.getElementById(element).disabled='disabled';
	}
}
function mettre_en_gras(element)
{
	if (document.getElementById && document.getElementById(element) != null)
	{
	document.getElementById(element).className='gras';
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////// Contrôle de la date //////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Fonction checkdate
function checkdate(chaineDate)
{
	if(chaineDate=='')
	{
	return false;
	}
var ladate=(chaineDate).split("/");
var unedate=new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]));
var annee=unedate.getYear();
	if ((Math.abs(annee)+"").length<4)
	{
	annee=annee+1900;
	return ((unedate.getDate()==eval(ladate[0])) && (unedate.getMonth()==eval(ladate[1])-1) && (annee==eval(ladate[2])));
	}
}

// Fonction checkdate
function checkdate(chaineDate)
{
	if(chaineDate=='')
	{
	return false;
	}
var ladate=(chaineDate).split("/");
var unedate=new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]));
var annee=unedate.getYear();
	if ((Math.abs(annee)+"").length<4)
	{
	annee=annee+1900;
	return ((unedate.getDate()==eval(ladate[0])) && (unedate.getMonth()==eval(ladate[1])-1) && (annee==eval(ladate[2])));
	}
}
var dtCh="/";
var minYear=1900;
var maxYear=2100;
function isInteger(s){
	var i;
    for (i=0;i<s.length;i++){   
        // Check that current character is number.
        var c=s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag){
	var i;
    var returnString="";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i=0;i<s.length;i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c)==-1) returnString+=c;
    }
    return returnString;
}
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year%4==0) && ((!(year%100==0)) || (year%400==0)))?29:28);
}
function DaysArray(n) {
	for (var i=1;i<=n;i++){
		this[i]=31
		if (i==4 || i==6 || i==9 || i==11) {this[i]=30}
		if (i==2){this[i]=29}
   } 
   return this;
}
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false;
	}
return true
}
function controle_date(date)
{
	if (isDate(date)==false)
	{
	return false;
	}
	else
	{
	return true;
	}
return true;
}
// Fin contrôle de la date
function deux_chiffres(variable)
{
	if(variable=='0' || variable.toString().length==1)
	{
	variable='0'+variable;
	}
return variable;
}
