function is_defined( x ) {
    return (typeof(window[x]) != "undefined");
}

function getScreenSize() {
	var screenH = screen.height;
    var screenW = screen.width;
    if(document.all){
        x = document.body.clientWidth;
        y = document.body.clientHeight;
    }
	if(isIE5() || isIE6() ) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	return new Array( x, y );
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie( name, value, expires, path, domain, secure )  {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
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));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


function chgImg( pImg, pUrl ) {
	
	newImg 		= new Image();
	newImg.src 	= pUrl;
	imgSrc		= document[ pImg ].src;
	
	imgSrc			= newImg.src;
	
	if( imgSrc == null ) {
		alert( imgSrc + " == null" );
	}
}

function alternativeEntities(string){
	index = 0;
	var anArray = new Array(2);
	anArray[0]  = new Array (	"ä",		'Ä',		'ö',		'Ö',		'ü',		'Ü',		'ß',		'å',		'Å',		'ø',		'Ø',		'æ',		'Æ'			);
	anArray[1]  = new Array (	"&auml;",	'&Auml;',	'&ouml;',	'&Ouml;',	'&uuml;',	'&Uuml;',	'&szlig;',	'&aring;',	'&Aring;',	'&oslash;',	'&Oslash;',	'&aelig;',	'&AElig;'	);	
	
	for (var i=0; i<anArray[index].length; i++){
		myRegExp = new RegExp(anArray[index][i],"g");
		string = string.replace(myRegExp, anArray[(index==0?1:0)][i]);
	}
	return string;
}

function highlightNav(x,y) {}
function SafeOurSouls(x,y,z) {}
window.onerror=SafeOurSouls;

function inputInsert(input, aTag, eTag) {
  input.focus();
  /* IE */
  if(typeof document.selection != 'undefined') {
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
    /* Gecko */
  } else if(typeof input.selectionStart != 'undefined') {
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  	/* Misc */
  } else {
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}

function fixPNG(imgsrc) {
    if (window.ie55up) {
		 var imgID = (imgsrc.id) ? "id='" + imgsrc.id + "' " : ""
		 var imgClass = (imgsrc.className) ? "class='" + imgsrc.className + "' " : ""
		 var imgTitle = (imgsrc.title) ? "title='" + imgsrc.title + "' " : "title='" + imgsrc.alt + "' "
		 var imgStyle = "display:inline-block;" + imgsrc.style.cssText 
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 strNewHTML += " style=\"" + "width:" + imgsrc.width + "px; height:" + imgsrc.height + "px;" + imgStyle + ";"
		 strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 strNewHTML += "(src=\'" + imgsrc.src + "\', sizingMethod='scale');\"></span>" 
		 imgsrc.outerHTML = strNewHTML
	 }
}

function correctPNGs() {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
}
if (window.attachEvent) {
	window.attachEvent("onload", correctPNGs);
}
   
function printVersion(url) {
	Fenster1 = window.open(url,'','toolbar=yes,menubar=yes,scrollbars=yes,resizable=1,width=600,height=600');
	Fenster1.focus();
}

function trim(str) { 
	return str.replace(/^\s+|\s+$/, '');
}
function trimNL(str) { 
	return str.replace(/\n/g, '');
}

function isIE() {
	return ( /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) );
}
function isIE5() {
	return ( /msie 5\.0/i.test(navigator.userAgent) );
}
function isIE6() {
	return ( /msie 6\.0/i.test(navigator.userAgent) );
}
function isIE7() {
	return ( /msie 7\.0/i.test(navigator.userAgent) );
}

function isOpera() {
	return ( /opera/i.test(navigator.userAgent) );
}

function isKonqueror() {
	return ( /Konqueror|Safari|KHTML/i.test(navigator.userAgent) );
}

function isEmail(email) {
	return isMail( email.value );
}

function isMail(mail) {
	return (mail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);
}

function isEmpty(input) {
	var input = input.value
	
	if(input=="")
		return true;
	else
		return false;
}
function isChecked(radio) {
	if(radio.checked)
		return true;
	else
		return false;
}

function in_array(the_needle, the_haystack) {
        var the_hay = the_haystack.toString();
        if(the_hay == ''){
            return false;
        }
        var the_pattern = new RegExp(the_needle, 'g');
        var matched = the_pattern.test(the_haystack);
        return matched;
}

function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function getRequestParameter( strParamName ) {
	var strReturn = "";
	var strHref  = document.URL;
	if( strHref.indexOf( "?" ) > -1 ) {
		var strQueryString = strHref.substr( strHref.indexOf( "?" ) );
		var aQueryString   = strQueryString.split( "&" );
		for ( var intParam = 0; intParam < aQueryString.length; intParam++ ){
			if ( aQueryString[intParam].indexOf( strParamName + "=" ) > -1 ){
				var aParam = aQueryString[intParam].split( "=" );
				strReturn  = aParam[1];
				break;
				}
			}
		}
	return strReturn;
}