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

var speed = 5
var loop, timer

function makeObj( obj ){
	this.el = document.getElementById( obj );
 	this.css = document.getElementById( obj ).style;
	this.scrollWidth = this.el.offsetWidth
	this.clipWidth = this.el.offsetWidth
	this.left = goLeft
	this.right = goRight;
	this.moveIt = moveIt
	this.x = 0
	this.y = 0;
  this.obj = obj + "Object"
  eval(this.obj + "=this")
  return this
}

var px = window.opera ? "" : "px";

function moveIt(x,y){
	this.x = x
	this.y = y
	this.css.left = this.x + px
	this.css.top = this.y + px
}

function goRight(step){
	if ( this.x > - this.scrollWidth + oCont.clipWidth ){
		this.moveIt( this.x - step , 0 )
		if (loop) setTimeout( this.obj + ".right(" + step + ")" , speed )
	}
}

function goLeft(step){
	if ( this.x < 0 ){
		this.moveIt( this.x - step , 0 )
		if (loop) setTimeout( this.obj + ".left(" + step + ")" , speed )
	}
}

function scroll(speed){
	if (scrolltextLoaded){
		loop = true;
		if ( speed > 0 ) oScroll.right(speed)
		else oScroll.left(speed)
	}
}

function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}

function scrollInit(){
	oCont = new makeObj('scrollContainer')
	oScroll = new makeObj('scrollBox')
	oScroll.moveIt( 0 , 0 )
	scrolltextLoaded = true
}


/**
* 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 sendMail( f ){
	
  if ( ! ( exprNotEmpty.exec(document.getElementById("name").value ) ) ){
    alert("Bitte gib Deinen Namen ein.");
    document.getElementById("name").focus();
    return false;
  }

  if ( ! ( exprEmail.exec(document.getElementById("email").value ) ) ){
    alert("Bitte gib eine gültige Emailadresse ein.");
    document.getElementById("email").focus();
    return false;
  }
  
	Effect.Appear( 'sendMail' , { duration: 0.5 , beforeStart: function() { hideChilds('sendMail') } , afterFinish: function(){ showChilds('sendMail') } } );
	
	paramArray = new Array();
	paramArray = paramArray.concat( getFormValues( f , 'input' ) );
	paramArray = paramArray.concat( getFormValues( f ,  'textarea' ) );

  var myAjax = new Ajax();
  myAjax.url = "/ajax.php";
  myAjax.params = paramArray.join("&")
  myAjax.method = 'post';
  
  myAjax.onSuccess=function(txt) {
  	document.getElementById( 'sendMail' ).innerHTML = txt;
  }
  
  myAjax.onError=function(msg) {
    alert(msg);
  }
  
  myAjax.doRequest();
  
	return false;
  
}

function showProduktdetails( uid ){
	
	if ( navigator.appName == "Microsoft Internet Explorer") {
	  var Version = /(MSIE 6)/g;
		if ( ( Version.test( navigator.appVersion ) ) == true ) return true;
	}

	document.getElementById( 'ProduktdetailsBoxHL' ).innerHTML = "Produktdetails";
	document.getElementById("msgBox").style.position = "fixed";

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

	var size = getPageSize()
 	document.getElementById( 'ProduktdetailsScrollBox' ).style.height = (size[3] - 140) + "px";
	
  var myAjax = new Ajax();
  myAjax.url = "/ajax.php";
  myAjax.params = "action=detail&uid=" + uid;
  myAjax.method = 'get';
  
  myAjax.onSuccess=function(txt) {
  	document.getElementById( 'ProduktdetailsScrollBox' ).innerHTML = txt;
  }
  
  myAjax.onError=function(msg) {
    alert(msg);
  }
  
  myAjax.doRequest();
  
	return false;

}

function orderItem( uid ){

	if ( navigator.appName == "Microsoft Internet Explorer") {
	  var Version = /(MSIE 6)/g;
		if ( ( Version.test( navigator.appVersion ) ) == true ) return true;
	}

  var myAjax = new Ajax();
  myAjax.url = "/ajax.php";
  myAjax.params = "action=order_item&uid=" + uid;
  myAjax.method = 'get';

  myAjax.onSuccess=function(txt) {
  	document.getElementById( 'ProduktdetailsScrollBox' ).innerHTML = txt;
		document.getElementById( 'ProduktdetailsBoxHL' ).innerHTML = "Reservierungsanfrage";
		document.getElementById( 'name' ).focus();
  }

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

  myAjax.doRequest();

	return false;

}

function sendOrderItem( form ){

  if ( ! ( exprNotEmpty.exec(document.getElementById("name").value ) ) ){
    alert("Bitte gib Deinen Namen ein.");
    document.getElementById("name").focus();
    return false;
  }
  if ( ! ( exprEmail.exec(document.getElementById("email").value ) ) && ! ( exprFon.exec(document.getElementById("fon").value ) ) ){
    alert("Bitte gib eine gültige Emailadresse oder eine Telefonnumer ein.");
    document.getElementById("email").focus();
    return false;
  }
  if ( ! document.getElementById("agb").checked ){
    alert("Bitte lesen Sie die Kundeninformationen und die AGBs und stimmen Sie diesen zu.");
    return false;
  }

	pa = getFormValues(form , "input");
	request("/ajax.php", pa, "post", "ProduktdetailsScrollBox" );
	return false;
}

function request( url , paramArray , method , target ){
  var myAjax = new Ajax();
  myAjax.url = url;
  //alert(paramArray.join("&"));
  myAjax.params = paramArray.join("&")
  myAjax.method = method;

  myAjax.onSuccess=function(txt) {
    if (HasError(txt)) {
    	myAjax.onError(GetError(txt));
      return null;
    } else {
	    document.getElementById( target ).innerHTML = txt;
    }
  }

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

  myAjax.doRequest();
}


function getFormValues( f , tag ){
	var anzahl = f.getElementsByTagName( tag ).length;
	var param_array = new Array();
	for ( i=0 ; i < anzahl ; i++ ){
		var name = f.getElementsByTagName( tag )[i].name;
		var value = f.getElementsByTagName( tag )[i].value;
		param_array.push( name + "=" + encodeURIComponent( value ) );
	}
	return param_array;
}

//Überprüft Rückgabe eines PHP-Skripts, ob es eine Fehlermeldung ist
function HasError(msg)
{
  //Hat msg einen Inhalt?
  if (!msg) return false;

  //Befindet sich Zeichenkette AOERROR: am Anfang von msg?
  if (msg.indexOf("ERROR:") == 0) {
    return true;
  } else {
    return false;
  }
}

function GetError(msg)
{
  //ERROR: aus Fehlermeldung entfernen
  return msg.replace(/ERROR:/, "");
}

//Allgemeine Funktion für alle Fehlerfälle
function ErrorHandler(msg)
{
  //Fehler als Meldungsfenster anzeigen
  alert(msg);
}










function hideProduktdetails(){
	hideMsg();
	document.getElementById("msgBox").style.position = "absolute"; 
	Effect.BlindUp( 'ProduktdetailsBox' , { duration: 1.0, afterFinish: function() { Effect.Fade( 'pd_overlay' , { from: 0.7, to: 0 , duration: 0.5 , afterFinish: function() { document.getElementById( 'ProduktdetailsScrollBox' ).innerHTML = "" } } ) } } );
}

/**
* 
*/
function showMsg( element , text ){
	document.getElementById("msgBoxText").innerHTML = text;
	pos = getPosition( element );
	elem = document.getElementById("msgBox"); 
	elem.style.top = pos.y + "px";
	elem.style.left = pos.x + "px";
	elem.style.display = "block";
}

function hideMsg(){
	document.getElementById("msgBoxText").innerHTML = "&nbsp;";
	elem = document.getElementById("msgBox"); 
	elem.style.top = "0px";
	elem.style.left = "0px";
	elem.style.display = "none";
}

/**
* Merkzettel
*/
function add2Notepad( ProdId , element ){

	var myAjax = new Ajax();
  myAjax.url = "/ajax.php";
  myAjax.params = "action=notepad&action2=add|info&uid=" + ProdId;
  myAjax.method = 'get';

  showMsg( element , "Der Artikel wird auf Deinen persönlichen Merkzettel gesetzt.");

  myAjax.onSuccess=function(txt) {
  	document.getElementById( 'notepad_body' ).innerHTML = txt;
  }
  
  myAjax.onError=function(msg) {
    alert(msg);
  }
  
  myAjax.doRequest();

  return false;
}

function showNotepadStatus(){
	var myAjax = new Ajax();
  myAjax.url = "/ajax.php";
  myAjax.params = "action=notepad&action2=info";
  myAjax.method = 'get';

  myAjax.onSuccess=function(txt) {
  	document.getElementById( 'notepad_body' ).innerHTML = txt;
  }
  
  myAjax.onError=function(msg) {
    alert(msg);
  }
  
  myAjax.doRequest();
}

/**
* Produktvergleich
*/
function add2Compare( uid ){
	var w = 800,h = 600;
	posx= Math.round((screen.width - w)/2);
	posy= Math.round((screen.height - h)/2);
	w=window.open("/compare.html?action=add|show&uid=" + uid,"compare",'width='+w+',height='+h+',screenX='+posx+',screenY='+posy + ",scrollbars=yes,resizable=yes");
	w.focus();
	return false;
}

/**
* Cookie Funktionen
*/

// gibt den Wert aus einer Cookievariable zurück
function getCookieVar( varName ){
	if ( document.cookie ){
		var cookieData = (document.cookie).split("; ");
		for( var i = 0 ; i < cookieData.length ; i++ ){
			temp = ( cookieData[i]).split("=");
			if ( temp[0] == varName ) return temp[1];
		}
	}
}

// 
function setCookieVar( varName , value ){
	if ( document.cookie ){
		var ablauf = new Date();
		var infuenfTagen = ablauf.getTime() + (5 * 24 * 60 * 60 * 1000);
		ablauf.setTime(infuenfTagen);
		document.cookie = varName + "=" + value + "; expires=" + ablauf.toGMTString();
	}
}


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

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

/* 
	regExNames = /^([A-Za-zÃ?Ã¶Ã?ÃŸ]+ *-? *)+[A-Za-zÃ?Ã?Ã¶ÃŸ]+$/;

  regExStreet = /^([0-9A-Za-zÃ?Ã¶Ã?ÃŸ]+ *-? *)+[0-9A-Za-zÃ?Ã¶Ã?ÃŸ]+.?( *\d*)$/;

  regExPostalCode = /^[0-9]\d*$/;

  regExAmount = /(^[1-9][0-9]{0,2}(\.[0-9]{3})*$)|(^[1-9]\d*$)/;
*/