// - - - - - - - - - - - - - - - - - - - - - - -
// Fichier JavaScript
// Créé le samedi 18 janvier 2003 12:07:04
// Last Modif : samedi 28 février 2009 17:19:09

// This array is used to remember mark status of rows in browse mode
//
 
 //alert ("this is a alert message for test purpose");
 
var marked_row = new Array;
 
function validate_who(lang) {
    var lblAdresse;
    var lblCodePostal;
    var lblLocalite;
    var lblEmail;
    var strToTest;
    var strBlank;
    lblAdresse ="L'adresse est obligatoire";
    if (lang==2){
        lblAdresse="Address is a mandatory field";
    }
    lblCodePostal="Le code postal est obligatoire";
    if (lang==2){
        lblCodePostal="Postal code is a mandatory field";
    }
    lblLocalite="La localité est obligatoire";
    if (lang==2){
        lblLocalite="Town is a mandatory field";
    }
    lblEmail="L'adresse email est incorrecte";
    if (lang==2){
        lblEmail="Email address is incorrect";
    }
    lblDate="La date doit être au format JJ/MM/AAAA par ex. : 13/02/2009";
    if (lang==2){
        lblDate="Date should be formatted DD/MM/YYYY e.g. 13/02/2009";
    }    
    var strInput=document.getElementById("strAdresse").value;
    if (validate_required(strInput,lblAdresse)==false) {
          document.getElementById("strAdresse").focus;
          return false;
    }
    strInput=document.getElementById("strCodePostal").value;
    if (validate_required(strInput,lblCodePostal)==false) {
          document.getElementById("strCodePostal").focus;
          return false;
    }      
    strInput=document.getElementById("strLocalite").value;
    if (validate_required(strInput,lblLocalite)==false) {
          document.getElementById("strLocalite").focus;
          return false;
    }                                                     
    strInput=document.getElementById("strEmail").value;
//    if (strInput!==null && strInput!=="") {
        if (validate_email(strInput,lblEmail)==false) {
              document.getElementById("strEmail").focus;
              return false;
         }
//    }  
    strInput=document.getElementById("dteNaissanceEur").value;
    if (validate_date(strInput,lblDate)==false) {
             document.getElementById("dteNaissanceEur").focus;
              return false;
    }  
                                 
    // if we get this far everthing is ok, so
    // let the form submit
    return true;                    
}
function validate_required(inputText,alertText)
{
    if (inputText==null||inputText=="") {
        alert(alertText);
        return false;
    }
    var strTemp = inputText;
    strTemp = trimAll(strTemp);
    if(strTemp.length <3){    // let say that there must be at least 3 characters  (Zoé)
        alert(alertText);  
        return false;
   }
   return true;
}
function validate_email(inputText,alertText)
{
    var strTemp = inputText; 
    apos=strTemp.indexOf("@");
    dotpos=strTemp.lastIndexOf(".");
    if (apos<1||dotpos-apos<2) {
          alert(alertText);
          return false;
    }
    else {
        return true;
    }
}
function trimAll(strValue) {
/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}
function validateclass() {
return true;
}

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; }
}

// This script and many more are available free online at 
// The JavaScript Source!! http://javascript.internet.com 
 
function validate_date(inputText,alertText) {
   // Original JavaScript code by Chirp Internet: www.chirp.com.au
  // Please acknowledge use of this code by including this header.
    var allowBlank = true;
    var minYear = 1908;
    var maxYear = (new Date()).getFullYear();

    var errorMsg = "";
    var dteTemp =   inputText;
    // regular expression to match required date format
    re = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
    
    if(dteTemp != '' & dteTemp != '00/00/0000') {
      if(regs = dteTemp.match(re)) {
        if(regs[1] < 1 || regs[1] > 31) {
             alert (alertText);
             return false;   
        } else if(regs[2] < 1 || regs[2] > 12) {
             alert (alertText);
             return false;   
        } else if(regs[3] < minYear || regs[3] > maxYear) {
             alert (alertText);
             return false;   
        }
      } else {
             alert (alertText);
             return false;   
      }
    }     
    return true;
  }

function validate_inscription_index(lang) {
                                            // will return true or false
                                            // Step 1: check that required fields are
                                            // filled in, alert and exit without
                                            // submitting if not

    var lblNomPrenom="Le nom et le prénom de la personne à inscrire sont obligatoires"
    if (lang==2){
        lblNomPrenom="Last name and First name are mandatory"
    }
    var strInput=document.getElementById("firstname").value;
    
    if (validate_required(strInput,lblNomPrenom)==false) {
          document.getElementById("firstname").focus;
          return false;
    }
    strInput=document.getElementById("lastname").value;
    if (validate_required(strInput,lblNomPrenom)==false) {
          document.getElementById("lastname").focus;
          return false;
    }
                                        // 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=0;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;
    var lblOption="Sélectionnez une option"
    if (lang==2){
    var lblOption="Selct an option"
    }
    alert(lblOption);
    //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(intForm) {
  for (intForm = 0; intForm < 3; intForm++) {
           document.forms[intForm].elements.pkeyWho.value = ""
  }
  return true;
}
function pkeyWhoSelected(intForm,lang)  {
    if (document.forms[intForm].elements.pkeyWho.value !=="") {
        document.forms[intForm].submit();
        return true;
    }
    else   {
        var lblLigne="Sélectionnez d'abord une ligne"
        if (lang==2){
            lblLigne="Select a line first"
        }
        alert(lblLigne);
    }
}
function initparameterclass() {
  for (intForm = 0; intForm < 8; intForm++) {
           document.forms[intForm].elements.parameterclass.value = ""
  }
  return true;
}
function parameterclassSelected(intForm,lang) {
    if (document.forms[intForm].elements.parameterclass.value !=="") {
        document.forms[intForm].submit();
        return true;
    }
    else   {
        var lblLigne="Sélectionnez d'abord une ligne";
        if (lang==2){
            lblLigne="First select a row";
        }
        alert(lblLigne);
    }
}
function parameterclassNew(intForm) {
        document.forms[intForm].submit();
        return true;
}
function setparameterclass(pkeyClass){
  for (intForm = 0; intForm < 9; 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)
   {
	var lblPlace="Vous devez réserver au moins une place !"
	if (lang==2){
		lblPlace="Book at least one seat !"
	}
	alert(lblPlace);
        document.getElementById("number_adult1").focus;
        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)
   {
	var lblPlace="Vous devez réserver au moins une place !"
	if (lang==2){
		lblPlace="Book at least one seat !"
	}
	alert(lblPlace);
       document.getElementById("number_adult1").focus;  
       return false;
   }
	var lblNomPrenom="Le nom et le prénom de la personne à inscrire sont obligatoires"
	if (lang==2){
		lblNomPrenom="Last name and First name are mandatory"
	}
	var lblEmail="L'adresse email est incorrecte"
	if (lang==2){
		lblEmail="Email address is incorrect"
	}
	var lblDateReserve="Sélectionnez une date de réservation"
	if (lang==2){
		lblDateReserve="Select a date of booking"
	}
    var strInput=document.getElementById("firstname").value;
    if (validate_required(strInput,lblNomPrenom)==false) {
          document.getElementById("firstname").focus;
          return false;
    }
    strInput=document.getElementById("lastname").value;
    if (validate_required(strInput,lblNomPrenom)==false) {
          document.getElementById("lastname").focus;
          return false;
    }
    strInput=document.getElementById("email").value;
    if (strInput!==null && strInput!=="") {
        if (validate_email(strInput,lblEmail)==false) {
              document.getElementById("email").focus;
              return false;
         }
    } 
var radioValue = checkRadio(form.date_book_for);
//    if(radioValue) {
//      alert("You selected " + radioValue);
//      return true;
//    } else {
      if(!radioValue) {
          alert(lblDateReserve);
      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;
}

