var lastPopupUrl = '';
function popup(url, width, height) {
	var openfirst = (getAction(url)!=getAction(lastPopupUrl) ? '&openfirst=1' : '');
	if (!width) width = 400;
	if (!height) height = 400;
//	alert('width=' + width + ',height=' + height + ',left=0,top=0,menubar=no,resizable=yes,scrollbars=yes,toolbar=no');
	popupWindow = window.open(url + openfirst , 'popupWindow', 'width=' + width + ',height=' + height + ',left=0,top=0,menubar=no,resizable=yes,scrollbars=yes,toolbar=no');
	lastPopupUrl = url;
	if (popupWindow) popupWindow.focus();
}

/** gibt bei einer url den teil vorm .do zurück **/
function getAction(url) {
	var pos = url.indexOf(".do");
	if (pos>=0) {
		return url.substr(0, pos);
	} else {
		return url;
	}
}

/* Start Cookie Methoden */
function Cookie(document, name, hours, path, domain, secure) {
    this.$document = document;
    this.$name = name;
    if (hours)
        this.$expiration = new Date((new Date()).getTime() + hours*3600000);
    else this.$expiration = null;
    if (path) this.$path = path; else this.$path = null;
    if (domain) this.$domain = domain; else this.$domain = null;
    if (secure) this.$secure = true; else this.$secure = false;
}
function _Cookie_store() {
    var cookieval = "";
    for(var prop in this) {
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + escape(this[prop]);
    }
    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';
    this.$document.cookie = cookie;
}
function _Cookie_load() {
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;
    var start = allcookies.indexOf(this.$name + '=');
    if (start == -1) return false; 
    start += this.$name.length + 1;
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);
	var a = cookieval.split('&');
    for(var i=0; i < a.length; i++)
        a[i] = a[i].split(':');
    for(var i = 0; i < a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }
    return true;
}
function _Cookie_remove() {
    var cookie;
    cookie = this.$name + '=';
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
    this.$document.cookie = cookie;
}
function CookieTests(AlertText) {
	new Cookie();
	Cookie.prototype.store = _Cookie_store;
	Cookie.prototype.load = _Cookie_load;
	Cookie.prototype.remove = _Cookie_remove;
	var testcookie = new Cookie(document, "test_for_cookie_function", 240);
	if (!testcookie.load()) {
		testcookie.testcounter = 5;
		testcookie.store();
	}
	if (!testcookie.load()) {
	    document.write(AlertText);
	}
}


//// Alternativer Cookietester:

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/**
 * Tabs code.
 */
function selectTab(tabGroupId, tabGroupSize, selectedTabId, enabledStyle, disabledStyle, errorStyle) {
	// first unselect all tab in the tag groups.
	for (i=0;i<tabGroupSize;i++) {
		element = document.getElementById("tabs" + tabGroupId + "head" + i);
		if (element.classNameErrorStdLayout) {
			element.className = errorStyle;
			element.style.color = "";
			document.getElementById("tabs" + tabGroupId + "tab" + i).style.display = "none";		
		} else if (element.className == enabledStyle) {
			element.className = disabledStyle;
			element.style.color = "";
			document.getElementById("tabs" + tabGroupId + "tab" + i).style.display = "none";
		} else { // <tw:ahe>
			document.getElementById("tabs" + tabGroupId + "tab" + i).style.display = "none";
		} // </tw:ahe>		
	}
	if (document.getElementById("tabs" + tabGroupId + "head" + selectedTabId).className==errorStyle) {
		document.getElementById("tabs" + tabGroupId + "head" + selectedTabId).classNameErrorStdLayout = new Object();
	}
	document.getElementById("tabs" + tabGroupId + "head" + selectedTabId).className = enabledStyle;
	document.getElementById("tabs" + tabGroupId + "head" + selectedTabId).style.cursor = "default";
	document.getElementById("tabs" + tabGroupId + "tab" + selectedTabId).style.display = "";
}

function onTabHeaderOver(tabGroupId, selectedTabId, enabledStyle) {
	element = document.getElementById("tabs" + tabGroupId + "head" + selectedTabId);
	if (element.className == enabledStyle) {
		element.style.cursor = "default";
	} else {
		element.style.cursor = "hand";
	}
}
