
// Browse Type
// IE Script
var global_dragging=false;
var global_debugmode=false;
var Browser=new browserCheck();
function browserCheck(){
	var agt=navigator.userAgent.toLowerCase();
	var is_major=parseInt(navigator.appVersion);
	var is_minor=parseFloat(navigator.appVersion);
	var is_ie=((agt.indexOf("msie")!=-1)&&(agt.indexOf("opera")==-1));
	var is_ie3=(is_ie&&(is_major<4));
	var is_ie4=(is_ie&&(is_major==4)&&(agt.indexOf("msie 4")!=-1));
	var is_ie4up=(is_ie&&(is_major>=4));
	var is_ie5=(is_ie&&(is_major==4)&&(agt.indexOf("msie 5.0")!=-1));
	var is_ie5_5=(is_ie&&(is_major==4)&&(agt.indexOf("msie 5.5")!=-1));
	var is_ie5up=(is_ie&&!is_ie3&&!is_ie4);
	var is_ie5_5up=(is_ie&&!is_ie3&&!is_ie4&&!is_ie5);
	var is_ie6=(is_ie&&(is_major==4)&&(agt.indexOf("msie 6.")!=-1));
	var is_ie6up=(is_ie&&!is_ie3&&!is_ie4&&!is_ie5&&!is_ie5_5);
	var is_xp=((agt.indexOf("windows")!=-1)&&(agt.indexOf("5.1")!=-1));
	var is_xp_sp2=(is_xp&&(agt.indexOf("sv1")!=-1));
	this.is_ie=is_ie;
	this.is_ie5up=is_ie5up;
	this.is_ue5_5up=is_ie5_5up;
	this.is_ie6up=is_ie6up;
	this.is_xp=is_xp;
	this.is_xp_sp2=is_xp_sp2;
}
var NS4;
var IE4;
if (document.all)
{
		IE4 = true;
		NS4 = false;
}
else
{
		IE4 = false;
		NS4 = true;
}
isWin = (navigator.appVersion.indexOf("Win") != -1)

/* ÆË¾÷ °ü·Ã ÇÔ¼ö */
function open_window(url, name, width, height, feature)
{
		var oWnd;

		if (IE4 && width < window.screen.width && height < window.screen.height) 
		{
				var windowX = Math.ceil( (window.screen.width	- width) / 2 );
				var windowY = Math.ceil( (window.screen.height - height) / 2 );

				oWnd = window.open(url, name, feature+",width=" + width +",height=" + height+",left="+windowX+",top="+windowY + ",resizable=no");
		}
		else 
		{
				oWnd = window.open(url, name, feature+",width=" + width +",height=" + height + ",resizable=no");
		}

		return oWnd;
}

function open_wnd(url, name, width, height)
{
		var oWnd = open_window(url, name, width, height, "toolbar=0,menubar=0,resizable=no,scrollbars=no");
		return oWnd;
}

/* onLoad Handler */
LOAD_LIST = new Array();
function LH_create()
{
		this.LIST = LOAD_LIST;
		this.add = LH_add;
		this.exec = LH_exec;
}

function LH_add(strExec)
{
		LOAD_LIST[LOAD_LIST.length] = strExec;
}

function LH_exec()
{
		var list_len = LOAD_LIST.length;
		for (var i = 0; i < list_len; i++)
		{
				eval(LOAD_LIST[i]);
		}
}

/* ÇÑ±Û ½ºÆ®¸µ Ã³¸® ÇÔ¼ö */
// string String::cut(int len, string tail)
String.prototype.cut = function(len, tail) 
{
		var str = this;
		var l = 0;
		for (var i=0; i<str.length; i++) 
		{
				l += (str.charCodeAt(i) > 128) ? 2 : 1;
				if (l > len) return str.substring(0,i) + tail;
		}
		return str;
}

// bool String::bytes(void)
String.prototype.bytes = function() 
{
		var str = this;
		var l = 0;
		for (var i=0; i<str.length; i++) 
				l += (str.charCodeAt(i) > 128) ? 2 : 1;

		return l;
}

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

// µû¿ÈÇ¥¿Í ¿ª½½·¡½¬ Ã³¸®
function replaceBackslash(paramStr) 
{
		var str = paramStr;
		if (str.indexOf("\\") >= 0) str = str.replace(/\\/g, "\\\\");
		if (str.indexOf("\"") >= 0) str = str.replace(/\"/g, "\\\"");
		return str;
}

function setTop()
{
	window.scrollTo(0,0);
}
// == Iframe Handling ==
// iframe resize½Ã ÃÖ¼Ò width, height
var frmMinWidth;
var frmMinHeight;
var applyMinSize = false;
// iframe resize½Ã ÃÖ´ë width, height
var frmMaxWidth;
var frmMaxHeight;
var applyMaxSize = false;
function setMinSize(width, height)
{
		frmMinWidth = width;
		frmMinHeight = height
		applyMinSize = true;
}
function setMaxSize(width, height)
{
		frmMaxWidth = width;
		frmMaxHeight = height
		applyMaxSize = true;
}

function resizeIframe(name,widthObj)
{
		if (name == null || name == "")
		{
				name = "cafe_main";
		}
				
		try
		{
				if (IE4)
						var oBody	 = document.frames(name).document.body;
				else
						var oBody = document.getElementById(name).contentDocument.body;
				var oIFrame = document.getElementById(name);
		var subWidth = eval("document."+widthObj);;

				var frmWidth	= subWidth.width;
				var frmHeight = oBody.scrollHeight;

				if (applyMinSize)
				{
						frmWidth	= Math.max(frmWidth, frmMinWidth);
						frmHeight = Math.max(frmHeight, frmMinHeight);
				}
				if (applyMaxSize)
				{
						frmWidth	= Math.min(frmWidth, frmMaxWidth);
						frmHeight = Math.min(frmHeight, frmMaxHeight);
				}


				oIFrame.style.height = frmHeight;
				oIFrame.style.width = frmWidth;
		}
		catch (e) {}
}

function parentResizeIframe(name,widthObj)
{
		if (parent && parent != this && parent.resizeIframe != null)
		{
				parent.resizeIframe(name,widthObj);
		}
}

// F5¸¦ ´­·¶À»¶§ iframe ³»ºÎ¸¸ refresh µÇµµ·Ï Ã³¸® start
if (NS4) 
{
		document.captureEvents(Event.KEYDOWN)
		document.onkeydown = trapRefreshNS;
} 
else if (IE4) 
{
		document.onkeydown = trapRefreshIE;
}

function trapRefreshNS(e)
{
		if (e.keyCode == 116)
		{
				e.cancelBubble = true; 
				e.returnValue = false;
				document.location.reload();
		}
}

function trapRefreshIE()
{
		if (event.keyCode == 116)
		{
				event.keyCode = 0; 
				event.cancelBubble = true; 
				event.returnValue = false;
				document.location.reload();
		}
}
// F5¸¦ ´­·¶À»¶§ iframe ³»ºÎ¸¸ refresh µÇµµ·Ï Ã³¸® end

function parentPlusIframe(name, height)
{
		if (parent && parent != this && parent.plusIframe != null)
		{
				parent.plusIframe(name, height);
		}
}

function plusIframe(name, height)		 
{
		if (name == null || name == "")
		{
				name = "cafemain";
		}
		
		try
		{
				if (IE4)
						var oBody	 = document.frames(name).document.body;
				else
						var oBody = document.getElementById(name).contentDocument.body;
				var oIFrame = document.getElementById(name);

				var frmWidth	= oBody.scrollWidth;
				var frmHeight	= oBody.scrollHeight;

				if (applyMinSize)
				{
						frmHeight = Math.max(frmHeight, frmMinHeight);
				}
				if (applyMaxSize)
				{
						frmHeight = Math.min(frmHeight, frmMaxHeight);
				}
				oIFrame.style.height = frmHeight + height;
		}
		catch (e)
		{
				window.status = "IFrame Size Plus Error";
		}
}

function move_login(msg){
	if(confirm(msg+' ·Î±×ÀÎÇØ¾ßÁö¸¸ »ç¿ë°¡´ÉÇÕ´Ï´Ù. ·Î±×ÀÎÇÏ½Ã°Ú½À´Ï±î?') == true)
	{
		document.form_login.submit();
	}
}

function msglen(contentFormElement,limit){
	var length_limit=limit;
	var length=calculate_msglen(contentFormElement.value);
	if(length>length_limit){
	 alert("ÃÖ´ë "+length_limit+"byteÀÌ¹Ç·Î ÃÊ°úµÈ ±ÛÀÚ¼ö´Â ÀÚµ¿À¸·Î »èÁ¦µË´Ï´Ù.");
	 contentFormElement.value=contentFormElement.value.replace(/\r\n$/,"");
	 return assert_msglen(contentFormElement,length_limit);
	}
 return length;
}
function calculate_msglen(message){
	var nbytes=0;
	for(i=0;i<message.length;i++){
		var ch=message.charAt(i);
	 if(escape(ch).length>4){
		 nbytes+=2;
	 }else if(ch=='\n'){
	 if(message.charAt(i-1)!='\r'){
		nbytes+=1;
	 }
		 }else if(ch=='<'||ch=='>'){
		nbytes+=4;
	 }else{
		nbytes+=1;
	 }
	}
	return nbytes;
}
function assert_msglen(contentFormElement,maximum) {
	var message=contentFormElement.value;
	var inc=0;
	var nbytes=0;
	var msg="";
	var msglen=message.length;
	 for(i=0;i<msglen;i++){
	 var ch=message.charAt(i);
		if(escape(ch).length>4){
		inc=2;
		}else if(ch=='\n'){
			if(message.charAt(i-1)!='\r'){
		 inc=1;
		 }
		}else if(ch=='<'||ch=='>'){
		 inc=4;
		}else{
		 inc=1;
		}
	 if((nbytes+inc)>maximum){
		break;
	 }
	 nbytes+=inc;msg+=ch;
	}
 contentFormElement.value=msg;
 return nbytes;
}

function b64eURL(input){
	var keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output="";
	var chr1,chr2,chr3;
	var enc1,enc2,enc3,enc4;
	var i=0;
	do{chr1=input.charCodeAt(i++);
	chr2=input.charCodeAt(i++);
	chr3=input.charCodeAt(i++);
	enc1=chr1>>2;
	enc2=((chr1&3)<<4)|(chr2>>4);
	enc3=((chr2&15)<<2)|(chr3>>6);
	enc4=chr3&63;
	if(isNaN(chr2)){
		enc3=enc4=64;
	}else if(isNaN(chr3)){
		enc4=64;
	}
	output=output+keyStr.charAt(enc1)+keyStr.charAt(enc2)+keyStr.charAt(enc3)+keyStr.charAt(enc4);
 }
 while(i<input.length);
 output=output.replace(/[\=]/g,"_");
 return output;
 }
function b64dURL(input){
	var keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output="";
	var chr1,chr2,chr3;
	var enc1,enc2,enc3,enc4;
	var i=0;
	input=input.replace(/[\_]/g,"=");
	input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");
	do{enc1=keyStr.indexOf(input.charAt(i++));
	enc2=keyStr.indexOf(input.charAt(i++));
	enc3=keyStr.indexOf(input.charAt(i++));
	enc4=keyStr.indexOf(input.charAt(i++));
	chr1=(enc1<<2)|(enc2>>4);
	chr2=((enc2&15)<<4)|(enc3>>2);
	chr3=((enc3&3)<<6)|enc4;
	output=output+String.fromCharCode(chr1);
	if(enc3!=64){
		output=output+String.fromCharCode(chr2);
	}
		if(enc4!=64){
		output=output+String.fromCharCode(chr3);
	}
	}
	while(i<input.length);
	return output;
}

var alert2=function(msg,moduleID,width,height,params,url,thema){
	if(Browser.is_ie){
		showModal(msg,moduleID,width,height,params,url,'alert',tUrl);
	}else{
		alert(msg);
	}
}

var confirm2=function(msg,moduleID,width,height,params,url,thema){
	if(Browser.is_ie){
		return(showWindow(msg,moduleID,width,height,params,boardDir+'/popup/confirmMessage.html','confirm',tUrl));
	}else{
		return(showWindow(msg,moduleID,width,height,params,boardDir+'/popup/confirmMessage.html','confirm',tUrl));
	}

}

var passInput=function(msg,moduleID,width,height,params,url,thema){
	if(Browser.is_ie){
		return(showWindow(msg,moduleID,width,height,params,boardDir+'/popup/passInput.html','confirm',tUrl));
	}else{
		return(showWindow(msg,moduleID,width,height,params,boardDir+'/popup/passInput.html','confirm',tUrl));
	}

}


function showWindow(msg,moduleID,width,height,params,url,type,thema){
if(!width||'undefined'==typeof(width))
var width=420;
if(!height||'undefined'==typeof(height))
var height=220;
if(!msg||'undefined'==typeof(msg))
var msg="¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.";
if(!url||'undefined'==typeof(url)){
		var url=boardDir+"/popup/alertMessage.html";
}

if(Browser.is_xp)
height=height+30;

window.open(url,'windows','height='+height+',width='+width);
}

function showModal(msg,moduleID,width,height,params,url,type,thema){
	if(typeof moduleID=='undefined'||!moduleID){
		if(type=='alert')
			moduleID="common.alert";
		else if(type=='confirm')
			moduleID="common.confirm";
		else

	return false;
	 }
if(!width||'undefined'==typeof(width))
var width=420;
if(!height||'undefined'==typeof(height))
var height=220;
if(!msg||'undefined'==typeof(msg))
var msg="¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.";
if(!url||'undefined'==typeof(url)){ var url=boardDir+"/popup/alertMessage.html"; }

if(Browser.is_xp)
height=height+30;
if(typeof params!='object')params={};
 var args=new Array();
 args["msg"]=msg;
 args["thema"]=thema;
 var userparamQueryString='';
 for(var p in params)
 {
	if(p!='extend')
	{
		args[p]=params[p];
		if(p=='userparam'){ userparamQueryString='&userparam='+params[p] }
	}
 }
 
if(!args["title"])args["title"]="CICBOARD";
var modalurl=url+"";
return(window.showModalDialog(modalurl,args,"dialogWidth:"+width+"px; dialogHeight:"+height+"px; edge:sunken; center:yes; resizable:yes; status:no; help:no, scroll:no;"));
}

global_disable_select=function(){
debug("global_disable_select");
document.onselectstart=new Function('return false');
}

global_enable_select=function(){
document.onselectstart=new Function('return true');
}

function global_textarea_limiter(textarea,max){
if(textarea.value.length>max)textarea.value=textarea.value.substring(0,max);
}

_pi=function(str){
return parseInt(str);
}

_ge=function(id){
return document.getElementById(id);
}

String.prototype.chop=function(){
return this;
}

function getRandomId(){
return(new Date().getTime());
}

function trim(s){
while(s.substring(0,1)==' '){
s=s.substring(1,s.length);
}

while(s.substring(s.length-1,s.length)==' '){
s=s.substring(0,s.length-1);
}

return s;
}

String.prototype.nl2br=function(){
return this.split('\n').join('<br \/>\n');
}

String.prototype.replace=function(find,replace){
return this.split(find).join(replace);
}

String.prototype.escapeForXML=function(){
return this.replace('&','&amp;').replace('"','&quot;').replace('<','&lt;').replace('>','&gt;');
}

String.prototype.escapeForDisplay=function(){
return this.replace('<','&lt;');
}

String.prototype.truncate_with_ellipses=function(chars_allowed){
var t=this;
if(t.length>chars_allowed-3){
t=t.substr(0,chars_allowed-3)+'...'
}

return t;
}
