/*
 * öffnet ein Popup mit der angegebenen URL und den angegebenen Werten
 * @param int width Breite des Popups (Standard 300)
 * @param int height Höhe des Popups (Standard 300)
 * @param int resizable Skalierbar
 * @param string scrollbar yes || no (Standard yes)
 *
 */
function popup (url, width, height, resizable, scrollbar)
{
    if(!width)
    {
        width = 450;
    }

    if(!height)
    {
        height = 300;
    }

    if(!resizable)
    {
        resizable = 'yes';
    }

    if(!scrollbar)
    {
	scrollbar = 'yes';
    }


    var fenster = window.open(url, "Popupfenster", "width="+width+",height="+height+",resizable="+resizable+",scrollbars="+scrollbar);
    fenster.focus();

    return false;
}


/*
 * use this function to dim the page down
 */
function fadeSite(show)
{
	var rootObj;

	if(show)
	{
		if ($('fullOverlayBg') == null)
		{
			var bg = document.createElement('div');
			bg.setAttribute('class', 'fullOverlayBg');
			bg.setAttribute('id', 'fullOverlayBg');



			bg.style.width = getPageSize().w + 'px';
			bg.style.height = getPageSize().h + 'px';

			if (checkBrowser('IE'))
			{
				rootObj = $('globalWrapper');

				var mLeft = -((getPageSize().w - $('globalWrapper').getDimensions().width)/2);
				bg.style.marginLeft = mLeft+'px';
			}
			else
			{
				rootObj = $$("body")[0];
			}

			rootObj.appendChild(bg);
		}

	}
	else
	{
		if ($('fullOverlayBg') != null)
		{
			if (checkBrowser('IE'))
			{
				rootObj = $('globalWrapper');
			}
			else
			{
				rootObj = $$("body")[0];
			}

			rootObj.removeChild($('fullOverlayBg'));
		}
	}

	// scaling the Overlay to full window size on resize
	if(show)
	{
		window.onresize = function()
		{
			fadeSite(false);
			fadeSite(true)
		}
	}
	else
	{
		window.onresize = function(){};
	}
	
}

/**
 * returns 	w - width
 * 			h - height
 * 			of current browser window
 */
function getPageSize()
{
	var bodyObj=document.body
	var docObj=document.documentElement;
	var esw=0;
	var eow=0;
	var bsw=0;
	var bow=0;
	var esh=0;
	var eoh=0;
	var bsh=0;
	var boh=0;

	if (docObj) {
	    esw = docObj.scrollWidth;
	    eow = docObj.offsetWidth;
	    esh = docObj.scrollHeight;
	    eoh = docObj.offsetHeight;
  	}
  	if (bodyObj) {
	    bsw = bodyObj.scrollWidth;
	    bow = bodyObj.offsetWidth;
	    bsh = bodyObj.scrollHeight;
	    boh = bodyObj.offsetHeight;
  	}
	return {w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}

/**
 * browserweiche
 * extendable in core.js
 *
 * parms	forBrowser:String 	- IE for Internet Explorer
 * 								- FF for Firefox
 * 								- GC for Google Chrome
 * 								- SF for Safari
 * 								- XX for all the others
 */

function checkBrowser(forBrowser)
{
	if(__GLOBALS.browser.shortName == forBrowser)
		return true;
	else
		return false;
}

function checkBrowserVersion(version)
{
	if(__GLOBALS.browser.version == version)
		return true;
	else
		return false;
}


function filterNumbers(event)
{
	var elm = Event.findElement(event);
	elm.value = elm.value.replace(/[^\d]+/g, '');
}


function initFilters()
{
	$$('.filterNumbers').each(function(elm){
		Event.observe(elm, 'keyup', filterNumbers);
	});
}


Event.observe(window, 'load', initFilters);
