/**************************************************
 SI_isValidEmail()
 
 Returns true if the value passed is a valid email 
 address. Duh.
 **************************************************/
function SI_isValidEmail(email) { return (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)?true:false; }

/**************************************************
 SI_empty()
 
 Similar to the php function empty()
 Returns true if val contains an empty string
 or contains only whitespace.
 ie. spaces or returns
 **************************************************/
function SI_empty(val) { var empty = /^\s*$/; return empty.test(val); }

/**************************************************
 SI_handleErrors/SI_clearErrors()
 
 Used to present the user feedback.
 The first index of the SI_errors array is presented
 in paragraph form. The remaining indexes are output
 in an unordered list.
 **************************************************/
var SI_errors = new Array();
function SI_handleErrors() {
	var d = document;
	errorMsg = '<p>'+SI_errors[0]+'<'+'/p><ul style="margin-bottom:20px">';
	for (var i=1; i<SI_errors.length; i++) {
		errorMsg += '<li>'+SI_errors[i]+'<'+'/li>';
		}
	errorMsg += '<'+'/ul>';
	d.getElementById('container-errors').innerHTML = errorMsg;
	SI_clearErrors();
	}
function SI_clearErrors() { SI_errors = new Array(); }


/**************************************************
 SI_prescreenComments() (MT 2.64+)
 
 Called from the comment form's onsubmit handler and
 makes sure that author, email, and comments all have
 values and that the email provided is valid.
 **************************************************/
function SI_prescreenComments(f) {
	var d = document;
	if (!d.getElementById) return true;
	
	var a = f.name.value;
	var e = f.email.value;
	var t = f.nachricht.value;
		
	// Error message for missing author name
	if (SI_empty(a)) { SI_errors[SI_errors.length] = 'Bitte tragen Sie Ihren Namen ein.';  }
	
	// Error message for missing email address
	if (SI_empty(e)) { SI_errors[SI_errors.length] = 'Bitte tragen Sie Ihre E-Mail-Adresse ein.'; }
	
	// Error message for invalid email address
	else if (!SI_isValidEmail(e)) { SI_errors[SI_errors.length] = 'Bitte &uuml;berpr&uuml;fen Sie Ihre E-Mail-Adresse.'; }
	
	// Error message for missing comment
	if (SI_empty(t)) { SI_errors[SI_errors.length] = 'Bitte tragen Sie Ihre Nachricht ein.'; }
	
	// Yay! No errors!
	if (!SI_errors.length) {
		SI_clearErrors();
		return true;
		}
	// Nay! Try again!
	else {
		// Error message lead-in.
		var failed = ['<strong style="color:#e3100e">Bitte &Uuml;berpr&uuml;fen Sie folgende Angaben:</strong>'];
		SI_errors = failed.concat(SI_errors);
		SI_handleErrors();
		
		// Cancel form submission
		return false;
		}
	}
