/**********************************************
/	Funktionen zum Scrollen
**********************************************/

var ScrollBox;
var ScrollCont;
var clipHeight;
var referencePos = 1;


function scrollInit(){
	if ( document.getElementById('ScrollContainer') ){
		ScrollBox = document.getElementById('ScrollText');
		ScrollCont = document.getElementById('ScrollContainer');
		clipHeight = ScrollCont.offsetHeight;
		scrollHeight = ScrollBox.offsetHeight;
		new Effect.Move(document.getElementById('ScrollText'), {x: 0, y: 0 , mode: 'absolute'});
	}
}


function scrollDown(){
	var pos_y = parseInt( ScrollBox.style.top , 10 );
	if ( (2 * clipHeight - pos_y ) < scrollHeight ){
		move_y = pos_y - clipHeight;
	}
	else{
		move_y = clipHeight - scrollHeight;
	}
	new Effect.Move(document.getElementById('ScrollText'), {x: 0, y: move_y , mode: 'absolute'});return false;
}

function scrollUp(){
	var pos_y = parseInt( ScrollBox.style.top , 10 );
	if ( (pos_y + clipHeight) < 0 ){
		move_y = pos_y + clipHeight;
	}
	else{
		move_y = 0;
	}
	new Effect.Move(document.getElementById('ScrollText'), {x: 0, y: move_y , mode: 'absolute'});
}

function reference(pos){
	document.getElementById('reference_' + referencePos).className = "";
	referencePos = parseInt( pos , 10 );
	document.getElementById('reference_' + referencePos).className = "selected";
	if ( (referencePos - 6) > 0 ) {

		if ( (referenceMax - referencePos) < 5 ) move_y = ( 11 - referenceMax ) * 16;
		else move_y = ( 6 - pos ) * 16;
		new Effect.Move(document.getElementById('ScrollList'), {x: 0, y: move_y , mode: 'absolute'});
	}
	else{
		new Effect.Move(document.getElementById('ScrollList'), {x: 0, y: 0 , mode: 'absolute'});
	}

	move_y = ( 1 - pos ) * clipHeight;
	new Effect.Move(document.getElementById('ScrollText'), {x: 0, y: move_y , mode: 'absolute'});
	return false;
}

function referenceUp(){
	if ( referencePos > 1 ) {
		reference( referencePos - 1 );
	}
	return false;
}

function referenceDown(){
	if ( referencePos < referenceMax ){
		reference( referencePos + 1 );
	}
	return false;
}

/**
* Reguläre Ausdrücke zum Testen von Formulareingaben
*/
exprFon = /^[0-9\(\)\-\/\s]+$/;
exprEmail = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([a-z]{2,3}))$/;
exprNotEmpty = /.+/;

function ContactForm(){

	var arrayPageSize = getPageSize();

	$('ContactFormOverlay').setStyle({ height: arrayPageSize[1] + 'px' });

	var arrayPageScroll = document.viewport.getScrollOffsets();
	var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	$('ContactFormBox').setStyle({ top: Top + 'px' });

	Effect.Appear( 'ContactFormOverlay' , { from: 0, to: 0.8 , duration: 1, afterFinish: function() { Effect.BlindDown('ContactFormBox',{duration:1.0}) } } );

	$('ContactFormOverlay').onclick = hideContactForm;

  var myAjax = new Ajax();
  myAjax.url = "/ajax.php5";
  myAjax.params = "mode=kontaktformular";
  myAjax.method = 'get';

	myAjax.onSuccess=function(txt) {
		if ( HasError( txt ) ) {
			ErrorHandler( GetError(txt) );
		}
		else{
			$( 'ContactFormBox' ).innerHTML = txt;
			$( 'nachricht' ).focus();
		}
	}

  myAjax.onError=function(msg) {
    alert(msg);
  }

  myAjax.doRequest();

	return false;

}


function hideContactForm(){
	$( 'ContactFormBox' ).innerHTML = "";
	Effect.BlindUp( 'ContactFormBox' , { duration: 1.0, afterFinish: function() { Effect.Fade( 'ContactFormOverlay' , { from: 0.7, to: 0 , duration: 0.5 } ) } } );
}

function sendMail( f ){

	if ( ! ( exprNotEmpty.exec($("name").value ) ) ){
		alert("Bitte geben Sie Ihren Namen ein.");
		$("name").focus();
		return false;
	}

	if ( ! ( exprEmail.exec($("email").value ) ) ){
		alert("Bitte geben Sie eine gültige E-Mailadresse ein.");
		$("email").focus();
		return false;
	}

	paramArray = new Array();
	paramArray = paramArray.concat( getFormValues( f , 'input' ) );
	paramArray = paramArray.concat( getFormValues( f ,  'textarea' ) );

	var myAjax = new Ajax();
	myAjax.url = "/ajax.php5";
	myAjax.params = paramArray.join("&")
	myAjax.method = 'post';

	myAjax.onSuccess = function(txt) {
		if ( HasError( txt ) ) {
			ErrorHandler( GetError(txt) );
		}
		else{
			$( 'ContactFormBox' ).innerHTML = txt;
		}
	}

	myAjax.onError = function(msg) {
		alert(msg);
	}

	myAjax.doRequest();

	return false;

}


/**
*
*/
function getPosition( element ){
  var tagname="" , x=0 , y=0;
  while ( ( typeof(element) == "object" ) && ( typeof( element.tagName ) != "undefined" ) ){
    y += element.offsetTop;
    x += element.offsetLeft;
    tagname = element.tagName.toUpperCase();
    if ( ( tagname == "BODY" ) || ( tagname == "HTML" ) )  element=0;
    if ( typeof( element ) == "object" ){
      if ( typeof( element.offsetParent ) == "object" ) element = element.offsetParent;
      if ( element == null ) element=0;
    }
  }
  position=new Object();
  position.x=x;
  position.y=y;
  return position;
}

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;
	}

	pageHeight = yScroll;

	pageWidth = xScroll;

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}




