var Mac = navigator.appVersion.indexOf('Mac',0) != -1;
var Win = navigator.appVersion.indexOf('Win',0) != -1;
var IE  = navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1;
var NN  = navigator.appName.indexOf("Netscape",0) != -1;
var Moz = navigator.userAgent.indexOf("Gecko") != -1;
var Vmajor = parseInt(navigator.appVersion); // ex. 3
var Vminor = parseFloat(navigator.appVersion); // ex. 3.01
var WinIE = (Win && IE);
var MacIE5 = ((Mac && navigator.appVersion.indexOf('MSIE 5',0) != -1) || (Mac && IE && VER > 4));


var MacIE4 = ((Mac && navigator.appVersion.indexOf('MSIE 4.',0) != -1));
var MacIE3 = ((Mac && navigator.appVersion.indexOf('MSIE 3.',0) != -1));

var bAgent = navigator.userAgent;
var d = document;
function sniffer(){
this.Win = bAgent.indexOf("Win",0) != -1 ? 1 :0;
this.Mac = bAgent.indexOf("Mac",0) != -1 ? 1 :0;
this.Moz = ((bAgent.indexOf("Gecko") != -1) && (bAgent.indexOf("Safari",0) == -1)) ? 1 :0;
this.OPERA = bAgent.indexOf("Opera",0) != -1 ? 1 :0;
this.SAFARI = bAgent.indexOf("Safari",0) != -1 ? 1 :0;
this.checkObj = d.all?(d.getElementById?3:2):(d.getElementById?4:(d.layers?1:0));
this.allObj = ((this.checkObj == 1) || (this.checkObj == 2) || (this.checkObj == 3) || (this.checkObj == 4));
return this;
}
var usr = new sniffer;


function swapImage(target,src) {
 if (document.images) document.images[target].src = src;
}


/* js component for "reloading page onResize"
   original source: resize.js 0.3 970811 by gary smith */
 if(!window.saveInnerWidth) {
   window.onresize = resizeIt;
   window.saveInnerWidth = window.innerWidth;
   window.saveInnerHeight = window.innerHeight;
 }
function resizeIt() {
    if (saveInnerWidth < window.innerWidth || 
        saveInnerWidth > window.innerWidth || 
        saveInnerHeight > window.innerHeight || 
        saveInnerHeight < window.innerHeight ) 
    {
        window.history.go(0);
    }
}


function actItemClick(_target) {
 if (!document.styleSheets) return;
 if (window.event) {
//  if (event.srcElement.tagName == "TD") _target.children.tags("A")[0].click();
  if (event.srcElement.tagName == "TD") _target.children.tags("TABLE").item(0).getElementsByTagName("A")[0].click();
 } else {
  location.href = _target.getElementsByTagName("A")[0].href;
 }
}

// ex) actItemFocus(this);
function actItemFocus(_target) {
 if (!document.styleSheets) return;
 var _bgColor = "#FFF27F";
 if (window.event) {
  if (!_target.contains(event.fromElement)) {
   _target.style.cursor = "hand";
   _target.style.backgroundColor = _bgColor;
  }
 } else {
  _target.style.cursor = "pointer";
  _target.style.backgroundColor = _bgColor;
 }
}

// ex) actItemBlur(this);
function actItemBlurA(_target) {
 var _bgColor = "#ffffff";
 if (!document.styleSheets) return;
 if (window.event) {
  if (!_target.contains(event.toElement)) {
   _target.style.cursor = "default";
   _target.style.backgroundColor = _bgColor;
  }
 } else {
  _target.style.cursor = "default";
  _target.style.backgroundColor = _bgColor;
 }
}


// ex) actItemBlur(this);
function actItemBlurB(_target) {
 var _bgColor = "#E5E5E5";
 if (!document.styleSheets) return;
 if (window.event) {
  if (!_target.contains(event.toElement)) {
   _target.style.cursor = "default";
   _target.style.backgroundColor = _bgColor;
  }
 } else {
  _target.style.cursor = "default";
  _target.style.backgroundColor = _bgColor;
 }
}


var staybColor="";
function stayMenu(id){
 if (!document.getElementById) return;
  var obj = document.getElementById(id);
  if(obj.style){
     if(obj.style.backgroundColor != "#ffe600") staybColor = obj.style.color;
     obj.style.backgroundColor = "#ffe600";
  }
}

/* open window */

function openWindow(url, title, width, height, options, move) {
	if (!!window && url) {
		if (!title) title = "_blank";
		if (!options) options = "toolbar=yes,location=yes,directories=yes,status=no,menubar=yes,scrollbars=yes,resizable=yes,favorites=no";
		var whop = "width="+width+",height="+height+","+options;
		newWin = window.open(url, title, whop);
		newWin.focus();
		if (move != 1) newWin.moveTo(0, 0);
	}
}

	function getWindowHeight(){
		if(usr.Mac && usr.checkObj == 1){
			return window.innerHeight;
		}else if(usr.Win && usr.checkObj == 1){
			return window.innerHeight - 16;
		}else if(usr.checkObj == 4){
			return window.innerHeight - 15;
		}else if(usr.OPERA || usr.checkObj == 2 || usr.checkObj == 3){
			return d.body.clientHeight;
		}
	}

	function getWindowXOffset(){
		if(usr.checkObj == 2 || usr.checkObj == 3){
			return d.body.scrollLeft;
		}else if(usr.checkObj == 1 || usr.checkObj == 4){
			return window.pageXOffset;
		}
	}
	function getWindowYOffset(){
		if(usr.checkObj == 2 || usr.checkObj == 3){
			return d.body.scrollTop;
		}else if(usr.checkObj == 1 || usr.checkObj == 4){
			return window.pageYOffset;
		}
	}

	function getDocHeight(){
		if(usr.checkObj == 1){
			return getTagTop('end') + 1;
		}else if(usr.checkObj == 2 || usr.checkObj == 3 || usr.checkObj == 4){
			return getTagTop('end');
		}
	}

	function getDistanceMaxY(){
		if(usr.allObj){
			return (getDocHeight() - getWindowHeight());
		}
	}

	function setObj(idName){
		return d.all ? d.all(idName) : d.getElementById ? d.getElementById(idName) : d.layers[idName];
	}

	function getTagTop(idName) {
		//alert('getTagTop: '+idName+',CheckObj: '+usr.checkObj);
		var obj = setObj(idName);
		var tagCoords = new Object();

		if(usr.OPERA && usr.Mac){
			return idName;
		} else if((usr.checkObj == 2) || (usr.checkObj == 3) || (usr.checkObj == 4)) {
			//alert('obj.offsetTop: '+obj.offsetTop);
			//alert('Alternative offset: '+document.getElementById(idName));
			tagCoords.y = obj.offsetTop;
			while ((obj = obj.offsetParent) != null) {
				tagCoords.y += obj.offsetTop;
			}
			if(usr.Mac && usr.Moz){
				return tagCoords.y - 12;
			}else if((usr.Win && usr.Moz) || (usr.Mac && usr.SAFARI)){
				return tagCoords.y - 9;
			}else{
				return tagCoords.y;
			}
		} else if(usr.checkObj == 1) {
			tagCoords.y = d.anchors[idName].y;
			return tagCoords.y;
		}return idName;
	}

	/*PageScroller*/
	var pageScrollTimer;
	function pageScroll(toX,toY,frms,frX,frY) {
	    //alert('PageScroll: '+toX+','+toY);
		if(pageScrollTimer) clearTimeout(pageScrollTimer);
		var spd = usr.Mac ? 14 :16;
		var actX = getWindowXOffset();
		var actY = getWindowYOffset();
		if(!toX || toX < 0) toX = 0;
		if(!toY || toY < 0) toY = 0;
		if(!frms) frms = usr.NN ? 10 :usr.Mac ? 4 :5;
		if(!frX) frX = 0 + actX;
		if(!frY) frY = 0 + actY;

		frX += (toX - actX) / frms;
		if (frX < 0) frX = 0;
		frY += (toY - actY) / frms;
		if (frY < 0) frY = 0;
		var posX = Math.ceil(frX);
		var posY = Math.ceil(frY);
		window.scrollTo(posX, posY);
		if((Math.floor(Math.abs(actX - toX)) < 1) && (Math.floor(Math.abs(actY - toY)) < 1)){
			clearTimeout(pageScrollTimer);
			window.scroll(toX,toY);
		}else if(posX != toX || posY != toY){
			pageScrollTimer = setTimeout("pageScroll("+toX+","+toY+","+frms+","+frX+","+frY+")",spd);
		}else{
			clearTimeout(pageScrollTimer);
		}
	}

	function jumpToAnchor(idName) {
	    //alert('Jump: '+idName);
		if(usr.allObj){
			if(!!idName){
				var anchorY = getTagTop(idName);
				var dMaxY = getDistanceMaxY();
				var setY = (anchorY<1)?0:(anchorY>dMaxY)?dMaxY:anchorY;
				if(anchorY>1){
					pageScroll(0,setY);
				}else if(anchorY<=1){
					pageScroll(0,0);
				}else{
					location.hash = idName;
				}
			}else{
				pageScroll(0,0);
			}
		}else{
			!!idName ? location.hash = idName : location.hash = "top";
		}
	}
	function jumpToPageTop() {
		if(usr.allObj){
			pageScroll(0,0);
		}else{
			!!idName ? location.hash = idName : location.hash = "top";
		}
	}

