if(typeof(Frontend)=='undefined'){	
	Frontend={		
		run:function(){
			this.configSlideBanner();
			this.configAddToCart();
			this.configFormAjaxPostComment();
			this.configFormAjaxUserRegister();
			this.configFormAjaxLogin();
			this.configCartIndex();
			this.configFormUpdateCartInfo();
			this.configFormBuyerCart();
			this.configRemoveCartButton();
			this.configFckEditor();
			this.configFormUserProfile();
			this.configFormAjaxForgotPassword();
			this.configFormMemberPostBlog();
			this.configDateTimeInput();
			this.configOtherProductsTab();
			this.configLikeProduct();
			this.configFormAjaxContact();
			this.configMenuSuperfish();
			this.checkLikeInfoCartOrder();
			this.checkOrderCartBuy();
			this.configValidateFormSendMailStatics();
		},
		configValidateFormSendMailStatics:function(){
			if($('#myOnPageDetailStatics .form-send-email').length){
				var  that = this;
				if($('#frm_send_email').length){
					$('#frm_send_email').validate({
						rules:{
							txt_name_pep_sent:{
								required:true
							},
							txt_email_pep_sent:{
								required:true,
								email:true
							},
							txt_email_pep_get:{
								required:true,
								email:true
							}
						},
						messages:{
							txt_name_pep_sent:{
								required:'<br>Bạn phải nhập họ tên người gửi'
							},
							txt_email_pep_sent:{
								required:'<br>Bạn phải nhập email người gửi',
								email:'<br>Email người gửi không đúng định dạng'
							},
							txt_email_pep_get:{
								required:'<br>Bạn phải nhập email người nhận',
								email:'<br>Email người nhận không đúng định dạng'
							}
						},
						clearForm:true,
						submitHandler:function(form){
							jQuery(form).ajaxSubmit({
								success:function(responseText){
									$(form).resetForm();
									alert('Bạn đã gửi thư chia sẻ tin bài thành công !');
									self.parent.tb_remove();
							}
							});
						}
					});
				}
			}
		},
		checkOrderCartBuy:function(){
			if($('#order-cart').length){
				$('#order-cart').click(function(){
					$('#info-cart-buy').css('display','block');
					$('#cart-buttons').css('display','none');					
				});	
			}
		},
		checkLikeInfoCartOrder:function(){
			if($('#check_like_cart_info').length){
				$('#check_like_cart_info').click(function(){
					if($(this).is(":checked")){
						var receiver_name = $('#input-cart-full-name-buyer').attr('value');
						var receiver_gender = $('#input-cart-buyer-gender').attr('value');
						var receiver_address = $('#input-cart-address-name-buyer').attr('value');
						var receiver_phone = $('#input-cart-buyer-phone').attr('value');
						var receiver_mobile = $('#input-cart-mobile-buyer').attr('value');
						var receiver_fax = $('#input-cart-buyer-fax').attr('value');
						var receiver_email = $('#input-cart-email-buyer').attr('value');
						var receiver_notice = $('#input-cart-buyer-notice').attr('value');

						$('#input-cart-full-name-receiver').attr('value',receiver_name);
						$('#input-cart-receiver-gender').attr('value',receiver_gender);
						$('#input-cart-address-name-receiver').attr('value',receiver_address);
						$('#input-cart-receiver-phone').attr('value',receiver_phone);
						$('#input-cart-mobile-receiver').attr('value',receiver_mobile);
						$('#input-cart-receiver-fax').attr('value',receiver_fax);
						$('#input-cart-email-receiver').attr('value',receiver_email);
						$('#input-cart-receiver-notice').attr('value',receiver_notice);
					}else {
						$('#input-cart-full-name-receiver').attr('value','');
						$('#input-cart-receiver-gender').attr('value',1);
						$('#input-cart-address-name-receiver').attr('value','');
						$('#input-cart-receiver-phone').attr('value','');
						$('#input-cart-mobile-receiver').attr('value','');
						$('#input-cart-receiver-fax').attr('value','');
						$('#input-cart-email-receiverr').attr('value','');
						$('#input-cart-receiver-notice').attr('value','');	
					}										 
				});
			}
		},
		configSlideBanner:function(){
			
		},		
		getEval:function(response){
			if(response){
				eval('var response = ' + response + ';');
				return response;
			}
		},
		
		configFckEditor:function(){
			var that = this;
			var fckOptions = { 
				path:'/extsource/fckeditor/',
				width:550,
				height:350,
				toolbar:'Default'
			};
			if($('.fckEditor').length > 0){
				fckOptions.toolbar = 'Default';
				fckOptions.width = 640;
				fckOptions.height = 400;
				$('.fckEditor').fck(fckOptions);
			}
		},
		
	 	configMenuSuperfish:function(){
			Menu.makeMenuSuperfish('ul.sf-menu',{
				autoArrows: false
			});
		},
		
		changeFilter:function(value){
			location.href = value;
		},
		configCartIndex:function(){
			if($('#tien-bang-chu').length){
				money_value = $('#tong-tien-bang-chu').val();
				$('#total_price_cart').html(money_value);
				money_text = DocTienBangChu(money_value);
				$('#tien-bang-chu').html(money_text);
			}
		},
		configAddToCart:function(){
			if($('.add-to-cart').length){
				var cartPage = $('#link-to-cart-page').attr('href');
				$('.add-to-cart').click(function(){	
					var id = $(this).attr('rel');
					$.get('/?c=cart&m=add&id=' + id,function(response){
						location.href = cartPage;
					});
				});
			}
		},
		configLikeProduct:function(){
			if($('.add-like-product').length){
				var cookie = $.cookie('likeProduct');
				var items = cookie ? cookie.split(/,/) : new Array();
				$('.add-like-product').click(function(){
					var productId = $(this).attr('rel');
					var index = items.indexOf(productId);
					if(index == -1){
						items.push(productId);
						$.cookie('likeProduct',items,{path:'/'});
						alert("Bạn đã thêm vào sản phẩm ưa thích thành công !");
					}
				});
			}
			if($('.del-like-product').length){
				var cookie = $.cookie('likeProduct');
				var items = cookie ? cookie.split(/,/) : new Array();
				$('.del-like-product').click(function(){
					var productId = $(this).attr('rel');
					var index = items.indexOf(productId);
					if(index != -1){
						delete(items[index]);
						$.cookie('likeProduct',items,{path:'/'});
						alert("Bạn đã xóa sản phẩm ưa thích thành công !");
					}
				});
			}
		},
		
		configFormAjaxUserRegister:function(){
			var  that = this;
			if($('#frm-register-user').length){
				that.messages = {
					account: {
						remote: '<br>Tên tài khoản không hợp lệ hoặc đã tồn tại ( The account name is invalid or has existed )',
						required: '<br>Bạn phải nhập tên tài khoản ( You must enter the account name )',
						minlength: '<br>Tên tài khoản phải có ít nhất 5 kí tự ( The account name must have at least 5 characters )'
					},
					full_name:{
						required: "<br>Bạn cần nhập họ và tên ( You need to enter name )"
					},			
					password: {
						required: '<br>Bạn phải nhập mật khẩu ( You must enter a password )',
						minlength: '<br>Mật khẩu phải có ít nhất 5 ký tự. ( The password must be at least 5 characters. )'
					},
					confirm_password: {
						required: '<br>Bạn phải nhập lại mật khẩu',
						equalTo: '<br>Mật khẩu không đồng nhất với mật khẩu đã nhập. Vui lòng nhập lại.'
					},
					email: {
						required: '<br>Bạn phải nhập email',
						email: '<br>Email không đúng định dạng, vui lòng nhập Email khác',
						remote: '<br>Email đã tồn tại, vui lòng chọn Email khác'
					},
					agree: {
						required: '<br>Bạn phải chấp nhận điều khoản hệ thống'
					},
					captcha: {
						required:'<br>Hãy nhập mã bảo mật',
						remote: "<br>Nhập mã bảo mật không đúng !"
					},
					id_card: {
						minlength: '<br>Số chứng minh thư không hợp lệ, vui lòng nhập lại.',
						maxlength: '<br>Số chứng minh thư không hợp lệ, vui lòng nhập lại.',
						required: '<br>Vui lòng nhập số chứng minh thư.'
					}
				};
				that.rules = {
					account: {
						required: true,
						minlength: 5,
						remote:'/?c=user&m=check_account'
					},
					password: {
						required: true,
						minlength: 5
					},
					confirm_password: {
						required: true,
						minlength: 5,
						equalTo: "#new-password"
					},
					email: {
						required: true,
						email: true,
						remote:'/?c=user&m=check_email'
					},
					full_name: {
						required: true
					},	
					agree: {
						required: true
					},				
					captcha: {
						required: true,
						remote: "/?c=user&m=check_captcha"
					}, 
					id_card: {
						minlength: 9,
						maxlength: 11,
						required:true
					}
				};
				$('#frm-register-user').validate({
					rules:that.rules,
					messages:that.messages,
					clearForm:true,
					submitHandler:function(form){
						jQuery(form).ajaxSubmit({
							success : function(response){
								$(form).resetForm();
								alert('Bạn đã đăng ký thành công !');
							} 
						});
					}
				});
			}
		},
		
		configFormAjaxLogin:function(){
			var  that = this;
			if($('#frm-login-form').length){
				var options = {
					success:function(response){
						response = that.getEval(response);
						if(response['status'] == 'success'){
							$('#zone-login-html').html(response['html']);
						}else {
							alert('Thông tin đăng nhập không đúng !');
						}
					}
				};
				$('#frm-login-form').ajaxForm(options);
			}
		},
		
		configFormAjaxPostComment:function(){
			var  that = this;
			if($('#frm_sent_comment').length){
				$('#frm_sent_comment').validate({
					rules:{
						username:{
							required:true
						},
						email:{
							required:true,
							email:true
						},
						content:{
							required:true
						}
					},
					messages:{
						username:{
							required:'<br>Bạn phải nhập họ tên'
						},
						email:{
							required:'<br>Bạn phải nhập email',
							email:'<br>Email không đúng'
						},
						content:{
							required:'<br>Bạn phải nhập nội dung'
						}
					},
					clearForm:true,
					submitHandler:function(form){
						jQuery(form).ajaxSubmit({
							success:function(responseText){
								if(responseText == 'FAIL'){
									alert("Mã bảo mật không đúng ! ( Security Code incorrect! )");
								}else {
									$(form).resetForm();
									alert('Cảm ơn bạn đã bình luận. Bình luận của bạn sẽ được hiển thị sau khi ban quản trị duyệt ( Thank you for your comment. Your comment will be displayed after the board approved)');
								}
							}
						});
					}
				});
			}
		},
		
		changeCaptcha:function(){
			var date = new Date();
			var captcha_time = date.getTime();
			$("#captcha-comment-image").attr({src:'/extsource/captcha/simple/create_image.php?'+captcha_time});
		},
		
		configFormUpdateCartInfo:function(){ // Cập nhật số lượng sản phẩm ở giỏ hàng
			var  that = this;
			if($('#update-product-cart-quantity').length){
				var options = {
					success:function(response){
						response = that.getEval(response);
						if(response['status'] == 'empty'){
							$('#zone-cart').html('Không có sản phẩm trong giỏ hàng !');
						}else {
							$('#zone-table-cart-info').html(response['html']);
						}
					}
				};
				$('#update-product-cart-quantity').ajaxForm(options);
			}
			
		},
		
		configFormBuyerCart:function(){ // Gửi thông tin khách hàng tới quản trị
			var  that = this;
			if($('#frm-post-cart-buyer-info').length){
				that.messages = {
					buyer_name:{
						required: $('#input-cart-full-name-buyer').attr('title')
					},		
					buyer_address:{
						required: $('#input-cart-address-name-buyer').attr('title')
					},
					buyer_mobile:{
						required: $('#input-cart-mobile-buyer').attr('title')
					},
					buyer_email: {
						required: $('#input-cart-email-buyer').attr('title'),
						email: $('#input-cart-email-buyer').attr('align')
					},
					receiver_name:{
						required: $('#input-cart-full-name-receiver').attr('title')
					},		
					receiver_address:{
						required: $('#input-cart-address-name-receiver').attr('title')
					},
					receiver_mobile:{
						required: $('#input-cart-mobile-receiver').attr('title')
					},
					receiver_email: {
						required: $('#input-cart-email-receiver').attr('title'),
						email: $('#input-cart-emailreceiver').attr('align')
					},
					trans_date: {
						required: $('#input-cart-date-calendar-receiver').attr('title')
					}
				};
				that.rules = {
					buyer_name: {
						required: true
					},
					buyer_address: {
						required: true
					},
					buyer_mobile: {
						required: true
					},
					buyer_email: {
						required: true,
						email: true
					},
					receiver_name: {
						required: true
					},
					receiver_address: {
						required: true
					},
					receiver_mobile: {
						required: true
					},
					receiver_email: {
						required: true,
						email: true
					},
					trans_date: {
						required: true
					}
				};
				$('#frm-post-cart-buyer-info').validate({
					rules:that.rules,
					messages:that.messages,
					clearForm:true,
					submitHandler:function(form){
						jQuery(form).ajaxSubmit({
							success : function(response){
								alert("Bạn đã đặt hàng thành công !");
								location.href = response;
							} 
						});
					}
				});
			}
		},
		
		configRemoveCartButton:function(){
			var  that = this;
			if($('.remove-item-from-cart-button').length){
				$('.remove-item-from-cart-button').click(function(){
					var productId = $(this).attr('rel');
					$.get('/?c=cart&m=remove_one_product&id=' + productId,function(response){
						response = that.getEval(response);
						if(response['status'] == 'empty'){
							$('#zone-cart').html('Không có sản phẩm trong giỏ hàng !');
						}else {
							$('#zone-table-cart-info').html(response['html']);
						}
					});
				});
			}
		},
		
		configFormUserProfile:function(){
			if($('#form-update-user-profile-info').validate){
			var checkURL = baseURL + '?c=passwd&m=check_current_password';
			var rules = {
				old_password: {
					required: true,
					remote:checkURL
				}, 
				new_password: {
					required: true
				},
				confirm_new_password: {
					required: true,
					equalTo: "#new_password"
				}
			};
			var messages = {
				old_password: {
					required: "<div>Hãy nhập mật khẩu cũ!</div>",
					remote: '<div>Mật khẩu cũ không đúng!'
				},
				new_password: {
					required: "<div>Hãy nhập mật khẩu mới!</div>"
				},
				confirm_new_password: {
					required: "<div>Hãy nhập lại mật khẩu!</div>",
					equalTo: "<div>Mật khẩu mới và nhập lại mật khẩu mới không trùng nhau</div>"
				}
			};
			$('#form-update-user-profile-info').validate({
				rules:rules,
				messages:messages,
				submitHandler:function(form){
					jQuery(form).ajaxSubmit({
						success : function(response){
							alert("Cập nhật thành công");
							location.reload();
						} 
					});
				}
			});
		}},
		
		configFormMemberPostBlog:function(){
			if($('#form-member-post-blog').length){
				var options = {
					success:function(response){
						alert("Bài viết của bạn sẽ được quản trị viên kiểm duyệt trước khi cho phép hiển thị !");
						location.href = response;
					}
				};
				$('#form-member-post-blog').ajaxForm(options);
			}
		},
		
		configDateTimeInput:function(){		// Nếu có config date-time
			var that = this;
			if($('.input-date-calendar').length){
				$('.input-date-calendar').dynDateTime({
					ifFormat: "%d-%m-%Y",
					button: ".next()",
					debug:  false,
					step:1
				});
			}
		},
		
		configOtherProductsTab:function(){		// Ẩn hiện tab sản phẩm khác trên trang chi tiết sản phẩm
			var that = this;
			if($('#cont-other-pro').length){
				$('#name-title').click(function(){
					document.getElementById('name-title').style.background = 'url(/system/application/frontend/views/skins/images/bg-item-ttle-detail-pro.jpg)no-repeat';
					document.getElementById('name-title-other').style.background = 'url(/system/application/frontend/views/skins/images/bg-item-ttle-other-pro-active.jpg)no-repeat';
					document.getElementById('cont-ino-pro').style.display = 'block';
					document.getElementById('cont-other-pro').style.display = 'none';
				});
				$('#name-title-other').click(function(){
					document.getElementById('name-title-other').style.background = 'url(/system/application/frontend/views/skins/images/bg-item-ttle-other-pro.jpg)no-repeat';
					document.getElementById('name-title').style.background = 'url(/system/application/frontend/views/skins/images/bg-item-ttle-detail-pro-active.jpg)no-repeat';
					document.getElementById('cont-other-pro').style.display = 'block';
					document.getElementById('cont-ino-pro').style.display = 'none';
				});
			}
		},
		
		configFormAjaxForgotPassword:function(){		
			var  that = this;
			if($('#form_forgot_password').length){
				that.messages = {
					account: {
						remote: '<br>Tên tài khoản không tồn tại',
						required: '<br>Bạn phải nhập tên tài khoản'
					},
					captcha: {
						required:'<br>Hãy nhập mã bảo mật',
						remote: "<br>Nhập mã bảo mật không đúng !"
					}
				};
				that.rules = {
					account: {
						required: true,
						remote:'/?c=user&m=check_account_exist'
					},
					captcha: {
						required: true,
						remote: "/?c=user&m=check_captcha"
					}
				};
				$('#form_forgot_password').validate({
					rules:that.rules,
					messages:that.messages,
					clearForm:true,
					submitHandler:function(form){
						jQuery(form).ajaxSubmit({
							success : function(response){
								$(form).resetForm();
								that.changeCaptcha();
								alert('Bạn hãy check email để nhận mật khẩu mới!');
							} 
						});
					}
				});
			}
		},
				
		configFormAjaxContact:function(){		
			var  that = this;
			if($('#form_contact').length){
				that.messages = {
					name: {
						required: $('#input-contact-full-name').attr('title')
					},
					email: {
						required: $('#input-contact-email').attr('title'),
						email: $('#input-contact-email').attr('align')
					},
					phone: {
						required: $('#input-contact-phone').attr('title')
					},
					content: {
						required: $('#input-contact-content').attr('title')
					},
					captcha: {
						required: $('#input-contact-security-code').attr('title'),
						remote: $('#input-contact-security-code').attr('label')
					}
				};
				that.rules = {
					name: {
						required: true
					},
					email: {
						required: true,
						email: true
					},
					phone: {
						required: true
					},
					content: {
						required: true
					},
					captcha: {
						required: true,
						remote: "/?c=contact&m=check_captcha"
					}
				};
				$('#form_contact').validate({
					rules:that.rules,
					messages:that.messages,
					clearForm:true,
					submitHandler:function(form){
						jQuery(form).ajaxSubmit({
							success : function(response){
								$(form).resetForm();
								that.changeCaptcha();
								alert('Gửi thành công!');
							} 
						});
					}
				});
			}
		},
		setLanguage:function(lang){
			$.get(baseURL+ '?c=language&m=set_language&lang=' + lang,function(){
				location.reload();
			});
		}
		
	};
	
	
	Frontend.run();
}
