/*
function abFieldValidationError
function abGetURLParam
function abIsLocal
function abMemoAddr
function abOnLoad
function abOnSubmit
function abOpenLocation
function abTrim
function abValidateField 
*/

// ==================================================
function abFieldValidationError ( vFormID , vFieldName , vRaiseErrors , vErrorMessage ) {

	if ( vRaiseErrors && vErrorMessage.length > 0 ) {
		alert ( vErrorMessage ) ;
		document.getElementById ( vFormID ).elements[vFieldName].focus() ;
		} ;

	return false ;

	} ;	// function abFieldValidationError ()



// ==================================================

function abGetURLParam ( vPName ) {

	var vSearch = window.location.search ;

	if ( vSearch.length == 0 ) {
		return '' ;
		} ;

	if ( vSearch.indexOf ( vPName + "=" ) < 1 ) {
		return '' ;
		} ;

	vSearch = vSearch.substring ( vSearch.indexOf ( vPName + "=" ) + vPName.length + 1 , vSearch.length ) ;

	if ( vSearch.indexOf ( '&' ) > 0 ) {
		vSearch = decodeURIComponent ( vSearch.substring ( 0 , vSearch.indexOf ( '&' ) ) ) ;
		} ;

	return decodeURIComponent ( vSearch ) ;

	} ;	// function abGetURLParam



// ==================================================

function abIsLocal () {
	return ( window.location.hostname.indexOf ( 'dr-notes.de' ) > 0 ? false : true ) ;
	} ;	// function abIsLocal ()



// ==================================================

function abMemoAddr ( strPrefix ) {
	var str1 = 'e' ;
	var str2 = 'otes' ;
	var str3 = 'de' ;
	var str4 = 'dr-n' ;
	var str5 = 'mail' ;
	return strPrefix + str1 + unescape ( '%2D' ) + str5 + unescape ( '%40' ) + str4 + str2 + unescape ( '%2E' ) + str3 ;
	}	// function abMemoAddr ()



// ==================================================

function abOnLoad()	{

	var vLocationHostname = self.location.hostname ;
	var vLocationPathname = self.location.pathname ;

	for ( i = 0 ; i < document.links.length ; i++ ) {
		with ( document.links[i] ) {
			if ( href ) {
				if ( vLocationHostname == hostname && vLocationPathname == pathname && attributes['class']) {
					if ( attributes['class'].value == 'nav1' ) {
						id = 'anav1active' ;
						} ;
					} ;
				if ( ( href.search ( /^http:\/\/drnotes.xbay/ ) == -1 && href.search ( /^http:\/\/dr-notes.de/ ) == -1 && href.search ( /^http:\/\/www.dr-notes.de/ ) == -1 && href.search ( /^javascript:/ ) == -1  && href.search ( /^file:\/\// ) == -1 ) || className == 'a1' ) {
					target = '_blank' ;
					} ;
				} ;
			} ;
		} ;

	} ;	// function abOnLoad()



// ==================================================

function abOnSubmit ( vFormID ) {

	if ( document.getElementById( vFormID ) ) {
		with ( document.getElementById( vFormID ) ) {
			for ( var i = 0 ; i < elements.length ; i++ ) {
				switch (elements[i].name) {
					case 'LotusNotesVersion' :
						break ;
					case 'mailto' :
						elements[i].value = abMemoAddr ('');
						break ;
					case 'redirect' :
						elements[i].value = vFormID == "formkommentar" ? self.location.href + '#formfeedback' : self.location.href.replace ( /.html/ , 'ok.html' ) ;
						break ;
					case 'subject' :
						elements[i].value = 'Dr-Notes Formular "' + vFormID + '"' ;
						break ;
					default :
						if ( !abValidateField ( vFormID , elements[i].name , true ) ) {
							return false ;
						} ;
					} ;
				} ;
				// attributes['action'].value = vFormID == "formschulungen" ? '/cgi-bin/frmmemoschulungen.pl' : '/cgi-bin/frmmemo.pl' ;
				attributes['action'].value = self.location.href.indexOf ( 'lotusnotesschulungeneffizienz.html ' ) > 0 ? '/cgi-bin/frmmemoschulungen.pl' : '/cgi-bin/frmmemo.pl' ;
			} ;
		} ;
	return true ;
	} ;



// ==================================================

function abOpenLocation ( oLink ) {

	var vLocation ;

	if ( oLink.attributes['href'] ) {

		vLocation = oLink.attributes['href'].value ;

		if ( document.location.protocol == 'file:' ) {
			vLocation = self.location.href ;
			vLocation = vLocation.substring ( 0 , vLocation.lastIndexOf ( '.htm' ) ) ;
			vLocation = vLocation.substring ( 0 , vLocation.lastIndexOf ( '/' ) + 1 ) + oLink.attributes['href'].value ;

			if ( oLink.attributes['target'] ) {
				if ( oLink.attributes['target'].value == '_blank' ) {
					window.open ( oLink.attributes['href'].value , '' ) ;
					}
				else {
					self.location.href =  vLocation ;
					}
				}
			else {
				self.location.href = vLocation ;
				}
			}
		else {

			if ( oLink.attributes['target'] ) {
				if ( oLink.attributes['target'].value == '_blank' ) {
					window.open ( vLocation , '' ) ;
					}
				else {
					self.location.href =  vLocation ;
					}
				}
			else {
				self.location.href = vLocation ;
				}
			} ;
		} ;

	} ;	// function abOpenLocation ()



// ==================================================

function abTrim ( vString ) {

	while ( vString.charAt (0) == ' ' ) {
		vString = vString.slice ( 1 ) ;
		} ;

	while ( vString.charAt ( vString.length - 1 ) == ' ' ) {
		vString = vString.substring ( 0 , vString.length - 1 ) ;
		} ;

	return vString ;

	} ;	// function abTrim ()



// ==================================================

function abValidateField ( vFormID , vFieldName , vRaiseErrors ) {

	if ( document.getElementById ( vFormID ).elements[vFieldName] ) {
		if ( document.getElementById ( vFormID ).elements[vFieldName].value ) {
			with ( document.getElementById ( vFormID ).elements[vFieldName] ) {

				vFieldValue = value.toLowerCase() ;

				switch ( vFieldName ) {

					case 'BlogNote' :

						if ( vFieldValue.length < 10 ) {
							return abFieldValidationError ( vFormID , vFieldName , vRaiseErrors , 'Bitte formulieren Sie ihren Kommentar (mindestens 10 Zeichen).' ) ;
							} ;

						return true ;
						break ;

					// ------------------------------------------------

					case 'EMail' :

						if ( vFieldValue.indexOf ( '@' ) < 1 ) {
							return abFieldValidationError ( vFormID , vFieldName , vRaiseErrors , 'Die E-Mail-Adresse muss ein "@" enthalten !' ) ;
							} ;

						if ( vFieldValue.lastIndexOf ( '.' ) < vFieldValue.indexOf ( '@' ) + 3 || vFieldValue.lastIndexOf ( '.' ) > vFieldValue.length - 3 ) {
							return abFieldValidationError ( vFormID , vFieldName , vRaiseErrors , 'Die E-Mail-Adresse scheint nicht korrekt zu sein !' ) ;
							} ;

						return true ;
						break ;

					// ------------------------------------------------

					case 'LastName' :

						if ( vFieldValue.length < 2 ) {
							return abFieldValidationError ( vFormID , vFieldName , vRaiseErrors , 'Bitte geben Sie ihren Nachnamen an.' ) ;
							} ;

						return true ;
						break ;

					// ------------------------------------------------

					case 'Question' :

						if ( vFieldValue.length < 10 ) {
							return abFieldValidationError ( vFormID , vFieldName , vRaiseErrors , 'Bitte formulieren Sie ihre Frage (mindestens 10 Zeichen).' ) ;
							} ;

						return true ;
						break ;

					// ------------------------------------------------

					case 'Request' :

						if ( vFieldValue.length < 10 ) {
							return abFieldValidationError ( vFormID , vFieldName , vRaiseErrors , 'Bitte schildern Sie kurz ihr Anliegen (mindestens 10 Zeichen).' ) ;
						} ;

						return true ;
						break ;

					// ------------------------------------------------

					default : return true ;

					} ;	// switch ( vFieldName )
				} ;
			} ;
		} ;
	return true ;
	} ;	// function abValidateField ()