function bildpopup(source, title, alt)
{
  	var undefined;

  	if(alt == undefined)
		alt = 'Bild';

  	if(title == undefined)
  		title = 'Bildvorschau';

  	windowObj = window.open('','','width=100,height=100,scrollbars=no,resizable=no,toolbars=no,menubar=no,location=no,status=no');

	with (windowObj)
	{
	   	focus();
	   	document.open();
		document.write(
			'<!DOCTYPE html' + "\n" +
     		' PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' + "\n" + 
    		' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' + "\n" + 
			'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">' + "\n" + 
  			'<head>' + "\n" +  	
			'<title>' + title + '</title>' + "\n" + 
			'<meta http-equiv="Content-type" content="text/html; charset=utf-8" />' + "\n" + 
			'<meta name="author" content="M.Sc., B.Sc. R. Kuntze" />' + "\n" + 
			'<meta name="robots" content="noindex, nofollow" />' + "\n" + 
			'<meta name="keywords" content="Gallery" />' + "\n" + 
			'<meta name="description" content="Gallery - Administration" />' + "\n" + 
			'<meta name="generator" content="Gallery" />' + "\n" + 	
			'<base href="' + opener.document.getElementsByTagName("base")[0].getAttribute("href") + '" />' + "\n" + 
			'<link rel="shortcut icon" type="image/x-icon" href="./img/favicon.ico" />' + "\n" + 		
			'<link rel="stylesheet" href="./lib/module_layout.css" type="text/css" />' + "\n" + 
 			'</head>' + "\n" +
 			'<body style="margin:10px; padding:0px" onload="opener.resizeWindow(document.images[0].width, document.images[0].height)">' + "\n" +
 			'<div>' + "\n" +
 			'<a href="#" onclick="self.close(); return false;">' +
	   		'<img style="border: 1px solid black" src="' + source + '" alt="' + alt + '" /></a>' + "\n" +
			'</div>' + "\n" +
 			'</body>' + "\n" +
 			'</html>'			 
		);
	   	document.close();
	}
}

function vidpopup(source, title, width, height)
{
  	var undefined;
 
  	if(title == undefined)
  		title = 'Videovorschau';

  	windowObj = window.open('','','width=100,height=100,scroll=no,resizable=no,toolbars=no,menubar=no,location=no,status=no');

	with (windowObj)
	{
	   	focus();
	   	document.open();
		document.write(
			'<!DOCTYPE html' + "\n" +
     		' PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' + "\n" + 
    		' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' + "\n" + 
			'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">' + "\n" + 
  			'<head>' + "\n" +  	
			'<title>' + title + '</title>' + "\n" + 
			'<meta http-equiv="Content-type" content="text/html; charset=utf-8" />' + "\n" + 
			'<meta name="author" content="M.Sc., B.Sc. R. Kuntze" />' + "\n" + 
			'<meta name="robots" content="noindex, nofollow" />' + "\n" + 
			'<meta name="keywords" content="Gallery" />' + "\n" + 
			'<meta name="description" content="Gallery - Administration" />' + "\n" + 
			'<meta name="generator" content="Gallery" />' + "\n" + 	
			'<base href="' + opener.document.getElementsByTagName("base")[0].getAttribute("href") + '" />' + "\n" + 
			'<link rel="shortcut icon" type="image/x-icon" href="./img/favicon.ico" />' + "\n" + 		
			'<link rel="stylesheet" href="./lib/page_layout.css" type="text/css" />' + "\n" + 
 			'</head>' + "\n" +
 			'<body style="margin:10px; padding:0px" onload="opener.resizeWindow(' + width + ', ' + height + ')">' + "\n" +
 			'<div>' + "\n" +
 			'<script type="text/javascript" src="./module/Gallery/lib/ufo.js"></script>' + "\n" +
            '<p id="flvplayer"></p>' + "\n" +
      		'<script type="text/javascript">' + "\n" +
      		' /*<![CDATA[*/' + "\n" +
			'var FO = {	movie:"./module/Gallery/lib/flvplayer.swf?file=./' + source + '",' + "\n" +
			'width:"' + width + '",height:"' + height + '",majorversion:"7",build:"0",bgcolor:"#fff",' + "\n" +
			'flashvars:"showdigits=false&autostart=true&showfsbutton=false&repeat=false" };' + "\n" +
			'UFO.create( FO, "flvplayer");' + "\n" +
      		' /*]]>*/' + "\n" +
      		'</script>' + "\n" +
			'</div>' + "\n" +
 			'</body>' + "\n" +
 			'</html>'			 
		);
	   	document.close();
	   	
	   	// IE-Fix
	   	location.reload();
	}
}

function resizeWindow(x, y)
{
	// neue Lösung mit Hilfe des Prototype-Frameworks (getWindowSize), die Browserunabhängig exakt(!) skaliert
	windowObj.resizeTo(x, y);
	var array = getWindowSize(windowObj);
	var newX = x + (x - array[0]) + 20;
	var newY = y + (y - array[1]) + 20;
	windowObj.resizeTo(newX, newY);
	windowObj.moveTo((screen.width/2)-(newX/2), (screen.height/2)-(newY/2));
}

function getWindowSize(w) 
{
    var array = [];

    w = w ? w : window;
    array.width = array[0] = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
    array.height = array[1] = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);

    return array;
}

function setCookie(name, value, domain, path, expires, secure)
{
  // Cookie setzen (wird später im TypoScript ausgelesen)
  var cook = name + "=" + unescape(value);
   cook += (domain) ? "; domain=" + domain : "";
   cook += (expires) ? "; expires=" + expires : "";
   cook += (path) ? "; path=" + path : "";

   cook += (secure) ? "; secure" : "";
   document.cookie = cook;
}

function getCookie(name) 
{
   var i=0;  //Suchposition im Cookie
   var suche = name + "=";
   while (i < document.cookie.length) 
   {
      if (document.cookie.substring(i, i + suche.length) == suche) 
	  {
         var ende = document.cookie.indexOf(";", i + suche.length);
         if(ende == -1)
         	ende = document.cookie.length;
         var cook = document.cookie.substring(i + suche.length, ende);
         return unescape(cook);
      }
      i++;
   }
   return "";
}

function AddToFavorites(url, title)
{
	if ((navigator.appName == "Microsoft Internet Explorer") &&
	(parseInt(navigator.appVersion) >= 4))
	{
		window.external.AddFavorite(url,title)
	}
	else
	{
		var FavText = "Fügen Sie die Seite bitte mit den Tasten STRG+D zu ihren Favoriten hinzu.";
		alert(FavText);
	}
}

function Go(x)
{
 if(x == "nothing")
 {
   document.forms[0].reset();
   document.forms[0].elements[0].blur();
   return;
 }
 else if(x == "end") top.location.href = location;
 else
  {
   location.href = x;
   document.forms[0].reset();
   document.forms[0].elements[0].blur();
  }
}

function imagePreloader()
{
	var BildArray = new Array();

	/* 
	BildArray[0] = "image/menu-back.jpg";
	BildArray[1] = "image/menu-back_over.jpg";
	BildArray[2] = "image/menu-back2.jpg";
	BildArray[3] = "image/menu-back2_over.jpg";
	BildArray[4] = "image/button_oben1.jpg";
	BildArray[5] = "image/button_oben2.jpg";
	*/

	for (i=0; i < BildArray.length; i++) {
	  var Bild = new Image();
	  Bild.src = BildArray[i];
	}
}

function page_checkForm(formID, langID)
{
	if(langID == null)
		langID = 'de';
		
	var ERRCODE = new Array();
		ERRCODE['de'] = new Object();
		ERRCODE['de']['single'] = 'Das markierte Feld (%1) beinhaltet keine oder eine fehlerhafte Eingabe.';
		ERRCODE['de']['multiple'] = 'Die markierten Felder (%1) beinhalten keine oder fehlerhafte Eingaben.';

		ERRCODE['en'] = new Object();
		ERRCODE['en']['single'] = 'The selected field (%1) contains no or an incorrect entry.';
		ERRCODE['en']['multiple'] = 'The selected fields (%1) contain no or incorrect entries.';

		ERRCODE['fr'] = new Object();
		ERRCODE['fr']['single'] = 'Le champ sélectionné (%1) ne comprend pas ou entrées incorrectes.';
		ERRCODE['fr']['multiple'] = 'Les champs marqués (%1) ne comprennent pas ou entrées erronées.';

	var necessary = $(formID)['necessary'].value;
    var temp = new Array();
    var ok = true;
    var formularerror = '';
    var errorfields = new Array();
    
    temp = necessary.split(';');
	var i = 0;
		
    for (var n = 0; n < temp.length; n++)
    {
    	var type = $(formID)[temp[n]].type;
    	
		if(type == undefined)
		{
			var radioerror = true;
			for (var k = 0; k < $(formID)[temp[n]].length; k++)
			{						
				if(document.forms[formID][temp[n]][k].checked){
					radioerror = false;
				}								
			}
			
			if(!radioerror)
				for (var k = 0; k < $(formID)[temp[n]].length; k++)
					$(formID)[temp[n]][k].style.border = '0px';
			else
			{
	            ok = false;
	        	errorfields[i++] = temp[n];
				for (var k = 0; k < $(formID)[temp[n]].length; k++)
					$(formID)[temp[n]][k].style.border = '1px solid #f00';
			}
		}     
		else if(type == 'checkbox')    
		{
			if($(formID)[temp[n]].checked)
			{
				$(formID)[temp[n]].style.border = '0px';				
			}
			else
			{
	            ok = false;
	        	errorfields[i++] = temp[n];
				$(formID)[temp[n]].style.border = '1px solid #f00';				
			}				
		}
		else
		{       	
	        if($(formID)[temp[n]].value == '')
	        {
	            ok = false;
	        	errorfields[i++] = temp[n];
				$(formID)[temp[n]].style.border = '1px solid #f00';
	        }		
	   		else
				$(formID)[temp[n]].style.border = '1px solid #666';
		}
	}

    if($(formID)['E-Mail'].value != '')
    {
	    if(!emailCheck($(formID)['E-Mail'].value))
        {
        	ok = false;
        	errorfields[i++] = 'E-Mail';
            $(formID)['E-Mail'].style.border = '1px solid #f00';
        }
    }

    if(ok)
        return true;
	else
	{
		var error = '';
		for (var j = 0; j < errorfields.length; j++)
    	{	
    		error += errorfields[j];
    		if(j < (errorfields.length-1))
    			error += ', ';
    	}
    	if(errorfields.length > 1)
    		formularerror = ERRCODE[langID]['multiple'];    
    	else
    		formularerror = ERRCODE[langID]['single'];		
    		
    	$('page_form_error').innerHTML = formularerror.replace('%1', error);
        $('page_form_error').style.display = 'block';
        
        return false;
    }
}

function emailCheck (emailStr) 
{
    /* The following variable tells the rest of the function whether or not
    to verify that the address ends in a two-letter country or well-known
    TLD.  1 means check it, 0 means don't. */
    
    var checkTLD=1;
    
    /* The following is the list of known TLDs that an e-mail address must end with. */
    
    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    
    /* The following pattern is used to check if the entered e-mail address
    fits the user@domain format.  It also is used to separate the username
    from the domain. */
    
    var emailPat=/^(.+)@(.+)$/;
    
    /* The following string represents the pattern for matching all special
    characters.  We don't want to allow special characters in the address. 
    These characters include ( ) < > @ , ; : \ " . [ ] */
    
    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
    
    /* The following string represents the range of characters allowed in a 
    username or domainname.  It really states which chars aren't allowed.*/
    
    var validChars="\[^\\s" + specialChars + "\]";
    
    /* The following pattern applies if the "user" is a quoted string (in
    which case, there are no rules about which characters are allowed
    and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    is a legal e-mail address. */
    
    var quotedUser="(\"[^\"]*\")";
    
    /* The following pattern applies for domains that are IP addresses,
    rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    e-mail address. NOTE: The square brackets are required. */
    
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    
    /* The following string represents an atom (basically a series of non-special characters.) */
    
    var atom=validChars + '+';
    
    /* The following string represents one word in the typical username.
    For example, in john.doe@somewhere.com, john and doe are words.
    Basically, a word is either an atom or quoted string. */
    
    var word="(" + atom + "|" + quotedUser + ")";
    
    // The following pattern describes the structure of the user
    
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    
    /* The following pattern describes the structure of a normal symbolic
    domain, as opposed to ipDomainPat, shown above. */
    
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
    
    /* Finally, let's start trying to figure out if the supplied address is valid. */
    
    /* Begin with the coarse pattern to simply break up user@domain into
    different pieces that are easy to analyze. */
    
    var matchArray=emailStr.match(emailPat);
    
    if (matchArray==null) {
    
    /* Too many/few @'s or something; basically, this address doesn't
    even fit the general mould of a valid e-mail address. */
    
    //alert("Email address seems incorrect (check @ and .'s)");
    return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];
    
    // Start by checking that only basic ASCII characters are in the strings (0-127).
    
    for (i=0; i<user.length; i++) {
    if (user.charCodeAt(i)>127) {
    //alert("Ths username contains invalid characters.");
    return false;
       }
    }
    for (i=0; i<domain.length; i++) {
    if (domain.charCodeAt(i)>127) {
    //alert("Ths domain name contains invalid characters.");
    return false;
       }
    }
    
    // See if "user" is valid 
    
    if (user.match(userPat)==null) {
    
    // user is not valid
    
    //alert("The username doesn't seem to be valid.");
    return false;
    }
    
    /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */
    
    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {
    
    // this is an IP address
    
    for (var i=1;i<=4;i++) {
    if (IPArray[i]>255) {
    //alert("Destination IP address is invalid!");
    return false;
       }
    }
    return true;
    }
    
    // Domain is symbolic name.  Check if it's valid.
     
    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) {
    if (domArr[i].search(atomPat)==-1) {
    //alert("The domain name does not seem to be valid.");
    return false;
       }
    }
    
    /* domain name seems valid, but now make sure that it ends in a
    known top-level domain (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding 
    the domain or country. */
    
    if (checkTLD && domArr[domArr.length-1].length!=2 && 
    domArr[domArr.length-1].search(knownDomsPat)==-1) {
    //alert("The address must end in a well-known domain or two letter " + "country.");
    return false;
    }
    
    // Make sure there's a host name preceding the domain.
    
    if (len<2) {
    //alert("This address is missing a hostname!");
    return false;
    }
    
    // If we've gotten this far, everything's valid!
    return true;
}

function get_radio_value(obj)
{
	var rad_val = '';
	for (var i=0; i < obj.length; i++)
   		if (obj[i].checked)
      		rad_val = obj[i].value;
    return rad_val;
}

function setFontSize(name, value) {
        setCookie(name, value, null, '/');
        var idelement = document.getElementsByTagName("body")[0];
        idelement.style.fontSize = value + "px";
}

function actualFontsize(name) {
        value = getCookie(name);
        if (value && value != 0) {
	        var idelement = document.getElementsByTagName("body")[0];
	        idelement.style.fontSize = value + "px";
        }
}