 (function(D){D.fn.htmlClean=function(X){return this.each(function(){var Y=D(this);if(this.value){this.value=D.htmlClean(this.value,X)}else{this.innerHTML=D.htmlClean(this.innerHTML,X)}})};D.htmlClean=function(b,m){m=D.extend({},D.htmlClean.defaults,m);var e=/<(\/)?(\w+:)?([\w]+)([^>]*)>/gi;var h=/(\w+)=(".*?"|'.*?'|[^\s>]*?)/gi;var d;var f=new R();var g=[f];var X=f;if(m.bodyOnly){if(d=/<body[^>]*>((\n|.)*)<\/body>/i.exec(b)){b=d[1]}}while(d=e.exec(b)){var l=new H(d[3],d[1],d[4]);var j=RegExp.leftContext.substring(c);if(j.length>0){var Z=X.children[X.children.length-1];if(X.children.length>0&&N(Z=X.children[X.children.length-1])){X.children[X.children.length-1]=Z.concat(j)}else{X.children.push(j)}}var c=e.lastIndex;if(l.isClosing){if(I(g,[l.name])){g.pop();X=g[g.length-1]}}else{var a=new R(l);if(!l.toIgnore){if(l.allowedAttributes!=null){var Y;while(Y=h.exec(l.rawAttributes)){if(l.allowedAttributes.length==0||D.inArray(Y[1],l.allowedAttributes)>-1){a.attributes.push(new A(Y[1],Y[2]))}}}var k=true;if(!X.isRoot){if(X.tag.isInline&&!l.isInline){k=false}else{if(X.tag.disallowNest&&l.disallowNest&&!l.requiredParent){k=false}else{if(l.requiredParent){if(k=I(g,l.requiredParent)){X=g[g.length-1]}}}}}if(k){X.children.push(a);if(!l.isSelfClosing&&!l.isNonClosing){g.push(a);X=a}}}}}return W(f,m).join("")};D.htmlClean.defaults={bodyOnly:true,removeAttrs:[],allowedClasses:[],format:false,formatIndent:0,replace:[[["b","big",/span.*?weight:\s*bold/i],"strong"],[["i",/span.*?style:\s*italic/i],"em"],[[/span.*?-align:\s*super/i],"sup"],[[/span.*?-align:\s*sub/i],"sub"]]};function G(a,Z,Y,X){if(!a.tag.isInline&&Y.length>0){Y.push("\n");for(i=0;i<X;i++){Y.push("\t")}}}function W(c,j){var Y=[],e=c.attributes.length==0,Z;var d=this.name.concat(c.tag.rawAttributes==undefined?"":c.tag.rawAttributes);for(var f=0;f<j.replace.length;f++){for(var k=0;k<j.replace[f][0].length;k++){var h=typeof (j.replace[f][0][k])=="string";if((h&&j.replace[f][0][k]==c.tag.name)||(!h&&j.replace[f][0][k].test(d))){c.tag.name=j.replace[f][1];f=j.replace.length;break}}}if(!c.isRoot){Y.push("<");Y.push(c.tag.name);D.each(c.attributes,function(){if(D.inArray(this.name,j.removeAttrs)==-1){var l=RegExp(/^(['"]?)(.*?)['"]?$/).exec(this.value);var n=l[2];var o=l[1];if(this.name=="class"){n=D.grep(n.split(" "),function(m){return D.inArray(m,j.allowedClasses)>-1}).join(" ");o='"'}if(n!=null&&n.length>0){Y.push(" ");Y.push(this.name);Y.push("=");Y.push(o);Y.push(n);Y.push(o)}}})}if(c.tag.isSelfClosing){Y.push(" />");e=false}else{if(c.tag.isNonClosing){e=false}else{if(!c.isRoot){Y.push(">")}var Z=j.formatIndent++;var b=[];for(var a=0;a<c.children.length;a++){var X=c.children[a];var g=D.htmlClean.trim(C(N(X)?X:X.childrenToString()));if(Q(X)){if(a>0&&g.length>0&&(V(X)||F(c.children[a-1]))){b.push(" ")}}if(N(X)){if(g.length>0){b.push(g)}}else{if(a!=c.children.length-1||X.tag.name!="br"){if(j.format){G(X,j,b,Z)}b=b.concat(W(X,j))}}}j.formatIndent--;if(b.length>0){if(j.format&&b[0]!="\n"){G(c,j,Y,Z)}Y=Y.concat(b);e=false}if(!c.isRoot){if(j.format){G(c,j,Y,Z-1)}Y.push("</");Y.push(c.tag.name);Y.push(">")}}}if(!c.tag.allowEmpty&&e){return[]}return Y}function I(X,Z,Y){Y=Y||1;if(D.inArray(X[X.length-Y].tag.name,Z)>-1){return true}else{if(X.length-(Y+1)>0&&I(X,Z,Y+1)){X.pop();return true}}return false}function R(X){if(X){this.tag=X;this.isRoot=false}else{this.tag=new H("root");this.isRoot=true}this.attributes=[];this.children=[];this.childrenToString=function(){return this.children.join("")};return this}function A(X,Y){this.name=X;this.value=Y;return this}function H(X,Z,Y){this.name=X.toLowerCase();this.isSelfClosing=D.inArray(this.name,K)>-1;this.isNonClosing=D.inArray(this.name,S)>-1;this.isClosing=(Z!=undefined&&Z.length>0);this.isInline=D.inArray(this.name,T)>-1;this.disallowNest=D.inArray(this.name,P)>-1;this.requiredParent=E[D.inArray(this.name,E)+1];this.allowEmpty=D.inArray(this.name,B)>-1;this.toIgnore=D.inArray(this.name,J)>-1;this.rawAttributes=Y;this.allowedAttributes=L[D.inArray(this.name,L)+1];return this}function V(X){while(O(X)&&X.children.length>0){X=X.children[0]}return N(X)&&X.length>0&&D.htmlClean.isWhitespace(X.charAt(0))}function F(X){while(O(X)&&X.children.length>0){X=X.children[X.children.length-1]}return N(X)&&X.length>0&&D.htmlClean.isWhitespace(X.charAt(X.length-1))}function N(X){return X.constructor==String}function Q(X){return N(X)||X.tag.isInline}function O(X){return X.constructor==R}function C(X){return X.replace(/&nbsp;|\n/g," ").replace(/\s\s+/g," ")}D.htmlClean.trim=function(X){return D.htmlClean.trimStart(D.htmlClean.trimEnd(X))};D.htmlClean.trimStart=function(X){return X.substring(D.htmlClean.trimStartIndex(X))};D.htmlClean.trimStartIndex=function(X){for(var Y=0;Y<X.length-1&&D.htmlClean.isWhitespace(X.charAt(Y));Y++){}return Y};D.htmlClean.trimEnd=function(X){return X.substring(0,D.htmlClean.trimEndIndex(X))};D.htmlClean.trimEndIndex=function(Y){for(var X=Y.length-1;X>=0&&D.htmlClean.isWhitespace(Y.charAt(X));X--){}return X+1};D.htmlClean.isWhitespace=function(X){return D.inArray(X,U)!=-1};var J=["basefont","center","dir","font","frame","frameset","iframe","isindex","menu","noframes","s","strike","u"];var T=["a","abbr","acronym","address","b","big","br","button","caption","cite","code","del","em","font","hr","i","input","img","ins","label","legend","map","q","samp","select","small","span","strong","sub","sup","tt","var"];var P=["h1","h2","h3","h4","h5","h6","p","th","td"];var B=["th","td"];var E=[null,"li",["ul","ol"],"dt",["dl"],"dd",["dl"],"td",["tr"],"th",["tr"],"tr",["table","thead","tbody","tfoot"],"thead",["table"],"tbody",["table"],"tfoot",["table"]];var M=["script","style","pre","code"];var K=["br","hr","img","link","meta"];var S=["!doctype","?xml"];var L=[["class"],"?xml",[],"!doctype",[],"a",["accesskey","class","href","name","title","rel","rev","type","tabindex"],"abbr",["class","title"],"acronym",["class","title"],"blockquote",["cite","class"],"button",["class","disabled","name","type","value"],"del",["cite","class","datetime"],"form",["accept","action","class","enctype","method","name"],"input",["accept","accesskey","alt","checked","class","disabled","ismap","maxlength","name","size","readonly","src","tabindex","type","usemap","value"],"img",["alt","class","height","src","width"],"ins",["cite","class","datetime"],"label",["accesskey","class","for"],"legend",["accesskey","class"],"link",["href","rel","type"],"meta",["content","http-equiv","name","scheme"],"map",["name"],"optgroup",["class","disabled","label"],"option",["class","disabled","label","selected","value"],"q",["class","cite"],"script",["src","type"],"select",["class","disabled","multiple","name","size","tabindex"],"style",["type"],"table",["class","summary"],"textarea",["accesskey","class","cols","disabled","name","readonly","rows","tabindex"]];var U=[" "," ","\t","\n","\r","\f"]})(jQuery);
 
 (function($) {
    $.fn.wait = function(option, options) {
        milli = 1000; 
        if (option && (typeof option == 'function' || isNaN(option)) ) { 
            options = option;
        } else if (option) { 
            milli = option;
        }
        var defaults = {
            msec: milli,
            onEnd: options
        },
        settings = $.extend({},defaults, options);

        if(typeof settings.onEnd == 'function') {
            this.each(function() {
                setTimeout(settings.onEnd, settings.msec);
            });
            return this;
        } else {
            return this.queue('fx',
            function() {
                var self = this;
                setTimeout(function() { $.dequeue(self); },settings.msec);
            });
        }

    }
})(jQuery);

  
  $(function() {
	$(".ajax_add_to_cart_button").click(function() {
		var idProduct =  $(this).attr('rel').replace('ajax_id_product_', '');
	
		$(this).effect("transfer", { to: "div#cart_block" }, 700).wait(function(){
			$('#cart_block').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
			add(idProduct);
		});
		return false; 
    });
	
	$("#ajax_add_to_pair_button").click(function() {
		var idProduct =  $(this).attr('rel').replace('ajax_id_product_', '');
		add_pair(idProduct);
		return false; 
    });
	
	$(".ajax_pair_to_cart_button").click(function() {
		var idProduct =  $(this).attr('rel').replace('ajax_id_pair_', '');		
		pair_to_cart(idProduct);
		return false; 
    });
	
	/*Translate Product*/
	$("#translate_to_english").click(function() {
		$("#translate_to_english").addClass("eb_wp_title_active").show("slow");
		$("#translate_to_vietnamese").removeClass("eb_wp_title_active").show("slow");
		$("#reset_to_vietnamese").removeClass("eb_wp_title_active").show("slow");
		
		
		var content = $("#product_detail").html();
		content = $.htmlClean(content, {format:true});
		var idProduct =  $(this).attr('rel').replace('detail_id_product_', '');
		translate(content, idProduct, 'vi', 'en');
		return false; 
    });
	
	$("#reset_to_english").click(function() {
		$("#translate_to_english").addClass("eb_wp_title_active").show("slow");
		$("#reset_to_english").addClass("eb_wp_title_active").show("slow");
		$("#translate_to_vietnamese").removeClass("eb_wp_title_active").show("slow");
		$("#reset_to_vietnamese").removeClass("eb_wp_title_active").show("slow");
		
		
		var content = $("#product_detail").html();
		content = $.htmlClean(content, {format:true});
		var idProduct =  $(this).attr('rel').replace('detail_id_product_', '');
		reset_lang(content, idProduct, 'vi', 'en');
		return false; 
    });
	
	$("#translate_to_vietnamese").click(function() {
		$("#translate_to_english").removeClass("eb_wp_title_active").show("slow");
		$("#reset_to_english").removeClass("eb_wp_title_active").show("slow");
		$("#translate_to_vietnamese").addClass("eb_wp_title_active").show("slow");
		var content = $("#product_detail").html();
		var idProduct =  $(this).attr('rel').replace('detail_id_product_', '');
		content = $.htmlClean(content, {format:true});
		translate(content, idProduct, 'en', 'vi');
		return false; 
    });
	
	$("#reset_to_vietnamese").click(function() {
		$("#translate_to_english").removeClass("eb_wp_title_active").show("slow");
		$("#reset_to_english").removeClass("eb_wp_title_active").show("slow");
		$("#translate_to_vietnamese").addClass("eb_wp_title_active").show("slow");
		$("#reset_to_vietnamese").addClass("eb_wp_title_active").show("slow");
		var content = $("#product_detail").html();
		var idProduct =  $(this).attr('rel').replace('detail_id_product_', '');
		content = $.htmlClean(content, {format:true});
		reset_lang(content, idProduct, 'en', 'vi');
		return false; 
    });
	
	/*Translate News*/
	$("#translate_to_english_news").click(function() {
		$("#translate_to_english_news").addClass("eb_wp_title_active").show("slow");
		$("#translate_to_vietnamese_news").removeClass("eb_wp_title_active").show("slow");
		$("#reset_to_vietnamese_news").removeClass("eb_wp_title_active").show("slow");
		
		
		var content = $("#news_detail").html();
		content = $.htmlClean(content, {format:true});
		var idProduct =  $(this).attr('rel').replace('detail_id_news_', '');
		translate_news(content, idProduct, 'vi', 'en');
		return false; 
    });
	
	$("#reset_to_english_news").click(function() {
		$("#translate_to_english_news").addClass("eb_wp_title_active").show("slow");
		$("#reset_to_english_news").addClass("eb_wp_title_active").show("slow");
		$("#translate_to_vietnamese_news").removeClass("eb_wp_title_active").show("slow");
		$("#reset_to_vietnamese_news").removeClass("eb_wp_title_active").show("slow");
		
		
		var content = $("#news_detail").html();
		content = $.htmlClean(content, {format:true});
		var idProduct =  $(this).attr('rel').replace('detail_id_news_', '');
		reset_lang_news(content, idProduct, 'vi', 'en');
		return false; 
    });
	
	$("#translate_to_vietnamese_news").click(function() {
		$("#translate_to_english_news").removeClass("eb_wp_title_active").show("slow");
		$("#reset_to_english_news").removeClass("eb_wp_title_active").show("slow");
		$("#translate_to_vietnamese_news").addClass("eb_wp_title_active").show("slow");
		var content = $("#news_detail").html();
		var idProduct =  $(this).attr('rel').replace('detail_id_news_', '');
		content = $.htmlClean(content, {format:true});
		translate_news(content, idProduct, 'en', 'vi');
		return false; 
    });
	
	$("#reset_to_vietnamese_news").click(function() {
		$("#translate_to_english_news").removeClass("eb_wp_title_active").show("slow");
		$("#reset_to_english_news").removeClass("eb_wp_title_active").show("slow");
		$("#translate_to_vietnamese_news").addClass("eb_wp_title_active").show("slow");
		$("#reset_to_vietnamese_news").addClass("eb_wp_title_active").show("slow");
		var content = $("#news_detail").html();
		var idProduct =  $(this).attr('rel').replace('detail_id_news_', '');
		content = $.htmlClean(content, {format:true});
		reset_lang_news(content, idProduct, 'en', 'vi');
		return false; 
    });
  });
  
  function translate(text, idProduct, from, to){
	$.ajax({
			type: "POST",
			url: "/product/product_detail_lang/"+idProduct+"/"+from+"/"+to,
			data: 	"content=" + text,
			beforeSend: function(){
				$("#translate_to_english_loading").show();
			},
			success: function(html){
				$("#translate_to_english_loading").hide();
				$("#product_detail").html(html);
			}
		});
  }
  
  function translate_news(text, idProduct, from, to){
	$.ajax({
			type: "POST",
			url: "/news/news_detail_lang/"+idProduct+"/"+from+"/"+to,
			data: 	"content=" + text,
			beforeSend: function(){
				$("#translate_to_english_loading").show();
			},
			success: function(html){
				$("#translate_to_english_loading").hide();
				$("#news_detail").html(html);
			}
		});
  }
  
  function reset_lang(text, idProduct, from, to){
	$.ajax({
			type: "POST",
			url: "/product/product_detail_iframe/"+idProduct+"/"+from+"/"+to,
			data: 	"content=" + text,
			beforeSend: function(){
				$("#translate_to_english_loading").show();
			},
			success: function(html){
				$("#translate_to_english_loading").hide();
				$("#product_detail").html(html);
			}
		});
  }
  
  function reset_lang_news(text, idProduct, from, to){
	$.ajax({
			type: "POST",
			url: "/news/news_detail_iframe/"+idProduct+"/"+from+"/"+to,
			data: 	"content=" + text,
			beforeSend: function(){
				$("#translate_to_english_loading").show();
			},
			success: function(html){
				$("#translate_to_english_loading").hide();
				$("#news_detail").html(html);
			}
		});
  }
  
  function loadCart(){
	$("#cart_block").load("/product/ajax_add_cart");
  }
  
  function add(idProduct){
	$.ajax({
			type: "POST",
			url: "/product/ajax_add_cart",
			data: 	"product_id=" + idProduct,
			success: function(html){
				$("#cart_block").html(html);
				$("#small_cart_block").load("/product/ajax_small_cart");
			}
		});
  }
  
  function add_pair(idProduct){
	$.ajax({
			type: "POST",
			url: "/product/ajax_add_pair",
			data: 	"product_id=" + idProduct,
			success: function(html){
				$("#pair_block").html(html);
			}
		});
  } 
  
  function del_pair(idProduct){
	$.ajax({
			type: "POST",
			url: "/product/ajax_del_pair",
			data: 	"pair_id=" + idProduct,
			success: function(html){
				location.reload(); 
			}
		});
  } 
  function pair_to_cart(idProduct){
	$.ajax({
			type: "POST",
			url: "/product/ajax_pair_to_cart",
			data: 	"pair_id=" + idProduct,
			success: function(html){
				$("#cart_block").html(html);
				$("#small_cart_block").load("/product/ajax_small_cart");
			}
		});
  }
  
  function showVideo(idProduct, idVideo){
	$.ajax({
			type: "POST",
			url: "/product/get_video",
			data: 	"product_id=" + idProduct + "&video_id=" + idVideo,
			success: function(html){
				$("#open_video").html(html);		
				$("#open_video").show();
			}
		});
		
		
  }
  
  function ship_for_me(){
	var buy_link = $("#buy_link").val() ;
	var buy_email = $("#buy_email").val() ;
	var cur_link = $("#cur_link").val() ;
	
	if ((buy_link==null)||(buy_link=="")){
		alert("Vui lòng nhập link sản phẩm!!")
		$("#buy_link").focus();
		return false
	}
	if (buy_link.indexOf('http://')==-1){
		alert("Vui lòng nhập địa chỉ trang web bạn tìm thấy!");
		$("#buy_link").val('') ;
		$("#buy_link").focus();
		return false
	}
	if ((buy_email==null)||(buy_email=="")){
		alert("Vui lòng nhập email!!")
		$("#buy_email").focus();
		return false
	}
	if (validate_email(buy_email)==false){
		$("#buy_email").val('') ;
		$("#buy_email").focus();
		return false
	}
	
	$.ajax({
			type: "POST",
			url: "/product/ajax_buy_for_me",
			data: 	"cur_link=" + cur_link +"&buy_link="+buy_link+"&buy_email="+buy_email,
			
			success: function(html){
				alert("Thông tin đã được gởi cho chúng tôi, chúng  tôi sẽ liên lạc với bạn trong thời gian sớm nhất có thể.");
				$("#buy_email").val('') ;
				$("#buy_link").val('') ;
			}
		});
}
  
  function find_product(){
	var product_name = $("#find_product_name").val() ;
	var address = $("#find_address").val() ;
	var phone = $("#find_phone").val() ;
	
	if(product_name == '' || address == '' || phone == ''){
		alert('Vui lòng nhập đầy đủ thông tin.');
		return false;
	}
	
	$.ajax({
			type: "POST",
			url: "/product/find_product",
			data: 	"product_name=" + product_name + "&address=" + address + "&phone=" + phone,
			success: function(html){
				alert("Thông tin đã được gởi cho chúng tôi, chúng  tôi sẽ liên lạc với bạn trong thời gian sớm nhất có thể.");
				$("#find_product_name").val('') ;
				$("#find_address").val('') ;
				$("#find_phone").val('') ;
			}
		});
  }
  
  function tg_product(){
	var tg_fullname = $("#tg_fullname").val() ;
	var tg_address = $("#tg_address").val() ;
	var tg_phone = $("#tg_phone").val() ;
	var tg_price = $("#tg_price").val() ;
	var tg_link = $("#tg_link").val() ;
	var cur_price = $("#cur_price").val() ;
	var tg_email = $("#tg_email").val() ;
	var check1 = $('input:checkbox[id=tg_check1]:checked').val();
	var check2 = $('input:checkbox[id=tg_check2]:checked').val();
	
	tg_price = tg_price.replace('.', "");
	tg_price = tg_price.replace('.', "");
	tg_price = tg_price.replace('.', "");
	
	if(tg_fullname == '' || tg_address == '' || tg_phone == '' || tg_price == ''|| tg_email == ''){
		alert('Vui lòng nhập đầy đủ thông tin');
		return false;
	}
	
	if (validate_email(tg_email)==false){
		$("#tg_email").val('') ;
		$("#tg_email").focus();
		return false
	}
	
	if(check1 != 1 || check2 != 1){
		alert('Vui lòng xem kỹ qui định.');
		return false;
	}
	
	if(!IsNumeric(tg_price)){
		alert("Thông tin chưa hợp lệ!!")
		$("#tg_price").val('') ;
		$("#tg_price").focus();
		return false;
	}
	
	if(tg_price < 70*cur_price/100){
		alert('Gía bạn đưa ra quá thấp!!');
		alert(tg_price);
		alert(cur_price);
		return false;
	}
	
	var r=confirm("Vui lòng kiểm tra lại thông tin, với hình thức này bạn phải thanh toán toàn bộ giá trị sản phẩm.");
	if (r==true){
		$.ajax({
			type: "POST",
			url: "/product/ajax_tg_product",
			data: 	"link=" + tg_link + "&address=" + tg_address + "&phone=" + tg_phone + "&name=" + tg_fullname+ "&price=" + tg_price+ "&email=" + tg_email,
			success: function(html){
				alert("Thông tin đã được gởi cho chúng tôi, chúng tôi sẽ liên lạc với bạn trong thời gian sớm nhất.");
				$("#tg_fullname").val('') ;
				$("#tg_address").val('') ;
				$("#tg_phone").val('') ;
				$("#tg_price").val('') ;
			}
		});
	}else{
	  return false;
	}
  }
  
function factory_active_tab(obj, f_char){
		var curentTab=obj.id;
		var tabs=$('#' + curentTab).parent().children();
		$(tabs).each( function(){								
				$(this).attr('class','');
		});	
		$('#' + curentTab).addClass('active_tab');
		
		$.ajax({
			type: "POST",
			url: "/product/ajax_get_factory_by_char",
			data: 	"f_char=" + f_char,
			beforeSend: function(){
				$("#factory_content_loading").show();
			},
			success: function(html){
				$("#factory_content_loading").hide();
				$("#factory_content").html(html);
			}
		});
	}
	
function validate_email(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Địa chỉ email không hợp lệ!")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Địa chỉ email không hợp lệ!")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Địa chỉ email không hợp lệ!")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Địa chỉ email không hợp lệ!")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Địa chỉ email không hợp lệ!")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Địa chỉ email không hợp lệ!")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Địa chỉ email không hợp lệ!")
		    return false
		 }

		 
		
 		 return true					
	}

function reg_sale_email(){
	var emailID = $("#sale_email").val() ;
	if ((emailID==null)||(emailID=="")){
		alert("Vui lòng nhập địa chỉ email!!")
		$("#sale_email").focus();
		return false
	}
	if (validate_email(emailID)==false){
		$("#sale_email").val('') ;
		$("#sale_email").focus();
		return false
	}
	
	$.ajax({
			type: "POST",
			url: "/home/ajax_sale_off_email",
			data: 	"email=" + emailID,
			success: function(html){
				alert("Bạn đã đăng ký thành công, chúng tôi sẽ gởi bạn thông tin khuyến mãi qua email này.")
				$("#sale_email").val('') ;
			}
		});
	return true
 }
 
 function IsNumeric(strString)
   {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

  
 function search_price(){	
	var from = $("#price_from").val() ;
	var to = $("#price_to").val() ;
	
	if ((from==null)||(from=="")){
		alert("Vui lòng nhập thông tin!!")
		$("#price_from").focus();
		return false
	}
	
	if((to==null) || (to=="")){
		alert("Vui lòng nhập thông tin!!")
		
		$("#price_to").focus();
		return false
	}
	
	if(!IsNumeric(from)){
		alert("Thông tin chưa hợp lệ!!")
		$("#price_from").val('') ;
		$("#price_from").focus();
		return false
	}
	
	if(!IsNumeric(to)){
		alert("Thông tin chưa hợp lệ!!");
		$("#price_to").val('') ;
		$("#price_to").focus();
		return false
	}
	
	if(parseInt(from) >= parseInt(to)){
		alert("Thông tin chưa hợp lệ!!");
		$("#price_to").focus();
		return false
	}
	
	location='http://muahangmy.com/product/view/price/'+from+'/'+to+'.html';
 }
 
 function cal_ship_fee(){
	var weight = $("#ship_fee").val() ;
	var your_price = $("#your_price").val() ;
	if(!IsNumeric(weight)){
		alert("Thông tin chưa hợp lệ!!")
		$("#ship_fee").val('') ;
		$("#ship_fee").focus();
		return false
	}
	if(!IsNumeric(your_price)){
		alert("Thông tin chưa hợp lệ!!")
		$("#your_price").val('') ;
		$("#your_price").focus();
		return false
	}
	$("#ship_fee_result").html('Loading...<br />');
	$.ajax({
			type: "POST",
			url: "/product/ajax_cal_ship_fee",
			data: 	"weight=" + weight + "&your_price=" + your_price,
			success: function(html){
				$("#ship_fee_result").html(html);
			}
		});
 }
 
 function pay_after_check(){
	$("#note_pay_after").show();
	$('#note_pay_after').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
	
	$("#pay_after_datcoc").show();
	$('#pay_after_datcoc').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
	
	$("#pay_after_fee").show();
	$('#pay_after_fee').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
	
	$("#pay_before_price").hide();
	$("#pay_after_price").show();
	$('#pay_after_price').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
	
	$("#pay_before_price_label").hide();
	$("#pay_after_price_label").show();
	$('#pay_after_price_label').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
	
	$("#pay_after_tratruoc").show();
	$("#pay_before_discount").hide();
	$('#pay_after_tratruoc').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
	
//	$("#pay_paypal").show();
//	$('#pay_paypal').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
 }
  
 function pay_after_uncheck(){
	$("#note_pay_after").hide();
	$("#pay_after_datcoc").hide();
	$("#pay_after_fee").hide();
	$("#pay_after_price_label").hide();
	$("#pay_after_tratruoc").hide();
	
	$("#pay_after_price").hide();
	$("#pay_before_price").show();
	$('#pay_before_price').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
	
	$("#pay_before_price_label").show();
	$('#pay_before_price_label').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
	
	$("#pay_before_discount").show();
	$('#pay_before_discount').animate({opacity: 0.4}, {duration: 700, easing: 'easeOutBack'}).animate({opacity: 1}, {duration: 700, easing: 'easeOutBack'});
	
	//$("#pay_paypal").hide();
 }
 
 function choice_frame(id){
	$.ajax({
			type: "POST",
			url: "/product/ajax_choise_frame_product",
			data: 	"id=" + id,
			success: function(html){
				alert('Thêm thành công');
			}
		});
 }
 
 function delete_frame(id){
	$.ajax({
			type: "POST",
			url: "/product/ajax_delete_frame_product",
			data: 	"id=" + id,
			success: function(html){
				alert('Xóa thành công');
			}
		});
 }
 
 function add_baogia(){
	var url = $("#bg_url").val() ;
	var name = $("#bg_name").val() ;
	var price = $("#bg_price").val() ;
	var price_off = $("#bg_price_off").val() ;
	var weight = $("#bg_weight").val() ;
	var type_name = $("#bg_type_name").val() ;
	var qty = $("#bg_qty").val() ;
	
	if(url == '' || name == '' || price == '' || price_off == ''|| weight == '' || type_name == '' || qty == ''){
		alert('Vui lòng nhập đầy đủ thông tin');
		return false;
	}
	
	if(!IsNumeric(price)){
		alert("Thông tin chưa hợp lệ!!")
		$("#bg_price").val('') ;
		$("#bg_price").focus();
		return false;
	}	
	if(!IsNumeric(price_off)){
		alert("Thông tin chưa hợp lệ!!")
		$("#bg_price_off").val('') ;
		$("#bg_price_off").focus();
		return false;
	}
	if(!IsNumeric(weight)){
		alert("Thông tin chưa hợp lệ!!")
		$("#bg_weight").val('') ;
		$("#bg_weight").focus();
		return false;
	}
	if(!IsNumeric(qty)){
		alert("Thông tin chưa hợp lệ!!")
		$("#bg_qty").val('') ;
		$("#bg_qty").focus();
		return false;
	}
	
	$.ajax({
		type: "POST",
		url: "/product/ajax_submit_bao_gia",
		data: 	"url=" + url +"&price="+price+"&price_off="+price_off+"&weight="+weight+"&type_name="+type_name+"&qty="+qty+"&name="+name,
		success: function(html){
			$("#bg_bao_gia").load("/product/ajax_list_bao_gia");
		}
	});
	$("#bg_name").val('') ;
	$("#bg_url").val('') ;
	$("#bg_price").val('') ;
	$("#bg_price_off").val('') ;
	$("#bg_weight").val('') ;
	$("#bg_type_name").val('') ;
	$("#bg_qty").val('') ;	
	$("#bg_name").focus();
 }
 
 function add_baogia_more(){
	add_baogia();
	$("#bg_name").val('') ;
	$("#bg_url").val('') ;
	$("#bg_price").val('') ;
	$("#bg_price_off").val('') ;
	$("#bg_weight").val('') ;
	$("#bg_type_name").val('') ;
	$("#bg_qty").val('') ;	
	$("#bg_name").focus();
 }