function CheckSearchArticle(theForm) {
	if (Len(theForm.search_value.value) == 0) {
		alert('Fill in the search word.');
		theForm.search_value.focus();
		return false;
	}

	return true;
}

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 >= 8) {
		alert('Until the maximum 8 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 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 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, RelatedContentList.options[i].value, true);

		document.getElementById("related_content_list_1").options[i] = option;
		document.getElementById("related_content_list_1").options[i].selected = 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("topic")) {
		if (Len(document.getElementById("topic").value) == 0) {
			alert('Fill in the group title.');
			document.getElementById("topic").focus();
			return;
		}
	}

	if (document.getElementById("group_topic")) {
		if (Len(document.getElementById("group_topic").value) == 0) {
			alert('Fill in the title.');
			document.getElementById("group_topic").focus();
			return;
		}
	}

	if (document.getElementById("delete_image") && Len(document.getElementById("image_path").value) > 0) {
		document.getElementById("delete_image").checked = true;
	}

	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;
	}

	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 SearchRelatedContent(CatSeq, ContentSeq) {
	internal_content_search = window.open('/_admin/search/internal_content_search.asp?cat_seq=' + CatSeq +'&content_seq=' + ContentSeq, 'internal_content_search', 'left=' + (screen.availWidth - 600) / 2  + ',top=' + (screen.availHeight - 605) / 2 + ',width=600,height=605,scrollbars=no');
	internal_content_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;
}

function GoPage(ArticleID, ArticleGroup) {
	top.location.href='./read.asp?article_seq=' + ArticleID + '&article_group=' + ArticleGroup;
}