﻿
    function resize_image(i, max) { if (!max) { max = 120; } if (i.width >= i.height && i.width > max) { i.width = max; } else if (i.width < i.height && i.height > max) { i.height = max; } }
    function on_noimage_img(obj) { ; }
    function tx_noimage_thumb() { ; }
    function news_resize_thumb() { ; }
    function goOtherCR() { ; }
    function include_script() { ; }
    function chkNewsDateSv() { ; }
    function kin_resize_thumb() { ; }
    var g_crt = "";
    var onload_post = ""

    function remove_image_table(target) { node = target.parentNode.parentNode; node.parentNode.removeChild(node); return; } 
    //nate
    function limit_imgsize_new() { ; }
    function ErrorThumb(obj, src, w, h) {
        if (obj) {
            obj.style.width = w;
            obj.style.height = h;
            obj.src = src;
        }
    }
    var nShow = false;
    var overdiv = 0;
    var bmove = 0;
    var timeid = "";
    function xT(contents, e, userstyle, w) {
        if (contents == "") return;
        if (contents == " ") return;
        if (contents == "  ") return;
        if (timeid) clearTimeout(timeid);
        var objxT = document.getElementById("obj_xT");
        objxT.style.left = -999
        objxT.style.top = -999
        if (!userstyle) {
            var div_string = "<div class='tooltip-content' style='width:400px'>" + contents + "</div>";
        } else {
            div_string = contents;
        }
        objxT.innerHTML = div_string;
        objxT.style.display = "block";
        Pos(e);
        overdiv = 0;
        nmove = 0;
        nShow = true;
        return;
    }
    function cT() {
        if (!overdiv) {
            var obj = document.getElementById("obj_xT");
            if (obj) {
                obj.style.display = "none";
            }
            nShow = false;
        }
        return;
    }
    function sT(e, havelink) {
        if (!nShow) return;
        if (!havelink || havelink != 1) {
            Pos(e)
        } else {
            if (bmove < 5) Pos(e)
            ++bmove
        }
        var obj = document.getElementById("obj_xT");
        if (obj) {
            obj.style.display = "block";
        }
        nShow = true;
        return;
    }

    function Pos(e) {
        var BodyWidth = document.body.scrollWidth - 200;
        var BodyLeft = document.body.scrollLeft;
        var BodyHeight = document.body.clientHeight;
        var BodyTop = document.body.scrollTop;
        var DivWidth = document.getElementById("obj_xT").scrollWidth;
        var DivHeight = document.getElementById("obj_xT").scrollHeight;
        xpos = e.clientX + BodyLeft + 11;
        ypos = e.clientY + BodyTop + 11;
        if (xpos + DivWidth > BodyWidth) xpos = BodyWidth - DivWidth;
        if (BodyLeft > xpos) xpos = BodyLeft + 10;
        if (ypos + DivHeight > BodyTop + BodyHeight) ypos = ypos - DivHeight - 10;
        if (ypos < BodyTop) ypos = BodyTop + 10;
        var obj = document.getElementById("obj_xT");
        if (obj) {
            obj.style.left = xpos
            obj.style.top = ypos
        }
    }
    function virtuallink(id) {
        return;
    }
    function UCCL() {
        return;
    }
    function NUCL() {
        return ;
    }
       function _jsVclipMouseMove() {
        return;
    }
    function onThumbnailLoad() {
        return;
    }
     
    //daum

   //moyer


    function getObject(objectId) {
        // checkW3C DOM, then MSIE 4, then NN 4. 
        if (document.getElementById && document.getElementById(objectId)) {
            return document.getElementById(objectId); // 대부분의 브라우저 
        } else if (document.all && document.all(objectId)) {
            return document.all(objectId); // IE4와 5.0 
        } else if (document.layers && document.layers[objectId]) {
            return document.layers[objectId];  // Netscape 4.x 
        } else {
            return false;
        }
    }

    // 탭 메뉴 이미지 변경
    function changeTabMenu(idx) {
        if (idx == "sbar_")
            idx = "sbar_all"; 
        var sel = getObject("" + idx + "");
        if (sel.parentNode.className == "") {
            sel.parentNode.className = "menu_on";
        } else {
            sel.parentNode.className += "menu_on";
        }
        var selSpan = sel.getElementsByTagName("span")[0];
          selSpan.innerHTML = "<strong>" + selSpan.innerHTML + "</strong>";
    }

    // 탭 메뉴 이미지 변경2
    function changeTabOut(idx, ov) {
        if (ov == "o") {
            try { getObject("tblit_" + (idx - 1) + "").style.visibility = "hidden"; } catch (e) { }
            try { getObject("tblit_" + idx + "").style.visibility = "hidden"; } catch (e) { }
        } else {
            try { getObject("tblit_" + (idx - 1) + "").style.visibility = ""; } catch (e) { }
            try { getObject("tblit_" + idx + "").style.visibility = ""; } catch (e) { }
        }
    }



    function goTabClick(linkObj, tab) {

        document.getElementById("recKeyword").innerHTML = "";
        document.getElementById("img_wait").style.display = "";
        document.getElementById("img_wait").style.top = 110;
        document.getElementById("img_wait").style.left = 100;
        
        var q = encodeURI(document.getElementById("query").value);// document.getElementById("hdnkeyword").value);
        
        if (tab=="all")
            linkObj.href = "search.aspx?where=" + tab + "&query=" + q;
        else
            linkObj.href = "search_sg.aspx?w=" + tab + "&q=" + q; //naver =>where,query
       
        document.location.href = linkObj.href;
    }



    function ftKeyDown(div) {
        k = event.keyCode;
        if (k == 13) {
            ftSearchOpen(null, div);
            event.returnValue = false;
        }
        else {
            event.returnValue = true;
        }
    }
    function ftSearchOpen(ctext,div) {

        var obj = document.getElementById('query');
        if (obj == null)
            obj = document.getElementById('TopControl1_query');
        var obj1 = document.getElementById('query1');
            
        if (ctext == null || typeof (ctext) == "undefined") {
            if (div==0)
            {
                ctext = obj.value;
            }
            else
                ctext = obj1.value;
            
        }
        if (ctext == "") return;
        document.getElementById("autocomp").style.display = "none";
        try {
            document.getElementById("recKeyword").innerHTML = "";
            document.getElementById("img_wait").style.display = "";
            document.getElementById("img_wait").style.top = 110;
            document.getElementById("img_wait").style.left = 100;
        }catch(e){};
        
        var cook = getCookie("query_history");
        var cooks = cook.split("|");
        var cook = "";
        var cook1 = "";
        if (ctext.length > 10)
            cook1 = ctext.substr(0, 10);
        else
            cook1 = ctext;
        cook = cook1 + "|";
        var cookdisp = "<a href=\"javascript:ftSearchOpen('" +  encodeURI(ctext) + "')\" >" + cook1 + "</a> | ";
        var cnt = 0;
        for (i = 0; i < cooks.length; i++) {
            if (cooks[i] != "" && cooks[i] != cook1) {
                cook += cooks[i] + "|";
                cookdisp += "<a href=\"javascript:ftSearchOpen('" + cooks[i] + "')\" >" + cooks[i] + "</a> | ";

            }
            if (++cnt == 10)
                break;
        }
        setCookie("query_history", cook, 300);
        if (cnt > 0)
            cookdisp = cookdisp.substr(0, cookdisp.length - 2);
//        document.getElementById('recKeyword').innerHTML = cookdisp;
        obj.value = ctext;
        if (obj1 != null) {
            obj1.value = ctext;
        }
        document.forms[0].submit();

    }
    function setCookie(CookieName, CookieValue, CookieDay) {
        var objCookieTime = new Date();
        objCookieTime.setTime(objCookieTime.getTime() + (CookieDay * 86400 * 1000));
        if (CookieDay) CookieDay = "expires=" + objCookieTime.toGMTString() + ";";
        else CookieDay = "";
        document.cookie = CookieName + "=" + CookieValue + "; " + CookieDay;
    }

    function getCookie(name) {
        var prefix = name + "=";
        var cookieStartIndex = document.cookie.indexOf(prefix);
        if (cookieStartIndex == -1)
            return "";
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
        if (cookieEndIndex == -1)
            cookieEndIndex = document.cookie.length;
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
    }


    var autokeyword = "";
    function ftKeyUp() {

        var obj = document.getElementById("query");
        var obj1 = document.getElementById("autocomp");
        if (obj == null) {
            obj = document.getElementById("TopControl1_query");
        }
        k = event.keyCode;
        if (k == 27) {
            obj.value = "";
        }
        else if (k == 40) { //down
            if (obj1.childNodes.length == 0) return;
            var ct = obj.value;
            for (i = 0; i < obj1.childNodes.length; i++) {
                obj1.childNodes[i].style.backgroundColor = "#ffffff";
                if (obj1.childNodes[i].innerText == ct) {
                    if (obj1.childNodes.length > i + 1) {
                        obj.value = obj1.childNodes[i + 1].innerText;
                        obj1.childNodes[i + 1].style.backgroundColor = "#eeeeee";
                        ++i;
                    }
                }
            }
            if (ct == obj.value) {
                obj.value = obj1.childNodes[0].innerText;
                obj1.childNodes[0].style.backgroundColor = "#eeeeee";
            }
        }
        else if (k == 38) { //up
            if (obj1.childNodes.length == 0) return;
            var ct = obj.value;
            for (i = obj1.childNodes.length - 1; i >= 0; i--) {
                obj1.childNodes[i].style.backgroundColor = "#ffffff";
                if (obj1.childNodes[i].innerText == ct) {
                    if (i > 0) {
                        obj.value = obj1.childNodes[i - 1].innerText;
                        obj1.childNodes[i - 1].style.backgroundColor = "#eeeeee";
                        --i;
                    }
                }
            }
            if (ct == obj.value) {
                obj.value = obj1.childNodes[obj.childNodes.length - 1].innerText;
                obj1.childNodes[obj1.childNodes.length - 1].style.backgroundColor = "#eeeeee";
            }
        }
        else if (k == 13 || k > 32 && k < 41 || k == 45) {

        }

        else {
            if ( k ==229) return;
            var ct = obj.value;

            if (ct == "" || ct == autokeyword) return;
            autokeyword = ct;
            $.ajax({
                type: "POST",
                url: "ajax.aspx",
                data: { "site": "autoComp", "keyword": ct },
                dataType: "text",
                timeout: 10000,
                error: function() {
                    //alert("error");
                },
                success: function(rt) {
                    if (rt != "") {
                        var asp = rt.split(",");
                        cts = "";
                        for (i = 0; i < asp.length; i++) {

                            cts += "<div style='height:20px'  onmousemove='ftAutoMouseover(this)' onmouseout='ftAutoMouseout(this)' onmousedown='ftAutoClick(this)' >" + asp[i].replace(ct, "<font color='#ff6600'>" + ct + "</font>") + "</div>";
                        }
                        obj1.style.height = 20 * asp.length + 20;

                        obj1.innerHTML = cts;
                        obj1.style.display = "";

                    }
                }
            });

        }
    }
    function ftAutoMouseover(obj) {
        obj.style.backgroundColor = "#eeeeee";
    }
    function ftAutoMouseout(obj) {
        obj.style.backgroundColor = "#ffffff";
    }

    function ftAutoClick(obj) {
        var obj = document.getElementById("query");
        var obj1 = document.getElementById("autocomp");
        if (obj == null) {
            obj = document.getElementById("TopControl1_query");
        }
        obj.value = obj.innerText;
        obj1.style.display = "none";
        ftSearchOpen(null, 0);

    }





