﻿function getNowTime()
{
    var time = new Date();
    var yyyy = time.getFullYear();
    var mm = time.getMonth() + 1;
    var dd = time.getDate();
    var hh = time.getHours();
    var nn = time.getMinutes();
    var ss = time.getSeconds();

    var tm = "am";
    if ((hh - 12) > 0)
    {
        hh -= 12;
        tm = "pm";
    }

    if (mm < 10) { mm = "0" + mm; }
    if (dd < 10) { dd = "0" + dd; }
    if (hh < 10) { hh = "0" + hh; }
    if (nn < 10) { nn = "0" + nn; }
    if (ss < 10) { ss = "0" + ss; }

    //var timeString = "Current Date. " + yyyy + "." + mm + "." + dd + " | " + tm + " " + hh + ":" + nn + ":" + ss;
    var timeString = yyyy + "." + mm + "." + dd + " | " + tm + " " + hh + ":" + nn + ":" + ss;

    document.getElementById("viewNowTime").innerHTML = timeString;

    window.setTimeout("getNowTime();", 1000);
}

/****** 팝업 ******/
var popupCount = 0;
function popupOpen(cookieName, url, width, height, top, left) {

    popupCount++;

    try {
        if (getCookie(cookieName) == "")
        {
            var options = "toolbar=0";
            options += ",scrollbars=0";
            options += ",menubar=0";
            options += ",resizable=0";
            options += ",width=" + width;
            options += ",height=" + height;
            if (top != null)
                options += ",top=" + top;
            if (left != null)
                options += ",left=" + left;

            window.open(url, cookieName + "_" + popupCount, options)
        }
    }
    catch (err)
    {
        alert(err.message);
    }

    return false;
}

function popupLayer(cookieName, content, w, h, topPos, leftPos)
{
    try
    {
        if (findCookie(cookieName) == false)
        {
            if ($('#' + cookieName).size() > 0)
            {
                $('#' + cookieName + ' .popupContent').css({ width: w, height: h });
                $('#' + cookieName + ' .popupActionBox').css({ width: w });
                $('#' + cookieName).css({ top: topPos, left: leftPos }).show();

                return false;
            }

            var layer = $("<div id='" + cookieName + "' class='popupLayer'><div class='popupContent'>" + content +
                    "</div><div class='popupActionBox'><label><input type='checkbox' id='chkToday' name='chkToday' class='" + cookieName +
                    "' />오늘하루만 보기</label><a class='close' href='#'>[닫기]</a></div></div>");

            $('.popupContent', layer).css({ width: w, height: h, overflow:'auto' });
            $('.popupActionBox', layer).css({ width: w });
            $('.popupActionBox a.close', layer).click(
                    function()
                    {
                        var chk = $(":checked", layer);
                        if (chk.size() == 1)
                            setCookie(chk.attr("class"), "1", 1);

                        $(layer).hide();
                    });

            $('body div:first').append(layer);

            layer.css({ top: topPos, left: leftPos }).show();
        }
    }
    catch (err)
    {
        alert(err.message);
    }

    return false;
}

function popupWindow(cookieName, contentSn, w, h, topPos, leftPos)
{
    try {
        // 팝업창 닫기 높이 고려.
        popupOpen(cookieName, "/common/popup.aspx?cSn=" + contentSn, w, h+20, topPos, leftPos);
    }
    catch (err)
    {
        alert(err.message);
    }

    return false;
}

/* list row over/out style */
function overRow(ctl, isfocus)
{
    if (ctl.tagName == "TR") {
        $(ctl).find("td").addClass("overRow");
//        var arr = ctl.getElementsByTagName("td");
//        for (var i = 0; i < arr.length; i++)
//            arr[i].style.backgroundColor = "#efefef";
    }
    else {
        $(ctl).addClass("overRow");
//        ctl.style.backgroundColor = "#efefef";
//        if (isfocus != null)
//            ctl.style.cursor = "hand";
    }
}

function outRow(ctl, isfocus)
{
    if (ctl.tagName == "TR") {
        $(ctl).find("td").removeClass("overRow");
//        var arr = ctl.getElementsByTagName("td");
//        for (var i = 0; i < arr.length; i++)
//            arr[i].style.backgroundColor = "#fff";
    }
    else {
        $(ctl).removeClass("overRow");
//        ctl.style.backgroundColor = "#fff";

//        if (isfocus != null)
//            ctl.style.cursor = "pointer";
    }
}


/* TinyMCE
**************************************/
function tinyEditor_insertAttach(editorId, url, clientFilename)
{    
    var inst = tinyMCE.getInstanceById(editorId);
    if (inst == null)
        return;

    var tagString = "";
    var className = "";
    if (/\.(gif|png|bmp|jpg|jpeg|tif|tiff)$/.test(url))
    {
        inst.execCommand('mceInsertContent', false, "<img src='" + url + "' alt='' />");
        return;
    }
    else if (/\.swf$/.test(url))
    {
        className = "mceItemFlash";
    }
    else if (/\.dcr$/.test(url))
    {
        className = "mceItemFlashVideo";
    }
    else if (/\.(mov|qt|mpg|mp3|mp4|mpeg)$/.test(url))
    {
        className = "mceItemShockWave";
    }
    else if (/\.(avi|wmv|wm|asf|asx|wmx|wvx)$/.test(url))
    {
        className = "mceItemWindowsMedia";
    }
    else if (/\.(rm|ra|ram)$/.test(url))
    {
        className = "mceItemRealMedia";
    }
    else
    {
        inst.execCommand('mceInsertContent', false,
	             "<a href='" + url + "' target='_blank'>" + clientFilename + "</a>");
        return;
    }

    tagString = "<img class=\"mceItemFlash\" " +
	            "class=\"" + className + "\" " +
	            "title=\"src:'" + url + "'\" ,width:'100',height:'100'" +
	            "src=\"/_skins/tiny_mce/plugins/media/img/trans.gif\" " +
	            "style=\"width: 100px; height: 100px;\" " +
	            "mce_src=\"/_skins/tiny_mce/plugins/media/img/trans.gif\" _moz_resizing=\"true\" />";

    inst.execCommand('mceInsertContent', false, tagString);
}


function tinyEditor_removeAttach(strId, filePath)
{
    try
    {
        var ptn = "";

        if (/\.(gif|png|bmp|jpg|jpeg|tif|tiff)$/i.test(filePath))
        {
            ptn = "<img[^<]*src=(?:|'|\")(.*)" + filePath + "(?:|'|\")(.?)[^>]*>";
        }
        else if (/\.(swf|dcr|mov|qt|mpg|mp3|mp4|mpeg|avi|wmv|wm|asf|asx|wmx|wvx|rm|ra|ram)$/i.test(filePath))
        {
            ptn = "<object([^>]*)>\n(.*)(" + filePath + ")(.*)\n</object>";
        }
        else
        {
            ptn = "<a[^<]*href=(?:|'|\")(.*)" + filePath + "(?:|'|\")(.?)[^>]*>([^<>])*</a>";
        }
        var re = new RegExp(ptn, 'gi');
        var inst = tinyMCE.getInstanceById(strId);
        if (inst != null)
        {
            inst.getWin().focus();
            var contents = inst.getContent();
            contents = contents.replace(re, "");
            inst.setContent(contents);
        }
    } catch (e) { alert("alert => " + e.message); }
}

function tinyEditor_addImage_auto(strId, filePath)
{
    var ptn = "<div[^<](.*)</div>";
    var re = new RegExp(ptn, 'gi');
    var inst = tinyMCE.getInstanceById(strId);
    var contents = $get(strId).value;

    contents = contents.replace(re, "$1");
    contents = "<div>" + contents + "<img src='" + filePath + "' /><div>";
    inst.setContent(contents);
}

/* 퀵메뉴
******************************************************************/
function quickMoving(ele, interval)
{
    this.element = ele;
    this.defaultTop = parseInt($(ele).css('top').replace('px', ''));
    this.interval = interval;

    var local = this;
    this.move = function()
    {
        $(local.element).stop().animate({ top: ($(this).scrollTop() + local.defaultTop) + 'px' }, local.interval);
    };

    $(window).load(this.move).resize(this.move).scroll(this.move);
}





/* popup */
function openGuestBook()
{
    openWindow('scroll', '/common/guestbook.aspx', { widnowName: 'guestbook', width: 680, height: 700 });
}

function openUbco()
{
    openWindow('scroll', '/common/ubco.aspx', { widnowName: 'ubco', width: 640, height: 700 });
}

function openVisitRequest()
{
    openWindow('scroll', '/common/visitRequest.aspx', { widnowName: 'visitRequest', width: 640, height: 490 });
}


function openVolunteerProgram()
{
    openWindow('scroll', '/common/volunteerProgram.aspx', { widnowName: 'volunteerProgram', width: 800, height: 500 });
}

function openZipCode(ctl)
{
    ctl.blur();
    openWindow('scroll', '/common/searchZipCode.aspx', { widnowName: 'ZipcodeSearch', width: 500, height: 550 });
}

/**********/
function getQueryString(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}
/**********/


