mt24h.customer = {
	logout:function(){
		if(confirm("Bạn có chắc chắn là bạn thoát khỏi website không ?")){
			mt24h.ajax_popup('ajax_logout',"POST",{},
			function (j) {
				location.reload();
			});
			return false;
		}		
	},
	
	loginForm: function(){
		mt24h.customer.login.submit();
		return false;
	},
	openWindow: function(windowUri, windowName,  windowWidth, windowHeight, property){
		var centerWidth = (window.screen.width - windowWidth) / 2;
		var centerHeight = (window.screen.height - windowHeight - 60) / 2;		
		newWindow = window.open(windowUri, windowName, 'width=' + windowWidth + 
								',height=' + windowHeight + ',left=' + centerWidth + ',top=' + centerHeight+ ',' + property);
		newWindow.focus();
	},
	
	register:{
		registerForm:function(email){
			mt24h.show_overlay_popup('mua24h-register', '',
			mt24h.customer.register.theme.registerForm('mua24h-register'),
			{
				background: {'background-color' : 'transparent'},
				border: {
					'background-color' : 'transparent',
					'padding' : '0px'
				},
				title: {'display' : 'none'},
				content: {
					'padding' : '0px',
					'width' : '300px'
				},
				release:function(){
					//mt24h.enter('#forgot_email', mt24h.header.password.submit);
				}
			});
		},
		submit:function(){
			var username = mt24h.util_trim(jQuery('#txtUserName1').val());
			var password = mt24h.util_trim(jQuery('#txtPassword1').val());
			var repassword = mt24h.util_trim(jQuery('#txtRePassword').val());
			var email = mt24h.util_trim(jQuery('#txtEmail').val());
			var fullname = mt24h.util_trim(jQuery('#txtFullName').val());
			var Address = mt24h.util_trim(jQuery('#txtAddress').val());
			var Phone = mt24h.util_trim(jQuery('#txtPhone').val());
			
			if(username == ''){
				mt24h.error.set('#txtUserName1', 'Chưa nhập Tên đăng nhập', 230, '.forgot_pasword');
				return false;
			}else if(password == ''){
				mt24h.error.set('#txtPassword1', 'Chưa nhập mật khẩu', 230, '.forgot_pasword');
				return false;
			}else if(password.length < 6){
				mt24h.error.set('#txtPassword1', 'Mật khẩu phải từ 6 ký tự trở lên', 230, '.forgot_pasword');
				return false;
			}else if(repassword == ''){
				mt24h.error.set('#txtRePassword', 'Chưa nhập nhắc lại mật khẩu', 230, '.forgot_pasword');
				return false;
			}else if(repassword != password){
				mt24h.error.set('#txtRePassword', 'Mật khẩu và nhắc lại mật khẩu phải trùng khớp' + password + '--' + repassword, 230, '.forgot_pasword');
				return false;
			}else if(Address == ''){
				mt24h.error.set('#txtAddress', 'Chưa nhập Địa chỉ', 230, '.forgot_pasword');
				return false;
			}else if(fullname == ''){
				mt24h.error.set('#txtFullName', 'Chưa nhập tên đầy đủ', 230, '.forgot_pasword');
				return false;
			}else if(Phone == ''){
				mt24h.error.set('#txtPhone', 'Chưa nhập Số điện thoại', 230, '.forgot_pasword');
				return false;
			}else if(isNaN(Phone)){
				mt24h.error.set('#txtPhone', 'Số điện thoại phải là số', 230, '.forgot_pasword');
				return false;
			}else if(Phone.length < 10 || Phone.length > 11){
				mt24h.error.set('#txtPhone', 'Số điện thoại phải từ 10 đến 11 số', 230, '.forgot_pasword');
				return false;
			}else if(email == ''){
				mt24h.error.set('#txtEmail', 'Chưa nhập email', 230, '.forgot_pasword');
				return false;
			}else if(!mt24h.is_email(email)){
				mt24h.error.set('#txtEmail', 'Email không hợp lệ', 230, '.forgot_pasword');
				return false;
			}else{
				mt24h.error.close('#txtEmail', '.forgot_pasword');
			}
			mt24h.ajax_popup('ajax_register',"POST",{username: username,password: password,email: email,fullname: fullname,Address: Address,Phone: Phone},
			function (j) {
				if (j.err == 0 && j.msg == 'success') {
					mt24h.hide_overlay_popup('mua24h-register');
					mt24h.show_popup_message(j.msg, "Đăng ký thành công", 0);
					location.reload();
				}else{
					mt24h.error.set('#forgot_email', j.msg, 230, '.forgot_pasword');
				}
			});
			return true;
		},		
		theme:{
			registerForm:function(id){
				return mt24h.join
				('<div class="new-popup" style="margin:0 auto;">')
					('<div class="new-popup-title"><div class="bgl"><div class="bg">')
						('<div class="fl">Đăng ký</div>')
						('<a href="javascript:void(0)" class="new-popup-close" title="Đóng" onclick="mt24h.hide_overlay_popup(\''+id+'\')">x</a>')
						('<div class="c"></div>')
					('</div></div></div>')
					('<div class="content forgot_pasword" style="padding:1px 20px 20px">')
						('<div id="cError"></div>')
						('<div class="label mTop10">Tên đăng nhập : </div>')
						('<div class="input-txt" style="width:260px">')
							('<input type="text" id="txtUserName1" name="txtUserName1" class="txt" style="width:250px" />')
						('</div>')
						('<div class="label mTop10">Mật khẩu :</div>')
						('<div class="input-txt" style="width:260px">')
							('<input type="password" id="txtPassword1" name="txtPassword1" class="txt" style="width:250px" />')
						('</div>')
						('<div class="label mTop10">Nhập lại mật khẩu :</div>')
						('<div class="input-txt" style="width:260px">')
							('<input type="password" id="txtRePassword" name="txtRePassword" class="txt" style="width:250px" />')
						('</div>')
						('<div class="label mTop10">Email :</div>')
						('<div class="input-txt" style="width:260px">')
							('<input type="text" id="txtEmail" name="txtEmail" class="txt" style="width:250px" />')
						('</div>')
						('<div class="label mTop10">Tên đầy đủ :</div>')
						('<div class="input-txt" style="width:260px">')
							('<input type="text" id="txtFullName" name="txtFullName" class="txt" style="width:250px" />')
						('</div>')
						('<div class="label mTop10">Địa chỉ :</div>')
						('<div class="input-txt" style="width:260px">')
							('<input type="text" id="txtAddress" name="txtRePassword" class="txt" style="width:250px" />')
						('</div>')
						('<div class="label mTop10">Số điện thoại :</div>')
						('<div class="input-txt" style="width:260px">')
							('<input type="text" id="txtPhone" name="txtEmail" class="txt" style="width:250px" />')
						('</div>')
						('<div class="mTop10">')
							('<div style="width:150px;margin:0 auto">')
								('<a id="fr" class="blueButton mLeft10" onclick="mt24h.hide_overlay_popup(\''+id+'\')" href="javascript:void(0)"><span><span>Hủy bỏ</span></span></a>')
								('<a id="fr" class="blueButton" onclick="mt24h.customer.register.submit()" href="javascript:void(0)"><span><span>Đăng ký</span></span></a>')
								('<div class="c"></div>')
							('</div>')
						('</div>')
					('</div>')
					('<div class="bottom"><div class="bgl"><div class="bg"></div></div></div>')
				('</div>')();
			}
		}
	},
	loginForm_submit: function(){
		mt24h.customer.Login_form.submit();
		return false;
	},
	Login_form:{
		submit: function(){
			var email = mt24h.util_trim(jQuery('#txtUserName').val());
			var password = mt24h.util_trim(jQuery('#txtPassword').val());
			if(email == '' || email == 'Nhập tên đăng nhập')
			{
				mt24h.show_popup_message("Vui lòng nhập tên đăng nhập của bạn", "Lỗi đăng nhập", -1);
				return false;
			}else  if(password == '')
			{
				mt24h.show_popup_message("Vui lòng nhập mật khẩu của bạn", "Lỗi đăng nhập", -1);
				return false;
			}else
			{
				mt24h.ajax_popup('ajax_login',"POST",{user_name:email, password:password},
				function (j) {
					if (j.err == 0 && j.msg == 'success') {
						window.location.reload( false );
					}else{
						mt24h.show_popup_message("Đăng nhập thất bại", "Lỗi đăng nhập", -1);
					}
				});
				
			}
			return true;
		}
	},
	/*Login:{
		LoginForm:function(email){
			mt24h.show_overlay_popup('mua24h-Login', '',
			mt24h.customer.Login.theme.LoginForm('mua24h-Login'),
			{
				background: {'background-color' : 'transparent'},
				border: {
					'background-color' : 'transparent',
					'padding' : '0px'
				},
				title: {'display' : 'none'},
				content: {
					'padding' : '0px',
					'width' : '300px'
				},
				release:function(){
					//mt24h.enter('#forgot_email', mt24h.header.password.submit);
				}
			});
		},
		submit:function(){
			var username = mt24h.util_trim(jQuery('#txtUserName').val());
			var password = mt24h.util_trim(jQuery('#txtPassword').val());
			
			
			if(username == ''){
				mt24h.error.set('#txtUserName', 'Chưa nhập Tên đăng nhập', 230, '.forgot_pasword');
				return false;
			}else if(password == ''){
				mt24h.error.set('#txtPassword', 'Chưa nhập mật khẩu', 230, '.forgot_pasword');
				return false;
			}else{
				mt24h.error.close('#txtPassword', '.forgot_pasword');
			}
			mt24h.ajax_popup('ajax_login',"POST",{user_name:username, password:password},
			function (j) {
				if (j.err == 0 && j.msg == 'success') {
					location.reload();
				}else{
					mt24h.error.set('#forgot_email', j.msg, 230, '.forgot_pasword');
				}
			});
			return true;
		},		
		theme:{
			LoginForm:function(id){
				return mt24h.join
				('<div class="new-popup" style="margin:0 auto;">')
					('<div class="new-popup-title"><div class="bgl"><div class="bg">')
						('<div class="fl">Đăng nhập</div>')
						('<a href="javascript:void(0)" class="new-popup-close" title="Đóng" onclick="mt24h.hide_overlay_popup(\''+id+'\')">x</a>')
						('<div class="c"></div>')
					('</div></div></div>')
					('<div class="content forgot_pasword" style="padding:1px 20px 20px">')
						('<div id="cError"></div>')
						('<div class="label mTop10">Tên đăng nhập : </div>')
						('<div class="input-txt" style="width:260px">')
							('<input type="text" id="txtUserName" name="txtUserName" class="txt" style="width:250px" />')
						('</div>')
						('<div class="label mTop10">Mật khẩu :</div>')
						('<div class="input-txt" style="width:260px">')
							('<input type="password" id="txtPassword" name="txtPassword" class="txt" style="width:250px" />')
						('</div>')
						('<div class="mTop10">')
							('<div style="width:180px;margin:0 auto">')
								('<a id="fr" class="blueButton mLeft10" onclick="mt24h.hide_overlay_popup(\''+id+'\')" href="javascript:void(0)"><span><span>Hủy bỏ</span></span></a>')
								('<a id="fr" class="blueButton" onclick="mt24h.customer.Login.submit()" href="javascript:void(0)"><span><span>Đăng nhập</span></span></a>')
								('<div class="c"></div>')
							('</div>')
						('</div>')
					('</div>')
					('<div class="bottom"><div class="bgl"><div class="bg"></div></div></div>')
				('</div>')();
			}
		}
	},*/
	
	password:{
		resendPassword:function(email){
			mt24h.show_overlay_popup('mua24h-resend-password', '',
			mt24h.customer.password.theme.resendPassword('mua24h-resend-password', email),
			{
				background: {'background-color' : 'transparent'},
				border: {
					'background-color' : 'transparent',
					'padding' : '0px'
				},
				title: {'display' : 'none'},
				content: {
					'padding' : '0px',
					'width' : '305px'
				},
				release:function(){
					//mt24h.enter('#forgot_email', mt24h.header.password.submit);
				}
			});
		},
		submit:function(){
			var email = mt24h.util_trim(jQuery('#forgot_email').val());
			if(email == ''){
				mt24h.error.set('#forgot_email', 'Chưa nhập email', 230, '.forgot_pasword');
				return false;
			}else if(!mt24h.is_email(email)){
				mt24h.error.set('#forgot_email', 'Email không hợp lệ', 230, '.forgot_pasword');
				return false;
			}else{
				mt24h.error.close('#forgot_email', '.forgot_pasword');
			}
			mt24h.ajax_popup('ajax_forgetpass',"POST",{email: email},
			function (j) {
				if (j.err == 0 && j.msg == 'success') {
					mt24h.hide_overlay_popup('mua24h-resend-password');
					alert("Thông tin hỗ trợ đã được gửi vào "+email+"\nQuý khách vui lòng làm theo hướng dẫn trong email");
				}else{
					mt24h.error.set('#forgot_email', j.msg, 230, '.forgot_pasword');
				}
			});
			return true;
		},		
		theme:{
			resendPassword:function(id, email){
				return mt24h.join
				('<div class="new-popup" style="margin:0 auto">')
					('<div class="new-popup-title"><div class="bgl"><div class="bg">')
						('<div class="fl">Quên mật khẩu</div>')
						('<a href="javascript:void(0)" class="new-popup-close" title="Đóng" onclick="mt24h.hide_overlay_popup(\''+id+'\')">x</a>')
						('<div class="c"></div>')
					('</div></div></div>')
					('<div class="content forgot_pasword" style="padding:1px 20px 20px">')
						('<div id="cError"></div>')
						('<div class="label mTop10">Email đã đăng kí:</div>')
						('<div class="input-txt" style="width:260px">')
							('<input type="text" id="forgot_email" name="email" class="txt" style="width:250px" value="'+(email?email:'')+'" />')
						('</div>')
						('<div class="f11">Vui lòng nhập đúng email đã đăng kí để nhận thông tin hỗ trợ lấy lại mật khẩu từ mekongland24h.com.vn</div>')
						('<div class="mTop10">')
							('<div style="width:150px;margin:0 auto">')
								('<a id="fr" class="blueButton mLeft10" onclick="mt24h.hide_overlay_popup(\''+id+'\')" href="javascript:void(0)"><span><span>Hủy bỏ</span></span></a>')
								('<a id="fr" class="blueButton" onclick="mt24h.customer.password.submit()" href="javascript:void(0)"><span><span>Gửi đi</span></span></a>')
								('<div class="c"></div>')
							('</div>')
						('</div>')
					('</div>')
					('<div class="bottom"><div class="bgl"><div class="bg"></div></div></div>')
				('</div>')();
			}
		}
	},
	
	delImage:{
		del:function(file,i){
			mt24h.ajax_popup('del-file',"POST",{file: file},
			function (j) {
				if (j.err == 0 && j.msg == 'success') {
					$('#'+i+'').css({'display':'none'});
				}else{
					alert(j.msg);
				}
			});
			return true;
		},	
	},
	
};
