/* - - - - - - - - - - - - - - - - - - - - - - -
 Fichier JavaScript
 Créé le samedi 18 janvier 2003 12:07:04
 Petit conservatoire -
  - - - - - - - - - - - - - - - - - - - - - - - */
  /**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

function setFocus(aField) {
  document.forms[0][aField].focus();
}
function isAnEmailAddress(aTextField) {
// 1+@3+ [or x@x.x] is as close as we will test
  if (document.forms[0][aTextField].value.length<5) {
    return false;
  }
  else if (document.forms[0][aTextField].value.indexOf("@") < 1) {
    return false;
  }
  else if (document.forms[0][aTextField].value.length -
   document.forms[0][aTextField].value.indexOf("@") < 4) {
   return false;
  }
  else { return true; }
}
function isEmpty(aTextField) {
  if ((document.forms[0][aTextField].value.length==0) ||
   (document.forms[0][aTextField].value==null)) {
   return true;
  }
  else { return false; }
}
<!-- Original:  Mike Welagen (welagenm@hotmail.com) -->
 
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
 
<!-- Begin
function checkdate(objName) {
var datefield = objName;
if (chkdate(objName) == false) {
datefield.select();
alert("La date n'est pas correcte : introduisez par exemple le 13/02/1989");
datefield.focus();
return false;
}
else {
return true;
   }
}
function chkdate(objName) {
//var strDatestyle = "US"; //United States date style
var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intDay;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield.value;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
   intYear = parseInt(strYear, 10);
   if (intYear < 10) {
      strYear = '20' + strYear;
   }
   else {
      strYear = '19' + strYear;
   }
}

if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intDay = parseInt(strDay, 10);
if (isNaN(intDay)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}

if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intDay > 31 || intDay < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intDay > 30 || intDay < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intDay < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intDay > 29) {
err = 9;
return false;
}
}
else {
if (intDay > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + " " + intDay+" " + strYear;
}
else {
    strDay = String(intDay);
    if (strDay.length == 1) {
          strDay = '0' + strDay;
    }
    strMonth = String(intMonth);
    if (strMonth.length == 1) {
          strMonth = '0' + strMonth;
    }
datefield.value = strDay + "/" + strMonth + "/" + strYear;
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}
function doDateCheck(from, to) {
if (Date.parse(from.value) <= Date.parse(to.value)) {
alert("The dates are valid.");
}
else {
if (from.value == "" || to.value == "") 
alert("Both dates must be entered.");
else 
alert("To date must occur after the from date.");
   }
}

function validate_inscription_index() {
// will return true or false
// Step 1: check that required fields are
// filled in, alert and exit without
// submitting if not

// check that the name field is valued
if (isEmpty("firstname"))
   {
  alert("Le nom et le prénom de la personne à inscrire sont obligatoires");
  setFocus("firstname");
  return false;
  }
if (isEmpty("lastname"))
   {
  alert("Le nom et le prénom de la personne à inscrire sont obligatoires");
  setFocus("lastname");
  return false;
  }
// if we get this far everthing is ok, so
// let the form submit
return true;

}
function validate_who() {

if (isEmpty("strAdresse")) {
    alert("L'adresse est obligatoire");
    setFocus("strAdresse");
    return false;
}
if (isEmpty("strCode_Postal")) {
    alert("Le code postal est obligatoire");
    setFocus("strCode_Postal");
    return false;
}
if (isEmpty("strLocalite")) {
    alert("La localité est obligatoire");
    setFocus("strLocalite");
    return false;
}
if (!isEmpty("strEmail")) {

  //  check that the email address is correct
  if (!isAnEmailAddress("strEmail")) {
    alert("L'adresse email est incorrecte");
    setFocus("strEmail");
    return false;
  }
}
if (document.forms[0].elements.invoke.value == "output_from_db_edit")  {
   document.who.action = '/prof/output_from_db.php';
}

// if we get this far everthing is ok, so
// let the form submit
return true;
}
function validateclass() {
return true;
}
function validate_register() {

args = validate_register.arguments;
formObj = args[0];
var isOK = true;
for (i=1;i<args.length;i++) {
elemSelected=false;
elems = formObj.elements[args[i]];
for (j=0;j<elems.length;j++) if (elems[j].checked) elemSelected=true;
if (!elemSelected) {
isOK = false;
alert("Sélectionnez une option");
//alert("You have to select a "+args[i]);
   return false;
}
}
return true;
}

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
        newColor              = theDefaultColor;
    //             newColor              = (thePointerColor != '')
    //                              ? thePointerColor
    //                              : theDefaultColor;
    //        marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
    //                              ? true
    //                              : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
function printPage() {

window.print();
}
//  End -->
function initpkeyWho() {
  for (intForm = 0; intForm < 3; intForm++) {
           document.forms[intForm].elements.pkeyWho.value = ""
  }
  return true;
}
function pkeyWhoSelected(intForm) {
if (document.forms[intForm].elements.pkeyWho.value !=="") {
 document.forms[intForm].submit();
    return true;
}
else   {
alert("Sélectionnez d'abord une ligne");
}
}
function initparameterclass() {
  for (intForm = 0; intForm < 8; intForm++) {
           document.forms[intForm].elements.parameterclass.value = ""
  }
  return true;
}
function parameterclassSelected(intForm) {
if (document.forms[intForm].elements.parameterclass.value !=="") {
    document.forms[intForm].submit();
    return true;
}
else   {
       alert("Sélectionnez d'abord une ligne");
}
}
function setparameterclass(pkeyClass){
  for (intForm = 0; intForm < 8; intForm++) {
           document.forms[intForm].elements.parameterclass.value = pkeyClass;
  }
}

function DisplayImages(intNumberOfImages){
   var intImageNo = Math.floor(Math.random()*intNumberOfImages);
   if (intImageNo==0) { intImageNo=intNumberOfImages}
   var strImageNo = String(intImageNo);
   document.write("<p><a href=\"photo/photo-"+ strImageNo + ".jpg\"><img src=\"photo/photo-"+ strImageNo + ".jpg\" alt=\"image " + strImageNo +"\"></a></p>");
   //var intImageNo = Math.floor(Math.random()*intNumberOfImages);
   //if (intImageNo==0) { intImageNo=intNumberOfImages}
   //var strImageNo = String(intImageNo);
   //document.write("<p><a href=\"photo/photo-"+ strImageNo + ".jpg\"><img src=\"photo/photo-"+ strImageNo + ".jpg\" alt=\"image " + strImageNo +"\"></a></p>");

}
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
 href=mylink;
else {
 href=mylink.href;
 }
window.open(href, windowname, 'width=801,height=600,scrollbars=no');
return false;
}
function safemail(name, domain, display) {
displayed=(typeof(display)=="undefined") ? name+"@"+domain : display
document.write('<a href=mailto:' + name + '@' + domain + '>' + displayed + '</a>');
}
function workitout()
  {
  var num1,num2,num3;
  num0=document.reservation.number_adult0.value;
  num1=document.reservation.number_adult1.value;
  num2=document.reservation.number_adult2.value;
  num3=document.reservation.number_child.value;
  if (num1=='')
  {
    num1= 0;
  }
  if (num0=='')
  {
    num0= 0;
  }
  if (num1=='')
  {
    num1= 0;
  }
  if (num2=='')
  {
    num2= 0;
  }
  if (num3=='')
  {
    num3= 0;
  }
   if (num0==0 & num1==0 & num2==0 & num3==0)
   {
       alert("Vous devez réserver au moins une place !");
       setFocus("number_adult1");
       return false;
   }
   else
   {
       result=parseFloat(num0)*35 + parseFloat(num1)*25 + parseFloat(num2)*20+ parseFloat(num3)*10;
        document.reservation.output.value =
            "je paierai la somme de " + result + " €\n" +
            "en arrivant au Vaudeville" + "\n" ;
   }
  }
function printSpecial()
{
var gAutoPrint = yes; // Flag for whether or not to automatically call the print function
  if (document.getElementById != null)
  {
    var html = '<HTML>\n<HEAD>\n';

    if (document.getElementsByTagName != null)
    {
      var headTags = document.getElementsByTagName("head");
      if (headTags.length > 0)
        html += headTags[0].innerHTML;
    }
    
    html += '\n</HE' + 'AD>\n<BODY>\n';
    
    var printReadyElem = document.getElementById("printReady");
    
    if (printReadyElem != null)
    {
        html += printReadyElem.innerHTML;
    }
    else
    {
      alert("Could not find the printReady section in the HTML");
      return;
    }
      
    html += '\n</BO' + 'DY>\n</HT' + 'ML>';
    
    var printWin = window.open("","printSpecial");
    printWin.document.open();
    printWin.document.write(html);
    printWin.document.close();
    if (gAutoPrint)
      printWin.print();
  }
  else
  {
    alert("Sorry, the print ready feature is only available in modern browsers.");
  }
}
function validate_reservation(form) {

  var num0,num1,num2,num3;
  num0=document.reservation.number_adult0.value;
  num1=document.reservation.number_adult1.value;
  num2=document.reservation.number_adult2.value;
  num3=document.reservation.number_child.value;
  if (num0=='')
  {
    num0= 0;
  }
  if (num1=='')
  {
    num1= 0;
  }
  if (num2=='')
  {
    num2= 0;
  }
  if (num3=='')
  {
    num3= 0;
  }
   if (num0==0 & num1==0 & num2==0 & num3==0)
   {
       alert("Vous devez réserver au moins une place !");
       setFocus("number_adult1");
       return false;
   }
if (isEmpty("firstname"))
   {
  alert("Le nom et le prénom de la personne à inscrire sont obligatoires");
  setFocus("firstname");
  return false;
  }
if (isEmpty("lastname"))
   {
  alert("Le nom et le prénom de la personne à inscrire sont obligatoires");
  setFocus("lastname");
  return false;
  }
if (!isEmpty("email"))
   {
  //  check that the email address is correct
  if (!isAnEmailAddress("email")) {
    alert("L'adresse email est incorrecte");
    setFocus("email");
    return false;
  }
    }
var radioValue = checkRadio(form.date_book_for);
//    if(radioValue) {
//      alert("You selected " + radioValue);
//      return true;
//    } else {
      if(!radioValue) {
      alert("Sélectionnez une date de réservation");
      return false;
    }

return true;
}
function checkRadio(field)
  {
    for(var i=0; i < field.length; i++) {
      if(field[i].checked) return field[i].value;
    }
    return false;
  }
  