
/**
 * common.js
 *
 * Àü ÆäÀÌÁö °øÅë ½ºÅ©¸³Æ®
 *
 * @author  ÄÁÅÙÃ÷°³¹ßÆÀ ±èÁÖÈ« (joohong98-at-skcomms.co.kr)
 * @date    2008-01-28
 */

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

var IE = (navigator.userAgent.indexOf('MSIE') != -1) ? true : false;		// IE Check
var IE6 = (navigator.userAgent.indexOf('MSIE 6.0') != -1) ? true : false;		// IE Check
var IE7 = (navigator.userAgent.indexOf('MSIE 7.0') != -1) ? true : false;	// IE7 Check
var IE8 = (navigator.userAgent.indexOf('MSIE 8.0') != -1) ? true : false;	// IE8 Check
var FF = (navigator.userAgent.indexOf('Firefox') != -1) ? true : false;	// FF Check

 /**
  * ¿µ¿ª³» ¸µÅ©ÀÇ Å¸°ÙÀ» ¸ðµÎ º¯°æ
  * @param this_s	¿µ¿ª
  * @param target	target
  * @param type		true: targetÀÌ ÀÖ¾îµµ °­Á¦·Î ¹Ù²Û´Ù. false: ¾øÀ» °æ¿ì¸¸ ¹Ù²Û´Ù 
  */
function link_auto_target_inarea(this_s,target,type){ 
	//this_s¾ÈÀÇ a¸¦ Ã¼Å©ÇØ¼­ Å¸°ÙÀ» ¹Ù²Û´Ù. 
	//type°¡ trueÀÌ¸é targetÀÌ ÀÖ¾îµµ °­Á¦·Î ¹Ù²Û´Ù. false¸é ¾øÀ» °æ¿ì¸¸ ¹Ù²Û´Ù 
	//alert(this_s.childNodes.length);
	if (!target) {target='_blank';}
	if (!type) {type=false;}
	if (!this_s){return;}
	if (this_s.nodeType!=1){return;}
	//alert(this_s.nodeName);
	for (var i=0,m=this_s.childNodes.length;i<m;i++) {
		var ta = this_s.childNodes[i];
		if (ta.nodeName=='A') {
			if (ta.href){
				if (ta.href.toLowerCase().indexOf('javascript')==0) {
					continue;
				} else if ((!ta.target || type) ) {
					ta.target = target;
				}
			}
		}
		if (ta.childNodes.length>0) {
			link_auto_target_inarea(ta,target,type);
		}
	}
	return;
}

/**
 * ·Î±×ÀÎ Ã³¸® - return url
 * @param returnUrl ¸®ÅÏ URL
 */
function CmdLogin(returnUrl) {
	if (confirm("º» ¼­ºñ½º´Â ·Î±×ÀÎÀ» ÇØ¾ß ÀÌ¿ëÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.\n\n·Î±×ÀÎ ÇÏ½Ã°Ú½À´Ï±î ?")) {
		returnUrl = 'http://movie.nate.com?url='+returnUrl;
		top.document.location.href = "http://xo.nate.com/login.jsp?redirect=" +returnUrl;
	} else return;
}

/**
 * ¿£ÅÍÃ¼Å©
 * @obj °´Ã¼
 */
function EnterCheck(obj, act) {
	if (event.keyCode == 13) {
		event.returnValue = false;
		eval(act);
	} else
		return;
}

/**
 * Å¬¸³º¸µå·Î º¹»ç
 * @param {Object} url
 */
function CopyClipBoard(url) {
	if (IE) {
		window.clipboardData.setData("Text", url);
		alert("º¹»çµÇ¾ú½À´Ï´Ù.\n\nÇÊ¿äÇÑ °÷¿¡ ºÙ¿©³Ö±â(Ctrl+V) ÇÏ¼¼¿ä.");
	} else {
		prompt("ÀÌ ±ÛÀÇ ÁÖ¼ÒÀÔ´Ï´Ù. Ctrl+C¸¦ ´­·¯ º¹»çÇÏ¼¼¿ä", url);
	}
}

/**
 * ºÎ¸ðÃ¢¿¡¼­ ÀÌµ¿
 * @param {Object} url
 */
function ParentMove(url) {
	if (typeof(parent.MovePage) == 'function') {
		parent.location.href = url;
	} else {
		document.location.href = url;
	}
}
/**
 * ·Î±×ÀÎ °ü·Ã ÀÌµ¿
 * @param {Object} url
 * @param {Object} es
 */
function LoginMove(url, es) {
	if (typeof(parent.MovePage) == 'function') {
		parent.MovePage(url, es);
	} else {
		if (es == '')
			es = 'http://movie.nate.com/main';
		var sLoginUrl = 'http://movie.nate.com/?url='+encodeURIComponent(es);
		document.location.href = url+'?es='+sLoginUrl;
	}
}

/**
 * ½½¶óÀÌµå ·¹ÀÌ¾î IFRAME º¯°æ
 * @param {Object} pos ÁÂ/¿ì (left/right)
 * @param {Object} url URL
 */
function changeSlideFrame(pos, url) {
	document.getElementById('slide_'+pos+'_content').src = url;
}
/**
 * ¿¹¸Å¹Ù±¸´Ï ¿­±â
 */
function showHelpBasket() {
	document.getElementById('reserveBasketLayer').style.display = 'block';
}
/**
 * ¿¹¸Å¹Ù±¸´Ï ´Ý±â
 */
function closeHelpBasket() {
	document.getElementById('reserveBasketLayer').style.display = 'none';
}
/**
 * ÇöÀç ÆäÀÌÁö ¼³Á¤
 * @param {Object} url
 */
function setCurrentPage(url) {
	this.currentPage = url;
}
/** 
 * ¸ÞÀÎ ÄÁÅÙÃ÷ ¸®·Îµå
 */
function reloadMain() {
	document.getElementById('mainContent').src = 'http://movie.nate.com/move?url='+this.currentPage;
}

/** 
 * ¸ÞÀÎ ÄÁÅÙÃ÷ ÀÌµ¿
 * @param {Object} url URL
 */
function moveMain(url) {
	document.location.href = url;
}
/**
 * ¿À´Ãº» ¿µÈ­ Ä«¿îÆ® ¼³Á¤
 * @param {Object} today ³¯Â¥
 */
function setTodayMovieCount(today) {
	if (typeof(parent.MovePage) == 'function') {
		parent.reloadTodayMovie(today);
	}
}
function calcHeight(iframe_id){
	try {
		var objIframeBody = document.getElementById(iframe_id);
		var innerBody = objIframeBody.contentWindow.document.body;

		var the_height = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);
		if(FF) the_height += 2;
		document.getElementById(iframe_id).height = the_height + 'px';

		if (typeof(parent.MovePage) == 'function') {
			parent.resizeCurrentFrame(null);
		}
	} catch(e) {
	}
}
/**
 * iframe resize
 * @param {Object} iframelist
 */
function resizeMainFrame(iframelist) {
	/* ³ôÀÌ¿¡ ¿µÇâÀ» ¹ÌÄ¡´Â iframe ¹è¿­Å©±â °è»ê */
	var listsize = 0;
	if (iframelist) {
		try {
			for (var i = 0; i < iframelist.length ; i++) {
				var objIframe = document.getElementById(iframelist[i]);
				listsize += objIframe.contentWindow.document.body.scrollHeight;
			}
		} catch (e) {}
	}

	// ÇÁ·¹ÀÓ ¸®»çÀÌÁî
	var objIframeBody = document.getElementById("mainContent");
	var innerBody = objIframeBody.contentWindow.document.body;
	var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight) + listsize;
	objIframeBody.style.height = innerHeight + 'px';

	if (IE7) document.documentElement.scrollTop = 0;
	if (IE) document.body.scrollTop = 0;
	else document.documentElement.scrollTop = 0;

	// ie6¿ë ·¹ÀÌ¾î À§Ä¡ ¼³Á¤
	window.setTimeout('SetLayer()', 100);
}
/**
 * ÇöÀç Ã¢ iframe resize ½ºÅ©·Ñ °íÁ¤
 * @param {Object} iframelist
 */
function resizeCurrentFrame(iframelist) {
	// ÇÁ·¹ÀÓ ¸®»çÀÌÁî
	var objIframeBody = document.getElementById("mainContent");
	var innerBody = objIframeBody.contentWindow.document.body;
	var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);

	objIframeBody.style.height = innerHeight + 'px';
}
/**
 * TAB Switch
 * @param {Object} dest		º¯°æÅÇ
 * @param {Object} source	ÇöÀçÅÇ
 */
function CmdSwitchTab(dest, source) {
	document.getElementById(dest).style.display = '';
	document.getElementById(source).style.display = 'none';
}

/**
 * FlashWrite
 * 
 * @param {Object} source     ÇÃ·¡½¬ ÆÄÀÏÀÇ °æ·Î
 * @param {Object} id         ÇÃ·¡½¬ id 
 * @param {Object} width      °¡·ÎÅ©±â
 * @param {Object} height     ¼¼·ÎÅ©±â
 * @param {Object} addParam   embed Ãß°¡ ÀÎÀÚ
 * @param {Object} otherparam Ãß°¡ ÀÎÀÚ "<param name='myParam' value='myValue' />
 */
function FlashWrite(source,id,width,height,addParam,otherParam) {
	DocumentWrite( "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,12,36\" width="+width+" height="+height+" id="+id+"><param name=movie value="+source+" /><param name='wmode' value='transparent'><param name=quality value=high />"+otherParam+"<embed src="+source+" quality=high "+addParam+" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash\" width="+width+" height="+height+" wmode=\"transparent\"></embed></object>" );
}

function FlashWriteText(source,id,width,height,addParam,otherParam) {
	return "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,12,36\" width="+width+" height="+height+" id="+id+"><param name=movie value="+source+" /><param name='wmode' value='transparent'><param name=quality value=high />"+otherParam+"<embed src="+source+" quality=high "+addParam+" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash\" width="+width+" height="+height+" wmode=\"transparent\"></embed></object>" ;
}

function ObjectWrite(classid,codebase,name,id,width,height,param) {
	DocumentWrite( "<object classid="+classid+" codebase="+codebase+" name="+name+" width="+width+" height="+height+" id="+id+">"+param+"</object>" );
}

function MovieWrite(classid,codebase,filename,id,width,height,param,type) {
	DocumentWrite( "<object classid="+classid+" codebase="+codebase+" id="+id+" width="+width+" height="+height+" standby='loading microsoft windows media player components...' type="+type+" >"+param+"<param name=filename value="+filename+"></object>" );
}

function DocumentWrite(refObjectString) {
	document.write(refObjectString);
}

/**
 * ÀÌ¹ÌÁö ¸®»çÀÌÂ¡ 
 * resetImageSize
 * 
 * @param {Object} _id			ÀÌ¹ÌÁö¸¦ °¨½Î°í ÀÖ´Â id °ª 
 * @param {Object} _maxSize		¿øÇÏ´Â ¸Æ½º »çÀÌÁî 
 */
function resetImageSize(_id, _maxSize) {
	try {
		if (_id==null) _id = "imageResizeArea";
		if (_maxSize==null) _maxSize = 508;
		var area = $(_id);
		var imgs = area.getElementsByTagName("IMG");
		var maxWidth = _maxSize;

		for (var i=0; i<imgs.length; i++) {
			if (parseInt(imgs[i].offsetWidth)>maxWidth) {
				imgs[i].style.width = maxWidth + "px";
			}
		}
	} catch(e) {}
}



/****** ÆË¾÷Ã¢ ¸®»çÀÌÁî **************************************************************/
function uf_popResize() {
	
	// FireFoxÀÏ °æ¿ì
	if (FF) {
		popFF();
	}
	
	// IE 6, 7, 8 ÀÏ °æ¿ì
	if (IE6 ||IE7 || IE8) {
		popIE();
	}
}

function popFF() {
	var thisX = document.body.offsetWidth;
	var thisY = document.body.offsetHeight;

	var maxThisX = screen.width - 50;
	var maxThisY = screen.height - 80;
	
	// Å¬¶óÀÌ¾ðÆ® width, height¸¦ Á¦¿ÜÇÑ FrameÀÇ °ªÀ» Ãß°¡ÇØÁà¾ß Á¦´ë·Î Ç¥ÇöµÊ.
	var marginY = 230;
	var marginX = 10;
	
	if( thisY > maxThisY - marginY ) {
		window.scrollbars.visible = true;
		
		thisX += 16;
		thisY = maxThisY - marginY;
	} else {
		window.scrollbars.visible = false;
	}
	
	window.resizeTo( thisX+marginX, thisY+marginY );
}

function popIE() {
	var thisX = document.body.offsetWidth;
	var thisY = document.body.offsetHeight;

	var maxThisX = screen.width - 50;
	var maxThisY = screen.height - 80;
	
	var xScroll = 16;

	if ( IE6 ) { // 6.0
		var marginY = 78; //
		var marginX = 10;
	} else if (IE7 ) {	// 7.0
		var marginY = 98;	//
		var marginX = 10;
	} else if (IE8 ) {	// 8.0
		var marginY = 138;
		var marginX = 10;
	}	else {
		var marginY = 98;	//
		var marginX = 10;
	}

	if( thisY > maxThisY - marginY ) {
		window.document.body.scroll = "yes";
		thisX += xScroll;
		thisY = maxThisY - marginY;
		isScroll = true;
	} else {
		window.document.body.scroll = "no";
	}

	window.resizeTo( thisX+marginX, thisY+marginY );
}

/****** ÆË¾÷Ã¢ ¸®»çÀÌÁî **************************************************************/
/*
* È­Æó´ÜÀ§ Ã³¸®
*/
function number_fomat(v) {
	v = v.toString();
	if (v.length > 3) {
		var mod = v.length % 3;
		var retval = (mod > 0 ? (v.substring(0,mod)) : "");
		for (i=0 ; i < Math.floor(v.length / 3); i++) {
			if ((mod == 0) && (i == 0)) {
				retval += v.substring(mod+ 3 * i, mod + 3 * i + 3);
			} else {
				retval+= "," + v.substring(mod + 3 * i, mod + 3 * i + 3);
			}
		}
		return retval;
	} else {
		return v;
	}
}

/*
* ´ñ±Û, Æ®·¢¹é, ³ªµµÇÑ¸¶µð µî·Ï½Ã Ä«¿îÆ®¼ýÀÚ¸¦ Àç¼³Á¤
*/
function refreshCount(kind, cnt){
	if (kind=='replyboard') {
		$('iframe_reply_cnt01').innerHTML = number_fomat(cnt);
		$('iframe_reply_cnt02').innerHTML = number_fomat(cnt);
	} else if(kind=='trackback') {
		$('iframe_trackback_cnt01').innerHTML = number_fomat(cnt);
		$('iframe_trackback_cnt02').innerHTML = number_fomat(cnt);
	} else {
		$(kind).innerHTML = number_fomat(cnt);
	}
}

/*
* ¿µ¹®/ÇÑ±Û ±ÛÀÚ¼ö Ã¼Å©
*/
function byteCheck(code){
	var code_byte = 0;
	for (var inx = 0; inx < code.value.length; inx++) {
		var oneChar = escape(code.value.charAt(inx));
		if ( oneChar.length == 1 ) {
			code_byte ++;
		} else if (oneChar.indexOf("%u") != -1) {
			code_byte += 2;
		} else if (oneChar.indexOf("%") != -1) {
			code_byte += oneChar.length/3;
		}
	}
	return code_byte;
}

/**
 * png Åõ¸íÈ­
 * @param {Object} obj
 */
function setPng24(obj) {
	try {
		obj.width = obj.height = 1;
		obj.className = obj.className.replace(/\bpng24\b/i, '');
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.src + "',sizingMethod='image');";
		obj.src = '';
		return '';
	} catch (e) {}
}

/**
 * ÇÑ±Û/¿µ¹®/Æ¯¼ö¹®ÀÚ ÀÔ·ÂÁ¦ÇÑµÎ±â 
 * @param formName form ÀÌ¸§
 * @param contents ÇØ´ç ÀÔ·Â ±Û 
 * @param strLen Á¦ÇÑ ±ÛÀÚ 
 »ç¿ë¹ý : OnKeyUp="textAreaLenCheck('formName', 'contents', 100)"
 */
function textAreaLenCheck(formName, elmName, strLen) {
	var msgtext, taObj
	taObj = eval('document.'+ formName +'.'+elmName)
	msgtext = taObj.value;

	var i=0,l=0;
	var temp,lastl;

	while(i < msgtext.length)
	{
		temp = msgtext.charAt(i);
		if (escape(temp).length > 4) {
			l+=2;
		} else {
			var b = parseInt(escape(temp).charCodeAt(0));
			if (((b >= 65377)&&(b <= 65500))||((b >= 65512)&&(b <= 65518))) // ¹Ý°¢¹®ÀÚ À¯´ÏÄÚµå 10Áø¼ö ¹üÀ§ : ÇÑ±¹¾î, ÀÏº»¾î, Æ¯¼ö¹®ÀÚ
				l++; // + 1byte
			else // Àü°¢¹®ÀÚ : À§ Á¶°ÇÀ» Á¦¿ÜÇÑ ¸ðµç ¹®ÀÚ
				l+= 2; // + 2byte
		}

		if(l>strLen){
			alert(parseInt(strLen/2) +'ÀÚ ±îÁö ÀÔ·Â°¡´ÉÇÕ´Ï´Ù.');
			temp = taObj.value.substr(0,i);
			taObj.value = temp;
			taObj.focus();
			l = lastl;
			break;
		}
		lastl = l;
		i++;
	}
}

/**
 * ÇÑ±Û/¿µ¹®/Æ¯¼ö¹®ÀÚ ÀÔ·ÂÁ¦ÇÑµÎ±â 
 * @param formName form ÀÌ¸§
 * @param contents ÇØ´ç ÀÔ·Â ±Û 
 * @param strLen Á¦ÇÑ ±ÛÀÚ 
 »ç¿ë¹ý : OnKeyUp="textAreaLenCheck('formName', 'contents', 100)"
 */
function returnTextAreaLenCheck(formName, elmName, strLen) {
	var msgtext, taObj
	taObj = eval('document.'+ formName +'.'+elmName)
	msgtext = taObj.value;

	var i=0,l=0;
	var temp,lastl;
	var bReturn = 0;

	while(i < msgtext.length)
	{
		temp = msgtext.charAt(i);
		if (escape(temp).length > 4) {
			l+=2;
		} else {
			var b = parseInt(escape(temp).charCodeAt(0));
			if (((b >= 65377)&&(b <= 65500))||((b >= 65512)&&(b <= 65518))) // ¹Ý°¢¹®ÀÚ À¯´ÏÄÚµå 10Áø¼ö ¹üÀ§ : ÇÑ±¹¾î, ÀÏº»¾î, Æ¯¼ö¹®ÀÚ
				l++; // + 1byte
			else // Àü°¢¹®ÀÚ : À§ Á¶°ÇÀ» Á¦¿ÜÇÑ ¸ðµç ¹®ÀÚ
				l+= 2; // + 2byte
		}

		if(l>strLen){
			bReturn = 1;
			alert(parseInt(strLen/2) +'ÀÚ ±îÁö ÀÔ·Â°¡´ÉÇÕ´Ï´Ù.');
			temp = taObj.value.substr(0,i);
			taObj.value = temp;
			taObj.focus();
			l = lastl;
			break;
		}
		lastl = l;
		i++;
	}
	return bReturn;
}

// ¿¹¸Å¼­¹ö ÀÌÀü alert °øÁö
function alert_notice() {
	var notice_date = '6¿ù 1ÀÏ(00:00) ~ 6¿ù 2ÀÏ(00:00)';
	alert('ÁË¼ÛÇÕ´Ï´Ù. ¾¾Áñ¿¹¸Å Á¡°ËÀÛ¾÷À¸·Î \n¿¹¸Å¼­ºñ½º ÀÌ¿ëÀÌ ºÒ°¡´ÉÇÕ´Ï´Ù.\n\n*½Ã°£: '+notice_date);
}

/**
 * ¹Ì´ÏÈ¨ÇÇ open - °øÅë ¸ðµâ »ç¿ë Àü ÀÓ½Ã »ç¿ë
 */
function openMinihompy(tid, cy_tid, user_sn, _width, _height) {
	var popupUrl = '';
	popupUrl = "http://minihp.cyworld.com/pims/main/pims_main.asp?tid=" + tid;  //ÀÓ½Ã 

	if ( cy_tid != '' && user_sn !='') {
		popupUrl = "https://xo.nate.com/cysso/cysso.jsp?from=na&r_url=" + popupUrl;
	}

	if(_width == '' || _width == null) _width = 932;
	if(_height == '' || _height == null) _height = 538;

	var popMinihompy = window.open(popupUrl, 'person_info', "height="+_height+",width="+_width+",scrollbars=no,resizable=yes");
	popMinihompy.focus();
}

/**
 * ³×ÀÌÆ®/½ÎÀÌ sso ¿¬µ¿ interface (¹Ì´ÏÈ¨ÇÇ¿ë)
 */
function goSSOInterface(returnUrl, _width, _height) {
	if(_width == '' || _width == null) _width = 932;
	if(_height == '' || _height == null) _height = 538;

	//var popSSO = window.open("https://xo.nate.com/cysso/cysso.jsp?from=na&r_url="+returnUrl,"popSSO","height="+_height+",width="+_width+",scrollbars=no,resizable=no");
	var popSSO = window.open("https://xo.nate.com/cysso/cysso.jsp?from=na&r_url="+returnUrl,"popSSO","height="+_height+",width="+_width+",scrollbars=no,resizable=no");
	popSSO.focus();	
}

/**
 * °ü½É¿µÈ­ / ÀÎ¹° ¼³Á¤
 * 
 * @param contents_id ¿µÈ­/ÀÎ¹° Å°
 * @param view_content ¿µÈ­/ÀÎ¹° ±¸ºÐ
 */
function CmdSetInterest(contents_id, view_content) {
	var _width = 350;
	var _height = 360;
	var popupUrl = '/mymovie/alimi/set_interest?contents_id='+contents_id+'&view_content='+view_content;
	var popInterest = window.open(popupUrl, 'pop_interest', "height="+_height+",width="+_width+",scrollbars=no,resizable=yes");
	popInterest.focus();
}
/**
 * ³×ÀÌÆ®¿Â ¾Ë¸®¹Ì ¼³Á¤
 */
function openSetPopupNATE() {
	var service_id = 51;	// ¿µÈ­ service_id
	window.open("http://nateonalarm.nate.com/interface/check_connect.php?service_id="+service_id,
"NateonAlarm","toolbar=no,status=no,menubar=no, scrollbars=no,resizable=no,width=430,height=480");
}

/**
 * ºÎºÐ print ÇÏ±â 
 */
var initBody;
function BeforePrint() {
	initBody = '';
	initBody = document.body.innerHTML;
	document.body.innerHTML = $('print_page').innerHTML;
}

function AfterPrint() {
	document.body.innerHTML = initBody;
	initBody = '';
}

function ReportPrint() {
	window.onbeforeprint = BeforePrint;
	window.onafterprint = AfterPrint;
	window.print();
}
