function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function n3_swapClass(theID,cssStyle,cssStyleOther) {
	if(!document.getElementById){return};
	var theElement = document.getElementById(theID);
	if (theElement.className == cssStyle) {
		theElement.className = cssStyleOther;
	} else {
		theElement.className = cssStyle;
	}
}

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 getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function


function getSelectedButton(buttonGroup){
	for (var i = 0; i < buttonGroup.length; i++) {
		if (buttonGroup[i].checked) {
			return i
		}
	}
	return 0
}

function getSelectedButton1(buttonGroup){
	alert(buttonGroup.length);
	for (var i = 0; i < buttonGroup.length; i++) {
		if (buttonGroup[i].checked) {
			return i
		}
	}
	return 99
}


function checkMail(str) {
	var verif = /^[a-zA-Z0-9\-\_]{1,}[a-zA-Z0-9\.\-\_]*[a-zA-Z0-9\-\_]{1,}@[a-zA-Z0-9]{1,}[a-zA-Z0-9\.\-\_]*[a-zA-Z0-9]{1,}[.][a-zA-Z]{2,4}$/;
	if(verif.test(str)) return true;
	else return false;
}

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 validateDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy


PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()

   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/

  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return 1; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(4,5) //find date separator
    var arrayDate = strValue.split(strSeparator); //split date into month, day, year
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[2]);

    //check if month value and day value agree
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)

        return 99; //found in lookup table, good date
    }

    //check for February
    var intYear = parseInt(arrayDate[0]);
    var intMonth = parseInt(arrayDate[1]);
    if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
      return 99; //Feb. had valid number of days
  }
  return 2; //any other values, bad date
}

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


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_cal_fr(str_date) {
	var str = '';
	str += '&date=' + str_date;
	var options = {};
	options.postBody = str;
	var au = new Ajax.Updater({ success: 'calendar' }, '../php/chg_cal_fr.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: 'filtre' }, 'php/chg_filtre.php?from_ajax=1&no_cache=' + Math.random(), options);
}