
function deuxC(texte)
{
	texte = texte.toString();
	if(texte.length==1)
		return '0' + texte;
	else
		return texte;
}

function showPopup(link,h,w)
{
	window.open(link, "showPopup", "toolbar=no, status=yes, scrollbars=no, resizable=no, width=" + w + ", height=" + h);
}

function makeHomePage(url,myPage)
{

	if (window.sidebar) // Firefox
    {
        //return true;
    } 
    else if(window.opera && window.print) // Opera
    {
		//return true;
    } 
    else if(document.all) // IE
    {
    alert(myPage);
		//myPage.style.behavior='url(#default#homepage)';
		myPage.setHomePage(url);
    }
}


function makeBookMark(url,title)
{
    if (window.sidebar) // Firefox
    {
        //window.sidebar.addPanel(title, url,"");
        //return true;
    } 
    else if(window.opera && window.print) // Opera
    {
		//return true;
    } 
    else if(document.all) // IE
    {
		window.external.AddFavorite( url, title);
    }
}

function isDateValid(chaineDate) 
{
	// Si la chaine est vide 
	if (chaineDate == "") 
		return false;

	// On récupére le jour / mois / année
	var ladate = (chaineDate).split("/");

	// Si l'on n'a pas récupéré trois éléments ou bien s'il ne s'agit pas d'entiers
	if ((ladate.length != 3) || isNaN(parseInt(ladate[0])) || isNaN(parseInt(ladate[1])) || isNaN(parseInt(ladate[2])))
		return false;

	// Création d'une date JavaScript avec la date passée en argument. Attention, les mois sont étalonnés de 0 à 11 !
	var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]));

	// Modification de la date si elle ne comporte pas 4 chiffres
	var annee = unedate.getYear();
	
	if ((Math.abs(annee)+"").length < 4) 
		annee = annee + 1900;

	// Test d'égalité entre la date passée en paramètre et celle donnée par le JavaScript.
	return ((unedate.getDate() == eval(ladate[0])) && (unedate.getMonth() == eval(ladate[1])-1) && (annee == eval(ladate[2])))
}

function somethingSelected(element, message)
{
	if(document.getElementById(element).value == 0)
	{
		alert(message);
		return false;
	}
	return true;
}	

Date.prototype.addOneDay = function()
{
	var	daysInMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	if((this.getFullYear()%4 == 0 && this.getFullYear()%100 != 0) || this.getFullYear() == 0)
		daysInMonth[1] = 29;

	var dayOfDate = this.getDate();
	if(this.getDate() == daysInMonth[this.getMonth() + 1])
	{
		this.setDate(1);
		if(this.getMonth() + 1 == 12)
			{
				this.setMonth(0)
				this.setFullYear(this.getFullYear()+1)
			}
		else
			this.setMonth(this.getMonth() + 1);
	}
	else
		this.setDate(this.getDate()+1);
}

Date.prototype.addDay = function (nbDay)
{
	for(var i=0;i<nbDay;i++)
		this.addOneDay();
}

Date.prototype.dateToString = function (format)
{
	if(format=='DDMMYYYY')
		return deuxC(this.getDate()) + deuxC(this.getMonth() + 1) + this.getFullYear();
	else if(format=='YYYYMMDD')
		return this.getFullYear() + deuxC(this.getMonth() + 1) +  deuxC(this.getDate());
	else if(format=='DD/MM/YYYY')
		return deuxC(this.getDate()) + '/' + deuxC(this.getMonth() + 1) + '/' + this.getFullYear();
};	

