
	function sleep(seconds) {
	    // http://kevin.vanzonneveld.net
	    // +   original by: Christian Doebler
	    // +   bugfixed by: Brett Zamir
	    // %          note: For study purposes. Current implementation could lock up the user's browser. 
	    // %          note: Consider using setTimeout() instead.
	    // *     example 1: sleep(1);
	    // *     returns 1: 0
	    
	    var start = new Date().getTime();
	    while (new Date() < start + seconds*1000);
	    return 0;
	}
	
	function getScrollXY() {
		var scrOfX = 0, scrOfY = 0;
	
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return [ scrOfX, scrOfY ];
	}

	
	 //
    //  getPageSize()
    //
   function  getPageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}



	function close_postcard(){
		
		over_opacity = 0.6;
		
		$('postcard').fade( {
			duration: 1.0
		}); 
		sleep(0.5);
		$('overlay_post').fade( {
			duration: 0.1,
			from: over_opacity,
			to: 0
		}); 
		
		return false;
	}




	

	function open_postcard(){
		
		//Gästebuch Formular abrufen und einbetten
		
		
		//var url = "http://localhost/seebestattung/js/guestbook.html";
		var url = "http://www.rostock-seebestattung.de/js/guestbook.html";

		/*new Ajax.Request(url, {
		  method:'get',
		 
		  
		  onComplete: function(transport){
      		var response = transport.responseText || "no response text";
      		alert("Success! \n\n" + response);
			
			
			$('postcard').innerHTML = response;
			
			
			
			}*/
			
			
		  
      new Ajax.Request("js/guestbook.html", {
  
                 method: "post",
		         parameters: 'id=2',
 
                 onComplete: function(transport){
					var response = transport.responseText || "no response text";
      				//alert("Success! \n\n" + response); 
					
					$('postcard').innerHTML = response;
				 }
   				
                 }); 
			
			
		
		
		
		
		
		
		
		
		
		//overlay_post-Opacity
		
		over_opacity = 0.6;
		
		
		// stretch overlay_post to fill page and fade in
    	var arrayPageSize = getPageSize();
    	$('overlay_post').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
		
		
		
		//erscheine !!!
		
		$('overlay_post').appear( {
			duration: 0.1,
			from: 0,
			to: over_opacity
		}); 
		
		sleep(0.5);
		
		$('postcard').appear( {
			duration: 1.0
		}); 
		return false;
		
	}
	
	
	
	
	function guestbook_view(){
		if ($('overlay_post').style.display != 'none') {
			
			var scroll = getScrollXY();
		
		
			var overlay_post 	= scroll[1];
			var postcrad 	= scroll[1] + 125;
			
			$('overlay_post').style.top 	= overlay_post + 'px';
			$('postcard').style.top = postcrad + 'px';
		
		}
	}
	
	
	function data_proof(){
		
		var name 	= document.getElementById("name").value;
		var email	= document.getElementById("email").value;
		var text	= document.getElementById("text").value;
		var captcha	= document.getElementById("captcha").value;
		
		
		if(name == ""){
			document.getElementById("name").style.borderColor = "#ff0000";
			//document.getElementById("name").style.color = "#ff0000";
			document.getElementById("name").value = "Bitte geben Sie Ihren Namen ein!";
			document.getElementById("name").focus();
			var result = "false";
		}
		if(email == ""){
			document.getElementById("email").style.borderColor = "#ff0000";
			//document.getElementById("email").style.color = "#ff0000";
			document.getElementById("email").value = "Bitte geben Sie Ihre E-Mailadresse ein!";
			document.getElementById("email").focus();
			var result = "false";
		}
		if(text == ""){
			document.getElementById("text").style.borderColor = "#ff0000";
			//document.getElementById("text").style.color = "#ff0000";
			//document.getElementById("text").focus();
			var result = "false";
		}
		if(captcha == ""){
			document.getElementById("captcha").style.borderColor = "#ff0000";
			document.getElementById("captcha").style.color = "#ff0000";
			document.getElementById("captcha").value = "Sicherheitscode!";
			document.getElementById("captcha").focus();
			var result = "false";
		}
		
		if(result != "false"){
			eintrag_senden();
		}
	}
	
	function eintrag_senden(){
		
		//var url = 'http://localhost/seebestattung/doc/guestbook_insert.php';
		
		var url = "doc/guestbook_insert.php";
		// notice the use of a proxy to circumvent the Same Origin Policy.


		
		var name 	= document.getElementById("name").value;
		var email	= document.getElementById("email").value;
		var text	= document.getElementById("text").value;
		var captcha	= document.getElementById("captcha").value;

		
	
		
		
		
		
		

		new Ajax.Request(url, {
		  
		  
		  //method:'post',
		  //parameters: {name: name, email: email, captcha: captcha, text: text, neu: 'neu'},
		  
		  method: 'post',
      	  //requestHeaders: ['Content-Type', 'text/html', 'Cache-Control', 'no-cache, must-revalidate'],
          parameters: {name: name, email: email, captcha: captcha, text: text, neu: 'neu'},
		  
		  onSuccess: function(transport){
      		var response = transport.responseText || "no response text";
      		//alert("Success! \n\n" + response);
			
			if(response == "error"){
				$('info').innerHTML = 'Ihr Eintrag konnte leider nicht vorgenommen werden.<br />Bitte versuchen Sie es noch einmal.';
				var timeout = 2000;
			}
			else {
				$('info').innerHTML = 'Ihr Eintrag wurde vorgenommen.';
				var timeout = 1000;
			}
			
			
		    
			over_opacity = 0.6;
		
			$('postcard').fade( {
				duration: 1.0
			}); 	
			
			$('info').appear( {
				duration: 1.0
			}); 	
			
			setTimeout("location.reload()", timeout);
			
			return false;
			
			
			
			//close_postcard();
			
    		},
    		onFailure: function(){ alert('Something went wrong...') }
		    //mach was
	
		  });
		
	}

