//if($('gmap')) {
Event.observe(window, 'load', Gload, false);
//Event.observe(body, 'unload', GInitCity, false);
Event.observe(window, 'unload', GInitCity, false);

 // Event.observe(window, 'unload', GUnload, false);
//}
/***
 * util functions
 * */ 
function JS_startCallbackAvatar() {
  $('upload-ava-btn').disable();
  $('upload-ava-btn').value = 'Chargement ...';
  return true;  
}
function JS_completeCallbackAvatar(response) {
  $('avatar-previ').innerHTML = response;
  $('upload-ava-btn').enable();
  $('upload-ava-btn').value = 'Télécharger l\'image';
  new Effect.Morph('avatar-previ',{
    style:{
      width:'400px'
    }
  });
}
function JS_loadLinkEditor(id) {
  if($F('is-edit-link-' + id) == '0') {
    $('is-edit-link-' + id).value = '1';
    eval('var editorlink' + id + ' = new Ajax.InPlaceEditor(\'edit-link-'+ id + '\', \'/include/settings/link.php\', { callback: function(form, value) { return \'item=' + id + '&value=\' + escape(value) }});');
    eval('editorlink' + id + '.enterEditMode(\'click\')');
  }
}
function JS_loadEditor(page,ob) {
  if($F('is-edit-' + ob) == '0') {
    $('is-edit-' + ob).value = '1';
    eval('var editor' + ob + ' = new Ajax.InPlaceEditor(\'' + ob + '\', \'' + page + '\', { callback: function(form, value) { return \'item=' + ob + '&value=\' + escape(value) }});');
    eval('editor' + ob + '.enterEditMode(\'click\')');
  }
}
function JS_tabChange(tab,rub) {
  t = $(tab).getElementsByClassName('a-tab-selected');
  t[0].removeClassName('a-tab-selected');
  $(rub).addClassName('a-tab-selected');
}

function JS_menuMyrtille(name) {
  menumyr = document.getElementsByClassName('submenu');
  for(var im = 0; im < menumyr.length; im++) {
    if(menumyr[im].getAttribute('id') != 'mp-menu-' + name) {
      //menumyr[im].hide();
      new Effect.BlindUp(menumyr[im], {duration:0.2, fps: 100});
  		//$('mp-menu-' + name + '-upper').removeClassName('menu-on');
	 }
  }
  if($('mp-menu-' + name + '').visible()) {
  	new Effect.BlindUp($('mp-menu-' + name), {duration:0.2, fps: 100});
  	//$('mp-menu-' + name + '-upper').removeClassName('menu-on');
    //$('mp-menu-' + name + '').hide(); 
  } else { 
  	new Effect.BlindDown($('mp-menu-' + name), {duration:0.2, fps: 100});
  	//$('mp-menu-' + name + '-upper').addClassName('menu-on');
    //$('mp-menu-' + name + '').show();
  }
}
function JS_myrtillesearch(type) {
	$('request-typev').value = type;
	if(type == 2 ) {
    url = 'http://market.myrtille.com/search/mm_adssearch_form2.html';
  } else if(type == 3) {    
    url = 'http://market.myrtille.com/search/mm_spacesearch_form.html';
  } else {
    //url = 'http://pass.myrtille.com/search/';
    url = 'http://pass.myrtille.com/search/';
  }
	document.location.href = url + '?q=' + $F('request') + '&x=' + $F('request-type');
}
function JS_showhideother(a,b) {
  if($F(a) == 'other') { 
    alert($F(a));
    $(b).show();
  } else {
    $(b).hide();
  }
}
  if($('gmap')) {  
    var Gmap = null;
    var Ggeocoder = new GClientGeocoder();
    var Gcity = '';
    var Gzoom = 5;
  }
function Gload() {
  if (GBrowserIsCompatible()) {
    if($('gmap')) {
      Gmap = new GMap2($('gmap'));
      Gmap.setCenter(new GLatLng(0, 0), 13);
      GInitCity();
    }
  }
}

function initCity(city,zoom) {
  Gcity = city;
  Gzoom = zoom;
}
function GInitCity() {
  if(Gcity != '') {
    GshowAddress(Gcity);
  }
}
function GshowAddress(address) {
  if (!Ggeocoder) {
    var Ggeocoder = new GClientGeocoder();
  }
  Ggeocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        Gmap.setCenter(point, Gzoom);
        /*var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(address);*/
      }
    }
  );
}


function JS_subimg(f,sb) {
  f.submit();
  sb.value = 'Telechargement en cours...';
  //sb.disable();
}

function JS_sbscr() {
  var lbsb;
  lbsb = new lightbox($('sub-lb'));
  lbsb.activate();
}

function JS_checkAll(c) {
	cx = document.getElementsByClassName(c);
  for(j = 0; j < cx.length; j++) {
    cx[j].checked = true;
  }
}
function JS_uncheckAll(c) {
	cx = document.getElementsByClassName(c);
  for(j = 0; j < cx.length; j++) {
    cx[j].checked = false;
  }
}

function a(txt) {
  alert(txt);
}

function c(txt) {
  return confirm(txt);
}

function cc(txt, h) {
	if(confirm(txt)) {
		document.location.href = h;
	} else {
		return false;
	}
}

var myrtille_url = 'http://static.myrtille.com/img/pages/m25px-f.jpg';
var myrtille_url_over =	'http://static.myrtille.com/img/pages/m25px.jpg';
var myrtille_base_note = 'myrtille-note-';	
var lenght_myrtille_base_note = myrtille_base_note.lastIndexOf('');
var myrtille_note_exe = false;
function JS_myrtilleNote() { 
	if(!myrtille_note_exe) {
		for (i = 1; i < 6; i++) {
			var img	= $('myrtille-note-' + i);
			img.onclick	= function() { $('myrtille-note').value = (i - 1); JS_myrtilleUnNote(); };
			img.alt	= 'Donner la note de ' + i;
			img.src = myrtille_url;
			img.onmouseover	= function() {$('myrtille-note').value = i; JS_myrtilleOver(this.id);};
			img.onmouseout	= function() {JS_myrtilleOut(this.id);};
		}
		myrtille_note_exe = true;
	}
}
function JS_myrtilleNoteInit() {
		myrtille_note_exe = false;
}
function JS_myrtilleUnNote() { 
	if(myrtille_note_exe) {
		for (i = 1; i < 6; i++) {
			var img	= $('myrtille-note-' + i);
			img.onclick	= function() {myrtille_note_exe = false; JS_myrtilleNote(); };
			img.onmouseover	= function() {};
			img.onmouseout	= function() {};
		}
	}
}
function JS_myrtilleOver(m) {
	for (i = 1; i < (m.slice(lenght_myrtille_base_note) * 1) + 1; i++) {
		$('myrtille-note-'+i).src = myrtille_url_over;
	}
}

function JS_myrtilleOut(m) {
	for (i = 1; i < (m.slice(lenght_myrtille_base_note) * 1) + 1; i++) {
		$('myrtille-note-'+i).src = myrtille_url;
	}
}

function JS_initSearch() {
	if($F('q-search') == 'Rechercher un ami, une page, un groupe ...') {
		$('q-search').value = '';
	}
}

function JS_optionMod(n, i) {
  m = 'module-profil-' + n + '-option';
  if($(m).visible()) {
    new Effect.BlindUp(m, {duration:0.2, fps: 100});
    $('a-edtion-module-' + i).update('Editer');
  } else {
    new Ajax.Updater(m, '/ajax/mod-option.php?idappm=' + i, {
        onComplete: function () {
          new Effect.BlindDown(m, {duration:0.2, fps: 100}) 
        } 
    });
    $('a-edtion-module-' + i).update('Fermer edition');
  }
}

function JS_optionContent(n) {
  m = 'module-profil-' + n + '-content';
  if($(m).visible()) {
    new Effect.BlindUp(m, {duration:0.2, fps: 100});
    $('module-a-' + n).update('Ouvrir');
  } else {
    new Effect.BlindDown(m, {duration:0.2, fps: 100});
    $('module-a-' + n).update('Fermer');
  }
}

function JS_updateProfilMod(i, n, cx) {
  for(c = 2; c < 8; c++) {
    $('module-footer-border-' + i).removeClassName('c' + c);
    $('module-content-border-' + i).removeClassName('c' + c);
    $('module-header-' + i).removeClassName('bc' + c);
  }
  $('module-footer-border-' + i).addClassName('c' + n);
  $('module-content-border-' + i).addClassName('c' + n);
  $('module-header-' + i).addClassName('bc' + n);
  new Ajax.Request('/ajax/mod-optionsav.php?idappm=' + i + '&color=' + n, {
  method: 'get'});
  m = 'module-profil-' + cx + '-option';
  new Effect.BlindUp(m, {duration:0.2, fps: 100});
}
function JS_updateProfilL() {
  params = Sortable.serialize('profil-left', {tag: 'div'});
  new Ajax.Request('/ajax/mod-optionpsav.php', {
  parameters:  params,
  method: 'post'});
}

function JS_updateProfilR() {
  params = Sortable.serialize('profil-right', {tag: 'div'});
  new Ajax.Request('/ajax/mod-optionpsav.php', {
  parameters:  params,
  method: 'post'});
}

function JS_optionModG(n, i, gid) {
  m = 'module-profil-' + n + '-option';
  if($(m).visible()) {
    new Effect.BlindUp(m, {duration:0.2, fps: 100});
    $('a-edtion-module-' + i).update('Editer');
  } else {
    new Ajax.Updater(m, '/ajax/group/mod-option.php?idappm=' + i + '&gid=' + gid + '&n=' + n, {
        onComplete: function () {
          new Effect.BlindDown(m, {duration:0.2, fps: 100}) 
        } 
    });
    $('a-edtion-module-' + i).update('Fermer edition');
  } 
}

function JS_updateProfilModG(i, n, cx, gid) {
  for(c = 2; c < 8; c++) {
    $('module-footer-border-' + i).removeClassName('c' + c);
    $('module-content-border-' + i).removeClassName('c' + c);
    $('module-header-' + i).removeClassName('bc' + c);
  }
  $('module-footer-border-' + i).addClassName('c' + n);
  $('module-content-border-' + i).addClassName('c' + n);
  $('module-header-' + i).addClassName('bc' + n);
  new Ajax.Request('/ajax/group/mod-optionsav.php?idappm=' + i + '&color=' + n + '&gid=' + gid, {
  method: 'get'});
  m = 'module-profil-' + cx + '-option';
  new Effect.BlindUp(m, {duration:0.2, fps: 100});
  $('a-edtion-module-' + i).update('Editer');
}
function JS_updateProfilLG() {
  params = Sortable.serialize('profil-left', {tag: 'div'});
  //alert('/ajax/group/mod-optionpsav.php' + params + '&gid=' + $F('gid'));
  new Ajax.Request('/ajax/group/mod-optionpsav.php', {
  parameters:  params + '&gid=' + $F('gid'),
  method: 'get'});
}
 
function JS_updateProfilRG() {
  params = Sortable.serialize('profil-right', {tag: 'div'});
  //alert('/ajax/group/mod-optionpsav.php' + params + '&gid=' + $F('gid'));
  new Ajax.Request('/ajax/group/mod-optionpsav.php', {
  parameters:  params + '&gid=' + $F('gid'),
  method: 'get'});
}


function JS_overTemplate(i) {
  $('template-' + i).addClassName('template-over');
}
function JS_outTemplate(i) {
  $('template-' + i).removeClassName('template-over');
}
function JS_changeTemplate(c) {
  t = document.getElementsByClassName('template-select');
  for(i = 0; i < t.length; i++) {
    t[i].removeClassName('template-selected');
  }
  $('template-' + c).addClassName('template-selected');
  
  new Ajax.Updater('update-template', '/ajax/template.php', {
  parameters:  {'template': c},
  method: 'get'});
}
function JS_changeTemplateG(c, gid) {
  t = document.getElementsByClassName('template-select');
  for(i = 0; i < t.length; i++) {
    t[i].removeClassName('template-selected');
  }
  $('template-' + c).addClassName('template-selected');
  
  new Ajax.Updater('update-template', '/ajax/group/template.php', {
  parameters:  {'template': c, 'gid' : gid},
  method: 'get'});
}
function JS_addMComment(uid) {
  new Ajax.Updater('module-content-11', '/ajax/mod-comment.php', {
  parameters: $('form-MComment').serialize() + '&uid=' + uid});
}

function JS_pMComment(uid, p) {
  new Ajax.Updater('module-content-11', '/ajax/mod-comment.php', {
  parameters: 'p=' + p + '&uid=' + uid});
}
function JS_pMCommentG(gid, p) {
  new Ajax.Updater('module-content-11', '/ajax/group/mod-comment.php', {
  parameters: 'p=' + p + '&gid=' + gid});
}

function JS_addMCommentG(gid) {
  new Ajax.Updater('module-content-11', '/ajax/group/mod-comment.php', {
  parameters: $('form-MGComment').serialize() + '&gid=' + gid,
  method: 'get'});
}

function JS_pMCommentG(gid, p) {
  new Ajax.Updater('module-content-11', '/ajax/group/mod-comment.php', {
  parameters: 'p=' + p + '&gid=' + gid,
  method: 'get'});
}
 
function JS_updateStatut() {  
    new Ajax.Updater('feed-statut-update', '/ajax/statut.php?value=' + $F('vstatut'), {
        method: 'get'
      });
}
function JS_clearStatut() {
  if($F('vstatut') == 'Dites ce que vous faites !') { 
    $('vstatut').value = '';
  }
}
