﻿/**
 *	API Community 파일 업로드 스크립트
 *	2007-10-31	장정연	최초작성
 */

// 09.04.07 seukim 
String.prototype.endWith = function(str) {
	return (this.match(str+"$")==str);
}

// 09.04.11 hudson
String.prototype.startWith = function(str) 
{return (this.match("^"+str)==str)}

function APIFileUpload() {	
	// 파일 업로드 완료 후, 부모창에 업로드 파일 넘기기
	this.SetUploadFileName = function (fileName) {
		if (fileName != null && fileName != "undefined") {
			window.returnValue = fileName;
		}
		window.close(); 
	}
	// 파일 Validation 체크
	this.UploadCheckValue = function (objFile) {
		if (objFile.value == "") {
			alert ("업로드 할 파일을 선택하세요");
			objFile.focus();
			return false;
		} else {
			// 09.04.07 seukim 
			var filename = objFile.value;
			if(filename.toLowerCase().endWith("zip") 
				|| filename.toLowerCase().endWith("jpg")
				|| filename.toLowerCase().endWith("gif") 
				//09.08.31 IE 확장자 파싱 취약점 대응 
				|| filename.indexOf(';') == -1)	
			{
				// alert("허용된 확장자입니다.");
				return true;	
			}
			else
			{
				alert("업로드가 허용되지 않은 파일입니다. zip, jpg, gif 파일만 가능합니다.");
				objFile.focus();
				return false;
			}		
		}
	}
	// 파일 업로드 창 팝업 띄우기(모달리스 팝업)
	this.OpenFileUpload = function (_apiUploadPage, _folder, _window) {
		document.domain = "auction.co.kr";
		
		var fileName = "";
		var uploadPage = _apiUploadPage + "?kind=" + _folder;
		
		if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 7.0") >= 0) {
			var fileName = window.showModalDialog(uploadPage,_window,"dialogWidth:400px; dialogHeight:260px;status:no;help:no");
		}else{
			var fileName = window.showModalDialog(uploadPage,_window,"dialogWidth:406px; dialogHeight:310px;status:no;help:no");
		}
		
		return (fileName != null && fileName != "undefined" && fileName != "") ? fileName : "";
	}
	// 파일 다운로드
	this.FileDownload = function (_downloadPage, _folder, _fileName) {
		_fileName = encodeURIComponent(_fileName);
		if (_downloadPage != "" && _fileName != "") location.href = _downloadPage + "?kind=" + _folder + "&name=" + _fileName;
	}
}