﻿
// designed by iFactory, Würzburg, Germany       //

// Copyright 2000-2006 by iFactory               //
// All rights reserved.                          //
// Duplication in any form or any use of this    //
// script or parts of it are strictly prohibited //
// for private and commercial use.               //


/****************************************************************
 * global constants
 ****************************************************************/
recommend = true;


/****************************************************************
 * functions
 ****************************************************************/

/**
 * initializes module
 */
function initRecommend () {
	if (document.getElementById("recommend")) {
		document.getElementById("sname").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace('error','') + (parseFullName(this.value)>1?'error':'');
		};
		document.getElementById("smail").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace('error','') + (parseMail(this.value)>1?'error':'');
		};
		document.getElementById("rname").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace('error','') + (parseFullName(this.value)>1?'error':'');
		};
		document.getElementById("rmail").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace('error','') + (parseMail(this.value)?'error':'');
		};
		document.getElementById("recommend").send.onclick = function (evt) {
			error = 0x0;

			// sname
			str = '';
			switch (parseFullName(this.form.sname.value)) {
			case 2: error |= 0x2; str = 'error'; break;
			}
			this.form.sname.parentNode.className = this.form.sname.parentNode.className.replace('error','') + str;

			// smail
			str = '';
			switch (parseMail(this.form.smail.value)) {
			case 2: error |= 0x2; str = 'error'; break;
			}
			this.form.smail.parentNode.className = this.form.smail.parentNode.className.replace('error','') + str;

			// rname
			str = '';
			switch (parseFullName(this.form.rname.value)) {
			case 2: error |= 0x2; str = 'error'; break;
			}
			this.form.rname.parentNode.className = this.form.rname.parentNode.className.replace('error','') + str;

			// rmail
			str = '';
			switch (parseMail(this.form.rmail.value)) {
			case 1: error |= 0x1; str = 'error'; break;
			case 2: error |= 0x2; str = 'error'; break;
			}
			this.form.rmail.parentNode.className = this.form.rmail.parentNode.className.replace('error','') + str;


			// show message
			if (error) {
				str = "Eingabefehler!";
				if (error&0x2) str += "\nDie Daten sind fehlerhaft.";
				if (error&0x1) str += "\nSie haben nicht alle Felder ausgefüllt.";
				alert(str);
				return false;
			}

			return true;
		};
		document.getElementById("recommend").onreset = function (evt) {

			// sname
			this.sname.value = '';
			this.sname.defaultValue = '';
			this.sname.parentNode.className = this.sname.parentNode.className.replace('error','');

			// smail
			this.smail.value = '';
			this.smail.defaultValue = '';
			this.smail.parentNode.className = this.smail.parentNode.className.replace('error','');

			// rname
			this.rname.value = '';
			this.rname.defaultValue = '';
			this.rname.parentNode.className = this.rname.parentNode.className.replace('error','');

			// rmail
			this.rmail.value = '';
			this.rmail.defaultValue = '';
			this.rmail.parentNode.className = this.rmail.parentNode.className.replace('error','');

			// subject
			this.subject.value = 'Link-Empfehlung';
			this.subject.defaultValue = 'Link-Empfehlung';
			this.subject.parentNode.className = this.subject.parentNode.className.replace('error','');

			// message
			this.message.value = '';
			this.message.defaultValue = '';
		};
	}
}