////////////////////////////////////////////////////////////////////////////////////
//
//	±âº» ÇÔ¼ö
//
////////////////////////////////////////////////////////////////////////////////////
function convevent(ev) { // Explorer ¹× Firebox ÀÌº¥Æ® °´Ã¼ È£È¯
	e = (window.event) ? window.event : ev;
	return e;
}


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.prototype.parseNo = function () { // NaN Ã³¸®
	var str = this;
	str = parseInt (str);
	if ( isNaN (str) ) str = 0;

	return str;
}

function getHttpRequest(URL) { // Ajax »ç¿ëÇÔ¼ö
	
	nochache = new Date();

	if ( URL.indexOf("?") < 0) URL += "?";

	URL = URL+"&ncache="+nochache;

	var xmlhttp = null;
	if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
	else 	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.open('GET', URL, false);
		
	xmlhttp.onreadystatechange = function() { 
		if(xmlhttp.readyState==4 && xmlhttp.status == 200 && xmlhttp.statusText=='OK') {
			responseText = xmlhttp.responseText; 
		} 
	}
	xmlhttp.send('');
		
	return responseText = xmlhttp.responseText;
}

function fr_resize(frm){ //	ÇÁ·¹ÀÓÀÇ ¼¼·Î ±æÀÌ¸¦ ÀÚµ¿ Á¶Á¤ÇÑ´Ù
	fn = eval(frm.name);
	frm.style.height = fn.document.body.scrollHeight+25;
}

 function number_format(val){            
	 ret_val = val.toLocaleString();
	 pos = ret_val.indexOf(".");
	 if(pos==-1) pos = ret_val.length;
	 ret_val = ret_val.substr(0,pos);
	 return(ret_val);
}


////////////////////////////////////////////////////////////////////////////////////
//
//	ÀÌ¹ÌÁö ±æÀÌ ÀÚµ¿ Á¶Á¤
//
////////////////////////////////////////////////////////////////////////////////////
function autosize() {
	for (i = 0; i < document.images.length; i++) { //	ÀüÃ¼ ÀÌ¹ÌÁöÀÇ °¡·Î ±æÀÌ Á¶Á¤
		obj = document.images[i];
		pr_size = getParentsize(obj);
		if (pr_size) {
			if (obj.width > pr_size) {
				obj.width = pr_size;
				obj.alt = "°¡·Î ±æÀÌ ÃÊ°ú·Î ÀÚµ¿ Ãà¼ÒµÈ ÀÌ¹ÌÁö ÀÔ´Ï´Ù\nÀÌ¹ÌÁö°¡ ±úÁ®º¸ÀÏ ¼ö ÀÖ½À´Ï´Ù";
				obj.style.cursor = "pointer";
				obj.onclick = function () { pview (this) };
			}
		}
	}
}

function getParentsize(obj) { //	ºÎ¸ð ·¹ÀÌ¾î¸¦ Ã£¾Æ ±× offsetWidth ¸¦ ±¸ÇÑ´Ù
	while (1) {
		if (obj.parentNode.tagName == "BODY" ||  obj.parentNode.tagName == "HTML") return false;
		if (obj.parentNode.className == "bbscontent") {
			parentWidth = obj.parentNode.offsetWidth;
			return parentWidth;
		} else obj = obj.parentNode;
	}
}


////////////////////////////////////////////////////////////////////////////////////
//
//	[ Object ] ÀÇ innerHTML À» Å¬¸³º¸µå·Î º¹»çÇÑ´Ù
//
////////////////////////////////////////////////////////////////////////////////////
function toClipboard(obj) {  
	obj.blur();
	obj = obj.innerHTML
	window.clipboardData.setData('Text', obj);
	window.alert("[ "+obj+" ]\nÅ¬¸³º¸µå¿¡ ÀúÀåµÇ¾ú½À´Ï´Ù");
	return false;
}  


////////////////////////////////////////////////////////////////////////////////////
//
//	Æû ÄÁÆ®·Ñ °ü·Ã ¸Þ¼Òµå
//
////////////////////////////////////////////////////////////////////////////////////
function f_check(f,nh){ // Æû ÇÊ¼ö ÀÔ·Â»çÇ×À» Ã¼Å©ÇÑ´Ù

	try {
		if ( f.getAttribute("isR2Na") != null ) R2NaTocontent (f.getAttribute("isR2Na"));
	}	catch ( ex ) { }

	var msg = "";
	for(i = 0; i < f.length; i++){
		fe = f.elements[i];
		if (fe.title && !fe.limit){
			if (fe.maxbytes && fe.value.bytes() > fe.maxbytes) msg = fe.maxbytes+"ÀÚ ÀÌÇÏ·Î ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À";
			if (fe.minbytes && fe.value.bytes() < fe.minbytes) msg = fe.minbytes+"ÀÚ ÀÌ»óÀ¸·Î ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À";
			if (!fe.value.length) msg = fe.title;
			if (msg)	{
				window.alert (msg);
				if (fe.style.display != "none") fe.focus();
				return false;
			}
		}
	}

	return true;
}

function cknum(form) { // Æû ³»ÀÇ Ã¼Å©µÈ ckno[] °¹¼ö¸¦ ¸®ÅÏ
	ckea = 0;
	if (	form.elements.length) {
		for (i = 0; i < form.length; i++){
			if (form.elements[i].name == "ckno[]" && form.elements[i].checked == true) ckea++;
		}
	}
	return ckea;
}

function ckno(form,msg) { //	ÆûÀÇ Ã¼Å©µÈ ckno[] °¹¼ö¸¦ °è»êÇÏ¿© msg ·Î ÁúÀÇÇÑ ÈÄ action À» ºÎ¿©ÇÏ¿© Submit

	ckea = cknum(form);

	if (!ckea) {
		alert ("¼±ÅÃµÈ Ç×¸ñÀÌ ¾ø½À´Ï´Ù");
		return false;
	} else {
		if (msg)	{
			conf = confirm(msg);
			if (!conf) return false;
		}
		form.submit();
		return false;
	}
}

function ckall(elem,obj){ //	 ÀÌ¸§ÀÌ $1 ÀÎ Ã¼Å©¹Ú½ºÀÇ checked Á¤º¸¸¦ obj¿Í °°°Ô ÇÑ´Ù = Æû ³»ºÎ =

	form = obj.form;

	if (obj.checked == true) {
		for (i = 0; i < form.length; i++){
			if (form.elements[i].name == elem && form.elements[i].disabled == false) {
				form.elements[i].checked = true;
			}
		}
	} else {
		for (i = 0; i < form.length; i++){
			form.elements[i].checked = false;
		}
	}
}

function ckallDocument(f,obj){//	 ÀÌ¸§ÀÌ $1 ÀÎ Ã¼Å©¹Ú½ºÀÇ checked Á¤º¸¸¦ obj¿Í °°°Ô ÇÑ´Ù = ÀüÃ¼ ¹®¼­ =

	f = document.getElementById (f);

	if (obj.checked == true) {
		for (i = 0; i < 	f.length; i++){
			if (	f.elements[i].type == "checkbox" && f.elements[i].disabled == false) {
				f.elements[i].checked = true;
			}
		}
	} else {
		for (i = 0; i < f.length; i++){
			f.elements[i].checked = false;
		}
	}
}

function selectOrder (select,m) {
	var f = document.getElementById (select);

	now = f.selectedIndex;
	target = now + m;

	if ( now < 0 ) {
		window.alert ("ÀÌµ¿½ÃÅ³ Ç×¸ñÀ» ¼±ÅÃÇØ ÁÖ½Ê½Ã¿À");
	}

	if ( target < 0 ) target = 0;
	if ( target >= f.length ) target = f.length -1;
	if (m > 0 ) target++;

	obj = f.children (now);
	pos = f.children (target);

	f.insertBefore (obj, pos);
}

function setOrder (s,n) {
	var s = document.getElementById (s);
	var n = document.getElementById (n);
	var posdata = "";

	for ( i = 0; i < s.length; i++) {
		obj = s.children(i);
		posdata += "@"+obj.value;
	}

	n.value = posdata;
}

////////////////////////////////////////////////////////////////////////////////////
//
// ½ºÅ¸ÀÏ °ü·Ã ½ºÅ©¸³Æ®
//
////////////////////////////////////////////////////////////////////////////////////
var seq = "";
function show(rep){ //	¼±ÅÃÇÑ ·¹ÀÌ¾î¸¦ show/hide ½ÃÅ²´Ù
	rep = document.getElementById (rep);

	if(seq != rep){
		if(seq !="" ) seq.style.display = "none";
		rep.style.display = "block";
		seq = rep;
	}
	else{
		rep.style.display = "none";
		seq = "";
	}
}

function colourOn(obj, code) { //	[object] ÀÇ backgroundcolor ¸¦ º¯°æÇÑ´Ù
	if (code) obj.style.backgroundColor = code;
	else obj.style.backgroundColor = "";
}


////////////////////////////////////////////////////////////////////////////////////
//
//	Image Preview Window Open
//
////////////////////////////////////////////////////////////////////////////////////
function pview(obj, filename) {

	filename = (filename) ? filename : obj.src;

	var browser = navigator.appName;
	var explorer = browser.indexOf("Explorer");

	if (explorer > 0) window.showModalDialog ("/inc/image_viewer.php?filename="+filename,self, "center:true;resizable:no;scroll:no;status:no");
	else wopen ("/inc/image_viewer.php?filename="+filename, "imageView","width=200 menubar=no scrollbars=yes statusbar=no toolbar=no resizable=no");

	return false;
}


////////////////////////////////////////////////////////////////////////////////////
//
//	ÁúÀÇ Ã¼Å©
//
////////////////////////////////////////////////////////////////////////////////////
function query(msg){
	if (!msg) msg = "Á¤¸» »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?";

	conf = confirm (msg);
	if (!conf) return false;
}


////////////////////////////////////////////////////////////////////////////////////
//
//	°ªÀ» ÀÔ·Â¹Þ¾Æ % ¸¦ ±¸ÇÑÈÄ ÁöÁ¤µÈ Æû¿¡ ³»¿ë Ãâ·Â
//
////////////////////////////////////////////////////////////////////////////////////
function getPercent ( val, per, dest, mode ) {
	val  = document.getElementsByName ( val )[0];
	per  = document.getElementsByName ( per )[0];
	dest  = document.getElementsByName ( dest )[0];

	if ( !val || !per || !dest) return;

	val = parseInt (val.value);
	per = parseInt (per.value);

	calc = val - ( val * ( per / 100 ) );
	if (mode == "floor" ) calc = Math.floor (calc);
	else calc = Math.ceil (calc);

	dest.value = calc;
	if (dest.value == "NaN") dest.value = 0;
}


////////////////////////////////////////////////////////////////////////////////////
//
//	»õÃ¢ °ü·Ã ½ºÅ©¸³Æ®
//
////////////////////////////////////////////////////////////////////////////////////
function wopen (theURL,winName,features) { // ÀÏ¹Ý »õÃ¢ ¶ç¿ì±â
	var win;
	win = window.open (theURL,winName,features);
	if ( win ) win.focus();
}

function load_modal_window(file,arg,width,height){//	Modal Window¸¦ ¿¬´Ù / IE Àü¿ë
	a = window.showModalDialog(file,arg,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;center:true;resizable:no;scroll:no;status:no");
	return false;
}


////////////////////////////////////////////////////////////////////////////////////
//
//	Ajax¸¦ ÀÌ¿ëÇÏ¿© ÄíÅ°¸¦ ±Á´Â´Ù
//
////////////////////////////////////////////////////////////////////////////////////
function burnCookie(cookieName,value) {
	getHttpRequest(url_root+"/inc/burncookie.php?cookiename="+cookieName+"&value="+value);
}


////////////////////////////////////////////////////////////////////////////////////
//
//	Comment Module
//
////////////////////////////////////////////////////////////////////////////////////
function remComment(no,echomode) {
	conf = confirm ("ÄÚ¸àÆ®¸¦ »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?");
	if (conf) hide.location.href = 'sub/comment/comment_del.php?no='+no+"&echomode="+echomode;
}

var mod_ing = "";
function ComMod(no) {
	form = document.getElementById ("comment_"+no);
	content = document.getElementById ("content_"+no);
		
	if (form.submit.style.display == "none") {
		if (mod_ing != no && mod_ing) {
			old_form = document.getElementById ("comment_"+mod_ing);
			old_content = document.getElementById ("content_"+mod_ing);

			if (old_form.submit.style.display == "block") {
				old_form.reset();
				value = old_form.content.value.replace(/\n/g, "<br />");
				old_content.innerHTML = value;
				old_form.submit.style.display = "none";
			}
		}
		value = content.innerHTML.replace(/<BR>/g, "\n");
		content.innerHTML = "<textarea name='content' class='writearea2' title='ÄÚ¸àÆ®¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä'>"+value+"</textarea>";
		form.submit.style.display = "block";
		content.focus();

		mod_ing = no;
	} else {
		value = form.content.value.replace(/\n/g, "<br />");
		value = form.content.value.replace(/\r/g, "<br />");
		form.reset();
		content.innerHTML = value;
		form.submit.style.display = "none";
	}
}


////////////////////////////////////////////////////////////////////////////////////
//
//	¿ìÆí¹øÈ£ Ã³¸®
//
////////////////////////////////////////////////////////////////////////////////////
function openPost (post1, post2, address) {

	wopen (url_root+"/inc/putPost.php?field="+post1+"@"+post2+"@"+address,"chkaddr","width = 353px height = 351px left = "+event.x+" top = "+event.y+"center= true scrollbars = no resizable = no status=no");
}

function toPost (obj) {
	var tar =obj.field.value.split ("@");
	var zcode = obj.zipcode.value.split ("-");

	t_post1 = opener.document.getElementsByName (tar[0])[0];
	t_post2 = opener.document.getElementsByName (tar[1])[0];
	t_addr = opener.document.getElementsByName (tar[2])[0];

	t_post1.value = zcode[0];
	t_post2.value = zcode[1];
	t_addr.value = obj.addr.value+" "+obj.bunji.value;

	opener.focus();
	self.close();

	return false;

}


////////////////////////////////////////////////////////////////////////////////////
//
//	´Þ·Â È£Ãâ
//
////////////////////////////////////////////////////////////////////////////////////
function inputCal(objname) {
	t = (screen.availHeight / 2) - 150;
	left = ( screen.availWidth /2) - 150;

	var calander = wopen (url_root+"/inc/calander.php?obj="+objname, "calander", "width=230px height=265px top="+t+"px left="+left+"px scrollbars=no status=no");
	if (calander) calander.focus();

	return false;

}


////////////////////////////////////////////////////////////////////////////////////
//
//	ÆË¾÷°ü¸®ÀÚ °ü·Ã ½ºÅ©¸³Æ®
//
////////////////////////////////////////////////////////////////////////////////////
function openpopup(no, w, h) {
	alert (1);
	pop = window.open (url_root+"/inc/popview.php?no="+no, "pop"+no, "width="+w+"px height="+h+"px scrollbars=auto status=no");

	if (pop) pop.focus();
}

function layerPOP (page,width,pos) {

	if ( !pos ) pos = 0;
	if ( !width ) width = 300;

	temp = document.createElement ("DIV");
	temp.className = "layerpopup";
	temp.style.zIndex = pos;
	temp.style.top = 30 * pos;
	temp.style.left = 30 * pos;
	temp.style.width = width;
	temp.dragable = 1;
	temp.id = "lpopup_"+pos;

	temp.innerHTML = getHttpRequest (page);
	document.body.appendChild (temp);
	drag_init();
	autosize();

}

function removepop (pos) {
	pop = document.getElementById ("lpopup_"+pos);
	if ( pop ) document.body.removeChild ( pop );
}

function neveropen(no,pos) {

	if ( !pos ) pos = no;

	burn = getHttpRequest (url_root+"/inc/burncookie.php?cookiename=cookie_popup_prt_"+no+"&value=1&time=1");
	if (burn) removepop (pos)
}

function popchange(obj) {

	no = obj.value;
	val = obj.checked;

	val = (val == true) ? "Y" : "N";

	burn = getHttpRequest (url_root+"/admin/shop/popup_change.php?no="+no+"&val="+val);
	if (burn) window.alert ("ÆË¾÷ Ãâ·Â ¿©ºÎ°¡ º¯°æµÇ¾ú½À´Ï´Ù");

}

function byteCheck (obj,slen) {

	var tmpStr1, tmpStr2;
	tmpStr1 = obj.value;
	tmpStr2='';
	tcount=0;
	temp=0;

	for (k=0;k<tmpStr1.length;k++)
	{
		onechar=tmpStr1.charAt(k);
		if (escape(onechar).length > 4) {
			temp=2;
		}
		else if (onechar != '\r'){
			temp=1;
		}
		else temp=0;

		tcount+=temp;

		if (tcount > slen) {
			alert("\n ¹ß¼ÛÇÒ ¼ö ÀÖ´Â ¹®ÀÚ´Â 80ÀÚ·Î Á¦ÇÑµË´Ï´Ù \n");
			obj.value = tmpStr2;
			tcount-=temp;
			break;
		}
		else {
			tmpStr2+=onechar;
		}
	}

	var prtArea = document.getElementById("prtBytes");
	if (prtArea) prtArea.innerText = tcount;
	return;
}

function openpopup(no, w, h) {
	pop = wopen (url_root+"/inc/popview_win.php?no="+no, "pop"+no, "width="+w+"px height="+h+"px scrollbars=auto status=no");

	if (pop) pop.focus();
}

function neveropen_win(no) {

	burn = getHttpRequest (url_root+"/inc/burncookie.php?cookiename=cookie_popup_prt_"+no+"&value=1&time=1");
	if (burn) self.close();
}


/*////////////////////////////////////////////////////////////////////////////////////
//
//	Tulltip Control
//
////////////////////////////////////////////////////////////////////////////////////*/
function onmsg (msg) {

	var mbox;
	mbox = document.getElementById ("msgbox");

	if (msg) {
		if (!mbox) mbox = init_mbox();
		mbox.style.display = "block";
		mbox.innerText = msg;
		if ( mbox.offsetWidth > 300 ) mbox.style.width = 300;
		mbox.style.left = event.clientX + document.body.scrollLeft;
		mbox.style.top = event.clientY + document.body.scrollTop - mbox.offsetHeight - 5;

	} else {
		if (mbox) document.body.removeChild (mbox);
	}

}

function init_mbox () {
	mbox = document.createElement ("DIV");
	mbox.id = "msgbox";
	mbox.style.display = "none";
	mbox.style.position = "absolute";
	mbox.style.border = "solid 1px pink";
	mbox.style.backgroundColor = "#fff";
	mbox.style.padding = "3px 10px";
	mbox.style.fontWeight = "bold";
	mbox.color = "#000";
	mbox.style.filter = "alpha(opacity=90)";
	document.body.appendChild (mbox);

	return mbox;
}


/*////////////////////////////////////////////////////////////////////////////////////
//
//	Neko_upper
//
////////////////////////////////////////////////////////////////////////////////////*/
function neko_init () {
	neko_id = document.getElementsByName("neko_id");
	neko_group = document.getElementsByName("neko_gr");
	neko_mode = document.getElementsByName("neko_mode");
	
	if ( !neko_id[0] || !neko_group[0] ) return;

	neko_id = neko_id[0].value;
	neko_group = neko_group[0].value;
	neko_mode = neko_mode[0].value;

	if (!neko_id || !neko_group || !neko_mode){
		window.alert ("[Neko Uploader]\n\nÇÊ¼ö ÆÄ¶ó¸ÞÅÍ°¡ ºÎÁ·ÇÕ´Ï´Ù\nÆÄ¶ó¸ÞÅÍ ÀÔ·Â¿©ºÎ¸¦ È®ÀÎÇØ ÁÖ½Ê½Ã¿À              ");
		return;
	}

	frm = "<iframe id='neko_load' src='/inc/neko_upper/neko_body.php?neko_id="+neko_id+"&neko_gr="+neko_group+"&neko_mode="+neko_mode+"' frameborder='0'></iframe>";
	document.write (frm);
}

function neko_loaded () {
	document.body.onload = function() {
		fr = parent.document.getElementById ("neko_load");
		fr.style.width = document.body.scrollWidth;
		fr.style.height = document.body.scrollHeight;
	}
}


function neko_sel ( no ) {
	pr = document.getElementById ("neko_preview");
	pr.src = "/inc/neko_upper/neko_preview.php?no="+no;

	var neko_selno = document.getElementsByName ("neko_selno")[0];
	if (neko_selno.value) {
		oldsel = document.getElementById ("nekolist_"+neko_selno.value);
		oldsel.style.backgroundColor = "";
	}
	newsel = document.getElementById ("nekolist_"+no);
	newsel.style.backgroundColor = "#FFFBD7";
	neko_selno.value = no;
}

function neko_copyTo() {
	var neko_selno = document.getElementsByName ("neko_selno")[0];
	var neko_id = document.getElementsByName ("neko_id")[0];
	var neko_related = parent.document.getElementsByName ("neko_related")[0];
	var neko_mode = parent.document.getElementsByName ("neko_mode")[0];

	if ( neko_selno.value ) {
		no = neko_selno.value;
		filename = getHttpRequest (url_root+"/inc/neko_upper/neko_related.php?mode="+neko_mode.value+"&no="+no);
		if ( filename ) {
			parent.R2Na_Exec(1,'InsertImage',filename);
			parent.R2NaTocontent('content');

			neko_related.value = neko_related.value+"@"+filename;
			neko_frame.location.href = url_root+"/inc/neko_upper/neko_load.php?neko_id="+neko_id.value;
		} else {
			window.alert ("GIF, JPG, PNG ÆÄÀÏ¸¸ »ç¿ëÇÒ¼ö ÀÖ½À´Ï´Ù");
		}
	} else {
		window.alert ("¼±ÅÃµÈ ÆÄÀÏÀÌ ¾ø½À´Ï´Ù");
	}
}

function reEmbed(eid) {
	obj = document.getElementById (eid);
	document.write (obj.value);
}
