

function done(){

  	var elem = $('splash');
	if (elem == null) return true;
	var elem = $('splashbg');
	if (elem == null) return true;
  	var elem = $('alert');
	if (elem == null) return true;

  $("alert").remove();
  $("splashbg").toggle();
  $("splash").toggle();
}

function show(){

  var elem = $('splash');
  if (elem == null) return true;
  var elem = $('splashbg');
  if (elem == null) return true;

  var h=document.viewport.getHeight();
  var w=document.viewport.getWidth();
  var scroll=document.viewport.getScrollOffsets();
  var wh=document.body.offsetHeight;
  document.getElementById("splashbg").style.height = wh + "px";
  document.getElementById("splashbg").style.width = w + "px";

  var imgh= scroll.top + ((h/2)- ($("splash").getHeight()/2));
   document.getElementById("splash").style.marginTop = imgh+"px";
  var imgh= 0 ;
  var imgw= scroll.left + ((w/2)- ($("splash").getWidth()/2));

  $("splash").setStyle("top:"+imgh+"px;");
  $("splash").setStyle("left:"+imgw+"px;");
  $("splashbg").show();
  $('splashbg').setOpacity(0.7);
  $("splash").toggle();
}



function newsletter() {

	var elem = $('splash');
	if (elem == null) return true;
	var elem = $('splashbg');
	if (elem == null) return true;
	var elem = $('newsletter');
	if (elem == null) return true;

	var elem = $('absenden');
	if (elem == null) return true;

  $("splash").toggle();
  Event.observe('newsletter', 'submit', function(event) {
	  Event.stop(event);
  });

  Event.observe('absenden', 'click', function(event) {

	  var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	  if (!$F("email").match(emailRegEx) && $F("name")=="Ihr Name")  {
		  Element.insert( $('splash'), '<div id="alert"><h1>Geben Sie Bitte eine korrekte E-Mail Adresse und Ihren Namen ein.</h1><br /><br /><a href="javascript:done()" id="schliessen">Schliessen / Close</a><br /></div>');
			show();
			return false;
	  }

	  if (!$F("email").match(emailRegEx)) {
		    Element.insert( $('splash'), '<div id="alert"><h1>Geben Sie Bitte eine korrekte E-Mail Adresse ein.</h1><br /><h1>Invalid email address format, please try again.</h1><br /><br /><a href="javascript:done()" id="schliessen">Schliessen /Close</a><br /></div>');
			show();
			return false;
	  }

	  if ($F("name")=="Ihr Name") {
		  Element.insert( $('splash'), '<div id="alert"><h1>Geben Sie Bitte Ihren Name an.</h1><br /><h1>Name required, please try again.</h1><br /><br /><a href="javascript:done()" id="schliessen">Schliessen / Close</a><br /></div>');
		  show();
		  return false;
	  }

	  $('newsletter').request({
		  onComplete: function(){
			Element.insert( $('splash'), '<div id="alert"><h1>Danke für Ihre Anmeldung.</h1><br /><h1>Thank You! - You have successfuly signed up for the newsletter.</h1><br /><br /><a href="javascript:done()" id="schliessen">Schliessen / Close</a><br /></div>');
			  show();
			  return true;
		  }
	  });


  });

}

document.observe("dom:loaded",newsletter);

