/***************************************************/
/*** 함수 명   | popwindow  ************************/
/**************|************************************/
/*** Argument1 | Page 주소   ***********************/
/*** Argument2 | 가로 높이   ***********************/
/*** Argument3 | 세로 높이   ***********************/
/*** Argument4 | X 좌표      ***********************/
/*** Argument5 | Y 좌표      ***********************/
/*** Argument6 | Window 이름 ***********************/
/*** Argument7 | Properties  ***********************/
/***************************************************/

var example  = null;
var example1 = null;

function popWindow(url){
  var args = popWindow.arguments;
  var window_name, window_properties, window_width, window_height, window_left, window_top ;
    url               = args[0];
    window_width      = args[1];
    window_height     = args[2];
    window_left       = args[3];
    window_top        = args[4];
    window_name       = args[5];
    window_properties = args[6];

    if ( typeof(window_width ) == 'undefined' ) { window_width  = -1; }
    if ( typeof(window_height) == 'undefined' ) { window_height = -1; }
    if ( typeof(window_left  ) == 'undefined' ) { window_left   = -1; }
    if ( typeof(window_top   ) == 'undefined' ) { window_top    = -1; }
    if ( typeof(window_name  ) == 'undefined' ) { window_name   = ''; }

    if ( window_width  < 0 ) { window_width  = screen.width ; }
    if ( window_height < 0 ) { window_height = screen.height; }

    if ( window_left   < 0 ) { window_left = ( screen.width - window_width  ) / 2; }
    if ( window_top    < 0 ) { window_top  = ( screen.height- window_height ) / 2; }

    var properties = '';

    var ieVersion = getIEVersion();
    if(ieVersion != null && ieVersion.indexOf("7") == 0) {
        window_height = window_height + 15;  
    }

    properties = "width=" + window_width + " ,height=" + window_height + ",";
    if ( window_properties == null || window_properties == "" ) {
        properties += "location=no,toolbar=no,menubar=no,resizable=yes,scrollbars=no,top=" + window_top + ",left=" + window_left;
    } else {
        properties += window_properties + ",top=" + window_top + ",left=" + window_left;
    }

    var name;
    if ( window_name == null || window_name == "" ) {
        name = "";
    } else {
        name = window_name;
    }

	window.open(url,name,properties);
}

/***************************************************/
/*** 함수 명   | modalDialog   *********************/
/**************|************************************/
/*** Argument0 | 구분 ( Modal, Modeless ) **********/
/*** Argument1 | Page 주소   ***********************/
/*** Argument2 | 가로 높이   ***********************/
/*** Argument3 | 세로 높이   ***********************/
/*** Argument4 | X 좌표      ***********************/
/*** Argument5 | Y 좌표      ***********************/
/*** Argument6 | Window 이름 ***********************/
/*** Argument7 | Properties  ***********************/
/***************************************************/

function modalDialog(url) {
  var args = modalDialog.arguments;
  var window_width,window_height, window_left, window_top ;
  
    gubun             = args[0];
    url               = args[1];
    window_width      = args[2];
    window_height     = args[3];
    window_left       = args[4];
    window_top        = args[5];
    window_name       = args[6];
    window_properties = args[7];

    if ( typeof(window_width ) == 'undefined' ) { window_width  = -1; }
    if ( typeof(window_height) == 'undefined' ) { window_height = -1; }
    if ( typeof(window_left  ) == 'undefined' ) { window_left   = -1; }
    if ( typeof(window_top   ) == 'undefined' ) { window_top    = -1; }
    if ( typeof(window_name  ) == 'undefined' ) { window_name   = ''; }

    if ( window_width  < 0 ) { window_width  = screen.width ; }
    if ( window_height < 0 ) { window_height = screen.height; }

    if ( window_left < 0 ) { window_left = ( screen.width - window_width  ) / 2; }
    if ( window_top < 0 ) { window_top  = ( screen.height- window_height ) / 2; }

    var properties = "dialogWidth=" + window_width + "px;dialogHeight=" + window_height + "px;";
    if ( window_properties == null || window_properties == "" ) {
        properties += "dialogTop:" + window_top + ";dialogleft:" + window_left + ";status:false;px;dialogresizable=no;scroll:no;";
    } else {
        properties += "dialogTop:" + window_top + ";dialogleft:" + window_left + ";" + window_properties;
    }

    var name;
    if ( window_name == null || window_name == "" ) { name = "example"; } else { name = window_name; }
    window.name = name;
    if ( gubun == 'Modal' ) {
        showModalDialog(url,window,properties);
    } else if( gubun == 'Modeless' ) {
        if ( example1 == null ) {
            example1 = showModelessDialog(url,window,properties);
        } else {
            example1.close();
            example1 = showModelessDialog(url,window,properties);
        }
    }
}


function getNavigatorType() {
    if ( navigator.appName == "Microsoft Internet Explorer" )
        return 1;
    else if ( navigator.appName == "Netscape" )
        return 2;
    else
        return 0;
}

function getIEVersion() {
    if(getNavigatorType() == 1) {
        info = window.navigator.appVersion.toString();
        info = info.substring(info.indexOf("MSIE"));
        info = info.substring(info.indexOf(" ")+1);
        info = info.substring(0, info.indexOf(";"));
        
        return info;
    }
}

function resizeToWindowPop(width, height) {
    if("7.0" == getIEVersion()) {
        window.resizeTo(width, height+22);
    }else {
        window.resizeTo(width, height);
    }
}

    // set cookie
    function popSetCookie(name, value, expires, path, domain, secure) {     
        document.cookie = name + '=' + escape(value) + ';'
            + ((expires) ? ' expires=' + expires.toGMTString() + ';' : '')
            + ((path) ? ' path=' + path + ';' : '')
            + ((domain) ? ' domain=' + domain + ';' : '')
            + ((secure) ? ' secure' + ';' : '');
    }
    
    // delete cookie
    function popDeleteCookie(name,path,domain) {
        if (popGetCookie(name))
            document.cookie = name + '=;'
            + ' expires=Thu, 01-Jan-70 00:00:01 GMT;'
            + ((path) ? ' path=' + path + ';' : '')
            + ((domain) ? ' domain=' + domain + ';' : '');
    }
    
    // change cookie
    function changePopupState(checkbox, cookieName) {
        if (checkbox.checked) {
            // 쿠키값을 설정한다.
            var expDate = new Date();
            expDate.setDate(expDate.getDate() + 1);
            expDate.setHours(0);
            expDate.setMinutes(0);
            expDate.setSeconds(0);
            popSetCookie(cookieName, 'close', expDate, '/');
        } else {
            // 쿠키값을 없앤다.
            popDeleteCookie(cookieName, '/');
        }
    }
    
    function changePopupStateClose(cookieName, day) {
        changePopupState(cookieName, day);
        window.close();
    }
    
    function changePopupState(cookieName, day) {
        // 쿠키값을 설정한다.
        var expDate = new Date();
        expDate.setDate(expDate.getDate() + day);
        expDate.setHours(0);
        expDate.setMinutes(0);
        expDate.setSeconds(0);
        popSetCookie(cookieName, 'close', expDate, '/');
    }
        
    // get cookie
    function popGetCookie(name) {
        var srch = name + '=';
        if (document.cookie.length > 0) {
            offset = document.cookie.indexOf(srch);
            if (offset != -1) {
                offset += srch.length;
                end = document.cookie.indexOf(';', offset);
                if (end == -1) end = document.cookie.length;
                return unescape(document.cookie.substring(offset, end));
            } else return false;
        } else return false;
    }
   
function openViewImagePop(imgUrl, width, height) {
     imgWin = window.open('/web/jsp/common/pop_view_image.jsp?imgUrl='+imgUrl+'', 'imgWin', 'left=300,top=350,width='+width+',height='+height+',location=no,toolbar=no,menubar=no,resizable=yes,scrollbars=no');
}

function resizeToViewImagePop(width, height) {
    if(width < 1) width = 100;  
    if(height < 1) height = 120;
    resizeToWindowPop(width, height+44);
}
 
function resizeToImagePopImg(){
  resizeToImage("popImg");
}
 
function resizeToImage(imgObj){
    var width = eval("document."+imgObj+".width");
    var height = eval("document."+imgObj+".height");

    resizeToImageByWidth(imgObj, width, height);
}

function resizeToImageByWidth(imgObj, width, height){

    var max_width= 600;   // 이미지의 최대 크기     
    
    //alert(" w : " + width + ", h : " + height);
    if ( width > max_width ) {  // 이미지가 600보다 크다면 너비를 600으로 맞우고 비율에 맞춰 세로값을 변경한다. 
       height = height * ( max_width / width);     
       width = max_width;
    }

    eval("document."+imgObj+".width = width");     
    eval("document."+imgObj+".height = height");        

    self.resizeTo(width, height+44);      
} 
     
function openWindowOption(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)  // 옵션이 필요한 팝업 띄우기
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';

  cookie_str = document.cookie;
  cookie_str.toString();

  pos_start  = cookie_str.indexOf(name);
  pos_end    = cookie_str.indexOf('=', pos_start);

  cookie_name = cookie_str.substring(pos_start, pos_end);

  pos_start  = cookie_str.indexOf(name);
  pos_start  = cookie_str.indexOf('=', pos_start);
  pos_end    = cookie_str.indexOf(';', pos_start);
  
  if (pos_end <= 0) pos_end = cookie_str.length;
  cookie_val = cookie_str.substring(pos_start + 1, pos_end);
  if (cookie_name == name && cookie_val  == "done")
    return;

  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

        

        
