/*
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
description:	JavaScript core library
created:		21.01.2002
author:			benjamin nowack
copyright:		2002, appmosphere.com, germany, all rights reserved
language:		JavaScript
version:		1.0
changes:		
comments:		
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
*/

function unentity(v){
	v=""+v;
	var entities=new Array("&Uuml;","&uuml;","&Ouml;","&ouml;","&Auml;","&auml;","&szlig;","&amp;","&#039;", "&quot;", "&deg;", "<br />", "<br>", "<br/>");
	var chars=new Array("Ü", "ü", "Ö", "ö", "Ä", "ä", "ß", "&", "'", "\"", "°", "\n", "\n", "\n");
	for(var i=0; i<entities.length; i++){
		while(v.indexOf(entities[i])!=-1){
			var s_pos=v.indexOf(entities[i]);
			v=v.substring(0, s_pos)+chars[i]+v.substring(s_pos+entities[i].length, v.length);
		}
	}
	return v;
}


function remove_crlfs(val){
	esc_val=escape(val);
	if(esc_val["replace"]){
		while(esc_val.indexOf("%0D%0A")!=-1){
			esc_val=esc_val.replace('%0D%0A', "");
		}
		while(esc_val.indexOf("%0D")!=-1){
			esc_val=esc_val.replace('%0D', "");
		}
		while(esc_val.indexOf("%0A")!=-1){
			esc_val=esc_val.replace('%0A', "");
		}
	}
	return unescape(esc_val);
}


function get_search_args(win, array_type){
	var r=new Array();
	if(win){
		/* query_string */
		var qs=win.location.search;
		if(qs){
			var pointer, cur_start, cur_equal, arg_name, arg_value;
			pointer=0;
			while(qs.charAt(pointer)=='?' || qs.charAt(pointer)=='&'){
				cur_start=pointer+1;
				if(qs.indexOf('&', cur_start)>cur_start){
					pointer=qs.indexOf('&', cur_start);
				}
				else{
					pointer=qs.length;
				}
				cur_equal=qs.indexOf('=', cur_start);
				arg_name=qs.substring(cur_start, cur_equal);
				arg_value=qs.substring(cur_equal+1, pointer);
				if(array_type=="key_ar"){
					r[arg_name]=unescape(arg_value);
				}
				else{
					r[r.length]=new Array(arg_name, unescape(arg_value));
				}
			}
		}
	}
	return r;	
}


function get_year(uts){
	var my_date=new Date();
	if(uts){
		my_date.setTime(uts);
	}
	var my_year=my_date.getYear();
	/* Y2K-Test */
	var test_date=new Date(2002, 1, 1);
	var test_year=test_date.getYear();
	if(test_year==102){/* not Y2K-compliant */
		return my_year+1900;
	}
	else{
		return my_year;
	}
}


function get_month(uts){
	var my_date=new Date();
	if(uts){
		my_date.setTime(uts);
	}
	var my_month=my_date.getMonth()+1;
	if(my_month<10){
		return "0"+my_month;
	}
	else{
		return my_month;
	}
	return my_month;
}


function get_month_day(uts){
	var my_date=new Date();
	if(uts){
		my_date.setTime(uts);
	}
	var my_day=my_date.getDate();
	if(my_day<10){
		return "0"+my_day;
	}
	else{
		return my_day;
	}
}


function get_formatted_date(uts){
	var day=get_month_day(uts);
	var month=get_month(uts);
	var year=get_year(uts);
	var result=day+"."+month+"."+year;
	return result;
}


/* # # # # # # # # # # */

function set_window_title(value, ua_cat){
	var p=get_p();
	if(!ua_cat && p["get_ua_cat"]){
		ua_cat=p.get_ua_cat();
	}
	if(ua_cat!="ns4"){
		if(value){
			p.document.title=p.unentity(value);/* l_core.js */
		}
	}
	return true;
}


function set_window_status(value){
	var p=get_p();
	p.status=p.unentity(value);/* l_core.js */
}


function do_alert(value){
	if(value && value.length){
		alert(unentity(value));
	}
}

function do_confirm(value){
	if(value && value.length){
		return confirm(unentity(value));
	}
}


/* # # # # # # # # # # */

function get_root_path(){
	var p=get_p();
	var r='_null';
	var whole_uri=""+p.location.href;
	if(whole_uri.indexOf(".php")!=-1){
		r=whole_uri.substring(0, 1+whole_uri.lastIndexOf("/"));
	}
	else{
		if(whole_uri.lastIndexOf("/")==(whole_uri.length)-1){
			r=whole_uri.substring(0, 1+whole_uri.lastIndexOf("/"));
		}
		else{
			r=whole_uri+"/";
		}
	}
	return r;
}


function remove_path(val){
	/* os specific, get file_name without path */
	if(val.indexOf("/")!=-1){
		val=val.substring(1+val.lastIndexOf("/"), val.length);
	}
	val_escaped=escape(val);
	if(val_escaped.indexOf("%5C")!=-1){/* backslash */
		val=unescape(val_escaped.substring(3+val_escaped.lastIndexOf("%5C"), val_escaped.length));
	}
	return val
}


/* # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # */

if(!window.libs_loaded){
	window.libs_loaded=1;
}
else{
	window.libs_loaded++;
}