// $Id: bookingfile.js,v 1.7 2010/09/17 13:55:37 mb Exp $

function addTif(rk,fml,srv,libsrv,nom,prenom){
  this.tifArray[this.nbtif]=new Tif(rk,fml,srv,libsrv,nom,prenom);
  //alert("TIF "+this.tifArray[this.nbtif].rk+" At FML "+fml);
  this.nbtif++;
}

function addPrsTif(rk,fml,srv,libsrv,nom,prenom){
  this.tifPrsArray[this.nbPrstif]=new Tif(rk,fml,srv,libsrv,nom,prenom);
  
  this.nbPrstif++;
}

// D�claration d'un tif
function Tif(rk,fml,srv,libsrv,nom,prenom){
  this.rk=rk;
  this.fml=fml;
  this.srv = srv;
  this.libsrv = libsrv;
  this.prenom = prenom;
  this.nom = nom;
}

function TabFmlSrv(){
  this.typ = "room";
  this.addTif = addTif;
  this.toHtml = toHtml;
  this.tifArray = new Array();
  this.nbtif=0;
}

function TabPrsFml(){
  this.typ = "oth";
  this.addTif = addPrsTif;
  this.toHtml = toPrsHtml;
  this.tifPrsArray = new Array();
  this.nbPrstif=0;
}

function toPrsHtml(){
    var html=new String("");
    for(var i=0;i<this.nbPrstif;i++){
        if(i!=0){
            html+=" - ";
        }
        
        if(this.tifPrsArray[i].prenom && this.tifPrsArray[i].prenom.length>0){
            html+=this.tifPrsArray[i].prenom;
            html+=" ";
        }
        html+=this.tifPrsArray[i].nom;
    }
    return html;
}


function toHtml(){
  //alert("TIF: "+this.nbtif);
  var html=new String("");
  var k = 0;
  for(var i=0;i<this.nbtif;i++){
    if(i!=0){
        //alert(this.tifArray[i].srv+" "+this.tifArray[i].srv);
        if(this.tifArray[i].srv != this.tifArray[i-1].srv && this.tifArray[i].srv.length>0 && this.tifArray[i-1].srv.length>0){
            k=1;
            break;
        }
    }
  }

  //alert(this.nbtif);
  for(var i=0;i<this.nbtif;i++){
    if(i!=0){
        html+=" - ";
    }
    else if(k == 0 && this.typ == "room"){
        html+=this.tifArray[i].libsrv;
        html+="<br />";
    }

    //alert(this.tifArray[i].prenom);
    if(this.tifArray[i].prenom && this.tifArray[i].prenom.length>0){
        html+=this.tifArray[i].prenom;
        html+=" ";
    }
    html+=this.tifArray[i].nom;

    if(k==1 && this.tifArray[i].libsrv.length>0){
        html+=" ("+this.tifArray[i].libsrv+")";
    }

  }
  return html;
}

function Segments() {
  this.segmentlst = new Array();
  this.addSegment = addSegment;
}

function Segment(rkpro, rkacc, ttlacc, qty, prsOblig, prodOblig, prodCmpsite) {
  this.rkpro = rkpro;
  this.rkacc = rkacc;
  this.ttlacc = ttlacc;
  this.qty = qty;
  this.prsOblig = prsOblig;
  this.prodOblig = prodOblig;
  this.prodCmpsite = prodCmpsite;
}

function addSegment(seg) {
  var lpos = this.segmentlst.length;
  this.segmentlst[lpos] = seg;
  return 1;
}

function GetXml(XMLQuery,choix){
  var i=0;
  var size=0;
  //alert('begin');
  XMLQuery.value="";

  //alert("CHOIX: "+choix);

  if(choix==2){
     XMLQuery.form.screent.value="LTypCompl.vm"
        XMLQuery.value="<?xml version=\"1.0\"?>"+
        "<request>"+
           "<modelid>cplreq</modelid>"+
           "<content>"+
              "<cplreq/>"+
           "</content>"+
      "</request>";
  }
  else if(choix==1){
     XMLQuery.form.screent.value=""
     XMLQuery.form.xsl.value="namelist"
     XMLQuery.value="<?xml version=\"1.0\"?>"+
      "<request>"+
         "<modelid>namereq</modelid>"+
         "<content>"+
            "<namereq>"+
            "</namereq>"+
         "</content>"+
      "</request>";
  }
  else{

    /*XMLQuery.form.screent.value=""
     XMLQuery.form.xsl.value="namelist"
     XMLQuery.value="<?xml version=\"1.0\"?>"+
      "<request>"+
         "<modelid>namereq</modelid>"+
         "<content>"+
            "<namereq>"+BuildBfheader(choix)+
            "</namereq>"+
         "</content>"+
      "</request>";*/

  }

  //alert(XMLQuery.value);
  return 1;
}

function confirmSubmit(segs,rkpro,rkacc,smdt,pmdt,pcmpsit)
{
    var agree = false;
    var ask = "Etes-vous s\u00FBr(e) de vouloir supprimer cette prestation ?";

    if(smdt == 'Y' && pcmpsit == 'Y'){
      var lstprs="";
      var nbfounds=0;
      for(var i=0; i < segs.segmentlst.length; i++){
        if(segs.segmentlst[i].rkpro == rkpro && segs.segmentlst[i].rkacc != rkacc){
          if(nbfounds > 0){
            lstprs += ", ";
          }
          lstprs += segs.segmentlst[i].ttlacc;
          nbfounds++;
        }
      }
      var info = "La suppression de cette prestation peut entrainer la suppression d'autres prestations d\u00E9pendantes: \u000D\u000A"+lstprs;
      return confirm(info+"\u000D\u000A"+ask);
    }
    else{
      return confirm(ask);
    }
}

function BuildBfheader(nat_res){
	var bfheader = new String("");

	bfheader += "&lt;bfheader>";
	bfheader += "&lt;bfstatus val=\'"+"true"+"\' nat=\'"+nat_res+"\'>&lt;/bfstatus>";
        bfheader += "&lt;/bfheader>";
	//alert(bfheader);

	return bfheader;
}

function validateForm(){
    choix=getInputSelect(document.paoreqAsx.natdos)
    document.paoreqAsx.xsl.value="namelist";
    document.paoreqAsx.natres.value = choix;
    document.paoreqAsx.bean.value = "bkgdmdreq";
    document.paoreqAsx.action.value="VldDosAct";
    document.paoreqAsx.submit();
    return true;
}

function modPrs(prs,pro,qty){
    document.paoreqAsx.xsl.value="availreq";
    //alert("PRO: " +pro);
    document.paoreqAsx.prscur.value = prs;
    document.paoreqAsx.procur.value = pro;
    document.paoreqAsx.nbpax.value = qty;
    document.paoreqAsx.bean.value = "lstfmlreq";
    document.paoreqAsx.action.value="UpdatePrs";
    // inutile maintenant que la modif est un input de type image
    document.paoreqAsx.submit();
    return true;
}

function delPrs(seg, segments){
    //alert("PRO RK:"+seg.rkpro);
    //alert("PRS RK:"+seg.rkacc);
    if(!confirmSubmit(segments,seg.rkpro, seg.rkacc,seg.prsOblig,seg.prodOblig,seg.prodCmpsite)){
        return false;
    }
    document.paoreqAsx.xsl.value="bookingMenu";
    document.paoreqAsx.prscur.value = seg.rkacc;
    document.paoreqAsx.tspcur.value = '0';
    document.paoreqAsx.procur.value = seg.rkpro;
    document.paoreqAsx.nbpax.value = seg.qty;
    document.paoreqAsx.action.value="DeletePrs";
    document.paoreqAsx.bean.value = "delprsreq";
    document.paoreqAsx.submit();
    return true;
}

function cpnred(){

    if (!(validateBlanc(document.paoreqAsx.cpn,'Référence coupon obligatoire !' )))
          return false;

   // alert("coupon réduction : "+document.paoreqAsx.cpn.value.toUpperCase());

    document.paoreqAsx.xsl.value="bookingMenu";
    document.paoreqAsx.action.value="CouponRed";
    document.paoreqAsx.bean.value = "cpnredreq";
    document.paoreqAsx.submit();

    return true;
}

function modTsp(pro,tsp)
{
  document.paoreqAsx.xsl.value="listtsp";
  document.paoreqAsx.procur.value = pro;
  document.paoreqAsx.tspcur.value = tsp;
  document.paoreqAsx.bean.value = "lstvolreq";
  document.paoreqAsx.action.value="UpdateTsp";
  document.paoreqAsx.submit();
}

function modTspSti(pro,tsp)
{
  document.paoreqAsx.xsl.value="listtspsti";
  document.paoreqAsx.procur.value = pro;
  document.paoreqAsx.tspcur.value = tsp;
  document.paoreqAsx.bean.value = "retreiveTspOfferList";
  document.paoreqAsx.mode.value = "init";
  document.paoreqAsx.action.value="UpdateTsp";
  document.paoreqAsx.submit();
}

function delTsp(pro,tsp)
{
  document.paoreqAsx.xsl.value="bookingMenu";
  document.paoreqAsx.tspcur.value = tsp;
  document.paoreqAsx.prscur.value = '0';
  document.paoreqAsx.procur.value = pro;
  document.paoreqAsx.nbpax.value = '0';
  document.paoreqAsx.action.value="DeletePrs";
  document.paoreqAsx.bean.value = "delprsreq";
  document.paoreqAsx.submit();
  return true;
}

function modPax(){
  document.paoreqAsx.xsl.value="bookingMenu";
  document.paoreqAsx.prscur.value = '0';
  document.paoreqAsx.procur.value = '0';
  document.paoreqAsx.nbpax.value = '0';
  document.paoreqAsx.bean.value = "lstpaxreq";
  document.paoreqAsx.action.value="UpdatePax";
  document.paoreqAsx.submit();
  return true;
}
