// 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 insertEmail(emailID)
	{
		makeRequest_2("insertEmail.php",'?Email='+emailID,alertContentsEmail);	
		//name_div_load=namediv;
	}
	function alertContentsEmail() {
	   
      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);
			alert(result);
         } else {

            alert('There was a problem with the request.');
         }
      }
   }
	
	function sendmailmember(){
		if(document.getElementById("Email_member").value == "")
		{
			alert('Nhập Email Của Bạn.');
			document.getElementById("Email_member").focus();
			return false;
		}	
		if(!isEmail(document.getElementById("Email_member").value))
		{
			alert('Email không hợp lệ');
			document.getElementById("Email_member").focus();
			return false;
		}	
		 send_mail_member();
	}
	
	function send_mail_member(){
		var Email_member=document.getElementById("Email_member");
		var account =  encodeURIComponent(Email_member.name) + "=" + encodeURIComponent(Email_member.value);
			account += "&"+ encodeURIComponent("type") + "=" + encodeURIComponent("send_mail_member");
			makePostRequest("sendContact.php", account, onchange_send_mail_member);	
		return false;
	}
	function onchange_send_mail_member() {
	   
      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);
			alert(result);
         } else {
            alert('Có vấn đề khi thực hiện, vui lòng liên hệ với nhà điều hành.');
         }
		 document.getElementById("Email_member").value="";
      }
   }
	
	function check_register()
	{
		var f = document.frm_register;
		if(f.UserName.value=='')
		{
			alert('Nhập tên đăng nhập ');
			f.UserName.focus();
			return false;
		}
		if(f.Password.value!='')
		{
			if(f.Password.value.length<7)
			{
				alert('Mật khẩu (7-13 ký tự)');
				f.Password.focus();
				return false;
			}
			if(f.Password.value!=f.PassConfirm.value)
			{
				alert('Pass và xác nhận pass không giống nhau ');
				f.PassConfirm.value = "";
				f.Password.value = "";
				f.Password.focus();
				return false;
			}
		}
		
		
		if(f.Email.value=='')
		{
			alert('Nhập email ');
			f.Email.focus();
			return false;
		}
		if(!isEmail(f.Email.value))
		{
			alert('Email không hợp lệ');
			f.Email.focus();
			return false;
		}
		if(f.cbDay.value=='')
		{
			alert('Nhập ngày sinh ');
			f.cbDay.focus();
			return false;
		}
		
		if(f.cbMonth.value=='')
		{
			alert('Nhập Tháng ');
			f.cbMonth.focus();
			return false;
		}
		
		if(f.cbYear.value=='')
		{
			alert('Nhập Năm sinh ');
			f.cbYear.focus();
			return false;
		}
		
		if(f.FullName.value=='')
		{
			alert('Nhập họ tên');
			f.FullName.focus();
			return false;
		}
		
		if(f.Address.value=='')
		{
			alert('Nhập địa chỉ');
			f.Address.focus();
			return false;
		}
		if(f.Phone.value=='')
		{
			alert('Nhập số điện thoại');
			f.Phone.focus();
			return false;
		}
		
		return true;
	}
	
	function send_info_contact()
	{
		var theForm=document.frm_contact;
		if(theForm.Name.value=='')
		{
			alert('Nhập Tên Quý Khách !');
			theForm.Name.focus();
			return false;
		}
				
		if(theForm.Telephone.value=='')
		{
			alert('Nhập số điện thoại Quý Khách !');
			theForm.Telephone.focus();
			return false;
		}
		
		if(!checkPhone(theForm.Telephone.value))
		{
			alert('Số điện thoại không hợp lệ!');
			theForm.Telephone.focus();
			return false;
		}
		
		/*if(theForm.Email.value=='')
		{
			alert('Nhập Email Quý Khách !');
			theForm.Email.focus();
			return false;
		}*/
		if(!isEmail(theForm.Email.value))
		{
			alert('Email không hợp lệ!');
			theForm.Email.focus();
			return false;
		}
		
		
		if(theForm.Address.value=='')
		{
			alert('Nhập địa chỉ Quý Khách !');
			theForm.Address.focus();
			return false;
		}
		
		if(theForm.Message.value=='')
		{
			alert('Nhập nội dung liên hệ !');
			theForm.Message.focus();
			return false;
		}
		
		if(theForm.Message.value.length<10)
		{
			alert('Nhập nội dung liên hệ !');
			theForm.Message.focus();
			return false;
		}
		
		if(theForm.capcha_check.value == "" || theForm.capcha_check.value.length < 5){
			alert('Nhập Mã an toàn!');
			theForm.capcha_check.focus();
			return false;
		}
		getParam(theForm);
	}
	function send_contact(){
		var theForm=document.frm_contact;
		var account =  encodeURIComponent(theForm.Name.name) + "=" + encodeURIComponent(theForm.Name.value)+"&"+encodeURIComponent(theForm.Telephone.name) + "=" + encodeURIComponent(theForm.Telephone.value);
		account += "&"+ encodeURIComponent(theForm.Address.name) + "=" + encodeURIComponent(theForm.Address.value);
		account += "&"+ encodeURIComponent(theForm.Email.name) + "=" + encodeURIComponent(theForm.Email.value);
		account += "&"+ encodeURIComponent(theForm.Message.name) + "=" + encodeURIComponent(theForm.Message.value);
		account += "&"+ encodeURIComponent(theForm.contact_frm.name) + "=" + encodeURIComponent(theForm.contact_frm.value);
		account += "&"+ encodeURIComponent(theForm.Telephone.name) + "=" + encodeURIComponent(theForm.Telephone.value);
		makePostRequest("sendContact.php", account, onchangeSendContact);	
		return false;
	}
	function onchangeSendContact() {
	   
      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);
			alert(result);
         } else {
            alert('Có vấn đề khi thực hiện, vui lòng liên hệ với nhà điều hành.');
         }
		 document.location.href="./";
      }
   }
    function trim(s){
		s = trimLeft(s);
		s = trimRight(s);
		return(s);
	}
	function trimLeft(s){
		var i;
		i=0;
		var n;
		n = s.length;
		while((i<n)&&(s.charAt(i)==' ')) i++;
			s = s.substring(i);
		return(s);
	} 

   function trimRight(s){
		var n;
		n = s.length;
		var i;
		i = s.length-1;
		while((i>=0)&&(s.charAt(i)==' ')) i--;
			s = s.substring(0,i+1);
		return(s);
	}
	function isDigit(c)
	{
	if((c=='0')||(c=='1')||(c=='2')||(c=='3')||(c=='4')||(c=='5')||(c=='6')||(c=='7')||(c=='8')||(c=='9'))
		return true;
	else
		return false;
	}
   
   function isEmail(strEmail)
	{
	 var intlen;
	 var ctmp;
	 strEmail = trim(strEmail);
	 if(strEmail=='') return false;
	 intlen=strEmail.length;
	 if(intlen<5) return false;
	 if(strEmail.indexOf('@')==-1) return false;
	 if(strEmail.indexOf('.')==-1) return false;
	 if(intlen - strEmail.lastIndexOf('.') -1 > 4) return false; 
	 if((strEmail.indexOf("_")!=-1) && (strEmail.lastIndexOf("_") > strEmail.lastIndexOf("@"))) return false;
	 if(strEmail.lastIndexOf(".") <= strEmail.lastIndexOf("@")+1)  return false;
	 if(strEmail.indexOf("@")!=strEmail.lastIndexOf("@")) return false;
	 if(intlen -1 == strEmail.lastIndexOf('.')) return false;
	 if(strEmail.charAt(strEmail.indexOf('@')+1)=='.') return false;
	 if(strEmail.indexOf(" ")!=-1) return false;
	 if(strEmail.indexOf("..")!=-1) return false;
	 
	 strEmail=strEmail.toLowerCase();
	 for(intcnt=0;intcnt<intlen;intcnt++)
		{
		 ctmp = strEmail.charAt(intcnt)
		 if((!isDigit(ctmp))&& ((ctmp>'z')||(ctmp<'a')) && (ctmp!='-') && (ctmp!='.') && (ctmp!='@') && (ctmp!='_')) return false;
		}
	
	return true	;
	}
	
	function isInteger(s)
	{   var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	
	function send_info_bds()
	{
		var theForm=document.form_bds;
		if(theForm.ContactName.value=='')
		{
			alert('Nhập Tên Quý Khách !');
			theForm.ContactName.focus();
			return false;
		}
		
		if(theForm.ContactTel.value!='')
		{
			if(!checkPhone(theForm.ContactTel.value)){
			alert('Nhập Điện Thoại Không Đúng Định Dạng!');
			theForm.ContactTel.focus();
			return false;
			}
		}
		if(theForm.ContactPhone.value!='')
		{
			if(!checkPhone(theForm.ContactPhone.value)){
			alert('Nhập Di Động Không Đúng Định Dạng!');
			theForm.ContactPhone.focus();
			return false;
			}
		}
		if(theForm.ContactFax.value!='')
		{
			if(!checkPhone(theForm.ContactFax.value)){
			alert('Nhập Số Fax Không Đúng Định Dạng!');
			theForm.ContactFax.focus();
			return false;
			}
		}
		
		if(theForm.ContactAddress.value=='')
		{
			alert('Nhập địa chỉ Quý Khách !');
			theForm.ContactAddress.focus();
			return false;
		}
		
		if(theForm.NameBDS.value=='')
		{
			alert('Nhập Tiêu Đề Tin Đăng!');
			theForm.NameBDS.focus();
			return false;
		}	
		
		if(theForm.NameBDS.value.length<10)
		{
			alert('Tiêu Đề Tin Đăng Quá Ngắn!');
			theForm.NameBDS.focus();
			return false;
		}	
		
		if(theForm.Price.value=='')
		{
			alert('Nhập Giá Bán!');
			theForm.Price.focus();
			return false;
		}	
		
		if(theForm.CityID_bds.value=='')
		{
			alert('Chọn Tỉnh/ Thành phố!');
			theForm.CityID_bds.focus();
			return false;
		}	
		
		
		/*if(!isInteger(theForm.DienTich.value)){
			alert('Nhập Diện tích!');
			theForm.DienTich.value = '';
			theForm.DienTich.focus();
			return false;
		}*/
		
		if(theForm.capcha_check.value == "" || theForm.capcha_check.value.length < 5){
			alert('Nhập Mã xác nhận!');
			theForm.capcha_check.focus();
			return false;
		}
		
		getParam(theForm,'bds');
	}
		
		
	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;
	
	function isInteger(s)
	{   var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	
	function stripCharsInBag(s, bag)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
	
	function checkInternationalPhone(strPhone){
		s=stripCharsInBag(strPhone,validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}
	
	function checkPhone(Phone){
		var Phone;
		if (checkInternationalPhone(Phone)==false){
			return false
		}
		return true
	 }
	 
	function checkNum_wh()
	{
	  	 var theForm=document.form_bds;
		
		var rong = Number(theForm.KichThuoc_rong.value.replace(",", "."));
		var dai = Number(theForm.KichThuoc_dai.value.replace(",", "."));
		var DTKV= rong*dai;
			DTKV = DTKV+'';
		var DTKV_arry = DTKV.split('.');
		if(DTKV_arry.length>1)
			DTKV = DTKV_arry[0]+'.'+DTKV_arry[1].substring(0,2);
		theForm.DienTichKV.value = DTKV;
	}
	
	function checkNum_bds(e,this_)
	{
	 var str = this_.value;
	 var keynum
	 var keychar
	 var numcheck
	 
	 if(window.event) // IE
	 {
	  keynum = e.keyCode
	 }
	 
	 else if(e.which) // Netscape/Firefox/Opera
	 {
	  keynum = e.which
	 }
	 if(keynum==undefined)
	 {
	 //  alert('AAAA');
	  //Tab
	  return true;
	 }
	 //alert(keynum)
	 keychar = String.fromCharCode(keynum)
	 //alert(keynum)
	
	 numcheck = /\d/
	 // 46 . 44 , 43 +,32 khoang trang; 44 day ,
	 //return (numcheck.test(keychar) || (keynum == 8)||(keynum == 45));
	 if(
			(numcheck.test(keychar) || 
				(keynum == 8) || (keynum == 9) ||(keynum == 45) ||(keynum == 41) ||(keynum == 40) ||
				(keynum == 46 && str.indexOf(".")==-1 && str.indexOf(",")==-1 && str != "") || 
				(keynum == 44 && str.indexOf(".")==-1 && str.indexOf(",")==-1 && str != "")
			) 
	 )
	 //if((keynum >47 && keynum <58))
	 {
		 
	  return true
	 }
	 else
	 {
	  return false  
	 }
	}
