Mys.emailInfo = function(form, btnEl, dataEl, data)
{
	Mys.emailInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
	
	Ext.fly(this.form.dom.emailDomainList).on("change", this.toggleDomain, this);
	//이메일 중복 자동 확인
	Ext.fly(this.form.dom.emailDomain).on("blur", this.checkEmail, this);
	Ext.fly(this.form.dom.emailDomainList).on("blur", this.checkEmail, this);
};

Ext.extend(Mys.emailInfo, Mys.InfoForm, {
	checkEmail : function(isAlert)
	{
		var email = this.getModify().email;
		
		if(!email.check("email"))
		{
			this.showStatus(this.form.dom.emailDomainList, "올바른 이메일을 입력해 주세요. 예) abc@abc.com", isAlert);
			
			this.checkedEmail = false;
			this.afterRegister = false;
			
			return false;
		}
		
		this.checkingEmail = true;
		
		Global.modelUser.checkEmail(email, function(data)
		{
			var ar = this.afterRegister;
			
			this.checkingEmail = false;
			this.afterRegister = false;
			
			if(data.response.code !== 100)
				return;
			
			if(data.response.check == 1)
			{
				if(isAlert !== true)
					this.showStatus(this.form.dom.emailDomainList, "사용할 수 있는 이메일 입니다.");
				
				this.checkedEmail = true;
				
				if(ar)
					this.modify();
			}
			else
			{
				this.showStatus(this.form.dom.emailDomainList, "이미 가입된 이메일 입니다. 다른 이메일을 입력하세요.", isAlert);
				this.checkedEmail = false;
			}
			
		}, this);
	},
	
	beforeShow : function()
	{
		if(this.data.email)
		{
			var fm = this.form.dom;
			var sp = this.data.email.split("@"), id = sp[0], domain = sp[1];
			
			fm.emailID.value = id;
			for(var i = 0 ;i < fm.emailDomainList.options.length - 1; i++)
			{
				if(fm.emailDomainList.options[i].value == domain)
					break;
			}
			
			fm.emailDomainList.selectedIndex = i;
			fm.emailDomain.value = domain;
			
			fm.getMail.checked = this.data.get_mail_flag ? true : false;
		}
		
		this.toggleDomain();
	},
	
	beforeHide : function()
	{
		this.dataEl.dom.innerHTML = this.data.email;
	},
	
	toggleDomain : function()
	{
		this.form.dom.emailDomain.style.display = this.form.dom.emailDomainList.value ? "none" : "";
	},
	
	getModify : function()
	{
		return {
			email : this.form.dom.emailID.value + "@" + (this.form.dom.emailDomainList.value || this.form.dom.emailDomain.value),
			get_mail_flag : (this.form.dom.getMail.checked ? 1 : 0)
		};
	},
	
	validModify : function()
	{
		if(this.checkingEmail)
		{
			this.afterRegister = true;
			return false;
		}
		
		if(!this.checkedEmail)
		{
			this.checkEmail(true);
			this.afterRegister = true;
			
			return false;
		}
		
		return true;
	}
});

Mys.nickInfo = function(form, btnEl, dataEl, data)
{
	Mys.nickInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
	
	Ext.fly(this.form.dom.nick).on("blur", this.checkNick, this);
};

Ext.extend(Mys.nickInfo, Mys.InfoForm, {
	checkNick : function(isAlert)
	{
		var nick = this.form.dom.nick.value;
		if(!nick.check("name"))
		{
			this.showStatus(this.form.dom.nick, "올바른 별명을 입력해 주세요. 예)KMA 회원", isAlert);
			
			this.checkedNick = false;
			this.afterRegister = false;
			
			return false;
		}
		
		this.checkingNick = true;
		
		Global.modelUser.checkNick(nick, function(data){
			var ar = this.afterRegister;
			
			this.checkingNick = false;
			this.afterRegister = false;
			
			if(data.response.code !== 100)
				return;
			
			if(data.response.check == 1)
			{
				if(isAlert !== true)
					this.showStatus(this.form.dom.nick, "사용할 수 있는 별명 입니다.");
				
				this.checkedNick = true;
				
				if(ar)
					this.modify();
			}
			else
			{
				this.showStatus(this.form.dom.nick, "이미 사용중인 별명 입니다. 다른 별명을 입력하세요.", isAlert);
				this.checkedNick = false;
			}
			
			this.afterRegister = false;
		}, this);
	},
	
	beforeShow : function()
	{
		this.form.dom.nick.value = this.data.nick || "";
	},
	
	beforeHide : function()
	{
		this.dataEl.dom.innerHTML = this.data.nick;
	},
	
	getModify : function()
	{
		return {nick : this.form.dom.nick.value};
	},
	
	validModify : function()
	{
		if(this.checkingNick)
		{
			this.afterRegister = true;
			return;
		}
		
		if(!this.checkedNick)
		{
			this.checkNick(true);
			this.afterRegister = true;
			
			return;
		}
		
		return true;
	},
	
	onModify : function(data)
	{
		if(data && data.response.code == 100)
		{
			var userData = this.getModify();
			
			Status.setNick(userData.nick);
			
			alert("수정에 성공하였습니다.");
			
			Ext.apply(this.data, userData);
			this.form.dom.reset();
			this.hide();
		}
	}
});

Mys.nameInfo = function(form, btnEl, dataEl, data){
	Mys.nameInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
	
	Ext.fly(this.form.dom.name).on("blur", this.checkName, this);
};

Ext.extend(Mys.nameInfo, Mys.InfoForm, {
	checkName : function(isAlert){
		var name = this.form.dom.name.value;
		if(!name.check("name"))
		{
			this.showStatus(this.form.dom.nick, "올바른 이름을 입력해 주세요. 예)김능률", isAlert);
			
			this.checkedNick = false;
			
			return false;
		}
		
		return true;
	},
	
	beforeShow : function(){
		this.form.dom.name.value = this.data.name || "";
	},
	
	beforeHide : function(){
		this.dataEl.dom.innerHTML = this.data.name;
	},
	
	getModify : function(){
		return {name : this.form.dom.name.value};
	},
	
	validModify : function(){
		return this.checkName(true);
	},
	
	onModify : function(data){
		if(data && data.response.code == 100)
		{
			var userData = this.getModify();
			
			alert("수정에 성공하였습니다.");
			
			Ext.apply(this.data, userData);
			this.form.dom.reset();
			this.hide();
		}
	}
});
Mys.passwordInfo = function(form, btnEl, dataEl, data)
{
	Mys.passwordInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
	
	//비밀번호 유효 확인
	Ext.fly(this.form.dom.password).on("blur", this.checkPassword, this);
	Ext.fly(this.form.dom.passwordRef).on("blur", this.checkPassword, this);
};
Ext.extend(Mys.passwordInfo, Mys.InfoForm, {
	beforeHide : function()
	{
		this.dataEl.dom.innerHTML = "********";
	},
	
	checkPassword : function(isAlert, el)
	{
		var ps = this.form.dom.password.value;
		var psrf = this.form.dom.passwordRef.value;
		
		if(!ps.check("password"))
		{
			this.showStatus(this.form.dom.password, "비밀번호가 형식에 맞지 않습니다.", isAlert);
			
			this.checkedPassword = false;
			
			return false;
		}
		
		if(psrf && psrf != ps)
		{
			this.showStatus(this.form.dom.passwordRef, "비밀번호와 비밀번호 확인이 다릅니다.", isAlert);
			
			this.checkedPassword = false;
			
			return false;
		}
		
		this.checkedPassword = true;
		
		return true;
	},
	
	getModify : function()
	{
		return {password : this.form.dom.password.value};
	},
	
	validModify : function()
	{
		if(!this.form.dom.passwordRef.value)
		{
			this.form.dom.passwordRef.focus();
			alert("비밀번호 확인을 입력하세요");
			return false;
		}
		if(!this.checkedPassword && !this.checkPassword(true))
			return false;
		
		return true;
	}
});

Mys.genderInfo = function(form, btnEl, dataEl, data)
{
	Mys.genderInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
};
Ext.extend(Mys.genderInfo, Mys.InfoForm, {
	beforeShow : function()
	{
		if(this.data.gender == 1)
			this.form.dom.gender[0].checked = true;
		else if(this.data.gender == 2)
			this.form.dom.gender[1].checked = true;
	},
	beforeHide : function()
	{
		var gender = "지정되지 않았습니다.";
		
		if(this.data.gender == 1)
			gender = "남성";
		else if(this.data.gender == 2)
			gender = "여성";
		
		this.dataEl.dom.innerHTML = gender;
	},
	
	getModify : function()
	{
		if(!this.form.dom.gender[0].checked && !this.form.dom.gender[1].checked)
			return {};
		else
			return {gender : this.form.dom.gender[0].checked ? 1 : 2};
	}
});

Mys.birthInfo = function(form, btnEl, dataEl, data)
{
	Mys.birthInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
};
Ext.extend(Mys.birthInfo, Mys.InfoForm, {
	beforeShow : function()
	{
		if(this.data.birth)
		{
			var birth = this.data.birth.split("-");
			
			this.form.dom.birthYear.value = birth[0];
			this.form.dom.birthMonth.value = birth[1];
			this.form.dom.birthDay.value = birth[2];
		}
		if(this.data.solar_lunar == 1)
			this.form.dom.solarLunar[0].checked = true;
		else if(this.data.solar_lunar == 1)
			this.form.dom.solarLunar[1].checked = true;
	},
	
	beforeHide : function()
	{
		var birthStr = '지정되지 않았습니다.';
		if(this.data.birth)
		{
			var birth = this.data.birth.split("-");
			var birthStr = birth[0] + "년 " + birth[1] + "월 " + birth[2] + "일 ";
			
			if(this.data.solar_lunar == 1)
				birthStr += "(양력)";
			else if(this.data.solar_lunar == 2)
				birthStr += "(음력)";
		}
		
		this.dataEl.update(birthStr);
	},
	
	getModify : function()
	{
		var fm = this.form.dom;
		if(!fm.birthYear.value || !fm.birthMonth.value || !fm.birthDay.value)
			return {};
		else
		{
			return {
				birth : this.form.dom.birthYear.value + "-" + this.form.dom.birthMonth.value + "-" + this.form.dom.birthDay.value,
				solar_lunar : this.form.dom.solarLunar[0].checked ? 1 : 2
			};
		}
	}
});

Mys.phoneInfo = function(form, btnEl, dataEl, data){
	Mys.phoneInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
};
Ext.extend(Mys.phoneInfo, Mys.InfoForm, {
	beforeShow : function(){
		if(this.data.cell_phone){
			var cell_phone = this.data.cell_phone.split("-");
			
			this.form.dom.cell_phone1.value = cell_phone[0];
			this.form.dom.cell_phone2.value = cell_phone[1];
			this.form.dom.cell_phone3.value = cell_phone[2];
		}
		
		if(this.data.com_phone){
			var com_phone = this.data.com_phone.split("-");
			
			this.form.dom.com_phone1.value = com_phone[0];
			this.form.dom.com_phone2.value = com_phone[1];
			this.form.dom.com_phone3.value = com_phone[2];
		}
		this.form.dom.getSMS.checked = this.data.get_sms_flag ? true : false;
	},
	
	beforeHide : function()
	{
		var phoneStr = '';
		
		if(this.data.cell_phone)
			phoneStr += '휴대전화 ' + this.data.cell_phone;
		
		phoneStr += '<br/>';
		
		if(this.data.com_phone)
			phoneStr += '직장&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' + this.data.com_phone;
		
		this.dataEl.update(phoneStr);
	},
	
	getModify : function()
	{
		var fm = this.form.dom;
		return {
			cell_phone : (fm.cell_phone2.value && fm.cell_phone3.value ? fm.cell_phone1.value + "-" + fm.cell_phone2.value + "-" + fm.cell_phone3.value : ""),
			com_phone : (fm.com_phone2.value && fm.com_phone3.value ? fm.com_phone1.value + "-" + fm.com_phone2.value + "-" + fm.com_phone3.value : ""),
			get_sms_flag : fm.getSMS.checked ? 1 : 0
		};
	},
	
	validModify : function(){
		var phone = this.getModify();
		if(!phone.cell_phone && !phone.com_phone){
			alert("휴대전화 혹은 직장 중 하나는 필수로 입력해야 합니다.");
			this.form.dom.cell_phone1.focus();
			return false;
		}
		
		return true;
	}
});

Mys.companyInfo = function(form, btnEl, dataEl, data)
{
	Mys.companyInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
};
Ext.extend(Mys.companyInfo, Mys.InfoForm, {
	beforeShow : function()
	{
		this.form.dom.company.value = this.data.company || "";
	},
	
	beforeHide : function()
	{
		this.dataEl.update(this.data.company || '지정되지 않았습니다.');
	},
	
	getModify : function()
	{
		return { company : this.form.dom.company.value };
	},
	
	validModify : function(){
		if(!this.form.dom.company.value)
		{
			alert("회사명이 입력되지 않았습니다.");
			this.form.dom.company.focus();
			return false;
		}
		
		return true;
	}
});

Mys.departmentInfo = function(form, btnEl, dataEl, data)
{
	Mys.departmentInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
};
Ext.extend(Mys.departmentInfo, Mys.InfoForm, {
	beforeShow : function()
	{
		this.form.dom.department.value = this.data.department || "";
	},
	
	beforeHide : function()
	{
		this.dataEl.update(this.data.department || '지정되지 않았습니다.');
	},
	
	getModify : function()
	{
		return { department : this.form.dom.department.value };
	},
	
	validModify : function(){
		if(!this.form.dom.department.value)
		{
			alert("부서명이 입력되지 않았습니다.");
			this.form.dom.department.focus();
			return false;
		}
		
		return true;
	}
});

Mys.positionInfo = function(form, btnEl, dataEl, data)
{
	Mys.positionInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
};

Ext.extend(Mys.positionInfo, Mys.InfoForm, {
	beforeShow : function()
	{
		this.form.dom.position.value = this.data.position || "";
	},
	
	beforeHide : function()
	{
		this.dataEl.update(this.data.position || '지정되지 않았습니다.');
	},
	
	getModify : function()
	{
		return { position : this.form.dom.position.value };
	},
	
	validModify : function(){
		if(!this.form.dom.position.value)
		{
			alert("직위가 입력되지 않았습니다.");
			this.form.dom.position.focus();
			return false;
		}
		
		return true;
	}
});

Mys.addressInfo = function(form, btnEl, dataEl, data)
{
	Mys.addressInfo.superclass.constructor.call(this, form, btnEl, dataEl, data);
	
	this.form.child(".zipcodeBtn").on("click", this.onClick, this);
	window.zipcodeUpdate = this.update.createDelegate(this);
};

Ext.extend(Mys.addressInfo, Mys.InfoForm, {
	onClick : function(){
		window.open("/pop/find_post.htm?callback=zipcodeUpdate", "find_post", "status=no,toolbar=no,location=no,titlebar=no,width=350,height=335");
	},
	
	update : function(value){
		this.form.dom.zipcode1.value = value.substr(0, 3);
		this.form.dom.zipcode2.value = value.substr(3, 3);
		
		this.form.dom.address1.value = value.substr(6, 200);
	},
	
	beforeShow : function(){
		this.form.dom.zipcode1.value = Mys.getSafeString(this.data.zipcode).substr(0, 3);
		this.form.dom.zipcode2.value = Mys.getSafeString(this.data.zipcode).substr(3, 3);
		
		this.form.dom.address1.value = Mys.getSafeString(this.data.address1);
		this.form.dom.address2.value = Mys.getSafeString(this.data.address2);
	},
	
	beforeHide : function(){
		if(this.data.zipcode || this.data.address1 || this.data.address2){
			var str = '(' + Mys.getSafeString(this.data.zipcode).substr(0, 3) + '-' + Mys.getSafeString(this.data.zipcode).substr(3, 3) + ')' + '<br/>' +
				Mys.getSafeString(this.data.address1) + '<br/>' +
				Mys.getSafeString(this.data.address2)
		}
		else
			var str = '지정되지 않았습니다.';
		
		this.dataEl.update(str);
	},
	
	getModify : function(){
		return {
			zipcode : this.form.dom.zipcode1.value + this.form.dom.zipcode2.value,
			address1 : this.form.dom.address1.value,
			address2 : this.form.dom.address2.value
		};
	}
});