﻿/* @@@@@@@@@@@@@@@@@@@@@@@@@@@ 기능 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
function bookmark(url, title)
{
    window.external.AddFavorite(url, title);
}

var isIE = is_IE();

function is_IE()
{
	if(navigator.appName && navigator.appName.indexOf("Microsoft") != -1)
		return true;
	else
		return false; 
}

function get_body_scroll()
{
    var x,y;
    if (self.pageYOffset) 
    {
        x = self.pageXOffset;
        y = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    {
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    }
    else if (document.body) 
    {
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    }
    var result = new Object;
    result.left = x;
    result.top = y;
    return result;
}


function get_body_inner_size()
{
    var result = new Object;
    if(self.innerWidth)
    {
        result.width = self.innerWidth;
        result.height = self.innerHeight;
        return result;
    }
    else if (document.documentElement && document.documentElement.clientHeight) 
    {
        result.width = document.documentElement.clientWidth;
        result.height = document.documentElement.clientHeight;
        return result;
    }            
    else if (document.body) { 
        result.width = document.body.clientWidth;
        result.height = document.body.clientHeight;
        return result;
    }
}

// convert pixel data to integer
function ConvertP2I(pixel)
{
	return parseInt( pixel.replace("px", "") );
}

/* 
(left, top)      (right, top)
    *----------------*
    |                |
    |                |
    *----------------*
(left, bottom)   (left, bottom) 
 */
 

function GetPositionLeft(element){
	var x = 0;
	do {
		if (element.style.position == 'absolute') {
			return x + element.offsetLeft; 
		}
		else{
			x += element.offsetLeft;
			if (element.offsetParent) 
			if (element.offsetParent.tagName == 'TABLE') 
			if (parseInt(element.offsetParent.border) > 0){
				x += 1; 
			}
		}
	}
	while ((element = element.offsetParent));
	return x; 
}


function GetPositionTop(element){
	var y = 0;
	do{
		if (element.style.position == 'absolute'){
			return y + element.offsetTop; 
		}
		else{
			y += element.offsetTop;
			if (element.offsetParent) 
			if (element.offsetParent.tagName == 'TABLE') 
			if (parseInt(element.offsetParent.border) > 0){
				y += 1; 
			}
		}
	}
	while ((element = element.offsetParent));
	return y; 
}

function GetPositionRight(element)
{
    return GetPositionLeft(element) + element.offsetWidth;
}

function GetPositionBottom(element)
{
    return GetPositionTop(element) + element.offsetHeight;
}

function AttachEvent(obj, evt, func, useCapture)
{
	if(!useCapture) useCapture = false;
	if(obj.addEventListener)
	{
		obj.addEventListener(evt, func, useCapture);
	}
	else if(obj.attachEvent)
	{
		obj.attachEvent('on'+evt, func);
	}
}
function DettachEvent(obj, evt, func, useCapture)/*{{{*/
{
	if(!useCapture) useCapture = false;
	if(obj.removeEventListener)
	{
		obj.removeEventListener(evt, func, useCapture);
	}
	else if(obj.detachEvent)
	{
		obj.detachEvent('on'+evt, func);
	}
}

function StopEvent(e) 
{
	if(!e) var e = window.event;
	if( isIE )
	{
	    e.cancelBubble = true;
	    e.returnValue = false;
	}

	if (e.stopPropagation) 
	{
	//alert(e.stopPropagation);
		e.stopPropagation();
		e.preventDefault();
	}
	return false;
}

/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ function script end @@@@@@@@@@@@@@@@@@@@@@@@@ */

/* checkbox list API */
function SelectAll(key, isSelect)
{
    var elements = document.forms[0].elements; 
    for( var i=0 ; i < elements.length ; ++i )
    {
        if( elements[i].id.indexOf(key) > -1 && elements[i].type == 'checkbox' )
            elements[i].checked = isSelect;
    }
}

// string trim --- value.trim();
String.prototype.trim = function() 
{ 
 return this.replace(/(^\s*)|(\s*$)/g, ""); 
}

String.prototype.bytes2 = function()
{
        var str = this;
        var l = 0;
        for( var i = 0; i < str.length; i++ ) 
		{
			if( str.charCodeAt( i ) == 13 ) continue;
			l += ( str.charCodeAt( i ) > 128 ) ? 2 : 1;
		}
        return l;
}

String.prototype.replaceAll = function(str1, str2)
{
      var temp_str = "";

      if (this.trim() != "" && str1 != str2)
      {
        temp_str = this.trim();

        while (temp_str.indexOf(str1) > -1)
        {
          temp_str = temp_str.replace(str1, str2);
        }
      }

      return temp_str;
}



function OpenStandardWindow(url)
{
    if( url.indexOf("http://") == -1 )
        url = "http://" + url;

    var size = get_body_inner_size();
	window.open(url, 'popup', 'toobar=1,scrollbars=1,menubar=1,resizable=1,width=' + size.width + ',height=' + size.height ) 
}

function OpenFullSizeWindow(url)
{
    var size = get_body_inner_size();
	window.open(url, 'popup', 'toobar=0,scrollbars=1,menubar=0,resizable=1,width=' + size.width + ',height=' + size.height ) 
}

function OpenWindow( url, w, h )
{
	window.open(url, 'popup', 'toobar=0,scrollbars=1,menubar=0,resizable=1,width=' + w + ',height=' + h ) 
}

function OpenWindow( url, windowName, w, h )
{
	window.open(url, windowName, 'toobar=0,scrollbars=1,menubar=0,resizable=1,width=' + w + ',height=' + h ) 
}

function OpenWindowScroll( url, windowName, w, h )
{
	window.open(url, windowName, 'toobar=0,scrollbars=1,menubar=0,resizable=0,width=' + w + ',height=' + h ) 
}

function OpenWindowFix( url, windowName, w, h )
{
	window.open(url, windowName, 'toobar=0,scrollbars=0,menubar=0,resizable=0,width=' + w + ',height=' + h ) 
}

function RequiredData(ctlId, msg)
{
    var ctl = document.getElementById(ctlId);
    if( ctl.value.trim().length == 0 )
    {
        alert(msg);
        ctl.focus();
        return false;
    }
    
    return true;
}

function ProcessAlert(msg, ctl)
{
    alert(msg);    
    document.getElementById(ctl).focus();
}

function ConfirmWindow(msg)
{
    if (!confirm(msg)) return false;
}

function GetNowTime()
{

    var time = new Date();
    var yyyy = time.getFullYear();
    var mm = time.getMonth() + 1;
    var dd = time.getDate();
    var hh = time.getHours();
    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;}
    var nn = time.getMinutes();
    if(nn < 10) {	nn = "0" + nn;}
    // var ss = time.getSeconds();  
    // if(ss < 10) {	ss = "0" + ss;}

    //Current Data. 2006.07.06 | am 12:00
    var timeString = "Current Date. " + yyyy + "." + mm + "." + dd + " | " + tm + " " + hh + ":" + nn;// + ":" + ss;


    document.getElementById("viewNowTime").innerHTML = timeString;
    
    window.setTimeout("getNowTime();", 1000*60);	
}

function getCookie(name) 
{ 
    var Found = false; 
    var start, end; 
    var i = 0; 
    var foundString;
    // cookie 문자열 전체를 검색 
    while(i <= document.cookie.length) 
    { 
        start = i 
        end = start + name.length 
        // name과 동일한 문자가 있다면 
        foundString = document.cookie.substring(start, end);
        if(foundString == name) 
        {
            Found = true;
            break;
        } 
        i++;
    } 
    
    // name 문자열을 cookie에서 찾았다면 
    if(Found == true) 
    { 
        start = end + 1 
        end = document.cookie.indexOf(";", start) 
        
        // 마지막 부분이라 는 것을 의미(마지막에는 ";"가 없다) 
        if(end < start) 
            end = document.cookie.length;
        // name에 해당하는 value값을 추출하여 리턴한다. 
        foundString = unescape(document.cookie.substring(start, end));
       
        return unescape(document.cookie.substring(start, end));
    } 
    
    // 찾지 못했다면 
    return "";
} 

function setCookie( name, value, expiredays ) 
{ 
    var todayDate = new Date(); 
    todayDate.setDate( todayDate.getDate() + expiredays ); 
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
} 

//쿠키 소멸 함수
function clearCookie(name) {
var expire_date = new Date();
//어제 날짜를 쿠키 소멸 날짜로 설정한다.
expire_date.setDate(expire_date.getDate() - 1)
document.cookie = name + "= " + "; expires=" + expire_date.toGMTString() + "; path=/"
}

//체크 상태에 따라 쿠키 생성과 소멸을 제어하는 함수. 새 창 닫기
function controlCookiePopup(name, Instance) {
	var CookieName = name;
	
	setCookie(CookieName,"true", 1) ;
	self.close();
}

//체크 상태에 따라 쿠키 생성과 소멸을 제어하는 함수, 윈도우 내 윈도우 닫기
function controlCookieWindow(Index, Instance) {
	var CookieName = "NoticeBoard"+Index	
	setCookie(CookieName,"true", 1) ;
}

function setHomePage(ctl, link) 
{
    ctl.style.behavior='url(#default#homepage)';
    ctl.setHomePage(link);
}

/*
function overRow(ctl, color)
{
    ctl.style.backgroundColor=color;
}
*/



/*
    마우스 오른쪽 클릭 방지, 복사 방지
*/


function UnableMouseRightClick(mouse) 
{
    if (document.all) 
    { 
        if (event.button==2||event.button==3) 
        {
            alert("오른쪽 마우스를 사용할수 없습니다.");
            return false;
        } 
    }

    if (document.layers)    
    { 
        if (mouse.which == 3) 
        {
            alert("오른쪽 마우스를 사용할수 없습니다.");
            return false;
        } 
    }
}

function InitUnableMouseRightClick()
{
    if (document.layers) 
    {
        document.captureEvents(Event.MouseDown);//protect from keyboard keypress

        function keypressed() 
        {
            alert("키작동이 안됩니다. \n\n복사 할수 없어요 ! 아임소리"); 
        }
    }

    document.onmousedown=unableMouseRightClick;
    document.onkeydown=keypressed;
}

function OverRow(ctl)
{ ctl.style.backgroundColor = '#FAF9F4'; }

function OutRow(ctl)
{ ctl.style.backgroundColor = '#FFFFFF'; }

function AutoFormFocus()
{
    var target;
    for( var i=0; i < document.forms[0].elements.length ; ++i )
    {
        target = document.forms[0].elements[i];       
        
        if( target.tagName == 'INPUT' && (target.type == 'text' || target.type == 'password') && target.disabled == false)
        {
            try {
            target.focus();
            } catch(e) { }
            return;
        }
    }           
    
    //GernerateAllBluring();             
}

function GernerateAllBluring()
{
    var target = document.getElementsByTagName('a');
    for( var i=0; i < target.length ; ++i )
    {
        if( target[i].childNodes.length == 1 && target[i].childNodes[0].tagName == "IMG")
            AttachEvent(target[i], "focus", function() { eval("this.blur();"); }, false);
    }   
    
//    target = document.getElementsByTagName('img');
//    for( var i=0; i < target.length ; ++i )
//    {           
//        AttachEvent(target[i], "focus", function() { target[i].blur(); }, false);            
//    }  
}

/// -------------------- 사용자 -------------------------------///
function IsSendDsFormat(hourCtlId, minuteCtlId)
{
    var hourCtl = document.getElementById(hourCtlId);
    var minuteCtl = document.getElementById(minuteCtlId);
    
    if( IsNumber(hourCtl.value) == false )
    {
        alert( '시간이 숫자형식이 아닙니다.');
        hourCtl.focus();
        return false;
    }
    
    if( IsNumber(minuteCtl.value) == false )
    {
        alert('분이 숫자형식이 아닙니다.');
        minuteCtl.focus();
        return false;
    }
    
    var hour = parseInt(hourCtl.value);
    var minute = parseInt(minuteCtl.value);
    
    if( hour < 0 || hour > 24 )
    {
        alert( '시간은 0~24 사이의 숫자이어야 합니다.');
        hourCtl.focus();
        return false;
    }
    
    if( minute < 0 || minute > 60 )
    {
        alert('분은 0~60사이의 숫자이어야 합니다.');
        minuteCtl.focus();
        return false;
    }
    
    return true;
}

// Tooltip
function ViewTooltip(ctl, msg)
{
    var table = document.createElement("table");
    table.id = "tblAlertList";
    table.className = "Tooltip";
    table.style.position = "absolute";
    table.style.display = "block";
    table.style.top = (GetPositionTop(ctl) + 5) + "px";
    table.style.left = (GetPositionRight(ctl) + 5) + "px";
    
    var tbody = document.createElement("tbody");
    var row = document.createElement("tr");
    var cell = document.createElement("td");
    cell.style.backgroundColor = "#FFFFFF";
    cell.style.textAlign = "left";
    cell.innerHTML = msg;        
    
    row.appendChild(cell);
    tbody.appendChild(row);
    table.appendChild(tbody);
    
    ctl.onmouseout = HideTooltip;
    document.body.appendChild(table);
    
    //alert(ctl.id  + ", " + GetPositionTop(ctl) + ", " + GetPositionRight(ctl));
    //alert(msg);
}

function HideTooltip()
{
    var table = document.getElementById("tblAlertList");
    if( table != null )
    {
        document.body.removeChild(table);    
    }
}

//
//  Ajax 로딩
//
function ViewLoading(ctlId)
{
    var ctl = document.getElementById(ctlId);
    var height = ctl.offsetHeight/2;    
    var loading = document.createElement("div");
    
	loading.id = ctlId + "View";	
	loading.style.backgroundColor = "#FFFFFF";	
	loading.style.textAlign = "center";
	loading.style.verticalAlign = "middle";	
	loading.style.width = (ctl.offsetWidth) + "px";
	loading.style.left = GetPositionLeft(ctl) + "px";
	loading.style.top = GetPositionTop(ctl) + "px";		
	loading.style.height = (height+1) + "px";	
	loading.style.zIndex = "9999";	
	loading.style.position = "absolute";
	loading.style.paddingTop = (ctl.offsetHeight - height) + "px";
	//loading.style.textAlign = "right";
	//loading.style.verticalAlign = "top";
	loading.innerHTML = "<img src='/Skin/Default/Images/Common/loading8.gif' style='border:none;' />";
	
	if(isIE)
	    loading.style.filter = "alpha(opacity='85')";
	else
		loading.style.opacity = 0.9;
		
	document.body.style.cursor = "wait";
	document.body.appendChild(loading);
}

function HideLoading(ctlId)
{
    var loadingCtl = document.getElementById(ctlId + "View");
    document.body.removeChild(loadingCtl);
    
    document.body.style.cursor = "default";	    
}

function overRow(ctl, color)
{
    ctl.style.backgroundColor=color;
}