function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',resizable,scrollbars'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


function emptyField(textObj)
{
	if (textObj.value.length == 0) return true;
	for (var i=0; i<textObj.value.length; ++i) {
		var ch = textObj.value.charAt(i);
		if (ch != ' ' && ch != '\t') return false;
	}
	return true;
}

function empty (mixed_var) {
    // !No description available for empty. @php.js developers: Please update the function summary text file.
    // 
    // version: 1009.2513
    // discuss at: http://phpjs.org/functions/empty    // +   original by: Philippe Baumann
    // +      input by: Onno Marsman
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: LH
    // +   improved by: Onno Marsman    // +   improved by: Francesco
    // +   improved by: Marc Jansen
    // +   input by: Stoyan Kyosev (http://www.svest.org/)
    // *     example 1: empty(null);
    // *     returns 1: true    // *     example 2: empty(undefined);
    // *     returns 2: true
    // *     example 3: empty([]);
    // *     returns 3: true
    // *     example 4: empty({});    // *     returns 4: true
    // *     example 5: empty({'aFunc' : function () { alert('humpty'); } });
    // *     returns 5: false
    
    var key;    
    if (mixed_var === "" ||
        mixed_var === 0 ||
        mixed_var === "0" ||
        mixed_var === null ||        mixed_var === false ||
        typeof mixed_var === 'undefined'
    ){
        return true;
    } 
    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            return false;
        }        return true;
    }
 
    return false;
}


function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function isPosInteger (inputVal) {
	inputStr = inputVal.toString()
	for (var i=0; i<inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);
		if (oneChar < "0" || oneChar > "9") {
			return false;
		}
	}
	return true;
}

function GeneratePassword(length) {

    if (parseInt(navigator.appVersion) <= 3) {
        alert("Sorry this only works in 4.0+ browsers");
        return true;
    }

    var sPassword = "";

    var noPunction = true;
    for (i=0; i < length; i++) {

        numI = getRandomNum();
        if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }

        sPassword = sPassword + String.fromCharCode(numI);
    }


    return sPassword;
}

function getRandomNum() {

    // between 0 - 1
    var rndNum = Math.random()

    // rndNum from 0 - 1000
    rndNum = parseInt(rndNum * 1000);

    // rndNum from 33 - 127
    rndNum = (rndNum % 94) + 33;

    return rndNum;
}

function checkPunc(num) {

    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }

    return false;
}

function bio(employe_id) {
	var str = '';
	str += '&employe_id=' + employe_id;
	var options = {};
	options.postBody = str;
	var ar = new Ajax.Request('php/bio.php?from_ajax=1&no_cache=' + Math.random(), options);
	ar.options.onSuccess = function (originalRequest){
		var msg=originalRequest.responseText;
		//console.debug(msg);
		$('biographie').innerHTML=msg;
		Element.show('biographie');
			
		}.bind(this);
		
		ar.options.onFailure = function(){ alert("Erreur, le serveur n'a pas répondu") };
	//alert (str);
}

function suggestion(secteur, livre, champ) {
	var str = '';
	str += '&sid=' + secteur + '&lid=' + livre + '&champ=' + champ;
	var options = {};
	options.postBody = str;
	var ar = new Ajax.Request('php/suggestion.php?from_ajax=1&no_cache=' + Math.random(), options);
	ar.options.onSuccess = function (originalRequest){
		var msg=originalRequest.responseText;
		//alert(msg);
		//console.debug(msg);
		/*$('biographie').update(msg);
		Element.show('biographie');*/
		$(champ).innerHTML=msg;
		}.bind(this);
		
		ar.options.onFailure = function(){ alert("Erreur, le serveur n'a pas r?pondu") };
	//alert (str);
}


var statusmsg=""

function hidestatus(){
window.status=statusmsg
return true
}

function chg_cal_news(str_date) {
	var str = '';
	str += '&date=' + str_date;
	var options = {};
	options.postBody = str;
	var au = new Ajax.Updater({ success: 'calendar' }, 'php/chg_cal_news.php?from_ajax=1&no_cache=' + Math.random(), options);
	//var ar = new Ajax.Request('php/chg_cal.php?from_ajax=1&no_cache=' + Math.random(), options);
	//alert (str);
}

function chg_cal(str_date) {
	var str = '';
	str += '&date=' + str_date;
	var options = {};
	options.postBody = str;
	var au = new Ajax.Updater({ success: 'calendar' }, 'php/chg_cal.php?from_ajax=1&no_cache=' + Math.random(), options);
	//var ar = new Ajax.Request('php/chg_cal.php?from_ajax=1&no_cache=' + Math.random(), options);
	//alert (str);
}

function chg_news(str_date) {
	var str = '';
	str += '&date=' + str_date;
	var options = {};
	options.postBody = str;
	var au = new Ajax.Updater({ success: 'news' }, 'php/chg_news.php?from_ajax=1&no_cache=' + Math.random(), options);
	var lau = new Ajax.Updater({ success: 'contenu_liens' }, 'php/chg_lnk.php?from_ajax=1&no_cache=' + Math.random(), options);
	//var ar = new Ajax.Request('php/chg_cal.php?from_ajax=1&no_cache=' + Math.random(), options);
	//alert (str);
}

function filtre_evenement(filtre) {
	var str = '';
	str += '&categorie=' + filtre;
	var options = {};
	options.postBody = str;
	var au = new Ajax.Updater({ success: 'events_col' }, 'php/chg_filtre.php?from_ajax=1&no_cache=' + Math.random(), options);
}

function recherche() {
	var str = document.search.kw.value;
	if (str.length <= 3) {
		alert("Vous devez entrer un mot-clé de 4 caractères ou plus !\n");
	} else {
		document.search.submit();
	}
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=300,height=180');");
}

function DeleteItem(url)
{
	if (confirm("Êtes-vous sûr de vouloir supprimer cet item?")) {
		document.location = url;
	}
	return false;
}
