/**
 * File for a lot of common JS functions without a spesific placement.
 */
function periodSelect(show, hide) {
	if (document.getElementById(show+'fs'))
		document.getElementById(show+'fs').style.display='block';
	var i = 0;
	while (hide[i]) {
		if (document.getElementById(hide[i]+'fs'))
			document.getElementById(hide[i]+'fs').style.display='none';
		i++;
	}
}
function periodSpecAddFields(ident, prefix, weekday) {
	var counter = 1;
	while(document.getElementsByName(prefix + 'ip' + weekday + counter + '_hh').length)
		counter++;
	var i = (counter+1)/2;
	
	var html = '';
	html+= '<input type="text" name="' + prefix + 'ip' + weekday + counter + '_hh" value="" size="3" maxlength="2" class="sysEditTimeField">:';
	html+= '<input type="text" name="' + prefix + 'ip' + weekday + counter + '_mm" value="" size="3" maxlength="2" class="sysEditTimeField"> - ';
	html+= '<input type="text" name="' + prefix + 'ip' + weekday + (counter+1) + '_hh" value="" size="3" maxlength="2" class="sysEditTimeField">:';
	html+= '<input type="text" name="' + prefix + 'ip' + weekday + (counter+1) + '_mm" value="" size="3" maxlength="2" class="sysEditTimeField">';
	document.getElementById(ident+i).innerHTML = html;
	if (!document.getElementById(ident+(i+1)))
		document.getElementById(ident+'link').style.display='none';
}

function GetXyCordForObj(obj)
{
	var res=[0,0];
	if (obj)
	{
		if (obj.offsetParent)
		{
			while(obj.offsetParent)
			{
				res[0]+=obj.offsetLeft;
				res[1]+=obj.offsetTop;
				obj=obj.offsetParent;
			}
		}
		else
		{
			res[0]=obj.x;
			res[1]=obj.y;
		}
	}
	return res;
}

function getScrollXY() 
{
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) 
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	} 
	else 
	if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} 
	else 
	if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function getDocHeight() 
{
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

/*
CSS Browser Selector v0.3.1
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
Source: http://github.com/rafaelp/css_browser_selector/blob/master/css_browser_selector.js
*/
function css_browser_selector(u)
{
	var ua = u.toLowerCase();
	var is=function(t) { return ua.indexOf(t)>-1;};
	var g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0];
	var b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; 
	c = b.join(' '); 
	h.className += ' '+c; 
	return c;
} 
 
/*
 * Function for get the size of the window.
 * The function was copied and modified from:
 * http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
 */
function GetScreenSize() 
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else 
	if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	return {w:myWidth, h:myHeight};
}

/**
 * In some rare cases we need to know what bowser it is to do some exception.
 * 
 * Actualy. The exceptions is only needed for IE so we only make a "is IE" check.
 * @return
 */
function isIE()
{
	if (navigator.userAgent.toLowerCase().indexOf("msie") == -1) return false;
	if (navigator.userAgent.toLowerCase().indexOf("opera") != -1) return false;
	return true;
}

/**
 * Function that can be runned when NOTHING shall happend.
 * 
 * This is primary uses so ajax response doing nothing on clien side dont 
 * end up in a error on IE.
 */
function NoOp() {}

function DoLog(txt,add)
{
	var db=document.getElementById("MyDebugArea");
	if (!db) return;
	if (add) db.innerHTML+=txt;
	else db.innerHTML=txt;
}