﻿
var gnb = {
	over : function(el){
		depth = el.getElementsByTagName("div")[0];
		depth_list = depth.getElementsByTagName("li");
		depth_link = depth.getElementsByTagName("a");
		depth.style.display = "block";
		el.onmouseout = depth.onmouseout = function(){
			depth.style.display = "none";
		}
		for(var i=0; i<depth_list.length; i++){
			depth_list[i].onmouseover = function(){ gnb.rollover(this); }
			depth_list[i].onmouseout = function(){ gnb.rollout(this); }
			depth_link[i].onfocus = function(){ this.blur(); }
			depth_link[i].onclick = function(){ depth.style.display = "none"; }
		}
	},
	rollover : function(el){
		el.getElementsByTagName("img")[0].src =
			el.getElementsByTagName("img")[0].src.replace(".gif","_on.gif");
	},
	rollout : function(el){
		el.getElementsByTagName("img")[0].src =
			el.getElementsByTagName("img")[0].src.replace("_on.gif",".gif");
	}
};


var category = {
	over : function(el){
		if(!el.onmouseout && el.className==""){
			el.className = "on";
			category.rollover(el);
		} else if(!el.onclick) { category.action(el); }
	},
	rollover : function(el){
		el.onmouseover = function(){ el.className = "on"; }
		el.onmouseout = function(){ el.className = ""; }
		category.action(el);
	},
	action : function(el){
		el.onclick = function(){
			var link = el.childNodes[0].getAttribute("href");
			if(el.childNodes[0].getAttribute("target") == "_blank"){
				window.open(link);
			} else {
				location.href = link;
			}
			return false;
		}
		el.childNodes[0].onfocus = function(){ this.blur(); }
	}
};


var news = {
	el : "tbl_news",
	action : function(el){
		if(!el){
			var table = document.getElementById(this.el);
		} else {
			this.el = el;
			var table = document.getElementById(this.el);
		}
		var tbody = table.getElementsByTagName("tbody")[0];
		var rows = tbody.childNodes;
		if(tbody.getElementsByTagName("tr").length == 0){
			news.none(tbody); //Not Find Data
			return false;
		}
		for(var i=0; i<rows.length; i++){
			if(rows[i].nodeType != 1 && rows[i].nodeName != "TR") continue;
			if(rows[i].getElementsByTagName("th").length > 0){
				news.open(rows,i);
			}
		}
		/*
		Preview
		ex)
		news.count = number;
		news.action();
		*/
		if(Number(this.count)){
			news.view(rows,(this.count*2)-2);
		}
	},
	close : function(el){
		for(var i=0; i<el.length; i++){
			if(el[i].nodeType != 1 && el[i].nodeName != "TR") continue;
			if(el[i].getElementsByTagName("th").length > 0){
				el[i].className = "";
			} else {
				el[i].style.display = "none";
			}
		}
	},
	open : function(el,n){
		el[n].onclick = function(){
			news.nextSibling(this);
			if(this.className == "on"){
				this.className = "";
				news.next.style.display = "none";
			} else {
				news.close(el);
				this.getElementsByTagName("th")[1].style.color = "";
				this.className = "on";
				news.next.style.display = "";
			}
			news.iframe(news.next);
		}
		el[n].onmouseover = function(){
			if(this.className != "on") this.className = "over";
		}
		el[n].onmouseout = function(){
			if(this.className != "on") this.className = "";
		}
	},
	view : function(el,n){
		for(var i=0; i<el.length; i++){
			if(el[i].nodeType != 1 && el[i].nodeName != "TR") continue;
			if(n == 0){
				el[i].getElementsByTagName("th")[1].style.color = "";
				el[i].className = "on";
				news.nextSibling(el[i]);
				news.next.style.display = "";
				news.iframe(news.next);
				break;
			} else {
				n--;
			}
		}
	},
	none : function(el){
		var tr = document.createElement("tr");
		var td = document.createElement("td");
		var text = document.createTextNode("Not Find Data!");
		td.className = "no-data";
		td.colSpan = "3";
		td.appendChild(text);
		tr.appendChild(td);
		el.appendChild(tr);
	},
	nextSibling : function(el){
		news.next = el;
		for(var i=0; i<100; i++){
			news.next = news.next.nextSibling;
			if(news.next.nodeType == 1) break;
		}
	},
	iframe : function(el){
	    if(typeof el.getElementsByTagName("iframe")[0] == "object"){
	        var ifmID = el.getElementsByTagName("iframe")[0].id;
	        var resizeFunc = function(){
                var height = document.getElementById(ifmID).contentWindow.document.body.scrollHeight;
                document.getElementById(ifmID).style.height = height + "px";
            }
	        if(Number(this.count)){
	            var loadFunc = window.onload;
                document.getElementById(ifmID).onload = function(){
                    resizeFunc();
                }
                if(typeof window.onload == "function"){
                    window.attachEvent("onload", loadFunc);
                }
            } else {
                resizeFunc();
            }
	    }
	}
};

var box = {
	count : 2,
	rgb : [246,0,70], //rgb[0]=red, rgb[1]=green, rgb[2]=blue
	color : function(el,desc,attr){
		if(!document.getElementById(el).style.display != "block"){
			document.getElementById(el).style.display = "block";
		}
		var g = Math.round((this.rgb[1]+this.count*4)/1.5);
		var b = Math.round(this.rgb[2]+this.count*2);
		var rgb = "rgb(" + this.rgb[0] + "," + g + "," + b + ")";
		if(217 != b && 217 > b){
			this.count += 2;
			document.getElementById(el).style.backgroundColor = rgb;
			change = setTimeout("box.color('"+el+"')",10);
		} else {
			this.count = 2;
			clearTimeout(change);
		}

		//Description
		if(desc && attr){
			box.description(desc,attr);
		} else if(desc){
			box.description(desc);
		} else { return false; }
	},
	text : ["id","pw","email","birth","gender","code"],
	description : function(el,attr){
		/*
		0 : User ID,
		1 : Password,
		2 : Email Address,
		3 : Date of Birth,
		4 : Gender,
		5 : Enter the code,
		*/
		var el = document.getElementById(el);
		var li = el.getElementsByTagName("li");
		for(var i=0; i<li.length; i++){
			li[i].style.display = "none";
			if(attr && attr == this.text[i]){
				li[i].style.display = "block";
			}
		}
	}
};


var input = {
    login : function(el){
		el.className = "";
		el.onblur = function(){
			if(el.value=="") el.className = "on";
		}
	},
	ok : function(el){
		el.className = "frmok";
	},
	error : function(el){
		el.className = "frmerror";
	},
	basic : function(el){
		el.className = "";
	}
};


var account = {
	el : "tbl_account",
	action : function(){
		if(!document.getElementById(this.el)) return false;
		var table = document.getElementById(this.el);
		var tr = table.getElementsByTagName("tr");
		tr[1].style.display = "";
		tr[2].style.display = "none";
		tr[3].style.display = "none";
		tr[1].getElementsByTagName("a")[0].onclick = function(){ 
			account.reset(tr[2],tr[3]);
			return false;
		}
	},
	reset : function(pw,repw){
		if(pw.style.display == "none"){
			pw.style.display = "";
			repw.style.display = "";
			pw.getElementsByTagName("input")[0].focus();
		} else {
			account.action();
			var el = document.getElementById("account_text");
			var el = el.getElementsByTagName("li");
			for(var i=0; i<el.length; i++){
				el[i].style.display = "none";
			}
			document.getElementById("alertbox_edit").style.display = "none";
		}
	}
};



var flash = {
	param : { url:"", w:"", h:"", wmode:"window", base:"./" },
	gnb : function(el){
		if(el){
		    
			this.param.url = "http://192.168.1.33/new/swf/main.swf?param=main&xmlLocation=" + el;
			this.param.w = "610";
			this.param.h = "256";
		} else {
			this.param.url = "http://192.168.1.33/new/swf/navi.swf";
			this.param.w = "570";
			this.param.h = "214";
		}
		    this.param.base = "http://192.168.1.33/new/swf/";
		    this.param.wmode = "transparent";
			flash.write(this.param.url,this.param.w,this.param.h,this.param.wmode,this.param.base);
		if(el){ document.getElementById("obj_flash").style.left = "-20px"; }
	},
	write : function(url,w,h,wmode,base){
		strObject =	"<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" id=\"obj_flash\" width=\"" + w + "\" height=\"" + h + "\">\n";
		strObject += "	<param name=\"allowScriptAccess\" value=\"always\" />\n";
		strObject += "	<param name=\"quality\" value=\"high\" />\n";
		strObject += "	<param name=\"movie\" value=\"" + url + "\" />\n";
		strObject += "	<param name=\"wmode\" value=\"" + wmode + "\" />\n";
		strObject += "	<param name=\"base\" value=\"" + base + "\" />\n";
		strObject += "	<embed src=\"" + url + "\" width=\"" + w + "\" height=\"" + h + "\" quality=\"high\" wmode=\"" + wmode + "\" base=\"" + base + "\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n";
		strObject += "</object>\n";
		document.write(strObject);
	}
};

var clock = {
	weekDays : ["SUN","MON","TUE","WED","THU","FRI","SAT"],
	monthNames : ["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"],
	serverDate : {}, // server date obj
	localDate : {}, // local date obj
	dateOffset: {}, // offset ammount
	nowDate : {}, // adjusted date
	dateString : {}, // formated
	el : {}, // element to update
	timeout : {}, // timeout handle
	init : function (date,id,interval) {
		this.calculateOffset(date);
		this.el = document.getElementById(id);
		this.updateClock(interval);
	},
	calculateOffset : function (serverDate) {
		this.serverDate = new Date(serverDate);
		this.localDate = new Date();
		this.dateOffset = this.serverDate - this.localDate;
	},
	updateClock : function (interval) {
		this.nowDate = new Date();
		this.nowDate.setTime(this.nowDate.getTime() + this.dateOffset);
		this.dateFormat(this.nowDate);
		this.el.innerHTML = this.dateString;
		var me = this; this.timeout = setTimeout(function(){me.updateClock(interval)},interval);
	},
	stopClock : function () {
		clearTimeout(this.timeout);
	},
	dateFormat : function (dateObj) {
		this.dateString = '<span>Hora Del Servidor ' + this.digit(dateObj.getHours()) + ':' + this.digit(dateObj.getMinutes()) + ':' + this.digit(dateObj.getSeconds()) + '</span>';
		this.dateString += ' ';
		this.dateString += this.monthNames[dateObj.getMonth()] + ' ';
		this.dateString += this.digit(dateObj.getDate()) + ', ';
		this.dateString += dateObj.getFullYear();
	},
	digit : function (str) {
		str = String(str);
		str = str.length == 1 ? "0" + str : str;
		return str;
	}
};