/**
 * Ouvre l'url spécifiée en popup dans une fentre de la taille souhaitée
 */
function openWindow(url, width, height) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var p = window.open(url, 'popup', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',directories=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,closed=0,opener=0');
} // end of 'openWindow()'

/**
 * Verifie que la chaine passée n'est pas une chaine vide
 *
 * @param	string strSaisie	Chaine de caractère
 * @return	boolean				Retourne false si elle est vide, true dans la cas contraire
 */
function isBlank(strSaisie) {
	var iSaisie = 0;
	var strBlank = ""

	if (strSaisie != "") {
		for (i=0; i < strSaisie.length; i++)
			if (strSaisie.charAt(i) != ' ') iSaisie = 1;
		if (iSaisie == 1)
			return false;
	}
	return true;
}

/**
 * Verifie la validité d'une adresse email (presence d'un @ puis d'un .
 *
 * @param	string strSaisie	Adresse email à vérifier
 * @return	boolean				Retourne true si c'est une adresse email, false dans le cas contraire
 */
function isEmail(strSaisie) {
	a = strSaisie.indexOf("@");
	if ( a != -1 ) {
		p = strSaisie.indexOf(".", a);
		if ( p != -1 )
			return true;
	}
	return false;
}

/**
 * Verifie si un objet de type radio ou checkbox a au moins un element selectionné
 *
 * @param	object obj	Input de type radio ou checkbox d'un formulaire
 * @return	boolean		Retourne true si un element au moins est selectionné false dans le cas contraire
 * @author				David Duret
 * @created				2002-06-12
 */
function isChecked(obj) {
	for ( var i = 0; i < obj.length; i++ ) {
		if ( typeof(checked) == 'undefined' ) checked = false;
		checked = ( obj[i].checked || checked );
	}
	return checked
}

/**
 * Vérifie une date au format francais dd/mm/yyyy
 */
function isDate( dateStr ) {
    
    var pattern = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
    var matchArray = dateStr.match(pattern); // is the format ok?
    if ( matchArray == null ) {
    //alert("Entrez la date sous le format jj/mm/aaaa.");
        return false;
    }
    //alert(matchArray);
    day = matchArray[1];
    month = matchArray[2]; // parse date into variables
    year = matchArray[3];
    if (month < 1 || month > 12) { // check month range
    //alert("Le mois doit être compris entre 1 et 12.");
    return false;
    }
    
    if (day < 1 || day > 31) {
    //alert("Le jour doit être compris entre 1 et 31.");
    return false;
    }
    
    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    //alert("Le mois " + month + " n'a pas 31 jours !")
    return false;
    }
    
    if (month == 2) { // check for february 29th
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day > 29 || (day==29 && !isleap)) {
    //alert("Il n'y a pas " + day + " jours en février " + year + " !");
    return false;
    }
    }
    return true; // date is valid
} // end of 'isDate()'

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

