var hlogin_id = '';
var IBURL = '';
var IBLINK = '';
var IBS = '';

String.prototype.trim = function() {
	return this.replace(/^\s*(\b.*\b|)\s*$/, "$1"); // ¹®ÀåÀÇ ¾Õ°ú µÚÀÇ °ø¹é Á¦°Å
}


function Comment_p_delete(member){
	f = document.comment_p;
	if(member == "0"){
		if(is_space(f.del_pwd.value)){
			alert("ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!");
			f.del_pwd.focus();
			return;
		}
	}

	f.action = "/MY/my_proc.html";
	f.submit();
}

function Img_delete_p(member){
	f = document.delete_p;
	if(member == "0"){
		if(is_space(f.del_pwd.value)){
			alert("ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!");
			f.del_pwd.focus();
			return;
		}
	}
	f.submit();
}

function delete_reply(reply_num,rform, type){

	f = document.getElementsByName(rform)[0];
	f.reply_num.value= reply_num;
	f.Mode.value = "Reply_del";
	img_filename = f.img_filename.value;
	user_id = f.parent_id.value;

	var url = IBURL + '/GALLERY/comment_p.html?img_filename='+img_filename +
			  '&reply_num='+reply_num+"&user_id="+user_id+"&type="+type + "&ibs=" + IBS;
	window.open(url, '_drp' ,'left=200,top=200,width=100,height=200,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0');
}

function delete_reply_v2(reply_num,rform, type, width, height){

	f = document.getElementsByName(rform)[0];
	f.reply_num.value= reply_num;
	f.Mode.value = "Reply_del";
	img_filename = f.img_filename.value;
	user_id = f.parent_id.value;

	var url = IBURL + '/GALLERY/comment_p.html?img_filename='+img_filename + '&reply_num='+reply_num+"&user_id="+user_id+"&type="+type + "&ibs=" + IBS;
	window.open(url, '_drp' ,'left=200,top=200,width='+width+',height='+height+',toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0');
}

function img_delete(rform, type){
	f = document.getElementsByName(rform)[0];
	img_filename = f.img_filename.value;
	page = f.page.value;
	var url = IBURL + '/GALLERY/img_delete_p.html?img_filename='+img_filename+'&page='+page+"&type="+type + "&ibs=" + IBS;
	del = window.open(url, 'dimg' ,'left=200,top=200,width=100,height=144,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0');
}

function delete_reply1(reply_num, img_filename){
	var url = '/GALLERY/comment_p.html?img_filename='+img_filename+'&reply_num='+reply_num;
	window.open(url, '_drp' ,'left=200,top=200,width=100,height=144,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0');
}


function is_space (s) {
	var space = " \t\n\r";
	var i;
	for (i=0; i<s.length; i++) {
		var c = s.charAt(i);
		if (space.indexOf(c) == -1) return false;
	}
	return true;
}



function reply_add(rform) {

	f = document.getElementsByName(rform)[0];

	var contents = f.reply_contents.value;
	var yahoo_id = f.yahoo_id.value;

	if(yahoo_id == ''){
		name = f.reply_name.value;
		pwd = f.reply_pwd.value;

		var s,bytes=0;
		for(s=0; s<name.length; s++) {
		if (escape(name.charAt(s)).length >= 4 ) {
		bytes = bytes + 2;}
		else{
		bytes = bytes + 1;}
		}

		if(is_space(pwd)||is_space(name)){
			alert("´Ð³×ÀÓ,ºñ¹Ð¹øÈ£,³»¿ë ¸ðµÎ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
			return;
		}else if (bytes>10)  {
				alert("´Ð³×ÀÓÀº 10 ¹ÙÀÌÆ®(¿µ¹® 10ÀÚ ¶Ç´Â ÇÑ±Û 5ÀÚ)¸¦ ³ÑÀ» ¼ö ¾ø½À´Ï´Ù");
				return;
		}
	}

	if ( is_space(contents))  {
		alert("³»¿ëÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
		f.reply_contents.focus();
		return;
	}else {
		if (!Is_check_length()) {
		}else {

			f.Mode.value = "Reply_add";
			f.action = IBURL + "/MY/my_proc.html";
			f.submit();
		}
	}
}

function recommend_reply_add(rform) {

	f = document.getElementsByName(rform)[0];

	contents = f.reply_contents.value;
	f.recommend.value='1';
	var yahoo_id = f.yahoo_id.value;

	if(yahoo_id == ''){
		name = f.reply_name.value;
		pwd = f.reply_pwd.value;

		var s,bytes=0;
		for(s=0; s<name.length; s++) {
		if (escape(name.charAt(s)).length >= 4 ) {
		bytes = bytes + 2;}
		else{
		bytes = bytes + 1;}
		}

		if(is_space(pwd)||is_space(name)){
			alert("ÀÌ¸§,ºñ¹Ð¹øÈ£,³»¿ë ¸ðµÎ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
			return;
		}else if (bytes>10)  {
				alert("ÀÌ¸§Àº 10 ¹ÙÀÌÆ®(¿µ¹® 10ÀÚ ¶Ç´Â ÇÑ±Û 5ÀÚ)¸¦ ³ÑÀ» ¼ö ¾ø½À´Ï´Ù");
				return;
		}
	}

	if ( is_space(contents))  {
		alert("³»¿ëÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
		f.reply_contents.focus();
		return;
	}else {
		if (!Is_check_length()) {
		}else {
			f.Mode.value = "Reply_add";
			f.action = "/MY/my_proc.html";
			f.submit();
		}
	}
}
function recommend(rform) {

	f = document.getElementsByName(rform)[0];
	f.recommend.value='1';
	var yahoo_id = f.yahoo_id.value;
	f.Mode.value = "Recommend";
	f.action = IBURL + "/MY/my_proc.html";
	f.submit();
}

function img_resize(img) {
   if(img.width > 619) {
	  img.width = 619;
   }
}


function write_img(img_path, width, fwidth, img_reload) {

  img1 = new Image();
  img1.src = img_path;
  img_param = "";
  img_onload = "";
  if(img_reload == '1') {
  }
//  width = img1.width;

  var oriImgWidth = width;

  if(width && width > 0) {

	if (width > fwidth) { width = fwidth; }
	img_param = " width=" + width;

  } else if(img1 && img1.width && img1.width > 0) {

	if (img1.width > fwidth) { img1.width = fwidth; }
	img_param = " width=" + img1.width;
  }

	// 2005.07.01 ¿ø·¡ ÀÌ¹ÌÁöº¸±â ÇÊ¿ä¾øÀ½.
	if (oriImgWidth && oriImgWidth <= 611) {

		document.write ("<img src=" + img1.src + img_param + img_onload + " border=0 onerror=\"this.src=this.src.replace('/img/','/thumb/');this.width = 100;\">");

	} else {

		document.write ("<a href= \"javascript:img_view('"+img_path+"')\" title='¿øº» Å©±âÀÇ »çÁøÀ» º¸·Á¸é Å¬¸¯ÇÏ¼¼¿ä'>");
		document.write ("<img src=" + img1.src + img_param + img_onload + " border=0 onerror=\"this.src=this.src.replace('/img/','/thumb/');this.width = 100;\">");
		document.write ("</a>");
	}
}

// ±Ûº¸±â¿¡¼­¸¸ »ç¿ëÇÔ
// Å×½ºÆ® ³¡³ª¸é write_img ·Î ¹Ù²Ü °Í
function write_img_view(img_path, width, fwidth, cat, randomWidth) {

  img1 = new Image();
  img1.src = img_path;
  img_param = "";
  img_onload = "";
//  if(img_reload == '1') {
//  }
//  width = img1.width;

  var oriImgWidth = width;

  if(width && width > 0) {

	if (width > fwidth) { width = fwidth; }
	img_param = " width=" + width;

  } else if(img1 && img1.width && img1.width > 0) {

	if (img1.width > fwidth) { img1.width = fwidth; }
	img_param = " width=" + img1.width;
  }

	// 2005.07.01 ¿ø·¡ ÀÌ¹ÌÁöº¸±â ÇÊ¿ä¾øÀ½.
	if (oriImgWidth && oriImgWidth <= 611) {

		document.write ("<img src=" + img1.src + img_param + img_onload + " border=0 onerror=\"this.src=this.src.replace('/img/','/thumb/');this.width = 100;\">");

	} else {

		if (cat == 'CB') {

			// ·£´ý »çÀÌÁî Ãâ·Â
			img_param = " width="+randomWidth;

			document.write ("<a href= \"javascript:img_view_CB('"+img_path+"',"+randomWidth+")\" title='¿øº» Å©±âÀÇ »çÁøÀ» º¸·Á¸é Å¬¸¯ÇÏ¼¼¿ä'>");
			document.write ("<img src=" + img1.src + img_param + img_onload + " border=0 onerror=\"this.src=this.src.replace('/img/','/thumb/');this.width = 100;\" ");
			document.write ("></a>");

		} else {
			document.write ("<a href= \"javascript:img_view('"+img_path+"')\" title='¿øº» Å©±âÀÇ »çÁøÀ» º¸·Á¸é Å¬¸¯ÇÏ¼¼¿ä'>");
			document.write ("<img src=" + img1.src + img_param + img_onload + " border=0 onerror=\"this.src=this.src.replace('/img/','/thumb/');this.width = 100;\">");
			document.write ("</a>");
		}
	}
}

function write_img_my(img_path) {

	img1 = new Image();
	img1.src = img_path;
	img_param = "";
	width = img1.width;
	height= img1.height;

	if (width > 0 && width > height)	img_param = " width=100";
	else if (height > 0 && width < height) img_param = " height=100";

	document.write ("<img src=" + img1.src + img_param + " border=0>");
}

function img_view(img_path) {

   img1 = new Image();
   img1.src = img_path;
   width = img1.width+70;
   height = img1.height+50;
   if (width > 800) width=800;
   if (height > 600) height=600
   var url = '/GALLERY/img_viewori.html?img_path=' + img_path;
   win = window.open(url,'imgviewori', 'width=' + width + ', height=' + height + ', scrollbars=yes, resizable=yes, status=yes');
//   resize(width, height);
   win.focus();
}

// ·¹ÀÌ½Ì°É Ä«Å×°í¸®¸¸ rd Å×½ºÆ® À§ÇØ¼­
// 2005.07.01
function img_view_CB(img_path, img_width) {

   img1 = new Image();
   img1.src = img_path;
   width = img1.width+70;
   height = img1.height+50;
   if (width > 800) width=800;
   if (height > 600) height=600

   var url = 'http://kr.rd.yahoo.com/image/imagebox/img'+img_width+'/*' + IBLINK + '/GALLERY/img_viewori.html?img_path=' + img_path;
//   alert(url);

   win = window.open(url,'imgviewori', 'width=' + width + ', height=' + height + ', scrollbars=yes, resizable=yes, status=yes');
//   resize(width, height);
   win.focus();
}

/* ÃÔ¿µÁ¤º¸*/
function view_print(img_path, rform,name,width) {
	img1 = new Image();
	img1.src = img_path;
	comment = document.getElementsByName(name)[0].value;

	var url = '/GALLERY/view_print.html?img_path=' + img_path+"&comment="+comment+"&width="+width;
	if (img1.width > 700 || img1.height > 600) win = window.open(url,'print', 'width=740, height=600, scrollbars=yes, resizable=yes, status=yes');
	else	win = window.open(url,'print', 'width=100, height=100, status=yes');
	win.focus();
}


if(document.captureEvents){
	document.captureEvents(Event.MOUSEMOVE);
}


function cal_menu(intMoveLeft, intMoveTop) {
	exiflayer.style.posLeft = event.x - event.offsetX + document.body.scrollLeft + intMoveLeft * 1;  // À§Ä¡ÁöÁ¤
	exiflayer.style.posTop = event.y - event.offsetY + document.body.scrollTop + intMoveTop * 1;
}

function open_menu(width,num, rform){

	var text, str;
	str = document.getElementsByName('exif_info' + num)[0].value;

	if (str != ""){

		exiflayer.style.width = width + 16;  // Å©±â ÁöÁ¤
		exiflayer.style.height = 400;

		text = '<table width="200" border="0" cellspacing="0" cellpadding="0" style="filter:alpha(opacity=90)"><tr><td align="center" valign=bottom><div align="left"><img src="http://cimage.mym.net/gallery/category/img/g01.gif" width="142" height="20"></div></td></tr><tr><td align="center"><div align="left"><img src="http://cimage.mym.net/gallery/category/img/g02.gif" width="214" height="8"></div></td></tr><tr><td align="center" background="http://cimage.mym.net/gallery/category/img/bg01.gif"><table width="95%" border="0" cellspacing="0" cellpadding="0">';

		text += '' + str + '</table></td></tr><tr><td align="center"><div align="left"><img src="http://cimage.mym.net/gallery/category/img/g03.gif" width="214" height="8"></div></td></tr></table>';

		exiflayer.style.borderColor = "#7F9DB9";
		exiflayer.innerHTML=text ;

		show_menu();
	}
}

function show_menu(){
	exiflayer.style.visibility = "visible";
}

function hide_menu(){
	exiflayer.style.borderColor = "#FFFFFF";
	exiflayer.style.visibility = "hidden";
}
/*ÃÔ¿µÁ¤º¸ ³¡*/

function location_href(f){
	location.href="/MY/home.html?id="+f.value;
}


function scrap(p,img_filename){

	if(p == "scrap_add"){
		var url = IBURL + "/GALLERY/scrap_add_p.html?img_filename="+img_filename;
		scrap_add =window.open(url, '_cp' ,'left=200,top=200,width=100,height=144,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0');

	}else if(p =="scrap_ok"){
		f = document.scrap_ok;
		yahoo_id = f.yahoo_id.value;
		gallery_num_i = f.gallery_num.value;
		var url = "/MY/my_gallery_read.html?id="+yahoo_id+"&img_filename="+img_filename+"&gallery_num_i="+gallery_num_i;
		scrap_ok=window.open(url, '_myhome' ,'left=200,top=200,width=888,height=538,status=1');
		self.close();
	}
}

function update_p(img_filename,type){

	var url = IBURL + "/GALLERY/update_p.html?img_filename=" + img_filename + "&type=" + type + "&ibs=" + IBS;
	mod_p=window.open(url, '_mod' ,'left=200,top=200,width=100,height=144,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0');
}

function update_p_v2(img_filename,type, width, height){

	var url = IBURL + "/GALLERY/update_p.html?img_filename=" + img_filename + "&type=" + type + "&ibs=" + IBS;
	mod_p=window.open(url, '_mod' ,'left=200,top=200,width='+width+',height='+height+',toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0');
}

function update(p,rform){

	f = document.update_p;

	of = opener.document.getElementsByName(rform)[0];
	if(f.member.value == 0)

		if(is_space(f.user_pwd.value)){
			alert("ºñ¹Ð¹øÈ£À» ÀÔ·ÂÇÏ¼¼¿ä");
			return;
		}else{
			of.user_pwd.value = f.user_pwd.value;
		}

	if(p == "MY"){
		of.action = "/MY/my_update.html";
	}else{
		of.action = IBURL + "/GALLERY/update.html";
	}

	of.submit();
	self.close();
}

function popup_size() {
	var obj = navigator.appVersion;
	var hei = 29;
	if (navigator.appVersion.indexOf("NT") != -1) {
		os = obj.substr(obj.indexOf("NT"),6);
		if (os > "NT 5.0") {
			hei = 35;
		}
	}
	wid = document.body.scrollWidth+10;
	hei = document.body.scrollHeight+hei;

	// ¼¼·Î°¡ 800 ÀÌ»óÀÌ¸é 800À¸·Î ¸ÂÃß°í ½ºÅ©·Ñ¹Ù¸¦ À§ÇØ °¡·Îµµ 16ÇÈ¼¿ ´Ã¸² - body¿¡ scroll=yes Ãß°¡ÇÒ °Í.
	if (hei > 800) {
		hei = 800;
		wid = wid + 16;
	}
	hei = hei + 40;
	self.resizeTo(wid,hei);
	this.focus();
}

function go_opener(url){
	if(opener.closed){window.open(url,"");}
	else {
		opener.location=url;
		opener.focus();
	}
	self.close();
}


/* ´Ð³×ÀÓ Å¬¸¯ ½Ã ·¹ÀÌ¾î */
var infoX;
var infoY;

function info_pos(x,y,sw) {
	if (sw) {
		infoX = event.x - event.offsetX + document.body.scrollLeft - x;
		infoY = event.y - event.offsetY + document.body.scrollTop - y;
	} else {
		infoX = event.x - event.offsetX + document.all.view.scrollLeft - x;
		infoY = event.y - event.offsetY + document.all.view.scrollTop - y;
	}
}

function info_nick() {
	infoX = event.x + document.body.scrollLeft - 3;
	infoY = event.y + document.body.scrollTop - 3;
}

function my_nick() {
		infoX = event.x - 3;
		infoY = event.y - 3;
}

function friend_add(id){

	var url = IBURL + "/MY/friend_add.html?id="+id;
	friend = open (url, '_friend', 'left=200,top=200,width=100,height=144,toolbar=0,menubar=0,status=0,scrollbars=0,resizable=0');

}

function go_mybox_url(url) {
	if (screen.width < 1024) {
		opt = "width=800,height=550,left=0,top=0,scrollbars=yes,status=yes";
	} else {
		left_pos = screen.width/2 - 444;
		top_pos  = screen.height/2 - 269;
		opt = "status=yes,width=888,height=538,left="+left_pos+",top="+top_pos;
	}

	window.open(url,'mybox',opt);
}

function go_mybox(nickname) {
	if (screen.width < 1024) {
		opt = "width=800,height=550,left=0,top=0,scrollbars=yes,status=yes";
	} else {
		left_pos = screen.width/2 - 444;
		top_pos  = screen.height/2 - 269;
		opt = "status=yes,width=888,height=538,left="+left_pos+",top="+top_pos;
	}

	window.open(IBURL + "/MY/home.html?id="+nickname,'mybox',opt);
}

function go_mybox2(nickname) {
	if (screen.width < 1024) {
		opt = "width=800,height=550,left=0,top=0,scrollbars=yes,status=yes";
	} else {
		left_pos = screen.width/2 - 444;
		top_pos  = screen.height/2 - 269;
		opt = "status=yes,width=888,height=538,left="+left_pos+",top="+top_pos;
	}

	//window.open("/MY/home.html?id="+nickname,'mybox',opt);
	window.open(IBURL + "/MY/my_photograph_list.html?id="+nickname,'mybox',opt);
}

function go_mybox_gallery(nickname) {
	if (screen.width < 1024) {
		opt = "width=800,height=550,left=0,top=0,scrollbars=yes,status=yes";
	} else {
		left_pos = screen.width/2 - 444;
		top_pos  = screen.height/2 - 269;
		opt = "status=yes,width=888,height=538,left="+left_pos+",top="+top_pos;
	}

	window.open(IBURL + "/MY/home.html?id="+nickname,'mybox',opt);
}

function show_nick(nickname) {
	var obj = document.all.linkNick;
	document.all.nick1.href = "javascript:friend_add('"+nickname+"')";
	document.all.nick2.href = "javascript:go_mybox('"+nickname+"')";

	obj.style.left = infoX;
	obj.style.top  = infoY;
	if (obj.style.visibility == "hidden") {
			obj.style.visibility = "visible";
	} else {
			obj.style.visibility = "hidden";
	}
}
function show_my(nickname) {
	var obj = document.all.linkNick;
	document.all.nick1.href = "javascript:friend_add('"+nickname+"')";
	document.all.nick2.href = "/MY/home.html?id="+nickname;

	obj.style.left = infoX;
	obj.style.top  = infoY;
	if (obj.style.visibility == "hidden") {
			obj.style.visibility = "visible";
	} else {
			obj.style.visibility = "hidden";
	}
}
/* ´Ð³×ÀÓ Å¬¸¯ ½Ã ·¹ÀÌ¾î
*/


	function view_scrap(name) {
		var url = "/GALLERY/scrap_view_p.html?img_filename="+name;
		window.open(url,"scrap","width=310,height=370,left=200,top=200,status=yes");
	}


function Is_check_length()
{
	var tmpStr;

	tmpStr = document.all.reply_contents.value;
	sw = cal_byte(tmpStr);
	if (sw) return true;
	else return false;
}

function cal_byte(aquery)
{

	var tmpStr;
	var temp=0;
	var onechar;
	var tcount;
	tcount = 0;

	tmpStr = new String(aquery);
	temp = tmpStr.length;

	for (k=0;k<temp;k++)
	{
		onechar = tmpStr.charAt(k);
		if (escape(onechar) =='%0D') {
		} else if (escape(onechar).length > 4) {
			tcount += 2;
		} else {
			tcount++;
		}
	}

//	document.all.reply_contents.value = tcount;
	if(tcount>180)
	{
		reserve = tcount-180;
		alert("¸Þ½ÃÁö ³»¿ëÀº 180¹ÙÀÌÆ® ÀÌ»óÀº ³ÑÀ»¼ö ¾ø½À´Ï´Ù.\r\n ¾²½Å ¸Þ¼¼Áö´Â "+reserve+"¹ÙÀÌÆ®°¡ ÃÊ°úµÇ¾ú½À´Ï´Ù.\r\n ÃÊ°úµÈ ºÎºÐÀº ÀÚµ¿À¸·Î »èÁ¦µË´Ï´Ù.");
		cutText();
		return false;
	}
	return true;

}

function cutText()
{
	nets_check( document.all.reply_contents.value);
}

function nets_check(aquery)
{

	var tmpStr;
	var temp=0;
	var onechar;
	var tcount;
	tcount = 0;

	tmpStr = new String(aquery);
	temp = tmpStr.length;

	for(k=0;k<temp;k++)
	{
		onechar = tmpStr.charAt(k);

		if(escape(onechar).length > 4)
		{
			tcount += 2;
		} else {
			// ¿£ÅÍ°ªÀÌ µé¾î¿ÔÀ»¶§ °ª(\r\n)ÀÌ µÎ¹ø½ÇÇàµÇ´Âµ¥ Ã¹¹øÂ° °ª(\n)ÀÌ µé¾î¿ÔÀ»¶§ tcount¸¦ Áõ°¡½ÃÅ°Áö ¾Ê´Â´Ù.
			if(escape(onechar)=='%0A') {
			} else {
				tcount++;
			}
		}

		if(tcount>180) {
			tmpStr = tmpStr.substring(0,k);
			break;
		}

	}
	document.all.reply_contents.value = tmpStr;
	cal_byte(tmpStr);
}

function askLogin(doneUrl, target){
	var loginConfirm = confirm('·Î±×ÀÎ ÇÏ½Ã°Ú½À´Ï±î?');
	if(loginConfirm == true){
		if(target == 'opener'){
			opener.location.href = doneUrl;
		}
		else{
			location.href = doneUrl;
		}
	}

}