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

// Copyright 2000-2008 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
 ****************************************************************/
join = true;


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

/**
 * initializes module
 */
function initJoin () {
	if (document.getElementById("join")) {
	  document.getElementById("name").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace('error','') + (Parse.name(this.value)?'error':'');
		};
	  document.getElementById("address").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace('error','') + (Parse.address(this.value)?'error':'');
		};
	  document.getElementById("zip").onblur = function (evt) {
			str = '';
			if (Parse.zip(this.value)) str = ' error';
			this.className = this.className.replace(' error','') + str;
			this.parentNode.firstChild.className = this.parentNode.firstChild.className.replace(' error','') + str;
		};
	  document.getElementById("place").onblur = function (evt) {
			str = '';
			if (Parse.place(this.value)) str = ' error';
			this.className = this.className.replace(' error','') + str;
			this.parentNode.firstChild.nextSibling.className = this.parentNode.firstChild.nextSibling.className.replace(' error','') + str;
  	};
	  document.getElementById("fon").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace('error','') + (Parse.phone(this.value)?'error':'');
		};
	  document.getElementById("fax").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace('error','') + (Parse.phone(this.value)>1?'error':'');
		};
	  document.getElementById("mail").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace('error','') + (Parse.mail(this.value)>1?'error':'');
		};
	  document.getElementById("birth").onblur = function (evt) {
			this.parentNode.className = this.parentNode.className.replace('error','') + (Parse.date(this.value)?'error':'');
		};
		if (document.getElementById("fee"))
		  document.getElementById("fee").onblur = function (evt) {
				this.parentNode.className = this.parentNode.className.replace('error','') + (this.value<1?'error':'');
			};
		if (document.getElementById("owner")) {
		  document.getElementById("owner").onblur = function (evt) {
				this.parentNode.className = this.parentNode.className.replace('error','') + (Parse.name(this.value)>1?'error':'');
			};
		  document.getElementById("bank").onblur = function (evt) {
				this.parentNode.className = this.parentNode.className.replace('error','') + (this.value.length<6?'error':'');
			};
		  document.getElementById("code").onblur = function (evt) {
				this.parentNode.className = this.parentNode.className.replace('error','') + (Parse.bank(this.value)?'error':'');
			};
		  document.getElementById("account").onblur = function (evt) {
				this.parentNode.className = this.parentNode.className.replace('error','') + (Parse.account(this.value)?'error':'');
			};
		}
	  document.getElementById("join").send.onclick = function (evt) {
			error = 0x0;

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

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

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

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

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

			// fax
			str = '';
			if (Parse.phone(this.form.fax.value) > 1) {
				error |= 0x2; str = 'error';
			}
			this.form.fax.parentNode.className = this.form.fax.parentNode.className.replace('error','') + str;

			// mail
			str = '';
			if (Parse.mail(this.form.mail.value) > 1) {
        error |= 0x2; str = 'error';
			}
			this.form.mail.parentNode.className = this.form.mail.parentNode.className.replace('error','') + str;

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

			// fee
			if (document.getElementById("fee")) {
				str = '';
				if (this.form.fee.value < 1) {
    	    error |= 0x2; str = 'error';
				}
				this.form.fee.parentNode.className = this.form.fee.parentNode.className.replace('error','') + str;

			// rotation
/*
			check = false;
			for (i=0; i<this.forms.rotation.length; i++)
				if (this.forms.rotation[i].checked) check = true;
			if (!check) msg += 'Zahlungsturnus fehlt\n';
*/
			}

			if (document.getElementById("owner")) {
				// owner
				str = '';
				switch (Parse.name(this.form.owner.value)) {
				case 2: error |= 0x2; str = 'error'; break;
				}
				this.form.owner.parentNode.className = this.form.owner.parentNode.className.replace('error','') + str;

				// bank
				str = '';
				if (this.form.bank.value.length < 1) {
					error |= 0x1; str = 'error';
				} else if (this.form.bank.value.length < 6) {
					error |= 0x2; str = 'error';
				}
				this.form.bank.parentNode.className = this.form.bank.parentNode.className.replace('error','') + str;

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

				// account
				str = '';
				switch (Parse.account(this.form.account.value)) {
				case 1: error |= 0x1; str = 'error'; break;
				case 2: error |= 0x2; str = 'error'; break;
				}
				this.form.account.parentNode.className = this.form.account.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("join").onreset = function (evt) {

			// name
      this.name.value = null;
			this.name.defaultValue = '';
			this.name.parentNode.className = this.name.parentNode.className.replace('error','');
			// address
      this.address.value = null;
			this.address.defaultValue = '';
			this.address.parentNode.className = this.address.parentNode.className.replace('error','');
			// zip
      this.zip.value = null;
			this.zip.defaultValue = '';
			this.zip.className = this.zip.className.replace(' error','');
			this.zip.parentNode.firstChild.className = this.zip.parentNode.firstChild.className.replace(' error','');
			// place
      this.place.value = null;
			this.place.defaultValue = '';
			this.place.className = this.place.className.replace(' error','');
			this.place.parentNode.firstChild.nextSibling.className = this.place.parentNode.firstChild.nextSibling.className.replace(' error','');
			// fon
      this.fon.value = null;
			this.fon.defaultValue = '';
			this.fon.parentNode.className = this.fon.parentNode.className.replace('error','');
			// fax
      this.fax.value = null;
			this.fax.defaultValue = '';
			this.fax.parentNode.className = this.fax.parentNode.className.replace('error','');
			// mail
			this.mail.value = null;
			this.mail.defaultValue = '';
			this.mail.parentNode.className = this.mail.parentNode.className.replace('error','');
			// birth
			this.birth.value = null;
			this.birth.defaultValue = '';
			this.birth.parentNode.className = this.birth.parentNode.className.replace('error','');

			// fee
			this.fee.parentNode.className = this.fee.parentNode.className.replace('error','');
			// owner
			this.owner.value = null;
			this.owner.defaultValue = '';
			this.owner.parentNode.className = this.owner.parentNode.className.replace('error','');
			// bank
			this.bank.value = null;
			this.bank.defaultValue = '';
			this.bank.parentNode.className = this.bank.parentNode.className.replace('error','');
			// code
			this.code.value = null;
			this.code.defaultValue = '';
			this.code.parentNode.className = this.code.parentNode.className.replace('error','');
			// account
			this.account.value = null;
			this.account.defaultValue = '';
			this.account.parentNode.className = this.account.parentNode.className.replace('error','');
		};
	}
}