﻿// JScript 파일

//공백문자 체크
function Check(keyword) 
{
	var st_num, key_len;
	st_num = keyword.indexOf(" ");	
	while (st_num != -1)
	{
		keyword = keyword.replace(" ", "");
		st_num  = keyword.indexOf(" ");
	}
	key_len=keyword.length;
	return key_len;
}

//이미지검사
function CheckImage(obj){
    flag = false;
	
	mm = ['&','+','#','\'','\"'];
	var error_message = "파일 이름에 다음 문자가 올 수 없습니다.\n\n     ＆＋＃＇￦＼／：＊？＜＞＂｜"
	aa = mm.length;
    
	var ImageObj = obj.value;
	
		
	if (Check(ImageObj) > 4) {
		
		for(i=0;i<aa;i++) {
			a1 = ImageObj.indexOf(mm[i]);
			if(a1 >=0) {
			alert(error_message);
			return false;
			}
	  	}	
		
		if (ImageObj.substr(ImageObj.length-3,ImageObj.length).toUpperCase()!= "JPG"&&ImageObj.substr(ImageObj.length-3,ImageObj.length).toUpperCase()!= "GIF"&&ImageObj.substr(ImageObj.length-3,ImageObj.length).toUpperCase()!= "JPEG"){
			alert("JPG 또는 GIF 파일을 등록하세요");
           }
        else
		{
		  flag = true;
		}
	}
		return flag;
}	  

function onlynumber()
  {
     if((event.keyCode<48)||(event.keyCode>57))
     {
         event.returnValue=false;
     }
  }

/*
   포커스 이동
   arg : 개체 (this)
   len : 글자길이
   nextname : 이동할 개체명
*/
function nextfocus(arg,len,nextname){
if(arg.value.length == len){
nextname.focus();
}
}

// 이메일 유효성 검사		
function CheckEmail(strValue) 
{ 
   var flag = false;
   s = strValue;
   if (s.search(/^\s*[\w\~\-\.]+\@[\w\~\-]+(\.[\w\~\-]+)+\s*$/g)<0)
   { flag = true; }
	
   return flag;
} 

//파일타입검사 (찾아보기 버튼 클릭시 이벤트 작동)
function FileType(){
 flag = false;
 alert('선택한 파일은 '+ event.srcElement.value + '입니다.');

  if( !event.srcElement.value.match(/(.jpg|.jpeg|.gif|.png)/)) { 
      alert(' 이미지가 아닌것은 업로드 안됩니다.');
  }
   else
		{
		  flag = true;
		} 
}


//textarea박스 조절
function TextAreaSizeDown(obj) {
	obj.style.height = parseInt(obj.style.height) + 40;
}
		
function TextAreaSizeUp(obj) {
	if (parseInt(obj.style.height) > 60) {
		obj.style.height = parseInt(obj.style.height) - 40;
	}
}

//길이조절
function lenCheck(obj, maxLen){

	if(obj.value.length>(maxLen-1)){
	//	txtObj.readOnly=true;
//	txtObj.disabled=true;
    obj.value=obj.value.substring(0,maxLen-1);
	obj.focus();
	return false;
	}
}




//파일유효검사
function CheckPds(obj){
    flag = false;
	
	mm = ['&','+','#','\'','\"'];
	var error_message = "파일 이름에 다음 문자가 올 수 없습니다.\n\n     ＆＋＃＇￦＼／：＊？＜＞＂｜"
	aa = mm.length;
    
	var PdsObj = obj.value;
	
		
	if (Check(PdsObj) > 4) {
		
		for(i=0;i<aa;i++) {
			a1 = PdsObj.indexOf(mm[i]);
			if(a1 >=0) {
			alert(error_message);
			return false;
			}
	  	}	
		
		if (PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "TXT" && PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "ZIP" && PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "HWP" && PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "DOC" && PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "PPT" && PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "XLS" && PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "PDF" && PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "JPG" && PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "JPEG" && PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "GIF" && PdsObj.substr(PdsObj.length-3,PdsObj.length).toUpperCase()!= "WMV"){
			alert("정해진 파일을 등록하세요");
           }
        else
		{
		  flag = true;
		}
	}
		return flag;
}	  


function default_size(img){ 
  imageid= new Image(); 
  imageid.src=(img); 
  imageCT(img); 
} 

function imageCT(img){ 
  if((imageid.width!=0)&&(imageid.height!=0)){ 
    NewWinImg(img); 
  } 
  else{ 
    imgCT="imageCT('"+img+"')"; 
    intervalID=setTimeout(imgCT,0); 
  } 
} 

function NewWinImg(img){ 
        H=imageid.height; 
        W=imageid.width;        
        O="width="+W+",height="+H; 
        
        imgWin=window.open("","big", "scrollbars=yes,resizable=yes,"+O); 
        imgWin.document.write("<html><head></head>");
        imgWin.document.write("<body topmargin=0 leftmargin=0>");
        imgWin.document.write("<img src='"+img+"' onclick='self.close()'>");
        imgWin.document.write("</body></html>");
        } 

//엔터를 칠경우 넘어온 주소로 이동 (사용안함)
 function key_check(obj){
    var url = document.getElementById(obj).value; 
    if(event.keyCode==13 && url != "")
    {
        location.href= url;
    }
  }



// 팝업스크립트 (드림위버용)
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//글자바이트제한
function checkContentLength (objname, maxlength) {
var objstr = objname.value; // 입력된 문자열을 담을 변수 
 var objstrlen = objstr.length; // 전체길이 
 // 변수초기화 
 var maxlen = maxlength; // 제한할 글자수 최대크기 
 var i = 0; // for문에 사용 
 var bytesize = 0; // 바이트크기 
 var strlen = 0; // 입력된 문자열의 크기
 var onechar = ""; // char단위로 추출시 필요한 변수 
 var objstr2 = ""; // 허용된 글자수까지만 포함한 최종문자열

 // 입력된 문자열의 총바이트수 구하기
 for(i=0; i< objstrlen; i++) { 
  // 한글자추출 
  onechar = objstr.charAt(i); 
  
  if (escape(onechar).length > 4) { 
   bytesize += 2;     // 한글이면 2를 더한다. 
  } else {  
   bytesize++;      // 그밗의 경우는 1을 더한다.
  } 
  
  if(bytesize <= maxlen)  {   // 전체 크기가 maxlen를 넘지않으면 
   strlen = i + 1;     // 1씩 증가
  }
 }

 // 총바이트수가 허용된 문자열의 최대값을 초과하면 
 if(bytesize > maxlen) { 
  alert( "제목에서 허용된 문자열의 최대값을 초과했습니다. \n초과된 내용은 자동으로 삭제 됩니다."); 
  objstr2 = objstr.substr(0, strlen); 
  objname.value = objstr2; 
 } 
 objname.focus(); 
 
 document.getElementById("textlimit").innerText = bytesize; //바이트표시
}



//*** 부분 글자스타일 두껍게 하기
var old_sid = ""; //이전값 저장 변수
function textFontSizeCh(s)
  {
      var sid = document.getElementById(s);
      if(old_sid != "") //이전값이 있다면
      {
        old_sid.style.fontWeight = 'normal'; //이전값 디폴트
      }
      sid.style.fontWeight = 'bold'; // 현재 들어오는 부분 설정
      old_sid = sid; //현재값 이전값변수에 대입

  }


// iframe auto size
 function resizeIfr(obj, minHeight) {
	minHeight = minHeight || 10;

	try {
		var getHeightByElement = function(body) {
			var last = body.lastChild;
			try {
				while (last && last.nodeType != 1 || !last.offsetTop) last = last.previousSibling;
				return last.offsetTop+last.offsetHeight;
			} catch(e) {
				return 0;
			}
			
		}
				
		var doc = obj.contentDocument || obj.contentWindow.document;
		if (doc.location.href == 'about:blank') {
			obj.style.height = minHeight+'px';
			return;
		}
		
		//var h = Math.max(doc.body.scrollHeight,getHeightByElement(doc.body));
		//var h = doc.body.scrollHeight;
		if (/MSIE/.test(navigator.userAgent)) {
			var h = doc.body.scrollHeight;
		} else {
			var s = doc.body.appendChild(document.createElement('DIV'))
			s.style.clear = 'both';

			var h = s.offsetTop;
			s.parentNode.removeChild(s);
		}
		
		//if (/MSIE/.test(navigator.userAgent)) h += doc.body.offsetHeight - doc.body.clientHeight;
		if (h < minHeight) h = minHeight;
	
		obj.style.height = h + 'px';
		if (typeof resizeIfr.check == 'undefined') resizeIfr.check = 0;
		if (typeof obj._check == 'undefined') obj._check = 0;

//		if (obj._check < 5) {
//			obj._check++;
			setTimeout(function(){ resizeIfr(obj,minHeight) }, 200); // check 5 times for IE bug
//		} else {
			//obj._check = 0;
//		}	
	} catch (e) { 
		//alert(e);
	}
	
}

//좌측이미지변경
 function chLeftimg(obj,img)
 {
    obj.src = img
 }
