﻿/*
 +-----------------------------------------------------------------------+
 | 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 jscookie(){
  this.get_offset_time = function(offset_str, factor)
  {
    if (factor == null) factor=1;

    var regs = null;
    var regex = new RegExp('^([0-9]+)\s*([smhdwnou])','i');
    regs = regex.exec(offset_str);

    if ( regs != null )
    {
      var amount = parseInt(regs[1]);
      var unit   = regs[2].toLowerCase();
    }
    else
    {
      var amount = parseInt(offset_str);
      var $unit  = 's';
    }
    
    var dt = new Date();
    var ts = dt.getTime();

    switch (unit)
    {
      case 'o':
      	ts = this.get_offset_time('30d', factor);
	break;
      case 'w':
        amount *= 7;
      case 'd':
        amount *= 24;
      case 'h':
        amount *= 60;
      case 'm':
        amount *= 60;
      case 's':
        amount *= 1000;
      case 'u':
        ts += amount * factor;
    }
  
    dt.setTime(ts);
    return dt.toGMTString();
  }

  this.create = function(name,value,time) {
    if (time) {
      var expires = "; expires="+this.get_offset_time(time);
    }
    else 
      var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
  }
											
  this.read = function(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  }

  this.erase = function(name) {
    this.create(name,"",-1);
  }
}

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();  	 
} 