/**
 * 클래스명 : Web()
 *
 */
Web = function () {
	// 교재 div 객체정보
	this._BOOK_DIV;

	// 코멘트 모드
	this._MEMOMODE = "P";
	this._MEMOPAGE = "1";
	this._MEMOURL = "";
	this._MEMOPARAM = "";
	this._MEMODELURL = "";
	this._MEMOOBJ;

	// 메일발송
	this._SENDMINURL= "";
	this._SENDPARAM = "";
	this._SENDOBJ;

	// 유선전화 국번
	this._PHEADNUM = new Array("02", "031", "032", "033", "041", "042", "043", "051", "052", "053", "054", "055", "061", "062", "063", "064", "070");

	// 핸드폰 통신사번호
	this.CHEADNUM = new Array("010", "011", "016", "017", "018", "019");

	// 이메일
	this.EMAIL = new Array("naver.com", "paran.com", "nate.com", "daum.net", "hanmail.net", "yahoo.co.kr", "netian.com", "hotmail.com", "lycos.co.kr", "dreamwiz.com", "hanafos.com");

	// 로그인
	this.Login = function () {
		document.location.href = MyLib.TopDir + "/member/login.asp?r=" + ((location.pathname.substr(1, 6) == "member") ? "/" : escape(location.pathname + location.search));
	}

	// 로그인 (빠른 수강신청)
	this.LoginApp = function () {
		document.location.href = MyLib.TopDir + "/member/login.asp?r=" + ((location.pathname.substr(1, 6) == "member") ? "/" : escape(location.pathname + location.search)) + "&appcheck=Y";
	}

	// 로그아웃
	this.Logout = function () {
		MyLib.UrlLink(MyLib.TopDir + "/member/logout.asp", "로그아웃 하시겠습니까?");
	}

	// 로그인 체크
	this.LoginCheck = function () {
		if (confirm("로그인후 사용 가능합니다.\n\n로그인 하시겠습니까?")) {
			document.location.href = MyLib.TopDir + "/member/login.asp?r=" + ((location.pathname.substr(1, 6) == "member") ? "/" : escape(location.pathname + location.search));
		} else {
			return;
		}
	}

	// 우편번호 검색
	this.SearchPostNum = function (frm, postName, Obj1, Obj2, PostNumName, Address1Name, Address2Name) {
		var _Rtn = "";

		// 폼네임
		var frmName = frm.name;

		if (!postName.value) {
			window.alert("주소를 입력하세요");
			postName.value = "";
			postName.focus();
			return;
		} else if (postName.value.length < 2) {
			window.alert("주소를 2글자 이상 입력하세요");
			postName.value = "";
			postName.focus();
			return;
		}

		// 전달할 파라메타
		var param = {
						PostNumName			: postName.value
				}

		// json 개체를 쿼리스트링 형식으로 변경합니다.
		param		= $H(param).toQueryString();

		// xml 실행
		new Ajax.Request(
							"/member/searchPostNum.asp",
							{
								method		: "post",
								asynchronous: false,
								parameters	: param,
								encoding	: "UTF-8",
								onComplete	: function(OriRuquest) { _Rtn = OriRuquest.responseText; }
							}
						);

		// 결과값
		var res = _Rtn.substr(0, 4);

		if (res == "NONE") {
			alert("검색된 정보가 없습니다");

			// 레이어 변경
			Obj1.style.display = "";
			Obj2.style.display = "none";

			return;
		} else {
			// 레이어 변경
			Obj1.style.display = "none";
			Obj2.style.display = "";

			// 내용삭제
			Obj2.innerHTML = "";

			// 결과값 배열로 만들기
			var searchPostNum = _Rtn.split("|");

			// 저장될 HTML 초기화
			var insertHtml = "";

			var tableHtml = ("<table cellspacing=\"0px\" cellpadding=\"0px\">"
					+ "<tr>"
					+ "	<td><a href=\"#\" class=\"select_text select_over\" onfocus=\"blur()\" onclick=\"Web.SearchPostNumInsert('{CHANGEVALUE}', document." + frmName + ", '" + PostNumName + "', '" + Address1Name + "', '" + Address2Name + "');return false;\">{CHANGENAME}</a></td>"
					+ "</tr>"
					+ "</table>");

			// 셀렉트 박스 출력
			for (var i = 1; i <= searchPostNum.length; i++) {
				// 가공
				var htmlVar		= tableHtml.replace("{CHANGEVALUE}", searchPostNum[i - 1]).replace("{CHANGENAME}", searchPostNum[i - 1].replace(/\^/gi, " "))

				insertHtml		= insertHtml + htmlVar;
			}

			Obj2.innerHTML = insertHtml;
			return;
		}
	}

	// 우편번호 검색
	this.SearchPostNumInsert = function (addressValue, frm, PostNumName, Address1Name, Address2Name) {
		if (!addressValue) {
			return;
		}

		// 주소관련 정보 가공하기
		var allAddress = addressValue.split("^");

		// 주소가공
		var addressVal = allAddress[1] + " " + allAddress[2] + " " + allAddress[3];
      
		// alert(allAddress[0]);	  
	  
		// 우편번호 값 넣기
		$(PostNumName).value = allAddress[0];

		// 주소값 넣기
		$(Address1Name).value = addressVal;

		// 포커스
		$(Address2Name).value="";

		// 포커스
		$(Address2Name).focus();
	}

	// 전화번호 셀렉트 박스
	this.PhoneSelect = function (SelectVal) {
		for (var i = 0; i < this._PHEADNUM.length; i++) {
			document.write('<option value="' + this._PHEADNUM[i] + '"' + (this._PHEADNUM[i] == SelectVal ? ' selected' : '') + '>' + this._PHEADNUM[i] + '</option>');
		}
	}

	// 핸드폰 셀렉트 박스
	this.MobileSelect = function (SelectVal) {
		for (var i = 0; i < this.CHEADNUM.length; i++) {
			document.write('<option value="' + this.CHEADNUM[i] + '"' + (this.CHEADNUM[i] == SelectVal ? ' selected' : '') + '>' + this.CHEADNUM[i] + '</option>');
		}
	}

	// 이메일 셀렉트 박스
	this.EmailSelect = function () {
		for (var i = 0; i < this.EMAIL.length; i++) {
			document.write('<option value="' + this.EMAIL[i] + '">' + this.EMAIL[i] + '</option>');
		}
	}

	// 이메일 변경하기
	this.ChangeEmail = function (SelectObj, obj1, obj2, obj3, EmailVal) {
		var EmailCheck;

		if (typeof EmailVal != "undefined") {
			EmailCheck = EmailVal;
		} else {
			EmailCheck = SelectObj.value;
		}

		if (MyLib.InArray(EmailCheck, this.EMAIL) == false){
			SelectObj.value = '';
			obj1.style.display = '';
			obj2.value = '';
			obj2.focus();

			if (typeof EmailVal != "undefined") {
				obj2.value = EmailVal;
			}
		} else {
			obj1.style.display = 'none';
			obj2.value = '';

			if (typeof EmailVal != "undefined") {
				obj3.value = EmailVal;
			}
		}
	}

	// flashWrite
	this.FlashWrite = function (s,w,h,d,bg,t,f,l){

		var code = "";
		code  = "<object type=\"application/x-shockwave-flash\" ";
		code +=         "classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" ";
		code +=         "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" ";
		code +=         "width=\""+w+"\" height=\""+h+"\" id=\""+d+"\">";
		code += "<param name=\"movie\" value=\""+s+"\" />";
		code += "<param name=\"quality\" value=\"high\" />";
		code += "<param name=\"wmode\" value=\""+t+"\" />";
		code += "<param name=\"menu\" value=\"false\" />";
		code += "<param name=\"allowScriptAccess\" value=\"always\" />";
		code += "<param name=\"swliveconnect\" value=\"true\" />";
		code += "<param name='scale' value='"+f+"' />";
		code += "<param name='salign' value='"+l+"' />";
		code += "<embed src=\""+s+"\" quality=\"high\" "
		code +=        "wmode=\""+t+"\" "
		code +=        "menu=\"false\" width=\""+w+"\" height=\""+h+"\" "
		code +=        "type=\"application/x-shockwave-flash\" "
		code +=        "pluginspage=\"http://www.macromedia.com/go/getflashplayer\"> "
		code += "</embed>"
		code += "</object>"

		document.write (code);
	}

	// 코멘트 리스트 출력
	this.MemoList = function (mode, page) {
		var Param = "";

		// 실행종류
		if (!(typeof mode == "undefined" || mode == null || mode == "")) {
			this._MEMOMODE		= mode;
		}

		// 페이지 번호
		if (!(typeof page == "undefined" || page == null || page == "")) {
			this._MEMOPAGE		= page;
		}

		// 파라메타 만들기
		if (this._MEMOPARAM) {
			Param		= this._MEMOPARAM + "&p=" + this._MEMOPAGE + "&m=" + this._MEMOMODE;
		} else {
			Param		= "p=" + this._MEMOPAGE + "&m=" + this._MEMOMODE;
		}

		var _Rtn = "";

		new Ajax.Request(
							this._MEMOURL,
							{
								method		: "get",
								asynchronous: false,
								parameters	: Param,
								encoding	: "UTF-8",
								onComplete	: function(OriRuquest) { _Rtn = OriRuquest.responseText; }
							}
						);

		try {
			this._MEMOOBJ.innerHTML = _Rtn;
		} catch (e) {
		}
	}

	// 코멘트 등록
	this.MemoReg = function (url, param) {
		// json 개체를 쿼리스트링 형식으로 변경합니다.
		param		= $H(param).toQueryString();

		var _Rtn = "";

		new Ajax.Request(
							url,
							{
								method		: "post",
								asynchronous: false,
								parameters	: param,
								encoding	: "UTF-8",
								onComplete	: function(OriRuquest) { _Rtn = OriRuquest.responseText; }
							}
						);

		// 등록여부
		if (_Rtn == "OKOK") {
			this.MemoList();
			alert("댓글이 등록되었습니다.");
			return true;
		} else if (_Rtn) {
			// 에러메시지
			alert(_Rtn);
			return false;
		} else {
			// 기타 에러
			alert("댓글 등록에 실패하였습니다.");
			return false;
		}
	}

	// 코멘트 삭제
	this.MemoDel = function (mseq) {
		if (confirm('삭제 하시겠습니까?') == false) {
			return;
		}

		var Param = "";
		var _Rtn = "";

		// 파라메타 만들기
		if (this._MEMOPARAM) {
			Param		= this._MEMOPARAM + "&m=MDEL&mn=" + mseq;
		} else {
			Param		= "m=MDEL&mn=" + mseq
		}

		new Ajax.Request(
							this._MEMODELURL,
							{
								method		: "get",
								asynchronous: false,
								parameters	: Param,
								encoding	: "UTF-8",
								onComplete	: function(OriRuquest) { _Rtn = OriRuquest.responseText; }
							}
						);

		// 등록여부
		if (_Rtn == "OKOK") {
			this.MemoList();
			alert("삭제되었습니다.");
			return;
		} else if (_Rtn) {
			// 에러메시지
			alert(_Rtn);
			return;
		} else {
			// 기타 에러
			alert("댓글 삭제에 실패하였습니다.");
			return;
		}
	}


	// 메일발송 2009년 2월 19일 목요일
	this.MailSend = function (url, param) {
		// json 개체를 쿼리스트링 형식으로 변경합니다.
		param		= $H(param).toQueryString();

		var _Rtn = "";

		new Ajax.Request(
							url,
							{
								method		: "post",
								asynchronous: false,
								parameters	: param,
								encoding	: "UTF-8",
								onComplete	: function(OriRuquest) { _Rtn = OriRuquest.responseText; }
							}
						);

		// 등록여부
		if (_Rtn == "OKOK") {
			this.MemoList();
			alert("메일이 발송되었습니다.");
			return true;
		} else {
			// 기타 에러
			alert("이메일 발송에 실패하였습니다.");
			return false;
		}
	}

	// 추천하기
	this.RecdReg = function (url, param) {
		var _Rtn = "";

		new Ajax.Request(
							url,
							{
								method		: "get",
								asynchronous: false,
								parameters	: param,
								encoding	: "UTF-8",
								onComplete	: function(OriRuquest) { _Rtn = OriRuquest.responseText; }
							}
						);

		// 등록여부
		if (_Rtn == "OKOK") {
			this.MemoList();
			alert("추천되었습니다.");
			history.go(0);
			return;
		} else if (_Rtn) {
			// 에러메시지
			alert(_Rtn);
			return;
		} else {
			// 기타 에러
			alert("추천 등록에 실패하였습니다.");
			return;
		}
	}

	// HTML 추가
	this.AddHtml = function (oname, html, Lenth) {
		// 생성숫자 증가
		$(Lenth).value++;

		// MAX 갯수 체크
		if (parseInt(eval(oname + "MaxLength")) < parseInt($(Lenth).value)) {
			$(Lenth).value--;
			alert("더 이상 생성하실수 없습니다.");
			return;
		}

		new Insertion.After(oname + (parseInt($(Lenth).value) - 1), "<span id=\"" + oname + parseInt($(Lenth).value) + "\">" + html + "</span>");
	}

	// HTML 삭제
	this.DelHtml = function (oname, Lenth) {

		// MIN 갯수 체크
		if (parseInt(eval(oname + "MinLength")) >= parseInt($(Lenth).value)) {
			alert("더 이상 삭제하실수 없습니다.");
			return;
		}

		// 파이어폭스에서 outerHTML을 사용 할수 없는관계로 innerHTML로 대체 원래 개발은 outerHTML이어야 함
		if ($(oname + $(Lenth).value) != null) {
			$(oname + $(Lenth).value).innerHTML = "";
			$(Lenth).value--;
		}
	}


	// 추천하기
	this.ScrapReg = function (KIND, LINK1, LINK2, LINK3) {
		var _Rtn = MyLib.AJAXGet("/scrapExec.asp", "KIND=" + KIND + "&LINK1=" + LINK1 + "&LINK2=" + LINK2 + "&LINK3=" + LINK3);

		// 등록여부
		if (_Rtn == "OKOK") {
			alert("스크랩되었습니다.");
			return;
		} else if (_Rtn) {
			// 에러메시지
			alert(_Rtn);
			return;
		} else {
			// 기타 에러
			alert("스크랩 등록에 실패하였습니다.");
			return;
		}
	}

	// 교재보기
	this.BookView = function (Obj) {
		try {
			this._BOOK_DIV.style.display = "none";
		} catch (e) {
		}

		// 객체 저장
		this._BOOK_DIV = Obj;

		// 보이기
		this._BOOK_DIV.style.display = "";
	}

	// 전화예약 처리자 추출 2009년 3월 4일 수요일
	this.PHONE = function (url, param) {
		// json 개체를 쿼리스트링 형식으로 변경합니다.
		param		= $H(param).toQueryString();

		var _Rtn = "";

		new Ajax.Request(
							url,
							{
								method		: "post",
								asynchronous: false,
								parameters	: param,
								encoding	: "UTF-8",
								onComplete	: function(OriRuquest) { _Rtn = OriRuquest.responseText; }
							}
						);
		// 등록여부
		if (_Rtn == "OKOK") {
			alert("처리되었습니다.");
			return true;
		} else {
			// 기타 에러
			alert("실패하였습니다.");
			return false;
		}
	}

}

var Web = new Web();