﻿/*
 +-----------------------------------------------------------------------+
 | M@il.go.th Login library                                              |
 |                                                                       |
 | This file is part of the M@il.go.th                                   |
 | Copyright (C) 2005-2008, MICT, - Thailand                             |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 +-----------------------------------------------------------------------+
 | Author: Surapun Prasit - RDDI                                         |
 |         Government Information Technology Services(GITS)              |
 +-----------------------------------------------------------------------+
 
 varsion 0.2.5
 $Id: 081029
*/

function get_viewport_size()
{
 // ref. http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
  var viewport = Array();
  viewport.width  = 0;
  viewport.height = 0;
 
  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
  if (typeof window.innerWidth != 'undefined')
  {
      viewport.width = window.innerWidth,
      viewport.height = window.innerHeight
  }
 
 // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

  else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
  {
       viewport.width = document.documentElement.clientWidth,
       viewport.height = document.documentElement.clientHeight
  }
 
  // older versions of IE
 
  else
  {
       viewport.width = document.getElementsByTagName('body')[0].clientWidth,
       viewport.height = document.getElementsByTagName('body')[0].clientHeight
  }
	return viewport;
}

function layout(height_id){
	var bg   = document.getElementById('mailgoth-content');
	var site = document.getElementById(height_id);
	var height = site.offsetHeight+75;
	bg.style.height = height+'px';
}

function centeric(){
	var mbody = document.getElementById('mailgoth-body');
	var viewport   = get_viewport_size();
	var bodyHeight = mbody.offsetHeight;
	
	//mbody.offsetHeight+10 > viewport.height
	if( bodyHeight < viewport.height )
  {
		 var mtop = (viewport.height-mbody.offsetHeight)/2;
		 mbody.style.marginTop = mtop+'px';
  }
}

var preload_image = new Array();
function preloadImg(name,src){
	if (document.images)
			{
				preload_image[name] = new Image; 
				preload_image[name].src=src; 
			}
}

//var ksearch = new KSearch();

function doc_load(hobj){
	layout(hobj);
	centeric();
	//ksearch.add_env('listItem',env.domain);
	mgt=new MGT();
	mgt.load();
	for( img in env.preload_img ){
			preloadImg(img,env.preload_img[img]);
	}
}