//################################################
//# made by Florian Sabolewski - homepage@22y.de #
//################################################

var headers = new Array();
var onloadfunc = new Array();

var armada_screen = { 

	init_ready		: null,
	
	admin_loaded	: null,

	http_request_ar : {},
	
	xsl_load_check	: {},

	areas 			: {},
	
	token			: null,
	
	token_used		: null,

	c_area_ids		: {},
	
	slide_activ		: {},
	
	load_func_save	: {},
	
	last_load		: {},

	mouse_xpos		: {},
	
	mouse_ypos		: {},

	sh_lock			: {},

	script_name		: null,

	my_loading		: null,
	
	my_load_error	: null,
	
	my_root			: null,
	
	bg_slide_timeout : null,
	
	error_hold		: null,
	
	error_save		: null,
	
	user_name		: null,
	
	user_id			: null,

	pw_check_obj	: null,
	
	pw_check_stat_obj : null,
	
	my_info_box		: null,
	
	init : function( script_name ) {
	
		armada_screen.error_hold = document.getElementById('display_error_main');
		armada_screen.my_info_box = document.getElementById('armard_info_box');
		armada_screen.error_save = new Array();
		armada_screen.script_name = script_name;		
		
		armada_screen.mouse_xpos = 0;
		armada_screen.mouse_ypos = 0;
		document.onmousemove = armada_screen.get_mouse_pos;
		document.onclick = armada_screen.onclick_func;
		armada_screen.get_mouse_pos();
		
		armada_screen.find_actions();

		var my_hold = document.createElement('div');
		var load_show = document.createTextNode('loading...');
		my_hold.appendChild(load_show);
		this.my_loading = my_hold;

		var my_hold2 = document.createElement('div');
		var load_error = document.createTextNode('loading error!');
		my_hold2.appendChild(load_error);
		
		this.my_load_error = my_hold2;

		if( ( arguments.length > 1 ) && ( arguments[1] != null ) ) armada_screen.c_area_ids = arguments[1].split(",");
		if( ( arguments.length > 2 ) && ( arguments[2] != null ) ) armada_screen.set_token(arguments[2]);
		if( ( arguments.length > 3 ) && ( arguments[3] != null ) ) armada_screen.user_name = arguments[3];
		if( ( arguments.length > 4 ) && ( arguments[4] != null ) ) armada_screen.user_id = arguments[4];

		armada_screen.admin_loaded = null;

		if(typeof(armada_admin) != 'undefined') {
		
			armada_admin.init();
			armada_screen.admin_loaded = true;
		}
		
		armada_screen.my_root = document.getElementsByTagName('body')[0];
		
		armada_screen.create_tooltip();

		armada_screen.init_ready = true;

		return null;
	},

	
	onclick_func : function(e) {
	
		if(!e) e = window.event;
	
		armada_screen.close_tooltip();
	},
	
	
	get_script_name : function() {
	
		return this.script_name;
	},


	is_ie : function() {
	
		return (window.ActiveXObject) ? true : false;
	},


	set_token : function( t ) {
	
		armada_screen.token = t;
		armada_screen.token_used = null;
		
		return null;
	},


	display_system_error : function() {

		armada_screen.reload_areas();

		var anz_error = armada_screen.error_save.length;
		var from_e = ( ( arguments.length > 0 ) && ( arguments[0] != null ) && ( arguments[0] >= 0 ) && ( arguments[0] < anz_error ) ) ? arguments[0] : 0;
		var to_e = ( ( arguments.length > 1 ) && ( arguments[1] != null ) && ( arguments[1] > from_e ) && ( arguments[1] < anz_error ) ) ? arguments[1] : anz_error;
		var tmp_e_hold = ( ( arguments.length > 2 ) && ( arguments[2] != null ) ) ? document.getElementById( arguments[2] ) : null;
		
		if( !tmp_e_hold ) {
		
			var new_error_hold = armada_screen.error_hold;
			
		} else {

			var new_error_hold = document.createElement( 'div' );
			new_error_hold.className = "display_error";		
		}

		var new_error_el_head = document.createElement( 'div' );
		new_error_el_head.className = "error_head";
		var new_error_el_head_t = document.createTextNode( ( to_e - from_e ) + " Error" );
		new_error_el_head.appendChild( new_error_el_head_t );
		new_error_hold.appendChild( new_error_el_head );
		
		for( var r=from_e; r<to_e; ++r ) {
		
			var new_error_el_title = document.createElement( 'div' );
			new_error_el_title.className = "error_title";
			var new_error_el_title_t = document.createTextNode( armada_screen.error_save[r][0] + ": " );
			new_error_el_title.appendChild( new_error_el_title_t );
			new_error_hold.appendChild( new_error_el_title );
		
			var new_error_el_text = document.createElement( 'div' );
			new_error_el_text.className = "error_text";
			var new_error_el_text_t = document.createTextNode( armada_screen.error_save[r][1] );
			new_error_el_text.appendChild( new_error_el_text_t );
			new_error_hold.appendChild( new_error_el_text );
		}
		
		if( tmp_e_hold ) tmp_e_hold.appendChild( new_error_hold );
		
		return true;
	},


	new_xmlhttp_obj : function() {
	
		var http_request = null;
		var mode = ( arguments.length > 0 ) ? 'text/xml' : 'text/html';
	
		if( window.XMLHttpRequest ) {
			
			http_request = new XMLHttpRequest();
	
			//if( http_request.overrideMimeType ) http_request.overrideMimeType( mode );
	
	      } else if( window.ActiveXObject ) {
	
			try {
	
				http_request = new ActiveXObject( 'Msxml2.XMLHTTP' );
	
			} catch( e ) {
	
				try {
	
					http_request = new ActiveXObject( 'Microsoft.XMLHTTP' );
	
				} catch( e ) {
				
				}
			}
		}
	      
		if( http_request ) return http_request;
	
		alert('Cannot create XMLHTTP instance');
		return null;
	},
	
	
	make_request : function( xmlhttp_obj_ident, url, result_func, req_ident ) {

		if( armada_screen.init_ready == null ) return null;

		var param_l = arguments.length;
		var post_data = ( param_l > 4 ) ? arguments[4] : null;

		armada_screen.http_request_ar[xmlhttp_obj_ident].onreadystatechange = function() {
		
			if( armada_screen.http_request_ar[xmlhttp_obj_ident].readyState != 4 ) return null;
		
			if( armada_screen.http_request_ar[xmlhttp_obj_ident].status == 200 ) {
			
				if( typeof( result_func ) != 'undefined' ) eval( result_func + "('" + req_ident + "');" );
				
				return null;		
			}

			return armada_screen.request_error();
		}
	
		armada_screen.http_request_ar[xmlhttp_obj_ident].open( ( ( post_data == null ) ? 'GET' : 'POST' ), url, true );
		
		if( post_data != null ) {
		
			armada_screen.http_request_ar[xmlhttp_obj_ident].setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
			armada_screen.http_request_ar[xmlhttp_obj_ident].setRequestHeader( 'Content-length', post_data.length );
			armada_screen.http_request_ar[xmlhttp_obj_ident].setRequestHeader( 'Connection', 'close' );
		}
		
		armada_screen.http_request_ar[xmlhttp_obj_ident].send( post_data );
		
		return null;
	},
	
	
	request_error : function( msg ) {
	
		armada_screen.close_overlaypopup();					
		alert('There was a problem with the request. Please try again. ' + msg);
		this.token_used = null;
		armada_screen.http_request_ar = new Array();
		return null;
	},
	

	//armada_screen.load_xml_data( url, hold, postform_id, replace, load_xsl, send_token [, AFTER_LOAD_FUNC_NAME, AFTER_LOAD_FUNC_PARAMS, ... ] )

	load_xml_data : function( url, hold ) {

		var postform_id = ( arguments.length > 2 ) ? arguments[2] : null;
		var replace = ( arguments.length > 3 ) ? arguments[3] : true;
		var load_xsl = ( arguments.length > 4 ) ? arguments[4] : null;
		var send_token = ( arguments.length > 5 ) ? arguments[5] : null;
		var real_hold = ( load_xsl != null ) ? ( hold + '__' + load_xsl ) : hold;
		var copy_res_to = document.getElementById( hold );
		var data = null;
		
		if( replace == null ) armada_screen.remove_all_childs( copy_res_to );
		copy_res_to.appendChild( armada_screen.my_loading );

		if( armada_screen.http_request_ar[real_hold] = armada_screen.new_xmlhttp_obj( true ) ) {
			
			if( postform_id != null ) data = armada_screen.collect_post_data( postform_id );

			armada_screen.progress_req_params( arguments, real_hold, data, url, 6 );
			
			armada_screen.last_load[real_hold][4] = replace;
			armada_screen.last_load[real_hold][5] = load_xsl;
			armada_screen.last_load[real_hold][6] = hold;
			
			armada_screen.add_request( real_hold, url, 'armada_screen.progress_xml_result', data, send_token );

			return null;
		}
		
		return null;
	},
	
	
	add_request : function( real_hold, url, func, data, send_token ) {
	
		if( send_token != null ) {

			if( this.token_used == this.token ) {
			
				var c = ( arguments.length > 5 ) ? arguments[5] : 0;
		
				if(  c < 50 ) {
			
					var wait_for_new_token = setTimeout('armada_screen.add_request("' + real_hold + '","' + url + '","' + func + '",' + ( ( data != null ) ? ('"'+data+'"') : 'null' ) + ',true,' + c + ');', 100);
					return null;
				}
			
				if( this.token_used == this.token ) {
			
					alert('Request failed. No Token available.');
					return null;
				}
			}

			this.token_used = this.token;

			if( data != null ) {
			
				data = data + ( (data.length > 0 ) ? '&' : '' ) + 'token=' + this.token;
			
			} else {
			
				url = url + ( ( url.indexOf( '?' ) != -1 ) ? '&' : '?' ) + 'token=' + this.token;
			}			
		}

		armada_screen.make_request( real_hold, url, func, real_hold, data );
		return null;
	},
	
	
	progress_xml_result : function( real_hold ) {

		var replace = armada_screen.last_load[real_hold][4];
		var load_xsl = armada_screen.last_load[real_hold][5];
		var hold = armada_screen.last_load[real_hold][6];
		var copy_res_to = document.getElementById( hold );		
		var my_xml = armada_screen.http_request_ar[real_hold].responseXML;

		if( my_xml == null ) return armada_screen.request_error('[No XML-Format]');

 		if( load_xsl == null ) {

			var xsl_to_load_l = 0;

			var anz_ch = my_xml.childNodes.length;
						
			var xsl_to_load = new Array();

			for( var i=0; i<anz_ch; ++i ) {
		
				if( my_xml.childNodes[i].nodeName == 'xml-stylesheet' ) xsl_to_load[xsl_to_load.length] = /href="(.+?)"/.exec( my_xml.childNodes[i].nodeValue )[1];
			}

			xsl_to_load_l = xsl_to_load.length;
	
			if( xsl_to_load_l <= 0 ) {
			
				var old_error_anz = armada_screen.error_save.length;
			
				armada_screen.parse_xml( my_xml.documentElement, null, hold );

				var new_error_anz = armada_screen.error_save.length;

				if( replace == null ) {
			
					armada_screen.remove_all_childs( copy_res_to );
				
				} else {
			
					var my_ref = copy_res_to.lastChild;
					copy_res_to.removeChild(my_ref);
				}

				if( old_error_anz < new_error_anz ) {
				
					armada_screen.display_system_error( old_error_anz, new_error_anz, hold );
				}

				armada_screen.onload_execute();

				if( armada_screen.last_load[hold][4] ) delete armada_screen.http_request_ar[hold];

			} else {
			
				//only one xsl-template is supported ( at the moment -> IE8 )
				if( xsl_to_load_l > 1 ) xsl_to_load_l = 1;
			
				armada_screen.xsl_load_check[hold] = new Array();
			
				for( var e=0; e<xsl_to_load_l; ++e ) {

					armada_screen.xsl_load_check[hold][e] = null;								
					armada_screen.load_xml_data( xsl_to_load[e], hold, null, replace, e );
				}
			}
			
		} else {

			armada_screen.xsl_load_check[hold][load_xsl] = true;
			var xsl_load_l = armada_screen.xsl_load_check[hold].length;
			
			for( var f=0; f<xsl_load_l; ++f ) {

				if( armada_screen.xsl_load_check[hold][f] == null ) return null;
			}

			if( armada_screen.parse_xml( armada_screen.http_request_ar[hold].responseXML.documentElement, true, hold ) === null ) return null;

			var progress_error = true;

			if( window.XSLTProcessor ) {

				var proc = new XSLTProcessor();
				
				for( var q=0; q<xsl_load_l; ++q ) {

					proc.importStylesheet( armada_screen.http_request_ar[hold + '__' + q].responseXML );
				}
				
				var result = proc.transformToFragment( armada_screen.http_request_ar[hold].responseXML, document );								
				progress_error = null;

			} else if( window.ActiveXObject ) {

				var ie_xsl = new ActiveXObject( 'MSXML2.XSLTemplate' );
				//
				var ms_joke = new ActiveXObject( 'MSXML2.FreeThreadedDOMDocument' );
				ms_joke.async = false;
				ms_joke.load( url );	
				ie_xsl.stylesheet = ms_joke;
				//ie_xsl.stylesheet = armada_screen.http_request_ar[hold + '__0'].responseXML;
				var ie_xsl_proc = ie_xsl.createProcessor();
				ie_xsl_proc.input = armada_screen.http_request_ar[hold].responseXML;
				ie_xsl_proc.transform();								
				var result = document.createElement( 'div' );
				result.innerHTML = ie_xsl_proc.output;

				progress_error = null;
			}
						
			if( replace == null ) {
			
				armada_screen.remove_all_childs( copy_res_to );
				
			} else {
			
				var my_ref = copy_res_to.lastChild;
				copy_res_to.removeChild(my_ref);
			}
			
			if( progress_error == null ) {

				copy_res_to.appendChild( result );
				
			} else {

				copy_res_to.appendChild( armada_screen.my_load_error );
			}

			armada_screen.onload_execute();

			delete armada_screen.http_request_ar[hold];

			for( var w=0; w<xsl_load_l; ++w ) {

				delete armada_screen.http_request_ar[hold + '__' + q];
			}
			
			armada_screen.find_actions();
		}	
		
		armada_screen.progress_onload( hold );
		
		return null;
	},
	
	
	parse_xml : function( xml_doc, set_title, ident ) {

		if( xml_doc.nodeName == 'armard' ) {

			var result = xml_doc.childNodes;
			var result_l = result.length;

			for(var n=0; n<result_l; ++n) {

				if(result[n].nodeType == 1) {
				
					var node_type = result[n].nodeName;
					var data = result[n].childNodes;
	
					if( node_type == 'head' ) armada_screen.parse_xml_head( data, set_title, ident );
				}
			}
			
			return true;
		}
		
		return null;
	},

	parse_xml_head : function( data, set_title, ident ) {

		var new_info = true;
		var data_l = data.length;
		var header_nodes = document.documentElement.childNodes[0];	
		var add = true;
		var el_title = null;

		for(var v=0; v<data_l; ++v) {

			add = true;

			if( data[v].nodeType == 1 ) {

				var head_type = data[v].nodeName;
				
				if( data[v].hasChildNodes() ) {
				
					var d_childs = data[v].childNodes;
					var head_val = ( d_childs.length > 0) ? d_childs[0].nodeValue : '';
					
				} else {
				
					var head_val = '';
				}
								
				if( head_type == 'onload' ) {
				
					onloadfunc[(onloadfunc.length)] = head_val;
					
				} else if( head_type == 'token' ) {

					armada_screen.set_token( data[v].childNodes[0].nodeValue );
					
				} else if( head_type == 'error' ) {

					var error_save_l = armada_screen.error_save.length;
					
					armada_screen.error_save[error_save_l] = new Array();
					armada_screen.error_save[error_save_l][0] = ( data[v].attributes.length > 0 ) ? data[v].attributes[0].nodeValue : null;
					armada_screen.error_save[error_save_l][1] = data[v].childNodes[0].nodeValue;
					
				} else if( head_type == 'info' ) {
				
					if( new_info == true ) {
					
						new_info = null;
						armada_screen.remove_all_childs(armada_screen.my_info_box);
						armada_screen.my_info_box.style.display = 'block';
						
						var info_close = document.createElement( 'div' );
						var info_close_a = document.createElement( 'a' );
						var info_a_txt = document.createTextNode('x');
						info_close_a.appendChild( info_a_txt );
						info_close_a.onclick = armada_screen.close_infopopup;
						info_close.appendChild( info_close_a );
						armada_screen.my_info_box.appendChild( info_close );
					}
				
					var info_attr_l = data[v].attributes.length;
					var info_title = null;
					var info_type = null;
					var info_txt = data[v].childNodes[0].nodeValue;

					if( info_attr_l > 0 ) {
					
						for( var i=0; i<info_attr_l; i++ ) {
						
							if( data[v].attributes[i].nodeName == 'title' ) {
								
								info_title = data[v].attributes[i].nodeValue;
								
							} else if( data[v].attributes[i].nodeName == 'type' ) {
							
								info_type = data[v].attributes[i].nodeValue;
							}
						}
					}

					if( info_type == 'head' ) {
					
						var info_head = document.createElement( 'h1' );
						var info_head_txt = document.createTextNode(info_title);
						info_head.appendChild( info_head_txt );

						armada_screen.my_info_box.appendChild( info_head );

					} else if( info_type == 'link' ) {
					
						var info_normal_title = document.createElement( 'h2' );
						var info_normal_title_txt = document.createTextNode(info_title);

						armada_screen.my_info_box.appendChild( info_normal_title_txt );

						var info_normal_txt = document.createElement( 'h3' );
						var info_link = document.createElement( 'a' );
						info_link.href = info_txt;
						var info_link_txt = document.createTextNode(info_txt);
						info_link.appendChild( info_link_txt );
						info_normal_txt.appendChild( info_link );

						armada_screen.my_info_box.appendChild( info_normal_title );
						armada_screen.my_info_box.appendChild( info_normal_txt );
						
					} else {
					
						var info_normal_title = document.createElement( 'h2' );
						var info_normal_title_txt = document.createTextNode(info_title);
						armada_screen.my_info_box.appendChild( info_normal_title_txt );

						var info_normal_txt = document.createElement( 'h3' );
						var info_txt_node = document.createTextNode(info_txt);
						info_normal_txt.appendChild( info_txt_node );

						armada_screen.my_info_box.appendChild( info_normal_title );
						armada_screen.my_info_box.appendChild( info_normal_txt );
					}

				} else if( head_type == 'title' ) {
				
					el_title = data[v].childNodes[0].nodeValue;
				
					if( set_title == true ) onloadfunc[(onloadfunc.length)] = 'armada_screen.set_title("' + el_title + '");';
					
				} else {
				
					var new_head_element = document.createElement(head_type);
					var attr = data[v].attributes;
					var attr_l = attr.length;
			
					if( attr_l > 0 ) {
				
						for( var z=0; z<attr_l; ++z ) {
				
							var attr_name = attr[z].nodeName;
							var attr_value = attr[z].nodeValue;
						
							new_head_element.setAttribute( attr_name, attr_value );	
						
							if( ( ( attr_name == 'href' ) && ( head_type == 'link' ) ) || ( ( attr_name == 'src' ) && ( head_type == 'script' ) ) ) {
							
								if( armada_screen.is_header_loaded( attr_value ) ) {
							
									headers[(headers.length)] = attr_value;
								
								} else {
							
									add = false;
								}
							}
						}
					}	
				
					if(add) header_nodes.appendChild(new_head_element);			
				}
			}
		}

		return true;
	},


	is_header_loaded : function(val) {
	
		var l = headers.length;
	
		for(var h=0; h<l; ++h) {

			if(headers[h] == val) return null;
			
		}		
		
		return true;
	},


	set_title : function(title) {
	
		document.title = title;
		
		return null;
	},
	
	
	onload_execute : function() {
		
		var l = onloadfunc.length;
		var loading_error = 0;
	
		for(var o=0; o<l; ++o) {

			if(onloadfunc[o] != null) {
							
				var func_name = onloadfunc[o].split('(');
				var check_type = eval('typeof('+func_name[0]+')');
								
				if(check_type == 'function') {
				
					eval(""+onloadfunc[o]+"");
					onloadfunc[o] = null;
					
				} else {
				
					loading_error = 1;
				}
			}
		}
		
		if(loading_error == 0) {
		
			onloadfunc = new Array();
			
		} else {
				
			loading_error = (arguments.length == 0)?1:(arguments[0]+1);
			
			if(loading_error > 20) {
			
				alert('loading error!');
				
			} else {
			
				var loading_e = setTimeout('armada_screen.onload_execute(' + loading_error + ');', 100);
			}
		}
		
		return true;	
	},

	
	reload_all_areas : function() {
	
		var c_area_ids_l = armada_screen.c_area_ids.length;
		
		for( var i=0; i<c_area_ids_l; ++i ) {
			
			armada_screen.load_last_loaded( 'content_'+armada_screen.c_area_ids[i] );
		}
		
		return true;
	},
	

	// armada_screen.load_last_loaded( id [nix gespeichert -> defaut load, only_exec_new_func[, my_script_name[, get_params[, func_name[, func_params]]]]]);

	load_last_loaded : function( id ) {
	
		if( armada_screen.last_load[id] && ( typeof(armada_screen.last_load[id]) != 'undefined' ) ) {

			var only_exec_new_func = ( arguments.length > 1 ) ? arguments[1] : null;

			if( only_exec_new_func == 1 ) {

				return armada_screen.send_per_GET( armada_screen.last_load[id][1], armada_screen.last_load[id][0], id, ( ( arguments.length > 4 ) ? arguments[4] : null ), ( ( arguments.length > 5 ) ? arguments[5] : null ) );

			} else if( typeof( armada_screen.last_load[id][2] ) != 'undefined' ) {
			
				return armada_screen.send_per_GET( armada_screen.last_load[id][1], armada_screen.last_load[id][0], id );
			}

			return armada_screen.send_per_GET( armada_screen.last_load[id][1], armada_screen.last_load[id][0], id, armada_screen.last_load[id][2], armada_screen.last_load[id][3] );
		
		} else {

			if( arguments.length > 2 ) {
			
				var my_script_name = ( arguments[2] != null ) ? arguments[2] : this.get_script_name();
				var get_params = ( arguments[3] != null ) ? arguments[3] : '';
				var func_name = ( arguments.length > 4 ) ? arguments[4] : null;
				var func_params = ( arguments.length > 5 ) ? arguments[5] : null;

			} else {
			
				var content_id = id.match( /(\d+)$/gi );		
				var get_params = ( content_id && content_id.length == 1 ) ? 'a=i&area_id=' + content_id[0] : '';
				var my_script_name = this.get_script_name();
			}
		
			return armada_screen.send_per_GET( my_script_name, get_params, id, func_name, func_params );
		}
	},	

	
	//armada_screen.send_per_GET( URL, PARAM, DIV [, FUNC_NAME, FUNC_PARAMS, ... ] );
	
	send_per_GET : function( url, get_data, div_id ) {

		if( url == '' ) url = this.get_script_name();

		if( armada_screen.http_request_ar[div_id] = this.new_xmlhttp_obj() ) {
		
			if( ( div_id == "overlay_inhalt" ) && ( document.getElementById('overlay_popup_loading').style.display != 'inline' ) ) document.getElementById('overlay_popup_loading').style.display = 'inline';
			if( document.getElementById(div_id).style.display != 'block' ) document.getElementById(div_id).style.display = 'block';
			
			armada_screen.progress_req_params( arguments, div_id, get_data, url, 3 );
			
			armada_screen.make_request( div_id, url + ( ( get_data.length == 0 ) ? '' : ('?' + get_data ) ), 'armada_screen.progress_text_result', div_id );
		}
		
		return null;
	},

	
	send_per_POST : function( url, form_id, div_id ) {

		if( url == '' ) url = this.get_script_name();

		if( armada_screen.http_request_ar[div_id] = this.new_xmlhttp_obj() ) {

			if( ( div_id == "overlay_inhalt" ) && ( document.getElementById('overlay_popup_loading').style.display != 'inline' ) ) document.getElementById('overlay_popup_loading').style.display = 'inline';
			if( document.getElementById(div_id).style.display != 'block' ) document.getElementById(div_id).style.display = 'block';

			var post_data = armada_screen.collect_post_data( form_id );
		
			armada_screen.progress_req_params( arguments, div_id, post_data, url, 3 );

			armada_screen.make_request( div_id, url, 'armada_screen.progress_text_result', div_id, post_data );
		}
		
		return null;	
	},
	
	
	progress_req_params : function( my_params, req_ident, data, url, params_start_int ) {
	
		var param_l = my_params.length;

		armada_screen.last_load[req_ident] = new Array();
		armada_screen.last_load[req_ident][0] = ( data != null) ? data : url;
		armada_screen.last_load[req_ident][1] = url;

		if( param_l > params_start_int ) {
						
			var func_name = my_params[params_start_int];
			var param = '';

			if( param_l > ( params_start_int + 2 ) ) {
							
				for( var i=( params_start_int + 1 ); i<param_l; ++i ) {
						
					param = param + ( (i != ( params_start_int + 1 ) ) ? ", '" : "" ) + my_params[i] + ( ( i != ( param_l - 1 ) ) ? "'" : "" );
				}
					
			} else {
				
				param = my_params[( params_start_int + 1 )];
			}
				
			armada_screen.last_load[req_ident][2] = func_name;
			armada_screen.last_load[req_ident][3] = param;

			armada_screen.load_func_save[req_ident] = ( typeof( param ) != 'undefined' ) ? ( ''+func_name+'(\''+param+'\');' ) : ( ''+func_name+'();' );	
		}	
	
		return null;
	},
	
	
	progress_text_result : function( req_ident ) {

		if( typeof( armada_screen.http_request_ar[req_ident] ) == 'undefined' ) return null;
	
		var result = armada_screen.http_request_ar[req_ident].responseText;
		
		if( req_ident == 'overlay_inhalt' ) {
					
			if(document.getElementById('overlay_popup').style.display != 'inline') document.getElementById('overlay_popup').style.display = 'inline';
			if(document.getElementById('overlay_popup_loading').style.display != 'none') document.getElementById('overlay_popup_loading').style.display = 'none';
	    }
	    			
		document.getElementById(req_ident).innerHTML = result;  
		if(document.getElementById(req_ident).style.display != 'block') document.getElementById(req_ident).style.display = 'block';

		armada_screen.progress_onload( req_ident );
		armada_screen.find_actions();
		
		return null;
	},
	
	
	progress_onload : function( req_ident ) {

		if( typeof(armada_screen.load_func_save[req_ident]) != 'undefined' && armada_screen.load_func_save[req_ident] != 'undefined();' ) {
						
			eval( armada_screen.load_func_save[req_ident] );
						
			delete armada_screen.load_func_save[req_ident];
		}	
	},


	collect_post_data : function( form_id ) {
	
		l_a = armada_screen.areas.length;

		if(l_a > 0) {
			
			var temp_c = null;
			
			for(var q = 0; q < l_a; ++q) {
				
				temp_c = tinyMCE.get(armada_screen.areas[q]).getContent();
				document.getElementById(armada_screen.areas[q]).value = temp_c;
			}
			
			this.reset_areas();
		}
		
		var post_data = "";
		var search_multi_form = form_id.indexOf( "|" );

		if( search_multi_form == -1 ) {
	
			var form_x = new Array;
			form_x[0] = form_id;
			var form_x_count = 1;
		
		} else {
		
			var form_x = form_id.split( "|" );
			var form_x_count = form_x.length;
		}
		
		var form_i_count = new Array;
		var i = new Array;
		var my_id = "";

		for( var x=0; x<form_x_count; ++x ) {
		
			if( document.forms[form_x[x]] ) {
		
				form_i_count[x] = document.forms[form_x[x]].length;
	
				for( i[x]=0; i[x]<form_i_count[x]; ++i[x] ) {

					if( !( ( ( document.forms[form_x[x]].elements[i[x]].type == 'radio' ) || ( document.forms[form_x[x]].elements[i[x]].type == 'checkbox' ) ) && ( document.forms[form_x[x]].elements[i[x]].checked != true ) ) || ( document.forms[form_x[x]].elements[i[x]].type == 'file' ) ) {

						my_id = ( document.forms[form_x[x]].elements[i[x]].id != "" ) ? document.forms[form_x[x]].elements[i[x]].id : document.forms[form_x[x]].elements[i[x]].name;

						if( document.forms[form_x[x]].elements[i[x]].type != 'select-multiple' ) {
						
							if( post_data != "" ) post_data = post_data + "&";

							post_data = post_data + encodeURIComponent(my_id) + "=" + encodeURIComponent(document.forms[form_x[x]].elements[i[x]].value);
					
						} else {
					
							l_y = document.forms[form_x[x]].elements[i[x]].length;
					
							for( var y=0; y<l_y; ++y ) {
						
								if( document.forms[form_x[x]].elements[i[x]][y].selected ) {

									if( post_data != "" ) post_data = post_data + "&";
			
									post_data = post_data + encodeURIComponent(my_id) + "[]=" + encodeURIComponent(document.forms[form_x[x]].elements[i[x]][y].value);
								}
							}
						}
					}
				}
			}
		}
			
		return post_data;
	},

	
	reset_areas : function( r ) {

		if( (armada_screen.check_for_areas() > 0) && (typeof(tinyMCE) != 'undefined')) {

			var l_a = armada_screen.areas.length;

			for( var i = 0; i < l_a; ++i ) {

				tinyMCE.execCommand('mceFocus', false, armada_screen.areas[i]);    
				tinyMCE.execCommand('mceRemoveControl', false, armada_screen.areas[i]);
			}

			armada_screen.areas = new Array();
			
			if(r) var reload_areas = window.setTimeout("armada_screen.reload_areas()", 50);	
		}
		
		return true;
	},


	check_for_areas : function() {

		if(armada_screen.admin_loaded) {

			var a = document.getElementsByTagName("textarea");		
			var l_a = a.length;
			
			if((l_a > 0) && (typeof(tinyMCE) != 'undefined') && (armada_admin.editor_load != true)) armada_admin.html_editor_init();
		
			return l_a;
		}
		
		return 0;
	},


	reload_areas : function() {

		var l_a = armada_screen.check_for_areas();
		
		if((l_a > 0) && (typeof(tinyMCE) != 'undefined')) {

			var a = document.getElementsByTagName("textarea");		

			for( var y = 0; y < l_a; ++y ) {

				armada_screen.areas[y] = ''+a[y].id+'';
				
				tinyMCE.idCounter=0;
				tinyMCE.execCommand('mceAddControl', false, ''+a[y].id+'');
			}
		}
		
		return true;
	},


	find_actions : function() {

		if(armada_screen.admin_loaded) {
	
			this.reset_areas(true);
			
			if( !this.is_ie() ) {
			
				var b = document.getElementsByTagName("div");
		
				var l_b = b.length;
			
				for(var i = 0; i < l_b; ++i) {
				
					if(b[i].className.match(/not\_published/gi) != null) {
					
						b[i].xOpacity = .5;
						this.set_opacity(b[i]);
					
						b[i].onmouseover = function() { armada_screen.slide_opacity(.99, true, this.id, .02, 50, 1); };
						b[i].onmouseout = function() { armada_screen.slide_opacity(.5, false, this.id, .02, 50, 1); };
					}
				}
			}
		
			return true;
		}
		
		return null;
	},


	typeOf : function( t ) {
	
		return String( t.constructor ).split(" ")[1].split( "()" ).join( "" );
	},


	set_opacity : function(obj) {

		if( obj.xOpacity > .99 ) obj.xOpacity = .99;
		if( obj.xOpacity < 0 ) obj.xOpacity = 0;

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	
		return null;
	},

	reset_opacity : function(obj) {

		obj.style.opacity = '';
		obj.style.MozOpacity = '';
		obj.style.filter = '';
	
		return null;
	},


	create_tooltip : function() {
	
		if( !document.getElementById('armard_tooltip') ) {

		
			var my_tooltip = document.createElement('div');
			my_tooltip.id = 'armard_tooltip';
			my_tooltip.className = 'dont_display';

			this.my_root.appendChild(my_tooltip);			
		}
	},
	
	
	close_tooltip : function() {
	
		document.getElementById('armard_tooltip').style.display = 'none';
	},

	
	show_tooltip : function() {

		if( armada_screen.init_ready == null ) return null;

		var tooptip_hold = document.getElementById('armard_tooltip');
		var my_display = null;

		if( arguments.length == 1 ) {
		
			armada_screen.remove_all_childs( tooptip_hold );
			var ttext = document.createTextNode(arguments[0]);
			tooptip_hold.appendChild(ttext);
			my_display = true;
		}

		//return armada_screen.show_hide_div_mousepos( 'armard_tooltip', 0, 15, true, null, null, null, my_display );
		return armada_screen.show_hide_div_mousepos( 'armard_tooltip', 0, 15, true, null, null, null, my_display );
	},


	close_infopopup : function() {
	
		armada_screen.remove_all_childs(armada_screen.my_info_box);
		armada_screen.my_info_box.style.display = 'none';	
	},
	

	get_mouse_pos : function( e ) {
		
		if( ( typeof( e ) == 'undefined' ) || !e ) e = window.event;
			
		if( e ) { 
	  
			if( e.pageX || e.pageY ) {
	    	    
				armada_screen.mouse_xpos = parseInt(e.pageX);
				armada_screen.mouse_ypos = parseInt(e.pageY);
	      
			} else if( e.clientX || e.clientY ) {

				armada_screen.mouse_xpos = parseInt(e.clientX + document.body.scrollLeft);
				armada_screen.mouse_ypos = parseInt(e.clientY + document.body.scrollTop);
			}
			
			return null;
		}
		
		armada_screen.mouse_xpos = 0;
		armada_screen.mouse_ypos = 0;

		return null;
	},

	// show_hide_div_mousepos( div_id, my_x, my_y, only_add_xy, check_id, rew, displaymode, must_display, hidden_mode )
	show_hide_div_mousepos : function( div_id ) {

		if( armada_screen.init_ready == null ) return null;

		if( ( arguments.length > 2 ) && ( arguments[1] != null ) && ( arguments[2] != null ) ) {

	    	var my_x = arguments[1];
	    	var my_y = arguments[2];
		
			if( ( arguments.length > 3 ) && ( arguments[3] != null ) ) {
		
				my_x = my_x+armada_screen.mouse_xpos;
				my_y = my_y+armada_screen.mouse_ypos;
			}

		} else {
		
			var my_x = armada_screen.mouse_xpos;
			var my_y = armada_screen.mouse_ypos;
		}

	    var el = document.getElementById( div_id );

	    el.style.position = "absolute";
	    el.style.top = parseInt( my_y + 9 ) + "px";
	    el.style.left = parseInt( my_x + 9 ) + "px";
	  
	    return this.show_hide_div( div_id, (( arguments.length > 4 )?arguments[4]:null), (( arguments.length > 5 )?arguments[5]:null), (( arguments.length > 6 )?arguments[6]:null), ((arguments.length>7)?arguments[7]:null), ((arguments.length>8)?arguments[8]:null) );
	},

	// show_hide_div( div_id, check_id, rew, displaymode, must_display, hidden_mode )
	show_hide_div : function( div_id ) {

		if( armada_screen.init_ready == null ) return null;

	    var check_id = ( arguments.length > 1 ) ? arguments[1] : null;
	    var rew = ( arguments.length > 2 ) ? arguments[2] : null;
	    var displaymode = ( ( arguments.length > 3 ) && ( arguments[3] ) ) ? 'inline' : 'block';
	    var must_display = ( arguments.length > 4 ) ? arguments[4] : null;
	    var hidden_mode = ( arguments.length > 5 ) ? arguments[5] : null;
	    var el = document.getElementById( div_id );
	    var check = null;
	    
	    if( ( el.style.display == '' ) && ( must_display !== false ) && ( el.className.indexOf( 'dont_display' ) != -1 ) ) check = true;
	
	    if( ( check === true ) || ( ( ( el.style.display == 'none' ) || ( el.style.display == 'hidden' ) ) && ( must_display !== false ) ) || ( must_display === true ) ) {
	    	
	    	if( check_id ) document.getElementById( check_id ).checked = ( rew ) ? false : true;
			el.style.display = displaymode;
	        	
		} else {
		
	    	if( check_id ) document.getElementById( check_id ).checked = ( rew ) ? true : false;
			el.style.display = ( hidden_mode ) ? 'hidden' : 'none';
	    }
	    
	    return null;
	},

	
	show_hide_outline : function(div_id, on_off) {

		if( armada_screen.init_ready == null ) return null;

    	if( ( typeof(armada_screen.sh_lock[div_id]) != 'undefined' ) && ( armada_screen.sh_lock[div_id] == 1 ) ) return null;
    
		var el = document.getElementById( div_id );
		
		if( el ) {
		
			var color = ( arguments.length > 2 ) ? arguments[2] : 'C00';
	
			if( el !== null ) el.style.outline = ( on_off ) ? '1px #'+color+' dotted' : '';
		}
	
		return null;
	},

	
	show_hide_outline_lock : function( div_id ) {

		var color = ( arguments.length > 1 ) ? arguments[1] : 'C00';

		if(typeof(armada_screen.sh_lock[div_id]) == 'undefined') {
		
			this.show_hide_outline( div_id, true, color );
			armada_screen.sh_lock[div_id] = 1;

		} else if( armada_screen.sh_lock[div_id] == 1 ) {
		
			this.show_hide_outline( div_id, false, color );
			armada_screen.sh_lock[div_id] = 0;

		} else {
		
			this.show_hide_outline( div_id, true, color );
			armada_screen.sh_lock[div_id] = 1;
		}

		return null;
	},
	
	
	flip_checkbox_stat : function( id ) {

	    var obj = document.getElementById( id );
	    
	    obj.checked = ( obj.checked == true ) ? false : true;

		return null;	
	},

	
	open_overlaypopup : function(ueberschrift, datei, get_data) {

		if( armada_screen.init_ready == null ) return null;

		armada_screen.show_transparent_bg();
		document.getElementById('overlay_popup_loading').style.zIndex = 101;
	    document.getElementById('overlay_popup').style.zIndex = 102;
	    document.getElementById('overlay_uebers').innerHTML = ueberschrift;
		armada_screen.send_per_GET(datei, get_data, 'overlay_inhalt');

		return null;
	},

		
	close_overlaypopup : function() {

		if( armada_screen.init_ready == null ) return null;

		armada_screen.show_transparent_bg( true );
		this.find_actions();
	    document.getElementById('overlay_popup').style.border = "";
	    document.getElementById('overlay_popup').style.backgroundColor = "";		
		document.getElementById('overlay_popup').style.display = 'none';
		document.getElementById('overlay_inhalt').style.display = 'none';
		document.getElementById('overlay_popup_loading').style.zIndex = -11;
	    document.getElementById('overlay_popup').style.zIndex = -12;
	    document.getElementById('overlay_inhalt').innerHTML = '';

		armada_screen.close_tooltip();

		return null;
	},


	show_transparent_bg : function() {

		var close = ( arguments.length > 0 ) ? arguments[0] : null;

		if( typeof( this.bg_slide_timeout ) != 'undefined' ) window.clearTimeout( this.bg_slide_timeout );

		if( close === null ) {

			document.getElementById('trans_bg').xOpacity = 0;
			armada_screen.set_opacity(document.getElementById('trans_bg'));
			armada_screen.slide_opacity(.48, true, 'trans_bg', .12, 5, 10);
			
		} else {
		
			this.slide_opacity(0, false, 'trans_bg', .08, 10, -10);
		}
		
		return null;
	},


	slide_opacity : function(to, reverse, div_id, faktor, time, zindex) {

		if( armada_screen.init_ready == null || !document.getElementById(div_id) ) return null;
		
		if( ( typeof( armada_screen.slide_activ[div_id] ) != 'undefined' ) && ( armada_screen.slide_activ[div_id] != to ) ) return null;
		
		armada_screen.slide_activ[div_id] = to;
		
		check = false;
		
		if(reverse) {
	
			if(document.getElementById(div_id).style.display != 'block') document.getElementById(div_id).style.display = 'block';
			if(document.getElementById(div_id).style.zIndex != zindex) document.getElementById(div_id).style.zIndex = zindex;
			
			if(document.getElementById(div_id).xOpacity < to) {
			
				document.getElementById(div_id).xOpacity = document.getElementById(div_id).xOpacity + faktor;
				
			} else {
				
				check = true;
				document.getElementById(div_id).xOpacity = to;
			}
				
		} else {
					
			if((document.getElementById(div_id).xOpacity > to) && ((document.getElementById(div_id).xOpacity - faktor) > to)) {
		
				document.getElementById(div_id).xOpacity = document.getElementById(div_id).xOpacity - faktor;
			
			} else {
			
				check = true;
				document.getElementById(div_id).xOpacity = to;
				
				if(to == 0) document.getElementById(div_id).style.display = 'none';
				if(document.getElementById(div_id).style.zIndex != zindex) document.getElementById(div_id).style.zIndex = zindex;
			}
		}

		armada_screen.set_opacity(document.getElementById(div_id));
		
		if(!check) {
		
			this.bg_slide_timeout = setTimeout("armada_screen.slide_opacity(" + to + ", " + reverse + ", '" + div_id + "', " + faktor + ", " + time + ", " + zindex + ")", time);

		} else {

			if( to >= .99 ) armada_screen.reset_opacity(document.getElementById(div_id));
			delete armada_screen.slide_activ[div_id];
		}

		return null;
	},

	
	remove_all_childs_by_id : function(id) {
	
		var handle = document.getElementById(id);
	
		if( handle ) armada_screen.remove_all_childs( handle );
		
		return null;
	},


	remove_all_childs : function(handle) {
	
		if(!handle) return null;
	
		var e_l = handle.childNodes.length;
				
		for(var w=0; w<e_l; ++w) {
		
			var ref = handle.firstChild;
			handle.removeChild(ref);
		}
		
		return null;
	},
	
	
	checkbox_stat : function( checkbox_name, modus ) {
	
    	var my_checkboxes = document.getElementsByName(checkbox_name+'[]');

        if( my_checkboxes ) {

        	var my_checkboxes_l = my_checkboxes.length;
        
        	for( var i=0; i<my_checkboxes_l; ++i ) {
        
        		if( my_checkboxes[i].type && (my_checkboxes[i].type == 'checkbox') ) my_checkboxes[i].checked = (modus)?true:false;
        	}
        }
        
        return null;
	},
	
	
	check_pw_stat : function( obj_ref, status_id ) {
		
		armada_screen.pw_check_obj = obj_ref;
		armada_screen.pw_check_stat_obj = document.getElementById(status_id);
		
		document.onkeyup = function() {

			armada_screen.pw_check_stat_obj.style.color=(armada_screen.pw_check_obj.value.length<7)?'#C00000':'#129B00'
		}

		return null;
	},


	reset_check_pw_stat : function( obj_ref ) {

		armada_screen.pw_check_obj = null;
		armada_screen.pw_check_stat_obj = null;
		
		document.onkeyup = function() {}
		
		return null;
	},
	
	openinfo : function( id ) {
	
		window.open("index.php?a=pp&artikel_id="+id, "", 'scrollbars=yes,width=700,height=600,left=12,top=12,locationbar=false,menubar=false,resizable=yes');	
	}
}