var container_stack = new Array();
var max_height = 0;
	
// ************************************** chk_container
function chk_container() {
	var args = chk_container.arguments;
		// args[0] = 
	var i =0;
	var iConti =0;
		//

	if ((el_container = document.getElementById(args[0])) != null) {
		if (el_container.childNodes.length > 0){		
			for (i=0; i < el_container.childNodes.length; i++) {
					//				
				if (el_container.childNodes[i].id == 'box_row') {				
					container_stack = new Array();
					max_height = 0
					chk_container_element (el_container.childNodes[i]);				
//					alert(i+"-"+max_height+"-"+container_stack.length)
						//
						// Container-height updaten
					for (iConti=0; iConti < container_stack.length; iConti++) {	
						container_stack[iConti].style.height = max_height+"px";
						container_stack[iConti].parentNode.height=max_height+"px";
							//
						container_stack[iConti].style.minHeight = max_height+"px";
						container_stack[iConti].parentNode.minHeight=max_height+"px";
// alert(max_height+"-"+container_stack[iConti].id+"-"+container_stack[iConti].style.height);
					}
				}
			}			
		}
	}
}
// ************************************** chk_container_element
function chk_container_element() {
	var args = chk_container_element.arguments;
	var el_container = args[0];
	var i =0;
		//	
	if (el_container.childNodes.length > 0){
		for (i=0; i < el_container.childNodes.length; i++) {
//			if (el_container.childNodes[i].className == 'container') {
			if (el_container.childNodes[i].id == 'box_container_inner') {
				container_stack.push(el_container.childNodes[i]);
				max_height =  Math.max(el_container.childNodes[i].offsetHeight, max_height);
			}
			chk_container_element (el_container.childNodes[i]);
			
		}
	}
}

// ************************************** addNodeInputHidden2Frm
function addNodeInputHidden2Frm ()
{
	var args=addNodeInputHidden2Frm.arguments;
	var oNodeParent = args[0];
		// [0]: Node
		// [1]: Name des Elementes
		// [2]: Element-Wert
	var oNode = document.createElement('INPUT');
	oNode.setAttribute('type','hidden');
	oNode.setAttribute('name',args[1]);
	oNode.setAttribute('id','frm_'+args[1]);
	oNode.setAttribute('value',args[2]);
	if (oNodeParent != null) {	
		oNodeParent.appendChild (oNode);
	}
}
// ************************************** addTextNode2Node
function addTextNode2Node ()
{
	var args=addTextNode2Node.arguments;
	var oNodeParent = args[0];
	var strText = args[1];
		//
	oNode = document.createTextNode(strText);
	if (oNodeParent != null) {	
		oNodeParent.appendChild (oNode);
	}	
}
// ************************************** create_frm
function create_frm ()
{
	var args=create_frm.arguments;
		//
	switch (cfg['frm_flag']) {
		case 'assign':
			create_frm_assign(args[0],args[1],args[2],args[3],args[4]);
			break;
		case 'layout':
			create_frm_layout(args[0],args[1],args[2],args[3],args[4]);
			break;
	}
}
// ************************************** create_frm_assign
function create_frm_assign ()
{
	var args=create_frm_assign.arguments;
	var id = args[0];

	var container_id = 'container_' + args[0];
		//
	lfd = lfdofContainer('container_' + args[0]);
	if (lfd != cfg['lastContainer_lfd']) {
			//
		if (cfg['lastContainer_id'] != null){
			restoreContainer(cfg['lastContainer_id']);
		}		
		storeContainer(container_id);
		removeAllChildNotes(container_id);
			//
		if ((el_container = document.getElementById(container_id)) != null) {				
			oNode_Stack = new Array();
				//
			oNode_Stack['box_4frm'] = document.createElement('div');
			oNode_Stack['box_4frm'].setAttribute('id', 'box_frm');
				//
			oNode_Stack['frm'] = document.createElement('form');
			oNode_Stack['frm'].setAttribute('name', 'frm_containers');
			oNode_Stack['frm'].setAttribute('id', 'frm_containers');
			oNode_Stack['frm'].setAttribute('method', 'post');
			oNode_Stack['frm'].setAttribute('action',document.getElementById('frm_layout').action); //frm_action); 
					//			
			addNodeInputHidden2Frm (oNode_Stack['frm'], 'frm', 'frm_container_assign');
			addNodeInputHidden2Frm (oNode_Stack['frm'], 'lfd', lfd);			
			addNodeInputHidden2Frm (oNode_Stack['frm'], 'identkey', cfg['identkey']);
			addNodeInputHidden2Frm (oNode_Stack['frm'], 'identkey_id', cfg['identkey_id']);
			addNodeInputHidden2Frm (oNode_Stack['frm'], 'modtype', cfg['modtype']);
				//
			assignDATA = null;
			for (i=0; i < assignARR.length; i++) {
				if (lfd == assignARR[i]['lfd']){
					assignDATA = assignARR[i];
					addNodeInputHidden2Frm (oNode_Stack['frm'], 'id', assignARR[i]['id']);
//					addNodeInputHidden2Frm (oNode_Stack['frm'], 'container_id', assignARR[i]['container_id']);					
				}
			}
				//
			oNode_Stack['header'] = document.createElement('div');
			addTextNode2Node (oNode_Stack['header'], "ANZEIGE [ -"+lfd+"- ]");
				//				
			oNode_Stack['frm'].appendChild(oNode_Stack['header']);
				//
			oNode_Stack['div_body'] = document.createElement('div');
			oNode_Stack['div_body'].className = 'bod_y';
				//
			oNode_Stack['select'] = document.createElement('SELECT');
			oNode_Stack['select'].setAttribute('name','container_id');
			oNode_Stack['select'].setAttribute('id','container_id');
			oNode_Stack['select'].setAttribute('size',4);
			oNode_Stack['select'].className = 'selectAssign';
				//
				// einhängen der Options
			for(i=0; i < optionsARR.length; i++) {
				oNode = document.createElement('OPTION');
				oNode.appendChild(document.createTextNode(optionsARR[i]['text']));
				oNode.value = optionsARR[i]['value'];
				if ( assignDATA != null){
					if (assignDATA['container_id'] == oNode.value) {
						oNode.selected = 'selected';
					}
				}
				oNode_Stack['select'].appendChild(oNode);
			}
				//
			oNode_Stack['div_body'].appendChild(oNode_Stack['select']);
				//
			oNode_Stack['footer'] = document.createElement('div');
			oNode_Stack['footer'].className = 'footer';
				//						
			addTextNode2Node (oNode_Stack['footer'], "Breite der Box: "+ el_container.offsetWidth+" px");
			oNode_Stack['footer'].appendChild(document.createElement('BR'));
			oNode_Stack['footer'].appendChild(document.createElement('BR'));
							//
				
			oNode_Stack['submit'] = document.createElement('INPUT');
			oNode_Stack['submit'].setAttribute('type','submit');
			oNode_Stack['submit'].setAttribute('value','Senden');
			oNode_Stack['submit'].className = 'submitbtn';
			oNode_Stack['footer'].appendChild(oNode_Stack['submit']);
				//
			oNode_Stack['footer'].appendChild(document.createElement('p'));
				//
			oNode_Stack['a_remove'] = document.createElement('A');
			oNode_Stack['a_remove'].setAttribute('href', "javascript:remove_assign('"+args[0]+"', "+"'frm_containers');");
			oNode_Stack['a_remove'].className = 'blue';
			addTextNode2Node (oNode_Stack['a_remove'], "Zuordnung entfernen ");
			
			oNode_Stack['img_remove'] = document.createElement('IMG');
			oNode_Stack['img_remove'].setAttribute('src','cmsofi/images/icons/button_drop.png');
			oNode_Stack['img_remove'].setAttribute('alt',"Zuordnung von Container "+lfd+" entfernen");
			oNode_Stack['img_remove'].setAttribute('title',oNode_Stack['img_remove'].getAttribute('alt'));
			oNode_Stack['img_remove'].setAttribute('align',"middle");
			oNode_Stack['img_remove'].setAttribute('border','0');	
				//
			oNode_Stack['a_remove'].appendChild(oNode_Stack['img_remove']);
			oNode_Stack['footer'].appendChild(oNode_Stack['a_remove']);
				
			oNode_Stack['frm'].appendChild(oNode_Stack['div_body']);
			oNode_Stack['frm'].appendChild(oNode_Stack['footer']);
				//		
			oNode_Stack['box_4frm'].appendChild(oNode_Stack['frm']);
			el_container.appendChild(oNode_Stack['box_4frm']);
			oNode_Stack = null;
				//
		//	document.getElementById('x').setfocus();
				//
			cfg['lastContainer_id'] = container_id;
			cfg['lastContainer_lfd'] = lfd;
		}
	}	
}
// ************************************** create_frm_layout
function create_frm_layout ()
{
	var args=create_frm_layout.arguments;
	var id = args[0];

	var container_id = 'container_' + args[0];
		//
	lfd = lfdofContainer('container_' + args[0]);
	if (lfd != cfg['lastContainer_lfd']) {
			//
		if (cfg['lastContainer_id'] != null){
			restoreContainer(cfg['lastContainer_id']);
		}		
		storeContainer(container_id);
		removeAllChildNotes(container_id);
			//
		if ((el_container = document.getElementById(container_id)) != null) {
			oNode_box_4frm = document.createElement('div');
			oNode_box_4frm.setAttribute('id', 'box_frm');	
			oNode_box_4frm.className = 'frm_layout';	
				//		
			frm_id = 'frm_containers';
			oNode_frm = document.createElement('form');
			oNode_frm.setAttribute('name', frm_id);
			oNode_frm.setAttribute('id',frm_id);
			oNode_frm.setAttribute('method', 'post');
			oNode_frm.setAttribute('action',document.getElementById('frm_layout').action); //frm_action); 
					//			
			addNodeInputHidden2Frm (oNode_frm, 'frm', 'frm_container_layout');
			addNodeInputHidden2Frm (oNode_frm, 'matrix_x', args[3]);
			addNodeInputHidden2Frm (oNode_frm, 'matrix_y', args[4]);
			addNodeInputHidden2Frm (oNode_frm, 'y', 1);
				//
			oNode_header = document.createElement('div');
			oNode_header.className = 'header';
			addTextNode2Node (oNode_header, "ANZEIGE [ -"+lfd+"- ]");
			oNode_frm.appendChild(oNode_header);
				//
			oNode_body = document.createElement('div');
			oNode_body.setAttribute('class','bod_y');
				//
			oNode = document.createElement('INPUT');
			oNode.setAttribute('type','text');
			oNode.setAttribute('name','x');
			oNode.setAttribute('id','x');
			oNode.setAttribute('value', args[1]); //tmp_x);
			oNode.setAttribute('size',2);
			oNode.className = 'XY';			
			oNode_body.appendChild(oNode);
				//	
			addTextNode2Node (oNode_body, "-faches d.Std.Breite");
				//
			oNode_body.appendChild(document.createElement('BR'));
			oNode_body.appendChild(document.createElement('BR'));
			addTextNode2Node (oNode_body, "Breite der Box: "+ el_container.offsetWidth+" px");
				//
			oNode_frm.appendChild(oNode_body);
				//
			oNode_footer = document.createElement('div');
			oNode_footer.className = 'footer';
				//
			oNode = document.createElement('INPUT');
		//	oNode.setAttribute('type','button');
			oNode.setAttribute('type','submit');
			oNode.setAttribute('value','Senden');
			oNode.className = 'submitbtn';
		//	oNode.setAttribute('onclick',"javascript:document.getElementById(frm_id).submit();");
			oNode_footer.appendChild(oNode);
			oNode_frm.appendChild(oNode_footer);
				//
			oNode_box_4frm.appendChild(oNode_frm);	
			document.getElementById(container_id).appendChild(oNode_box_4frm);
				//
		//	document.getElementById('x').setfocus();
				//
			cfg['lastContainer_id'] = container_id;
			cfg['lastContainer_lfd'] = lfd;
		}
	}	
}

function remove_assign () {
	var args=remove_assign.arguments;
	var box_lfd = args[0];
	var frm_id = args[1];
		//
	if ( confirm("Möchten Sie die Zuordnung von Box "+box_lfd+" entfernen?") == true) {
		if ((el_frm = document.getElementById(frm_id)) != null) {
			if ((el_frm_input = document.getElementById('frm_frm')) != null) {
				el_frm_input.value = 'frm_container_remove_assign'				
			}
			el_frm.submit();
		}
	}
}
