/* hafas_standard_selectmot.js built  09.06.2005 */
/* by HaCon supported by Anton & Friedrich       */
/* stat(none/all)                                */
function selectMOT(stat,via,maxProduct,idx,type,journeyType){
  var value = (stat=="none") ? false:true;
  for(var i=0; i<=via; i++){
    if(idx){
      eval("document.formular.REQ"+journeyType+"JourneyProduct_"+ type +"_section_"+ i +"_"+ idx +".checked = "+ value +";");
      }
    else{
      for(var p=0; p<maxProduct; p++){
        var checkboxObj = eval("document.formular.REQ"+journeyType+"JourneyProduct_"+ type +"_section_"+ i +"_"+p);
        if(checkboxObj)
          checkboxObj.checked = value;
        }
      }
    }
  }

function hexToBinary(hexBitfield, festeBits)
{
   // convert hexadecimal to binary
   var temp = "";
   var binaryBitfield = "";
   for (var j=0; j < hexBitfield.length; j += 2) {
      temp = (parseInt(hexBitfield.substring(j,j+2),16)).toString(2);
      while (temp.length < 8) {
         temp = "0"+temp;
      }
      // remove feste bits at beginning of bitfield
      if (j == 0 && festeBits > 0 && festeBits <= temp.length) {
         temp = temp.substring(festeBits, temp.length);
      }
      binaryBitfield += temp;
   }
   return binaryBitfield;
}

var periodBegin = new Date (2006, 11, 10);
var periodEnd   = new Date (2007, 11, 8);
// Sa, So + Feiertage gleich '1'
var holidays = hexToBinary("e0c1e3860c183060c183060c183060e183068c18b070c583060c183060c183260c183060c183060c38b060c18307", 2);

function einfachRaus(stat,via,maxProduct,idx,type,journeyType)
  {
  /* Unselect all products */
  var productsER = new Array(4,5,8,9)  /* Valide Produkte */
  var noVia = e('erVia').value;
  var message = erTextPro;

  selectMOT(stat,via,maxProduct,idx,type,journeyType);

  /* Setze Produkte für Einfach Raus Ticket */
  for (var v=0;v<=noVia;v++)
     {
     for (var n=0;n<productsER.length;n++)
        {
        e('product_'+v+'_'+productsER[n]).checked = true;
        }
     }

  /* Ankunft */
  if(e('timesel').selectedIndex == 1)
     {
     /* NIX */
     }
  else /* Abfahrt */
     {
     var inputDate = Calendar_parseUserDateInput (e('date').value);
     var dateDiff = Date_diff(inputDate, periodBegin);

     /* Pruefe Datum == Werktag oder Feiertag */
     if (dateDiff >= 0 && dateDiff < holidays.length && holidays.substr(dateDiff,1) != '1')
        {
        /* Setze Uhrzeit für Einfach Raus Ticket wenn früher als 09:00 */
        if(1*(e('time').value.split(':')[0]) < 9)
           {
           message = erTextDep;
           e('time').value = '09:00';
           }
        }
     }
  alert(unescape(message));
  }

function einfachRausGlobal()
  {
  /* Unselect all products */
  var message = erTextPro;

  /* Ankunft */
  if(e('timesel').selectedIndex == 1)
     {
     /* NIX */
     }
  else /* Abfahrt */
     {
     /* Pruefe Datum == Werktag */
     var inputDate = Calendar_parseUserDateInput (e('date').value);
     var dateDiff = Date_diff(inputDate,periodBegin);

     if (dateDiff >= 0 && dateDiff < holidays.length && holidays.substr(dateDiff,1) != '1')
        {
        /* Setze Uhrzeit für Einfach Raus Ticket wenn früher als 09:00 */
        if(1*(e('time').value.split(':')[0]) < 9)
           {
           message = erTextDep;
           e('time').value = '09:00';
           }
        }
     }
  alert(unescape(message));
  }


