﻿var agt=navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
if (is_ie) document.write("<link "+"href=\"http://auto.tanakama.com/css/autoklein_ie.css\" rel=\"stylesheet\" type=\"text/css\""+">");
addEvent(window, "load", updateHeight);
addEvent(window, "resize", on_resize);	

var noreload=false;


function updateHeight()
{		
	var body_height;
	var min_height=500;
	
	var main_top_height=document.getElementById("main-top").offsetHeight;
	var main_bottom_height=document.getElementById("main-bottom").offsetHeight;
	var content_height=document.getElementById("content").offsetHeight+main_top_height+main_bottom_height;
	
	if (is_ie) body_height=document.body.clientHeight;
	else body_height=window.innerHeight;
	
	h_main=Math.max(body_height,min_height);
	h_main=Math.max(h_main,content_height);

	h_content=h_main-(main_top_height+main_bottom_height);
	
	noreload=true;
	document.getElementById("main").style.height = h_main+"px";
	document.getElementById("content").style.height = h_content+"px";
	document.getElementById("menu-left").style.height = h_content+"px";
	
}

function on_resize()
{	
	if (!noreload)
	{
		if (is_ie) document.location.reload();
		else updateHeight();
	}
	else noreload=false;
}

function addEvent(elm, evType, fn, useCapture)
{
  if (elm.addEventListener)
  {
    elm.addEventListener(evType, fn, useCapture);
    return true;
  }
  else if (elm.attachEvent)
  {
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  }
  else alert("Handler could not be removed");
}