///// 클래스 - 첨부파일 업로드 /////
cs_upload=function()
{
	/*
	//	+ 예제 :
	//				// 클래스를 시작함
	//				upload=new cs_upload;
	//
	//				// 첨부파일 업로드가능 갯수 (0 이면 제한없음)
	//				upload.upload_max=0;
	//
	//				// 미리 띄워둘 첨부파일 업로드폼 갯수 (업로드된 첨부파일의 갯수가 더 많으면 작동하지 않음)
	//				upload.upload_view=3;
	//
	//				// 현재 업로드되어 있는 첨부파일 갯수 (기본값으로 0 을 입력해야함)
	//				upload.upload_comp=0;
	//
	//				// 현재 출력되어 있는 첨부파일 갯수 (기본값으로 0 을 입력해야함)
	//				upload.upload_now=0;
	//
	//				// 첨부파일 폼이 포함된 폼명
	//				upload.form_name="document.all";
	//
	//				// 첨부파일 폼을 편집할 테이블명
	//				upload.table_name="table_upload";
	//
	//				// 첨부파일 폼 이름
	//				upload.fileform_name="input_file";
	//
	//				// 첨부파일 폼 스타일
	//				upload.fileform_style="style='width:100%;' class='default'";
	//	+ 결과 :
	//				첨부파일 폼을 늘리거나 줄임 (화면에 바로 적용됨)
	//	+ 참고 :
	//				주로 단독으로는 쓰이지 않고 PHP 나 ASP 안에 불러와서 사용됨
	*/

	// 첨부파일 폼이 포함된 폼명
	var form_name;

	// 첨부파일 폼을 편집할 테이블명
	var table_name;

	// 첨부파일 폼 이름
	var fileform_name;

	// 첨부파일 폼 스타일
	var fileform_style;

	// 첨부파일 업로드가능 갯수 (0 이면 제한없음)
	var upload_max;

	// 미리 띄워둘 첨부파일 업로드폼 갯수 (이미 업로드된 파일의 갯수가 더 많으면 작동하지 않음)
	var upload_view;

	// 현재 업로드되어 있는 첨부파일 갯수 (최대 업로드가능갯수보다 많을때도 업로드된 첨부파일은 제한없이 출력되야함. 기본값으로 0 을 입력해야함)
	var upload_comp;

	// 현재 출력되어 있는 첨부파일 갯수 (기본값으로 0 을 입력해야함)
	var upload_now;



	///// 첨부파일 갯수를 늘리고 줄임 /////
	this.upload_setup=function(fm, type, filelink)
	{
		/*
		//	+ 인수 :
		//				fm : 폼명
		//				type : 첨부파일 폼 갯수를 늘릴건지 줄일건지를 지정. up:폼갯수늘림, dn:폼갯수줄임
		//				filelink : 해당 첨부파일 순번에 실제로 첨부파일이 존재한다면 첨부파일 정보 및 삭제링크를 출력함 (첨부파일 폼 아래에 출력됨)
		//	+ 예제 :
		//				onclick="클래스이름.upload_setup(document.all, 'up');"
		//				onclick="클래스이름.upload_setup(document.all, 'dn');"
		//				onclick="클래스이름.upload_setup(document.all, 'up', '업로드된 파일명 : $filename');"
		*/

		// 첨부파일을 편집할 테이블을 지정함
		obj_table=document.getElementById(this.table_name);

		switch(type)
		{
			// 첨부파일 갯수 늘리기 (최대 첨부파일 폼갯수보다 업로드된 첨부파일이 더 많다면 최대값은 업로드된 첨부파일 폼갯수로 지정됨)
			case "up" :
				if(parseInt(this.upload_now)>=parseInt(this.upload_max) && this.upload_max)
				{
					if(parseInt(this.upload_now)>=parseInt(this.upload_comp))
					{
						alert("더 이상 첨부파일을 늘릴 수 없습니다.");
						return false;
					}
				}

				// 지정된 테이블에 한줄/한칸을 생성하여 첨부파일 폼을 추가함
				obj_row=obj_table.insertRow(obj_table.rows.length);
				obj_cell=obj_row.insertCell(0);
				if(filelink)
				{
					obj_cell.innerHTML="<input type='file' name='"+this.fileform_name+"[]' "+this.fileform_style+">"+filelink;
				}
				else
				{
					obj_cell.innerHTML="<input type='file' name='"+this.fileform_name+"[]' "+this.fileform_style+">";
				}
				this.upload_now++;
				break;

			// 첨부파일 줄이기
			case "dn" :
				if(parseInt(this.upload_now)<=parseInt(this.upload_comp) || parseInt(this.upload_now)<=0)
				{
					alert("더 이상 줄일 첨부파일이 없습니다.");
					return false;
				}

				// 지정된 테이블에 한줄을 삭제함
				obj_table.deleteRow(obj_table.rows.length-1);
				this.upload_now--;
				break;
		}
	}



	///// 첨부파일 목록을 출력함 (다운로드하기 위함) /////
	this.download_setup=function(fm, filelink)
	{
		/*
		//	+ 인수 :
		//				fm : 폼명
		//				filelink : 해당 첨부파일 순번에 실제로 첨부파일이 존재한다면 첨부파일 정보 및 삭제링크를 출력함 (첨부파일 폼 아래에 출력됨)
		//	+ 예제 :
		//				onclick="클래스이름.download_setup(document.all, '업로드된 파일명 : $filename');"
		*/

		// 첨부파일을 편집할 테이블을 지정함
		obj_table=document.getElementById(this.table_name);

		// 지정된 테이블에 한줄/한칸을 생성하여 첨부파일 폼을 추가함
		obj_row=obj_table.insertRow(obj_table.rows.length);
		obj_cell=obj_row.insertCell(0);
		obj_cell.innerHTML=filelink;
	}



	///// 첨부파일을 다운로드함 /////
	this.download=function(upload_path, oldfilename, newfilename)
	{
		/*
		//	+ 인수 :
		//				upload_path : 첨부파일 디렉토리명
		//				oldfilename : 원본첨부파일명
		//				newfilename : 실제첨부파일명
		//	+ 예제 :
		//				onclick="클래스이름.download('첨부파일디렉토리명', '원본첨부파일명', '실제첨부파일명');"
		*/

		parent.iframe_download.location.replace("./download.php?upload_path="+upload_path+"&oldfilename="+oldfilename+"&newfilename="+newfilename);
	}



	///// 첨부파일을 삭제함 /////
	this.upload_delete=function(fm, fileform, value1)
	{
		/*
		//	+ 인수 :
		//				fm : 폼명
		//				fileform : 첨부파일 폼명
		//				value1 : 첨부파일 번호
		//	+ 예제 :
		//				onclick="클래스이름.upload_delete(document.all, 'input_file', '1');"
		*/

		qna=confirm("첨부파일을 삭제하시겠습니까?\n\n※ 삭제한 첨부파일은 복구할 수 없습니다.");
		if(qna)
		{
			fm.selectfileform.value=fileform;
			fm.selectobj.value=value1;
			fm.submit_type.value="delete_upload";
			fm.submit();
		}
	}
}
