/*

*/
function Tooltip(width) {
	var self = this;
	this.tooltipobj = null;
	this.state = false;
	this.x = 0;
	this.y = 0;
	this.width = width;
	
	Event.observe( window, "load", function() { self.init(); } );
}

Tooltip.prototype.show = function(msg,evt) {
	var self = this;
	var element = Event.element(evt);
	Event.observe(element,"mouseout", function() {self.hide(evt); });
	
	this.setCoords(this.x,this.y);
	this.tooltipobj.innerHTML = msg;
	this.tooltipobj.style.display = "block";
	this.tooltipobj.style.border = "none";
	this.state = true;
}

Tooltip.prototype.hide = function(evt) {
	Event.stopObserving( Event.element(evt), "mouseout", function() { self.hide(evt); });
	this.state = false;
	this.tooltipobj.style.display = "none";
}

Tooltip.prototype.setCoords = function(x, y) {
	if ( (x + this.width) > (screen.availWidth) ) {
		x -= this.width + 12;
	} else {
		x += 12;
	}
	
	this.tooltipobj.style.top = y + "px";
	this.tooltipobj.style.left = x + "px";
	//screen.availHeight
	//screen.availWidth
}

Tooltip.prototype.mousemove = function(evt) {
	this.x = Event.pointerX(evt)
	this.y = Event.pointerY(evt);
	
	if ( this.state ) {
		this.setCoords( this.x, this.y );		
	}
}

Tooltip.prototype.init = function() {
	var self = this;
	this.tooltipobj = $("tooltip");
	if ( this.width > 0 ) { this.tooltipobj.style.width = this.width + "px"; } else { this.tooltipobj.style.minWidth = "50px"; }
	
	Event.observe( document, "mousemove", function( evt ) { self.mousemove(evt); } );
}



/*
	Switch eine grafik
*/
function switchImg( img ) {
	if ( $(img).getAttribute("active") == "true" ) return;

	if ( $(img).src.search(/_0\./) > -1 ) {
		$(img).src = $(img).src.replace(/_0\./, "_1.");	
	} else {
		$(img).src = $(img).src.replace(/_1\./, "_0.");
	}
}


/*
	Navi1 klick läd Navi2 content und Content nach
*/
function naviClick( site, navi2, content, footer, active ) {
	
	if( navi2 != "" ) {
		if ( navi2 == "none" ) {
			new Ajax.Updater("Navi2", "index.php",{
				method		: "POST",
				parameters 	: "tpl=none"
			});
		} else {	
			new Ajax.Updater("Navi2","index.php",{
				method 		: "POST",
				parameters 	: "tpl="+site+"/"+navi2
			});	
		}
	}
		
	if ( content != "" ) {
		if ( content == "none" ) {
			alert( "Error das gibts ned");
		} else {			
			new Ajax.Updater("Content","index.php",{
				method 		: "POST",
				parameters 	: "tpl="+site+"/"+content
			});		
		}
	}
	
	if ( footer != "" ) {
		if ( footer == "none" ) {
			$("Footer").style.display = "none";
		} else {			
			$("Footer").style.display = "block";
			new Ajax.Updater("Footer","index.php",{
				method 		: "POST",
				parameters 	: "tpl="+site+"/"+footer
			});				
		}
	}
	
	if ( active ) {
		$(active).blur();
		var Links = $$("a."+$(active).className+" img");
		
		for ( i=0; i < Links.length; i++ ) {
			if ( Links[i] == $(active).childNodes[0] ) {
				Links[i].src = Links[i].src.replace(/_0\./, "_1.");
				Links[i].setAttribute("active", "true");
			} else {
				Links[i].src = Links[i].src.replace(/_1\./, "_0.");
				Links[i].setAttribute("active", "false");
			}
		}
	}
	
	return false;
}

function showWindow( id ) {
	window.open("sendmail.php?todo="+id,"_blank","dependent=yes, location=no, menubar=no, scollbars=no, status=no, toolbar=no, width=320,height=320");
}

function sendEmpfehlung() {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if ( ($F("mailfrom") == "") || ($F("mail") == "") || ($F("comment") == "") ) {
		alert("Bitte geben sie eine eMail sowie einen Kommentar dazu an");
		return;
	}
	
	if ( !filter.test($F("mail")) ) {
		alert("Bitte \u00FCberpr\u00FCfen Sie ihre Email auf g\u00FCltigkeit");		
		return;
	}
	
	if ( !filter.test($F("mailfrom")) ) {
		alert("Bitte \u00FCberpr\u00FCfen Sie die Empf\u00E4ngermail auf g\u00FCltigkeit");		
		return;		
	}
	
	new Ajax.Updater("Content","index.php",{
		method 		: "POST",
		parameters 	: {
			tpl		: "weiterempfehlen",
			mail	: $F("mail"),
			name	: $F("name"),
			namefrom: $F("namefrom"),
			comment	: $F("comment"),
			mailfrom: $F("mailfrom")
		}
	});			
}