/**
 * cms페이지 로그아웃
 * @return void
 */
function logout(){
  document.location.href = "../cms/logout.jsp";
}



/**
 * depth1메뉴 포커스변경시 이미지교체
 * @param obj
 * @return
 */
function changeTopMenu( position ){
  var topMenuImages = document.getElementById('topmenulist').getElementsByTagName("img");
  for( var i = 0; i < topMenuImages.length; i++ ){
      topMenuImages[i].src = ( i == position )?topMenuImages[i].src.replace('_off', '_on')
                                      :topMenuImages[i].src.replace('_on', '_off');
  }
}



/**
 * depth2메뉴에 마우스오버시 스타일변경
 * @param position
 * @return
 */
function changeSubmenu( position ){
  var subMenuLists = document.getElementById('submenulist').getElementsByTagName("li");
  for( var i = 0; i < subMenuLists.length; i++ ){
    subMenuLists[i].className = ( i == position )?'menuOn':'menuOff';
  }
}



/**
 * 관리자메뉴수정(editAdminMenu.jsp)페이지의 하위링크 추가
 * @param liId
 * @return
 */
function addSubMenu(){
  var root = document.getElementById('subitemlist');
  var items = root.getElementsByTagName('li');
  
  var maxrow = 0;
  for( var i = 0; i < items.length; i++ ){
    maxrow = ( maxrow < ( (items[i].getAttribute('rowid') == null)?0:items[i].getAttribute('rowid') )
               ?    items[i].getAttribute('rowid') : maxrow );
  }
  if( maxrow == 0 && items.length == 1 ){
    root.removeChild(items[0]);
  }else{
    maxrow += 1;
  }
  var li = document.createElement('li');
  li.setAttribute('rowid', maxrow);
  var tempArray = new Array();
  tempArray.push('<label style="cursor:move;">메뉴명: <input type="text" name="menuname" class="txt" /></label>\n');
  tempArray.push('<label>링크: <input type="text" name="menulink" class="txt" size="50" /></label>\n');
  tempArray.push('<a href="#" onclick="deleteSubMenu(\''+maxrow+'\');return false;" class="btnType2 btnType2Style"><span class="btnType2SpanStyle">삭제</span></a>');
  tempArray.push(' <a href=\"#\" onclick="moveSubMenu(this, \'up\'); return false;" class="btnType2 btnType2Style"><span class="btnType2SpanStyle">위로</span></a>');
  tempArray.push(' <a href=\"#\" onclick="moveSubMenu(this, \'down\'); return false;" class="btnType2 btnType2Style"><span class="btnType2SpanStyle">아래로</span></a>');

  li.innerHTML = tempArray.join('');
  root.appendChild(li);

}



/**
 * 관리자메뉴수정(editAdminMenu.jsp)페이지의 하위링크 삭제
 * @param liId
 * @return
 */
function deleteSubMenu( liId ){
  if( confirm('선택하신 하위메뉴를 삭제하시겠습니까?') ){
    var root = document.getElementById('subitemlist');
    var items = root.getElementsByTagName('li');
    for( var i = 0; i < items.length; i++ ){
      if( items[i].getAttribute('rowid') == liId ){
        root.removeChild(items[i]);
      }
    }
  }
}




/**
 * editAdminMenu.jsp 하위메뉴의 순서변경함수
 * @param obj anchor태그개체
 * @param direction 방향('up' or '아무거나')
 * @return
 */
function moveSubMenu( obj, direction ){
  var parentLi = obj.parentNode;
  var root = parentLi.parentNode;
  var liList = root.getElementsByTagName('li');
  var prevLinumber = 0;
  var replacedNode;
  
  for( var i = 0; i < liList.length; i++ ){
    
    if( ( parentLi == liList[i] ) ){
      
      if( direction == 'up' ){
        root.insertBefore( parentLi, liList[prevLinumber] );
      }else if( i < (liList.length - 1) ){
        replacedNode = root.replaceChild( parentLi, liList[i + 1] );
        root.insertBefore( replacedNode, parentLi );
        i++;
      }
      
    }
    
    prevLinumber = i;
    
  }
  
}



/**
 * 달력 보여주는 함수
 * @param target
 * @param frame
 * @param e
 * @return
 */
function showCalendar(target, frame, e){
  var event = window.event || e;
  var x = event.pageX || event.clientX + document.body.scrollLeft;
  var y = event.pageY || event.clientY + document.body.scrollTop;
  document.getElementById(frame).style.left = x + 'px';
  document.getElementById(frame).style.top = y + 'px';
  document.getElementById(frame).src = "../../djemals/calendar/calendarFrame.jsp?targetId="+target+"&frameId="+frame;
  document.getElementById(frame).style.display = "inline";
}




/**
 * <script>fncCalendarImg('inputid');</script>
 * 달력 이미지보여주는 함수
 * @param e
 * @return
 */
function fncCalendarImg(type){
  document.write("<img src=\"../files/images/common/icon_calendar.gif\" align=\"absmiddle\" onclick=\"showCalendar('"+type+"','calendarframe', event);\" style=\"cursor:pointer;margin-right:5px;\">");
}



/**
 * 게시판관리분류입력
 * @author 김지은
 * @param 분류텍스트객체
 * @param 분류select객체
 * @param text
 * @return 
 */
function addItem(obj1, obj2, text) {
  if( obj1.value.replace(/\s/g, '')=="" ) {
    alert("입력할 "+text+"를 입력하세요");
    obj1.focus();
    return;
  }
  
  var sOption = document.createElement("OPTION");
/*
  if ( objectid != "" ) {
	  $.post("itemProcess.jsp",        //ajax 로 페이지 부르기 
	        { 'itemFieldName':obj1.value, 'mode':"insertItemProcess", 'groupID':groupid, 'objectID':objectid },  // 선택된 것 Array로 넘기기
	        function(data) {            // Callback 함수
		        aData = data.split("|");
		        len = aData.length ;
		        for (i=0;i<len;i++) {
		          if ( i == 0 ) {
		            sOption.value=aData[0];
		          } else if ( i == 1 ) {
		            alert(aData[1]);
		          }
		        }
	        }, 
	        "text");
  } else {
    sOption.value=" ";
  }
  */
  sOption.value="";
  sOption.text=obj1.value;
  obj2.options.add(sOption);
  obj1.value = "";
}


/**
 * 게시판관리분류삭제
 * @author 김지은
 * @param 분류select객체
 * @param text
 * @return
 */
function deleteItem(obj2, text) {
  if( obj2.selectedIndex == -1 ) {
    alert("삭제할  "+text+"를 선택하세요");
    obj2.focus();
    return;
  }
  $.post("itemProcess.jsp",        //ajax 로 페이지 부르기 
          { 'itemID':obj2.options[obj2.selectedIndex].value, 'mode':"checkItemProcess" },  // 선택된 것 Array로 넘기기
          function(data) {            // Callback 함수
            aData = data.split("|");
            len = aData.length ;
            for (i=0;i<len;i++) {
              if ( i == 0 ) {
                //obj2.remove(obj2.selectedIndex);
              } else if ( i == 1 ) {
                if ( confirm(aData[i]) ) {
                  obj2.remove(obj2.selectedIndex);
                }
              }
            }
          }, 
          "text");
  /*
  if ( objectid != "" ) {
    $.post("itemProcess.jsp",        //ajax 로 페이지 부르기 
          { 'itemID':obj2.options[obj2.selectedIndex].value, 'mode':"deleteItemProcess", 'groupID':groupid, 'objectID':objectid },  // 선택된 것 Array로 넘기기
          function(data) {            // Callback 함수
            aData = data.split("|");
            len = aData.length ;
            for (i=0;i<len;i++) {
              if ( i == 0 ) {
                obj2.remove(obj2.selectedIndex);
              } else if ( i == 1 ) {
                alert(aData[1]);
              }
            }
          }, 
          "text");
  } else {
    obj2.remove(obj2.selectedIndex);
  }
  */
  //obj2.remove(obj2.selectedIndex);
}

function editItemDisplay(obj1, obj2) {
  obj2.value = obj1.options[obj1.selectedIndex].text;
  /*
  obj3.value = obj1.options[obj1.selectedIndex].value;
  */
}

function editItem(itemfieldname, obj){
/*
        $.post("itemProcess.jsp",        //ajax 로 페이지 부르기 
          { 'itemFieldName':itemfieldname, 'itemID':itemid, 'mode':"updateItemProcess", 'groupID':groupid, 'objectID':objectid },  // 선택된 것 Array로 넘기기
          function(data) {            // Callback 함수
            aData = data.split("|");
            len = aData.length ;
            for (i=0;i<len;i++) {
              if ( i == 0 ) {
                if ( obj.options[obj.selectedIndex].value == itemid ) {
*/
                  obj.options[obj.selectedIndex].text = itemfieldname;
/*
                }
              } else if ( i == 1 ) {
                alert(aData[1]);
              }
            }
          }, 
          "text");
*/
}
/**
 * 게시판관리분류   위로
 * @author 김지은
 * @param 분류select객체
 * @return
 */
function upItem(obj2) {
  var nSelectedIndex = obj2.selectedIndex;
  if ( nSelectedIndex < 0 ) {
    alert("선택한 값이 없습니다.");
    return;
  }
  if ( nSelectedIndex == 0 ) {
    alert("처음입니다.");
    return;
  }

  var sText = obj2.options[nSelectedIndex].text;
  var sValue = obj2.options[nSelectedIndex].value;
  obj2.options[nSelectedIndex].text = obj2.options[nSelectedIndex-1].text;
  obj2.options[nSelectedIndex].value = obj2.options[nSelectedIndex-1].value;
  obj2.options[nSelectedIndex-1].text = sText;
  obj2.options[nSelectedIndex-1].value = sValue;
}



/**
 * 게시판관리분류아래로
 * @author 김지은
 * @param 분류select객체
 * @return
 */
function downItem(obj2) {
  var nSelectedIndex = obj2.selectedIndex;
  if ( nSelectedIndex < 0 ) {
    alert("선택한 값이 없습니다.");
    return;
  }
  if ( nSelectedIndex == obj2.length -1 ) {
    alert("마지막입니다.");
    return;
  }

  var sText = obj2.options[nSelectedIndex].text;
  var sValue = obj2.options[nSelectedIndex].value;
  obj2.options[nSelectedIndex].text = obj2.options[nSelectedIndex+1].text;
  obj2.options[nSelectedIndex].value = obj2.options[nSelectedIndex+1].value;
  obj2.options[nSelectedIndex+1].text = sText;
  obj2.options[nSelectedIndex+1].value = sValue;
}

/**
 * 분류select객체의 text를 아이템필드로 삽입
 * @author 조지은
 * @param 분류select객체
 * @param 아이템필트네임객체
 * @return
 */
function checkItemFieldName(sSelectItem, sItemFieldName){
  if ( sSelectItem && sItemFieldName ) {
    var sTxt = "";
    var nOption = sSelectItem.length;
    for( i = 0; i < nOption; i++ ) {
     sTxt += sSelectItem.options[i].value;
     sTxt += ":";
     sTxt += sSelectItem.options[i].text;
      if( i < nOption - 1 ) {
        sTxt = sTxt + "|";
      }
    }
    sItemFieldName.value = sTxt;
  }
}

/**
* 첨부파일 확장자 검사
* @author 조지은
* @param 첨부파일 허용종류
* @param 파일 객체
* @return
*/ 
function checkFile(existExt){
  existExtArray = existExt.split("|");
  var inputs = document.getElementsByTagName("input");
  var file = new Array();
  var idx =0;
        
  for ( var i=0; i<inputs.length;i++){
    if ( inputs[i].type == "file" && inputs[i].value != "" ) {
      file[idx] = inputs[i];
      idx++;
    }
  }
  
  if ( file.length > 0 ) {
    for ( var i=0; i<file.length;i++){
		  Temp_file1_name = file[i].value;
		  if (Temp_file1_name != "") {
		    bi = false;
		    Temp_strExt1_num = Temp_file1_name.slice(Temp_file1_name.lastIndexOf(".")).toLowerCase();
		    for (var j=0; j < existExtArray.length; j++){
		      if (Temp_strExt1_num == existExtArray[j]){
			      bi = true;
		      }
		      if ( ( j == existExtArray.length - 1 ) && !bi ) {
		        if ( !bi ) {
				      alert(Temp_strExt1_num+"는 첨부할 수 없는 확장자입니다.");
				      return false;
				    } else {
				      return true;
				    }
		      }
		    }
		  } else {
		    return true;
		  }
    }
    if ( !bi ) {
      alert(Temp_strExt1_num+"는 첨부할 수 없는 확장자입니다.");
      return false;
    } else {
      return true;
    }
  } else {
    return true;
  } 
}

/**
* 글쓰기제한단어 검사
* @author 조지은
* @param 글쓰기제한단어
* @param 인풋
* @return
*/
function checkRestrictWord(restrictWord, input){
  Temp_name = input.value;
  restrictWordArray = restrictWord.split(",");
  if ( restrictWord != "" && Temp_name != "" ) {
    ci = false;
    for(i=0;i<restrictWordArray.length;i++){
      var c = new RegExp(restrictWordArray[i].replace(/(^\s*)|(\s*$)/g, ""));
      if ( c.test(Temp_name) ) {
        ci = false;
        break;
      } else {
        ci = true;
      }
    }
    if ( !ci ) {
      alert("금지어를 포함하고 있습니다. 다시 작성해주세요.");
      return false;
    } else {
      return true;
    }
  } else {
    return true;
  }
}


/**
 * open popup, window open을 이용, 인자전달 없음
 *
 * @param       sURL    url
 * @param       sWidth  window width(optional)
 * @param       sHeight window height(optional)
 * @return  window  object
 * @since       1.0
 */
function openPopup (sURL) {
    var sWidth, sHeight;
    var sFeatures;
    var oWindow;
    var SP2 = false;
		var POPUP_WIDTH     = 400;
		var POPUP_HEIGHT    = 300;
		var B_MAIN_PAGE     = true;

    sHeight = POPUP_HEIGHT;
    sWidth  = POPUP_WIDTH;
    sTitle = "PopupWindow";

    try {
      SP2 = (window.navigator.userAgent.indexOf("SV1") != -1);
      if (arguments[1] != null && arguments[1] != "") sWidth = arguments[1] ;
      if (arguments[2] != null && arguments[2] != "") sHeight = arguments[2] ;
      if (arguments[3] != null && arguments[3] != "") sTitle = arguments[3] ;
      if (SP2)     {   // XP SP2 브라우저임..
        sHeight = Number(sHeight)+10;
      }else{  //그외 브라우저
      }
    } catch(e) {}

    sFeatures =  "width=" + sWidth + ",height=" + sHeight ;
    sFeatures += ",left=0,top=0" ;
    sFeatures += ",directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no";

    oWindow = window.open(sURL, sTitle, sFeatures);
    oWindow.focus();

    // move to screen center
    //oWindow.moveTo( (window.screen.availWidth - sWidth) / 2, (window.screen.availHeight - sHeight) / 2);

    return oWindow;
}

/**
* textarea 바이트체크
* @author 인터넷
* @param obj(textarea), iSize(byte), sId(textarea id)
* @return
*/
function char_length(obj, iSize, sId) {
  var tmpStr;
  var temp=0;
  var onechar;
  var tcount;
  tcount = 0;
  aquery = obj.value;
  tmpStr = new String(aquery);
  temp = tmpStr.length;
  
  for (k=0;k<temp;k++)
  {
    onechar = tmpStr.charAt(k);
    if (escape(onechar) =='%0D') { } else if (escape(onechar).length > 4) { tcount += 2; } else { tcount++; }
  }
  
  document.getElementById(sId).innerHTML = tcount;
  
  if(tcount>iSize) {
    reserve = tcount-iSize;
    alert(iSize+"바이트 이상 입력할 수 없습니다.");
    cutText(obj, iSize, sId);
    return;
  }
}

/**
* textarea 바이트수  보여주기
* @author 인터넷
* @param obj(textarea), iSize(byte), sId(textarea id)
* @return
*/
function cutText(obj, iSize, sId){
  var tmpStr;
  var temp=0;
  var onechar;
  var tcount;
  tcount = 0;
  aquery = obj.value;
  tmpStr = new String(aquery);
  temp = tmpStr.length;
  
  for(k=0;k<temp;k++)
  {
    onechar = tmpStr.charAt(k);
    
    if(escape(onechar).length > 4) {
      tcount += 2;
    } else {
      // 엔터값이 들어왔을때 값(\r\n)이 두번실행되는데 첫번째 값(\n)이 들어왔을때 tcount를 증가시키지 않는다.
      if(escape(onechar)=='%0A') {
      } else {
        tcount++;
      }
    }
  
    if(tcount>iSize) {
      tmpStr = tmpStr.substring(0,k);
      break;
    }
  }
  obj.value = tmpStr;
  char_length(obj, iSize, sId);
}

/*
 * 팝업 자동 리사이징
 *  - 윈도 환경에 따라 사이즈가 다를 수 있습니다.
 *  - 팝업페이지의 스크립트 최하단에서 실행하십시오.
 *
 * (ex.) window.onload = function(){popupAutoResize();}
*/
function popupAutoResize() {
  if ( navigator.userAgent.indexOf("Linux") < 0 ) {  
    var thisX = parseInt(document.documentElement.scrollWidth);
    var thisY = parseInt(document.documentElement.scrollHeight);
    var maxThisX = screen.width - 50;  
    var maxThisY = screen.height - 50;
    var marginY = 0;
    //var SP2 = (navigator.appVersion.indexOf("MSIE 7.0") != -1);   
    //WindowsXP SP2
    if(navigator.userAgent.indexOf("MSIE 8") > 0) {
      marginY = 78;
    } else if(navigator.userAgent.indexOf("MSIE 7") > 0) {
      marginY = 78;                       
    } else if (navigator.userAgent.indexOf("MSIE 6") > 0) {
      marginY = 58;         
    } else if (navigator.userAgent.indexOf("Firefox") > 0) {
      marginY = 84;         
    } else if (navigator.userAgent.indexOf("Chrome") > 0) {
      marginY = 0;            
      thisX -= 8;     
    } else {
      marginY = 50;
    } 
    /*
    if (SP2) { 
      marginY = Number(marginY) - 23;
    }else{    
    }
    */
    //WindowsVISTA, Windows7
    if(navigator.userAgent.indexOf("Windows NT 6") > 0) { 
      if (navigator.userAgent.indexOf("MSIE") > 0) {
        marginY += 0;    
      } else if (navigator.userAgent.indexOf("Firefox") > 0) {
        marginY += -1;      
        thisX += 8;                
      } else if (navigator.userAgent.indexOf("Chrome") > 0) {
        marginY += 3;
        thisX += 8;            
      } 
    }
    //Windows2000
    if(navigator.userAgent.indexOf("Windows NT 5.0") > 0) {
      if (navigator.userAgent.indexOf("MSIE") > 0) {
        marginY -= 41;         
      } else if (navigator.userAgent.indexOf("Firefox") > 0) {
        marginY -= 3;      
      } 
    }
    if (thisX > maxThisX) {
        window.document.body.scroll = "yes";
        thisX = maxThisX;
    }
    if (thisY > maxThisY - marginY) {
        window.document.body.scroll = "yes";
        thisX += 19;
        thisY = maxThisY - marginY;
    }
    if (arguments[0] != null && arguments[0] != "") {
      window.resizeTo(arguments[0], thisY+marginY);
    } else {
      window.resizeTo(thisX+8, thisY+marginY);
    }  
  }
}


/**
 * 글자수check
 * @param obj
 * @param max
 * @param checkMaxID
 * @return
 */
function displayStateData (targetID, displayState) {
  var targetArray = targetID.split('|');
  for( var i = 0; ( i < targetArray.length ) && targetArray[i] != '' ; i++ ){
    document.getElementById(targetArray[i]).style.display = displayState;
  }
}

/**
 * cookie
 * @param targetID
 * @return
 */
function setCookie(name,value,expiredays) {
  var todayDate = new Date();
  todayDate.setDate(todayDate.getDate() + expiredays);
  document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
  
function getCookie(name) {
  var nameOfCookie = name + "=";
  var x = 0;

  while( x <= document.cookie.length ) {
    var y = (x+nameOfCookie.length);
    if( document.cookie.substring( x, y ) == nameOfCookie ) {
      if( (endOfCookie=document.cookie.indexOf( ";",y )) == -1 ) endOfCookie = document.cookie.length;
      return unescape( document.cookie.substring(y, endOfCookie ) );
    }
    x = document.cookie.indexOf( " ", x ) + 1;
    if ( x == 0 ) break;
  }
  return "";
}

/**
 * 글자수check
 * @param obj
 * @param max
 * @param checkMaxID
 * @return
 */
function checkMax(obj, max, checkMaxID){
  var sTxt = obj.value;
  if( sTxt.length > max ) {
    alert(max+'자 이내로 입력해 주십시오.');
    obj.value = obj.value.substring(0, max );
    return false;
  }
  var sCheckMaxID = document.getElementById(checkMaxID);
  sCheckMaxID.innerHTML = sTxt.length;
  return true;
}

/**
 * 트리밍
 * @param str
 * @return
 */
function trim(str){
  str = str.replace(/^\s*/,'').replace(/\s*$/, '');
  return str;
}  

/**
 * 첨부파일 다운로드
 * @param str
 * @return
 */
function fncDownload( arg1, arg2 ) {
 
  if ( document.getElementById("fileDownloadForm") ) {
    document.getElementById("fileDownloadForm").action = "../../inc/download.jsp";
    document.getElementById("fileDownloadForm").dirName.value = arg1;
    document.getElementById("fileDownloadForm").fileName.value = arg2;
    document.getElementById("fileDownloadForm").target = "hFrame";
    document.getElementById("fileDownloadForm").submit();
  }

}

/**
 * add combobox list
 *
 * @param   oCombo      combo object
 * @param   sValue      combo data string
 * @param   sText       combo text string
 * @since   1.0
 */
function addCombo (oCombo, sValue, sText) {
    if (sValue == null || sValue == "") return;

    var optionElem = document.createElement("OPTION");
    optionElem.setAttribute("value", sValue);
    optionElem.appendChild(document.createTextNode(sText));

    eval(oCombo).appendChild(optionElem);
}

/**
 * remove combobox list
 *
 * @param   oCombo          combo object
 * @since   1.0
 */
function removeCombo (oCombo, idx) {
  var cntOption = eval(oCombo).getElementsByTagName("option");

  if ( idx < 0 || idx > (cntOption.length - 1 ) ) {
    return;
  }

  aCompare = (oCombo.options[idx].value).split(":");
  len = aCompare.length;
  for (i=0;i<len;i++){
    if ( i == 0 ) {
      if ( aCompare[i] == "U" ) {
        var DEL_FILE_LIST = document.createElement("input");
        DEL_FILE_LIST.type = "hidden"
        DEL_FILE_LIST.name = "DEL_FILE_LIST";
        DEL_FILE_LIST.setAttribute("name", "DEL_FILE_LIST");
        DEL_FILE_LIST.value = (oCombo.options[idx].value).replace("U:", "");
        document.forms['writeForm'].appendChild(DEL_FILE_LIST);
      } 
      oCombo.removeChild(cntOption[idx]);    
    }
  }
}

/**
 * file 삭제
 * @param path
 * @return
 */
function fileDelSubmit (path) {
  var frm = document.forms['writeForm'];
  if(frm.file_list.length == 0){
    alert('삭제할 파일이 없습니다.');
    return;
  }

  if(frm.file_list.selectedIndex == -1){
    alert('삭제할 파일을 선택해 주십시오.');
    return;
  }
  var fileID   = frm.file_list.options[frm.file_list.options.selectedIndex].value;
  var fileName = frm.file_list.options[frm.file_list.options.selectedIndex].innerHTML;

  hFrame.location.href = "../../inc/fileUploading.jsp?path="+path+"&fileID="+ encodeURI(fileID) + "&fileName="+ encodeURI(fileName);
}

/**
 * file 첨부 후 
 * @param fileID
 * @param fileName
 * @return
 */
function afterFileSave(fileID, fileName){
  var frm = document.forms['writeForm'];
  addCombo(frm.file_list, fileID, fileName);
}

/**
 * file 삭제 후 
 * @param file_list
 * @param idx
 * @return
 */
function afterFileDelete(file_list, idx){
  if ( file_list == null || file_list == "" ) {
    file_list = document.forms['writeForm'].file_list;
  }
  if ( idx == null || idx == "" ) {
    idx = file_list.options.selectedIndex;
  }
  removeCombo(file_list, idx);
}
  
/**
 * 폼 전송 전에 file list 생성  
 * 형식은 (모드):VALUE:TEXT|의 반복
 * @param obj(form)
 * @param input(select)
 * @return
 */
function fileListEdit(obj, input){
  var FILE_LIST = document.createElement("input");
  FILE_LIST.type = "hidden"
  FILE_LIST.id = "FILE_LIST";
  FILE_LIST.name = "FILE_LIST";
  FILE_LIST.setAttribute("name", "FILE_LIST");
  FILE_LIST.value = "";
  obj.appendChild(FILE_LIST);
  
  var file_list = input;
  var fOption = file_list.getElementsByTagName("option");
  FILE_LIST.value = "";
  for(var i=0;i<fOption.length;i++){
    FILE_LIST.value = FILE_LIST.value + fOption[i].value+":"+fOption[i].innerHTML;
    FILE_LIST.value = FILE_LIST.value + "|";
  }
  return true;
}
 
 /**
 *  Ajax 이용한 로그인 구현
 *
 *
 *
 */
 function loginCheckAjax() {
   $.ajax({url: "../../main/loginCheckAjax.jsp", 
        success : function(msg) {
          if ( jQuery.trim(msg) == "login" ) {
            $("#logout").css("display","inline");
            $(".logout").css("display","inline");
            $("#login").css("display","none");  
            $(".login").css("display","none");
            $("#memberJoin").css("display","none");
          } else if ( jQuery.trim(msg) == "logout" ) {            
            $("#login").css("display","inline");
            $(".login").css("display","inline");
            $("#logout").css("display","none");
            $(".logout").css("display","none");
          }
        }   
      });
   } 
 $(document).ready(loginCheckAjax);
 
 
 /**
  * 이미지리사이즈
  * 이미지를 둘러싸고있는   객체ID, 축소할가로사이즈, 축소할세로사이즈
  * IMG태그에 width,height주지말고, style="display:none;" 으로 세팅
  * @param targetID, targetWidth, targetHeight
  * @return
  */
  function imageResize(targetID ,targetWidth, targetHeight){
    if (document.getElementById(targetID) != null) {      
      var images = document.getElementById(targetID).getElementsByTagName('IMG');
      var newWidth;
      var newHeight;
      for ( var i = 0; i < images.length; i++) {
        images[i].style.display = "";
        var originalWidth = images[i].width;
        var originalHeight = images[i].height;
        if ( originalWidth < targetWidth && originalHeight < targetHeight ) {
          newWidth = originalWidth;
          newHeight =  originalHeight;
        } else {
          if ( images[i].width > images[i].height ) {
            newWidth = targetWidth;
            newHeight = Math.ceil(images[i].height * targetWidth / images[i].width);
          } else if ( images[i].width <= images[i].height ) {
            newWidth = Math.ceil(images[i].width * targetHeight / images[i].height);
            newHeight = targetHeight;
          } else {
            newWidth = targetWidth;
            newHeight = targetHeight;
          }
          if( newWidth > targetWidth ) {
            newWidth = targetWidth;
            newHeight = Math.ceil(images[i].height * targetWidth / images[i].width);
          }
          if( newHeight > targetHeight ) {
            newWidth = Math.ceil(images[i].width * targetHeight / images[i].height);
            newHeight = targetHeight;
          }          
        }
        images[i].width = newWidth;
        images[i].height = newHeight;
      }
    }
  }

  function Play0_OnClick(){
    var Player = eval("document.getElementById('Player0')");
    Player.Play();  //Run(); 
    currID0 = setInterval("Player0_position()", 100); 
  }

  function Stop_OnClick(){
    var Player = eval("document.getElementById('Player0')");
    Player.Stop();
  }
  
  function Pause_OnClick(){
    var Player = eval("document.getElementById('Player0')");
    Player.Pause();
  }
  function Player0_position() { 
	if (parseInt(document.all.Player0.CurrentPosition) == parseInt(document.all.Player0.Duration)) { 
      swapImg(2, "Image2", "Image1", "Image3");
      close_Player0();
    } 
  }
  function Play0_changeFile(obj1, obj2){
    var Player = eval("document.getElementById('Player0')");
    var videoClass = '';

    Player.Stop();
    //if ( obj == 1 ) {
      Player.Filename = "../../files/images/"+obj1;
      
      for ( var i = 1; i < 9; i++ ) {
        if ( document.getElementById("videoClass"+i) != null ) {
          videoClass = document.getElementById("videoClass"+i);
          /*
          if ( i == obj2 ) {
             videoClass.style.color = "#ffffff";
             videoClass.className="li_on";
             if (videoClass.getElementsByTagName("img")[0] != null){
               videoClass.getElementsByTagName("img")[0].src.replace('.gif', '_on.gif');
             }
          
          } else {
            
             videoClass.style.color = "#000000";
             videoClass.className=""; 
             if (videoClass.getElementsByTagName("img")[0] != null){
               videoClass.getElementsByTagName("img")[0].src.replace('_on.gif', '.gif');
             }
             
          }
          */
        }
      }
      
    //} else {
    //  Player.Filename = "../../files/images/WEC2013_PT_2.wmv";   
    //}
    //Player.Play();  //Run(); 
    //currID0 = setInterval("Player0_position()", 100); 
  }
 
