/* Library */

String.prototype.trim = function()
{
  return this.replace(/^\s*|\s*$/g, '');
};

function Email()
{
  this.check = function(str)
  {
    var regexpobj = new RegExp('^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$', '');
    return regexpobj.test(str);
  };
}

function changeImage(imageobj, image)
{
  imageobj.src = image;
  return true;
}

function preloadImage(image)
{
  var imageobj = new Image();
  imageobj.src = image;
}

function showPopup(html, left, top, width, height, resizable, scrollbars)
{
  var windowobj = new Object();
  if ((html.substr(html.length - 4, 4).toLowerCase() == '.htm') || (html.substr(html.length - 5, 5).toLowerCase() == '.html'))
    windowobj = window.open(html, '', 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',resizable=' + ((resizable == true) ? 'yes' : 'no') + ',scrollbars=' + ((scrollbars == true) ? 'yes' : 'no'));
  else
  {
    windowobj = window.open('', '', 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',resizable=' + ((resizable == true) ? 'yes' : 'no') + ',scrollbars=' + ((scrollbars == true) ? 'yes' : 'no'));
    windowobj.document.open();
    windowobj.document.write(html);
    windowobj.document.close();
  }
  windowobj.focus();
}

function showPicture(title, css, picture, width, height)
{
  var html;
  html = '<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n';
  html += '<html>\n';
  html += '  <head>\n';
  html += '    <title>' + title + '</title>\n';
  html += '    <link rel=\"stylesheet\" href=\"' + css + '\" type=\"text/css\">\n';
  html += '  </head>\n';
  html += '  <body style=\"margin: 0px\">\n';
  html += '    <img src=\"' + picture + '\" alt=\"\" border=\"0\" width=\"' + width + '\" height=\"' + height + '\">\n';
  html += '  </body>\n';
  html += '</html>\n';
  if ((width > (screen.availWidth - 12)) || (height > (screen.availHeight - 31)))
    showPopup(html, 0, 0, width, height, true, true);
  else
    showPopup(html, (screen.availWidth - width) / 2, (screen.availHeight - height) / 2, width, height, false, false);
}

/* Routines */

var divobj = new Object();

var t;

function preloadImages()
{
  if (document.images != null)
  {
    preloadImage('images/home.gif');
    preloadImage('images/homed.gif');
    preloadImage('images/address.gif');
    preloadImage('images/addressd.gif');
    preloadImage('images/menu.gif');
    preloadImage('images/menud.gif');
    preloadImage('images/humor.gif');
    preloadImage('images/humord.gif');
    preloadImage('images/pictures.gif');
    preloadImage('images/picturesd.gif');
    preloadImage('images/reservation.gif');
    preloadImage('images/reservationd.gif');
  }
}

function setInputColor(inputobj, focus)
{
  if (focus == true)
    inputobj.style.background = '#ffaaaa';
  else
    inputobj.style.background = '#ffdddd';
}

function check(text)
{
  if (confirm(text) == true)
    window.location = "reservation.html";
  else
    window.location = "mailto:info@dewaterput.com";
}

function loadingMap()
{
  var div2obj = new Object();
  div2obj = document.createElement('div');
  div2obj.innerHTML = t;
  div2obj.style.color = '#777777';
  div2obj.style.fontWeight = 'bold';
  divobj.insertBefore(div2obj, divobj.firstChild);
}

function loadMap(text, map, satellite, hybrid, browser)
{
  var glatlngobj = new Object();
  var gmap2obj = new Object();
  divobj = document.getElementById('map');
  if (GBrowserIsCompatible() == true)
  {
    gmap2obj = new GMap2(divobj);
    t = text;
    GEvent.addListener(gmap2obj, 'load', loadingMap);
    gmap2obj.enableScrollWheelZoom();
    gmap2obj.setCenter(new GLatLng(51.26924, 3.26090), 13);
    gmap2obj.addOverlay(new GMarker(gmap2obj.getCenter()));
    gmap2obj.addControl(new GLargeMapControl());
    gmap2obj.addControl(new GMapTypeControl());
    gmap2obj.addControl(new GScaleControl());
    G_NORMAL_MAP.getName = function() { return map; };
    G_SATELLITE_MAP.getName = function() { return satellite; };
    G_HYBRID_MAP.getName = function() { return hybrid; };
  }
  else
    window.alert(browser);
}

function showMap(html, width, height)
{
  showPopup(html, (screen.availWidth - width) / 2, (screen.availHeight - height) / 2, width, height, false, false);
}

function isValidReservation(warning, emailwarning)
{
  var emailobj = new Email();
  var str;
  str = '';
  if (reservation.fullname.value.trim().length == 0)
  {
    reservation.fullname.focus();
    str = warning;
  }
  else if (reservation.phone.value.trim().length == 0)
  {
    reservation.phone.focus();
    str = warning;
  }
  else if (emailobj.check(reservation.email.value) == false)
  {
    reservation.email.focus();
    str = emailwarning;
  }
  else if (reservation.message.value.trim().length == 0)
  {
    reservation.message.focus();
    str = warning;
  }
  if (str.length > 0)
  {
    window.alert(str);
    return false;
  }
  else
    return true;
}

function submitReservation(warning, emailwarning)
{
  if (isValidReservation(warning, emailwarning) == true)
    reservation.submit();
}

