﻿/////////////////////////////////////////////////////////////////////////////////
/////                                                                       /////
/////     KIMS OnLine Common JavaScript (KIMS OnLine 공통 자바스크립트)     /////
/////                                                                       /////
/////            작성자 : 남정석        최초 작성일 : 2008.06.04            /////
/////            수정자 : 남정석        최종 수정일 : 2008.12.03            /////
/////                                                                       /////
/////////////////////////////////////////////////////////////////////////////////


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)";
    }
    else
    {
        if( obj.value == "" )
            obj.style.backgroundImage="url(..//images/Common/input_pw.gif)";
    }
}
// 텍스트 박스 이미지 제어 ( 2008.06.05 남정석 )

// 로그인 시 사용 ( 2008.06.04 남정석 )
function fnLoginCheck(objTxtID, objTxtPW)
{
    if( objTxtID != undefined && objTxtPW != undefined )
    {
        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");
        }
        
        return true;
    }
    else
    {
        return false;
    }
}

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=www.kimsonline.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=www.kimsonline.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=www.kimsonline.co.kr; expires="+expire.toGMTString();
    }
}
// 아이디 저장 쿠키 값 설정 ( 2008.06.05 남정석 )

// 검색조건 및 검색어 입력 확인 ( 2008.06.04 남정석 )
function fnSearchCheck(objOpt, objTxtSrh, objMoh, objKIMSClass, objForm, objMedicationChannel, objProductType, objInsurance, objDoubleGeneric, objATC)
{
    if( objTxtSrh.value == "" )
    {
        alert("검색어를 입력해 주세요.");
        objTxtSrh.focus();
        return false;
    }
    else
    {
        if( objTxtSrh.value.length < 2 )
        {
            alert("두 글자 이상의 검색어를 입력해 주세요.");
            objTxtSrh.value = "";
            objTxtSrh.focus();
            return false;
        }
        
        if( !fnInputTextChk(objTxtSrh) )
        {
            alert("입력하신 검색어중 잘못된 문자가 포함되어 있습니다.\n다시 입력해 주세요.");
            objTxtSrh.value = "";
            objTxtSrh.focus();
            return false;
        }
    }
    
    location.href = "/DrugSearch/search_result.aspx?Opt=" + escape(objOpt.value) + "&Key=" + escape(objTxtSrh.value);
    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, obj2);
    }
}
// 엔터키 입력 확인 ( 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;
        }
    }
}
// 숫자 입력 확인 ( 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=/; domain=www.kimsonline.co.kr; expires=" + today.toGMTString() + ";";
}

function get_cookie(name) 
{d
    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("kol_fontsize"));
    
    if (isNaN(fontSize))
    {
        fontSize = 12;
    }
    
    return fontSize;
}

function scaleFont(val)
{
    var fontSize = getFontSize();
    var fontSizeSave = fontSize;
    
    if (val > 0)
    {
        if (fontSize <= 18)
        {
            fontSize = fontSize + val; 
        }
    }
    else
    {
        if (fontSize > 12)
        {
            fontSize = fontSize + val; 
        }
    }
    if (fontSize != fontSizeSave)
    {
        drawFont(fontSize);
    }
    
    //set_cookie("kol_fontsize", fontSize, 30);
    set_cookie("kol_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");
    
    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 fnFileDataView(code, item, filenm) {
    window.open("/501_Etc/PopFileDataView.aspx?KIMSCode=" + code + "&Detailing=" + item + "&FileNm=" + filenm, "popup", "toolbar=no,menubar=no,status=no,width=900,height=700");  //
}

function fnGoTwitter(str) {
    //    window.open("http://twitter.com/home?status=" + str, "_blank", "toolbar=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, scroll=yes, width=800,height=500");
    window.open("/omniture/rss.aspx?tp=twitter&url=" + str, "_blank", "toolbar=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, scroll=yes, width=800,height=500");
}

function fnSNSEmail(str) {
    window.open("/omniture/rss.aspx?tp=email&url=" + str, "_blank", "toolbar=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, scroll=yes, width=400,height=267");
}
 


function fnValidateWord(obj)
{
    forbiddenchars = new RegExp("[<>\'\"]","gi");
    //obj.value = obj.value.replace(forbiddenchars,"");
    if(forbiddenchars.test(obj.value) == true)
    { 
        alert("특수 문자를 사용할수 없습니다. 정확한 한글 또는 영문을 입력해주세요");
        return false;
    }
    return true;
}

function fnBytesLength(str)
{
    var l = 0;
    for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
    return l;
}


function fnBytesCutLength(str,substringLength)
{
    var cnt = 0;
    for (var i=0; i<substringLength; i++)  (str.charCodeAt(i) > 128) ? cnt++ : cnt;
    
    return substringLength-cnt;
}
