// JavaScript Document
/*
function SetTop(){
	
	if ($("content")){
		var headings;
		var headerrow;
		var h=document.getElementById('contentTitel').offsetHeight;
		
		document.getElementById('contentTitel').style.height=h;
		if ($("producttable")){
			headings = $("producttable").cloneNode(true);
			for (i=0; i<headings.attributes.length;i++){
				if (headings.attributes[i].nodeName.toLowerCase()=="id"){
					headings.attributes[i].nodeValue="productheadings";
					break;
				}
			}
			
			for (i=0; i<headings.childNodes.length;i++){
				if (headings.childNodes[i].nodeName.toLowerCase()=="tbody"){
					if (false){// (document.all){
						headings.childNodes[i].style.display="none";
					}else{
						headings.childNodes[i].style.visibility="hidden";
						headings.childNodes[i].style.height=0;
						headings.childNodes[i].style.overflow="hidden";
						headings.childNodes[i].style.lineHeight=0;
					}
				}else if(headings.childNodes[i].nodeName.toLowerCase()=="thead"){
					for (j=0;j< headings.childNodes[i].childNodes.length;j++){
						if(headings.childNodes[i].childNodes[j].nodeName.toLowerCase()=="tr"){
						headerrow= 	headings.childNodes[i].childNodes[j];
						}
					}
				}
			}
			//headings is now a table with just theads
			//now strip heading of the procducttable
			for (i=0; i<$("producttable").childNodes.length;i++){
			if ($("producttable").childNodes[i].nodeName.toLowerCase()=="thead"){
					if (document.all){
						$("producttable").childNodes[i].style.display="none";
					}else{
						$("producttable").childNodes[i].style.visibility="hidden";
						$("producttable").childNodes[i].style.height=0;
						$("producttable").childNodes[i].style.lineHeight=0;
					}
					break;
				}
			}	
			var foot= element("tfoot");
			foot.appendChild(headerrow.cloneNode(true));
			
			$("producttable").appendChild(foot);
			
			$("tablecontainer").parentNode.insertBefore ( headings, $("tablecontainer") );
		}	
			//$("producttable_body").style.height=(parseInt($("content").style.height)-parseInt($("producttable_head").offsetHeight))-5 + "px" ;		
		$("content").style.height=document.body.offsetHeight- h -190 + 'px';
		
		if ($("producttable")){
			h= h+headings.offsetHeight;
			$("tablecontainer").style.height=document.body.offsetHeight- h -190+ 'px';
		}
	}
}
*/
/*
function SetTop(){
	
	if ($("content")){
		
		var h = document.getElementById('contentTitel').offsetHeight;
		
		if ($("tablecontainer")){
			var headings = $("headings");	//get headers; childnodes should be th's
			var bottomTable = $("producttable_body"); 
			var tableBody;
			var tableRow;
			var headimg = $("fakeheadimg");
			var prodimg = $("fakeprodimg");
			var widths = new Array();
			// get a row from bottom table
			for (i=0; i<bottomTable.childNodes.length;i++){
				if (bottomTable.childNodes[i].nodeName.toLowerCase()=="tbody"){
					tableBody= bottomTable.childNodes[i];
					break;
				}
			}
			for (i=0; i<tableBody.childNodes.length;i++){
				if (tableBody.childNodes[i].nodeName.toLowerCase()=="tr"){
					tableRow= tableBody.childNodes[i];
					break;
				}
			}
			//we have row from both tables
			//they should contain the same number of cells, one as th, the other as td
			
			var j=0
			for (i=0; i<tableRow.childNodes.length;i++){
				if (tableRow.childNodes[i].nodeName.toLowerCase()=="td"){
					if (tableRow.childNodes[i].offsetWidth >headings.childNodes[i].offsetWidth){
						// bottomcolumn is wider; apply to heading
						widths[j] = tableRow.childNodes[i].offsetWidth+"px";
					}else{
						widths[j] = headings.childNodes[i].offsetWidth+"px";
					}
				j++;
				}
			}
		
			//now set em all
			j=0 	
			for (i=0; i < headimg.childNodes.length;i++){
				if (headimg.childNodes[i].nodeName.toLowerCase()=="td"){
					for (k=0; k < headimg.childNodes[i].childNodes.length;k++){
						if (headimg.childNodes[i].childNodes[k].nodeName.toLowerCase()=="img"){
							headimg.childNodes[i].childNodes[k].style.width = widths[j]
							prodimg.childNodes[i].childNodes[k].style.width = widths[j]
							j++;
						}
					}
				}
			}
		}	
		// now to set the height of content; then set the height of tablecontainer (if needed)
		$("content").style.height=document.body.offsetHeight- h -190 + 'px';
		
		if ($("tablecontainer")){
			h= h+headings.offsetHeight;
			$("tablecontainer").style.height=document.body.offsetHeight- h -195+ 'px';
		} 
	}
}
*/
//rewrite to use tablerow.cells for better workings..
function SetTop(){
	
	if ($("content")){
		
		var h = document.getElementById('contentTitel').offsetHeight;
		
		if ($("tablecontainer")){
			var headings = $("headings");	//get headers; childnodes should be th's
			var bottomTable = $("producttable_body"); 
			var tableBody;
			var tableRow;
			var headimg = $("fakeheadimg");
//			var prodimg = $("fakeprodimg");
			var widths = new Array();
			// get a row from bottom table
			for (i=0; i<bottomTable.childNodes.length;i++){
				if (bottomTable.childNodes[i].nodeName.toLowerCase()=="tbody"){
					tableBody= bottomTable.childNodes[i];
					break;
				}
			}
			for (i=0; i<tableBody.childNodes.length;i++){
				if (tableBody.childNodes[i].nodeName.toLowerCase()=="tr"){
					tableRow= tableBody.childNodes[i];
					break;
				}
			}
			//we have row from both tables
			//they should contain the same number of cells, one as th, the other as td
			var j=0
			for (i=0; i<tableRow.cells.length;i++){

//				if (tableRow.cells[i].offsetWidth >headings.cells[i].offsetWidth){
						// bottomcolumn is wider; apply to heading
					widths[j] = tableRow.cells[i].offsetWidth+"px";
//				}else{
//					widths[j] = headings.cells[i].offsetWidth+"px";
//				}
			j++;
			}
			
			
			j=0 	
			for (i=0; i < headimg.cells.length;i++){
				for (k=0; k < headimg.cells[i].childNodes.length;k++){
					if (headimg.cells[i].childNodes[k].nodeName.toLowerCase()=="img"){
						headimg.cells[i].childNodes[k].style.width = widths[j]
//						prodimg.cells[i].childNodes[k].style.width = widths[j]
						j++;
					}
				}
			}			
			
/*			var j=0
			for (i=0; i<tableRow.childNodes.length;i++){
				if (tableRow.childNodes[i].nodeName.toLowerCase()=="td"){
					if (tableRow.childNodes[i].offsetWidth >headings.childNodes[i].offsetWidth){
						// bottomcolumn is wider; apply to heading
						widths[j] = tableRow.childNodes[i].offsetWidth+"px";
					}else{
						widths[j] = headings.childNodes[i].offsetWidth+"px";
					}
				j++;
				}
			}
	
	
			//now set em all
			j=0 	
			for (i=0; i < headimg.childNodes.length;i++){
				if (headimg.childNodes[i].nodeName.toLowerCase()=="td"){
					for (k=0; k < headimg.childNodes[i].childNodes.length;k++){
						if (headimg.childNodes[i].childNodes[k].nodeName.toLowerCase()=="img"){
							headimg.childNodes[i].childNodes[k].style.width = widths[j]
							prodimg.childNodes[i].childNodes[k].style.width = widths[j]
							j++;
						}
					}
				}
			}
*/
		}	

		// now to set the height of content; then set the height of tablecontainer (if needed)
		$("content").style.height=document.body.offsetHeight- h -185 + 'px';
		
		if ($("tablecontainer")){
			h= h+headings.offsetHeight;
      $("tablecontainer").style.height=document.body.offsetHeight- h -203+ 'px';
      if (bottomTable.offsetHeight>h) {
        //we'll be having a scrollbar; so we should have the headings slimmed by 16px.
        $("headerbody").style.paddingRight = 16 +"px";    
      }
		} 
	}
}

function SetTopff(){
	if ($("content")){
		top = $("content").offsetTop;
		alert(top);
		alert(document.body.offsetHeight);
		$("content").style.height=document.body.offsetHeight- top -30 + 'px';
		$("producttable_body").style.height=(parseInt($("content").style.height)-parseInt(document.defaultView.getComputedStyle($("producttable_head"), null)[height])) + "px" ;
	}
}

function beforePrint(){
	alert('yo');
	if ($("content")){
		$("content").style.height="auto";
		$("content").style.overflowY = "visible"; 
	}
	if ($("tablecontainer")){
			$("tablecontainer").style.height="auto";
			$("tablecontainer").style.overflowY = "visible"; 
	}
}
//window.onbeforeprint= beforePrint;
