
//function initPage

$(window).load(function() {
	if (typeof(MM_preloadImages) == "function") {
		MM_preloadImages('image/index/menu01_.gif',
			'image/index/menu01_sub01_.gif',
			'image/index/menu01_sub02_.gif',
			'image/index/menu01_sub03_.gif',
			'image/index/menu01_sub04_.gif',
			'image/index/menu01_sub05_.gif'
		);
	}

	$("comment.object").each(function() {
		$(this).after(this.innerHTML);
	});
	
	$("img.rollover").each(function() {
		rollover_apply(this);
	});
	
	if (typeof(gi_FocusPos) != "undefined") {
		$("input:text").focus(function() {
			gi_FocusPos = this;
		});
	}
	
	$("span.tab").mouseover(function() {
		//$(this).addClass("tab_over");
		//$(this).toggleClass("tab");
		if (this.getAttribute("selected") != "yes") {
			$.className.add(this, "tab_over");
		}
	});
	
	$("span.tab").mouseout(function() {
		//$(this).removeClass("tab_over");
		//$(this).toggleClass("tab");
		if (this.getAttribute("selected") != "yes") {
			$.className.remove(this, "tab_over");
		}
	});
	
	// Á¤·Ä Ç×¸ñ Ç¥½Ã
	if (document.frm) {
		if (document.frm.OldField && document.frm.SortMode) {
			var sort = document.frm.OldField.value;
			var mode = document.frm.SortMode.value;
			if (sort && mode) {
				var ch = (mode == "a") ? "¡å" : "¡ã";
				var a = document.getElementById(sort);
				if (a) { a.innerHTML = a.innerHTML + "&nbsp;<font color='blue'>" + ch + "</font>"; }
			}
		}
	}
	
	// °Ë»ö °£·«¿¡¼­ À¯Çüº° ÀÚ·á ÀÌ¹ÌÁö¸¦ »ó´Ü¿¡ ³ªÅ¸³½´Ù
	/*
	var d = $("#datatype_image_list");
	if (d) {
		var dts = new Object();
		var dt
		$("img.datatype").each(function() {
			dt = this.getAttribute("datatype");
			if (dt && !dts[dt]) {
				d.append('<span class="type_image" datatype="' + dt + '"><img src="' + this.src + '" align="absmiddle" alt="' + dt + '">' + this.alt + '</span>');
				dts[dt] = true;
			}
		});
		
		var span = $("span.type_image");
		span.mouseover(function() {
			var dt = this.getAttribute("datatype");
			if (dt) {
				$("tr[@datatype='" + dt + "']").addClass("tracked");
			}
		});
		span.mouseout(function() {
			var dt = this.getAttribute("datatype");
			if (dt) {
				$("tr[@datatype='" + dt + "']").removeClass("tracked");
			}
		});
		span.click(function() {
			var dt = this.getAttribute("datatype");
			if (dt) {
				$("tr[@datatype='" + dt + "']").each(function() {
					$("input:checkbox", this).attr("checked", true);
				});
			}
		});
	}
	*/
	
	d = document.getElementById("selectAll");
	if (d) {
		$(d).click(function() {
			var chks = $(".listitem");
			chks.attr("checked", true);
		});
	}
	
	window.status = "¿Ï·á";
	
	InitializeStaticMenu();
});


//========================================================
//  ÀÌ¹ÌÁö ·Ñ¿À¹ö °ü·Ã Function
//========================================================
function rollover_getoversrc(src) {
	var imgsrc = "";
	var index = src.lastIndexOf(".");
	if (index >= 0) {
		var name, ext;
		
		name = src.substr(0, index);
		ext = src.substr(index);
		
		if (name.charAt(name.length - 1) == '_') {
			imgsrc = src;
		} else {
			imgsrc = name + "_" + ext;
		}
	}
	return imgsrc;
}

function rollover_getoutsrc(src) {
	var imgsrc = "";
	var index = src.lastIndexOf(".");
	if (index >= 0) {
		var name, ext;
		
		name = src.substr(0, index);
		ext = src.substr(index);
		
		if (name.charAt(name.length - 1) != '_') {
			imgsrc = src;
		} else {
			imgsrc = name.substr(0, name.length - 1) + ext;
		}
	}
	return imgsrc;
}

function rollover_over() {
	this.src = rollover_getoversrc(this.src);
}

function rollover_out() {
	this.src = rollover_getoutsrc(this.src);
}

function rollover_apply(img) {
	var src = img.src;
	var overimg = rollover_getoversrc(src);

	if (src != overimg) {
		img.setAttribute("srcimage", src);
		img.setAttribute("overimage", overimg);
			
		$(img).mouseout(rollover_out);
		$(img).mouseover(rollover_over);
	}
}

function rollover_remove(img) {
	$(img).unbind("mouseover", rollover_over);
	$(img).unbind("mouseout", rollover_out);
}
//===============================================================

//========================================================
//  Æû °ü·Ã
//========================================================
function checkForm(f) {
	var filtered = $(".required", f).filter(function() {
		var p = $(this);
		if ($.trim(p.val()) == "") {
			var hname = p.attr("hname");
			if (!hname) hname="°ª";
			alert(hname + "À»(¸¦) ÀÔ·ÂÇÏ¼¼¿ä");
			p.focus();
			return true;
		} else {
			return false;
		}
	});
	var ok = filtered.size() ? false : true;
	return ok;
}

// container °¡ Æ÷ÇÔÇÏ´Â input À» ¹ÝÈ¯
// ¿¹¸¦ µé¾î type="checkbox"ÀÏ °æ¿ì´Â Ã¼Å©¹Ú½º¸¦ ¹ÝÈ¯
function getInputElements(container, type, name) {
	var elems = container.getElementsByTagName("input");
	var cbs = new Array();

	type = type.toLowerCase();
	for (var ii = 0; ii < elems.length; ii++) {
		if (elems[ii].type.toLowerCase() == type && (!name || elems[ii].name == name))
			cbs.push(elems[ii]);
	}

	return cbs;
}

// Ã¼Å©¹Ú½º Åä±Û
// value=""ÀÏ °æ¿ì´Â ÀüÃ¼ Ã¼Å©¹Ú½º·Î Ã³¸®ÇÑ´Ù
/*
function toggleCheckBox(input, parent, passive) {
	if (!input) return;
	passive = false;

	var cbs = getInputElements(parent ? parent : input.parentNode, "checkbox");
	var all;
	var cb;
	var ii;
	var cnt = 0;
	var checkall = false;

	if (input.value == "") {
		all = input;
		if (!passive) {
			for (ii = 0; ii < cbs.length; ii++) {
				cbs[ii].checked = true;
			}
		} else {
			for (ii = 0; ii < cbs.length; ii++) {
				cb = cbs[ii];
				if (cb.value != "") {
					cb.checked = input.checked;
				}
			}
		}
	} else {
		for (ii = 0; ii < cbs.length; ii++) {
			cb = cbs[ii];
			if (cb.value == "") {
				all = cb;
			}	else {
				if (cb.checked) cnt++;
			}
		}
		if (all) {
			if (cnt == 0) {
				if (!passive) checkall = true;
			} else if (cnt == cbs.length - 1) {
				checkall = true;
			}
			else all.checked = false;
		}
		if (checkall) {
			for (ii = 0; ii < cbs.length; ii++) {
				cb = cbs[ii];
				if (cb.value != "") {
					cb.checked = true;
				}
			}
			all.checked = true;
		}
	}
}
*/
function goUseApp(kossdano) {
	location = "w05_01c.asp?KossdaNo=" + kossdano;
}

function toggleCheckBox(input, parent, passive) {
	if (!input) return;

	var cbs = getInputElements(parent ? parent : input.parentNode, "checkbox");
	var all;
	var cb;
	var ii;
	var cnt = 0;
	var checkall = false;

	if (input.value == "") {
		all = input;
		all.checked = true;
		for (ii = 0; ii < cbs.length; ii++) {
			cb = cbs[ii];
			if (cb.value != "") {
				cb.checked = false;
			}
		}
	} else {
		for (ii = 0; ii < cbs.length; ii++) {
			cb = cbs[ii];
			if (cb.value == "") {
				all = cb;
			}	else {
				if (cb.checked) cnt++;
			}
		}
		if (all) {
			if (cnt == 0) {
				if (!passive) checkall = true;
			} else if (cnt == cbs.length - 1) {
				checkall = true;
			}	else all.checked = false;
		}
		if (checkall) {
			for (ii = 0; ii < cbs.length; ii++) {
				cb = cbs[ii];
				if (cb.value != "") {
					cb.checked = false;
				}
			}
			all.checked = true;
		}
	}
}

var SelectBox = {
	setOptions: function(selectbox, options, def) {
		while (selectbox.options.length > 0) {
			selectbox.options.remove(0);
		}
		for (k in options) {
			var opt = document.createElement("option");
			opt.value = k;
			opt.text = options[k];
			if (def && def == k) {
				opt.defaultSelected = true;
				opt.selected = true;
			}
			selectbox.options.add(opt);
		}
	}
}

var Collapsible = {
	show: function(f) {
		f = $(f);
		var w = f.width();
		
	},
	
	hide: function(f) {
		f = $(f);
		var w = f.width();
	},
	
	attach: function(f) {
		f = $(f);
		
		f.each(function() {
			var div;
			div = document.createElement("div");
			div.style.zIndex = 9;
			div.style.position = "relative";
			div.style.left = "0";
			div.style.top = "0";
			div.style.width = this.style.width;
			div.style.height = "20px";
			div.setAttribute("text", this.getAttribute("text"));
			div.style.textAlign = "right";
			
			$(div).insertBefore(this);
		});
	},
	
	over: function(f) {
		
	}
}

// ¹Ù±¸´Ï
var Basket = {
	_getItems: function(f) {
		var q = "";
		var qc = 0;
		
		$(".item", f).each(function() {
			var input;
			input = $("input", this);
			if (input[0].checked) {
				if (qc > 0) q += ",";
				q += input[1].value + ":" + input[2].value;
				qc++;
			}			
		});
		
		return q;
	},
	
	_call: function(cmd, items) {
		$.ajax({
			async:false,
			type: "POST",
			url : "x_basket.asp",
			data: "action=" + cmd + "&items=" + items,
			dataType: "xml",
			contentType: "application/x-www-form-urlencoded;charset=EUC-KR",
			
			success: function(xml) {
				alert(xml.selectSingleNode("//message").text);
			},
			error: function(http, msg, ex) {
				alert(msg);
			}
		});
	},
	
	add: function(f) {
		this._call("add", this._getItems(f));
	},
	
	addOne: function(ctrlno, datatype) {
		this._call("add", ctrlno + ":" + datatype);
	},
	
	remove: function(f) {
		this._call("remove", this._getItems(f));
	}, 
	
	addFavor: function(f) {
		this._call("addFavor", this._getItems(f));
	},
	
	addFavorOne: function(ctrlno, datatype) {
		this._call("addFavor", ctrlno + ":" + datatype);
	},
	
	removeFavor: function(f) {
		this._call("removeFavor", this._getItems(f));
	},
		
	goList: function(f) {
		f=eval(f);
		if (f) {
			f.target='_self';
			f.action='w_basket.asp';
			gf_StatusRun();		//ÁøÇà »óÅÂ Ç¥½Ã
			f.submit();
			return;
		}
	}
}


// °Ë»öÀÌ·Â
var History = {
	save: function(f) {
		var checks = $("input:checkbox[@name^='cbx_his']", $(f));
		var h = '';
		var c = 0;
		checks.each(function() {
			if (this.checked) {
				if (c > 0) h += ",";
				h += this.value;
				c++;
			}
		});

		$.ajax({
			async:false,
			type: "POST",
			url : "x_history.asp",
			data: "action=save&items=" + h,
			dataType: "xml",
			contentType: "application/x-www-form-urlencoded;charset=EUC-KR",
			
			success: function(xml) {
				alert(xml.selectSingleNode("//message").text);
			},
			error: function(http, msg, ex) {
				alert(msg);
			}
		});
	}
}

// ÆË¾÷
var Popup = {
	w02_07p: null, 
	w02_07q: null,
	c_subject: null,
	c_japan: null,
	zipfind: null,
	filebox: null,
	chargegubun: null,
	chargegubun_01a: null,
	chargegubun_01b: null,
	chargegubun_02a: null,
	chargegubun_02b: null,
	chargegubun_03a: null,
	chargegubun_03b: null,
	help: null,
	contents: null,
	abstracts: null,
	
	showHelp:function(index) {
		this.help = window.open("c_help_" + index + ".asp", "help", "width=840px,height=500px,scrollbars=yes");
		this.help.focus();
	},
	
	showVariables: function(kossdano, seqno) {
		this.w02_07p = window.open("w02_07p.asp?KossdaNo=" + kossdano + "&SeqNo=" + seqno, 
			"w02_07p", "width=500px,height=550px");
		this.w02_07p.focus();
	},
	
	showPoll: function(kossdano) {
		this.w02_07q = window.open("w02_07q.asp?KossdaNo=" + kossdano, 
			"w02_07q", "width=690px,height=550px");
		this.w02_07q.focus();
	},
	
	showSubject: function(selected, onselect, oldcode) {
		var param = "selected=" + selected + "&onselect=" + onselect;
		if (oldcode) param += "&type=oldclassno";
		this.c_subject = window.open("c_subject.asp?" + param, 
			"c_subject", "width=500px,height=600px");
		this.c_subject.focus();
	},
	
	showJapaneseChar: function(onselect){
		this.c_japan = window.open("c_japan.asp?onselect=" + onselect, 
			"c_japan", "width=515px,height=470px");
		this.c_japan.focus();
	},
	
	showZipFind: function(onselect) {
		this.zipfind = window.open("c_zipfind.asp?onselect=" + onselect, 
			"zipfind", "width=600px,height=380px");
		this.zipfind.focus();
	},
	
	showAttachFile: function(ctrlno, gubun) {
		var height = "530";
		if (!gubun || gubun == "0") height="300";
		this.filebox = window.open("c_download_popup.asp?ctrlno=" + ctrlno + "&gubun=" + gubun, 
			"filebox", "width=500px,height=" + height + "px");
		this.filebox.focus();
	},
		
	showMemberCharge: function(onselect) 
	{
		this.chargegubun = window.open("w01_05a_signup_popup.asp?onselect=" + onselect, 
			"chargegubun", "width=600px,height=342px");
		this.chargegubun.focus();
	},
	
	showMemberCharge_01a: function(onselect) 
	{
		this.chargegubun_01a = window.open("w01_05a_signup_popup_01a.asp?onselect=" + onselect, 
			"chargegubun_01a", "width=600px,height=342px");
		this.chargegubun_01a.focus();
	},
	
	showMemberCharge_01b: function(onselect) 
	{
		this.chargegubun_01b = window.open("w01_05a_signup_popup_01b.asp?onselect=" + onselect, 
			"chargegubun_01b", "width=600px,height=480px");
		this.chargegubun_01b.focus();
	},

	showMemberCharge_02a: function(onselect) 
	{
		this.chargegubun_02a = window.open("w01_05a_signup_popup_02a.asp?onselect=" + onselect, 
			"chargegubun_02a", "width=600px,height=520px");
		this.chargegubun_02a.focus();
	},

	showMemberCharge_02b: function(onselect) 
	{
		this.chargegubun_02b = window.open("w01_05a_signup_popup_02b.asp?onselect=" + onselect, 
			"chargegubun_02b", "width=600px,height=532px");
		this.chargegubun_02b.focus();
	},
	showMemberCharge_03a: function(onselect) 
	{
		this.chargegubun_03a = window.open("w01_05a_signup_popup_03a.asp?onselect=" + onselect, 
			"chargegubun_03a", "width=600px,height=380px");
		this.chargegubun_03a.focus();
	},
	
	showMemberCharge_03b: function(onselect) 
	{
		this.chargegubun_03b = window.open("w01_05a_signup_popup_03b.asp?onselect=" + onselect, 
			"chargegubun_03b", "width=600px,height=480px");
		this.chargegubun_03b.focus();
	},
	
	showContents: function(as_ctrlno, as_type)
	{
		var arg = "gs_arg=" + $.trim(as_ctrlno) + "," + $.trim(as_type);
		this.contents = window.open("c_content.asp?" + arg, "contents", "width=525px,height=400px");
		this.contents.focus();
	},
	
	showAbstracts: function(as_ctrlno, as_type)
	{
		var arg = "gs_arg=" + $.trim(as_ctrlno) + "," + $.trim(as_type);
		this.abstracts = window.open("c_abstract.asp?" + arg, "abstract", "width=525px,height=400px");
		this.abstracts.focus();
	}
}

function gs_print_win() {
	window.open("w_print.asp",  "print", "width=715,height=672,scrollbars=yes,resizable");
}

function gs_sendmail() {
	window.open("w_sendmail.asp",  "print", "width=715,height=672,scrollbars=yes,resizable");
}

/* Äü¸Þ´º ½ºÅ©·Ñ */
        var stmnLEFT = 915; // ½ºÅ©·Ñ¸Þ´ºÀÇ ÁÂÃø À§Ä¡. ÇÊ¿ä ¾øÀ» °æ¿ì »èÁ¦ 
        var stmnGAP1 = 115; // ÆäÀÌÁö Çì´õºÎºÐÀÇ ¿©¹é (ÀÌº¸´Ù À§·Î´Â ¿Ã¶ó°¡Áö ¾ÊÀ½) 
        var stmnGAP2 = 10; // ½ºÅ©·Ñ½Ã ºê¶ó¿ìÀú »ó´Ü°ú ¾à°£ ¶ç¿ò. ÇÊ¿ä¾øÀ¸¸é 0À¸·Î ¼¼ÆÃ 
        var stmnBASE = 200; // ½ºÅ©·Ñ¸Þ´º ÃÊ±â ½ÃÀÛÀ§Ä¡ (¾Æ¹«·¸°Ô³ª ÇØµµ »ó°üÀº ¾øÁö¸¸ stmnGAP1°ú ¾à°£ Â÷ÀÌ¸¦ ÁÖ´Â°Ô º¸±â ÁÁÀ½) 
        var stmnActivateSpeed = 500; // ¿òÁ÷ÀÓÀ» °¨ÁöÇÏ´Â ¼Óµµ (¼ýÀÚ°¡ Å¬¼ö·Ï ´Ê°Ô ¾Ë¾ÆÂ÷¸²) 
        var stmnScrollSpeed = 10; // ½ºÅ©·ÑµÇ´Â ¼Óµµ (Å¬¼ö·Ï ´Ê°Ô ¿òÁ÷ÀÓ) 
        var STATICMENU;
        var ANIMATE;

        var stmnTimer; 

        // ÄíÅ° ÀÐ±â 
        function ReadCookie(name) 
        { 
                var label = name + "="; 
                var labelLen = label.length; 
                var cLen = document.cookie.length; 
                var i = 0; 

                while (i < cLen) { 
                        var j = i + labelLen; 

                        if (document.cookie.substring(i, j) == label) { 
                                var cEnd = document.cookie.indexOf(";", j); 
                                if (cEnd == -1) cEnd = document.cookie.length; 

                                return unescape(document.cookie.substring(j, cEnd)); 
                        } 
      
                        i++; 
                } 

                return ""; 
        } 

        // ÄíÅ° ÀúÀå 
        function SaveCookie(name, value, expire) 
        { 
                var eDate = new Date(); 
                eDate.setDate(eDate.getDate() + expire); 
                document.cookie = name + "=" + value + "; expires=" +  eDate.toGMTString()+ "; path=/"; 
        } 

        // ½ºÅ©·Ñ ¸Þ´ºÀÇ À§Ä¡ °»½Å 
        function RefreshStaticMenu() 
        { 
                var stmnStartPoint, stmnEndPoint, stmnRefreshTimer; 

                stmnStartPoint = parseInt(STATICMENU.style.top, 10); 
                stmnEndPoint = document.body.scrollTop + stmnGAP2; 
                if (stmnEndPoint < stmnGAP1) stmnEndPoint = stmnGAP1; 

                stmnRefreshTimer = stmnActivateSpeed; 

                if ( stmnStartPoint != stmnEndPoint ) { 
                        stmnScrollAmount = Math.ceil( Math.abs( stmnEndPoint - stmnStartPoint ) / 15 ); 
                        STATICMENU.style.top = parseInt(STATICMENU.style.top, 10) + ( ( stmnEndPoint<stmnStartPoint ) ? -stmnScrollAmount : stmnScrollAmount ); 
                        stmnRefreshTimer = stmnScrollSpeed; 
                } 

                stmnTimer = setTimeout ("RefreshStaticMenu();", stmnRefreshTimer); 
        } 

        // ¸Þ´º ON/OFF ÇÏ±â 
        function ToggleAnimate() 
        { 
                if (ANIMATE.checked) { // ÀÌµ¿ÇÏ±â ¹öÆ°ÀÌ Ã¼Å©µÇ¾ú´Ù¸é 
                        RefreshStaticMenu(); // ¸Þ´ºÀ§Ä¡¸¦ ´Ù½Ã Á¶Á¤ 
                        SaveCookie("ANIMATE", "true", 300); // ÀÌµ¿ÀÌ ON »óÅÂ¶ó°í ÄíÅ°¸¦ ¼³Á¤ 
                } 
                else { // ¾Æ´Ï¶ó¸é... (ÀÌµ¿ÇÏ±â ¹öÆ°ÀÌ Ã¼Å©µÇ¾î ÀÖÁö ¾ÊÀ¸¸é) 
                        clearTimeout(stmnTimer); // ÀÌµ¿¿ë Å¸ÀÌ¸Ó ÇØÁ¦ 
                        STATICMENU.style.top = stmnGAP1; // ¸Þ´ºÀÇ À§Ä¡¸¦ »ó´ÜÀ¸·Î ¿Å±ä´Ù. 
                        SaveCookie("ANIMATE", "false", 300); // ÀÌµ¿»óÅÂ°¡ "OFF" ÀÓ 
                } 
        } 

        // ¸Þ´º ÃÊ±âÈ­ 
        function InitializeStaticMenu() 
        { 
        	STATICMENU = document.getElementById("STATICMENU");
        	ANIMATE = document.getElementById("ANIMATE");
        	
        	if (!STATICMENU) return;
        	
                if (ReadCookie("ANIMATE") == "false") { // ÀÌµ¿»óÅÂ°¡ off »óÅÂ¶ó¸é 
                       // ANIMATE.checked = false; // Ã¼Å©Ç¥½Ã¸¦ Áö¿ì°í 
                        STATICMENU.style.top = document.body.scrollTop + stmnGAP1; // ¸Ç À§¿¡ µé·¯ ºÙ´Â´Ù. 
                } 
                else { // ÀÌµ¿ on »óÅÂ¶ó¸é 
                        //ANIMATE.checked = true; // Ã¼Å©Ç¥½Ã¸¦ ÇÏ°í 
                        STATICMENU.style.top = document.body.scrollTop + stmnBASE; // ±âº»À§Ä¡·Î ÀÌµ¿ÇÑ´Ù. 
                        RefreshStaticMenu(); // ½ºÅ©¸³Æ® °¡µ¿ 
                } 

                STATICMENU.style.left = stmnLEFT; // ¸Þ´º ¿ÞÂÊ À§Ä¡ ÃÊ±âÈ­. ÇÊ¿ä¾øÀ» °æ¿ì »èÁ¦ 
        } 

