// JavaScript Document
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) {
	  test=args[i+2];
	  val=MM_findObj(args[i]);
	  if (val) {
		  nm=val.title;
		  if ((val=val.value)!="") {
			  if (test.indexOf('isEmail')!=-1) {
				  p=val.indexOf('@');
				  if (p<1 || p==(val.length-1)) errors+='<li>'+nm+' muss eine <strong>E-Mail-Adresse</strong> enthalten.</li>\n';
			  } else if (test!='R') {
				  num = parseFloat(val);
				  if (isNaN(val)) errors+='<li>'+nm+' muss eine <strong>Zahl</strong> sein.</li>\n';
				  if (test.indexOf('inRange') != -1) {
					  p=test.indexOf(':');
					  min=test.substring(8,p);
					  max=test.substring(p+1);
					  if (num<min || max<num) errors+='<li>'+nm+' muss eine Zahl zwischen '+min+' und '+max+' enthalten.</li>\n';
                  }
		      }
		   } else if (test.charAt(0) == 'R') errors += '<li>Das Feld <strong>'+nm+'</strong> muss ausgef&uuml;llt sein.</li>\n'; 
	   }
  } if (errors) alert('Die folgenden Fehler traten auf:\n<ul>'+unescape(errors)+'</ul>');
  document.MM_returnValue = (errors == '');
}

// CUSTOM ALERT-BOX (http://slayeroffice.com/code/custom_alert/)

// constants to define the title of the alert and button text.
var ALERT_TITLE = "Fehler";
var ALERT_BUTTON_TEXT = "Ok";

// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if(document.getElementById) {
	window.alert = function(txt) {
		createCustomAlert(txt);
	}
}

function createCustomAlert(txt) {
	// shortcut reference to the document object
	d = document;

	// if the overlay object already exists in the DOM, bail out.
	if(d.getElementById("overlay")) return;

	// create the overlay div as a child of the BODY element
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "overlay";
	 // make sure its as tall as it needs to be to overlay all the content on the page
	mObj.style.height = document.documentElement.scrollHeight + "px";

	// create the DIV that will be the alert 
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alert";
	// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
	if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
	// center the alert box
	alertObj.style.left = (d.documentElement.clientWidth - alertObj.offsetWidth)/2 + "px";
	alertObj.style.top = (d.documentElement.clientHeight - alertObj.offsetHeight)/2 - 100 + "px";

	// create an H1 element as the title bar
	h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode(ALERT_TITLE));

	// create a paragraph element to contain the txt argument
	msg = alertObj.appendChild(d.createElement("p"));
	msg.id = "msg";
	msg.innerHTML = txt;
	
	// create an anchor element to use as the confirmation button.
	//btn = alertObj.appendChild(d.createElement("a"));
	btn = d.getElementById("msg").appendChild(d.createElement("a"));
	btn.id = "button";
	btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	btn.href = "#";
	// set up the onclick event to remove the alert when the anchor is clicked
	btn.onclick = function() { removeCustomAlert();return false; }
	
	
}

// removes the custom alert from the DOM
function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("overlay"));
}
