﻿/////////////////////////////////////////////////////////////////////////////////
/////                                                                       /////
/////     KIMS OnLine Common JavaScript (KIMS OnLine 공통 자바스크립트)     /////
/////                                                                       /////
/////            작성자 : 남정석        최초 작성일 : 2008.06.04            /////
/////            수정자 : 남정석        최종 수정일 : 2008.12.03            /////
/////                                                                       /////
/////////////////////////////////////////////////////////////////////////////////

var msg = 'Medical Observer'; //상태표시줄에 넣을 메세지
function hideURL() {
window.status = msg;
timerID= setTimeout("hideURL()", 0);
}
hideURL();

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function gotop() {
	window.scroll(0,0);
}

// 쿠키에 저장된 아이디 확인 후 아이디 입력 텍스트 박스에 설정 ( 2008.06.05 남정석 )
var savedID = GetCookie("KOL_ID");
if(savedID != '') {
    document.getElementById('id').value=savedID;
    document.getElementById('id').checked = true;
    document.getElementById('id').style.backgroundImage="";
}
// 쿠키에 저장된 아이디 확인 후 아이디 입력 텍스트 박스에 설정 ( 2008.06.05 남정석 )

// 텍스트 박스 텍스트 내용 지우기 ( 2008.06.04 남정석 )
function fnInputSet(name)
{
    var obj = document.getElementById(name);
    
    obj.value = "";
}
// 텍스트 박스 내용 지우기 ( 2008.06.04 남정석 )

// 텍스트 박스 이미지 제어 ( 2008.06.05 남정석 )
function ch(obj)
{
    obj.style.backgroundImage="";
}

function chout(gbn, obj)
{
    if( gbn == "id" )
    {
        if( obj.value == "" )
            obj.style.backgroundImage="url(../../Images/Common/input_id.gif)";
            //obj.style.backgroundImage="url(http://dev.moonline.co.kr/Images/Common/input_id.gif)";
    }
    else if( gbn == "pw" )
    {
        if( obj.value == "" )
            obj.style.backgroundImage="url(../../Images/Common/input_pw.gif)";
            //obj.style.backgroundImage="url(http://dev.moonline.co.kr/Images/Common/input_pw.gif)";
    }
    else if( gbn == "kims_search" )
    {
        if( obj.value == "" )
            obj.style.backgroundImage="url(../../Images/Common/srh_banner_kol.gif)";
            //obj.style.backgroundImage="url(http://dev.moonline.co.kr/Images/Common/srh_banner_kol.gif)";
    }
}
// 텍스트 박스 이미지 제어 ( 2008.06.05 남정석 )

// 로그인 시 사용 ( 2008.06.04 남정석 )
function fnLoginCheck(objTxtID, objTxtPW)
{
    if( objTxtID.type == "text" )
    {
        if( objTxtID.value == "" )
        {
            alert("아이디를 입력해 주세요.");
            objTxtID.value = "";
            objTxtID.focus();
            objTxtPW.style.backgroundImage="url(../../Images/Common/input_pw.gif)";
            return false;
        }
        else
        {
            if( !fnInputTextChk(objTxtID) )
            {
                alert("입력하신 아이디에 잘못된 문자가 포함되어 있습니다.\n다시 입력해 주세요.");
                objTxtID.value = "";
                objTxtID.focus();
                return false;
            }
        }
    }
    
    if( objTxtPW.type == "password" )
    {
        if( objTxtPW.value == "" )
        {
            alert("비밀번호를 입력해 주세요.");
            objTxtPW.value = "";
            objTxtPW.focus();
            return false;
        }
        else
        {
            if( !fnInputTextChk(objTxtPW) )
            {
                alert("입력하신 비밀번호에 잘못된 문자가 포함되어 있습니다.\n다시 입력해 주세요.");
                objTxtPW.value = "";
                objTxtPW.focus();
                return false;
            }
        }
    }

    if( document.forms[0].saveid_top.checked )
    {
	    SetCookieExpire("KOL_ID", objID.value, 365);
    }
    else
    {
	    DeleteCookie("KOL_ID");
    }
	
	self.focus();
	return true;
}

function GetCookie (name) 
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    
    while ( i < clen )
    {
        var j = i + alen;
        if ( document.cookie.substring(i, j) == arg )
            return getCookieVal (j);
        
        i = document.cookie.indexOf(" ", i) + 1;
        if ( i == 0 ) break;
    }
    
    return "";
}

function getCookieVal (offset)
{
    var endstr = document.cookie.indexOf (";", offset);
    
    if (endstr == -1)
        endstr = document.cookie.length;
    
    return document.cookie.substring(offset, endstr);
}
// 로그인 시 사용 ( 2008.06.04 남정석 )

// 아이디 저장 여부 확인 ( 2008.10.14 남정석 )
function saveidWarning(chk)
{
    var objChk = document.getElementById( chk );
    
    if(objChk.checked)
    {
        if(confirm("[주의] 'ID 저장' 기능은 아이디 정보를 귀하의 컴퓨터에 저장합니다.\n\n여러 사람이 같이 사용하는 PC라면 본 기능을 사용하지 마세요.\n\n'ID 저장' 기능을 사용하시겠습니까?") == false) 
            objChk.checked = false;
    }
}
// 아이디 저장 여부 확인 ( 2008.10.14 남정석 )
        
// 아이디 저장 쿠키 값 설정 ( 2008.06.05 남정석 )
function SetCookie (name,value)
{
    document.cookie = name+"="+value+"; path=/; domain=monews.co.kr";
}

function SetCookieExpire (name,value,days)
{
    var expire = new Date();
    expire.setTime(expire.getTime()+(1000*60*60*24*days));

    document.cookie = name+"="+value+"; path=/; domain=monews.co.kr; expires="+expire.toGMTString();
}

function DeleteCookie (name)
{
    if( GetCookie(name) )
    {
        var expire = new Date();
        expire.setTime(expire.getTime() - 1);

        document.cookie = name+"=; path=/; domain=monews.co.kr; expires="+expire.toGMTString();
    }
}
// 아이디 저장 쿠키 값 설정 ( 2008.06.05 남정석 )

// 검색조건 및 검색어 입력 확인 ( 2008.06.04 남정석 )
function fnSearchCheck(objTxtSrh)
{
    var objRadio = document.getElementsByName('rbtn_search');
    var val_idx;
    var val_searchtype;
    var objTxt = "";
    
    if( objTxtSrh.style.backgroundImage == "url(/Images/Ad/srh_ad_1004_polybutein.gif)" )
    {
        objTxt = "포리부틴";
    }
    else if( objTxtSrh.style.backgroundImage == "url(/Images/Ad/banner_merck.gif)" )
    {
        objTxt = "Concor";
    }
    else if( objTxtSrh.style.backgroundImage == "url(/Images/Ad/srh_glivec.gif)" )
    {
        objTxt = "글리벡";
    }
    else if( objTxtSrh.style.backgroundImage == "url(/Images/Ad/srh_tasigna.gif)" )
    {
        objTxt = "타시그나";
    }
    else if( objTxtSrh.style.backgroundImage == "url(/Images/Ad/srh_lusentis.gif)" )
    {
        objTxt = "루센티스";
    }
    else if( objTxtSrh.style.backgroundImage == "url(/Images/Ad/srh_pletaal.gif)" )
    {
        objTxt = "프레탈";
    }
    else if( objTxtSrh.style.backgroundImage == "url(/Images/Ad/srh_msd.gif)" )
    {
        objTxt = "MSD";
    }
    else if( objTxtSrh.style.backgroundImage == "url(/Images/Ad/226x19.gif)" || objTxtSrh.style.backgroundImage == "url(/Images/Common_Renew/bannerS01.gif)" )
    {
        objTxt = "리피딜슈프라";
    }
    else if( objTxtSrh.style.backgroundImage == "url(/Images/Ad/315X25.gif)" )
    {
        objTxt = "노바티스";
    }
    else if( objTxtSrh.style.backgroundImage == "url(/Images/Ad/banner_search2.gif)" )
    {
        objTxt = "코자";
    }
    else if( objTxtSrh.value == "" )
    {
        alert("검색어를 입력해 주세요.");
        objTxtSrh.focus();
        return false;
    }
    else
    {
        if( objTxtSrh.value.length < 2 )
        {
            alert("두 글자 이상의 검색어를 입력해 주세요.");
            objTxtSrh.value = "";
            objTxtSrh.focus();
            return false;
        }
        else if( !fnInputTextChk(objTxtSrh) )
        {
            alert("입력하신 검색어중 잘못된 문자가 포함되어 있습니다.\n다시 입력해 주세요.");
            objTxtSrh.value = "";
            objTxtSrh.focus();
            return false;
        }
        else
        {
            objTxt = objTxtSrh.value;
        }
    }

    if(objRadio != null && objRadio.length > 0)
    {
        for(i=0; i < objRadio.length; i++)
        {
            if(objRadio[i].checked)
            {
                val_idx = i;
            }
        }
        
        var val_str = objRadio[parseInt(val_idx)].value;
        if(val_str == "total")
        {
            val_searchtype = "result_total";
        }
        else if(val_str == "news")
        {
            val_searchtype = "result_news";
        }
    }
    else
    {
        val_searchtype = "result_total";
    }
    
    //location.href = "/Search/search_result.aspx?Opt=" + escape(objOpt.value) + "&Key=" + escape(objTxtSrh.value);
    location.href = "/Search/" + val_searchtype + ".aspx?Key=" + escape(objTxt);
    return false;
}
// 검색조건 및 검색어 입력 확인 ( 2008.06.04 남정석 )

// 새 창 열기 ( 2008.06.04 남정석 )
function fnWindowOpen(winUrl, winName, winFeatures)
{
    window.open(winUrl,winName,winFeatures);
}
// 새 창 열기 ( 2008.06.04 남정석 )

// 엔터키 입력 확인 ( 2008.06.04 남정석 )
function fnFoward(type, obj1, obj2)
{
    if( type == "login" )
    {            
        return fnLoginCheck(obj1, obj2);
    }    
    else if( type == "search" )
    {
        return fnSearchCheck(obj1);
    }
}
// 엔터키 입력 확인 ( 2008.06.04 남정석 )

// 텍스트 박스 입력 값중 "'" 에 대한 확인 ( 2008.06.10 남정석 )
function fnInputTextChk(ctl)
{
    if( ctl.value.search("'") != -1 )
    {
        return false
    }
    else
    {
        return true;
    }
}
// 텍스트 박스 입력 값중 "'" 에 대한 확인 ( 2008.06.10 남정석 )

//
function fnTempChk(ctl, e)
{
    if( document.all )
    {
        if( event.keyCode == 13 )
        {
            return false;
        }
    }
    else
    {
        if( e.which == 13 )
        {
            return false;
        }
    }
}
//

// 숫자 입력 확인 ( 2008.06.05 남정석 )
function fnNumberCheck(obj)
{
    var num_chk = /^[0-9]$/;
    
    if( obj.value.length > 0 )
    {
        var len = obj.value.length;
        
        if( !num_chk.test(obj.value.substring(len-1, len)) )
        {
            alert("숫자를 입력해 주세요.");
            obj.value = "";
            obj.focus(); 
            return false;
        }
        else
        {
            return true;
        }
    }
}
// 숫자 입력 확인 ( 2008.06.05 남정석 )

// 입력값 형식 체크
function fnValueFormCheck1(obj)
{
    var chk2 = /[a-z]/;
    
    var len = obj.value.length;
    
    if( !chk2.test(obj.value) )
    {
        return false;
    }
    else
    {
        return true;
    }
}

function fnValueFormCheck2(obj)
{
    var chk1 = /[0-9]/;
    var chk2 = /[a-z]/;
    
    var len = obj.value.length;
    
    if( !chk1.test(obj.value) || !chk2.test(obj.value) )
    {
        return false;
    }
    else
    {
        return true;
    }
}
// 입력값 형식 체크

// 텍스트 박스 내 안내 문구 지우기 ( 2008.10.17 남정석 )
function fnEraseText(obj)
{
    obj.value = "";
}
// 텍스트 박스 내 안내 문구 지우기

// 글자크기 크게/작게 ( 2008.11.06 남정석 )
function set_cookie(name, value, expirehours) 
{
    var today = new Date();
    
    //today.setTime(today.getTime() + (60*60*1000*expirehours));
    today.setTime(today.getTime() + (60*1000*expirehours));
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";
}

function get_cookie(name) 
{
    var find_sw = false;
    var start, end;
    var i = 0;

    for (i=0; i<= document.cookie.length; i++)
    {
        start = i;
        end = start + name.length;

        if(document.cookie.substring(start, end) == name) 
        {
            find_sw = true
            break
        }
    }

    if (find_sw == true) 
    {
        start = end + 1;
        end = document.cookie.indexOf(";", start);

        if(end < start)
            end = document.cookie.length;

        return document.cookie.substring(start, end);
    }
    return "";
}

function delete_cookie(name) 
{
    var today = new Date();

    today.setTime(today.getTime() - 1);
    var value = get_cookie(name);
    
    if(value != "")
        document.cookie = name + "=" + value + "; path=/; expires=" + today.toGMTString();
}
    
function getFontSize()
{
    var fontSize = parseInt(get_cookie("mol_fontsize"));

    if (isNaN(fontSize))
    {
        fontSize = 13;
    }
    
    return fontSize;
}

function scaleFont(val)
{
    var fontSize = getFontSize();
    var fontSizeSave = fontSize;

    if (val > 0)
    {
        if (fontSize <= 18)
        {
            fontSize = fontSize + val;
        }
    }
    else
    {
        if (fontSize > 13)
        {
            fontSize = fontSize + val;
        }
    }
    
    if (fontSize != fontSizeSave)
    {
        drawFont(fontSize);
    }
    
    //set_cookie("kol_fontsize", fontSize, 30);
    set_cookie("mol_fontsize", fontSize, 1);
}

function drawFont(fontSize)
{
    if (!fontSize)
    {
        fontSize = getFontSize();
    }

    //var subject=document.getElementById("writeSubject"); 
    //var content=document.getElementById("writeContents"); 
    //var comment=document.getElementById("commentContents");
    //var wr_subject=document.getElementById("wr_subject");
    //var wr_content=document.getElementById("wr_content");
    //var test1 = document.getElementById("td_textsize_1");
    //var test2 = document.getElementById("td_textsize_2");
    //var test3 = document.getElementById("td_textsize_3");
    
    var objTd = document.getElementById('td_contents');

    if(objTd)
        objTd.style.fontSize=fontSize;

    //if (test1)
    //    test1.style.fontSize=fontSize;
    //if (test2)
    //    test2.style.fontSize=fontSize;
    //if (test3)
    //    test3.style.fontSize=fontSize;

    /*if (comment)
    {
        var commentDiv = comment.getElementsByTagName("div");
        var lineHeight = fontSize+Math.round(1.1*fontSize); 
    }

    fontSize = fontSize + "px";

    if (subject)
        subject.style.fontSize=fontSize;
    if (content)
        content.style.fontSize=fontSize; 
    if (wr_subject)
        wr_subject.style.fontSize=fontSize; 
    if (wr_content)
        wr_content.style.fontSize=fontSize; 
    if (commentDiv)
    {
        for (i=0;i<commentDiv.length;i++)
        {
            commentDiv[i].style.fontSize=fontSize;
        }
    }*/
}
// 글자크기 크게/작게 ( 2008.11.06 남정석 )



//----------------------------------------------
//Floating v1.1 Source By Bermann
//dobermann75@gmail.com
//----------------------------------------------

//new Floating(적용할개체 , X축여백 , Y축여백 , 미끄러지는속도:작을수록빠름..기본20 , 빠르기:작을수록부드러움..기본10);

function Floating(FloatingObj,MarginX,MarginY,Percentage,setTime) {
	this.FloatingObj = FloatingObj;
	this.MarginX = (MarginX) ? MarginX : 0;
	this.MarginY = (MarginY) ? MarginY : 0;
	this.Percentage = (Percentage) ? Percentage : 20;
	this.setTime = (setTime) ? setTime : 10;
	this.FloatingObj.style.position = "absolute";
	this.Body = null;
	this.setTimeOut = null;
	this.Run();
}

Floating.prototype.Run = function () {
	if ((document.documentElement.scrollLeft + document.documentElement.scrollTop) > (document.body.scrollLeft + document.body.scrollTop)) {
		this.Body = document.documentElement;
	} else {
		this.Body = document.body;
	}

	var This = this;
	var FloatingObjLeft = (this.FloatingObj.style.left) ? parseInt(this.FloatingObj.style.left,10) : this.FloatingObj.offsetLeft;
	var FloatingObjTop = (this.FloatingObj.style.top) ? parseInt(this.FloatingObj.style.top,10) : this.FloatingObj.offsetTop;
	var DocLeft = this.Body.scrollLeft + this.MarginX;
	var DocTop = this.Body.scrollTop + this.MarginY;

	var MoveX = Math.abs(FloatingObjLeft - DocLeft);
	MoveX = Math.ceil(MoveX / this.Percentage);
	var MoveY = Math.abs(FloatingObjTop - DocTop);
	MoveY = Math.ceil(MoveY / this.Percentage);

	if (FloatingObjLeft < DocLeft) {
		this.FloatingObj.style.left = FloatingObjLeft + MoveX + "px";
	} else {
		this.FloatingObj.style.left = FloatingObjLeft - MoveX + "px";
	}

	if (FloatingObjTop < DocTop) {
		this.FloatingObj.style.top = FloatingObjTop + MoveY + "px";
	} else {
		this.FloatingObj.style.top = FloatingObjTop - MoveY + "px";
	}

	window.clearTimeout(this.setTimeOut);
	this.setTimeOut = window.setTimeout(function () { This.Run(); },this.setTime);
}
//


//
function fnTodayViewDrug(gbn, obj1, obj2, obj3)
{
    if( obj3.value == "1" )
    {
        document.getElementById( 'today_1' ).style.display = "block";
    }
    else
    {
        if( gbn == "prev" )
        {
            if( parseInt(obj1.value) >= 1 )
            {
                obj2.value = obj1.value;
                obj1.value = parseInt(obj1.value) - 1;
                
                for( var i=1; i <= parseInt(obj3.value); i++ )
                {
                    var objTblID = "today_" + i;
                    var objTbl = document.getElementById( objTblID );
                    
                    if( parseInt(obj2.value) == i)
                    {
                        objTbl.style.display = "block";
                    }
                    else
                    {
                        objTbl.style.display = "none";
                    }
                }
            }
        }
        else if( gbn == "next" )
        {
            if( parseInt(obj2.value) < parseInt(obj3.value) )
            {
                obj1.value = obj2.value;
                obj2.value = parseInt(obj2.value) + 1;
                
                for( var j=1; j <= parseInt(obj3.value); j++ )
                {
                    var objTblID = "today_" + j;
                    var objTbl = document.getElementById( objTblID );
                    
                    if( parseInt(obj2.value) == j)
                    {
                        objTbl.style.display = "block";
                    }
                    else
                    {
                        objTbl.style.display = "none";
                    }
                }
            }
        }
    }
}
//

// 콩나물 지도 서비스 - 병의원 찾기
function viewMap()
{
	var aw = 800;
	var ah = 600;
	var openUrl = "http://medical.congnamul.com/MedicalMap/view/map.jsp?SIMPLEJOIN=21";	
	mapWindow = window.open(openUrl, "MedicalMapBrowser", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width="+aw+",height="+ah+",top=0,left=0");
}
// 콩나물 지도 서비스 - 병의원 찾기

function fnDivConvert(gbn, count, order)
{
    for( i = 1; i <= parseInt(count); i++)
    {
        //var val_Td = "td_" + gbn + "_" +i;
        var val_Div = "apDiv_" + gbn + "_" + i;
        //var objTd = document.getElementById( val_Td );
        var objDiv = document.getElementById( val_Div );
        
        if( i == parseInt(order) )
        {
            objDiv.style.display = "block";
            //objTd.className = "menu_ca01";
        }
        else
        {
            objDiv.style.display = "none";
            //objTd.className = "menu_ca";
        }
        
        if( gbn == "News" )
        {
            var var_Id = "mn0" + i;
            var objImg = document.getElementById( var_Id );
            
            if( i == parseInt(order) )
            {
                objImg.src = "/Images/Main/main_newstap_0" + i + "_o.gif";
            }
            else
            {
                objImg.src = "/Images/Main/main_newstap_0" + i + ".gif";
            }
        }
    }
}

function fnSearchBox(ctl)
{	
	var obj = document.getElementById( ctl );
	obj.style.backgroundImage = "none";

	return false;
}


function fnCopyUrl(url)
{
	var IE=(document.all) ? true: false;

	if(IE)
	{
		if(confirm("이 기사의 주소를 클립보드에 복사하시겠습니까?"))
		{
		    str_url = url.href;
		    text = window.clipboardData.setData("Text", str_url);
		}
	}
	else
	{
	    temp = prompt("이 기사의 주소입니다. Ctrl+C를 눌러 클립보드로 복사하세요", url);
	}
}
