function GoPage(ArticleID, ArticleGroup) {
	top.location.href='./read.asp?article_seq=' + ArticleID + '&article_group=' + ArticleGroup;
}

function CheckSearchArticle(theForm) {
	if (Len(theForm.search_value.value) == 0) {
		alert('Fill in the search word.');
		theForm.search_value.focus();
		return false;
	}

	return true;
}

function ToggleDelAll(theForm, theID) {
	if (eval('theForm.' + theID).length) {
		for (var i, i = 0; i < eval('theForm.' + theID).length; i++) {
			eval('theForm.' + theID)[i].checked = eval('theForm.' + theID + '_all').checked;
		}
	} else {
		if (eval('theForm.' + theID).checked) {
			eval('theForm.' + theID).checked = eval('theForm.' + theID + '_all').checked;
		} else {
			eval('theForm.' + theID).checked = eval('theForm.' + theID + '_all').checked;
		}
	}
}

function DeleteBatch(theForm, theID) {
	if (eval('theForm.' + theID).length) {
		for (var i, i = 0; i < eval('theForm.' + theID).length; i++) {
			if (eval('theForm.' + theID + '[i]').checked) break;
		}
		if (i == eval('theForm.' + theID).length) {
			alert('To select the article which it will eliminate');
			return false;
		}

		if (confirm('Under eliminating route it wishes the article?')) {
			return true;
		}
		else {
			return false;
		}
	} else {
		if (eval('theForm.' + theID).checked) {
			if (confirm('Under eliminating route it wishes the article?')) {
				return true;
			}
			else {
				return false;
			}
		} else {
			alert('To select the article which it will eliminate');
			return false;
		}
	}
}

var blnUploading = false;
var blnDeleting = false;

function AttachFile() {
	var strFilePath = 'File attaching...';
	var intFileCnt = document.getElementById("file_list").length;

	if (Len(document.getElementById("file_path").value) == 0) {
		alert('To select the file which it will attach.');
		return;
	}

	if (blnUploading) {
		alert('File attaching.');
		return;
	}

	if (blnDeleting) {
		alert('File attaching.');
		return;
	}

	if (intFileCnt >= 5) {
		alert('Until the maximum 5 it is possible');
		return;
	}

	blnUploading = true;

	var nIndex = strFilePath.lastIndexOf('\\');
	if (nIndex > 0)	strFilePath = strFilePath.substr(nIndex + 1);

	var option = new Option(strFilePath, strFilePath, true);
	document.frm_attach_file.file_list.options[intFileCnt] = option;
	
	document.frm_attach_file.submit();
}

function UploadComplete(FilePath, FileName) {
	var intFileCnt = document.getElementById("file_list").length;
	blnUploading = false;

	var nListIndex = intFileCnt - 1;
	document.getElementById("file_list").options[nListIndex].value = FilePath;
	document.getElementById("file_list").options[nListIndex].text = FileName;
}

function UploadCancel() {
	var intFileCnt = document.getElementById("file_list").length;
	blnUploading = false;
	
	var nListIndex = intFileCnt - 1;
	document.getElementById("file_list").options[nListIndex] = null;

	parent.ifrm_area.location.href = "about:blank";	
}

function DeleteFile() {
	var FileList = document.getElementById("file_list");

	if (blnUploading) {
		alert('File attaching.');
		return;
	}
	if (blnDeleting) {
		alert('File eliminating.');
		return;
	}
	
	if (FileList.length == 0) {
		alert('There is no file.');
		return;
	}
	
	if (FileList.selectedIndex < 0 || FileList.selectedIndex == null) {
		alert('To select the file which it will eliminate.');
		return;
	}
	
	blnDeleting = true;

	FileList.options[FileList.selectedIndex].text = FileList.options[FileList.selectedIndex].text + ' File remove...';

	var nIndex, strFilePath, strFileName;

	strFilePath = FileList.options[FileList.selectedIndex].value;
	nIndex = strFilePath.lastIndexOf('/');
	strFileName = strFilePath.substr(nIndex + 1);
	strFilePath = strFilePath.substr(0, nIndex);

	if (strFilePath.toLowerCase( ).indexOf('/pds/temp') >= 0) {
		document.frm_delete_file.delete_file_index.value = FileList.selectedIndex;
		document.frm_delete_file.delete_file_path.value = FileList.options[FileList.selectedIndex].value;
		
		document.frm_delete_file.submit();
	} else {
		if (Len(document.getElementById("delete_file_list").value) > 0) document.getElementById("delete_file_list").value = document.getElementById("delete_file_list").value + ',';
		document.getElementById("delete_file_list").value = document.getElementById("delete_file_list").value + FileList.options[FileList.selectedIndex].value;
		
		DeleteComplete(FileList.selectedIndex);
	}
}

function DeleteComplete(ListIndex) {
	blnDeleting = false;
	
	document.getElementById("file_list").options[ListIndex] = null;
}

function DeleteCancel() {
	blnDeleting = false;
	
	var FileList = document.getElementById("file_list");

	var strFilePath = FileList.options[FileList.selectedIndex].value;
	var nIndex = strFilePath.lastIndexOf('/');
	var strFileName = strFilePath.substr(nIndex + 1);

	FileList.options[FileList.selectedIndex].text = strFileName;
}

function KeyDeleteFile() {
	if (window.event.keyCode == 46) DeleteFile();
}

function SetImageInfo() {
	for (var i, i = document.getElementById("img_list_1").length - 1; i >= 0; i--)
		document.getElementById("img_list_1").options[i] = null;

	for (var i, i = document.getElementById("img_list_2").length - 1; i >= 0; i--)
		document.getElementById("img_list_2").options[i] = null;
	
	var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

	parent.ifrm_area.document.open();
	parent.ifrm_area.document.write(document.getElementById("org_content").innerHTML);
	parent.ifrm_area.document.close();

	if (parent.ifrm_area.document.getElementsByTagName("img").length) {
		var intImgIndex = parent.ifrm_area.document.getElementsByTagName("img").length

		for (var i, i = 0; i < intImgIndex; i++) {
			var option = new Option(parent.ifrm_area.document.getElementsByTagName("img")[i].src, parent.ifrm_area.document.getElementsByTagName("img")[i].src, true);
			document.getElementById("img_list_1").options[i] = option;
			document.getElementById("img_list_1").options[i].selected = true;
		}
	}

	parent.ifrm_area.document.open();
	parent.ifrm_area.document.write(oEditor.GetXHTML());
	parent.ifrm_area.document.close();

	if (parent.ifrm_area.document.getElementsByTagName("img").length) {
		var intImgIndex = parent.ifrm_area.document.getElementsByTagName("img").length

		for (var i, i = 0; i < intImgIndex; i++) {
			var option = new Option(parent.ifrm_area.document.getElementsByTagName("img")[i].src, parent.ifrm_area.document.getElementsByTagName("img")[i].src, true);
			document.getElementById("img_list_2").options[i] = option;
			document.getElementById("img_list_2").options[i].selected = true;
		}
	}
}

function SetFileInfo () {
	for (var i, i = 0; i < document.getElementById("file_list").length; i++) {
		var option = new Option(document.getElementById("file_list").options[i].text, document.getElementById("file_list").options[i].value, true);

		document.getElementById("file_list_1").options[i] = option;
		document.getElementById("file_list_1").options[i].selected = true;
	}
}

function CheckComment() {
	if (Len(document.getElementById("topic").value) == 0) {
		alert('Fill in the subject.');
		document.getElementById("topic").focus();
		return false;
	}

	if (Len(document.getElementById("mesg").value) == 0) {
		alert('Fill in the message.');
		document.getElementById("mesg").focus();
		return false;
	}
	return true;
}

function CheckForm() {
	if (document.getElementById("writer_name")) {
		if (Len(document.getElementById("writer_name").value) == 0) {
			alert('Fill in the writer name.');
			document.getElementById("writer_name").focus();
			return;
		}
	}

	if (document.getElementById("email")) {
		if (Len(document.getElementById("email").value) == 0) {
			alert('Fill in the e-mail.');
			document.getElementById("email").focus();
			return;
		}
	}

	if (document.getElementById("news_source")) {
		if (Len(document.getElementById("news_source").value) == 0) {
			alert('Fill in the news source.');
			document.getElementById("news_source").focus();
			return;
		}
	}

	if (document.getElementById("news_mm") && document.getElementById("news_mm") && document.getElementById("news_mm")) {
		if (Len(document.getElementById("news_mm").value) == 0) {
			alert('Please input your News Date');
			document.getElementById("news_mm").focus();
			return false;
		}

		if (Len(document.getElementById("news_dd").value) == 0) {
			alert('Please input your News Date');
			document.getElementById("news_dd").focus();
			return false;
		}

		if (Len(document.getElementById("news_yy").value) == 0) {
			alert('Please input your Newsdate');
			document.getElementById("news_yy").focus();
			return false;
		}

		var news_yy = document.getElementById("news_yy").value;
		var news_mm = document.getElementById("news_mm").value;
		var news_dd = document.getElementById("news_dd").value;
		
		
		if (news_dd.substring(0, 1) == 0) {
			news_dd = news_dd.substring(1, 2);
		}

		if (!CheckNum(news_dd)) {
			alert('Input with only number.');
			document.getElementById("news_dd").focus();
			return false;
		}

		if (!CheckNum(news_yy)) {
			alert('Input with only number.');
			document.getElementById("news_yy").focus();
			return false;
		}
	}

	if (document.getElementById("topic")) {
		if (Len(document.getElementById("topic").value) == 0) {
			alert('Fill in the subject.');
			document.getElementById("topic").focus();
			return;
		}
	}

	if (document.getElementById("temple_seq")) {
		if (Len(document.getElementById("temple_seq").value) == 0) {
			alert('Fill in the Temple Name');
			document.getElementById("temple_name").focus();
			return;
		}
	}

	if (document.getElementById("pass_wd")) {
		if (Len(document.getElementById("pass_wd").value) == 0) {
			alert('Fill in the password.');
			document.getElementById("pass_wd").focus();
			return;
		}
	}

	var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

	if (Len(oEditor.GetXHTML()) == 0) {
		alert('Fill in the content.');
		return;
	}

	SetImageInfo();
	if (document.getElementById("frm_attach_file")) {
		SetFileInfo();
	}

	if (document.getElementById("related_content_info")) {
		SetRelatedContentInfo();
	}
	document.frm_article_info.submit();
}

function CheckDelete() {
	if (document.getElementById("pass_wd")) {
		if (Len(document.getElementById("pass_wd").value) == 0) {
			alert('Fill in the password.');
			document.getElementById("pass_wd").focus();
			return false;
		}
	}
}

function SetRelatedContentInfo () {
	var RelatedContentList = document.getElementById("related_content_list");

	for (var i, i = 0; i < RelatedContentList.length; i++) {
		var option = new Option(RelatedContentList.options[i].text.replace(",", "&#44;"), RelatedContentList.options[i].value.replace(",", "&#44;"), true);

		document.getElementById("related_content_list_1").options[i] = option;
		document.getElementById("related_content_list_1").options[i].selected = true;
	}
}

function SearchRelatedContent(BookSeq) {
	internal_content_search = window.open('/_admin/search/internal_content_search.asp?book_seq=' + BookSeq, 'internal_content_search', 'left=' + (screen.availWidth - 600) / 2  + ',top=' + (screen.availHeight - 605) / 2 + ',width=600,height=605,scrollbars=no');
	internal_content_search.focus();
}

function SearchTemple() {
	temple_search = window.open('/common/temple_board/search_temple.asp', 'temple_search', 'left=' + (screen.availWidth - 620) / 2  + ',top=' + (screen.availHeight - 605) / 2 + ',width=620,height=605,scrollbars=1');
	temple_search.focus();
}

function CreateRelation(related_seq, topic) {
	var RelatedContentList = document.getElementById("related_content_list");

	for (var i, i = 0; i < RelatedContentList.length; i++) {
		if (RelatedContentList.options[i].value == related_seq) {
			alert('It is being register already');
			return;
		}
	}

	var intRelatedContentCnt = RelatedContentList.length;
	var option = new Option(topic, related_seq, true);
	RelatedContentList.options[intRelatedContentCnt] = option;
}

function DeleteRelation() {
var RelatedContentList = document.getElementById("related_content_list");

	if (RelatedContentList.length == 0) {
		alert('There is no content.');
		return;
	}
	
	if (RelatedContentList.selectedIndex < 0 || RelatedContentList.selectedIndex == null) {
		alert('To select the article which it will eliminate.');
		return;
	}

	RelatedContentList.options[RelatedContentList.selectedIndex] = null;
}