﻿/*******************************************************************
	프로젝트명	:	serakorea.com
	파	  일	명	:	/Script/jsGeneralFunction.js
	기	  능	명	:	전 사이트 공통 함수 보관
	이			력	:	2007.10.17	남궁만 생성
********************************************************************/

document.domain = "serakorea.com";

/*******************************************************************
// 함수 Index

	01.	chkEmptyString	: 빈 문자열 체크
	
	02.	chkNumeric		: 숫자 체크
	
	03.	chkOpener			: 정상적인 오프너 체크
	
	04.	fnSetResizeFrm	: 현 페이지의 크기 만큼 Parent의 IFRAME Resize
	
	05.	fnGetCookie		: 쿠키 반환
	
	06.	fnSetCookie		: 쿠키 설정
	
	07.	fnGetMsIVersion	: 브라우져 버젼 확인
	
	08.	fnGetPopHeight	: 팝업 사이즈 변경 
********************************************************************/


//------------------------------------------------------------------
//	함수명	: 01. chkEmptyString
//	기능명	: 빈 문자열 체크
//	이	  력	: 2007.10.17 남궁만 생성
//------------------------------------------------------------------
function chkEmptyString(value) {

		var strTemp = value.split(" ").join("");
		strTemp = strTemp.split('\r\n').join("");
		
		if (strTemp == "") {
			return false;
		}

		return true;
}


//------------------------------------------------------------------
//	함수명	: 02. chkNumeric
//	기능명	: 숫사 여부 체크
//	이	  력	: 2007.10.17 남궁만 생성
//------------------------------------------------------------------
function chkNumeric(value) {
	var temp = new String(value)
		
	if(temp.search(/\D/) != -1) {
		return false;
	}
	return true;
}


//------------------------------------------------------------------
//	함수명	: 03. chkOpener
//	기능명	: 정상적인 오프너 체크
//	이	  력	: 2007.10.17 남궁만 생성
//------------------------------------------------------------------
function chkOpener(strCurrentDomain)
{
	var checkurl = "";
	
	if (window.opener) 
	{
		checkurl = window.opener.location.href;
			
		if (checkurl.indexOf(strCurrentDomain, 0) == -1) 
		{
			alert ('정상적인 접근 경로가 아닙니다.');
			self.close();
		}
	}
	else 
	{
		alert ('정상적인 접근 경로가 아닙니다.');
		self.close();
	}
}


//------------------------------------------------------------------
//	함수명	: 04. fnSetResizeFrm
//	기능명	: 현 페이지의 크기 만큼 Parent의 IFRAME Resize
//	이	  력	: 2007.10.17 남궁만 생성
//------------------------------------------------------------------
function fnSetResizeFrm(width) {
	var oBody = document.body;
	var min_height = 140; //iframe의 최소높이(너무 작아지는 걸 막기위함, 픽셀단위, 편집가능)

	var i_height = oBody.scrollHeight + (oBody.offsetHeight-oBody.clientHeight) + getPopHeight();
	
	window.resizeTo(width, i_height);
}


//------------------------------------------------------------------
//	함수명	: 05. fnGetCookie
//	기능명	: 쿠키 반환
//	이	  력	: 2007.10.17 남궁만 생성
//------------------------------------------------------------------
function fnGetCookie( name ) {
	var nameOfCookie = name + "=";
	var x = 0;
	while ( x <= document.cookie.length )
	{
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
				endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}
		x = document.cookie.indexOf( " ", x ) + 1;
		if ( x == 0 )
			break;
	}
	return "";
}

//------------------------------------------------------------------
//	함수명	: 06. fnSetCookie
//	기능명	: 쿠키 설정
//	이	  력	: 2007.10.17 남궁만 생성
//------------------------------------------------------------------
function fnSetCookie(name, value, ExpireDate) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + ExpireDate );
	document.cookie = name + "=" + escape( value ) + "; path=/;domain=huxleylab.com;expires=" + todayDate.toGMTString() + ";"
	//document.cookie = name + "=" + escape( value ) + ";path=/;expires=" + todayDate.toGMTString() + ";"
}


///-----------------------------------------------------------------
/// 함수명	: 07. fnGetMsIVersion
/// 기능명 : 브라우져 버젼 확인
/// 이   력 : 2007.10.17 남궁만 생성
///-----------------------------------------------------------------
function fnGetMsIVersion()
{
	var ua = window.navigator.userAgent
	var msie = ua.indexOf ( "MSIE " )

	if ( msie > 0 )      // If Internet Explorer, return version number
		return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
	else                 // If another browser, return 0
		return 0
}

//-----------------------------------------------------------------
/// 함수명	: 08. fnGetPopHeight
/// 기능명 : 팝업 사이즈 변경 
/// 이   력 : 2007.10.17 남궁만 생성
//-----------------------------------------------------------------
function fnGetPopHeight()
{
	var version = fnGetMsIVersion();
	var iHeight = 73;
	
	if (version == 7 )
	{
		iHeight += 17;
	}

	return iHeight;	
}

//-----------------------------------------------------------------
/// 함수명	: 09. PopUpOpen
/// 기능명 : 팝업 오픈
/// 이   력 : 2007.11.26 손지인 생성
//-----------------------------------------------------------------
function PopUpOpen(sUrl,sName,sWidth,sHeight,bScroll,bResize)
{
	var sScroll = "no";
	var sResize = "no";
	if(bScroll) sScroll = "yes";
	if(bResize) sResize = "yes";
	
	window.open(sUrl, sName,"width=" + sWidth + ",height=" + sHeight + ",scrollbars=" + sScroll + ",resizable=" + sResize + ",status=no,toolbar=no,menubar=no"); 
}

//공백 제거
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g,"");
}