// JavaScript Document

function ShowFlash(url, width, height){
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + width + '" height="' + height + '" VIEWASTEXT>');
        document.write('<param name="movie" value="' + url + '">');
        document.write('<param name="quality" value="high">');
        document.write('<param name="wmode" value="transparent">');
        document.write('<embed src="' + url + '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>');
        document.write('</object>');
}

function ShowFlash2(url){
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width=100% height=100% VIEWASTEXT>');
        document.write('<param name="movie" value="' + url + '">');
        document.write('<param name="quality" value="high">');
        document.write('<param name="wmode" value="transparent">');
		document.write('<param name="menu" value="false">');
        document.write('<embed src="' + url + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width=100% height=100%></embed>');
        document.write('</object>');
}


function openWindow(url, name, width, height, scrollbars) {
    if (width < window.screen.width && height < window.screen.height){
        var windowX = Math.ceil( (window.screen.width  - width) / 2 );
        var windowY = Math.ceil( (window.screen.height - height) / 2 );
    }
   new_win =  window.open(url, name, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=no,status=no,width=' + width + ',height=' + height + ',scrollbars=' + scrollbars + ',left=' + windowX + ',top=' + windowY);
   new_win.opener = self;
}

// 새창띄우기
function winOpen(url,name,width,height,scrollbar){
	var top_pos = screen.height/2 - height/2;
	var left_pos = screen.width/2 - width/2;

	window.open(url,name,"width="+width+",height="+height+",top="+top_pos+",left="+left_pos+",scrollbars="+scrollbar+", status=no");
}

// --------------------------------------------------
// 입력폼 관련 스크립트
// --------------------------------------------------

// 입력항목 입력체크
function checkEmpty(obj,name,foc){
	var str = obj.value;
	if (str.length < 1)	{
		alert(name + " 항목을 입력하셔야 합니다.\n\n다시 입력하여 주십시요.");
			if(foc != "N") obj.focus();
			return false;
	}
	if (str.substring(0,1)==" " || str.substring(0,1)==null){
		alert(name + " 항목은 빈칸 혹은 공백으로 시작될 수 없습니다..\n\n다시 입력하여 주십시오");
			if(foc != "N") obj.focus();
			return false;
	}
	return true;
}

// 입력항목 최소 글자수 체크
function checkStr(obj,name,len){
	var str = obj.value;
	if (str.length < len)	{
		alert(name + " 항목은 " +len+ "자이상 입력하셔야 합니다.\n\n다시 입력하여 주십시요.");
			obj.focus();
				return false;
	}
	if (str.substring(0,1)==" " || str.substring(0,1)==null){
		alert(name + " 항목은 빈칸 혹은 공백으로 시작될 수 없습니다..\n\n다시 입력하여 주십시오");
			obj.focus();
				return false;
	}
	return true;
}

// 숫자만 입력가능
function onlyNumber(){
	if(event.keyCode<48||event.keyCode>57)
		event.returnValue=false;
}
// 숫자, '.'(소수점) 만 입력가능
function onlyNumber2(){
	if(event.keyCode != 46 && (event.keyCode < 48 || event.keyCode > 57))
		event.returnValue=false;
}
// 숫자, '-' 만 입력가능
function onlyNumber3(){
	if(event.keyCode != 45 && (event.keyCode < 48 || event.keyCode > 57))
		event.returnValue=false;
}
// 영문, 숫자만 입력가능
function onlyEngNum(){
	if((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 97 || event.keyCode > 122) && (event.keyCode < 65 || event.keyCode > 90))
		event.returnValue=false;
}
// 콤보박스 초기화
function removeCombo(obj){
	for(j=obj.length; j >= 0; j--){
		obj.options[j] = null;
	}
}
// 콤보박스 초기화2
function removeComboChild(obj){
	for(var i=obj.length-1; i>=0; i--){
		obj.removeChild(obj.options[i]);
	}
}

// --------------------------------------------------
// 날짜 관련 스크립트
// --------------------------------------------------

//콤보박스 - 년
function addYear(obj,sYear,lYear,val){
	var y = 0;
	now = new Date();
	if(!sYear) sYear = now.getFullYear()-1;
	if(!lYear) lYear = now.getFullYear()+1;
	if(!val) val = now.getFullYear();

	sYear = parseFloat(sYear);
	lYear = parseFloat(lYear);
	val = parseFloat(val);

	for (i=sYear ; i < lYear+1; i++)  {
		var optiontmp = new Option(i+ "년",i);
		obj.options[y] = optiontmp;
		if(i == val){obj.options[y].selected = true;}
		y++;
	}
}

//콤보박스 - 월
function addMonth(obj,val){
	now = new Date();
	if(!val) val = now.getMonth()+1;
	val = parseFloat(val);

	if(val.length == 1){val = "0" + val;}
	for (i=1 ; i < 13; i++)  {
		if(i<10){i="0"+i;}
		var optiontmp = new Option(i+ "월",i);
		obj.options[i-1] = optiontmp;
		if(i == val){obj.options[i-1].selected = true;}
	}
}

// 콤보박스 - 일
function addDay(obj,yObj,mObj,val){
	now = new Date();
	if(val == 0) val = now.getDate();
	val = parseFloat(val);

	var d = obj.length;;
	for (i=d ; i >= 0; i--)  {
		obj.options[i] = null;
	}

	switch (parseFloat(mObj.value)){
		case 4 : d = 30; break;
		case 6 : d = 30; break;
		case 9 : d = 30; break;
		case 11 : d = 30; break;
		case 2 : d = 28; break;
		default : d = 31;
	}
	if(yObj.value % 4 == 0 && mObj.value == 2){
		d = 29;
	}

	for (i=1 ; i < d+1; i++)  {
		if(i<10){i = "0" + i;}
		var optiontmp = new Option(i+ "일",i);
		obj.options[i-1] = optiontmp;
	   if(i == val){obj.options[i-1].selected = true;}
	}
}

// 콤보박스 시간
function addHour(obj,val){
	var form = document.theForm;
	now = new Date();
//	if(val == 0) val = now.getHours();
	if(val == "") val = now.getHours();

	for (i=0 ; i < 24; i++)  {
		if(i<10){i="0"+i;}
		var optiontmp = new Option(i+"시",i);
		obj.options[i] = optiontmp;
		if(i==parseFloat(val)){obj.options[i].selected = true;}
	}
}

// 콤보박스 분
function addMinute(obj,val){
	var form = document.theForm;
	now = new Date();
//	if(val == 0) val = now.getMinutes();
	if(val == "") val = now.getMinutes();

	var j = 0;
//	for (i=00 ; i < 59; i+=5)  {
	for (i=00 ; i < 60; i++)  {
		if(i<10){i=String("0")+i;}
		var optiontmp = new Option(i+"분",i);
		obj.options[j] = optiontmp;
		if(i==parseFloat(val)){obj.options[j].selected = true;}
		j ++;
		i = parseFloat(i)
	}
}

function chkExtMedia(val, fname){
	var Arr_filename = val.value.split("\\");
	var filename = Arr_filename[Arr_filename.length-1];
/*
	for(i=0;i<filename.length;i++){
		if(filename.substr(i,1) == " "){
			alert(fname+"의 파일명에 공백이 존재할 수 없습니다.");
			return false;
		}
	}
*/
	if(val.value.indexOf(".") > -1){
		var Arr_ext = val.value.split(".");
		var ext = Arr_ext[Arr_ext.length-1].toLowerCase();
		if(ext != "wmv" && ext != "avi" && ext != "mpg" && ext != "asf" && ext != "jpg" && ext != "bmp" && ext != "gif"){
			alert(fname+" 항목은 wmv, avi, mpg, asf, jpg, bmp, gif 파일형식 외에는 업로드 할 수 없습니다");
			return false;	
		}
//		if(checkFileKor(val, fname)==false){return false};
		if(chkAttachLen(val, fname)==false){return false};
	}
}

//첨부파일 파일명 길이 체크
function chkAttachLen(val, fname){
	if(val.value.length){
		var Arr_file = val.value.split("\\");
		var filename = Arr_file[Arr_file.length-1];
		if(getStringSize(filename) > 50){
			alert(fname+" 항목은 파일명은 한글25자, 영문50자(공백포함) 이내로 하셔야 합니다.\n\n파일명을 확인하십시요.");
		return false;	
		}
	}
}

//문자열 바이트 계산
function getStringSize(str){
        var size = 0;

        for(var i = 0; i < str.length; i++){
                if(str.charCodeAt(i) > 255)                // 한글이면
                        size += 2;
                else if(str.charCodeAt(i) != 13)
                        size++;
        }
        return size;
}
// --------------------------------------------------
// 게시판 관련 스크립트
// --------------------------------------------------

// 검색시 검색어 체크
function sendSearch(){
	var form = document.searchForm;
	if(checkEmpty(form.key,"검색어")==false){return false;}
	form.submit();
}



// --------------------------------------------------
// 
// --------------------------------------------------

//첨부파일 이미지 확장자 체크
function chkExtImg(val, fname){
	if(val.value.indexOf(".") > -1){
		var Arr_ext = val.value.split(".");
		var ext = Arr_ext[Arr_ext.length-1].toLowerCase();
		if(ext != "jpg" && ext != "gif" && ext != "bmp"){
			alert(fname+" 항목은 jpg, gif, bmp 파일형식 외에는 업로드 할 수 없습니다");
			return false;	
		}
		if(chkAttachLen(val, fname)==false){return false};
	}
}

//첨부파일 파일명 길이 체크
function chkAttachLen(val, fname){
	if(val.value.length){
		var Arr_file = val.value.split("\\");
		var filename = Arr_file[Arr_file.length-1];
		if(getStringSize(filename) > 50){
			alert(fname+" 항목은 파일명은 한글25자, 영문50자(공백포함) 이내로 하셔야 합니다.\n\n파일명을 확인하십시요.");
		return false;	
		}
	}
}


//쿠키반환
function getcookie(Name) {
  var search = Name + "="
  if (document.cookie.length > 0) { // 쿠키가 설정되어 있다면
    offset = document.cookie.indexOf(search)
    if (offset != -1) { 
      offset += search.length
      end = document.cookie.indexOf(";", offset)
  
      if (end == -1)
        end = document.cookie.length
      return unescape(document.cookie.substring(offset, end))
    }
  }
  return "";
}
