var relative_path = '/';

// Email address toggle
Event.observe(window, 'load', function() {
  if($('maillist')) {
    Event.observe('maillist', 'focus', function() {
      $('maillist').value = ($F('maillist')=='e-mailadres'?'':$F('maillist'));
    });
    Event.observe('maillist', 'blur', function() {
      $('maillist').value = ($F('maillist')==''?'e-mailadres':$F('maillist'));
    });
  };
});

// Hides sidebar and enlarges map
function map_enlarge() {
  $('sidebar').hide(); // hide sidebar
  $('main').addClassName('enlarged'); // enlarge main
  $('map').addClassName('enlarged'); // enlarge map
  $('map_enlarge').hide();
  $('map_unlarge').show();
  map.checkResize(); // adjust map
}

// Reverses the process above
function map_unlarge() {
  $('map').removeClassName('enlarged');
  $('main').removeClassName('enlarged');
  $('sidebar').show();
  $('map_unlarge').hide();
  $('map_enlarge').show();
  map.checkResize();
}

function checkform(){
  var err = false;
  var req = document.getElementsByClassName('required');
  req.each(function(o) {
    if(o.match('input') || o.match('textarea')) {
      if(o.getValue().strip().empty()) {
        o.setStyle({backgroundColor:'#FFA500'});
        Event.observe(o, 'focus', function(){
          o.setStyle({backgroundColor:''});
        });
        err = true;
      }
    }
  });
  if(err) {
    alert('Vul alle velden in waarvoor een * staat.');
    return false;
  }
  return true;
}

function new_captcha() {
	thesrc = document.getElementById("captcha").src;
	thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
	document.getElementById("captcha").src = thesrc+"?"+Math.round(Math.random()*100000);
}


// Submit comment
function comment_submit() {
  $('comment_submit').update('<img src="'+relative_path+'img/ajax-loader.gif" width="16" height="16" />');
  new Ajax.Updater('div_newcomment', relative_path+'ajax/comment.php?do=comment', {parameters: $('form_newcomment').serialize(true)});
}

// Submit comment
function captcha_submit() {
  $('captcha_submit').update('<img src="'+relative_path+'img/ajax-loader.gif" width="16" height="16" />');
  new Ajax.Updater('div_newcomment', relative_path+'ajax/comment.php?do=captcha', {parameters: $('form_newcomment').serialize(true)});
}

// Fetch set of entry pictures
function entry_pictures_show(pid, page) {
  $('entrypictures').addClassName('being_ajaxed');
  new Ajax.Updater('entrypictures', relative_path+'ajax/ajaxcalls.php?action=showentrypictures&pid='+escape(pid)+'&page='+escape(page), {onComplete:function(){
    $('entrypictures').removeClassName('being_ajaxed');
  }});
}

// Log pageview
Event.observe(window, 'load', function() {
  new Ajax.Request(relative_path + 'ajax/ajaxcalls.php?action=logpageview', {
    parameters: {
      'url' : document.location.href, 
      'referer' : document.referrer
    }
  });
});
