// ActionScript Document

   var http_request = false;
   var name_div_load = '';
   //Initiate the AJAX GET request
   function makeRequest(url, parameters) {
       http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {	
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }

	function makeRequest_2(url, parameters,fun) 
	{
		   http_request = false;
		  if (window.XMLHttpRequest) { // Mozilla, Safari,...
			 http_request = new XMLHttpRequest();
			 if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/html');
			 }
		  } else if (window.ActiveXObject) { // IE
			 try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
				try {	
				   http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			 }
		  }
		  if (!http_request) {
			 alert('Cannot create XMLHTTP instance');
			 return false;
		  }
		  http_request.onreadystatechange =  fun;
		  http_request.open('GET', url + parameters, true);
		  http_request.send(null);
	}
	 
	//Initiate the AJAX POST request
	function makePostRequest(url, param, func) {
	  http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {	
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = func;
	  
      http_request.open('POST', url, true);
	  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  http_request.setRequestHeader("Content-length", param.length);
	  http_request.setRequestHeader("Connection", "close");
	
	  //Make the request
	  http_request.send(param); 
	}


   function alertContents() {
	   
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			//document.getElementById(name_div_load).className = 'test';
			//alert(result);
			document.getElementById(name_div_load).innerHTML = result;
         } else {

            show_notice_box('There was a problem with the request.');
         }
      }
   }
   function onchangeUpdateCheckbox() {
	   
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			//document.getElementById(name_div_load).className = 'test';
			document.getElementById(name_div_load + "_selectbox").innerHTML = result;
			//alert(result);
//			alert(name_div_load + "_selectbox");
			//
			if(result.length!=0)
			{
				//alert(customUpdate);
				//Custom.init();
			}
			else
			{
				document.getElementById(name_div_load).style.display="none";
			}
			customUpdate=0;
         } else {

            show_notice_box('There was a problem with the request.');
         }
      }
   }
   
   function onchangeShowTotal() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
			 //alert("add cart thành công");
            result = http_request.responseText;
			show_msg_box(result);

         } else {
            show_notice_box('There was a problem with the request.');
         }
      }
   }
   function onchangeAddCart() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
			 //alert("add cart thành công");
            result = http_request.responseText;
			document.getElementById('giohang003').innerHTML = result;
			//var myDiv=document.getElementById("giohang001");
			//if(myDiv!=null&&myDiv.scrollUpdate) myDiv.scrollUpdate(); 
			//document.getElementById('sum_cart').innerHTML=document.getElementById('sum_content_cart').value;
			//alert('Thêm vào giỏ hàng thành công !');
			show_notice_box('Thêm vào giỏ hàng thành công !');
			document.getElementById("e_16").style.display="none";
         } else {
            show_notice_box('There was a problem with the request.');
         }
      }
   }
   function onchangeCheckoutContentCart() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
			 //alert("add cart thành công");
            result = http_request.responseText;
			document.getElementById('checkout018_bis').innerHTML = result;	
			if(document.getElementById('total_cart').value==0)
			{
				window.location="index.php?action=notice";	
			}
			else
			{
				show_notice_box('Cập nhật thành công.');
				//alert('aaa');
				document.getElementById('sum_total_cart').innerHTML =addSignIntoNumber(document.getElementById('total_cart').value,'.');
				document.getElementById('div_value_shipping').innerHTML = addSignIntoNumber(document.getElementById('value_shipping_cart').value,".");
				//alert(document.getElementById('value_sale_off_cart').value);
				document.getElementById('div_value_sale_off').innerHTML = "-" + addSignIntoNumber(Math.round(document.getElementById('value_sale_off_cart').value),".");
				var x =Math.round(document.getElementById('total_cart').value);
				var y =0;
				var theForm=document.frm_do_checkout;
				//alert(theForm);
				if(theForm!=undefined)
				{
					var paymethod=getCheckedValue(theForm.radio_payment);
					if(paymethod==4)
					{
						y =Math.round(document.getElementById('value_shipping_cart').value);
					}
				}
				
				
				var z= Math.round(document.getElementById('value_sale_off_cart').value);
				var div_value_coupons=Math.round(addSignOuttoNumber(document.getElementById('div_value_coupons').innerHTML,"."));
				var div_value_sum_total=Number(x+y-z-div_value_coupons);
				if(div_value_sum_total<0) div_value_sum_total=0;
				document.getElementById('div_value_sum_total').innerHTML=addSignIntoNumber(div_value_sum_total,".");
				document.getElementById('giohang003').innerHTML=document.getElementById('banner_cart_div').innerHTML;
				
			}
			
         } else {
            show_notice_box('There was a problem with the request.');
         }
      }
   }

	function getCityCode(idCountry,namediv)
	{
		makeRequest('../getCityCode.php','?CountryID='+idCountry);	
		name_div_load=namediv;
	}
	//email exist in backend(admin)
	function checkEmailExist(process_file, emailID,namediv)
	{
		makeRequest(process_file,'?Email='+emailID);	
		name_div_load=namediv;
	}
	
	function checkCaptcha(process_file, captcha,namediv){
		makeRequest(process_file,'?txtCaptcha='+captcha);	
		name_div_load=namediv;
	}
	
	function checkUserDBExisting(userDBID,namediv)
	{
		makeRequest('../checkUserDB.php','?UserDB='+userDBID);	
		name_div_load=namediv;
	}
	
	function showSuggestList(email,namediv)
	{
		makeRequest('../getSuggestList.php','?email='+email);	
		name_div_load=namediv;
	}
	
	function ajaxUpdateDistrict(cityid,namediv)
	{
		
		makeRequest_2('./getDictrictCode.php','?CityID='+cityid,onchangeUpdateCheckbox);	
		name_div_load=namediv;
	}
	function ajaxUpdateWard(dictrictid,namediv)
	{
		
		makeRequest_2('./getWardCode.php','?DictrictID='+dictrictid,onchangeUpdateCheckbox);	
		name_div_load=namediv;
	}
	
	function ajaxShowTotal(date_pay)
	{
		
		if(check_frm_step_4())
		{
			var theForm=document.frm_do_checkout;
			var paymethod=getCheckedValue(theForm.radio_payment);
			makeRequest_2('./getContentTotal.php','?paymethod='+paymethod+"&date="+date_pay,onchangeShowTotal);
		}
		else
		{
			DontAgreeInfo();
		}
		return false;
	}
	function getRuleDescription(ruleId, divName){
		name_div_load=divName;
		makeRequest_2('./getContentRule.php','?rule_id='+ruleId, function(){ if (http_request.readyState == 4) {
         if (http_request.status == 200) {
				//alert(http_request.responseText);
				result = http_request.responseText;
				//document.getElementById(name_div_load).className = 'test';
				//alert(result);
				document.getElementById(name_div_load).innerHTML = result;
				for(i in ids){document.getElementById(ids[i]).style.color = "#000000"; };
				document.getElementById(ruleId).style.color = "#f5771e"; 
			 } else {
	
				show_notice_box('There was a problem with the request.');
			 }
     	 } });
	}
	
	function showProductDetail(productid)
	{
		makeRequest_2('./getProductDetail.php','?productid='+productid,alertContents_showProductDetail);	
	}
	
	function showProductDetail_2(productid)
	{
		makeRequest_2('./getProductDetail_2.php','?productid='+productid+'&mode=detail',alertContents_showProductDetail_2);	
	}
	function showProductDetail_3(productid)
	{
		makeRequest_2('./getProductDetail_3.php','?productid='+productid,alertContents_showProductDetail);	
	}
	function alertContents_showProductDetail() {
		   
		  if (http_request.readyState == 4) {
			 if (http_request.status == 200) {
				//alert(http_request.responseText);
				result = http_request.responseText;
				//document.getElementById(name_div_load).className = 'test';
				//alert(result);
				document.getElementById("e_16").innerHTML = result;
				document.getElementById("txt_amount").focus();
				//document.frm_detail_pro.txt_amount.focus();
				//alert("AAAAA");
			 } else {
	
				show_notice_box('There was a problem with the request.');
			 }
		  }
	   }
		
	function alertContents_showProductDetail_2() {
		   
		  if (http_request.readyState == 4) {
			 if (http_request.status == 200) {
				//alert(http_request.responseText);
				result = http_request.responseText;
				//document.getElementById(name_div_load).className = 'test';
				//alert(result);
				document.getElementById("e_16").innerHTML = result;
				
				//document.frm_detail_pro.txt_amount.focus();
				//alert("AAAAA");
			 } else {
	
				show_notice_box('There was a problem with the request.');
			 }
		  }
	   }
		
	
	function showMenu(cateid,stallid)
	{
		
		makeRequest_2('./getMenu.php','?categoryid='+cateid+'&stallid='+stallid,alertContents_showMenu);	
		//name_div_load=namediv;
	}
	function alertContents_showMenu() {
		   
		  if (http_request.readyState == 4) {
			 if (http_request.status == 200) {
				//alert(http_request.responseText);
				result = http_request.responseText;
				//document.getElementById(name_div_load).className = 'test';
				//alert(result);
				
				document.getElementById("menu").innerHTML = result;
				//alert(document.getElementById("id_parent").value);
				document.getElementById("article_"+document.getElementById("id_parent").value).className="linkMenuStall cursor_on_button";
				document.getElementById("article_"+document.getElementById("id_parent").value).className="linkMenuStall_active cursor_on_button";
				document.getElementById("id_parent").value=document.getElementById("id_parent").value;
				//document.getElementById("current_pro").value=0;
				//alert (document.getElementById("id_parent").value);
				so = new SWFObject("poster_1.swf", "flashObject", "710", "394", "5", "");
				so.addParam("wmode", "transparent");	
				so.write("poster")
				//loadArticle(document.getElementById("id_parent").value);
			} else {
	
				show_notice_box('There was a problem with the request.');
			 }
		  }
	   }
	
	function checkLoginAccount(theForm){
		if(theForm.txtEmail.value=='' || theForm.txtPass.value==''){
			show_message_box('w', "Vui lòng nhập Email (hoặc ID) và mật khẩu!", 120, 620, 3000);
			theForm.txtEmail.focus();
			return;
		}
		
		//REM
		//if(!chkEMail(theForm.txtEmail)){
			//alert("Bạn nhập email không đúng!\nVí dụ email đúng: tencuatui@dichotructuyen.vn");		
			//theForm.txtEmail.focus();
			//return;
		//}
		
		//var account =  encodeURIComponent(theForm.txtEmail.name) + "=" + encodeURIComponent(theForm.txtEmail.value)+"&"+encodeURIComponent(theForm.txtPass.name) + "=" + encodeURIComponent(theForm.txtPass.value)+"&"+encodeURIComponent(theForm.check_register.name) + "=" + encodeURIComponent(theForm.check_register.checked);
		
		var account =  encodeURIComponent(theForm.txtEmail.name) + "=" + encodeURIComponent(theForm.txtEmail.value)+"&"+encodeURIComponent(theForm.txtPass.name) + "=" + encodeURIComponent(theForm.txtPass.value);
		
		makePostRequest("checkLoginAccount.php", account, onchangeCheckLoginAccount);		
	}
	
	
	// begin private function part
	function encodeNameAndValue(sName, sValue) {
		var sParam = encodeURIComponent(sName);
		sParam += "";
		sParam += encodeURIComponent(sValue);
		return sParam;
	}
	
	
	 function onchangeCheckLoginAccount(){
		 var theForm = document.frmLogin;
		  if (http_request.readyState == 4) {
			  if (http_request.status == 200) {
					//alert(http_request.responseText);
					result = http_request.responseText;
					
					result = eval(result);
					if (result) {
						theForm.submit();
					}
					else{
						show_message_box('w', "Địa chỉ email hoặc mật khẩu không đúng!\nVui lòng nhập lại", 120, 620, 3000);
						theForm.txtEmail.focus();
						theForm.txtPass.value="";
					}
					
			  } else {
		
					show_notice_box('There was a problem with the request.');
			  }
		  }
	  }
	  
	   function onchangeCheckLoginAccount_Checkout(){
		 var theForm = document.frmLogin;
		  if (http_request.readyState == 4) {
			  if (http_request.status == 200) {
					//alert(http_request.responseText);
					result = http_request.responseText;
					
					result = eval(result);
					if (result) {
						//theForm.submit();
						show_notice_box('Đăng nhập thành công.');
						
						//window.location="index.php?action=checkout";
					}
					else{
						alert("Địa chỉ email hoặc mật khẩu khônd đúng!\nVui lòng nhập lại");
						//theForm.txtEmail.focus();
						//theForm.txtPass.value="";
						
					}
					window.location=document.location.href;
			  } else {
		
					show_notice_box('There was a problem with the request.');
			  }
		  }
	  }
	  // end private function part
	  
	 function onchangeAllStepProfile_1(){
		 var theForm = document.frmLogin;
		  if (http_request.readyState == 4) {
			  if (http_request.status == 200) {
					//alert(http_request.responseText);
					result = http_request.responseText;
					document.getElementById("tab_buoc_1").innerHTML = result;
					//alert("AAAAA");
					//Custom.init();
					//alert(document.getElementById("id_login_user").value);
					show_notice_box(msgInfoAccount + ' thông tin thành công.');
			  } else 
			  {
					show_notice_box('There was a problem with the request.');
			  }
		  }
	  }
	  // end private function part
	  
	  function onchangeAllStepProfile_2(){
		 var theForm = document.frmLogin;
		  if (http_request.readyState == 4) {
			  if (http_request.status == 200) {
					//alert(http_request.responseText);
					result = http_request.responseText;
					document.getElementById("tab_buoc_2").innerHTML = result;
					customUpdate="select_tinh_tp";
					//Custom.init();
					customUpdate="select_quan_huyen";
					//Custom.init();
					customUpdate="select_phuongxa";
					//Custom.init();	
					customUpdate=0;
					show_notice_box(msgInfoAccount + ' địa chỉ thanh toán thành công.');
					//alert("AAAAA");
					//Custom.init();
					//alert(document.getElementById("id_login_user").value);
			  } else 
			  {
					show_notice_box('There was a problem with the request.');
			  }
		  }
	  }
	  // end private function part
	  
	  function onchangeAllStepProfile_3(){
		 var theForm = document.frmLogin;
		  if (http_request.readyState == 4) {
			  if (http_request.status == 200) {
					//alert(http_request.responseText);
					result = http_request.responseText;
					document.getElementById("tab_buoc_3").innerHTML = result;
					customUpdate="select_tinh_tp_2";
					//Custom.init();
					customUpdate="select_quan_huyen_2";
					//Custom.init();
					customUpdate="select_phuongxa_2";
					//Custom.init();	
					customUpdate=0;
					show_notice_box(msgInfoAccount + ' địa chỉ giao hàng thành công.');
					//alert("AAAAA");
					//Custom.init();
					//alert(document.getElementById("id_login_user").value);
			  } else 
			  {
					show_notice_box('There was a problem with the request.');
			  }
		  }
	  }
	  function onchangeAllStepProfile_4(){
		 
		  if (http_request.readyState == 4) {
			  if (http_request.status == 200) {
					//alert(http_request.responseText);
					result = http_request.responseText;
					document.getElementById("tab_buoc_4").innerHTML = result;
					var theForm = document.frm_edit_coupons;
					if(theForm.upgrade_b4.value=="ok")
					{
						show_tab(6);
						$(document).ready(function(){
							$("#content-wrapper").easyPagi();
						});
						show_notice_box('Qui đổi điểm ra thẻ thành công.');
					}
					else
					{
						show_notice_box('Qui đổi điểm ra thẻ thất bại.');
					}
			  } else 
			  {
					show_notice_box('There was a problem with the request.');
			  }
		  }
	  }
	  
	  
	  
	  function onchangeAllStepProfile_5(){
		 var theForm = document.frmLogin;
		  if (http_request.readyState == 4) {
			  if (http_request.status == 200) {
					//alert(http_request.responseText);
					result = http_request.responseText;
					document.getElementById("tab_buoc_5_main").innerHTML = result;
					var theForm = document.frm_edit_coupons_level;
					if(theForm.upgrade_b5.value=="ok")
					{
						document.getElementById("level_name_user_div").innerHTML=theForm.level_name_user_value.value;
						//alert(theForm.level_name_user_value.value);
						$(document).ready(function(){
							$("#content-wrapper").easyPagi();
						});
						show_notice_box('Nâng cấp thành viên thành công.');
					}
					else
					{
						show_notice_box('Nâng cấp thành viên thất bại.');
					}
					
					
			  } else 
			  {
					show_notice_box('There was a problem with the request.');
			  }
		  }
	  }
	  // end private function part
	  
	 function onchangeAllStepCheckout(){
		 var theForm = document.frmLogin;
		  if (http_request.readyState == 4) {
			  if (http_request.status == 200) {
					//alert(http_request.responseText);
					result = http_request.responseText;
					document.getElementById("checkout009").innerHTML = result; 
					
					if(document.getElementById('verified_image')){
						captchaValue = getVerifyString();
						document.getElementById('verified_image').innerHTML = captchaValue;
					}
					//alert("AAAAA");
					//Custom.init();
					//alert(document.getElementById("id_login_user").value);
					if(document.getElementById("id_login_user").value=="YES")
					{
						document.getElementById("info_shipping").style.display="block";
						document.getElementById("info_user_level").style.display="block";
						document.getElementById("div_value_shipping").innerHTML =document.getElementById("value_shipping_input").value;
						document.getElementById("div_level_name").innerHTML =document.getElementById("value_name_level_input").value;
						document.getElementById("div_value_sale_off").innerHTML =document.getElementById("value_sale_off_input").value;
						
						if(document.getElementById("value_new_register").value=="YES")
						{
							window.location="index.php?action=checkout";
						}
					}
					else
					{
						document.getElementById("info_shipping").style.display="none";
						document.getElementById("info_user_level").style.display="none";
						document.getElementById("div_value_shipping").innerHTML ="";
						document.getElementById("div_level_name").innerHTML ="";
						document.getElementById("div_value_sale_off").innerHTML ="";
					}
					document.getElementById('div_value_shipping').style.display="none";
					document.getElementById('div_value_shipping_pay').style.display="block";
					var x= Math.round(document.getElementById("value_sum_total_input").value);
					var div_value_coupons=Math.round(addSignOuttoNumber(document.getElementById('div_value_coupons').innerHTML,"."));
					document.getElementById("div_value_sum_total").innerHTML =addSignIntoNumber(x-div_value_coupons,".");
					
					
			  } else 
			  {
		
					show_notice_box('There was a problem with the request.');
			  }
		  }
	  }
	  function onchangeUpdateCoupons()
	  {
		 
		 if (http_request.readyState == 4) {
			  if (http_request.status == 200) {
					//alert(http_request.responseText);
					  if (http_request.status == 200) {
					//alert(http_request.responseText);
							result = http_request.responseText;
							document.getElementById("content_the_giam_gia").innerHTML = result; 
							document.getElementById('div_value_coupons').innerHTML=addSignIntoNumber(document.getElementById("sale_off_amount_value").value);
							var x= Math.round(document.getElementById("value_sum_total_input").value);
							var y =0;
							var theForm=document.frm_do_checkout;
							if(theForm!=undefined)
							{
								var paymethod=getCheckedValue(theForm.radio_payment);
								if(paymethod==4)
								{
									y =Math.round(addSignOuttoNumber(document.getElementById('div_value_shipping').value,"."));
									
								}
							}
							
							document.getElementById('info_coupons').style.display="inner";
							var div_value_coupons=Math.round(addSignOuttoNumber(document.getElementById('div_value_coupons').innerHTML,"."));
							document.getElementById("div_value_sum_total").innerHTML =addSignIntoNumber(x+y-div_value_coupons,".");
							
			 		 }
					
			 
			  } 
			  else 
			  {
					show_notice_box('There was a problem with the request.');
			  }
		  }
		  
	  }
	  // end private function part
	 