
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var jhUtil = { //jnHealthUtilities ¾à¾î jhUtil
    loadedCSS:[],
    loadedJS:[],
    OpenWindow: function (url,name,width,height,xPos,yPos,scroll,status,etc) {
        var openwin,left,top;
        if (xPos==null)left = (screen.width - width) / 2;
        else left = xPos;
        if (yPos==null) top = (screen.height - height) / 2;
        else top=yPos;
        openwin=window.open(url,name,"resizable=no,width="+width+",height="+height+",left="+left+",top="+top+",scrollbars="+scroll+',status='+status+etc);
        openwin.focus();
    },
    OpenEbook: function (path,opt){
        var vn_screenx =  window.screen.width-10; // È­¸é½ºÅ©¸° ³ÐÀÌ
        var vn_screeny =  window.screen.height-58; // È­¸é½ºÅ©¸° ³ôÀÌ
        if ( opt==null ) window.open(path+'flashbook.html','catallog','width='+vn_screenx+',height='+vn_screeny+',status=no');
        else {
            if ( opt=="1" || opt=="2" ) path="/ebook/"+path+"/";
            else path="/ebook_jinhae/"+path+"/";
            window.open(path+'flashbook.html','catallog','width='+vn_screenx+',height='+vn_screeny+',status=no');
        }
    },
    loadCSS: function (fileName) {
        for ( var i=0; this.loadedCSS.length>i; i++ ) if ( this.loadedCSS[i]==fileName ) return;
        var CSS = document.createElement("link");
        CSS.rel="stylesheet";
        CSS.type="text/css";
        CSS.href="/css/"+fileName+".css";
        CSS.media="screen";
        document.getElementsByTagName("head")[0].appendChild(CSS);
        this.loadedCSS.push(fileName);
    },
    loadJS: function (fileName) {
        for ( var i=0; this.loadedJS.length>i; i++ ) if ( this.loadedJS[i]==fileName ) return;
        var JS  = document.createElement('script');
        JS.type = 'text/javascript';
        JS.src  = '/javascripts/' + fileName + '.js';   //Path of your Javascript files
        document.getElementsByTagName('head')[0].appendChild(JS);
        this.loadedJS.push(fileName);
    },
    swf: function(src,w,h,opt) {
        if ( typeof(opt)=="undefined") opt=null;
        var classid=(opt && opt.classid)?("class=\""+opt.classid+"\""):"";
        var id=(opt && opt.id)?("id=\""+opt.id+"\""):"";
        var wmode=(opt && opt.wmode)?("<param name=\"wmode\" value=\""+wmode+"\">"):"<param name=\"wmode\" value=\"transparent\">";
        html = '';
        html += '<object '+classid+' '+id+' width="'+w+'" height="'+h+'" type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">';
        html += '<param name="movie" value="'+src+'">';
        html += '<param name="quality" value="best">';
        html += wmode;
        html += '<embed src="'+src+'" quality=best width="'+w+'" height="'+h+'" quality="best" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"><\/embed>';
        html += '<\/object>';
        document.write(html);
    },
    setGoto : function () {
        var exp = new Date(); 
        exp.setTime (exp.getTime() + 3600); 
        document.cookie="goto="+document.URL.replace("http://"+document.domain, "")+"; path=/";//expires="+exp.toGMTString()+"; 
        //alert(document.cookie);
    },
    //##########################################################################
    // ¸Ê°ü·Ã ¸Þ¼Òµå!!!.
    jnMapObj:null,
    jnMarker:null,
    showMark: function(pos) {
        this.jnMarker.setPoint(pos);
        this.jnMapObj.addOverlay(this.jnMarker);
    },
    showMap: function(width,height,opt) {
        var viewMark=true;
        if ( opt==null ) opt={};
        if ( width==null ) width=670;
        if ( height==null ) height=430;
        //¸Ê°´Ã¼»ý¼º.
        this.jnMapObj = new NMap(document.getElementById('mapContainer'),width,height); //MAP°´Ã¼»ý¼º.
        var x=0;
        try{x=parseInt($('#POINT_X').val());}catch(e){x=0;}
        var y=0;
        try{y=parseInt($('#POINT_Y').val());}catch(e){y=0;}
        if ( !(x>0 && y>0) ) {viewMark=false; x=462350;y=291477;}//»ó³²µ¿.
        this.jnMapObj.setCenterAndZoom(new NPoint(x,y),2); //Áß¾ÓÀ¸·Î Ã³¸®ÇÏ°í 2Level·Î ÁÜ¼³Á¤.
        //mapObj.pan(321198,629730); //½½¶óÀÌµùÀ¸·Î À§Ä¡ÀÌµ¿.

        //=========================================================================
        //ÁÜ ÄÁÆ®·Ñ·¯ Ãß°¡.
        //-------------------------------------------------------------------------
        var zoom =new NZoomControl();
        zoom.setAlign("right");
        zoom.setValign("top");
        this.jnMapObj.addControl(zoom); //ÁÜÄÁÆ®·Ñ·¯.
        //this.jnMapObj.addControl(new NIndexMap()); //¹Ì´Ï¸Ê

        //=========================================================================
        //ÆË¾÷·¹ÀÌ¾î Ãß°¡. - »óÈ£/ÀÌ¹ÌÁö/ÆòÁ¡/ºÐ·ù/À§Ä¡/ÀüÈ­
        //-------------------------------------------------------------------------
        if ( !viewMark ) return;
        var iconUrl = '/images/life/icon_FD06.gif';
        this.jnMarker = new NMark(new NPoint(0,0),new NIcon(iconUrl,new NSize(18,19)));
        NEvent.addListener(this.jnMarker,"mouseover",function(pos){infowin.set(pos,'<div class="itm30_MapInfo"><h2><a href="#" class="JNPOPUP">Ä«Æä¿Ã</a></h2><span class="glRoundBox in_Photo"><a href="../images/imsi/food_pop01.jpg" class="JNPOPUP"><img src="../images/life/sample/img5.gif" width="136px" height="81px" class="in_srcImg" /></a></span><dl class="in_AddInfo"><dt>ÆòÁ¡</dt><dd><img src="../images/common/icon_star10px_5.gif" alt="º°Á¡5Á¡" /> (25)</dd><dt>ºÐ·ù</dt><dd>Ä«Æä</dd><dt>À§Ä¡</dt><dd>Ã¢¿ø > ¿ëÈ£µ¿</dd><dt>TEL</dt><dd>055 - 245 - 8415</dd></dl><div class="in_btn"><a href="#" class="JNPOPUP"><img src="../images/common/btn_detail.gif" class="glRollover3" alt="»ó¼¼º¸±â" /></a><!-- <div style="position:absolute; bottom:-36px; left:40px; width:15px; height:40px; background:url(../images/life/map_layer_bottom.png) no-repeat;"></div> --></div></div>');infowin.showWindow()});
        var infowin = new NInfoWindow();
        this.jnMapObj.addOverlay(infowin);
        if ( x>0 && y>0 ) this.showMark(new NPoint(x,y));
    },
    //##########################################################################
    goLogon: function (msg,url) {
        if ( msg=="" && url ) document.location.href="/member/login.php?goto="+escape(url); //¸Þ¼¼Áö ¾ø°í URLÀÌ Ç¥½ÃµÈ °æ¿ì ¹Ù·Î ·Î±×¿ÂÆäÀÌÁö·Î ÀÌµ¿.
        if ( url==null ) url=document.URL; //nullÀÎ°æ¿ì ±âº» ÀÌµ¿ÆäÀÌÁö ¼³Á¤.
        if ( msg!="" && confirm(msg+"\n\n·Î±×ÀÎ ÆäÀÌÁö·Î ÀÌµ¿ÇÏ½Ã°Ú½À´Ï±î?") ) document.location.href="/member/login.php?goto="+escape(url); //¸Þ¼¼Áö°¡ ÀÖ´Â °æ¿ì Ãâ·ÂÇÏ°í ÀÌµ¿¿©ºÎ¸¦ È®ÀÎÇÏ¿© ÀÌµ¿ÇÔ.
    },
    getElem: function (id) {
        return (document.getElementById(id) || document.getElementsByTagName(id));
    },
    getSize: function (elem) {
        var w = (window.event)?elem.offsetWidth:elem.clientWidth;
        var h = (window.event)?elem.offsetHeight:elem.clientHeight;
        /*var w=elem.clientWidth; //border °ª ¹ÌÆ÷ÇÔ.
        var h=elem.clientHeight; //border °ª ¹ÌÆ÷ÇÔ.
        var ow=elem.offsetWidth;
        var oh=elem.offsetHeight;*/
        return {width:w,height:h};
    },
    getPosition: function (elem) {
        var box  = elem.getBoundingClientRect();
        var doc = elem.ownerDocument;
        var body = doc.body;
        var docElem = doc.documentElement;
        var clientTop = docElem.clientTop || body.clientTop || 0;
        var clientLeft = docElem.clientLeft || body.clientLeft || 0; //clientÁ¤º¸ ±¸ÇÏ±â : body.XX, docElem.XX È£È¯ °Ë»ç
        var top  = box.top  + (self.pageYOffset || docElem.scrollTop  || body.scrollTop ) - clientTop;
        var left = box.left + (self.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft;
        //var top  = box.top  + (self.pageYOffset || jQuery.boxModel && docElem.scrollTop  || body.scrollTop ) - clientTop;
        //var left = box.left + (self.pageXOffset || jQuery.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft;
        return { top: top, left: left };
    },
    getStyle: function (element,style) {
        //var txt="<h1>"+element.nodeName+"</h1>";
        //for ( key in element.style ) txt+=key+":"+element.style[key]+"<br />";
        //document.getElementById("TXT").innerHTML=txt;

        var value = element.style[style];
        if ( !value && element.currentStyle ) value=element.currentStyle[style];
        if (!value) {
            var css=document.defaultView.getComputedStyle(element, null);
            value = css ? css[style] : null;
        }
        if (style == 'opacity') return value ? parseFloat(value) : 1.0;
        return value == 'auto' ? null : value;
    },
    getPageSize: function() {
        var xScroll, yScroll;
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = window.innerWidth + window.scrollMaxX;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
        var windowWidth, windowHeight;
        if (self.innerHeight) { // all except Explorer
            if(document.documentElement.clientWidth){
                windowWidth = document.documentElement.clientWidth;
            } else {
                windowWidth = self.innerWidth;
            }
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }
        // for small pages with total height less then height of the viewport
        if(yScroll < windowHeight){
            pageHeight = windowHeight;
        } else {
            pageHeight = yScroll;
        }
        // for small pages with total width less then width of the viewport
        if(xScroll < windowWidth){
            pageWidth = xScroll;
        } else {
            pageWidth = windowWidth;
        }
        arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
        return arrayPageSize;
    },
    checkElem: function (elem) {
        var r=[];
        if ( elem.constructor!=Array) elem=[elem];
        for (var i=0; i<elem.length; i++) {
            if ( elem[i].constructor==String ) {
                var div=document.createElement("div");
                div.innerHTML=elem[i];
                for ( var j=0; j<div.childNodes.length; j++ ) r[r.length]=div.childNodes[j];
            }
            else if (elem[i].length ) {
                for (var j=0; j<elem[i].length; j++ ) r[r.length]=elem[i][j];
            }
            else {
                r[r.length]=elem[i];
            }
        }
        return r;
    },
    append: function(parent,elem) {
        var elems = this.checkElem(elem);
        for ( var i=0; i<elems.length; i++ ) parent.appendChild(elems[i]);
    },
    isValidValue: function(exp,txt) {
        var rs=null;
        re = new RegExp(exp, "gi");
        return re.test(txt);
    }
};



//========================================
//String ÇÔ¼ö ÀçÁ¤ÀÇ
//----------------------------------------
String.prototype.cut = function(len, tail) {
    var str = this;
    var l = 0;
    if ( tail==null ) tail="";
    for (var i=0; i<str.length; i++)
    {
        l += (str.charCodeAt(i) > 128) ? 2 : 1;
        if (l > len) return str.substring(0,i) + tail;
    }
    return str;
}
String.prototype.bytes = function() {
    var str = this;
    var l = 0;
    for (var i=0; i<str.length; i++)
        l += (str.charCodeAt(i) > 128) ? 2 : 1;

    return l;
}
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.repeat = function(chr,nums) {
  var repeat_string="";
  for (var i=0; nums>i; i++ ) repeat_string+=chr;
  return repeat_string+this;
}
String.prototype.tolower = String.prototype.lower = function() {
    return this.toLowerCase();
}
String.prototype.toupper = String.prototype.upper = function () {
    return this.toUpperCase();
}
String.prototype.isNumber = function() {
    var re = new RegExp("^[0-9,\.\-]*$", "gi");
    if ( !re.test(this) ) return false;
    return true;
}
String.prototype.setNumberFormat = function(point,sep) {
    return this.setNF(point,sep);
}
String.prototype.getNumber = function(point,sep) {
    return this.getNum(point,sep);
}
String.prototype.setNF = function(arg1,arg2) {
    var sourceStr=this.trim();

    var signStr   = "";
    var dotStr    = "";
    if (sourceStr.substring(0, 1) == "-") {
        signStr   = "-";
        sourceStr = sourceStr.substring(1, sourceStr.length);
    }
    if (sourceStr.indexOf(".") >= 0) {
        dotStr    = sourceStr.substring(sourceStr.indexOf("."), sourceStr.length);
        sourceStr = sourceStr.substring(0, sourceStr.indexOf("."));
    }
    if ( !sourceStr.isNumber() ) {
        alert("ÀÔ·ÂµÈ °ªÀÇ Á¤¼ö¿µ¿ª¿¡ ¼ýÀÚ°¡ ¾Æ´Ñ ¹®ÀÚ°¡ Æ÷ÇÔµÇ¾îÀÖ½À´Ï´Ù. [setNumber]");
        return this.trim();
    }
    if ( !dotStr.isNumber() ) {
        alert("ÀÔ·ÂµÈ °ªÀÇ ¼Ò¼ö¿µ¿ª¿¡ ¼ýÀÚ°¡ ¾Æ´Ñ ¹®ÀÚ°¡ Æ÷ÇÔµÇ¾îÀÖ½À´Ï´Ù. [setNumber]");
        return this.trim();
    }
    //
    var point=0;
    try{ point=parseInt(arg1); }catch(e) {point=0;}
    if ( point==0 ) dotStr=""; //¼Ò¼öÁ¡ Á¦°Å. // -°ªÀÌ¸é ÀüÃ¼ ±×´ë·Î.
    else if ( point>0 ) dotStr = dotStr.substring(0, ((dotStr.length>=point)?point+1:dotStr.length) ); //ÇØ´çÀÚ¸® ¾Æ·¡¿¡¼­ ¹ö¸²

    //Ãµ´ÜÀ§ ÄÞ¸¶.
    var seq=",";
    sourceStr=sourceStr.replace(/,/gi,"");
    var resultStr="";
    if ( arg2 ) seq=arg2;
    var end_pos=sourceStr.length;
    while ( end_pos>0 ) {
        //alert(sourceStr.substring(end_pos-3,end_pos));
        resultStr=((end_pos-3>0)?seq:"")+sourceStr.substring(end_pos-3,end_pos)+resultStr;
        end_pos=end_pos-3;
        if ( end_pos<0 ) resultStr=sourceStr.substring(0,end_pos)+resultStr;
    }
    //
    return signStr + resultStr + dotStr;
}
String.prototype.getNum = function() {
    var sourceStr=this.trim();
    if ( sourceStr=="" ) return 0;
    if ( !sourceStr.isNumber() ) {
        alert("ÀÔ·ÂµÈ °ªÀÇ Á¤¼ö¿µ¿ª¿¡ ¼ýÀÚ°¡ ¾Æ´Ñ ¹®ÀÚ°¡ Æ÷ÇÔµÇ¾îÀÖ½À´Ï´Ù. [getNum]");
        return this.trim();
    }
    sourceStr=sourceStr.replace(/,/gi,"");
    //
    if (sourceStr.indexOf(".") >= 0) {
        return parseFloat(sourceStr);
    }
    else {
        return parseInt(sourceStr);
    }
}
//========================================
//Array ¸Þ¼Òµå.
//----------------------------------------
Array.prototype.in_array = function (key) {
    var txt=","+this+",";
    if ( txt.indexOf(","+key+",")>=0 ) return true;
    else return false;
}
Array.prototype.add = function (key) {
    if ( !this.in_array(key) ) this.push(key);
}
Array.prototype.remove = function (key) {
    var newlist=new Array();
    for (var i=0; this.length>i; i++ ) {
        if ( this[i]==key ) continue;
        newlist.push(this[i]);
    }
    return newlist;
}

//========================================
//Event ¿¬°á¸Þ¼Òµå.
//----------------------------------------
function addEventSimple(obj,evt,fn) {
    if ( obj.addEventListener ) 
        obj.addEventListener(evt,fn,false);
    else if ( obj.attachEvent ) {
        obj.attachEvent('on'+evt,fn);
    }
}
function removeEventSimple(obj,evt,fn) {
    if ( obj.removeEventListener) 
        obj.removeEventListener(evt,fn,false);
    else if ( obj.detachEvent) 
        obj.detachEvnet('on'+evt,fn);
}

