// 상태표시줄
var msg = '동행자 찾기';
var csPathVirtual = "/gangje_find";

function hidestatus() {
	window.status= msg;
	return true
}

if (document.layers)
document.captureEvents(Event.mouseover | Event.mouseout | Event.mousedown | Event.mouseup | Event.mousemove)
document.onmouseover=hidestatus
document.onmouseout=hidestatus
document.onmousedown=hidestatus
document.onmouseup=hidestatus
document.onmousemove=hidestatus

statuss();

function statuss() {
	window.status = msg;
	setTimeout("statuss()", 600);
}

// 링크의 포커스를 없앤다
function bluring() { 
	if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus(); 
} 
document.onfocusin=bluring;


// 새창열기
var win = null;
function NewWin(url,winname,w,h,scroll) {
	winToTop = 30;
	winToLeft = 30;
	
	making = 'height='+h+',width='+w+',top='+winToTop+',left='+winToLeft+',scrollbars='+scroll+',resizable'
	win = window.open(url,winname,making);
}


// 공백제거
function jsCheckValue(checkStr) {
	var FPoint=checkStr.indexOf(" ");	
	while(FPoint != -1) {
		checkStr = checkStr.replace(" ", "");
		FPoint  = checkStr.indexOf(" "); 
	}
	return (checkStr.length);
}

// 영문 체크 함수 (영문 외의 값이 있으면 false)
function jsCheckAlpha(checkStr) { 
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	for (i = 0;  i < checkStr.length;  i++) { 
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
			return false;
	}
	return true;
}

// 영문, 숫자 체크 함수 (영문,숫자 외의 값이 있으면 false) 
function jsCheckAlphaNumeric(checkStr) { 
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	for (i = 0;  i < checkStr.length;  i++)
	{ 
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
			return false;
	}
	return true;
}

function jsCheckResno(sSsn1, sSsn2)
{
	var sResno, sFmt
	var sBirth, sBirthYear, sBirthMonth, sBirthDate
	
  sResno = sSsn1 + '-' + sSsn2;

  // 주민번호의 형태와 7번째 자리(성별) 유효성 검사
  sFmt = /^\d{6}-[1234]\d{6}$/;
  if (!sFmt.test(sResno)) {
		return false;
  }

  // 날짜 유효성 검사
  sBirthYear = (sResno.charAt(7) <= "2") ? "19" : "20";
  sBirthYear += sResno.substr(0, 2);
  sBirthMonth = sResno.substr(2, 2) - 1;
  sBirthDate = sResno.substr(4, 2);
  sBirth = new Date(sBirthYear, sBirthMonth, sBirthDate);
  if ( sBirth.getYear() % 100 != sResno.substr(0, 2) ||
       sBirth.getMonth() != sBirthMonth ||
       sBirth.getDate() != sBirthDate) {
    return false;
  }

  // Check Sum 코드의 유효성 검사
  buf = new Array(13);
  for (i = 0; i < 6; i++) buf[i] = parseInt(sResno.charAt(i));
  for (i = 6; i < 13; i++) buf[i] = parseInt(sResno.charAt(i + 1));
  multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
  for (i = 0, sum = 0; i < 12; i++) sum += (buf[i] *= multipliers[i]);
  if ((11 - (sum % 11)) % 10 != buf[12]) {
    return false;
  }

  return true;
}

// 이메일 체크 함수
function jsIsEmail(s) 
{
	return s.search(/^\s*[\w\~\-\.]+\@[\w\~\-]+(\.[\w\~\-]+)+\s*$/g)>=0;
}

//숫자만 입력 체크
function jsCheckNumber() {
	var objEv = event.srcElement;
    var numPattern = /([^0-9^\-])/;
    numPattern = objEv.value.match(numPattern);
    if(numPattern != null){
        alert("숫자만 입력해 주세요!");
        objEv.value="";
        objEv.focus();
        return false;
    }
}

// 숫자 체크 함수 (숫자 외의 값이 있으면 false)
function jsCheckNumeric(x) 
{
	for(i=0;i<x.length;i++) {
		var a=x.charCodeAt(i);
		if(a < 48 || a > 57) {
			return false;
		}
	}
	return true;
}

//로그인 시 허용하지 않는 문자열 체크 
function jsValidate(pInput) {

	var bad_strings = new Array( "'", "select", "union", "insert", "--", "&quot;", "/", "\\", ";", ":", "+", "=", " ", "<", ">", "(", ")", "[", "]" );

	for (i = 0;  i < 19; i++)
	{
		if (pInput.indexOf(bad_strings[i]) >= 0)
		{
			return false;
			break;
		}
	}

	return true;
}

// Top Menu 상단 검색
function jsFind() {
	if (jsCheckValue(document.frmSearch.pFind.value) < 1) {
		alert("검색어를 입력해 주세요.");
		document.frmSearch.pFind.focus();
		return;
	}
	document.frmSearch.submit();         
}

// Top Menu 상단 검색의 Enter처리
function jsFindEnter() {
	if (window.event.keyCode == 13) {	    // 엔터가 들어오면
		window.event.keyCode = 0;           // 이벤트 무효화
		jsFind();
	}  
}

// 트리에서 자신이 속한 분류까지 펼치기 
function jsMenuFullDisplay(pSEQ) {
	var iTotCnt;
	var iCnt;

	iTotCnt = pSEQ.length / 3

	for (iCnt=2; iCnt<=iTotCnt; iCnt++) {
		jsMenuDisplay(pSEQ.substr(0, iCnt * 3));
	}
}

// 트리에서 하위메뉴 펼치기
function jsMenuDisplay(tmpID) {
	oTargetDiv = document.all(tmpID);
	oSignName = document.all("sign_" + tmpID);

	if(oTargetDiv.style.display != "none") {
		oTargetDiv.style.display="none";
		if (oSignName.src.indexOf(csPathVirtual + "/images/left/tr_lastminus.gif") > 0) {
			oSignName.src = csPathVirtual + "/images/left/tr_lastplus.gif";
		} else {
			oSignName.src = csPathVirtual + "/images/left/tr_plus.gif"
		}
	} else {
		oTargetDiv.style.display = "";
		if (oSignName.src.indexOf(csPathVirtual + "/images/left/tr_lastplus.gif") > 0) {
			oSignName.src = csPathVirtual + "/images/left/tr_lastminus.gif"
		} else {
			oSignName.src = csPathVirtual + "/images/left/tr_minus.gif"
		}
	}
}

// 로그인 창 열기 함수
function jsLogin(URL, STR, PAGE)
{
	popupWin(csPathVirtual + "/member/login/login.asp?pUrl=" + URL + "&pStr=" + STR + "&pPage=" + PAGE, "로그인", 360, 200);
}

// 로그아웃
function jsLogout() {
	location.href = csPathVirtual + "/member/login/logout.asp";
}

// 새창에서 본창 페이지 바꾸기
function jsChangeLocation(pUrl, pIsClose) {
	opener.location.target = "opener";
	opener.location.href = pUrl;
	opener.focus();
	if (pIsClose == '1') {
		self.close();
	}
}

//팝업창을 띄운다
function popupWin(url, name, width, height)
{
    var features;
    var t = screen.height / 2 - height / 2;
    var l = screen.width / 2 - width / 2;
    var option = "toolbar=no,menubar=no,location=no,scrollbars=no,status=no,resizable=no,maximize=no";

    features = "top=" + t + ",left=" + l + ",width=" + width + ",height=" + height + "," + option;

    var PopupWin = window.open(url, name, features);
    if (PopupWin) PopupWin.focus();
}

//스크롤 바 있는 팝업창 띄우기
function popupWinScroll(url, name, width, height)
{
    var features;
    var t = screen.height / 2 - height / 2;
    var l = screen.width / 2 - width / 2;

    if (width * 1 >= 750)
    {
        t -= 30;
    }

    var option = "toolbar=no,menubar=no,location=no,scrollbars=yes,status=no,resizable=yes";

    features = "top=" + t + ",left=" + l + ",width=" + width + ",height=" + height + "," + option;

    var PopupWinS = window.open(url, name, features);
    if (PopupWinS) PopupWinS.focus();

}


/********************************************************/
/*	툴팁 관련
/********************************************************/
/* 
 * 기능 : 툴팁 보이기
 * 파라미터
 *   - this, event는 그대로 넘기고 text만 지정한다.
 * 사용예 : onMouseover='showTip(this, event, "생산현황보고")' onMouseout='hideTip()'
 */
function showTip(current, e, text)
{
    if (document.all)
    {
        current.title = removeStr(text, '<br>');
    }
    else if (document.layers)
    {  
        tooltip = window.createPopup();
        tooltip.document.write('<layer class="tooltip"><table bgcolor="#FFFFFF" width="100%"><tr><td class="tooltip">' + text + '</td></tr></table></layer>');
        tooltip.document.close();
        tooltip.left = e.pageX + 5;
        tooltip.top = e.pageY + 5;
        tooltip.visibility = "show";
    }
}

/* 
 * 기능 : 툴팁 숨기기
 * 사용예 : onMouseover='showTip(this, event, "생산현황보고")' onMouseout='hideTip()'
 */
function hideTip()
{
    if (document.layers)
        document.tooltip.visibility = "hidden";
}

/* 
 * 기능 : 상태창비우기
 */
function ResetStatus()
{
    window.status = "";
}

/*
 * 기능 : 상태창에 표시하기
 */
function ChngStatus(value)
{
    window.status = value;
}

/* 
 * 기능 : 문자열삭제
 * 파라미터
 *   - beforeStr : 삭제하기 전의 문자열, - deleteStr : 삭제할 문자열
 * 사용예 : removeStr("abcdefgh", "bcd") -> aefgh
 */
function removeStr(beforeStr, deleteStr)
{
    aStr = beforeStr.split(deleteStr);
    afterStr = '';
    for (i = 0; i < aStr.length; i++)
        afterStr += aStr[i];
    return afterStr;
}