﻿/*****************************************************************************************
' @File : /include/js/util.js
' @Description	 : 기본관련 함수
' @Author by		 : 유성훈
' @Date				 : 2011 - 02 - 14
' ********************************************************************************************/


/****************************************************************************
	Basic Control
*****************************************************************************/
function isElement(object)		{ return (object && object.nodeType == 1); }
function isArray(object)		{ return (object != null && typeof object == "object" && 'splice' in object && 'join' in object); }
function isNull(object)			{ return (object == null); }
//function isEmpty(object)		{ var i, v; if(isObject(object)){ for (i in object){ v = object[i]; if(isUndefined(v) && isFunction(v)){ return false; }}} return true; }
function isEmpty(object)		{ if(object == null || object.length == 0 || object == ''){ return true; }else{ return false; } }
function isFunction(object)		{ return (typeof object == "function"); }
function isString(object)		{ return (typeof object == "string"); }
function isNumber(object)		{ return (typeof object == "number"); }
function isUndefined(object)	{ return (typeof object == "undefined"); }
function isObject(object)		{ return (object && typeof object == 'object') || isFunction(object); }
function isChkIE()				{ if (navigator.appName == "Microsoft Internet Explorer") isIE = true; else isIE = false; return isIE; }

/*
-- Jquery 충돌로 주석처리 pes
function $(element){
	if(arguments.length > 1) {
		for(var i=0, elements=[], length=arguments.length; i < length; i++)
			elements.push($(arguments[i]));
		return elements;
	} else {
		if(isString(element))
			element = document.getElementById(element);
		return element;
	}
}
*/
function show(element)	{ $(element).style.display = 'block'; }
function hide(element)	{ $(element).style.display = 'none'; }
function toggle(element){
	element = $(element);
	if(element.style.display == 'none')	{ show(element); }
	else								{ hide(element); }
}
/****************************************************************************/



/****************************************************************************
	Popup Control
*****************************************************************************/
function openPopup(){
	var fnUrl       = ( arguments[0] || "" );               // 팝업시킬 asp 파일을 경로까지 줌
    var fnName      = ( arguments[1] || "" );               // 팝업 명 ( default : PageTitle )

    var fnWidth     = ( arguments[2] || "400" );            // width		( default : 400 )
    var fnHeight    = ( arguments[3] || "400" );            // height		( default : 400 )
    var fnTop       = ( arguments[4] || "0" );              // Top			( default : 0 )
    var fnLeft      = ( arguments[5] || "0" );              // Left			( default : 0 )
    var fnPOPType   = ( arguments[6] || "0" );              // Scroll 등등	( default : 0 - 사용,1 - 미사용 )

    /*
    alert('fnUrl : '		+ fnUrl    );
    alert('fnName : '		+ fnName   );
    alert('fnWidth : '		+ fnWidth  );
    alert('fnHeight : '		+ fnHeight );
    alert('fnTop : '		+ fnTop    );
    alert('fnLeft : '		+ fnLeft   );
    alert('fnPOPType : '	+ fnPOPType);
	*/
	//openPopup(fnUrl,fnName,fnWidth,fnHeight,fnTop,fnLeft,fnPOPType)


    var fnPopupObj;

    if ( fnUrl != "" ) {

        var windowOption    = ""
                            + "scrollbars="     + fnPOPType
                            + ",toolbar="       + fnPOPType
                            + ",location="      + fnPOPType
                            + ",directories="   + fnPOPType
                            + ",status="        + fnPOPType
                            + ",menubar="       + fnPOPType
                            + ",resizable="     + fnPOPType
                            + ",top="           + fnTop
                            + ",left="          + fnLeft
                            + ",width="         + fnWidth
                            + ",height="        + fnHeight
                            + "";
		
		fnPopupObj = window.open( fnUrl , fnName, windowOption);
        fnPopupObj.focus();
	}
}

// 팝업 닫기
function closePopup(){
	top.close();
}

// 팝업 사이즈 조정
function autoResize(){
	try {
        var byWidth = document.getElementById('bodySize').clientWidth - document.documentElement.clientWidth;
        var byHeight = document.getElementById('bodySize').clientHeight - document.documentElement.clientHeight;
        window.resizeBy(byWidth, byHeight);
    }
    catch( e )  {}
}
/****************************************************************************/


/****************************************************************************
	Date Control
*****************************************************************************/
// 년월일
function getToDay(){
	var date = new Date();

	var year  = date.getFullYear();
	var month = date.getMonth() + 1; // 1월=0,12월=11이므로 1 더함
	var day   = date.getDate();

	if (("" + month).length == 1) { month = "0" + month; }
	if (("" + day).length   == 1) { day   = "0" + day;   }

	return "" + year + "-" + month + "-" + day;
}

// 년월일 구분자 변경하기
function getDateFormat(){
	
	//입력날짜가 Null 이거나 날짜형태가 아닌경우
	var strDate		= ( arguments[0] || getToDay() );
	var strinitial	= ( arguments[1] || "-");

	var ti,arrOrgDate,arrCnt;
	var tDate = "";

	if( strDate.indexOf("-") >= 0 ){
		arrOrgDate  = strDate.split("-");
		arrCnt		= arrOrgDate.length;
	}
	else if( strDate.indexOf(".") >= 0 ){
		arrOrgDate  = strDate.split(".");
		arrCnt		= arrOrgDate.length;
	}
	else if( strDate.indexOf("/") >= 0 ){
		arrOrgDate  = strDate.split("/");
		arrCnt		= arrOrgDate.length;
	}

	if( isArray(arrOrgDate) == true ){
		for(ti=0 ; ti<arrCnt; ti++) {
			tDate = tDate + arrOrgDate[ti];
			if( arrCnt-1 > ti ){ tDate = tDate + strinitial; }
		}
	}else{
		tDate = strDate;
	}

	return tDate;
}
/****************************************************************************/
/****************************************************************************
	MPlayer DownLoad Url
*****************************************************************************/
// Mplayer Download
function goToMPlayerSetup(){
		window.open("http://code.mnet.com/WebPage/OutUrl/mplayersetup.asp","mplayer","");
}

