/**
@ program			: javascript ui framework;
@ auth				: thhh2¢â 
@ desc				: È¸¿ø°ü·Ã
**/
th.member=function(actionfrm){
	this.actionfrm = actionfrm; 
}

th.member.prototype = {

	// login 
	Login: function(f) {
		try {
			if (f.userid.value=="" && f.userpwd.value=="") {
				th.Go('iu15', '0101');
			} else { 
				if (!th.Regular("" , f.userid , "Please enter your ID.")) return ;
				if (!th.Regular("" , f.userpwd , "Please enter your password.")) return ;
				f.target = this.actionfrm;
				f.submit();
			}
 

		}
		catch (e) {
			th.Error(e);
		}
	}, 

	// login enter;
	Enter : function(f) {
		if (event.keyCode==13) { this.Login(f); }
	},
	
	IsYak:function(f, gubun) {
		try {
//			if (!th.Regular("checked", f.isYak, "¾à°ü¿¡ µ¿ÀÇÇÏ¼Å¾ß °¡ÀÔÇÒ ¼ö ÀÖ½À´Ï´Ù.\n¾à°üµ¿ÀÇ¿¡ Ã¼Å©ÇÏ¼¼¿ä.")) return;
			if (confirm("¾à°ü¿¡ µ¿ÀÇÇÏ½Ã¸ç È¸¿ø°¡ÀÔÀ» ÇÏ½Ã°Ú½À´Ï±î?")) {
//				f.gubun.value = gubun;
				// cookie set 
				th.setCookie("isyak", "Y", 120); // 120ºÐ 
//				th.setCookie("gubun", gubun, 120); // 120ºÐ 
				
				if (gubun=="C") {
					window.location.href="/?code=login&subp=0401";
					return; 
					// f.action="/?code=login&subp=0401";
				} else {
					window.location.href="/?code=login&subp=0301";
				}
				// f.submit();
			} 
		}
		catch (e) {
			th.Error(e);
		}
	},

	IsJoin:function(f){
		try {
			if (!th.Regular("", f.name, "ÀÌ¸§À» ÀÔ·ÂÇÏ¼¼¿ä.")) return;
			if (!th.Regular("" , f.idn1 , "ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")) return;
			if (!th.Regular("idn1" , f.idn1 , "ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®´Â 6ÀÚ¸® ¼ýÀÚ¸¸ °¡´ÉÇÕ´Ï´Ù.")) return;
			if (!th.Regular("" , f.idn2 , "ÁÖ¹Îµî·Ï¹øÈ£ µÚÀÚ¸®¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")) return;
			if (!th.Regular("idn2" , f.idn2 , "ÁÖ¹Îµî·Ï¹øÈ£ µÞÀÚ¸®´Â 7ÀÚ¸® ¼ýÀÚ¸¸ °¡´ÉÇÕ´Ï´Ù.")) return;
			if (!this.IsIdn(f.idn1 , f.idn2)) return;	//ÁÖ¹Îµî·Ï¹øÈ£ Ã¼Å©·ÎÁ÷

			f.submit();
		}
		catch (e) {
			th.Error(e);
		}
	}, 
	
	IsIdn:function(idn1, idn2) {
		try {
			var values = idn1.value + idn2.value; 
			var sum = 0;
			for (i=0 ; i<8 ; i++) {sum+= values.substring(i,i+1)*(i+2); }
			for (i=8 ; i<12 ; i++) { sum+=values.substring(i,i+1)*(i-6); }
			sum=11-(sum%11);
			if (sum>=10) { sum-=10; }
			if (values.substring(12,13) != sum || (values.substring(6,7) !=1 && values.substring(6,7) != 2)) {
				alert("ÁÖ¹Îµî·Ï¹øÈ£¿¡ ¿À·ù°¡ ÀÖ½À´Ï´Ù. ´Ù½Ã È®ÀÎÇÏ½Ê½Ã¿À.");
				idn1.focus();
				return false;
			}
			else {
				return true;
			}
		}
		catch (e) {
			th.Error(e);
		}
	},

	IsBiz:function(idn1,idn2,idn3) {
		try {
			var tmp = idn1+""+idn2+""+idn3;
			sum = 0; 
			sum += parseInt(tmp.substring(0,1));
			sum += parseInt(tmp.substring(1,2)) * 3 % 10;
			sum += parseInt(tmp.substring(2,3)) * 7 % 10;
			sum += parseInt(tmp.substring(3,4)) * 1 % 10;
			sum += parseInt(tmp.substring(4,5)) * 3 % 10;
			sum += parseInt(tmp.substring(5,6)) * 7 % 10;
			sum += parseInt(tmp.substring(6,7)) * 1 % 10;
			sum += parseInt(tmp.substring(7,8)) * 3 % 10;
			sum += Math.floor(parseInt(tmp.substring(8,9)) * 5 / 10);
			sum += parseInt(tmp.substring(8,9)) * 5 % 10;
			sum += parseInt(tmp.substring(9,10));
			if (sum % 10 != 0) {
				alert("»ç¾÷ÀÚµî·Ï¹øÈ£°¡ Àß¸øµÇ¾ú½À´Ï´Ù.");
				return false;
			}
			return true;

		}
		catch (e) {
			th.Error(e);
		}
	},


	IdCheck:function(f) {
		try { 
//			f.id.value = th.Lower(f.id.value);
			if (!th.Regular("", f.id, "Please enter your ID.")) return;
			if (!th.Regular("id", f.id, "ID is 6-10 characters, letters and numbers only without space.")) return;
			// th.Modal("/popup/popup_idcheck.asp?id="+f.id.value, "popup", "dialogWidth:420px ; dialogHeight:280px;status:no;"); 
			f.gbn.value = "is_idcheck";
			f.idcheck.value = "yes";
			f.target = this.actionfrm;
			f.submit();
		}
		catch (e) {
			th.Error(e);
		}
	}, 

	EmailCheck:function(f) {
		try { 
//			f.id.value = th.Lower(f.id.value);
			if (!th.Regular("", f.email, "Please enter your E-mail address.")) return;
			if (!th.Regular("email", f.email, "The e-mail address is invalid. Please check again.")) return;
			f.gbn.value = "is_emailcheck";
			f.emailcheck.value = "yes";
			f.target = this.actionfrm;
			f.submit();
		}
		catch (e) {
			th.Error(e);
		}
	}, 

	BizCheck:function(f) { // »ç¾÷ÀÚ:
		try { 
			
			if (!th.Regular("", f.idn1, "»ç¾÷ÀÚ¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")) return;
			if (!th.Regular("", f.idn2, "»ç¾÷ÀÚ¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")) return;
			if (!th.Regular("", f.idn3, "»ç¾÷ÀÚ¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")) return;
			if (!this.IsBiz(f.idn1.value , f.idn2.value, f.idn3.value)) return;	//»ç¾÷ÀÚ¹øÈ£Ã¼Å©
			var idn = f.idn1.value+"-"+f.idn2.value+"-"+f.idn3.value; 
			th.Modal("/popup/popup_bizcheck.asp?idn="+idn, "popup", "dialogWidth:420px ; dialogHeight:130px;status:no;"); 
			/*
			f.gbn.value = "is_idcheck";
			f.target = this.actionfrm;
			f.submit();
			*/
		}
		catch (e) {
			th.Error(e);
		}
	}, 

	Submit:function(f) {
		try { 
			this.Member(f); 
		} catch (e) {
			th.Error(e); 
		}
	},

	Member:function(f) {
		try {
			f.id.value = th.Lower(f.id.value);

			if (!th.Regular("", f.id, "Please enter your ID..")) return;
			if (f.tmpgbn.value=="new") {
				if (!th.Regular("id", f.id, "ID is 6-10 characters, letters and numbers only without space.")) return;
			}
			if (f.tmpgbn.value=="new" && f.idcheck.value!="yes") { alert("Please check if your user ID is available."); return;  } 

			if (f.tmpgbn.value=="modify")	{

				if (!th.Regular("", f.oldpwd1, "To modify the information, please enter your password.")) return;

				if(f.pwdChangeGu.value == "Y"){

					if (!th.Regular("", f.pwd1, "Please enter your password.")) return;
					if (!th.Regular("", f.pwd2, "Please confirm your password.")) return;
					if (f.pwd1.value!=f.pwd2.value) { alert("The password and retyped password fields do not match. Please re-enter both fields. "); return; }
				}

			}			

			else {
				if (!th.Regular("", f.pwd1, "Please enter your password.")) return;
				if (!th.Regular("", f.pwd2, "Please confirm your password.")) return;
				if (f.pwd1.value!=f.pwd2.value) { alert("The password and retyped password fields do not match. Please re-enter both fields. "); return; }
			}
			
			// if (!th.Regular("checked", f.title, "Please select the Title.")) return;
			//if (!th.Regular("checked", f.degree, "Please select the Degree.")) return;

			if (!th.Regular("", f.firstname, "Please enter your first name.")) return;
			if (!th.Regular("", f.lastname, "Please enter your last name.")) return;
			if (!th.Regular("checked", f.sex, "Please select your gender. ")) return;
			if (!th.Regular("checked", f.title, "Please select your title.")) return;
			if (!th.Regular("", f.organization, "Please enter your organization.")) return;
			if (!th.Regular("", f.email, "Please enter your e-mail address. ")) return;
			if (!th.Regular("email", f.email, "The e-mail address is invalid. Please check again.")) return;

			if (f.tmpgbn.value=="modify")	{
				if(f.EmailOri.value != f.email.value){
					if (f.emailcheck.value!="yes") { alert("Please check if your e-mail address is available."); return;  }
				}
			}			
			else {
				if (f.emailcheck.value!="yes") { alert("Please check if your e-mail address is available."); return;  }
			}

//			if (!th.Regular("", f.position, "Please write your Position.")) return;
//			if (!th.Regular("", f.department, "Please write your Department.")) return;
			
//			if (!th.Regular("", f.company, "Please write your Exhibition Company.")) return;

			if (!th.Regular("", f.address, "Please enter your address.")) return;
			if (!th.Regular("", f.city, "Please enter your city.")) return;
//			if (!th.Regular("", f.postal, "Please write your Zip/Postal Code.")) return;
			if (!th.Regular("", f.nation, "Please select your country.")) return;

			// if (!th.Regular("", f.tel, "Please enter your phone number.")) return;

			if (f.level) {
				if (!th.Regular("" , f.level , "Please select the member grade. ")) return;
			}

			f.gbn.value = f.tmpgbn.value;
			f.target = this.actionfrm; 
//			contFormcheck ++;
			f.submit();

		}
		catch (e) {
			th.Error(e);
		}
	}, 

	AutoBirth:function(f) {
		try { 
			if (f.idn1.value && f.idn2.value) {
				tmp1 = f.idn1.value; 
				tmp2 = f.idn2.value;

				sex = tmp2.substring(0,1); 

				if (sex=="1" || sex=="2") {	// 1900³â´ë 
					thyear = "19" + tmp1.substring(0,2); 
				} else {	 // 2000³â´ë
					thyear = "20" + tmp1.substring(0,2); 
				}
				thmonth = tmp1.substring(2,4);
				thday = tmp1.substring(4,6);

				f.birthY.value = thyear;
				f.birthM.value = thmonth; 
				f.birthD.value = thday;
			}
		}
		catch (e) {
			th.Error(e);
		}
	} ,

	AutoSex:function(f) {
		if (f.idn2.value) {
			sex = f.idn2.value.substring(0,1); 
			if (sex==1 || sex == 3) {
				tmp = 1; 
			} else {
				tmp = 2; 
			}
			
			f.sex[tmp-1].checked = true; 
		}
	}, 
	Email:function(f, value) {
		try { 
			if (value) {
				if (value=="Á÷Á¢ÀÔ·Â") {
					f.email_name.value = "";
					f.email_name.readOnly = false; 
					f.email_name.focus();
				} else {
					f.email_name.value = value;
					f.email_name.readOnly = true;
				}
			}
		}
		catch (e) {
			th.Error(e);
		}
	}, 

	Leave:function(f) {
		try { 
//			if (!th.Regular("" , f.idn1 , "ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")) return;
//			if (!th.Regular("idn1" , f.idn1 , "ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®´Â 6ÀÚ¸® ¼ýÀÚ¸¸ °¡´ÉÇÕ´Ï´Ù.")) return;
//			if (!th.Regular("" , f.idn2 , "ÁÖ¹Îµî·Ï¹øÈ£ µÚÀÚ¸®¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")) return;
//			if (!th.Regular("idn2" , f.idn2 , "ÁÖ¹Îµî·Ï¹øÈ£ µÞÀÚ¸®´Â 7ÀÚ¸® ¼ýÀÚ¸¸ °¡´ÉÇÕ´Ï´Ù.")) return;
//			if (!this.IsIdn(f.idn1 , f.idn2)) return;	//ÁÖ¹Îµî·Ï¹øÈ£ Ã¼Å©·ÎÁ÷
			if (!th.Regular("", f.oldpwd1, "ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")) return;
//			if (!th.Regular("", f.reason, "Å»Åð»çÀ¯¸¦ ¼±ÅÃÇÏ¼¼¿ä.")) return;

			if (confirm("Å»ÅðÇÏ½Ã°Ú½À´Ï±î?")) {
				f.gbn.value = "leave";
				f.target = this.actionfrm ; 
				f.submit();
			}

		}
		catch (e) {
			th.Error(e);
		}
	}, 

	FindId:function(f){
		try { 

			if (!th.Regular("", f.name, "ÀÌ¸§À» ÀÔ·ÂÇÏ¼¼¿ä.")) return;

			if (!th.Regular("" , f.idn1 , "ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")) return;
			if (!th.Regular("idn1" , f.idn1 , "ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®´Â 6ÀÚ¸® ¼ýÀÚ¸¸ °¡´ÉÇÕ´Ï´Ù.")) return;
			if (!th.Regular("" , f.idn2 , "ÁÖ¹Îµî·Ï¹øÈ£ µÚÀÚ¸®¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")) return;
			if (!th.Regular("idn2" , f.idn2 , "ÁÖ¹Îµî·Ï¹øÈ£ µÞÀÚ¸®´Â 7ÀÚ¸® ¼ýÀÚ¸¸ °¡´ÉÇÕ´Ï´Ù.")) return;
			if (!this.IsIdn(f.idn1 , f.idn2)) return;	//ÁÖ¹Îµî·Ï¹øÈ£ Ã¼Å©·ÎÁ÷

			// contFormcheck ++;
			f.target = this.actionfrm;
			f.submit();

		}
		catch (e) {
			th.Error(e);
		}
	}, 
	FindPass:function(f) {
		try { 

			if (!th.Regular("", f.email, "Please enter your e-mail address. ")) return;
			if (!th.Regular("email", f.email, "The e-mail address is invalid. Please check again.")) return;
		
			f.target = this.actionfrm;
			f.submit();

		}
		catch (e) {
			th.Error(e);
		}
	}, 
	Zip:function(v) {
		// th.Open('/popup/pop_findzip.asp?v='+v,'findzip','width=450,height=490,scrollbars=yes');
		th.Modal('/popup/popup_findzip.asp?v='+v, 'findzip', 'dialogWidth:500px ; dialogHeight:350px;status:no; scroll:no;'); 
	},
	Nation:function(v){
		try {
			if (v) {
				var sp = v.split("\|");
				var country = sp[0];
				var phone = sp[1]; 
				document.frm.country.value = country;

				if (document.frm.gbn.value=="new") {
					document.frm.tel.value = "+"+phone+"-";
					document.frm.fax.value = "+"+phone+"-";
				}
			}
		}
		catch (e) {
			th.Error(e);
		}
	}

};

