function popImage(id, id1, id2, id3, str1, str2)
{
	//alert("popupwin/Editor_InsertImage.asp?tid="+id+"&boardid="+id1+"&chkurl="+id2+"&imgChk="+id3+"&str1="+str1+"&str2="+str2);
  showModalDialog(Editor_Root_Dir+"common/popupwin/Editor_InsertImage.asp?tid="+id+"&boardid="+id1+"&chkurl="+id2+"&imgChk="+id3+"&str1="+str1+"&str2="+str2, window, 'resizable: no; help: no; status: no; scroll: no;dialogWidth:340px;dialogHeight:320px');
/*		var dest = Editor_Root_Dir+"popupwin/img_popup.asp?grpcode="+id+"&nickname="+id1;
		var width = "698";
		var height = "590";
		oneshot = window.open(dest, "oneshot", "scrollbars=yes,toolbar=no,location=no,directories=no,width="+width+",height="+height+",resizable=no,mebar=no,left=250,top=65");
		oneshot.focus();*/

}


function removeAttach()
{
    var attachlist = document.getElementById("filePlus");
	var attachsize = document.getElementById("attachsizesum2");
    
    if (attachlist.selectedIndex <= 0)
        return;

   
    var s_data = attachlist.options[attachlist.selectedIndex].value;
	var array_data = s_data.split("+///+");  // split ÇÔ¼ö»ç¿ë..
	var s_file = array_data[0];   // Àß¶óÁø °ª ¹è¿­..
	var s_url = array_data[1];
	var s_length = array_data[2];
	var s_code = array_data[4];

	filelength = attachsize.value;
//	alert(filelength);
	attachsize.value = filelength - s_length;
	attachlist.remove(attachlist.selectedIndex);
	RemoveTagInEditor(  s_url+s_file);
	//GetResult( s_url, s_file, s_code);
}

function removeAttachFile()
{
    var attachlist = document.getElementById("selectfile");
    
    if (attachlist.selectedIndex <= 0)
        return;

	for(i=attachlist.length-1; i >= 1; i--)
	{
		if (attachlist.options[i].selected==true)
		{
			attachlist.options[i]=null;
		}
	}

	//attachlist.remove(attachlist.selectedIndex);
	//GetResult( s_url, s_file, s_code);
}

function AllselAttachFile(val)
{
    var attachlist = document.getElementById("selectfile");
    if (attachlist.length <= 1)
        return;

	if (val=="sel")
	{
		for(i=1;i<attachlist.length;i++)
		{
			attachlist.options[i].selected=true;
		}
	}
	else
	{
		for(i=1;i<attachlist.length;i++)
		{
			attachlist.options[i].selected=false;
		}
	}
	//GetResult( s_url, s_file, s_code);
}


function RemoveTagInEditor(src)
{

	src = src.toLowerCase();
//	alert(src);
	var Editor	=document.all['Editor__FORM_Content__EditorPad'];
	doc = Editor.contentWindow.document.body;
	el=doc.getElementsByTagName('IMG');

	for(i=0;i<el.length;i++)
	{
		var url = el[i].src.toLowerCase();
		var pattern = /http:\/\/[^/]*/
		url = url.replace(pattern,"");
		if ( url == src )
		{
			t = el[i];
			t.parentNode.removeChild(t);
		}
    }
}


function popFile(clubid)
{
  showModalDialog(Editor_Root_Dir+"common/popupwin/file_add.asp?strBoardID="+clubid, window, 'resizable: no; help: no; status: no; scroll: no;dialogWidth:340px;dialogHeight:250px');
}



// Common
function _getField(oField)
{
	if (typeof(oField.type) == 'undefined' && typeof(oField.length) != 'undefined')
		return oField[0];
	else
		return oField;
}

function _getFieldType(oField)
{
	return _getField(oField).type;
}

function _alertMessage(strMsg)
{
	if (typeof(strMsg) != 'undefined' && strMsg != "")
		alert(strMsg);
}

function _focusField(oField, blnFocus)
{
	if (typeof(blnFocus) != 'undefined' && blnFocus != null && blnFocus == true)
		_getField(oField).focus();
}

// FORM FIELD CHECK 1. NULL CHECK
function _hasValue(oField)
{
	if (oField.value.replace(/(^\s*)|(\s*$)/g, "") == "")
		return false;
	else
		return true;
}

function _hasEditerValue(oField)
{
	if (oField.value.replace(/&nbsp;/g, " ").replace(/(^\s*)|(\s*$)/g, "") == "")
		return false;
	else
		return true;
}

function _isChecked(oField)
{	
	var checked = false;

	if (typeof(oField.length) != 'undefined')
	{
		for (var i=0; i<oField.length; i++)
		{
			if (oField[i].checked)
				return true;
		}
	}
	else
	{
		return oField.checked;
	}
}

function _isNotSelected(oField)
{
	if (oField.selectedIndex == -1)
	{
		return false;
	}
	else
	{
		if (oField.value == -1)
			return false;
		else
			return true;
	}
}


function checkNull(oField, strMsg, blnFocus)
{
	var isNotNull = false;

	switch (_getField(oField).type)
	{
		case "text" :
		case "password" :
		case "file" :
			isNotNull = _hasValue(oField);
			break;
		case "textarea" :
			isNotNull = _hasEditerValue(oField);
			break;
		case "checkbox" :
		case "radio" :		
			isNotNull = _isChecked(oField);
			break;		
		case "select-one" :
		case "select-multiple" :
			isNotNull = _isNotSelected(oField);
			break;
	}

	if (!isNotNull)
	{
		_alertMessage(strMsg);
		_focusField(oField, blnFocus);
	}
	
	return isNotNull;
}




var MAX_MOVIE_COUNT = 1;	// ¾÷·Îµå °¡´ÉÇÑ µ¿¿µ»ó °³¼ö
function MovieUpload()
{
	var nMovieNum = document.frmWrite.movieno.value;

	if( nMovieNum < MAX_MOVIE_COUNT )
	{
		win = window.open('/movie/pup_picup.asp','pup_picup','width=448,height=640');
		win.focus();
	}
	else
	{
		alert( "µ¿¿µ»óÀº " + MAX_MOVIE_COUNT + "°³¸¸ ¾÷·Îµå °¡´ÉÇÕ´Ï´Ù." );
	}
}


function popFlv()
{

	var nMovieNum = document.frmWrite.movieno.value;

	var xMax = document.body.clientWidth, yMax = document.body.clientHeight;
	var xOffset = (xMax-200)/2-100, yOffset = (yMax-200)/2+50; 

	if( nMovieNum < MAX_MOVIE_COUNT )
	{
		win = window.open("/Movie/flvup.asp?xOffset="+xOffset+"&yOffset="+yOffset, "flvup", 'width=330,height=200, top='+yOffset+', left='+xOffset);
		win.focus();
	}
	else
	{
		alert( "µ¿¿µ»óÀº " + MAX_MOVIE_COUNT + "°³¸¸ ¾÷·Îµå °¡´ÉÇÕ´Ï´Ù." );
	}
	//window.open("/Movie/flvup.asp");
 
}


function setMovieInfo(movieFileName, movieURL, thumbURL, tag1, tag2, tag3)
{
	var nMovieNum = document.frmWrite.movieno.value;
//	alert("11");

	if( nMovieNum < MAX_MOVIE_COUNT )
	{
		nMovieNum++;
		
		document.frmWrite.movieno.value = nMovieNum;
		eval("document.frmWrite.movie_file"+nMovieNum).value = movieURL;
		eval("document.frmWrite.thumb_img" +nMovieNum).value = thumbURL;
		
		eval("document.frmWrite.scene_tag_"+nMovieNum+"1").value = tag1;
		eval("document.frmWrite.scene_tag_"+nMovieNum+"2").value = tag2;
		eval("document.frmWrite.scene_tag_"+nMovieNum+"3").value = tag3;

		szTag  = "";
		szTag += (trim(tag1) == "")  ?  ""  :  (szTag == "" ? "" : ",") + trim(tag1);
		szTag += (trim(tag2) == "")  ?  ""  :  (szTag == "" ? "" : ",") + trim(tag2);
		szTag += (trim(tag3) == "")  ?  ""  :  (szTag == "" ? "" : ",") + trim(tag3);

		document.frmWrite.keyword.value = (document.frmWrite.keyword.value == "" )  ?  szTag  :  document.frmWrite.keyword.value + "," + szTag;

		//alert(szTag);

		// ¾÷·Îµå µÈ µ¿¿µ»ó ¿øº» ÆÄÀÏ¸í º¸¿©ÁÖ±â
		var szMovieName = document.getElementById("td_movie_name").innerHTML;
		szMovieName += (szMovieName == "")  ?  movieFileName  :  "<br>" + movieFileName + szTag;
		document.getElementById("td_movie_name").innerHTML = szMovieName;
	}
	else
	{
		alert("µ¿¿µ»óÀº ÃÖ´ë1°³±îÁö ¾÷·Îµå °¡´ÉÇÕ´Ï´Ù.");
	}
}

function trim(str)
{
    var szTmp = new String(str);
    return szTmp.replace(/(^\s*)|(\s*$)/g, "");
}
