//$(\'fils_'.$row->page_id.'\').setStyle(\'display\', \'block\')
function in_array(needle, haystack, argStrict)
{
    var key = '', strict = !!argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
 
    return false;
}

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 verif_horaire(date)
{
	var e = new RegExp("^[0-9]{1,2}:[0-9]{1,2}$");			
	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_horaire(el){
    if (!verif_horaire(el.value)) {
	//	alert("dqsdqsd");
        el.errors.push("L'horaire n'est pas au format HH:MM");
        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 formcheck_img(el)
{
	var ext	=	el.value.substr(el.value.lastIndexOf(".")+1);
	ext		=	ext.toLowerCase();
	if(ext != 'gif' && ext != 'jpg' && ext != 'jpeg')
	{
		el.errors.push("Votre fichier n'est pas une image valide (JPG et GIF uniquement)");
		return false;
	}
	else
	{
		return true;
	}	
}

function formcheck_png_gif(el)
{
	var ext	=	el.value.substr(el.value.lastIndexOf(".")+1);
	ext		=	ext.toLowerCase();
	if(ext != 'gif' && ext != 'png')
	{
		el.errors.push("Votre fichier n'est pas une image valide (PNG et GIF uniquement)");
		return false;
	}
	else
	{
		return true;
	}	
}

function formcheck_png(el)
{
	var ext	=	el.value.substr(el.value.lastIndexOf(".")+1);
	ext		=	ext.toLowerCase();
	if(ext != 'png')
	{
		el.errors.push("Votre fichier n'est pas une image valide (PNG uniquement)");
		return false;
	}
	else
	{
		return true;
	}	
}

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

function centrerDiv(div)
{
	var scroll_win	=	window.getScroll();
	var ScrollX		=	scroll_win.x;
	var ScrollY		=	scroll_win.y;
	
	var dimension	=	window.getSize();
	var width		=	dimension.x;
	var height		=	dimension.y;	
	
	var size = div.measure(function(){
		return this.getSize();
	});
	var divWidth	=	size.x;
	var divHeight	=	size.y;
	
	if(divHeight < height)
		var s_top	=	((height / 2 - divHeight / 2 + ScrollY));
	else
		var s_top	=	(25 + ScrollY);
	
	if(divWidth < width)
		var s_left	=	((width / 2 - divWidth / 2 + ScrollX));
	else
		var s_left	=	(25 + ScrollX);
		
	div.setStyles({top : s_top, left : s_left, opacity : 0, display : "block"});
	//div.fade(0);
//	div.setStyle('display', "block");
	div.fade(1);
}


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;
}

function init_roll()
{
	$$('img.roll', 'input.roll').each(function(el)
	{
		// Preloader
		preLoadArray[preLoadNum] = new Image();
		preLoadArray[preLoadNum].src = el.src.replace('_off', '_on');
		preLoadNum++;

		el.addEvent('mouseover',function(){
			this.setAttribute('src',this.src.replace('_off', '_on'));
		});

		el.addEvent('mouseout',function(){
			this.setAttribute('src',this.src.replace('_on','_off'));
		});
	});	
	
	$$('button.roll').each(function(el)
	{
		// Preloader
		preLoadArray[preLoadNum] = new Image();
		preLoadArray[preLoadNum].src = el.getElement('img').src.replace('_off', '_on');
		preLoadNum++;

		el.addEvent('mouseover',function(){
			this.getElement('img').setAttribute('src',this.getElement('img').src.replace('_off', '_on'));
		});

		el.addEvent('mouseout',function(){
			this.getElement('img').setAttribute('src',this.getElement('img').src.replace('_on','_off'));
		});
	});
}


/**
 * 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;
}

function change_categorie_thematique(bouton, thematique_categorie_id)
{
	$$('.lien_thema').each(function(el)
	{
		var img	=	el.getElement("img");
		img.src	=	img.src.replace('_on', '_off');
	});
	
	var img	=	bouton.getElement("img");
	img.src	=	img.src.replace('_off', '_on');
	
	$("liste_article_thematique").innerHTML	=	'<div style="position:absolute;top:50%;left:50%;margin:-21px 0 0 -21px;width:42px;height:42px;"><img src="images/thematique_loading.gif" alt="chargement" /></div>';
	xajax_thematique_categorie(thematique_categorie_id);
	
	
}

function init_recherche()
{
	var valeur = $('recherche').value;
	if (valeur == 'Mot clé, référence...')
	{
		$('recherche').value = '';
	}
}
