

/* fhh_main Version 2010-05-05 09-53-15 */

/**
 * Abkürzung für document.getElementById.
 *
 * id			string		ID des Elements
 * 
 * return		object		Element mit der gegebenen ID
 */
function $(id) {
	return document.getElementById(id);
}

/**
 * Hides the current tab and shows the tab with the given id
 *
 * tabID	string	ID of the tab
 * 
 * @uses currentTag variable
 */
function showTab(tabID){
	if (currentTab!=""){
		div = $(currentTab);
		if (div!=null){
			div.className = 'detail_box_hidden';		
		}		
	}
	
	div = $(tabID);
	if (div!=null){
			div.className = 'detail_box';
			currentTab = tabID;
	}		
}

/**
 * Hides the current sub tab and shows the tab with the given id
 *
 * tabID	string	ID of the tab
 * 
 * @uses currentSection variable
 */
function showSubTab(tabID){
	if (currentSection!=""){
		div = $(currentSection);
		if (div!=null){
			div.className = 'detail_box_hidden';		
		}		
	}
	
	div = $(tabID);
	if (div!=null){
			div.className = 'detail_box';
			currentSection = tabID;
	}		
}


/**
 * Toggles between class 'box_expand' and 'box_collapse'
 *
 * id	string	ID of the tab
 *  
 */
function toggleExpand(id){
	div = $(id);
	if (div!=null){
		if (div.className=='box_collapse'){
			div.className = 'box_expand';
		} else {
			div.className = 'box_collapse';
		}
	} 
}


function openNewWindow(url,width,height,iDefaultPosTop,iDefaultPosLeft,Userparam){
var iPosLeft;
var iPosTop;
if (screen.width){
	iPosLeft=(screen.width/2)-width/2;
	iPosTop=(screen.height/2)-height/2;
}
else{
	iPosLeft=iDefaultPosLeft;
	iPosTop=iDefaultPosTop;
}
param=Userparam+",top="+String(iPosTop)+",left="+String(iPosLeft);
window.open(url, "", "width="+width+",height="+height+","+param);
}

/*!!Do not delete this function!!.
You need this function to use the validation of the formulargenerator.*/

function getFieldValue ( theField, vType){
	//this function will return the field value (or value list) based on the element type
	theValue=""; 
	sep=";"; 
	hits=0;
	vType=vType.toLowerCase();
	//text is the user-entered value as a string
	if(vType=="text" ) return(theField.value); 
	//textarea is the user-entered value as a string array of one element
	if(vType=="textarea" ) return(theField.value);
	//select is an array of selection pointers to an array of strings representing the choices
	if(vType=="select"){
		for ( i=0; i<theField.options.length; i++){
			if(theField.options[i].selected){
				hits++;
				if(theField.options[i].value==""){
					e=theField.options[i].text;
				}else{ 
					e=theField.options[i].value;
				}
				if(hits==1){
					theValue=e;
				}else{
					theValue+= sep+e;
				}
			}
		}
		return(theValue);
	}
	if(vType=="dropdown"){
		if(theField.options[0].selected){
			return("");
		}
		return("True");
	}
	// check Emailaddress
	if(vType=="mail"){
		var mail=theField.value;
		if(mail==""){
			return ("");
		}else{
			var erg =mail.search(/.+@..+\...+/);
			if(erg==-1){
				return ("");
			}
			var erg=mail.search(/\s/);
			if(erg!=-1){
				return ("");
			}
		}
		return (mail);
	}
	//checkboxes & radio buttons
	if(vType=="checkbox"||vType=="radiobutton"){
		if(theField.value==null){
			//if we're here, we are validating a radio button or a nn multi-element checkbox
			for ( i=0; i<theField.length; i++){
				if(theField[i].checked){
					hits++;
					if(hits==1){
						theValue=theField[i].value;
					}else{
						theValue+= sep+theField[i].value;
					}
				} 
			}
		} 
		return(theValue);
	}else{
		return(theField.value);
	}
}

/* Use this function to open a link. Use any htmltag with parameter "value (URL [|"_self"])"  to open the url. */

function openElementLink(objField,sType){
var sFieldValue=getFieldValue(objField,sType);

if (sFieldValue!=""){
	var aValue=sFieldValue.split("|");
	if(aValue[1]=="_self"){
		 location.href=aValue[0];
	}
	else{
		window.open(aValue[0]);
	}
}
}

/*Bottomline*/
function addToFavoritesDE(pagename){
	var errmsg="Ihr Browser unterstützt leider kein automatisches Hinzufügen von Seiten zu den Favoriten. Vermutlich handelt es sich nicht um den Internet Explorer. Bitte verwenden Sie das entsprechende Menü-Kommando ihres Browsers, um diese Seite zu Ihren Lesezeichen hinzuzufügen. Vielen Dank!";
	return addToFavorites(pagename,errmsg);
}
function addToFavoritesEN(pagename){
	var errmsg="Your browser does not support automated adding to favourites, probably you are not using Internet Explorer. However, please yuse your browsers menu command for bookmarking instead. Thank you!";
	return addToFavorites(pagename,errmsg);
}

function addToFavorites(pagename,errmsg){
var adress=window.location.href;
if(document.all){
window.external.addFavorite(adress,pagename);
}
else{
alert(errmsg);
}
}

function setCookie(name,value,expires,path,domain,secure){
	var curCookie=name+"="+escape(value)+
	((expires)?"; expires="+expires.toGMTString():"")+
	((path)?"; path="+path:"")+
	((domain)?"; domain="+domain:"")+
	((secure)?"; secure":"");
	document.cookie=curCookie;
}

function getCookie(name){
	var dc=document.cookie;
	var prefix=name+"=";
	var begin=dc.indexOf("; "+prefix);
	if(begin==-1){
		begin=dc.indexOf(prefix);
		if(begin!=0) return null;
	} 
	else begin+=2;
	var end=document.cookie.indexOf(";", begin);
	if(end==-1) end=dc.length;
	return unescape(dc.substring(begin+prefix.length, end));
}

/*Zoom Box*/
var iZoom=100;
function xWindowZoom(sMode){
var iPercent=10;
var objBody=document.body;
if (iZoom==0) return false
if (sMode=="in"){
		 iZoom=iZoom+iPercent;
}
else if (sMode=="out"){
		 iZoom=iZoom+iPercent*-1;
}
else{
iZoom=100;
}
sZoomPercent=String(iZoom)+"%";
objBody.style.fontSize=sZoomPercent;
}

function openNewWindowOPM(sUrl)
{
openNewWindow(sUrl,'400','200','0','0','scrollbars=no,resizable=no');
}

/************************ BEGIN BOX *************************/

/*Box - Quicksearch validation*/

function validateQuicksearch(objForm,sFieldname, sPreset) {
var sLanguage=language.toUpperCase();
var message="Please enter a searchstring!";
var sValue=objForm.elements[sFieldname].value;
if (sValue==sPreset){
	return false;
}
if (sValue==""){
if (sLanguage=="DE"){
message="Bitte geben Sie einen Suchbegriff ein!"
}
alert(message)
return false;
}
else{
return true;
}
}

/*Box - Login validation*/

function validateLogin(objform) {
var sLanguage=language.toUpperCase();
var sUsername=objform.elements["Username"].value;
var sPassword=objform.elements["Password"].value;
document.cookie="sessionCookie=troet";
if (getCookie("sessionCookie")==""){
alert ("Please enable sessionbased cookies in your browser \npreferences and reload the page!");
return false;
}
else if ((sUsername=="")||(sUsername=="Name")) {
if (sLanguage=="DE"){
alert ("Bitte geben sie ihren Usernamen ein!");
}
else{
alert ("Please enter your username!");
}
objform.elements["Username"].focus();
return false;
}
else if ((sPassword=="")||(sPassword=="Passwort")){
if (sLanguage=="DE"){
alert ("Bitte sie ihr Passwort ein!");
}
else{
alert ("Please enter your password!");
}
objform.elements["Password"].focus();
return false;
}
else{
var sAction=objform.action;
sAction=sAction+"&Username="+sUsername;
objform.action=sAction;
objform.submit();
return true;
}
}

/************************ END BOX *************************/

/************************ SHOW IMAGE *************************/

/**
 * displays an image in a div
 *
 * @param		initiator		object		the ojbect who initiated the call
 * @param		imageName	string		the filename of the image to be shown
 *
 * @author		Bernd Hort <bhort@assono.de>
 * @version		2007-10-31
 */
function showImage(initiator, imageName, imageWidth, imageHeight){
	
	var div = $('imagepreview');
	if (div==null){
		div = document.createElement('div');
		div.id = 'imagepreview';
		document.body.appendChild(div);
		div.style.position="absolute";
		div.style.width=imageWidth + 'px';
		div.style.height=(imageHeight + 15) + 'px';
		div.style.display="none";		
		div.style.background = "#ffffff";
		div.style.border="1px solid #5F82B4";
		div.style.padding="5px";
	}
	
	if (div.style.display!="block") {
	
	var left = initiator.offsetLeft;
	var top = initiator.offsetTop + initiator.offsetHeight;
	var parent = initiator;
	while (parent.offsetParent) {
		parent = parent.offsetParent;
		left += parent.offsetLeft;
		top += parent.offsetTop;
	}
	initiatorTop = top - initiator.offsetHeight;
	
	div.style.left = (left + 5) + 'px';
	div.style.top = (initiatorTop + 5) + 'px';
	div.style.width=imageWidth + 'px';
	div.style.height=(imageHeight + 15) + 'px';
	
	div.innerHTML = '&nbsp;<a href="#" onclick="hideImage();return false;">Schlie&szlig;en</a><br><img src="' + imageName + '" width="' + imageWidth + '" height="' + imageHeight + '" onclick="hideImage();">';
	div.style.display = "block";
}
}// 	showImage

/**
 * hides the div with an image 
 *
 * @author		Bernd Hort <bhort@assono.de>
 * @version		2007-10-31
 */
function hideImage(){
	
	var div = $('imagepreview');
	if (div!=null){
		div.style.display = "none";
	}
}// 	hideImage

/************************ END SHOW IMAGE *************************/

/************************ SHOW VIDEO *************************/
/**
 * displays an image in a div
 *
 * @param		initiator		object		the ojbect who initiated the call
 * @param		videoURL	string		the url of the video
 *
 * @author		Bernd Hort <bhort@assono.de>
 * @version		2009-05-20
 */
var player = null;
function showVideo(initiator, videoURL, textNoVideo, imageWidth, imageHeight){
	
	var div = $('imagepreview');
	if (div==null){
		div = document.createElement('div');
		div.id = 'imagepreview';
		document.body.appendChild(div);
		div.style.position="absolute";
		div.style.width=imageWidth + 'px';
		div.style.height=(imageHeight + 15) + 'px';
		div.style.display="none";		
		div.style.background = "#ffffff";
		div.style.border="1px solid #5F82B4";
		div.style.padding="5px";
	}
	
	if (div.style.display!="block") {
	
	var left = initiator.offsetLeft;
	var top = initiator.offsetTop + initiator.offsetHeight;
	var parent = initiator;
	while (parent.offsetParent) {
		parent = parent.offsetParent;
		left += parent.offsetLeft;
		top += parent.offsetTop;
	}
	initiatorTop = top - initiator.offsetHeight;
	
	div.style.left = (left + 5) + 'px';
	div.style.top = (initiatorTop + 5) + 'px';
	div.style.width=(imageWidth + 10) + 'px';
	div.style.height=(imageHeight + 45) + 'px';
	
	div.innerHTML = '&nbsp;<a href="#" onclick="hideVideo();return false;">Schlie&szlig;en</a><br><div id="video" style="text-align: center"><div style="border: #606B9F 1px solid; padding: 5px; width: ' + imageWidth + 'px; height: ' + imageHeight+ 'px; vertical-align: middle; background: #F0F0F0;margin-left: auto; margin-right: auto;">' + textNoVideo + '<br><br>Wenn Sie kein Video sehen, <br>ben&ouml;tigen Sie den <a href="http://www.macromedia.com/go/getflashplayer">Flash Player</a>.</div></div><div style="color:#888888;font-size:11px;">Wenn Sie in dem Videofenster auf das Icon <img src="' + dbpath + '/files/img/$file/icon_vollbildmodus.gif" width="11" height="11"> klicken, wird das Video im Vollbildmodus ge&ouml;ffnet.</div>';	
	player = new SWFObject('../player.swf','ply', imageWidth,imageHeight,'9','#FFFFFF');
	player.addParam('allowfullscreen','true');
	player.addParam('allowscriptaccess','always');
	player.addParam('flashvars','file=' +  dbpath + '/id/' + videoURL + '&autostart=true');
	player.write("video");
		
	div.style.display = "block";
}
}// 	showVideo

/**
 * hides the div with an image 
 *
 * @author		Bernd Hort <bhort@assono.de>
 * @version		2007-10-31
 */
function hideVideo(){
	
	var div = $('imagepreview');
	if (div!=null){
		document.body.removeChild(div);		
	}
}// 	hideImage

/************************ END SHOW VIDEO *************************/

/************************ ALTERNATE PICTURE *************************/
/**
 * changes the displayed image
 *
 * @param	imageID		string	the id of the image to be displayed
 * @param	fileNamesArray	array	an array with all filenames to be displayed
 * @param	interval	number	the intervall for changing the picture
 *
 * @author	Bernd Hort <bhort@assono.de>
 * @version	2010-05-05
 */
function alternatePicture(imageID, fileNamesArray, interval){
	var image = $(imageID);
	if (image == null){return false};
	
	var fileNamesArrayAsString = "[";
	var currentFilename = image.src.replace(/.*\/\$file\/(.*)/ig, "$1");
	for (var i = 0; i < fileNamesArray.length; ++i){
		if(fileNamesArray[i]==currentFilename){
			//check if there is an entry behind the current entry
			if(i<(fileNamesArray.length-1)){
				image.src = image.src.replace(/(.*\/\$file\/)(.*)/ig, "$1" + fileNamesArray[i+1]);
			} else {
				image.src = image.src.replace(/(.*\/\$file\/)(.*)/ig, "$1" + fileNamesArray[0]);
			}
		}
		if (i!=0){
 			fileNamesArrayAsString = fileNamesArrayAsString + ",";
		}
		fileNamesArrayAsString = fileNamesArrayAsString + "'" + fileNamesArray[i] + "'";

	}
	fileNamesArrayAsString = fileNamesArrayAsString + "]";
	var call = "alternatePicture('" + imageID + "'," + fileNamesArrayAsString + ","+ interval + ")";
	window.setTimeout(call, interval);	
	return true;	
}
/**
 * starter function for alternate pictures
 *
 * @param	imageID			string	the id of the image to be displayed
 * @param	fileNamesArrayAsString	string	an array with all filenames to be displayed as a string
 * @param	interval		number	the intervall for changing the picture
 *
 * @author	Bernd Hort <bhort@assono.de>
 * @version	2010-05-05
 */
function startAlternatePicture(imageID, fileNamesArrayAsString, interval){	
	var call = "alternatePicture('" + imageID + "'," + fileNamesArrayAsString + ","+ interval + ")";
	window.onload = function(){window.setTimeout(call, interval)};
}

/************************ END ALTERNATE PICTURE *************************/
/**
 * FormValidator - validates a form
 *
 * Inspired by  
 * http://www.devshed.com/c/a/JavaScript/Form-Validation-with-JavaScript
 * 
 * @author Bernd Hort <bhort@assono.de>
 * @version 2007-11-16
 * 
 */ 

/* Usage: But code like this into the form
// check form values
function checkForm()
{
// instantiate object
fv = new formValidator();
// perform checks
// Salutation
fv.checkNotEmpty('Salutation', 'Bitte wählen Sie die Anrede aus.');
// Firstname
fv.checkNotEmpty('Firstname', 'Bitte tragen Sie Ihren Vornamen ein.');
// Lastname
fv.checkNotEmpty('Lastname', 'Bitte tragen Sie Ihren Nachnamen ein.');
// StreetAddress
fv.checkNotEmpty('StreetAddress', 'Bitte geben Sie die Straße und Hausnummer an.');
// Zip
fv.checkNotEmpty('Zip', 'Bitte geben Sie die Postleitzahl an.');
// City
fv.checkNotEmpty('City', 'Bitte geben Sie den Ort an.');
// Country
fv.checkNotEmpty('Country', 'Bitte wählen Sie das Land aus.');
// PhoneNumber
fv.checkNotEmpty('PhoneNumber', 'Bitte geben Sie die Telefonnummer an.');
// MailAddress
fv.checkValidEMail('MailAddress', 'Bitte geben Sie eine gültige E-Mail-Adresse an.');
// if errors, display, else proceed
return fv.isValid();
}

And add at the onSubmit event the following code
return checkForm();
*/

// create object
function formValidator(formname)
{
		 //formName
		 this.formname = formname;
		 
		 // set up array to hold error messages
		 this.errorList = new Array;

 		 this.borderColorMarked = '#800000';
 		 this.borderColorUnmarked = 'none';

		 // set up object methods
		 this.isEmpty = isEmpty;		 
		 this.isNumber = isNumber;		 
		 this.isAlphabetic = isAlphabetic;		 
		 this.isAlphaNumeric = isAlphaNumeric;		 
		 this.isWithinRange = isWithinRange;		 
		 this.isEmailAddress = isEmailAddress;		 
		 this.isChecked = isChecked;		 

		 this.checkNotEmpty = checkNotEmpty;
		 this.checkValidEMail = checkValidEMail;
				
		 this.raiseError = raiseError;		 
		 this.numErrors = numErrors;		 
		 this.displayErrors = displayErrors;		 
		 
		 this.isValid = isValid;
		 
		 this.unmarkField = unmarkField;
		 this.markField = markField;
		 
}

// check to see if input is whitespace only or empty
function isEmpty(val)
{
		 if (val.match(/^s+$/) || val == "")
		 {
		 		 return true;
		 }
		 else
		 {
		 		 return false;
		 }		 
}

// check to see if input is number
function isNumber(val)
{
		 if (isNaN(val))
		 {
		 		 return false;
		 }
		 else
		 {
		 		 return true;
		 }		 
}

// check to see if input is alphabetic
function isAlphabetic(val)
{
		 if (val.match(/^[a-zA-Z]+$/))
		 {
		 		 return true;
		 }
		 else
		 {
		 		 return false;
		 }		 
}

// check to see if input is alphanumeric
function isAlphaNumeric(val)
{
		 if (val.match(/^[a-zA-Z0-9]+$/))
		 {
		 		 return true;
		 }
		 else
		 {
		 		 return false;
		 }		 
}

// check to see if value is within range
function isWithinRange(val, min, max)
{
		 if (val >= min && val <= max)
		 {
		 		 return true;
		 }
		 else
		 {
		 		 return false;
		 }		 
}

// check to see if input is a valid email address
function isEmailAddress(val)
{
		 //if (val.match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/))
		 if (val.match(/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i))		 
		 {
		 		 return true;
		 }
		 else
		 {
		 		 return false;
		 }		 
}

// check to see if form value is checked
function isChecked(obj)
{
		 if (obj.checked)
		 {
		 		 return true;
		 }
		 else
		 {
		 		 return false;
		 }		 
}

// display all errors
// iterate through error array and print each item
function displayErrors()
{
		var msg = "";
		 for (x=0; x<this.errorList.length; x++)
		 {
		 	msg = msg + this.errorList[x] + "\n";		 
		 }
		 alert("Fehler bei der Validierung der Eingabe:\n" + msg);
}

// add an error to error list
function raiseError(msg)
{
		 this.errorList[this.errorList.length] = msg;
}

// return number of errors in error array
function numErrors()
{
		 return this.errorList.length;
}


// checks and raises an error if is empty
function checkNotEmpty(fieldname, msg)
{
	var theField = document.forms[this.formname].elements[fieldname];
	var isEmptyValue = true;
	
	if(theField == null){
		//this.raiseError(msg);		
		return;
	}
			
	//Test for an array (radio buttons, checkboxes)
	if (theField.length != null && theField.type == null ){		//for selection the type is not null
		for (i = 0; i < theField.length; i ++) {
  			if (theField[i].checked) {
   				isEmptyValue = false;   // as long as one is chosen this gets set true
  			}		
		}							
	} else {
		if (theField.type.substr(0,6) =='select'){
			var i = 0;		
			while((i<theField.options.length) && isEmptyValue == true){
				if(theField.options[i].selected){
					if(isEmpty(theField.options[i].value) == false || isEmpty(theField.options[i].text) == false){
						isEmptyValue = false;
					}
				};
				i++;				
			};
		} else {
			isEmptyValue = isEmpty(theField.value)
		}					
	} //not an array
	
	
	if (isEmptyValue){
		this.raiseError(msg);
		this.markField(fieldname);
	} else {
		this.unmarkField(fieldname);
	}


}

// checks and raises an error if is empty
function checkValidEMail(fieldname, msg)
{
	if (isEmpty(document.forms[this.formname].elements[fieldname].value) || !isEmailAddress(document.forms[this.formname].elements[fieldname].value)){
		this.raiseError(msg);
		this.markField(fieldname);
	} else {
		this.unmarkField(fieldname);
	}
}

//mark the field
function markField(fieldname){
	var theField = document.forms[this.formname].elements[fieldname];
	
	if (theField == null) {return};
	
	//check for an array
	if (theField.length != null){
		for (i = 0; i < theField.length; i ++) {
  			if (this.borderColorMarked.toLowerCase =="none" || this.borderColorMarked ==""){		
				theField[i].style.border = "none";		
			} else {
				theField[i].style.border = "3px solid " + this.borderColorMarked;
			}	
  		}		
	} else {	
		if (this.borderColorMarked.toLowerCase =="none" || this.borderColorMarked ==""){		
			theField.style.border = "none";		
		} else {
			theField.style.border = "3px solid " + this.borderColorMarked;
		}	
	}
}

//unmark the field
function unmarkField(fieldname){
	var theField = document.forms[this.formname].elements[fieldname];
	
	if (theField == null) {return};
	
	//check for an array
	if (theField.length != null){
		for (i = 0; i < theField.length; i ++) {
  			if (this.borderColorMarked.toLowerCase =="none" || this.borderColorMarked ==""){		
				theField[i].style.border = "none";		
			} else {
				theField[i].style.border = "1px solid " + this.borderColorUnmarked;
			}	
  		}		
	} else {	
		if (this.borderColorMarked.toLowerCase =="none" || this.borderColorMarked ==""){		
			theField.style.border = "none";		
		} else {
			theField.style.border = "1px solid " + this.borderColorUnmarked;
		}	
	}	
}


// checks if this document is valid
function isValid()
{
	// all done
	// if errors, display, else proceed
	if (this.numErrors() > 0)
	{
		this.displayErrors();
		return false;
	}
	else
	{
		return true;
	}
}

// end object 
