function trim(aString) 
{
	var regExpBeginning = /^\s+/;
	var regExpEnd       = /\s+$/;
    return aString.replace(regExpBeginning, "").replace(regExpEnd, "");
}

function verif_date(date)
{
	var e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");			
	if (!e.test(date)) // On teste l'expression régulière pour valider la forme de la date
	{
		return false;
	}	
	return true;
}

function affiche_div(nom_el)
{
	monElement = $(nom_el);
	if (monElement.style.display == 'none')
		monElement.style.display = 'block';
	else
		monElement.style.display = 'none';
}

function formcheck_date(el){
    if (!verif_date(el.value)) {
	//	alert("dqsdqsd");
        el.errors.push("La date n'est pas au format JJ/MM/AAAA");
        return false;
    } else {
        return true;
    }
}

function formcheck_password(el)
{
	if($('confirm_password').value != '' && $('confirm_password').value != $('password').value)
	{
		el.errors.push("La confirmation ne correspond pas au mot de passe.");
		return false;
	}
	else
	{
		return true;
	}
}

function clear_champ(el, passwd)
{
	el.value	=	"";
	/*if (passwd)
		el.type	=	"password";*/
}

/* NAVIGATEUR */

function getStyle(x,styleProp)
{
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function centrerDiv(div)
{
	var Scroll	=	get_scroll();
	ScrollX		=	Scroll[0];
	ScrollY		=	Scroll[1];
	
	var size	=	get_viewport_size();
	width		=	size[0];
	height		=	size[1];
	
	if(div.style.height == '')
		divHeight	=	getStyle(div, 'height');
	else
		divHeight	=	div.style.height;
	if(div.style.width == '')
		divWidth	=	getStyle(div, 'width');
	else
		divWidth	=	div.style.width;
		
	// On enleve le 'px'
	divHeight	=	divHeight.substr(0, divHeight.length - 2);
	divWidth	=	divWidth.substr(0, divWidth.length - 2);
	
	if(divHeight < height)
		div.style.top	=	((height / 2 - divHeight / 2 + ScrollY)) + "px";
	else
		div.style.top	=	(25 + ScrollY) +'px';
	
	if(divWidth < width)
		div.style.left	=	((width / 2 - divWidth / 2 + ScrollX)) + "px";
	else
		div.style.left	=	(25 + ScrollX) +'px';
}

function get_scroll()
{
	if (navigator.appName=="Microsoft Internet Explorer")
	{
		ScrollY = document.documentElement.scrollTop + document.body.scrollTop;
		ScrollX = document.documentElement.scrollLeft + document.body.scrollLeft;
	}
	else
	{
		ScrollY = window.pageYOffset;
		ScrollX = window.pageXOffset;
	}
	return new Array(ScrollX, ScrollY);
}

function get_viewport_size()
{
	/*
	if (document.body)
	{
		var larg = (document.body.clientWidth);
		var haut = (document.body.clientHeight);
	}
	else
	{
		var larg = (window.innerWidth);
		var haut = (window.innerHeight);
	}
	*/
	var viewportwidth;
 	var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth,
		  viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth,
		   viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	
	return new Array(viewportwidth, viewportheight);
}

function number_format(valeur, nbDecimal, sep) 
{
	var div		=	Math.pow(10,nbDecimal);
	var val		=	Math.round( ( valeur * div) ) / div;

	
	var deci	=	val.toString().split(".");
	if(deci.length > 1)
	{
		var nbDeci	=	deci[1].length;
		var decim	=	deci[1];
	}
	else
	{
		var nbDeci	=	0;
		var decim	=	"";
	}
	for (var j = 0; j < (nbDecimal - nbDeci); j++) 
	{
		decim+="0";
	}
	return deci[0]+sep+decim;
}


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
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 strDay=dtStr.substring(0,pos1)
	var strMonth=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){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}