function ShowHideComTrack(com,v1,trk,v2) {
	var id1 = com+"-title";
	var id2 = trk+"-title";
	var obj1, obj2;
	if((t1_obj = document.getElementById(id1))
		&& (t2_obj = document.getElementById(id2))
		&& (obj1 = document.getElementById(com))
		&& (obj2 = document.getElementById(trk))) {
		if(v1 == 'show') {
			t1_obj.setAttribute("className","news_view_tr_com_show");
			t1_obj.setAttribute("class","news_view_tr_com_show");
			obj1.style.display = 'block';
		} else {
			t1_obj.setAttribute("className","news_view_tr_com_hide");
			t1_obj.setAttribute("class","news_view_tr_com_hide");
			obj1.style.display = 'none';
		}
		if(v2 == 'show') {
			t2_obj.setAttribute("className","news_view_tr_com_show");
			t2_obj.setAttribute("class","news_view_tr_com_show");
			obj2.style.display = 'block';
		} else {
			t2_obj.setAttribute("className","news_view_tr_com_hide");
			t2_obj.setAttribute("class","news_view_tr_com_hide");
			obj2.style.display = 'none';
		}
	}
}

String.prototype.mbLength = function() {
	var result = 0;
	for(var i=0; i<this.length; ++i) {
		var c = this.charAt(i);
		var enc = encodeURIComponent(c);
		result++;
		if(enc.length > 3) {
			result++;
		}
	}
	return result;
}

String.prototype.ltrim = function() {
	return this.replace(/^\s+/g, "");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/g, "");
}

String.prototype.trim = function() {
	return this.ltrim().rtrim();
}

/*** XMLHttpRequest functions ***/

var xmlHttp;

function xmlRequest(requestURL, callbackFunction) {
	if(window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	// Send Asynchronous Request
	xmlHttp.open("GET", requestURL, true);
	xmlHttp.onreadystatechange = callbackFunction;
	xmlHttp.send(null);
}

function isResponseDone() {
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			return true;
		}
	}
	return false;
}

function getXMLResult(tagName) {
	var nodeList = xmlHttp.responseXML.getElementsByTagName(tagName);
	if(nodeList.length == 0) {
		return null;
	} else if(nodeList.length == 1) {
		return getNodeValue(nodeList[0]);
	} else {
		var result = new Array();
		for(var i=0; i<nodeList.length; ++i) {
			result.push(getNodeValue(nodeList[i]));
		}
		return result;
	}
}

function getRSSResult() {
	var result = new Array();
	var nodeList = xmlHttp.responseXML.getElementsByTagName("item");
	for(var i=0; i<nodeList.length; ++i) {
		var rssItem = new RSSItem();
		rssItem.set(nodeList[i]);
		result.push(rssItem);
	}
	return result;
}

/*** RSSItem : RSS Item Object ***/
RSSItem = function() {
	// members : author, link, desciption, pubDate
	this.author = "";
	this.link = "";
	this.description = "";
	this.pubDate = "";
	this.title = "";
}

RSSItem.prototype.set = function(itemNode) {
	var childs = itemNode.childNodes;
	for(var i=0; i<childs.length; ++i) {
		var nodeName = childs[i].nodeName.trim().toLowerCase();
		if(nodeName == "author") {
			this.author = getNodeValue(childs[i]);
		} else if(nodeName == "title") {
			this.title = getNodeValue(childs[i]);
		} else if(nodeName == "link") {
			this.link = getNodeValue(childs[i]);
		} else if(nodeName == "description") {
			this.description = getNodeValue(childs[i]);
		} else if(nodeName == "pubdate") {
			this.pubDate = getNodeValue(childs[i]);
		}
	}
}

/*** DOM functions ***/
function getNodeValue(node) {
	var childs = node.childNodes;
	for(var i=0; i<childs.length; ++i) {
		if(childs[i].nodeType == 3 || childs[i].nodeType == 4) {
			return childs[i].data.trim();
		}
	}
}

function recommand(url,callbackFunction) {
	xmlRequest(url,callbackVote);
}

function callbackVote() {
	var result = null;
	if(isResponseDone()) {
		result = getRSSResult();
		if(result != null) {
			voteUpdate("_vote",result);
		}
	}
}

function voteUpdate(id,result) {
	var obj = document.getElementById(id);
	if(obj) {
		if(result.length > 0) {
			var itemObj = result[0];
			if(itemObj.title == "vote") {
				obj.innerHTML = itemObj.description;
				alert('ÀÌ ±â»ç¿¡ ´ëÇÑ ÃßÃµÀÌ ¿Ï·áµÇ¾ú½À´Ï´Ù.');
			}
		}
	}
}

function set_default_category(idx,sel,url) {
	var requestURL = url+"&category="+idx+"&category_default="+sel.options[sel.selectedIndex].value;
	if(idx == 1)
		xmlRequest(requestURL,callbackDefaultCategorySet1);
	else if(idx == 2)
		xmlRequest(requestURL,callbackDefaultCategorySet2);
	else if(idx == 3)
		xmlRequest(requestURL,callbackDefaultCategorySet3);
}

function callbackDefaultCategorySet1() {
	var result = null;
	if(isResponseDone()) {
		result = getRSSResult();
		if(result != null) {
			noticeCategory('category1',result);
		}
	}
}

function callbackDefaultCategorySet2() {
	var result = null;
	if(isResponseDone()) {
		result = getRSSResult();
		if(result != null) {
			noticeCategory('category2',result);
		}
	}
}

function callbackDefaultCategorySet3() {
	var result = null;
	if(isResponseDone()) {
		result = getRSSResult();
		if(result != null) {
			noticeCategory('category3',result);
		}
	}
}

function noticeCategory(id,result) {
	var obj = document.getElementById(id);
	if(obj) {
		for(i=0; i<result.length; i++) {
			var itemObj = result[i];
			var s=0;
			if(itemObj.title == id) {
				for(j=0; j<obj.childNodes.length; j++) {
					var optionObj = obj.childNodes[j];
					if(optionObj.value == itemObj.link) {
						alert(itemObj.author+"ÀÇ ±âº»°ªÀÌ "+itemObj.description+"À¸·Î ¼¼ÆÃµÇ¾ú½À´Ï´Ù.");
						s=1;
						break;
					}
				}
			}
			if(s) break;
		}
	}
}

function resize_Content_form(id,board,opt) {
	var obj = document.getElementById(id);
	if(obj) {
		var height = parseInt(obj.style.height.replace("px",""));
		if(opt == 1) {
			height = height+100;
		} else {
			if(height > 100)
				height = height-100;
		}
		obj.style.height = height+'px';
		setCookie(board+"_content_textarea_width_size",height,1);
	}
}

function setCookie(name, value, expireDays) {
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate() + expireDays);
	document.cookie = name + "=" + value + "; path=/; expires=" + todayDate.toGMTString() + ";";
}

function add_sitelink_num(id,idx,name) {
	var obj = document.getElementById(id);
	if(obj) {
		var lis = obj.getElementsByTagName('li');
		var s_num = lis.length+1;
		var li = document.createElement('li');
		var s_string = name+s_num+": ÀÌ¸§ ";
		var s_name = "sitelink"+idx+"["+s_num+"][name]";
		var s_link = "sitelink"+idx+"["+s_num+"][link]";
		var txt1 = document.createTextNode(s_string);
		var txt2 = document.createTextNode(' URL ');
		li.appendChild(txt1);
		var inp = document.createElement('input');
		inp.setAttribute('type','text');
		inp.setAttribute('className','news_write_input');
		inp.setAttribute('class','news_write_input');
		inp.setAttribute('style','width:155px;');
		inp.style.width='155px';
		inp.setAttribute('name',s_name);
		li.appendChild(inp);
		li.appendChild(txt2);
		var inp = document.createElement('input');
		inp.setAttribute('type','text');
		inp.setAttribute('class','news_write_input');
		inp.setAttribute('className','news_write_input');
		inp.setAttribute('style','width:200px;');
		inp.style.width='200px';
		inp.setAttribute('name',s_link);
		li.appendChild(inp);
		obj.appendChild(li);
	}
}

function del_sitelink_num(id) {
	var obj = document.getElementById(id);
	if(obj) {
		var lis = obj.getElementsByTagName('li');
		if(lis.length == 2) {
			alert('2°³ ÀÌÇÏ·Î ÁÙÀÏ ¼ö ¾ø½À´Ï´Ù.');
			return;
		}
		var inp = lis[lis.length-1].getElementsByTagName('input');
		for(i=0; i<inp.length; i++) {
			if(inp[i].getAttribute("value") != "" && inp[i].value != "") {
				alert("ÀÔ·Â°ªÀÌ Á¸ÀçÇÏ´Â °æ¿ì¿¡´Â »èÁ¦ÇÒ ¼ö ¾ø½À´Ï´Ù.");
				return;
			}
		}
		obj.removeChild(lis[lis.length-1]);
	}
}

function iframe_autoresize(fr) {
	fr.height = eval(fr.name+".document.body.scrollHeight");
}

function image_preview(url) {
	window.open(url,'','width=100,height=100');
}

function ShowHideWrite2(photo,v1,box,v2,movie,v3) {
	var id1 = photo+"-title";
	var id2 = box+"-title";
	var id3 = movie+"-title";
	var t_obj, obj;
	if((t_obj = document.getElementById(id1)) && (obj = document.getElementById(photo))) {
		if(v1 == 'show') {
			t_obj.setAttribute("className","news_write2_title");
			t_obj.setAttribute("class","news_write2_title");
			obj.style.display = 'block';
			var height = document.getElementById('news-write2-wrap').scrollHeight;
			parent.document.getElementById('write2_frame').height = height;
		} else {
			t_obj.setAttribute("className","news_write2_title_hide");
			t_obj.setAttribute("class","news_write2_title_hide");
			obj.style.display = 'none';
		}
	}
	if((t_obj = document.getElementById(id2)) && (obj = document.getElementById(box))) {
		if(v2 == 'show') {
			t_obj.setAttribute("className","news_write2_title");
			t_obj.setAttribute("class","news_write2_title");
			obj.style.display = 'block';
			var height = document.getElementById('news-write2-wrap').scrollHeight;
			parent.document.getElementById('write2_frame').height = height;
		} else {
			t_obj.setAttribute("className","news_write2_title_hide");
			t_obj.setAttribute("class","news_write2_title_hide");
			obj.style.display = 'none';
		}
	}
	if((t_obj = document.getElementById(id3)) && (obj = document.getElementById(movie))) {
		if(v3 == 'show') {
			t_obj.setAttribute("className","news_write2_title");
			t_obj.setAttribute("class","news_write2_title");
			obj.style.display = 'block';
			var height = document.getElementById('news-write2-wrap').scrollHeight;
			parent.document.getElementById('write2_frame').height = height;
		} else {
			t_obj.setAttribute("className","news_write2_title_hide");
			t_obj.setAttribute("class","news_write2_title_hide");
			obj.style.display = 'none';
		}
	}
}

function autoReSizeWin() {
	var width = document.body.scrollWidth;
	var height = document.body.scrollHeight;

	window.saveNavigator = window.navigator;
	navigator.OS    = '';
	navigator.version  = '';

	var platform = "";
	if (typeof(window.navigator.platform) != 'undefined'){
		platform = window.navigator.platform.toLowerCase();
		if (platform.indexOf('win') != -1) navigator.OS = 'win';
	}

	var i = 0;
	var ua = window.navigator.userAgent.toLowerCase();

	if ((i = ua.indexOf('msie')) != -1){
		var a_w =	0;
		var a_h = 27;
	} else if((i = ua.indexOf('opera')) != -1) {
		var a_w =	0;
		var a_h = 67;
	} else {
		var a_w =	0;
		var a_h = 47;
	}

	window.resizeTo((width+a_w > screen.availWidth ? screen.availWidth : width+a_w), ((height+a_h) > screen.availHeight ? screen.availHeight : height+a_h));
	if(width+a_w < screen.availWidth && height+a_h < screen.availHeight) {
		document.getElementById('commune_body_wrap').style.overflow='hidden';
	}
}

function pop_open(URL) {
	window.saveNavigator = window.navigator;
	navigator.OS    = '';
	navigator.version  = '';

	var platform = "";
	if (typeof(window.navigator.platform) != 'undefined'){
		platform = window.navigator.platform.toLowerCase();
		if (platform.indexOf('win') != -1) navigator.OS = 'win';
	}
	
	var i = 0;
	var ua = window.navigator.userAgent.toLowerCase();

	if ((i = ua.indexOf('msie')) != -1){
		var a_w =	600;
	} else if((i = ua.indexOf('opera')) != -1) {
		var a_w =	600;
	} else {
		var a_w =	630;
	}

	window.open(URL,'_write_pop','width='+a_w+',height=500');
}

