﻿/******************************************************************************
만든이     : 한현수
작성일     : 2008.09.22
최종수정일 : 2008.09.22
프로젝트명 : 웹전용 자바스크립트 라이브러리
모듈명     : 웹에서 사용되는 자바스크립트 함수 모음들 정리.
수정내용   : 
2008.10.01 findid(mode, options) 아이디 찾기
2008.10.01 findpwd(mode, options) 비밀번호 찾기
2008.10.01 findidpwd(mode, options) 아이디 비밀번호 찾기
******************************************************************************/

// 게시판리스트
// 검색
function brds_search() {
	var frm = document.frmlist;

	if (frm.searchkey.value == 0) {
		alert("검색 항목을 선택해주세요.");
		frm.searchkey.focus();
		return;
	}
	if (frm.searchvalue.value == "") {
		alert("검색 내용을 입력해주세요.");
		frm.searchvalue.focus();
		return;
	}

	var ctg = "";
	if (document.getElementById("cntscate_1") != null && document.getElementById("cntscate_1").value > 0) {
		ctg = document.getElementById("cntscate_1").value;
	}
	else {
		if (document.getElementById("cntscate_0") != null && document.getElementById("cntscate_0").value > 0) {
			ctg = document.getElementById("cntscate_0").value;
		}
	}

	location.href = frm.action + "&search_cntscate=" + ctg + "&searchkey=" + encodeURI(frm.searchkey.value) + "&searchvalue=" + encodeURI(frm.searchvalue.value);
}

// 날림으로 만들었다...ㅠㅠ 동적으로 배열생성하게 해서, 동적으로 초기화 되게 만들어야 한다.
// 연관된 Select 박스 초기화
function put_cntsctg(ctg_depth, initvalue1, initvalue2) {
	if (ctg_depth == '0') {
		for (i1 = ctg_depth; eval("window.ctg_" + i1 + "_key"); i1++)		// 해당 배열이 존재하는지 여부
		{
			var array_key = eval('ctg_' + i1 + '_key');
			var array_value = eval('ctg_' + i1 + '_value');
			var select_box = document.getElementById('cntscate_' + i1);

			for (i = 0; i < window.put_cntsctg.arguments.length; i++)	// 동적 파라미터 처리
			{
				//alert(window.put_cntsctg.arguments[i]);
			}

			for (i = 0; i < array_key.length; i++)						// Select 박스에 배열값 추가
			{
				var len = select_box.length;
				var opt = new Option(array_key[i], array_value[i]);
				if (opt.value == initvalue1)
					opt.selected = true;

				select_box.options[len] = opt;
			}
			//ChangeArrayCity(initvalue2);

			// 연관된 Select 박스 동기화 함수 추가
			//select_box.onchange = window.change_cntsctg('');//new Function('',"alert('"+i1+"')");
		}
	}
	else {
		if (eval("window.ctg_" + initvalue1 + "_key")) {
			var array_key = eval('ctg_' + initvalue1 + '_key');
			var array_value = eval('ctg_' + initvalue1 + '_value');
			document.getElementById('cntscate_1').options.length = 1;

			for (i = 0; i < array_key.length; i++) {
				var len = document.getElementById('cntscate_1').length;
				var opt = new Option(array_key[i], array_value[i]);
				if (opt.value == initvalue2)
					opt.selected = true;

				document.getElementById('cntscate_1').options[len] = opt;
			}
		}
		else {
			//		var cnt = document.getElementById('cntscate_1').length;
			//
			//		for (i=1; i<cnt; i++)
			//		{
			//			//alert(i);
			//			document.getElementById('cntscate_1').remove(i);
			//			
			//			.length;
			//			var opt = new Option(array_key[i], array_value[i]);
			//			if (opt.value == initvalue2)
			//				opt.selected = true;
			//			
			//			document.getElementById('cntscate_1').options[len] = opt;
			//		}
		}
	}
}
// 연관된 Select 박스 동기화
function change_cntsctg(initvalue2) {
	if (initvalue2 == '0') {
		var idx = document.getElementById('cntscate_0').selectedIndex;
		var value = document.getElementById('cntscate_0').options[idx].value;

		if (String(idx) != '0' && String(idx) != '-1') {
			put_cntsctg('1', value, initvalue2);
		}
	}
}
put_cntsctg('0', '', '');
/*****************************************************************************/

// 동적 파일 첨부
function addFileUI(maxcount) {
	var objTbl = document.all["tblAttFiles"];

	if (objTbl.rows.length < maxcount) {
		var objRow = objTbl.insertRow();
		var objCell = objRow.insertCell();

		objCell.innerHTML = "<input type='checkbox' name='cbx1' value='" + objTbl.rows.length + "'>&nbsp;<input type='file' name='files' style='width:553px' class='board_ctl1'>";
	}
}
// 동적 파일 삭제
function delFileUI() {
	var objTbl = document.all["tblAttFiles"];
	var objChk = document.all["cbx1"];
	var allRow = objTbl.rows;

	for (var i = allRow.length - 1; i >= 0; i--) {
		if (isNaN(objChk.length)) {
			if (objChk.checked) objTbl.deleteRow();
		}
		else {
			if (objChk[i].checked) objTbl.deleteRow(i);
		}
	}
}

/*****************************************************************************/
// 로그인
function login_exec(redirecturl) {
	var frm = document.form1;
	frm.action = COZA_CONFIG.COZA_URL + "/Member_Login_Exec.asp?redirecturl=" + encodeURIComponent(redirecturl);
	frm.encoding = "application/x-www-form-urlencoded";

	if (document.getElementById("login_id") != null && !document.getElementById("login_id").getAttribute("value").mem_id(4, 12)) {
		alert("[회원 아이디]가 올바르지 않습니다.");
		document.getElementById("login_id").focus();
		return;
	}
	if (document.getElementById("login_pwd") != null && !document.getElementById("login_pwd").getAttribute("value").mem_pwd(4, 12)) {
		alert("[회원 비밀번호]가 올바르지 않습니다.");
		document.getElementById("login_pwd").focus();
		return;
	}

	frm.submit();
}

/*****************************************************************************/
// 로그아웃
function logout_exec(redirecturl) {
	location.href = COZA_CONFIG.COZA_URL + "/member.asp?exec=logout&redirecturl=" + encodeURIComponent(redirecturl);
}

// 아이디/비밀번호 찾기
function findidpwd(mode, options) {
	if (mode == 'popup') {
		var win = window.open(COZA_CONFIG.MEM_SKIN_URL + "/findidpwd_popup.asp", "findidpwd", "scrollbars=0, width=400, height=300");
		win.focus();
	}
	else
		location.href = COZA_CONFIG.COZA_URL + "/member.asp?exec=findidpwd";
}

// 아이디 찾기
function findid(mode) {
	alert(1);
	if (mode == "popup") {
		var win = window.open(COZA_CONFIG.MEM_SKIN_URL + "/findid_popup.asp", "findid", "scrollbars=0, width=400, height=300");
		win.focus();
	}
	else
		location.href = COZA_CONFIG.COZA_URL + "/member.asp?exec=findid";
}

// 비밀번호 찾기
function findpwd(mode) {
	if (mode == "popup") {
		var win = window.open(COZA_CONFIG.MEM_SKIN_URL + "/findpwd_popup.asp", "findpwd", "scrollbars=0, width=400, height=300");
		win.focus();
	}
	else
		location.href = COZA_CONFIG.COZA_URL + "/member.asp?exec=findpwd";
}

// 비밀번호 변경
function changepwd(mode) {
	if (mode == "popup") {
		var win = window.open(COZA_CONFIG.MEM_SKIN_URL + "/changepwd_popup.asp", "changepwd", "scrollbars=1, width=400, height=300");
		win.focus();
	}
	else
		location.href = COZA_CONFIG.COZA_URL + "/member.asp?exec=findpwd";
}

// 회원가입
function mem_regi() {
	location.href = COZA_CONFIG.COZA_URL + "/member.asp?exec=regi";
}

// 우편번호 변경
function findzipcode() {
	var win = window.open(COZA_CONFIG.MEM_SKIN_URL + "/findzipcode.asp", "findzipcode", "width=416,height=300, toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=0");
	win.focus();
}

function checkid(mem_id) {
	//	if (mem_id != null && !mem_id.getAttribute("value").mem_id(4, 12)) {
	//		alert("[회원 아이디]가 올바르지 않습니다.");
	//		mem_id.focus();
	//		return;
	//	}

	//var win = window.open(COZA_CONFIG.MEM_SKIN_URL + "/checkid.asp?id=" + mem_id.value, "checkid", "width=400,height=150, top=250, left=400, toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0");
	var win = window.open(COZA_CONFIG.MEM_SKIN_URL + "/checkid.asp?id=", "checkid", "width=400,height=300, top=250, left=400, toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0");
	win.focus();
}

// SMS 발송
function sms_popup_win() {
	var win = window.open(COZA_CONFIG.COZA_URL + "/SMS.asp?exec=main", "sms", "width=209, height=538, left=650, top=50");
	win.focus();
}

// 새창으로 이미지 미리보기
function view_original_image(imageurl) {
	var win = window.open(COZA_CONFIG.COZA_URL + "/Lib/util/view_original_image.asp?imageurl=" + imageurl, "originalimage", "width=800, height=600, scrollbars=yes, resizeable=yes, status=no, menubar=no, toolbar=no");
	win.focus();
}

// 댓글 저장
function comment_save_exec(BRD_ID, BRD_SEQ, min, max) {
	var frm = document.form1;
	frm.action = COZA_CONFIG.COZA_URL + "/Board_cmt_write_exec.asp?exec=cmt_write&BRD_ID=" + BRD_ID + "&BRD_SEQ=" + BRD_SEQ;
	frm.encoding = "application/x-www-form-urlencoded";

	if (document.getElementById("cmt_cnts").getAttribute("value").wlen() < min) {
		alert("[내용]을 " + min + "자 이상 입력해주세요.");
		frm.cmt_cnts.focus();
		return;
	}
	if (document.getElementById("cmt_cnts").getAttribute("value").wlen() > max) {
		alert("[내용]을 " + max + "자 이하로 입력해주세요.");
		frm.cmt_cnts.focus();
		return;
	}
	frm.submit();
}

// 댓글 삭제
function comment_del_exec(BRD_ID, BRD_SEQ, SEQ) {
	if (window.confirm("삭제하시겠습니까?")) {
		var frm = document.form1;
		frm.action = COZA_CONFIG.COZA_URL + "/board_cmt_del_exec.asp?exec=cmt_del&brd_id=" + BRD_ID + "&brd_seq=" + BRD_SEQ + "&seq=" + SEQ;

		frm.submit();
	}
}

// 글삭제
function del(BRD_ID, BRD_SEQ, page) {
	var frm = document.form1;
	frm.action = COZA_CONFIG.COZA_URL + "/board_del_exec.asp?EXEC=DEL&BRD_ID=" + BRD_ID + "&BRD_SEQ=" + BRD_SEQ;

	if (window.confirm("정말로 [삭제]하시겠습니까?")) {
		frm.submit();
	}
}

// 글읽은회원 히스토리 보기
function view_access_log(brd_id, brd_seq, mem_seq) {
	var win = window.open(COZA_CONFIG.COZA_URL + "/lib/util/view_access_log.asp?BRD_ID=" + brd_id + "&BRD_SEQ=" + brd_seq + "&MEM_SEQ=" + mem_seq, "access_log", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=460,height=400")
	win.focus();
}

// 팝업공통(회원약관, 개인정보보호정책)
function js_popup(url, title, args) {
	var win = window.open(url, title, args);
	win.focus();
}


//#############################################################################
// Textarea 높이크기 조절
//#############################################################################
function reset_textarea(id, height) {
	document.getElementById(id).style.pixelHeight = height * 20;
}

function resize_textarea(id, height) {
	height = height * 20;

	nowheight = document.getElementById(id).style.pixelHeight;

	if (nowheight + height <= 20) {
		height = 20;
	}
	else {
		height = nowheight + height;
	}

	document.getElementById(id).style.pixelHeight = height;
}

//#############################################################################
// 풍선 도움말
//#############################################################################
function help(id, mode) {
	var help_id = document.getElementById(id);

	help_id.style.backgroundColor = "ffff00";
	help_id.style.pixelLeft = event.x + 10;
	help_id.style.pixelTop = event.y + 10;

	if (mode == "show") {
		help_id.style.display = "";
	}
	else {
		help_id.style.display = "none";
	}
}
