var FLW = {
  'MODEL_SUGGESTION':12005,
  'MODEL_PACKAGE':12006,
  'MODEL_LODGING':12003,
  'MODEL_ACCOMMODATION':12011,
  'MODEL_ACTIVITY':12002,
  'MODEL_ROOM':12004,
  'MODEL_DESTINATION':12018,
  'MODEL_GROUPING':12021,
  "getDialog": function () {
    return Kwo.registry["_flw_dialog"];
  },
  "setDialog": function (o) {
    Kwo.registry["_flw_dialog"] = o;
    return Kwo.registry["_dialog"];
  }
};

FLW.Program = {
  'view': function (position) {
    FLW.Map.panToBound(position);
  },
  'click': function (model, record, position) {
    var viewport = $$('.viewport').invoke('hide');
    $('btn_'+model+'_'+record).up('.viewport').show();
    $('btn_'+model+'_'+record).onclick();
  }
};

FLW.Status = {
  'swapTo': function (nb,count) {
    for (var i = 1; i <= count; i++) {
      if ($$('.status'+i).length > 0) if (el = $$('.status'+i)[0]) {
        el.id ="";
        el.hide();
        el.update('');
      }
    }
    if ($$('.status'+nb).length > 0) if (el = $$('.status'+nb)[0]) {
      el.id ="kwo-account-status";
      el.hide();
      el.update('');
    }
  }
};

FLW.Actions = {
  'bookmark': function (model, record) {
    new Kwo.Dialog('/community/bookmark.dialog', {'model_id':model, 'record_id':record}, {'width':500,'height':250});
  },
  'send': function (key) {
    new Kwo.Dialog('/share/dialog',{'item_key':key},{'height':350});
  },
  'print': function () {
    window.print();
  },
  'abuse': function (key) {
    new Kwo.AbuseDialog({'item_key':key});
  }
};

FLW.SlideShow = {
  'next': function (arg) {
    var selected = $(arg).up('div').previous('img.selected');
    if (selected) {
      var next = selected.next('img');
      if (!next) {
        var next = selected.up('.slideshow').down('img');
      }
      if (next) {
        selected.hide();
        selected.removeClassName('selected');
        next.show();
        next.addClassName('selected');
      }
    }
  },
  'prev': function (arg) {
    var selected = $(arg).up('div').previous('img.selected');
    if (selected) {
      var next = selected.previous('img');
      if (!next) {
        var next = selected.up('.slideshow').down('img',selected.up('.slideshow').childNodes.length-2);
      }
      if (next) {
        selected.hide();
        selected.removeClassName('selected');
        next.show();
        next.addClassName('selected');
      }
    }
  }
};

FLW.Period = {
  'change': function (box, el) {
    if ($(box)) {
      $$('table#'+$(box).id+' div.period').each(function (e) {
        e.hide();
      });
      $('period'+$(el).value).show();
    }
  }
};

FLW.Showcase = {
  'el': null,
  'view': function (el, offset) {
    if ($(el).hasClassName('disabled')) return;
    FLW.Showcase.el = el;
    $(FLW.Showcase.el).addClassName('disabled');
    $(FLW.Showcase.el).up('form').down('input.offset').value = offset;
    Kwo.exec($(FLW.Showcase.el).up('form').action,FLW.Showcase.el,{'container':FLW.Showcase.el.up('.showcase')})
  },
  'filter': function (el) {
    if ($(el).hasClassName('disabled')) return;
    FLW.Showcase.el = el;
    $(FLW.Showcase.el).addClassName('disabled');
    $(FLW.Showcase.el).up('form').down('input.offset').value = 0;
    Kwo.exec($(FLW.Showcase.el).up('form').action,FLW.Showcase.el,{'container':FLW.Showcase.el.up('.showcase')})
  }
};

FLW.Selection = {
  'view': function (el, offset) {
    $('offset').value = offset;
    if ($('selection')) {
      $('results').update('');
      Kwo.exec('/flw2/search.selection',$('selection'),{'container':$('results')});
    } else {
      $(el).up('form').submit();
    }
  },
  'filter': function (model) {
    $('filter').value = model;
    FLW.Selection.view(0);
  },
  'info': function (lat,lng,model,record) {
    var html = "<div class='infowindow'>"+$(model+"_"+record).innerHTML+"</div>"
    FLW.Map.windowHtml(lat,lng,html);
  }
};

FLW.Search = {
  'filter': function (el, offset) {
    var select = $(el).next('select');
    while (select) {
      select.value=0;
      select = select.next('select');
    }
    FLW.Search.view(el, offset);
  },
  'view': function (el, offset) {
    $('offset').value = offset;
    $(el).up('form').submit();
  },
  'change': function (el, type) {
    $('offset').value = 0;
    $('type').value = type;
    $(el).up('form').submit();
  },
  'tab': function (el, tab) {
    $('offset').value = 0;
    $('tab').value = tab;
    $(el).up('form').submit();
  },
  'info': function (lat,lng,model,record) {
    var html = "<div class='infowindow'>"+$(model+"_"+record).innerHTML+"</div>"
    FLW.Map.windowHtml(lat,lng,html);
  }
};

FLW.Playlist = {
  'el': null,
  'program': function (el,position,model,record) {
    FLW.Playlist.click(el,model,record);
    FLW.Program.view(position);
  },
  'next': function (el) {
    var viewport = $(el).up('.viewport');
    viewport.hide();
    viewport.next('.viewport').show();
  },
  'prev': function (el) {
    var viewport = $(el).up('.viewport');
    viewport.hide();
    viewport.previous('.viewport').show();
  },
  'click': function (el,model,record) {
    $$('.scroller .item').each(function(item) {
      item.removeClassName("selected");
    });
    $(el).addClassName("selected");
    $$('#info > div').each(function(item) {
      item.hide();
    });
    $('item_'+model+'_'+record).show();
    FLW.Player.view(model,record);
  },
  'edito': function (model,record) {
    $$('.scroller .item').each(function(item) {
      item.removeClassName("selected");
    });
    $$('#info > div').each(function(item) {
      item.hide();
    });
    $('edito').show();
    FLW.Player.view(model,record);
  }
};

FLW.Player = {
  'view': function (model,record) {
    var vars = {playlist:"/flw/data.playlist/-/record_id/"+record+"/model_id/"+model};
    var params = {menu:"false",allowfullscreen:"true",wmode:"transparent"};
    var attributes = {id:"player",name:"player"};
    swfobject.embedSWF("/app/flw2/swf/mediaplayer.swf", 'player', "340", "255", "9.0.0", "/app/flw2/swf/expressInstall.swf", vars, params, attributes);
  }
};

FLW.Proximity = {
  'view': function (offset) {
    $('offset').value = offset;
    $('results').update('');
    Kwo.exec('/flw2/search.proximity',$('proximity'),{'container':$('results')});
  },
  'filter': function (model) {
    $('filter').value = model;
    FLW.Proximity.view(0);
  },
  'info': function (lat,lng,model,record) {
    var html = "<div class='infowindow'>"+$(model+"_"+record).innerHTML+"</div>"
    FLW.Map.windowHtml(lat,lng,html);
  }
};

FLW.Map = {
  'el': null,
  'map': null,
  'overview': null,
  'bounds': null,
  'steps': null,
  'init': function (opts) {
    if (GBrowserIsCompatible()) {
      $(opts.container).style.backgroundImage = 'none';
      Event.observe(window, 'unload', FLW.Map.unload);
      FLW.Map.map = new GMap2($(opts.container));
      FLW.Map.bounds = new GLatLngBounds();
      FLW.Map.steps = new Hash();
    }
  },
  'setType': function (type) {
    if (GBrowserIsCompatible()) {
      if (type == 'satellite') {
        FLW.Map.map.setMapType(G_SATELLITE_MAP);
      } else if (type == 'terrain') {
        FLW.Map.map.setMapType(G_PHYSICAL_MAP);
      } else if (type == 'hybrid') {
        FLW.Map.map.setMapType(G_HYBRID_MAP);
      } else {
        FLW.Map.map.setMapType(G_NORMAL_MAP);
      }
    }
  },
  'setControl': function (type) {
    if (GBrowserIsCompatible()) {
      if (type == 'small') {
        FLW.Map.map.addControl(new GSmallZoomControl3D());
      } else {
        FLW.Map.map.addControl(new GLargeMapControl3D());
      }
    }
  },
  'setTypeControl': function () {
    if (GBrowserIsCompatible()) {
       FLW.Map.map.addControl(new GMenuMapTypeControl());
       FLW.Map.map.addMapType(G_PHYSICAL_MAP);
    }
  },
  'setMapControl': function (type) {
    var size = new GSize(150, 150);
    var control = new GOverviewMapControl(size);
    if (type == 'satellite') {
      control.setMapType(G_SATELLITE_MAP);
    } else if (type == 'terrain') {
      control.setMapType(G_PHYSICAL_MAP);
    } else if (type == 'hybrid') {
      control.setMapType(G_HYBRID_MAP);
    } else {
      control.setMapType(G_NORMAL_MAP);
    }
    FLW.Map.map.addControl(control);
  },
  'setCenter': function (lat,lng,zoom) {
    if (GBrowserIsCompatible()) {
      var point = new GLatLng(lat,lng);
      FLW.Map.map.setCenter(point,zoom);
    }
  },
  'addPoint': function (lat,lng,model) {
    if (GBrowserIsCompatible()) {
      var point = new GLatLng(lat,lng);
      var icon = new GIcon(G_DEFAULT_ICON);
      icon.image = '/app/flw2/pix/dot_'+model+'.png';
      icon.shadow = '';
      icon.iconSize = new GSize(12,12);
      icon.shadowSize = new GSize(12,12);
      icon.iconAnchor = new GPoint(6,6);
      icon.imageMap = [0,0,12,0,12,12,0,12];
      var marker = new GMarker(point,{'icon':icon,'clickable':false});
      FLW.Map.map.addOverlay(marker);
      FLW.Map.bounds.extend(point);
    }
  },
  'addPushpin': function (lat,lng,model,record,name) {
    if (GBrowserIsCompatible()) {
      name = name.replace('&#039;',"'")
      var point = new GLatLng(lat,lng);
      var icon = new GIcon(G_DEFAULT_ICON);
      icon.image = '/app/flw2/pix/pushpin_'+model+'.png';
      icon.shadow = '/app/flw2/pix/pushpin_shadow.png';
      icon.iconSize = new GSize(32, 32);
      icon.shadowSize = new GSize(59, 32);
      icon.imageMap = [0,0, 32,0, 32,32, 0,32];
      var marker = new GMarker(point,{'icon':icon,'clickable':false,'title':name});
      FLW.Map.map.addOverlay(marker);
      FLW.Map.bounds.extend(point);
    }
  },
  'addProduct': function (lat,lng,model,record,name,callback) {
    if (GBrowserIsCompatible()) {
      name = name.replace('&#039;',"'")
      var point = new GLatLng(lat,lng);
      var icon = new GIcon(G_DEFAULT_ICON);
      icon.image = '/app/flw2/pix/product_'+model+'.png';
      icon.shadow = '/app/flw2/pix/product_shadow.png';
      icon.iconAnchor = new GPoint(0, 23);
      icon.iconSize = new GSize(18, 23);
      icon.shadowSize = new GSize(36, 23);
      icon.imageMap = [0,0, 18,0, 18,23, 0,23];
      var marker = new GMarker(point,{'icon':icon,'clickable':(callback)?true:false,'title':name});
      if (callback) {
	GEvent.addListener(marker, 'click', callback);
      }
      FLW.Map.map.addOverlay(marker);
      FLW.Map.bounds.extend(point);
    }
  },
  'addStep': function (lat,lng,model,record,name,position,callback) {
    if (GBrowserIsCompatible()) {
      name = name.replace('&#039;',"'")
      var point = new GLatLng(lat,lng);
      var icon = new GIcon(G_DEFAULT_ICON);
      icon.image = '/app/flw2/pix/num_'+position+'.png';
      icon.iconAnchor = new GPoint(11, 35);
      icon.iconSize = new GSize(21, 35);
      icon.imageMap = [0,0, 21,0, 21,35, 0,35];
      var marker = new GMarker(point, {'icon':icon,'clickable':(callback)?true:false,'title':name});
      if (callback) {
        GEvent.addListener(marker, 'click', callback);
      }
      FLW.Map.map.addOverlay(marker);
      FLW.Map.bounds.extend(point);
      FLW.Map.steps[position] = point;
    }
  },
  'windowHtml': function (lat,lng,html) {
    if (GBrowserIsCompatible()) {
      var point = new GLatLng(lat,lng);
      FLW.Map.map.openInfoWindowHtml(point,html,{'onOpenFn':function () { 
        var info = FLW.Map.map.getInfoWindow();
        var container = $(info.getContentContainers()[0]).down('.window');
        info.reset(info.getPoint(), null, new GSize(container.getWidth(), container.getHeight()));
      }});
    }
  },
  'setViewport': function (lat,lng,zoom) {
    if (GBrowserIsCompatible()) {
      var point = new GLatLng(lat,lng);
      FLW.Map.map.setCenter(point,zoom);
    }
  },
  'autoZoom': function () {
    if (GBrowserIsCompatible()) {
      var point = FLW.Map.bounds.getCenter();
      var zoom = FLW.Map.map.getBoundsZoomLevel(FLW.Map.bounds);
      FLW.Map.map.setCenter(point,(zoom-1));
    }
  },
  'panToBound': function (position) {
    if (GBrowserIsCompatible()) {
      FLW.Map.map.panTo(FLW.Map.steps[position]);
    }
  },
  'clear': function () {
    FLW.Map.bounds = new GLatLngBounds();
    FLW.Map.steps = new Hash();
    FLW.Map.map.clearOverlays();
  },
  'unload': function () {
    if (GBrowserIsCompatible()) {
      GUnload();
    }
  }
};

/* FLW */

FLW.BirthDate = {
  'change': function (el) {
    var day = el.next('select');
    var month = day.next('select');
    var year = month.next('select');
    $(el).value = year.value+"-"+month.value+"-"+day.value;
  }
};

FLW.Select = {
  'active':false,
  'init': function (url,select,value,parent,args) {
    select = $(select);
    args.id = select.id;
    args.value =  value;
    if (parent) {
      args.parent = parent;
    }
    FLW.Select.clear(select);
    Kwo.exec(url, args, {'async':false,'callback':FLW.Select.load});
  },
  'load': function (resp) {
    var select = $(resp.result.select);
    var datas = resp.result.arr;
    var value = resp.result.value;
    for (var key in datas) {
      if (Object.isFunction(datas[key])) continue;
      var opt = document.createElement('option');
      var txt = document.createTextNode(datas[key]);
      opt.appendChild(txt);
      opt.value = key;
      if (key == value) {
        opt.selected = true;
      }
      select.appendChild(opt);
    }
    if (select.options.length<2) {
      FLW.Select.clear(select);
      select.disabled = true;
    } else {
      select.disabled = false;
    }
    while (select = select.next('select.auto')) {
      FLW.Select.clear(select);
      select.disabled = true;
    }
    FLW.Select.change();
  },
  'change': function () {
    if ($('legend')) {
      if ($('legend').className == 'form_ressource') {
        FLW.Ressource.get($('legend'));
      } else if ($('legend').className == 'form_estimation') {
        FLW.Estimation.get($('legend'));
      } else if (FLW.Select.active) {
        if ($('legend').className == 'form_catalog') {
          FLW.Catalog.get($('legend'));
        } else if ($('legend').className == 'form_adv_search') {
          FLW.Finder.get($('legend'));
        }
      }
    }
  },
  'clear': function (obj) {
    if (obj) while (obj.hasChildNodes()) {
      obj.removeChild(obj.firstChild);
    }
  }
};

FLW.Product = {
  "activate": function (args) {
    Kwo.exec('/account/flw/status.activate', args, {'async':false,'callback':FLW.Product.onCallbackUpdate});
  },
  "desactivate": function (args) {
    Kwo.exec('/account/flw/status.desactivate', args, {'async':false,'callback':FLW.Product.onCallbackUpdate});
  },
  "validate": function (args) {
    Kwo.exec('/account/flw/status.validate', args, {'async':false,'callback':FLW.Product.onCallbackUpdate});
  },
  "remove": function (args,msg) {
    if (confirm(msg)) {
      Kwo.exec('/account/flw/status.delete', args, {'async':false,'callback':FLW.Product.onCallbackRemove});
    }
  },
  "add": function (model,msg) {
    if (model.length > 0) {
      Kwo.exec('/account/flw/'+model+'.edit', null, {'async':false,'container':'kwo-account-content'});
    } else {
      alert(msg);
    }
  },
  "onCallbackUpdate": function (h) {
    if ($('legend')) {
      FLW.Select.change();
    }
  },
  "onCallbackRemove": function (h) {
    if ($('legend')) {
      FLW.Select.change();
    } else {
      Kwo.exec('/account/flw/catalog', null, {'async':false,'container':'kwo-account-content'});
    }
  }
};

FLW.Catalog = {
  'get': function (args) {
    FLW.Catalog.fetch(args);
  },
  'fetch': function (args) {
    Kwo.exec('/account/flw/data.catalog', args, {'async':false,'container':'catalog'});
  }
};

FLW.Estimation = {
  'get': function (args) {
    FLW.Estimation.fetch(args);
  },
  'fetch': function (args) {
    Kwo.exec('/account/flw/data.estimation', args, {'async':false,'container':'estimationlist'});
  }
};

FLW.Bookmark = {
  'get': function (args) {
    FLW.Bookmark.fetch(args);
  },
  'fetch': function (args) {
    Kwo.exec('/account/flw/data.bookmark', args, {'async':false,'container':'bookmarklist'});
  }
};

FLW.Ressource = {
  'get': function (args) {
    FLW.Ressource.fetch(args);
  },
  'fetch': function (args) {
    Kwo.exec('/account/flw/data.ressource', args, {'async':false,'container':'ressourcelist'});
  }
};

FLW.MediaPhoto = {
  "add": function (model) {
    FLW.Dialog.addressource(model);
  },
  "store": function (args,msg) {
    if ($F("media[name]") && $F("media[photo]")) {
      Kwo.exec('/account/flw/data.ressource.store', args, {'async':false,'callback':FLW.MediaPhoto.onCallbackInfos});
    } else {
      alert(msg);
    }
  },
  "remove": function (args) {
    Kwo.exec('/account/flw/data.ressource.remove', args, {'async':false,'callback':FLW.MediaPhoto.onCallbackRemove});
  },
  "onCallbackInfos": function (h) {
    Kwo.exec('/account/flw/photo.edit', $("form_edit"), {'async':false,'container':'kwo-account-content'})
  },
  "onCallbackRemove": function (h) {
    if ($('legend')) {
      FLW.Select.change();
    } else {
      Kwo.exec('/account/flw/media', null, {'async':false,'container':'kwo-account-content'});
    }
  }
};

FLW.Filters = {
  "show": function (model) {
    if ($('legend').className == 'form_adv_search') {
      $(model+'_filter').checked = true;
      $$('div.box_filters').invoke('hide');
      $(model+'_filters').show();
      FLW.Select.change();
    } else if ($('legend').className == 'form_catalog') {
      FLW.Filters.scroll(model);
      FLW.Catalog.get($(model+'_filter'));
    }
  },
  "swap": function (id1, id2) {
    if ($(id1).visible()) {
      $(id1).hide();
      $(id2).show();
    } else {
      $(id2).hide();
      $(id1).show();
    }
    FLW.Select.change();
  },
  "hide": function (model) {
    $(model+'_show').show();
    $(model+'_filters').hide();
    $(model+'_hide').hide();
  },
  "scroll": function (model) {
    FLW.Filters.collapse();
    $(model+'_show').hide();
    $(model+'_filters').show();
    $(model+'_hide').show();
    $(model+'_filter').checked = true;
  },
  "collapse": function (model) {
    for (var key in FLW) if (key.match('MODEL_') && $(FLW[key]+'_show')) {
      $(FLW[key]+'_show').show();
      $(FLW[key]+'_filters').hide();
      $(FLW[key]+'_hide').hide();
    }
  },
  "select": function (model) {
    $('filter').value=model;
    $('page').value=0;
    $('resultlist').update('');
    FLW.Search.fetch($('legend'));
    $('filters').hide();
    $('refine').show();
  }
};

FLW.Orders = {
  'set': function (link, order) {
    if ($('order').value == order) {
      $('order').value = order+' DESC';
    } else {
      $('order').value = order;
    }
    $(link).style.color = "red";
  }
};

FLW.AccountTab = {
  'view': function (el,id) {
    $(el).up('.tabs').down('.tabselected').removeClassName('tabselected');
    $(el).up('.tab').addClassName('tabselected');
    var panel = $(el).up('.tabs').up('div').down('.visible');
    panel.removeClassName('visible');
    panel.addClassName('hidden');
    panel.hide();
    $(id).removeClassName('hidden');
    $(id).addClassName('visible');
    $(id).show();
  }
};

FLW.AccountBookmark = {
  "remove": function (args) {
    Kwo.exec('/account/flw/data.bookmark.remove', args, {'async':false,'callback':FLW.AccountBookmark.onCallbackRemove});
  },
  "onCallbackRemove": function (h) {
    FLW.Bookmark.get($('legend'));
  }
};

FLW.AccountPeriod = {
  "view": function (args) {
    Kwo.exec('/account/flw/data.period', args, {'async':false,'container':'period_'+args.model_id+'_'+args.parent_id+'_'+args.type});
  },
  "add": function (args,container) {
    Kwo.exec('/account/flw/data.period.add', args, {'async':false,'container':container});
  },
  "remove": function (args) {
    Kwo.exec('/account/flw/data.period.remove', args, {'async':false,'container':'period_'+args.model_id+'_'+args.parent_id+'_'+args.type});
  }
};

FLW.AccountProximity = {
  "view": function (args) {
    Kwo.exec('/account/flw/data.proximity', args, {'async':false,'container':'proximitylist'});
  },
  "add": function (args) {
    Kwo.exec('/account/flw/data.proximity.add', args, {'async':false,'container':'proximitylist'});
  },
  "remove": function (args) {
    Kwo.exec('/account/flw/data.proximity.remove', args, {'async':false,'container':'proximitylist'});
  },
  "move": function (args) {
    Kwo.exec('/account/flw/data.proximity.move', args, {'async':false,'container':'proximitylist'});
  }
};

FLW.AccountRelation = {
  "view": function (args) {
    Kwo.exec('/account/flw/data.relation', args, {'async':false,'container':'relationlist'+args.record_id});
  },
  "add": function (args) {
    Kwo.exec('/account/flw/data.relation.add', args, {'async':false,'container':'relationlist'+args.record_id});
  },
  "remove": function (args) {
    Kwo.exec('/account/flw/data.relation.remove', args, {'async':false,'container':'relationlist'+args.record_id});
  },
  "move": function (args) {
    Kwo.exec('/account/flw/data.relation.move', args, {'async':false,'container':'relationlist'+args.record_id});
  }
};

FLW.AccountProgram = {
  "view": function (args) {
    Kwo.exec('/account/flw/data.program', args, {'async':false,'container':'programlist'});
  },
  "add": function (args) {
    Kwo.exec('/account/flw/data.program.add', args, {'async':false,'container':'programlist'});
  },
  "remove": function (args) {
    Kwo.exec('/account/flw/data.program.remove', args, {'async':false,'container':'programlist'});
  },
  "move": function (args) {
    Kwo.exec('/account/flw/data.program.move', args, {'async':false,'container':'programlist'});
  },
  "store": function (args) {
    Kwo.exec('/account/flw/data.program.store', args, {'async':false,'container':'programlist'});
  }
};

FLW.AccountMedia = {
  "view": function (args) {
    var container = 'medialist';
    if (args.record_id && args.record_id > 0 && args.model_id && args.model_id == FLW.MODEL_ROOM) {
      container = 'roommedialist'+args.record_id;
    }
    Kwo.exec('/account/flw/data.media', args, {'async':false,'container':container});
  },
  "add": function (args) {
    var container = 'medialist';
    if (args.record_id && args.record_id > 0 && args.model_id && args.model_id == FLW.MODEL_ROOM) {
      container = 'roommedialist'+args.record_id;
    }
    Kwo.exec('/account/flw/data.media.add', args, {'async':false,'container':container});
  },
  "remove": function (args) {
    var container = 'medialist';
    if (args.record_id && args.record_id > 0 && args.model_id && args.model_id == FLW.MODEL_ROOM) {
      container = 'roommedialist'+args.record_id;
    }
    Kwo.exec('/account/flw/data.media.remove', args, {'async':false,'container':container});
  },
  "move": function (args) {
    var container = 'medialist';
    if (args.record_id && args.record_id > 0 && args.model_id && args.model_id == FLW.MODEL_ROOM) {
      container = 'roommedialist'+args.record_id;
    }
    Kwo.exec('/account/flw/data.media.move', args, {'async':false,'container':container});
  }
};

FLW.AccountRoom = {
  "add": function (args) {
    Kwo.exec('/account/flw/accommodation.edit.rooms.add', args, {'async':false,'container':'rooms'});
  },
  "remove": function (args, msg) {
    if (confirm(msg)) {
      Kwo.exec('/account/flw/accommodation.edit.rooms.remove', args, {'async':false,'container':'rooms'});
    }
  }
};

FLW.AccountTheme = {
  "add": function (args) {
    Kwo.exec('/account/flw/destination.edit.themes.add', args, {'async':false,'container':'themes'});
  },
  "remove": function (args, msg) {
    if (confirm(msg)) {
      Kwo.exec('/account/flw/destination.edit.themes.remove', args, {'async':false,'container':'themes'});
    }
  }
};

FLW.GeoPicker = {
  "map": null,
  "geo": null,
  "marker": null,
  "lat": null,
  "lng": null,
  "zoom": null,
  "address": null,
  "simpleaddress": null,
  "names": null,
  "init": function (args, names) {
    FLW.GeoPicker.clear();
    FLW.GeoPicker.names = names;
    if (args.lat && args.lng && args.zoom) {
      FLW.GeoPicker.lat = args.lat;
      FLW.GeoPicker.lng = args.lng;
      FLW.GeoPicker.zoom = args.zoom;
    } else if (args.address && args.simpleaddress) {
      FLW.GeoPicker.address = args.address;
      FLW.GeoPicker.simpleaddress = args.simpleaddress;
    }
  },
  'view': function () {
    if (FLW.GeoPicker.lat && FLW.GeoPicker.lng && FLW.GeoPicker.zoom) {
      google.load("maps","2",{"callback": FLW.GeoPicker.display});
    } else if (FLW.GeoPicker.address) {
      google.load("maps","2",{"callback": FLW.GeoPicker.search});
    }
  },
  'display': function () {
    if (GBrowserIsCompatible()) {
      if (!FLW.GeoPicker.map || !FLW.GeoPicker.map.isLoaded()) {
        Event.observe(window, 'unload', FLW.GeoPicker.unload);
        FLW.GeoPicker.map = new GMap2($('gmap'));
        FLW.GeoPicker.map.addControl(new GLargeMapControl());
        GEvent.addListener(FLW.GeoPicker.map, 'zoomend', FLW.GeoPicker.change);
        var point = new GLatLng(FLW.GeoPicker.lat,FLW.GeoPicker.lng);
        FLW.GeoPicker.map.setCenter(point,FLW.GeoPicker.zoom);
        var icon = new GIcon(G_DEFAULT_ICON);
        FLW.GeoPicker.marker = new GMarker(point, {'icon':icon, 'clickable':false, 'draggable': true});
        GEvent.addListener(FLW.GeoPicker.marker, 'dragend', FLW.GeoPicker.change);
        FLW.GeoPicker.map.addOverlay(FLW.GeoPicker.marker);
      } else {
        FLW.GeoPicker.center();
      }
    }
  },
  'search': function () {
    $('gmap').show();
    $('message').hide();
    if (GBrowserIsCompatible()) {
      if (!FLW.GeoPicker.map || !FLW.GeoPicker.map.isLoaded()) {
        Event.observe(window, 'unload', FLW.GeoPicker.unload);
        FLW.GeoPicker.map = new GMap2($('gmap'));
        FLW.GeoPicker.map.addControl(new GLargeMapControl());
        GEvent.addListener(FLW.GeoPicker.map, 'zoomend', FLW.GeoPicker.change);
      } else {
        FLW.GeoPicker.map.clearOverlays();
      }
      FLW.GeoPicker.geo = new GClientGeocoder();
      FLW.GeoPicker.geo.getLatLng(FLW.GeoPicker.address, FLW.GeoPicker.result);
    }
  },
  'result': function (point) {
    if (!point) {
      FLW.GeoPicker.geo = new GClientGeocoder();
      FLW.GeoPicker.geo.getLatLng(FLW.GeoPicker.simpleaddress, FLW.GeoPicker.simpleresult);
    } else {
      FLW.GeoPicker.lat = point.y;
      $(FLW.GeoPicker.names["lat"]).value = point.y;
      FLW.GeoPicker.lng = point.x;
      $(FLW.GeoPicker.names["lng"]).value = point.x;
      FLW.GeoPicker.zoom = 15;
      $(FLW.GeoPicker.names["zoom"]).value = 15;
      FLW.GeoPicker.map.setCenter(point,FLW.GeoPicker.zoom);
      var icon = new GIcon(G_DEFAULT_ICON);
      FLW.GeoPicker.marker = new GMarker(point, {'icon':icon, 'clickable':false, 'draggable': true});
      GEvent.addListener(FLW.GeoPicker.marker, 'dragend', FLW.GeoPicker.change);
      FLW.GeoPicker.map.addOverlay(FLW.GeoPicker.marker);
    }
  },
  'simpleresult': function (point) {
    if (point) {
      FLW.GeoPicker.lat = point.y;
      $(FLW.GeoPicker.names["lat"]).value = point.y;
      FLW.GeoPicker.lng = point.x;
      $(FLW.GeoPicker.names["lng"]).value = point.x;
      FLW.GeoPicker.zoom = 15;
      $(FLW.GeoPicker.names["zoom"]).value = 15;
      FLW.GeoPicker.map.setCenter(point,FLW.GeoPicker.zoom);
      var icon = new GIcon(G_DEFAULT_ICON);
      FLW.GeoPicker.marker = new GMarker(point, {'icon':icon, 'clickable':false, 'draggable': true});
      GEvent.addListener(FLW.GeoPicker.marker, 'dragend', FLW.GeoPicker.change);
      FLW.GeoPicker.map.addOverlay(FLW.GeoPicker.marker);
    } else {
      $('gmap').hide();
      $('message').show();
    }
  },
  'change': function () {
    if (FLW.GeoPicker.marker) {
      var point = FLW.GeoPicker.marker.getPoint();
      if (point) {
        FLW.GeoPicker.lat = point.y;
        $(FLW.GeoPicker.names["lat"]).value = point.y;
        FLW.GeoPicker.lng = point.x;
        $(FLW.GeoPicker.names["lng"]).value = point.x;
      }
      FLW.GeoPicker.center();
    }
    FLW.GeoPicker.zoom = FLW.GeoPicker.map.getZoom();
    $(FLW.GeoPicker.names["zoom"]).value = FLW.GeoPicker.map.getZoom();
  },
  'center': function () {
    if (FLW.GeoPicker.map && FLW.GeoPicker.marker) {
      FLW.GeoPicker.map.checkResize();
      FLW.GeoPicker.map.panTo(FLW.GeoPicker.marker.getPoint());
    }
  },
  'clear': function () {
    FLW.GeoPicker.map = null;
    FLW.GeoPicker.geo = null;
    FLW.GeoPicker.marker = null;
    FLW.GeoPicker.lat = null;
    FLW.GeoPicker.lng = null;
    FLW.GeoPicker.zoom = null;
    FLW.GeoPicker.address = null;
    FLW.GeoPicker.names = null;
  },
  'unload': function () {
    GUnload();
  }
};

FLW.Dialog = {
  "media": function (args) {
    new FLW.Dialog.Media(args);
  },
  "file": function (el, args) {
    new FLW.Dialog.File(el, args);
  },
  "message": function (args) {
    new FLW.Dialog.Message(args);
  },
  "newsletter": function (args) {
    new FLW.Dialog.Newsletter(args);
  },
  "snippet": function (args) {
    new FLW.Dialog.Snippet(args);
  },
  "addprogram": function (args) {
    new FLW.Dialog.AddProgram(args);
  },
  "addproximity": function (args) {
    new FLW.Dialog.AddProximity(args);
  },
  "addrelation": function (args) {
    new FLW.Dialog.AddRelation(args);
  },
  "addressource": function (model) {
    new FLW.Dialog.AddRessource({'model':model});
  },
  "addperiod": function (args) {
    new FLW.Dialog.AddPeriod(args);
  }
};

FLW.KwoDialog = Class.create({
  "bind": null,
  "width": null,
  "height": null,
  "initialize": function(paint_method, args, opts) {
    opts = opts || {};
    if (window.flw_overlay === undefined) {
      window.flw_overlay = document.body.appendChild(new Element("div", {"id": "flw_overlay"}).setStyle({"display": "none", "opacity": "0.1"}));
      window.flw_subsupport = document.body.appendChild(new Element("div", {"id": "flw_subsupport"}).setStyle({"display": "none"}));
      window.flw_subsupport.appendChild(new Element("img", {"src": "/app/sys/pix/close-dialog2.gif", "id": "flw_close-dialog"})).observe("click", this.close);
      window.flw_support = window.flw_subsupport.appendChild(new Element("div", {"id": "flw_support"}).setStyle({"display": "none"}));
      $("flw_overlay").observe("click", this.close);
    }

    this.opts = opts;
    this.place();
    this.bind = this.place.bindAsEventListener(this);

    Event.observe(window, 'resize', this.bind);
    Event.observe(window, 'scroll', this.bind);

    FLW.setDialog(this);

    this.name = "dialog";

    $("flw_support").update('');

    if (typeof paint_method == "function") {
      paint_method.call(FLW.getDialog(), args);
    } else if (paint_method != undefined) {
      Kwo.exec(paint_method, args, {"async":false,"container": "flw_support"});
    }

    if (Prototype.Browser.IE && navigator.userAgent.indexOf("MSIE 6") > -1) {
      $$("SELECT").invoke("hide");
    }
    $("flw_overlay", "flw_subsupport", "flw_support").invoke("show");
  },
  "place": function () {
    var dimensions = document.viewport.getDimensions();
    var offsets = document.viewport.getScrollOffsets();

    var width = "width" in this.opts ? parseInt(this.opts["width"]) : 400;
    var height = "height" in this.opts ? parseInt(this.opts["height"]) : 300;

    var left = offsets.left + ((dimensions.width / 2) - (width / 2));
    var top = offsets.top + ((dimensions.height / 2) - (height / 2));

    if (top < 0) { top = 0; }
    if (left < 0) { left = 0; }

    $("flw_overlay").setStyle({"width": dimensions.width+"px",
                               "height": dimensions.height+"px",
                               "left": offsets.left+"px",
                               "top": offsets.top+"px"});

    $("flw_subsupport").setStyle({"width": width+"px",
                                "height": height+"px",
                                "left": left+"px",
                                "top": top+"px"});

    $("flw_support").setStyle({"width": width+"px",
                               "height": height+"px"});

  },
  "close": function() {
    $("flw_support", "flw_subsupport", "flw_overlay").invoke("hide");
    $("flw_support").update('');
    if (Prototype.Browser.IE && navigator.userAgent.indexOf("MSIE 6") > -1) {
      $$("SELECT").invoke("show");
    }
  }

});

FLW.Dialog.Snippet = Class.create(FLW.KwoDialog, {
  "initialize": function($super, code, args) {
    opts = {"width": 550, "height": 550};
    $super("/flw/dialog.snippet", {'code':code}, opts);
    FLW.setDialog(this);
  }
});

FLW.Dialog.Media = Class.create(FLW.KwoDialog, {
  "initialize": function($super, args) {
    opts = {"width": 600, "height": 400};
    this.args = args;
    $super("/account/flw/dialog.media", args, opts);
    FLW.setDialog(this);
  },
  "apply": function(rel_model_id, rel_record_id) {
    FLW.AccountMedia.add({"model_id":this.args.model_id,"record_id":this.args.record_id,"rel_model_id":rel_model_id,"rel_record_id":rel_record_id});
    this.close();
  }
});

FLW.Dialog.Message = Class.create(FLW.KwoDialog, {
  "initialize": function($super, args) {
    opts = {"width": 600, "height": 400};
    $super("/flw/dialog.message", args, opts);
    FLW.setDialog(this);
  },
  "apply": function(args, msg) {
    if ($('message').value.length > 0 && $('email').value.length) {
      Kwo.exec('/flw/message.send', args, {'async':false});
      $('message-button').hide();
      $('message-status').show();
    } else {
      alert(msg);
    }
    return false;
  }
});

FLW.Dialog.File = Class.create(Kwo.Dialog, {
  "initialize": function($super, el, args) {
    this.el = el;
    this.args = args;
    opts = {"width": 500, "height": 280};
    $super("/account/flw/dialog.file", args, opts);
    Kwo.setDialog(this);
  },
  "refresh": function() {
    Kwo.exec("/account/flw/dialog.file", null, {'async':false,'container': 'support'});
  },
  "apply": function(path,name) {
    if (this.args && this.args.name_only) {
      this.el.value = name;
    } else {
      this.el.value = path;
    }
    this.close();
  }
});

FLW.Dialog.AddProximity = Class.create(FLW.KwoDialog, {
  "initialize": function($super, args) {
    opts = {"width": 700, "height": 550};
    this.args = args;
    $super("/account/flw/dialog.product", args, opts);
    FLW.setDialog(this);
  },
  "apply": function(rel_model_id, rel_record_id) {
    FLW.AccountProximity.add({"model_id":this.args.model_id,"record_id":this.args.record_id,"rel_model_id":rel_model_id,"rel_record_id":rel_record_id});
    this.close();
  }
});

FLW.Dialog.AddRelation = Class.create(FLW.KwoDialog, {
  "initialize": function($super, args) {
    opts = {"width": 700, "height": 500};
    this.args = args;
    $super("/account/flw/dialog.product", args, opts);
    FLW.setDialog(this);
  },
  "apply": function(rel_model_id, rel_record_id) {
    FLW.AccountRelation.add({"model_id":this.args.model_id,"record_id":this.args.record_id,"rel_model_id":rel_model_id,"rel_record_id":rel_record_id});
    this.close();
  }
});

FLW.Dialog.AddProgram = Class.create(FLW.KwoDialog, {
  "initialize": function($super, args) {
    opts = {"width": 700, "height": 500};
    this.args = args;
    $super("/account/flw/dialog.product", args, opts);
    FLW.setDialog(this);
  },
  "apply": function(rel_model_id, rel_record_id) {
    FLW.AccountProgram.add({"model_id":this.args.model_id,"record_id":this.args.record_id,"rel_model_id":rel_model_id,"rel_record_id":rel_record_id});
    this.close();
  }
});

FLW.Dialog.AddRessource = Class.create(FLW.KwoDialog, {
  "initialize": function($super, args) {
    opts = {"width": 450, "height": 210};
    $super("/account/flw/dialog.ressource.add", args, opts);
    FLW.setDialog(this);
  },
  "check_form": function (args, msg) {
    if ($F("media[name]") &&
        $F("media[photo]")) {
      this.apply(args);
    } else {
      alert(msg);
    }
  },
  "apply": function(args) {
    Kwo.exec("/account/flw/data.ressource.add", args, {'async':false});
    if ($('legend')) {
      FLW.Select.change();
    }
    this.close();
  }
});

FLW.Dialog.AddPeriod = Class.create(FLW.KwoDialog, {
  "initialize": function($super, args) {
    opts = {"width": 350, "height": 375};
    $super("/account/flw/dialog.period.add", args, opts);
    FLW.setDialog(this);
  },
  "all_year": function (el) {
    if (el.checked) {
      $('from_date').disabled = true;
      $('from_date').value = "";
      $('from_date').setStyle({opacity: 0.3});
      $('to_date').disabled = true;
      $('to_date').value = "";
      $('to_date').setStyle({opacity: 0.3});
    } else {
      $('from_date').disabled = false;
      $('from_date').setStyle({opacity: 1});
      $('to_date').disabled = false;
      $('to_date').setStyle({opacity: 1});
    }
  },
  "apply": function(args,container) {
    FLW.AccountPeriod.add(args,container);
    this.close();
  }
});

FLW.Suggestion = {
  "status": function (args) {
    Kwo.exec('/account/flw/suggestion.edit.status', args, {'async':false,'container':'status'});
  },
  "infos": function (args) {
    Kwo.exec('/account/flw/suggestion.edit.infos', args, {'async':false,'container':'infos','callback':this.onCallback});
    Kwo.exec('/account/flw/suggestion.edit.status', args, {'async':false,'container':'status'});
  },
  "presentation": function (args) {
    Kwo.exec('/account/flw/suggestion.edit.presentation', args, {'async':false,'container':'presentation','callback':this.onCallback});
    Kwo.exec('/account/flw/suggestion.edit.status', args, {'async':false,'container':'status'});
  },
  "address": function (args) {
    Kwo.exec('/account/flw/suggestion.edit.address', args, {'async':false,'container':'address','callback':this.onCallback});
    Kwo.exec('/account/flw/suggestion.edit.status', args, {'async':false,'container':'status'});
  },
  "proximity": function (args) {
    Kwo.exec('/account/flw/suggestion.edit.proximity', args, {'async':false,'container':'proximity','callback':this.onCallback});
    Kwo.exec('/account/flw/suggestion.edit.status', args, {'async':false,'container':'status'});
  },
  "onCallback": function () {
    alert('Vos informations ont bien été prises en compte');
  }
};

FLW.Activity = {
  "status": function (args) {
    Kwo.exec('/account/flw/activity.edit.status', args, {'async':false,'container':'status'});
  },
  "infos": function (args) {
    Kwo.exec('/account/flw/activity.edit.infos', args, {'async':false,'container':'infos','callback':this.onCallback});
    Kwo.exec('/account/flw/activity.edit.status', args, {'async':false,'container':'status'});
  },
  "presentation": function (args) {
    Kwo.exec('/account/flw/activity.edit.presentation', args, {'async':false,'container':'presentation','callback':this.onCallback});
    Kwo.exec('/account/flw/activity.edit.status', args, {'async':false,'container':'status'});
  },
  "rates": function (args) {
    Kwo.exec('/account/flw/activity.edit.rates', args, {'async':false,'container':'rates','callback':this.onCallback});
    Kwo.exec('/account/flw/activity.edit.status', args, {'async':false,'container':'status'});
  },
  "address": function (args) {
    Kwo.exec('/account/flw/activity.edit.address', args, {'async':false,'container':'address','callback':this.onCallback});
    Kwo.exec('/account/flw/activity.edit.status', args, {'async':false,'container':'status'});
  },
  "proximity": function (args) {
    Kwo.exec('/account/flw/activity.edit.proximity', args, {'async':false,'container':'proximity','callback':this.onCallback});
    Kwo.exec('/account/flw/activity.edit.status', args, {'async':false,'container':'status'});
  },
  "onCallback": function () {
    alert('Vos informations ont bien été prises en compte');
  }
};

FLW.Package = {
  "status": function (args) {
    Kwo.exec('/account/flw/package.edit.status', args, {'async':false,'container':'status'});
  },
  "infos": function (args) {
    Kwo.exec('/account/flw/package.edit.infos', args, {'async':false,'container':'infos','callback':this.onCallback});
    Kwo.exec('/account/flw/package.edit.status', args, {'async':false,'container':'status'});
  },
  "presentation": function (args) {
    Kwo.exec('/account/flw/package.edit.presentation', args, {'async':false,'container':'presentation','callback':this.onCallback});
    Kwo.exec('/account/flw/package.edit.status', args, {'async':false,'container':'status'});
  },
  "rates": function (args) {
    Kwo.exec('/account/flw/package.edit.rates', args, {'async':false,'container':'rates','callback':this.onCallback});
    Kwo.exec('/account/flw/package.edit.status', args, {'async':false,'container':'status'});
  },
  "program": function (args) {
    Kwo.exec('/account/flw/package.edit.program', args, {'async':false,'container':'program','callback':this.onCallback});
    Kwo.exec('/account/flw/package.edit.status', args, {'async':false,'container':'status'});
  },
  "products": function (args) {
    Kwo.exec('/account/flw/package.edit.products', args, {'async':false,'container':'products','callback':this.onCallback});
    Kwo.exec('/account/flw/package.edit.status', args, {'async':false,'container':'status'});
  },
  "address": function (args) {
    Kwo.exec('/account/flw/package.edit.address', args, {'async':false,'container':'address','callback':this.onCallback});
    Kwo.exec('/account/flw/package.edit.status', args, {'async':false,'container':'status'});
  },
  "proximity": function (args) {
    Kwo.exec('/account/flw/package.edit.proximity', args, {'async':false,'container':'proximity','callback':this.onCallback});
    Kwo.exec('/account/flw/package.edit.status', args, {'async':false,'container':'status'});
  },
  "onCallback": function () {
    alert('Vos informations ont bien été prises en compte');
  }
};


FLW.Lodging = {
  "status": function (args) {
    Kwo.exec('/account/flw/lodging.edit.status', args, {'async':false,'container':'status'});
  },
  "infos": function (args) {
    Kwo.exec('/account/flw/lodging.edit.infos', args, {'async':false,'container':'infos','callback':this.onCallback});
    Kwo.exec('/account/flw/lodging.edit.status', args, {'async':false,'container':'status'});
  },
  "presentation": function (args) {
    Kwo.exec('/account/flw/lodging.edit.presentation', args, {'async':false,'container':'presentation','callback':this.onCallback});
    Kwo.exec('/account/flw/lodging.edit.status', args, {'async':false,'container':'status'});
  },
  "rates": function (args) {
    Kwo.exec('/account/flw/lodging.edit.rates', args, {'async':false,'container':'rates','callback':this.onCallback});
    Kwo.exec('/account/flw/lodging.edit.status', args, {'async':false,'container':'status'});
  },
  "address": function (args) {
    Kwo.exec('/account/flw/lodging.edit.address', args, {'async':false,'container':'address','callback':this.onCallback});
    Kwo.exec('/account/flw/lodging.edit.status', args, {'async':false,'container':'status'});
  },
  "proximity": function (args) {
    Kwo.exec('/account/flw/lodging.edit.proximity', args, {'async':false,'container':'proximity','callback':this.onCallback});
    Kwo.exec('/account/flw/lodging.edit.status', args, {'async':false,'container':'status'});
  },
  "onCallback": function () {
    alert('Vos informations ont bien été prises en compte');
  }
};

FLW.Accommodation = {
  "status": function (args) {
    Kwo.exec('/account/flw/accommodation.edit.status', args, {'async':false,'container':'status'});
  },
  "infos": function (args) {
    Kwo.exec('/account/flw/accommodation.edit.infos', args, {'async':false,'container':'infos','callback':this.onCallback});
    Kwo.exec('/account/flw/accommodation.edit.status', args, {'async':false,'container':'status'});
  },
  "presentation": function (args) {
    Kwo.exec('/account/flw/accommodation.edit.presentation', args, {'async':false,'container':'presentation','callback':this.onCallback});
    Kwo.exec('/account/flw/accommodation.edit.status', args, {'async':false,'container':'status'});
  },
  "rooms": function (args) {
    Kwo.exec('/account/flw/accommodation.edit.rooms', args, {'async':false,'container':'rooms','callback':this.onCallback});
    Kwo.exec('/account/flw/accommodation.edit.status', args, {'async':false,'container':'status'});
  },
  "rates": function (args) {
    Kwo.exec('/account/flw/accommodation.edit.rates', args, {'async':false,'container':'rates','callback':this.onCallback});
    Kwo.exec('/account/flw/accommodation.edit.status', args, {'async':false,'container':'status'});
  },
  "address": function (args) {
    Kwo.exec('/account/flw/accommodation.edit.address', args, {'async':false,'container':'address','callback':this.onCallback});
    Kwo.exec('/account/flw/accommodation.edit.status', args, {'async':false,'container':'status'});
  },
  "proximity": function (args) {
    Kwo.exec('/account/flw/accommodation.edit.proximity', args, {'async':false,'container':'proximity','callback':this.onCallback});
    Kwo.exec('/account/flw/accommodation.edit.status', args, {'async':false,'container':'status'});
  },
  "onCallback": function () {
    alert('Vos informations ont bien été prises en compte');
  }
};

FLW.Destination = {
  "status": function (args) {
    Kwo.exec('/account/flw/destination.edit.status', args, {'async':false,'container':'status'});
  },
  "infos": function (args) {
    Kwo.exec('/account/flw/destination.edit.infos', args, {'async':false,'container':'infos','callback':this.onCallback});
    Kwo.exec('/account/flw/destination.edit.status', args, {'async':false,'container':'status'});
  },
  "presentation": function (args) {
    Kwo.exec('/account/flw/destination.edit.presentation', args, {'async':false,'container':'presentation'});
    Kwo.exec('/account/flw/destination.edit.status', args, {'async':false,'container':'status'});
  },
  "address": function (args) {
    Kwo.exec('/account/flw/destination.edit.address', args, {'async':false,'container':'address','callback':this.onCallback});
    Kwo.exec('/account/flw/destination.edit.status', args, {'async':false,'container':'status'});
  },
  "selection": function (args) {
    Kwo.exec('/account/flw/destination.edit.selection', args, {'async':false,'container':'selection','callback':this.onCallback});
    Kwo.exec('/account/flw/destination.edit.status', args, {'async':false,'container':'status'});
  },
  "themes": function (args) {
    Kwo.exec('/account/flw/destination.edit.themes', args, {'async':false,'container':'themes','callback':this.onCallback});
    Kwo.exec('/account/flw/destination.edit.status', args, {'async':false,'container':'status'});
  },
  "onCallback": function () {
    alert('Vos informations ont bien été prises en compte');
  }
};

FLW.Grouping = {
  "status": function (args) {
    Kwo.exec('/account/flw/grouping.edit.status', args, {'async':false,'container':'status'});
  },
  "infos": function (args) {
    Kwo.exec('/account/flw/grouping.edit.infos', args, {'async':false,'container':'infos','callback':this.onCallback});
    Kwo.exec('/account/flw/grouping.edit.status', args, {'async':false,'container':'status'});
  },
  "presentation": function (args) {
    Kwo.exec('/account/flw/grouping.edit.presentation', args, {'async':false,'container':'presentation'});
    Kwo.exec('/account/flw/grouping.edit.status', args, {'async':false,'container':'status'});
  },
  "address": function (args) {
    Kwo.exec('/account/flw/grouping.edit.address', args, {'async':false,'container':'address','callback':this.onCallback});
    Kwo.exec('/account/flw/grouping.edit.status', args, {'async':false,'container':'status'});
  },
  "proximity": function (args) {
    Kwo.exec('/account/flw/grouping.edit.proximity', args, {'async':false,'container':'proximity','callback':this.onCallback});
    Kwo.exec('/account/flw/grouping.edit.status', args, {'async':false,'container':'status'});
  },
  "onCallback": function () {
    alert('Vos informations ont bien été prises en compte');
  }
};

FLW.Video = {
  "timeout": null,
  "home": function (model, id, container) {
    $(container).setStyle({backgroundRepeat:'no-repeat',backgroundPosition:'center',backgroundImage:'url(/app/flw/pix/loading.gif)'});
    FLW.Video.timeout = window.setTimeout("FLW.Video.onHome("+model+","+id+",'"+container+"')", 3000);
  },
  "onHome": function (model, id, container) {
    $(container).setStyle({backgroundRepeat:'',backgroundPosition:'',backgroundImage:''});
    $(container).update($('noflash').innerHTML);
    var flashvars = { playlist: "/flw/data.playlist/-/record_id/"+id+"/model_id/"+model+"/filter/video" };
    var params = { menu: "false", allowfullscreen: "true", wmode: "transparent"};
    var attributes = { id: "mediaplayer", name: "mediaplayer" };
    swfobject.embedSWF("/app/flw2/swf/mediaplayer.swf", container, "340", "255", "9.0.0", "/app/flw/swf/expressInstall.swf", flashvars, params, attributes);
  },
  "player": function (model, id, container) {
    $(container).setStyle({backgroundRepeat:'no-repeat',backgroundPosition:'center',backgroundImage:'url(/app/flw/pix/loading.gif)'});
    FLW.Video.timeout = window.setTimeout("FLW.Video.onPlayer("+model+","+id+",'"+container+"')", 3000);
  },
  "onPlayer": function (model, id, container) {
    $(container).setStyle({backgroundRepeat:'',backgroundPosition:'',backgroundImage:''});
    $(container).update($('noflash').innerHTML);
    var flashvars = { playlist: "/flw/data.playlist/-/record_id/"+id+"/model_id/"+model };
    var params = { menu: "false", allowfullscreen: "true", wmode: "transparent" };
    var attributes = { id: "mediaplayer", name: "mediaplayer" };
    swfobject.embedSWF("/app/flw2/swf/mediaplayer.swf", container, "340", "255", "9.0.0", "/app/flw/swf/expressInstall.swf", flashvars, params, attributes);
  }
};

FLW.Book = {
  'step1': function (el,msg) {
    var form = $(el).up('form');
    if (form.className == "form_accommodation") {
      var adult_count = 0;
      var child_count = 0;
      $$("input.adult_count").each(function (e) { adult_count = adult_count + parseInt($F(e)) });
      $$("input.child_count").each(function (e) { child_count = child_count + parseInt($F(e)) });
      if ($F('record[start_date]').length > 0 && (parseInt($F('record[night_count]')) > 0) && (adult_count > 0 || child_count > 0)) return form.submit();
    } else if (form.className == "form_lodging") {
      if ($F('record[start_date]').length > 0 && (parseInt($F('record[night_count]')) > 0) && (parseInt($F('record[adult_count]')) > 0 || parseInt($F('record[child_count]')) > 0)) return form.submit();
    } else if (form.className == "form_activity") {
      if ($F('record[start_date]').length > 0 && (parseInt($F('record[adult_count]')) > 0 || parseInt($F('record[child_count]')) > 0)) return form.submit();
    } else if (form.className == "form_package") {
      if ($F('record[start_date]').length > 0 && (parseInt($F('record[adult_count]')) > 0 || parseInt($F('record[child_count]')) > 0)) return form.submit();
    }
    return alert(msg);
  },
  'step2': function (el,msg) {
    var form = $(el).up('form');
    if ($F('record[first_name]').length > 0 &&
        $F('record[last_name]').length > 0 &&
        //$F('record[address]').length > 0 &&
        //$F('record[city]').length > 0 &&
        //$F('record[zip_code]').length > 0 &&
        //$('record[country_id]').value > 0 &&
        //$('record[region_id]').value > 0 &&
        //$('record[department_id]').value > 0 &&
        $F('record[phone_1]').length > 0) return form.submit();
    return alert(msg);
  },
  'step3': function (el) {
    var form = $(el).up('form');
    form.submit();
  },
  'step4': function () {
    Kwo.go("/");
  }
};

FLW.Duration = {
  'change': function (day,hour,min,res) {
    $(res).value = (parseInt($(day).value)*3600)+(parseInt($(hour).value)*60)+parseInt($(min).value);
  }
};

FLW.ProgressBar = {
  "view": function (id, ratio) {
    $(id).firstChild.style.width = Math.round(300 * ratio) + "px";
    $(id).firstChild.innerHTML = Math.round(ratio * 100) + "%";
  }
};

FLW.Profile = {
  "perso": function (args,msg) {
    if ($F("profile[country_id]") && $F("profile[country_id]").length>0 &&
        ((!$('accept-cpu')) || ($('accept-cpu') && $('accept-cpu').checked))) {
      if ($('accept-cpu') && $('accept-cpu').checked) {
        Kwo.exec("/account/flw/profile.store", args, {'async':false,'callback':function(){Kwo.Account.selectAction($('my_account:home'))}});
      } else {
        Kwo.exec("/account/flw/profile.store", args, {'async':false,'callback':Kwo.Account.refresh});
      }
    } else {
      alert(msg);
    }
  },
  "member": function (args,msg) {
    if ($F("profile[country_id]") && $F("profile[country_id]").length>0 &&
        $F("profile[pseudo]") && $F("profile[pseudo]").length>0 &&
        $F("profile[skill]") && $F("profile[skill]").length>0 &&
        ((!$('accept-cpu')) || ($('accept-cpu') && $('accept-cpu').checked))) {
      if ($('accept-cpu') && $('accept-cpu').checked) {
        Kwo.exec("/account/flw/profile.store", args, {'async':false,'callback':function(){Kwo.Account.selectAction($('my_account:home'))}});
      } else {
        Kwo.exec("/account/flw/profile.store", args, {'async':false,'callback':Kwo.Account.refresh});
      }
    } else {
      alert(msg);
    }
  },
  "commercial": function (args,msg) {
    if ($F("profile[country_id]") &&
        $F("profile[pseudo]") &&
        $F("profile[skill]") &&
        $F("profile[com_name]") &&
        $F("profile[com_civility]") &&
        $F("profile[com_first_name]") &&
        $F("profile[com_last_name]") &&
        $F("profile[com_country_id]") &&
        $F("profile[com_region_id]") &&
        $F("profile[com_department_id]") &&
        $F("profile[com_address]") &&
        $F("profile[com_city]") &&
        $F("profile[com_zip_code]") &&
        $F("profile[com_phone_1]") &&
        ((!$('accept-cpu')) || ($('accept-cpu') && $('accept-cpu').checked))) {
      if ($('accept-cpu') && $('accept-cpu').checked) {
        Kwo.exec("/account/flw/profile.store", args, {'async':false,'callback':function(){Kwo.Account.selectAction($('my_account:home'))}});
      } else {
        Kwo.exec("/account/flw/profile.store", args, {'async':false,'callback':Kwo.Account.refresh});
      }
    } else {
      alert(msg);
    }
  }
};
