﻿
// 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
 ****************************************************************/
contact = true;


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

/**
 * initializes module
 */
function initContact () {
	if (document.getElementById("contact")) {
		document.getElementById("sender").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace(' error','') + (parseName(this.value)>1?' error':'');
		};
		document.getElementById("mail").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace(' error','') + (parseMail(this.value)>1?' error':'');
		};
		document.getElementById("subject").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace(' error','') + (this.value.length<1?' error':'');
		};
		document.getElementById("contact").send.onclick = function (evt) {
			error = 0x0;

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

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

			// subject
			str = '';
			if (this.form.subject.value.length <= 0) {
				error |= 0x1; str = ' error';
			}
			this.form.subject.parentNode.className = this.form.subject.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("contact").onreset = function (evt) {

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

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

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

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