////////////////////////PRELOAD IMAGES///////////////////////////////////////////////////////////////
// Tooltips Class
// A superclass to work with simple CSS selectors
var Tooltips = Class.create();
Tooltips.prototype = {
	initialize: function(selector, options) {
		var tooltips = $$(selector);
		tooltips.each( function(tooltip) {
			new Tooltip(tooltip, options);
		});
	}
};
// Tooltip Class
var Tooltip = Class.create();
Tooltip.prototype = {
	initialize: function(el, options) {
		this.el = $(el);
		this.initialized = false;
		this.setOptions(options);

		// Event handlers
		this.showEvent = this.show.bindAsEventListener(this);
		this.hideEvent = this.hide.bindAsEventListener(this);
		this.updateEvent = this.update.bindAsEventListener(this);
		Event.observe(this.el, "mouseover", this.showEvent );
		Event.observe(this.el, "mouseout", this.hideEvent );

		// Content for Tooltip is either given through
		// 'content' option or 'title' attribute of the trigger element. If 'content' is present, then 'title' attribute is ignored.
		// 'content' is an element or the id of an element from which the innerHTML is taken as content of the tooltip
		if (options && options['content']) {
			this.content = $(options['content']).innerHTML;
		} else {
			this.content = this.el.title.stripScripts().strip();
		}
		// Removing title from DOM element to avoid showing it
		this.content = this.el.title.stripScripts().strip();
		this.el.title = "";

		// If descendant elements has 'alt' attribute defined, clear it
		this.el.descendants().each(function(el){
			if(Element.readAttribute(el, 'alt'))
				el.alt = "";
		});
	},
	setOptions: function(options) {
		this.options = {
			backgroundColor: '#999', // Default background color
			borderColor: '#666', // Default border color
			textColor: '', // Default text color (use CSS value)
			textShadowColor: '', // Default text shadow color (use CSS value)
			maxWidth: 250,	// Default tooltip width
			align: "left", // Default align
			delay: 250, // Default delay before tooltip appears in ms
			mouseFollow: true, // Tooltips follows the mouse moving
			opacity: .75, // Default tooltips opacity
			appearDuration: .25, // Default appear duration in sec
			hideDuration: .25 // Default disappear duration in sec
		};
		Object.extend(this.options, options || {});
	},
	show: function(e) {
		this.xCord = Event.pointerX(e);
		this.yCord = Event.pointerY(e);
		if(!this.initialized)
			this.timeout = window.setTimeout(this.appear.bind(this), this.options.delay);
	},
	hide: function(e) {
		if(this.initialized) {
			this.appearingFX.cancel();
			if(this.options.mouseFollow)
				Event.stopObserving(this.el, "mousemove", this.updateEvent);
			new Effect.Fade(this.tooltip, {duration: this.options.hideDuration, afterFinish: function() { Element.remove(this.tooltip) }.bind(this) });
		}
		this._clearTimeout(this.timeout);

		this.initialized = false;
	},
	update: function(e){
		this.xCord = Event.pointerX(e);
		this.yCord = Event.pointerY(e);
		this.setup();
	},
	appear: function() {
		// Building tooltip container
		this.tooltip = new Element("div", { className: "tooltip", style: "display: none" });

		var arrow = new Element("div", { className: "xarrow" }).insert('<b class="a1"></b><b class="a2"></b><b class="a3"></b><b class="a4"></b><b class="a5"></b><b class="a6"></b>');

		var top = new Element("div", { className: "xtop" }).insert(
			new Element("div", { className: "xb1", style: "background-color:" + this.options.borderColor + ";" })
		).insert(
			new Element("div", { className: "xb2", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";" })
		).insert(
			new Element("div", { className: "xb3", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";" })
		).insert(
			new Element("div", { className: "xb4", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";" })
		);

		var bottom = new Element("div", { className: "xbottom" }).insert(
			new Element("div", { className: "xb4", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";" })
		).insert(
			new Element("div", { className: "xb3", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";" })
		).insert(
			new Element("div", { className: "xb2", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";" })
		).insert(
			new Element("div", { className: "xb1", style:"background-color:" + this.options.borderColor + ";" })
		);

		var content = new Element("div", { className: "xboxcontent", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor +
			((this.options.textColor != '') ? "; color:" + this.options.textColor : "") +
			((this.options.textShadowColor != '') ? "; text-shadow:2px 2px 0" + this.options.textShadowColor + ";" : "") }).update(this.content);

		// Building and injecting tooltip into DOM
		this.tooltip.insert(arrow).insert(top).insert(content).insert(bottom);
		$(document.body).insert({'top':this.tooltip});

		// Coloring arrow element
		this.tooltip.select('.xarrow b').each(function(el){
			if(!el.hasClassName('a1'))
				el.setStyle({backgroundColor: this.options.backgroundColor, borderColor: this.options.borderColor });
			else
				el.setStyle({backgroundColor: this.options.borderColor });
		}.bind(this));

		Element.extend(this.tooltip); // IE needs element to be manually extended
		this.options.width = this.tooltip.getWidth() + 1; // Quick fix for Firefox 3
		this.tooltip.style.width = this.options.width + 'px'; // IE7 needs width to be defined

		this.setup();

		if(this.options.mouseFollow)
			Event.observe(this.el, "mousemove", this.updateEvent);

		this.initialized = true;
		this.appearingFX = new Effect.Appear(this.tooltip, {duration: this.options.appearDuration, to: this.options.opacity });
	},
	setup: function(){
		// If content width is more then allowed max width, set width to max
		if(this.options.width > this.options.maxWidth) {
			this.options.width = this.options.maxWidth;
			this.tooltip.style.width = this.options.width + 'px';
		}

		// Tooltip doesn't fit the current document dimensions
		if(this.xCord + this.options.width >= Element.getWidth(document.body)) {
			this.options.align = "right";
			this.xCord = this.xCord - this.options.width + 20;
			this.tooltip.down('.xarrow').setStyle({left: this.options.width - 24 + 'px'});
		} else {
			this.options.align = "left";
			this.tooltip.down('.xarrow').setStyle({left: 12 + 'px'});
		}

		this.tooltip.style.left = this.xCord - 7 + "px";
		this.tooltip.style.top = this.yCord + 12 + "px";
	},
	_clearTimeout: function(timer) {
		clearTimeout(timer);
		clearInterval(timer);
		return null;
	}
};
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function valid_homepage(homepage)
{

if(!homepage.match(/http\:\/\/www\.(.*?)\.([a-z]{2,})/))
error+="\nBitte geben Sie eine korrekte URL bei Homepage an!";

};
//////////////////////////AJAX//////////////////////////////////////////////////////////////////
var myGlobalHandlers= {
        onCreate: function()
        {
                Element.show('systemWorking');
				 Element.show('systemanzeige');
        },
        onComplete: function(){
                if (Ajax.activeRequestCount==0)
                {
                        Element.hide('systemWorking');
						 Element.hide('systemanzeige');
                }
        }
}
Ajax.Responders.register(myGlobalHandlers);
///////////////////////////////////////////////////////////////////////////////////////
Event.observe(window, 'load',

      function() {
      Element.hide('systemWorking');
      Element.hide('systemanzeige');
      }

);
///////////////////////////////////GOOGLE////////////////////////////////////////////////////////
function load_mein_google()
  {
   google.load("maps", "2.x");



  // Call this function when the page has been loaded
   function initialize()
   {
        var map = new google.maps.Map2(document.getElementById("map"));
        map.setCenter(new google.maps.LatLng(document.getElementById("x").value, document.getElementById("y").value), 15);
		map.setCenter(new GLatLng(document.getElementById("x").value,document.getElementById("y").value), 15);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.addOverlay(createMarker( new GLatLng(document.getElementById("x").value, document.getElementById("y").value), document.getElementById("googletext").value));
 }
      google.setOnLoadCallback(initialize);


  }

 function createMarker(point, mtext) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "mouseover", function() {
		marker.openInfoWindowHtml( mtext );
	});
	GEvent.addListener(marker, "mouseout", function(){
    marker.closeInfoWindow();
  });
	return marker;
 }


function get_url_ajax(t)
{
var url = '';
for (var i=1;i<=t;i++)
{
url+="../";
}
return url;
}
//////////////////////////////////EMAIL ERWEITERT///////////////////////////////////////////////
function validE(email) {
 var a = false;
 var res = false;
 if(typeof(RegExp) == 'function')
 {
  var b = new RegExp('abc');
  if(b.test('abc') == true){a = true;}
  }

 if(a == true)
 {
  reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                   '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                   '(\\.)([a-zA-Z]{2,4})$');
  res = (reg.test(email));
 }
 else
 {
  res = (email.search('@') >= 1 &&
         email.lastIndexOf('.') > email.search('@') &&
         email.lastIndexOf('.') >= email.length-5)
 }
 if (res==true)
 {

 } else {

 error+="\nBitte geben Sie eine korrekte E-Mail-Adresse ein!";

 }
}

///////////////////////////////////////////////////DATUM PRÜFEN////////////////////////////////
function datumtest (t, m, j) {
        if (t>31 || m>12  || j>2020 || t<1 || m <1 || j<1920)
		{

                 error+="\nBitte geben Sie ein korrektes Datum ein!";
		}
                 if (m==4 || m ==6 || m== 9 || m==11)
                {
                if (t >30){
            		if (m==4)
            		 mon="April";
					else if (m==6)
                	mon="Juni";
					else if (m==9)
                    mon="September";
					else
                	mon="November";



                error+="\nBitte geben Sie ein korrektes Datum ein, der Monat "+mon+" hat nur 30 Tage!";

                }
                } else if (m==2 || m==02)
                {

                 if (j%4==0 && t>29)
                 error+="\nBitte geben Sie ein korrektes Datum ein, der Monat Februar hat in dem gewählten Jahr nur 29 Tage!";
				 else  if(j%4!=0 && t>28)
                  error+="\nBitte geben Sie ein korrektes Datum ein, der Monat Februar hat in dem gewählten Jahr nur 28 Tage!";

                }


};


function checke_nummern(name,mind,maxi,par,notwendig,bedingung,bname,bpar)
{

if (
        (notwendig=='ja' || ((notwendig=='nein' && par!='') || bpar!=''))
        && (
        (mind!='' && maxi!='' && (isNaN(par) || par.length>maxi || par.length<mind)) ||
        (mind=='' && isNaN(par)) || (bpar!='' && (isNaN(par) || par==''))) )
{

error+="\nBitte verwenden Sie nur Ziffern beim Feld "+name+".";
if (mind!='')
error+=" Mindestens "+mind+" und maximal "+maxi+" Ziffern dürfen eingetragen werden.";
if (notwendig=="nein")
error+=" Oder lassen Sie das Feld leer.";
if (notwendig=="nein" && bedingung!='' && par!='')
error+=" In diesem Fall muss aber auch das Feld "+bname+" leer sein.";
}

}
function checke_anzahl(name,par,mind,maxi)
{
        if (par.length<mind || par.length>maxi)
		error+="Mindestens "+mind+" und maximal "+maxi+" Zeichen dürfen beim Feld "+name+" verwendet werden.";

}

function benoetigt(name,par)
{

if (par=='' || par==0)
error+="\nDas Feld "+name+" darf nicht leer sein!";
}

/////////////////////TOOLTIP//////////////////////////////////////////////////////////////
function showWMTT(id) {
        wmtt = document.getElementById(id);
        wmtt.style.display = "block"

}

function hideWMTT() {
        wmtt.style.display = "none";
}




function gehezu(url)
{
document.location=url;

}






