
/* ahrenkiel_main Version 2007-11-14 22-17-22 */


/**
 * 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;
	}		
}

/**
 * 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) {
var sLanguage=language.toUpperCase();
var message="Please enter a searchstring!";
var sValue=objForm.elements[sFieldname].value;
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-11-08
 */
function showImage(resourceID, imageName, imageWidth, imageHeight, imageAlt, imageCaption, fullsizeImageName, closeText, downloadText){
	
	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="auto";
		div.style.display="none";		
		div.style.background = "#000066";
		div.style.border="3px solid #eeeeee";
		div.style.padding="5px";
	}
	
	var initiator = $('preview-anchor');
	
	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 - 50) + 'px';
	div.style.top = (initiatorTop + 5) + 'px';
	
	div.innerHTML = '<div class="closeButton"><a href="#" onclick="hideImage();return false;">' + closeText + '</a></div>' + 
	'<div class="picture"><img src="../res/' + resourceID + '/$file/' + imageName +'" width="' + imageWidth + '" height="' + imageHeight + '" alt="' + imageAlt + '" title="'+ imageAlt + '"></div>' + 
	'<div class="pictureText">' + imageCaption + '</div>'+ 
	'<div class="downLoad">' + downloadText + '<br><a href="../res/' + resourceID + '/$file/' + fullsizeImageName + '" title="' + imageAlt + '">' + fullsizeImageName + '</a></div>'
	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


/**
 * show a single image instead of the gallery
 *
 * @author		Bernd Hort <bhort@assono.de>
 * @version		2007-11-14
 */
function showSingleImage(newUrl, windowWidth, windowHeight){
	//window.resizeTo(windowWidth, windowHeight);	
	window.location.href = newUrl;
}

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

/**
 * Resizes the window to fit
 *
 * @author		Bernd Hort <bhort@assono.de>
 * @version		2007-11-14
 */
function resizeToFit(divID, backupWindowWidth, backupWindowHeight){
	var div = $(divID);
	if (div!=null){
		if (div.innerHeight) // all except Explorer
		{
			var deltaWidth = window.outerWidth - window.innerWidth;
			var deltaHeight = window.outerHeight - window.innerHeight;
			window.resizeTo(div.offsetWidth + deltaWidth, div.offsetHeight+deltaHeight);
		}	else {
			window.resizeTo(backupWindowWidth, backupWindowHeight)
		}			
	}	
}
