var map;
var point;
var marker;
var html;

window.onload = initPage;

function initPage() {
  externalLinks();
  if(document.getElementById('map')) {
    load();
  }
  
  if(document.getElementById('contact_email')){
    var onC="cleanField('contact_email', false)"; 
    document.getElementById('contact_email').onclick = new Function(onC);
  } 
  
  if (document.getElementById('newsletter_submit')) {
    var onC="enquireNowSubmit();";
    document.getElementById('newsletter_submit').onclick = new Function(onC);
  }

}

function cleanField(id, submit) {
    var field = document.getElementById(id);
    
    if (submit == false) {
        if (document.getElementById('contact_email').value == '') {
            document.getElementById('contact_email').value = 'Enter your email address:';
        }
    }
    
    if (id == 'contact_email' && field.value == 'Enter your email address:') {
        field.value = '';
    }
}

function enquireNowSubmit() {
  cleanField('contact_email', true);
}


function display_flash() {
 
  document.write('<object type="application/x-shockwave-flash" data="flash/slide.swf" width="756" height="205"><param name="movie" value="flash/slide.swf" /></object>');
 
}

function image_popup(image) {

  var image = image;
  var newLink = image.replace("main", "large");

  window.open(newLink,"","width=1024,height=768,location,menubar");
  
}

function go_to_full_booking() {

  window.location = 'index.php?view=book-online'; return true;

}

function externalLinks() { 
  if (!document.getElementsByTagName) return; 
  var anchors = document.getElementsByTagName("a"); 
  for (var i=0; i<anchors.length; i++) { 
    var anchor = anchors[i]; 
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "external nofollow" ) 
      anchor.target = "_blank"; 
    } 
}

function load() {
  if (GBrowserIsCompatible()) {
    var html = document.getElementById('cont').innerHTML;
    html = html.replace('linkname','linkname2');
    html = html.replace('getDirToggle','getDirToggle2');  
    
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(51.51511242117285, -0.1912522315979004), 16);
    point = new GLatLng(51.51511242117285, -0.1912522315979004);
    marker = new GMarker(point);
    map.addOverlay(marker)
    map.openInfoWindowHtml(map.getCenter(), html);
    
    GEvent.addListener(marker, "click", function() {  
      map.openInfoWindowHtml(point, html);
    });
  }
}
function prepareForm(form, cid){
  if (GBrowserIsCompatible()) {
    gApplication.prepareForm(form, cid);
  }
}

function displayDir(){    
  if (GBrowserIsCompatible()) {  
    var toggle = document.getElementById("getDirToggle").style.display;
    if(toggle == 'none'){      
      document.getElementById("getDirToggle").style.display='block';
      document.getElementById("linkname").innerHTML = "Don't get directions";      
    }else{
        document.getElementById("getDirToggle").style.display='none';
        document.getElementById("linkname").innerHTML = "Get directions";
  }
    
    var html = document.getElementById('cont').innerHTML;
    html = html.replace('linkname','linkname2');
    html = html.replace('getDirToggle','getDirToggle2');      
    map.openInfoWindowHtml(point, html);
  }
}

function toggle(id) {
  
  var testimonial;

  testimonial = document.getElementById('testimonial_'+id+'_short').style.display;

  if(testimonial == 'none') {
    document.getElementById('testimonial_'+id+'_short').style.display = 'block';
    document.getElementById('testimonial_'+id+'_full').style.display = 'none';
  } else {
    document.getElementById('testimonial_'+id+'_short').style.display = 'none';
    document.getElementById('testimonial_'+id+'_full').style.display = 'block';
  }
}