function image_preview(url) {
	window.open(url,'','width=100,height=100,scrollbars=yes');
}
function copy_antidobae(s_id,t_id) {
	var obj = document.getElementById(s_id);
	var obj2 = document.getElementById(t_id);
	if(obj) {
		var str = obj.innerHTML;
		if(obj2) {
			obj2.setAttribute("value",str);
		}
	}
}

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','cinema-inp');
		inp.setAttribute('class','cinema-inp');
		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','cinema-inp');
		inp.setAttribute('className','cinema-inp');
		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 _findObj(n,d) {
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for(i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0; !x&&d.layers&&i<d.layers.length; i++) x=_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}

function resize_myframe() {
	var height = document.body.scrollHeight;
	var obj = _findObj('write2_frame',parent.document);
	if(obj.style) obj = obj.style;
	if(height) {
		obj.height = height;
	} else {
		obj.height = '450px';
	}
}

function content_image_auto_resize()
{
	var obj = document.getElementById('newscham_newsskin_chamtv_rtv_view');
	if(obj && _img_width) {
		var img = obj.getElementsByTagName('img');
		for(i=0; i<img.length; i++) {
			if(img[i].width > _img_width) {
				img[i].width = _img_width;
				var img_url = img[i].src;
				img[i].setAttribute("cursor","hand");
				img[i].style.cursor = 'hand';
				img[i].onclick = function () {
					image_preview('./view_image_pop?board='+_board_url+'&img_url='+img_url);
				}
			}
		}
		var tb = obj.getElementsByTagName('table');
		for(i=0; i<tb.length; i++) {
			if(tb[i].width > _img_width) {
				tb[i].width = _img_width;
			}
		}
	}
}

var _board_url;
var _img_width;

function addLoadEvent(board,width,func)
{
	_img_width = width;
	_board_url = board;
	var oldonLoad = window.onload;
	if(typeof(window.onload) != 'function') {
		window.onload = func;
	} else {
		window.onload = function () {
			if(oldonLoad) {
				oldonLoad();
			}
			func();
		}
	}
}

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 preview(URL,width) {
	window.open(URL,'','width='+width+',height=100,scrollbars=yes');
}

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

function resize_Content_form(id,board,opt,wh) {
	var obj = document.getElementById(id);
	if(obj) {
		if(wh) {
			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_height_size",height,1);
		} else {
			var width = parseInt(obj.style.width.replace("px",""));
			if(opt == 1) {
				width = width+100;
			} else {
				if(width > 100)
					width = width-100;
			}
			obj.style.width = width+'px';
			setCookie(board+"_content_textarea_width_size",width,1);
		}
	}
}
function reset_Content_form(id,board) {
	var obj = document.getElementById(id);
	if(obj) {
		obj.style.height = '200px';
		setCookie(board+"_content_textarea_height_size",'200',1);
		obj.style.width = '450px';
		setCookie(board+"_content_textarea_width_size",'450',1);
	}
}

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

function showHideDefaultInfo(id,vi)
{
	var v,obj
  if((obj=document.getElementById(id)) != null) {
		if(obj.style) {
			obj = obj.style;
			v = (vi=='show') ? '' : (vi=='hide') ? 'none' : vi;
		}
		obj.display = v;
	}
}

function clip_idx_copy(id) {
	var doc = document.body.createTextRange();
	var obj = document.getElementById(id);
	doc.moveToElementText(obj);
	doc.select();
	doc.execCommand('copy');
}

