// JavaScript Document

window.onload = initColumns;

var gvbody='';
var gvcomp1='';
var gvcomp2='';

// Function Used to resize body container & hide componentcontainer
function bodycontainertofull(tbody, comp1, comp2) {

	if( document.getElementById(tbody) ) {
		gvbody = document.getElementById(tbody);
	}
	if( document.getElementById(comp1) ) {
		gvcomp1 = document.getElementById(comp1);
	}
	if( document.getElementById(comp2) ) {
		gvcomp2 = document.getElementById(comp2);
	}

//alert(tbody);
//alert(comp1);
//alert(comp2);

}

function haschildren(obj) {
	var children = obj.childNodes;
	if( children.length )
		return true;
	else
		return false;
}

function getInnetDiv(obj) {
	var child_divs = obj.childNodes;
	var i;
	var robj;
	
	//alert('child_divs.length: '+child_divs.length);
	
	for(i=0; i<child_divs.length; i++)
	{
		//alert(child_divs[i].tagName);
		if( child_divs[i].tagName == "DIV" )
		{
			//alert("Clear: " + child_divs[i].className);
			//alert(haschildren(child_divs[i]));
			
			if(haschildren(child_divs[i])) 
				getInnetDiv(child_divs[i]);
			else
				robj = child_divs[i];
		}
	}
	//alert(robj);
	return robj;	
}

function trim(str) 
{ 
    return str.replace(/^\s+|\s+$/g,''); 
} 

function initColumns() {
	
	if( gvbody == '' ) return;

	var bw=0;
	var c1w=0;
	var c2w=0;
	var width=0;
	
	bw=gvbody.offsetWidth;
	width = bw;
	
	//alert(bw);

	if( gvcomp1 ) {
		c1w=gvcomp1.offsetWidth;
		
		//alert('gvcomp1.innerHTML: '+gvcomp1.innerHTML);
		
		if( trim(gvcomp1.innerHTML) == '' ) {
			width += c1w;
			gvcomp1.style.display = "none";
			//alert('HERE');
		}
		else {
			var tmp = getInnetDiv(gvcomp1);
			//alert('RRRRRR');
			/*if( tmp ) {
alert(tmp.innerHTML);
				if( trim(tmp.innerHTML) == '' ) {
					width += c1w;
					gvcomp1.style.display = "none";
				}
			}*/
		}
	}	
	
	if( gvcomp2 ) {
		c2w=gvcomp2.offsetWidth;
		
		//alert('gvcomp2.innerHTML: '+gvcomp2.innerHTML);
		
		if( trim(gvcomp2.innerHTML) == '' ) {
			width += c2w;
			gvcomp2.style.display = "none";
		}
		else {
			var tmp = getInnetDiv(gvcomp2);
			//alert(tmp.innerHTML);
			/*if( tmp ) {
				//alert('HERE');
				if( trim(tmp.innerHTML) == '' ) {
					width += c2w;
					gvcomp2.style.display = "none";
				}
			}*/
		}
	}
	
//	alert(gvbody.style.padding);
//alert(width);
	gvbody.style.width = (width-10) + "px";
}