// È­¸é°¡¿îµ¥ Ã¢¶ì¿ì±â
function opwc(name, url, width, height, toolbar, menubar, statusbar, scrollbar, resizable) {
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	opw(name, url, winl, wint, width, height, toolbar, menubar, statusbar, scrollbar, resizable);
}
// ÀÏ¹Ý Ã¢¶ì¿ì±â
function opw(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable) {
    toolbar_str = toolbar ? 'yes' : 'no';
    menubar_str = menubar ? 'yes' : 'no';
    statusbar_str = statusbar ? 'yes' : 'no';
    scrollbar_str = scrollbar ? 'yes' : 'no';
    resizable_str = resizable ? 'yes' : 'no';
    window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

// ·¹ÀÌ¾î ¼û±èº¸ÀÓ
function show(iobject){
	iobject.style.visibility="visible";
}
function hide(iobject){
	iobject.style.visibility="hidden";
}

//
function previews(a, b) {
	var xx = eval(a);
	if(b == 1) {
		xx.style.left = event.clientX + 16;
		xx.style.top = event.clientY;
		xx.style.visibility = 'visible';
	} else {
		xx.style.visibility = 'hidden';
	}
}

// ÀÌ¹ÌÁö ¹Ì¸®º¸±â
function preview_img(frm, pre) {
	if(frm) {
		pre.src = frm;
	}
}

// textArea¿¡ ¿øÇÏ´Â °ª ³Ö±â
function saveCurrentPos(objTextArea) {
	if(objTextArea.createTextRange) objTextArea.currentPos = document.selection.createRange().duplicate();
}

function insertText(objTextArea, text) {
	if(objTextArea.createTextRange && objTextArea.currentPos) {
		var currentPos = objTextArea.currentPos;
		currentPos.text = currentPos.text.charAt(currentPos.text.length - 1) == ' ' ? text + ' ' : text;
   } else {
         objTextArea.value  = text;
   }
}

function imgView(src, name) {
	ti = new Image();
	ti.src = src;

	s = "";
	s += "<html><head><title>" + name + "</title>\n";
	s += "<sc"+"ript>\n";
	s += "function resize() {\n";
	s += "	pic = document.myimg;\n";
	s += "	if(eval(pic).height) {\n";
	s += "		var name = navigator.appName\n";
	s += "		if (name == 'Microsoft Internet Explorer') {\n";

	if(ti.width > screen.width || ti.height > screen.height) {
		var imgwin = window.open("",'name','scrollbars=yes,status=no,toolbar=no,resizable=1,location=no,menu=no,top=5000,left=5000,width=1,height=1');
		s += "			myHeight = screen.availHeight - 50; myWidth = screen.availWidth - 50;\n";
		s += "		} else {\n";
		s += "			myHeight = screen.availHeight - 50; myWidth = screen.availWidth - 50;\n";
	} else {
		var imgwin = window.open("",'name','scrollbars=no,status=no,toolbar=no,resizable=1,location=no,menu=no,top=5000,left=5000,width=1,height=1');
		s += "			myHeight = eval(pic).height + 30; myWidth = eval(pic).width + 12;\n";
		s += "		} else {\n";
		s += "			myWidth = eval(pic).height + 9; myWidth = eval(pic).width;\n";
	}
	imgwin.focus();
	imgwin.document.open();

	s += "		}\n";
	s += "		clearTimeout();\n";
	s += "		var height = screen.height;\n";
	s += "		var width = screen.width;\n";
	s += "		var leftpos = width / 2 - myWidth / 2;\n";
	s += "		var toppos = height / 2 - myHeight / 2; \n";
	s += "		self.moveTo(leftpos, toppos);\n";
	s += "		self.resizeTo(myWidth, myHeight);\n";
	s += "	} else {\n";
	s += "		setTimeOut(resize(), 100);\n";
	s += "	}\n";
	s += "}\n";
	s += "</sc"+"ript>\n";
	s += "</head>\n";

	s += "<body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0 oncontextmenu='return false' ondragstart='return false' onselectstart='return false'>\n";

	s += "<img border=0 src='" + src + "' alt='Å¬¸¯ ´Ý±â' name=myimg onclick='self.close();' onload='resize();'>\n";
	s += "</body></html>\n";

	imgwin.document.write(s);
	imgwin.document.close();
}

// ÄíÅ° »ý¼º
function setCookie(name, value, expiredays) {
  var todayDate = new Date();
  todayDate.setDate( todayDate.getDate() + expiredays );
  document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

// Äí±â °ª ¹Þ±â
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if(endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

// ÄíÅ° Ã£±â
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

// delete the cookie
function deleteCookie(name,path,domain)
{
	if (getCookie(name))
	{
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// Å¬¸³º¸µå º¹»ç
function InnerClip(s){
	var copiedtext = "";
	var tempstore = "";
	tempstore = copiedtext;
	var doc = document.body.createTextRange();
	doc.moveToElementText(document.all(s));
	doc.execCommand('copy');
	copiedtext = window.clipboardData.getData("Text");
	//doc.select(); // ÁöÁ¤µÈ ºÎºÐ ¼±ÅÃ Ç¥½Ã ÇØÁÖ´Â °÷ 
	//alert('¼±ÅÃÇÏ½Å ³»¿ëÀÌ Å¬¸³º¸µå¿¡ º¹»çµÇ¾ú½À´Ï´Ù.' + copiedtext);
}

// textarea ÅÇ »ç¿ë : ¸Á´Ï´ÏÁa¾î
function IsTab(el) {
	if((document.all) && (9 == event.keyCode)) {
		el.selection = document.selection.createRange(); 
		document.all[el.name].selection.text = String.fromCharCode(9)
		document.all[el.name].focus();
		return false;
	}
}

// PAD
function lpad(stra, sa, va) {
	stra = String(stra);
	if(stra.length >= sa) return stra;
	for(abc = 1;abc < sa;abc++) {
		stra = va + stra;
	}
	return stra;
}

//tabs-menu
function tabs(obj,on,mnum,link) {
	_obj = document.getElementById(obj);
	imgobj = event.srcElement;
	/(.*)\/(.*)/.test(imgobj.src);
	_imgname = RegExp.$2;
	_imgname = _imgname.replace('.gif','');
	_imgname = _imgname.replace('_ob','');
	_imgname = _imgname.substring(0,_imgname.length-1);
	var sh = new RegExp(_imgname + "[1-"+mnum+"]");
	for (var i=0;i<_obj.childNodes.length;i++)
	{
		_obj.childNodes[i].className = "taboff";
	}

	for (i=0;i<document.images.length;i++)
	{		
		if (sh.test(document.images[i].src))
		{
			document.images[i].src = document.images[i].src.replace('_ob.gif','.gif');
		}
	}
	_obj.childNodes[on].className = "tabon";
	event.srcElement.src = '/images/' + _imgname + (on+1) + '_ob.gif';
	if (link!='')
	{
		document.getElementById(obj+'_link').href = link;
	}
}


function pop_event(pop,win_name,width,height,left,top,scr)
{
	var url = pop;
	var wd = width;
	var he = height;
	var le = left;
	var tp = top;
	var	scr_b = scr;

		//var Cookie=getCookie("shop");
		var eventCookie=getCookie(win_name);
		if (eventCookie != "no")
	{
	win = window.open(url,win_name,"toolbar=0,menubar=0,scrollbars="+ scr_b +",resizable=no,width=" + wd +",height=" + he + ",left=" + le + ",top=" + tp + ";");
	win.focus();
	}
	//ÆË¾÷Ã¢ÀÇ ÁÖ¼Ò, °°Àº µµ¸ÞÀÎ¿¡ ÀÖ¾î¾ß ÇÑ´Ù.
}

function facebookOpen() {
	var d = new Date();
	var gt = d.getTime();
	var title = document.getElementById("ntitle").innerHTML;
	var summary = document.getElementById("summary").innerHTML;
	var titl = title;
	var img = encodeURIComponent("http://www.chmbc.co.kr/life/eventimg/eventimg_basic.jpg");
	titl = titl.replace(/'/gi,"¢¥");
	titl = titl.replace(/"/gi,"¢©");
	titl = encodeURIComponent(titl);
	titl = titl.replace("%26lt%3B","<");
	titl = titl.replace("%26gt%3B",">");
	summary = encodeURIComponent(summary);
	//var link = encodeURIComponent(_getArticleLink() + "&outlink=facebook&tm=" + gt); 
	//var url = "http://www.facebook.com/sharer.php?u=" + link + "&t=" + titl;
	var url = "http://www.facebook.com/sharer.php?s=100&p[url]=" + encodeURIComponent(_getArticleLink()) + "&p[images][0]=" + img + "&p[title]=" + titl + "&p[summary]=" + summary;
	windowOpen (url, 500, 300, 'no');
}
//twitter
function twitterOpen() {
	//var titl = encodeURIComponent(_getArticleTitle());
	var title = document.getElementById("ntitle").innerHTML;
	var titl = title;
	titl = titl.replace(/'/gi,"¢¥");
	titl = titl.replace(/"/gi,"¢©");
	titl = encodeURIComponent(titl);
	var alink = _getArticleLink();
	if (/(\?)/.test(alink)==false){
		alink = alink + "?";
	}

	var link = encodeURIComponent(alink + "&outlink=twitter"); // + "?outlink=twitter"
	var url = "http://twitter.com/home?status=" + titl + "+" + link;
	windowOpen (url, 800, 400, 'yes');
}

//¹ÌÅõµ¥ÀÌ
function me2dayOpen() {
	var title = document.getElementById("ntitle").innerHTML;
	var titl = encodeURIComponent(title);
	var alink = _getArticleLink();
	if (/(\?)/.test(alink)==false){
		alink = alink + "?";
	}
	var link = encodeURIComponent(alink + "&outlink=me2day"); 
	var url = "http://me2day.net/posts/new?new_post[body]=\"" + titl + "\"" + " : " + link;
	windowOpen (url, 1000, 600, 'no');
}
//¿äÁò
function yozmOpen() {
	var titl = document.getElementById("ntitle").innerHTML;
	titl = titl.replace (/'/gi,"¢¥");
	titl = titl.replace (/"/gi,"¢©");
	titl = encodeURIComponent(titl);
	var alink = _getArticleLink();
	if (/(\?)/.test(alink)==false){
		alink = alink + "?";
	}

	var link = encodeURIComponent( alink + "&outlink=yozm"); 
	var url = "http://yozm.daum.net/api/popup/prePost?prefix=" + titl + "&link=" + link;
	windowOpen (url, 400, 364, 'no');
}




function _getArticleLink() {
	var link = location.protocol + "//" + location.hostname + "" + (location.port!="" ? ":"+location.port : "") + location.pathname;
	if (getQuerystring('seq_num')!=""){
		link+="?seq_num=" + getQuerystring('seq_num') + "&air="+getQuerystring('air');
	}else {
		link = document.URL;
	}

	return link;
}

function windowOpen () {
	var nUrl; var nWidth; var nHeight; var nLeft; var nTop; var nScroll;
	nUrl = arguments[0];
	nWidth = arguments[1];
	nHeight = arguments[2];
	nScroll = (arguments.length > 3 ? arguments[3] : "no");
	nLeft = (arguments.length > 4 ? arguments[4] : (screen.width/2 - nWidth/2));
	nTop = (arguments.length > 5 ? arguments[5] : (screen.height/2 - nHeight/2));
	
	winopen=window.open(nUrl, 'pbml_win', "left="+nLeft+",top="+nTop+",width="+nWidth+",height="+nHeight+",scrollbars="+nScroll+",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes");
}

function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null) return default_;
  else return qs[1];
}

