//공용자바스크립트유틸함수모음
//재정리 2007.05
//작성 : IB.LEE

//*********************************************************************
// Method : __RunTimer
// Purpose : 자바스크립트실행시간구하기
// Inputs : None
// Returns : Number
// Usage : 시작점 __RunTimer() - 종료점 __RunTimer()
//*********************************************************************
function __RunTimer(){
    var today = new Date() // 현재시간 얻기
    var RunTime = today.getTime(); // 밀리초 from 1/1/70
    return RunTime;
}

function OpenWindow(url,width,height,left,top, scrollbars , resizable){
    var url = (url==null)?"/main/blank.htm":url;
    var width = (width==null)?300:width;
    var height = (height==null)?300:height;
    var scrollbars = (scrollbars==null)?"no":scrollbars;
    var resizable = (resizable==null)?"no":resizable;
    if(left!=null || top!=null){
        window.open(url,"","width="+width+",height="+height+",left="+left+",top="+top+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scrollbars+",resizable="+resizable);
    }else{
        window.open(url,"","width="+width+",height="+height+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scrollbars+",resizable="+resizable);
    }
}

function __writeActiveX(src){
	document.write(src); 
}

var onloads = new Array();
function bodyOnLoad() {
    for ( var i = 0 ; i < onloads.length ; i++ )
    onloads[i]();
}

var __debug = function(str) {
	$('__debug').value = $('__debug').value +"\n"+ str ;
}
var alert404 = function(t) {
    LodingIndicatorEnd();
    alert('Error 404: location "' + t.statusText + '" was not found.');
}
var alertFailure= function(t) {
    LodingIndicatorEnd();
    alert('Error ' + t.status + ' -- ' + t.statusText);
}
var alertDebug = function(t) {
    LodingIndicatorEnd();
    __debug('DEBUG --------------------- \r\n\r\n' + t.responseText);
}

function alertText(obj){
    LodingIndicatorEnd();
    //__debug(obj.responseText);
    eval("res = " + obj.responseText);
    alert(res.strMsg);
}

function Href(url){
    location.href=url;
}

/* 쿠키 */
function setCommonCookie( name, value, expiredays )
{
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
function getCommonCookie( 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 "";
}

function goTop(){
	document.body.scrollTop = 0;
}
function IframeLoad(id,Href,isClear){
    parent.FrameLoad(id,Href,isClear);
}
function FrameLoad(id,strUrl,isClear){

	goTop();
//    if (dhtmlHistory.isFirstLoad()) {
//        alert(strUrl);
//        var complexObject = new Object();
//        complexObject.id = id;
//        complexObject.strUrl = strUrl;
//        complexObject.isClear = isClear;
//        dhtmlHistory.add("FRHIS"+Math.round(Math.random()*100000000000),complexObject);
//    }

    //isClear = (isClear==undefined)?0:isClear;

    if(isClear==0){
        GlobalVars = {} ;
    }

    $('_FrameContentArea').hide();
    $('_FrameUpdateArea').hide();
    $('_FrameViewArea').hide();
    $('_FrameListArea').hide();

    //_FrameUpdate.location.href="about:blank";
    //_FrameView.location.href="about:blank";

    //parent.document.getElementById('_FrameContent').height = 100;
    //parent.document.getElementById('_FrameUpdate').height = 100;
    //parent.document.getElementById('_FrameView').height = 100;
    //parent.document.getElementById('_FrameList').height = 100;

    if(id.toUpperCase()=="C"){
		_FrameUpdate.location.href="about:blank";
		_FrameView.location.href="about:blank";
        $('_FrameContentArea').show();
        _FrameContent.location.href=strUrl;
    }else if(id.toUpperCase()=="U"){
		_FrameView.location.href="about:blank";
        $('_FrameUpdateArea').show();
        _FrameUpdate.location.href=strUrl;
    }else if(id.toUpperCase()=="V"){
		_FrameUpdate.location.href="about:blank";
        $('_FrameViewArea').show();
        _FrameView.location.href=strUrl;
    }else if(id.toUpperCase()=="L"){
        var __bProc = true ;
        Try.these(
            function(){						
                if(NavVars.mypage==1 && isClear==1){//미결함				
                    _FrameUpdate.location.href="about:blank";
                    _FrameView.location.href="about:blank";
                    $('_FrameListArea').show();
                    _FrameList.location.href="/main/option/mypage/mypage_cnfm_list.jsp";
					__bProc=false;
                    return;
                }else if(NavVars.mypage==2 && isClear==1){//진행함				
                    _FrameUpdate.location.href="about:blank";
                    _FrameView.location.href="about:blank";
                    $('_FrameListArea').show();
                    _FrameList.location.href="/main/option/mypage/mypage_cnfm_ing_list.jsp";
					__bProc=false;
                    return;
                }
                if($('_FrameListFileid').innerHTML == _FrameList.LocalVars.fileid && isClear==1 ){
                    $('_FrameListArea').show();
                    __bProc = false ;
                }
            }
        );
        if(__bProc){
            _FrameUpdate.location.href="about:blank";
            _FrameView.location.href="about:blank";
            $('_FrameListArea').show();
            _FrameList.location.href=strUrl;
        }
    }

}

var LocalVars = {} ;//페이지지역변수활용
var GlobalVars = {} ;//전역변수활용
var NavVars = {};

function setVars(key,val){
    parent.GlobalVars[key] = val ;
}
function getVars(key){
    return parent.GlobalVars[key] ;
}

function getLocalVars(id,varname){
    Try.these(
        function(){
            if(id.toUpperCase()=="C"){
                ifrm = parent._FrameContent;
            }else if(id.toUpperCase()=="U"){
                ifrm = parent._FrameUpdate;
            }else if(id.toUpperCase()=="V"){
                ifrm = parent._FrameView;
            }else if(id.toUpperCase()=="L"){
                ifrm = parent._FrameList;
            }
            return ifrm.LocalVars[varname];
        },
        function(){
            return null;
        }
    );
}

// 툴팁 START IB.LEE 070881 IE,FF 지원

var _preview="";
var _gobj="";
function attachEvent_(obj, evt, fuc, useCapture) {
  if(!useCapture) useCapture=false;
  if(obj.addEventListener) { // W3C DOM 지원 브라우저
    return obj.addEventListener(evt,fuc,useCapture);
  } else if(obj.attachEvent) { // MSDOM 지원 브라우저
    return obj.attachEvent("on"+evt, fuc);
  } else { // NN4 나 IE5mac 등 비 호환 브라우저
    MyAttachEvent(obj, evt, fuc);
    obj['on'+evt]=function() { MyFireEvent(obj,evt) };
  }
}

function detachEvent_(obj, evt, fuc, useCapture) {
  if(!useCapture) useCapture=false;
  if(obj.removeEventListener) {
    return obj.removeEventListener(evt,fuc,useCapture);
  } else if(obj.detachEvent) {
    return obj.detachEvent("on"+evt, fuc);
  } else {
    MyDetachEvent(obj, evt, fuc);
    obj['on'+evt]=function() { MyFireEvent(obj,evt) };
  }
}

function MyAttachEvent(obj, evt, fuc) {
  if(!obj.myEvents) obj.myEvents= {};
  if(!obj.myEvents[evt]) obj.myEvents[evt]=[];
  var evts = obj.myEvents[evt];
  evts[evts.length]=fuc;
}

function MyFireEvent(obj, evt) {
  if(!obj.myEvents || !obj.myEvents[evt]) return;
  var evts = obj.myEvents[evt];
  for (var i=0;i<len;i++) {
    len=evts.length;
    evts[i]();
  }
}

function previewShow(e, obj, pv) {
  _preview=pv;
  _gobj=obj;
  attachEvent_(obj, "mousemove", previewMove, true);
  attachEvent_(obj, "mouseout", previewHide, true);
}

function previewMove(e) {
  var hb = document.getElementById(_preview);
  if(hb.parentElement) hb.parentElement.style.display="";
  else hb.parentNode.style.display="";
  var evt = e ? e : window.event;
  var posx=0;
  var posy=0;

  if (evt.pageX || evt.pageY) { // pageX/Y 표준 검사
    posx = evt.pageX +8;
    posy = evt.pageY +16;
  } else if (evt.clientX || evt.clientY) { //clientX/Y 표준 검사 Opera
    posx = evt.clientX +10;
    posy = evt.clientY +20;
    if (window.event) { // IE 여부 검사
      posx += document.body.scrollLeft;
      posy += document.body.scrollTop;
     }
  }

  //hb.style.left = posx + "px";
  hb.style.top = posy + "px";
}

function previewHide() {
  var hb = document.getElementById(_preview);
  if(hb.parentElement) hb.parentElement.style.display="none";
  else hb.parentNode.style.display="none";

  detachEvent_(_gobj,"mousemove", previewMove, true);
}

// 툴팁 END
/*******************************************/

function zoomIn() {
	nowZoom = nowZoom - 20;
	if(nowZoom <= 0) nowZoom = 20;
	zooms(0);
}

  //Zoom out
function zoomOut() {
	nowZoom = nowZoom + 20;
	if(nowZoom > 200) nowZoom = 200;
	zooms(0);
}

function zoomReset(){ 
	nowZoom = 100; //reset
	zooms(1030);
}

function zooms(left){
	document.body.style.zoom = nowZoom + "%";   

//	document.getElementById("floating").style.zoom =nowZoom + "%";
//	document.getElementById("floating").style.top = q_top*nowZoom/100+"px";
//	if(left>0){
//		document.getElementById("floating").style.left = left + "px";
//	}else{
//		document.getElementById("floating").style.left = q_left*nowZoom/100 +"px";
//	}
}
var nowZoom = 100; //배율 

var m_top = 77;        //상단메뉴 top
var m_left = 236;      //상단메뉴 left
var q_top = 180;       //퀵메뉴 top
var q_left = 900;      //퀵메뉴 left





function chk_byte(title, aro_name, ari_max)
{  

	var ls_str = aro_name.value; // 이벤트가 일어난 컨트롤의 value 값  
	var li_str_len = ls_str.length; // 전체길이  
	  
	// 변수초기화
	var li_max = ari_max; // 제한할 글자수 크기
	var i = 0; // for문에 사용
	var li_byte = 0; // 한글일경우는 2 그밗에는 1을 더함
   	var li_len = 0; // substring하기 위해서 사용
   	var ls_one_char = ""; // 한글자씩 검사한다
   	var ls_str2 = ""; // 글자수를 초과하면 제한할수 글자전까지만 보여준다.
	  
   	for(i=0; i< li_str_len; i++)
   	{
	    // 한글자추출
	    ls_one_char = ls_str.charAt(i);
  
	    // 한글이면 2를 더한다.
	    if (escape(ls_one_char).length > 4){
	     li_byte += 2;
	    }else{ // 그밗의 경우는 1을 더한다.
	     li_byte++;
	    }
  
	    // 전체 크기가 li_max를 넘지않으면
	    if(li_byte <= li_max){
	     li_len = i + 1;
	    }
   }
	  
   // 전체길이를 초과하면
   if(li_byte > li_max){
	   alert(title + "은 " + li_max + " byte를 초과 입력할수 없습니다. \n초과된 내용은 자동으로 삭제 됩니다. ");
	   ls_str2 = ls_str.substr(0, li_len);
	   aro_name.value = ls_str2;
	   aro_name.focus(); 
   }
}




/* 문자열을 길이 만큼 자른다.
 * param - str: 자를 문자열
 * param - limit: 자를 바이트 수
*/
function cutStr(str,limit){
 var tmpStr = str;
 var byte_count = 0;
 var len = str.length;
 var dot = "";

 for(i=0; i<len; i++){
  byte_count += chr_byte(str.charAt(i)); 
  if(byte_count == limit-1){
   if(chr_byte(str.charAt(i+1)) == 2){
    tmpStr = str.substring(0,i+1);
    dot = "...";
   }else {
    if(i+2 != len) dot = "...";
    tmpStr = str.substring(0,i+2);
   }
   break;
  }else if(byte_count == limit){
   if(i+1 != len) dot = "...";
   tmpStr = str.substring(0,i+1);
   break;
  }
 }
 return tmpStr+dot;
}
function chr_byte(chr){
 if(escape(chr).length > 4)
  return 2;
 else
  return 1;
}

	




