// CSME.PRO [  Encode in UTF-8  Without BOM ] [ ☺ ]

	//	useage:
	//	html,body { height: 100%; margin: 0; }
	//	window.onresize = FixElementsHeight; 	window.onload = FixElementsHeight;
	//	assign class="reheight" for 100% height elements
	
function FixElementsHeight() {
	FixElementsHeightOf(document);
	}

function FixElementsHeightOf(p) {

	var iefix = ( !/MSIE /.test(navigator.userAgent) ? false : true );
	var ie6fix = ( !/MSIE (5\.5|6\.)/.test(navigator.userAgent) ? false : true );
	var elements = p.getElementsByTagName("*");
	
	var fixElements = new Array();
	var fixElementsTypes = new Array();
	
	var fixElements_w_ie = new Array();
	
	var elements_length = elements.length;
	for(var i = 0;i<elements_length;i++) {	 
	//	o = elements.item(i);		
		o = elements[i];		


		
		// -----------------------------------------------------------------
		
		if (o.className.indexOf("reheight") != -1 ) {
			// Fix Width
			if (ie6fix) {
				if ( o.style.left.indexOf("px") != -1 && o.style.right.indexOf("px") != -1 ) {
					o.style.width = "1px";
					fixElements[fixElements.length] = o;			
					fixElementsTypes[fixElementsTypes.length] = "w-ie6";			
					}
				}
			// Fix Height
			if ( o.style.top.indexOf("px") != -1 && o.style.bottom.indexOf("px") != -1 ) {
				if (ie6fix) {
					o.style.height = "1px";
					fixElements[fixElements.length] = o;
					fixElementsTypes[fixElementsTypes.length] = "h-ie6";						
					}
				} else {
				o.style.height = "1px";
				fixElements[fixElements.length] = o;
				fixElementsTypes[fixElementsTypes.length] = "h-100";	
				}

			} 
			
		// -----------------------------------------------------------------
		if (o.className.indexOf("rewidth") != -1 ) {
			if (iefix) {
				fixElements_w_ie[fixElements_w_ie.length] = o;
				}
			}
		// -----------------------------------------------------------------
		}	
	var i;
	
	var fixElements_length = fixElements.length;
	for(i = 0;i<fixElements_length;i++) {
		o = fixElements[i];
		switch (fixElementsTypes[i]) {
			case "h-ie6":
				FixAbsoluteElementHeight(o);
				break;
			case "w-ie6":
				FixAbsoluteElementWidth(o);		
				break;
			case "h-100":
				FixElementHeight(o);
				break;
			
			}
		}
	
	var fixElements_w_ie_length = fixElements_w_ie.length;	
	for(i = 0;i<fixElements_w_ie_length;i++) {
		o = fixElements_w_ie[i];
		setTimeout( function(){ FixElementWidth( o );  }  , 0 );
		}
	
	}

function FixElementWidth(p) {
	var elements = p.getElementsByTagName("*");
	var elements_length = elements.length;
	for(var i = 0;i<elements_length;i++) {	 
	//	o = elements.item(i);
		o = elements[i];
		if ( (o.offsetLeft < 0 && getCSSProp(o,"width") == "100%") || o.rewidth ) {
			o.rewidth = 1;
			o.style.width = "100%";
			var new_width = o.offsetWidth + o.offsetLeft;
			o.style.width = new_width + "px";
			}
		}
	}
	

function FixAbsoluteElementHeight(o) {
	p = GetParentNode(o);

	if (p) {
		lastdisplay = o.style.display;
		o.style.height = "1px";
		o.style.display = "none";

		var newHeight = 0;
		newHeight += p.offsetHeight;
		newHeight -= parseNum(o.style.top);
		newHeight -= parseNum(o.style.bottom);

		if (newHeight) {
			if ( newHeight > 0 ) {
				o.style.height = newHeight+"px";
				o.height = newHeight;
				o.style.display = lastdisplay;
				FixTableRowsHeight(o);
				return ;
				}
			}
		o.style.display = lastdisplay;
		}
	}
	
function FixAbsoluteElementWidth(o) {
	p = GetParentNode(o);
	
	if (p) {
		lastdisplay = o.style.display;
		o.style.width = "1px";
		o.style.display = "none";

		var newWidth = 0;
		newWidth += p.offsetWidth;
		newWidth -= parseNum(o.style.left);
		newWidth -= parseNum(o.style.right);

		if (newWidth) {
			if ( newWidth > 0 ) {
				o.style.width = newWidth+"px";
				o.width = newWidth;
				o.style.display = lastdisplay;
				return ;
				}
			}
		o.style.display = lastdisplay;
		}
	}
	
function parseNum(str) {
	num = 0 ;
	if (!str) return num;
	if (str.indexOf("%") != -1) return num;
	num = parseInt(str);
	if (!num) num=0;
	return num;
	}

function GetParentNode(o) {
	p = o.parentNode;
	if (p.tagName == "FORM") p = GetParentNode(p);
	return p;
	}
	
	
function FixElementHeight(o) {
	p = GetParentNode(o);
	
	if (p) {
		lastdisplay = o.style.display;
		o.style.height = "1px";
		o.style.display = "none";

		var newHeight = 0;
		newHeight += p.offsetHeight;
		
		newHeight -= parseNum(p.style.paddingTop);
		newHeight -= parseNum(p.style.paddingBottom);

		newHeight -= parseNum(o.style.top);		
		newHeight -= parseNum(o.style.bottom);
		newHeight -= parseNum(o.style.marginTop);
		newHeight -= parseNum(o.style.marginBottom);		

		if (newHeight) {
			if ( newHeight > 0 ) {
				o.style.height = newHeight+"px";
				o.height = newHeight;
				o.style.display = lastdisplay;
				FixTableRowsHeight(o);
				setTimeout( function(){ var hh = parseNum(o.style.height); o.style.height = (hh-1)+"px"; o.style.height = hh+"px"; }  ,0 );
				return ;
				}
			}

		o.style.display = lastdisplay;
		}
	}

function FixTableRowsHeight (o) {
	if (o.tagName != "TABLE") return ;
	if (o.style.display == "none") return;
	if (o.rows < 1) return ;

	var TotalHeight = 0;
	var AutoHeightRows = new Array();

	var o_rows_length = o.rows.length;
	for(row=0; row<o_rows_length; row++)  {
		tr = o.rows[row];
		TrAutoHeight = ( tr.className.indexOf("autoheight") != -1 ? true : false );
		TrHeight = 0;

		TrHeight = parseNum(tr.style.height);
		if (TrHeight==0) TrHeight = parseNum(tr.height);

		var o_rows_cells_length = o.rows[row].cells.length;
		for(cell=0; cell<o_rows_cells_length; cell++) {
			td = o.rows[row].cells[cell];
			TdHeight = 0;
			TdHeight = parseNum(td.style.height);
			if (TdHeight==0) TdHeight = parseNum(td.height);
			if (TdHeight > TrHeight) TrHeight = TdHeight;
			if (td.className.indexOf("autoheight") != -1) TrAutoHeight = true;
			}

		if ( TrAutoHeight == true ) { 
			TrHeight = 0;
			} else if ( TrHeight == 0 ) {
			tr.className = tr.className + " autoheight";
			TrAutoHeight  = true;
			}

		if ( tr.style.display == "none" ) {
			TrHeight = 0;
			} else if (TrAutoHeight == true) {
			AutoHeightRows[AutoHeightRows.length] = row;
			}
		TotalHeight += TrHeight;
		}
	
	if (AutoHeightRows.length>0) {
		var SelfHeight = parseNum(o.style.height);
		if (SelfHeight==0) SelfHeight = o.offsetHeight;
		var AutoHeight = SelfHeight - TotalHeight;
		if (AutoHeight >= 0 ) {
			var EachRowHeight = ( AutoHeight == 0 ? 0 : Math.floor(AutoHeight/AutoHeightRows.length) );
			var FirstRowHeight = AutoHeight - (EachRowHeight * AutoHeightRows.length);
			var AutoHeightRows_length = AutoHeightRows.length;
			for(i=0; i<AutoHeightRows_length; i++) {
				row = AutoHeightRows[i];
				row = o.rows[row];
				SetTableRowHeight (row,( EachRowHeight + FirstRowHeight)+"px");
				FirstRowHeight = 0;	
				}
			}
	//	FixElementsHeightOf(o);
		}
	}

function SetTableRowHeight (tr,height) {
	if (tr.tagName!="TR") return ;
	tr.height = height;
	tr.style.height = height;
	var tr_cells_length = tr.cells.length;
	for(cell=0; cell<tr_cells_length; cell++) {
		td = tr.cells[cell];
		td.height = height;
		td.style.height = height;			
		}
	}
	
function SetTableRowAutoHeight(tr,mode) {
	if (tr.tagName!="TR") return ;
	if ( mode == true ) {
		if (tr.className.indexOf("autoheight") == -1) tr.className + " autoheight";
		var tr_cells_length = tr.cells.length;
		for(cell=0; cell<tr_cells_length; cell++) {		
			td = tr.cells[cell];	
			if (td.className.indexOf("autoheight") == -1) td.className + " autoheight";
			}
		} else {
		if (tr.className.indexOf("autoheight") != -1) tr.className = tr.className.replace("autoheight", "");
		var tr_cells_length = tr.cells.length;
		for(cell=0; cell<tr_cells_length; cell++) {		
			td = tr.cells[cell];	
			if (td.className.indexOf("autoheight") != -1) td.className = td.className.replace("autoheight", "");	
			}			
		}
	}
	
	
// ---------------------------------------------------------------------------------------

	
