var _numberOfImages = new Array(1,1,8,12,12,12,0,0,0,12,0,0,12);
var _numberOfChar = new Array(0,139,1000,1500,2000,2500,2500);

// This function use to get data from server 'AJAX' for Combobox
function updatepage(str,DivId){
    document.getElementById(DivId).innerHTML = str;
}
function xmlhttpLoadData(placeHolder,serverPage,id,type,width, size) {
	var strURL = serverPage+"?id="+id+"&type="+type+"&width="+width+"&size="+size;
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			if(encodeURIComponent(strURL) != ''){
				updatepage(self.xmlHttpReq.responseText,placeHolder);
			} 
        }
    }
    self.xmlHttpReq.send(null);    
}

function xmlhttpPostLocation(placeHolder,serverPage,id,type,width,size) {
	var strURL = serverPage+"?id="+id+"&type="+type+"&width="+width+"&size="+size;
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			if(encodeURIComponent(strURL) != ''){
				updatepage(self.xmlHttpReq.responseText,placeHolder);
			} 
        }
    }
    self.xmlHttpReq.send(null);
    
}

function checkDataSearchCustomer(){
	var cusID = trim(document.getElementById('srch_CusID').value);
	var cusName = trim(document.getElementById('srch_ReCode').value);	
	var cusIc = trim(document.getElementById('slt_IC').value);
	var cusPackage = trim(document.getElementById('slt_Package').value);
	var cusDate = trim(document.getElementById('srch_CusRegDate').value);
	if(cusID.length == 0 && cusName.length == 0 && cusDate.length == 0 && cusIc == '0' && cusPackage == '0'){
		alert('Vui lòng nhập vào trường cần tìm');
		return false;
	}
}

function xmlhttpLoadDataContact(placeHolder,serverPage,id,type,txtContactID) {
	var strURL = serverPage+"?id="+id+"&type="+type;
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			if(encodeURIComponent(strURL) != ''){
				if(self.xmlHttpReq.responseText){
					updatepage(self.xmlHttpReq.responseText,placeHolder);					
				}else {					
					//document.getElementById(txtContactID).focus();
					
					//if(type == 0)
						document.getElementById(placeHolder).innerHTML = "Không tồn tại mã số: <strong style=\"color:red\">"+ id +".</strong>";
					//else if(type == 1) document.getElementById(placeHolder).innerHTML = "Không tồn tại mã số: <strong style=\"color:red\">"+ id +". Vui lòng nhập mã số.</strong>";
				}
			} 
        }
    }
    self.xmlHttpReq.send(null);    
}
function openCheckCusId(placeHolder,serverPage,id,type){
	if(type == 0){
		if(id != ''){
			xmlhttpLoadDataContact(placeHolder,serverPage,id,0,'txtCusID');
		}
	}else if(type == 1){
		xmlhttpLoadDataContact(placeHolder,serverPage,id,1,'txtContactID');
	}	
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

var popUpWin = 0;
function js_popup(URLStr) {
	var width="530", height="400";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
    if(popUpWin) {
      if(!popUpWin.closed) popUpWin.close();
    }
    popUpWin = open(URLStr, 'popUpWin', 'scrollbars=yes,toolbar=no,location=no,directories=no,status=yes,menub ar=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  } 

function openCusInfo(inputID,serverPage) {
    js_popup(serverPage);//+"?cus_id=" + escape(inputID))
	return true;
} 

function showNewsCushtml(){
	document.getElementById('tbl_CusInfo').style.display = 'none';	
	document.getElementById('divCusInfor').style.display = 'block';	
}

function returnData(elementID,cID) {
    if (document.getElementById) {    	
      var el = document.getElementById(elementID);
      el.value = cID;
      el.focus();
    } else {
      alert("Khong the gan gia tri");
      return false;
    }
    return true;
} 

function autoChangeMoney(id){
	var smoney = document.getElementById(id).value;
	emoney = currency(smoney);
	/*if(emoney =='0')
		emoney ="";*/
	document.getElementById(id).value = emoney;
}

function currency(v){
   v2="";
   if(v.indexOf('.') >0){
   	v1 = v.substring(0,v.indexOf('.'));
   	v2 = v.substring(v.indexOf('.'),v.length);
   	v = v1;
   	v3 = v2.substring(1,v2.length);
   	if(v3.indexOf('.')>0){
   		v2=v3.substring(0,v3.indexOf('.'));   		
   	}
   	else if(v3.indexOf(',')>0){
   		v2=v3.substring(0,v3.indexOf(','));   		
   	}
   	else{
   		v2=v3;
   	}
   	if(isNaN(v2)) v2 = '0';
   	
   	if(v2.length>=2){
		numTemp = new Number(v2.substring(0,2));
		v2 = numTemp;
	}
	v2 = "."+v2;
   }
   v = v.toString().replace(/\$|\,/g,'');
   
    if(isNaN(v))
    v = "0";
    sign = (v == (v = Math.abs(v)));
    v = Math.floor(v*100+0.50000000001);
    cents = v%100;
    v = Math.floor(v/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((v.length-(1+i))/3); i++)
    v = v.substring(0,v.length-(4*i+3))+','+v.substring(v.length-(4*i+3));
    return (((sign)?'':'-')+ v)  + v2;
   
}

function checkAll(name,id){
	var chkControl = document.getElementsByName(name);
	var chkId = document.getElementById(id);
	if(chkId.checked){
		for(var i=0; i<chkControl.length; i++)
		{
			chkControl[i].checked = true;
		}
	}else
	{
		for(var i=0; i<chkControl.length; i++)
		{
			chkControl[i].checked = false;
		}
	}
}


function showCustomerCompany(id){
	if(id == 1 || id == 0){
		document.getElementById('tbl_Customer').style.display = 'block' ;
		document.getElementById('tbl_Company').style.display = 'none' ;
		document.getElementById('txt_Content').style.display = 'none' ;
		document.getElementById('divContentMsg').style.display = 'none' ;
	}
	else{
		document.getElementById('tbl_Customer').style.display = 'none' ;
		document.getElementById('tbl_Company').style.display = 'block' ;
		document.getElementById('txt_Content').style.display = 'block' ;
		document.getElementById('divContentMsg').style.display = 'block' ;
	}
		
}

function showPicture(mValue, id){
	if(mValue != ''){
		document.getElementById(id).innerHTML = "<img src='"+ mValue +"' width='90' height='70'>";
	}
}

function change_money(type, id, language){
	
	var _USD = document.getElementById('slt_Rate')[0].text;
	var _SJC = document.getElementById('slt_Rate')[1].text*10;
	var _re_TextRate = document.getElementById('hd_Price_'+id).value;
	var _re_Text = _re_TextRate.substring(_re_TextRate.indexOf(' '));
	var _re_RateTemp = _re_TextRate.substring(0,_re_TextRate.indexOf(' '));
	var _re_Unit = document.getElementById('hd_Unit_'+id).value;	
	var _re_UnitTitle = document.getElementById('hd_UnitTitle_'+id).value;
	var _re_RateID = document.getElementById('hd_Rate_'+id).value;
	var _re_AreaText = document.getElementById('re_Area_'+id).innerHTML; // get area of the property
	var _re_Area = _re_AreaText.substring(0, _re_AreaText.indexOf('m'));
	var _price = "";
	var _re_Rate = _re_RateTemp.replace(/,/g,'');	
	switch(type){
		case 1: //VND
			if(_re_Rate == 0){ _price = "Thương lượng";}
			else{
				if(_re_Unit > 1){				
					if(_re_RateID == 2){
						_price = currency1(_re_Rate * _USD) + " (VNĐ)";
					}else if(_re_RateID == 5){
						//_price = currency1(_re_Rate * (_SJC)*1000) + " (VNĐ)";
						_price = currency1(_re_Rate * (_SJC)) + " (VNĐ)";
					}
					else{
						_price = currency1(_re_Rate) + " (VNĐ)";
					}							
				}else{ 
					if(_re_RateID == 2){
						_price = currency1(_re_Rate * _USD * _re_Area) + " (VNĐ)";
					}else if(_re_RateID == 5){
						_price = currency1(_re_Rate * (_SJC)* _re_Area) + " (VNĐ)";
					}
					else{
						_price = currency1(_re_Rate * _re_Area) + " (VNĐ)";
					}
				}
			}
			
			break;
		case 2: //USD
			if(_re_Rate == 0){ _price = "Thương lượng";}
			else{
				if(_re_Unit > 1){
					if(_re_RateID == 5){
						//_price = currency1(_re_Rate * (_SJC) / _USD) *1000 + " (USD)";
						_price = currency1(_re_Rate * (_SJC) / _USD)  + " (USD)";
					}else if(_re_RateID == 2){
						_price = currency1(_re_Rate) + " (USD)";
					}
					else{
						_price = currency1(_re_Rate / _USD) + " (USD)";
					}					
				}else{
					if(_re_RateID == 5){
						_price = currency1(_re_Rate * _re_Area *  (_SJC) / _USD) + " (USD)";
					}else if(_re_RateID == 2){
						_price = currency1(_re_Rate * _re_Area) + " (USD)";
					}
					else{
						_price = currency1(_re_Rate * _re_Area/ _USD) + " (USD)";
					}
				}
			}
			break;
		case 3: //SJC10c
			if(_re_Rate == 0){ _price = "Thương lượng";}
			else{
				if(_re_Unit > 1){
					if(_re_RateID == 5){
						_price = currency1(_re_Rate) + " (SJC10c)";
										
					}else if(_re_RateID == 2){
						_price = currency1(_re_Rate * _USD / (_SJC)  ) + " (SJC10c)";
					}
					else{
						//_price = currency1(_re_Rate / (_SJC) /1000) + " (SJC10c)";
						_price = currency1(_re_Rate / (_SJC) ) + " (SJC10c)";
					}					
				} else{
					if(_re_RateID == 5){
						_price = currency1(_re_Rate) + " (SJC10c)";
					}else if(_re_RateID == 2){
						_price = currency1(_re_Rate * _re_Area * _USD / (_SJC) ) + " (SJC10c)";
					}
					else{
						_price = currency1(_re_Rate * _re_Area / (_SJC)) + " (SJC10c)";
					}
				}
			}
			break;		
		case 4:	//VND/m2
			if(_re_Rate == 0){ _price = "Thương lượng";}
			else{
				if(_re_Unit > 1){
					if(_re_Area > 0){
						if(_re_RateID == 2){
							_price = currency1(_re_Rate * _USD / _re_Area) + " (VNĐ/m<sup>2</sup>)";
						}else if(_re_RateID == 5){
							//_price = currency1(_re_Rate * (_SJC)*1000 / _re_Area)  + " (VNĐ/m<sup>2</sup>)";
							_price = currency1(_re_Rate * (_SJC) / _re_Area)  + " (VNĐ/m<sup>2</sup>)";
						}
						else{
							_price = currency1(_re_Rate / _re_Area) + " (VNĐ/m<sup>2</sup>)";
						}					
					}else{					
						if(_re_RateID == 2){
							_price = currency1(_re_Rate * _USD) + " (VNĐ)";
						}else if(_re_RateID == 5){
							_price = currency1(_re_Rate * (_SJC) ) + " (VNĐ)";
						}
						else{
							_price = currency1(_re_Rate) + " (VNĐ)";
						}
					}					
				} else {
					if(_re_Area > 0){
						if(_re_RateID == 2){
							//_price = currency1(_re_Rate * _USD * 1000) + " (VNĐ/m<sup>2</sup>)";
							_price = currency1(_re_Rate * _USD ) + " (VNĐ/m<sup>2</sup>)";
						}else if(_re_RateID == 5){
							//_price = currency1(_re_Rate * (_SJC) * 1000) + " (VNĐ/m<sup>2</sup>)";
							_price = currency1(_re_Rate * (_SJC) ) + " (VNĐ/m<sup>2</sup>)";
						}
						else{
							//_price = currency1(_re_Rate)*1000 + " (VNĐ/m<sup>2</sup>)";
							_price = currency1(_re_Rate) + " (VNĐ/m<sup>2</sup>)";
						}
					}
				}
			}
			break;
		default: break;
	}
	//alert(_re_Rate);
	document.getElementById('money_'+id).innerHTML = _price;
	
}
function currency1(v){
    v = (Math.round((v-0)*100))/100;
    v = (v == Math.floor(v)) ? v + "" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
    v = String(v);
    var ps = v.split('.');
    var whole = ps[0];
    var sub = ps[1] ? '.'+ ps[1] : '';
    var r = /(\d+)(\d{3})/;
    while (r.test(whole)) {
        whole = whole.replace(r, '$1' + ',' + '$2');
    }
    return whole +sub ;
}

function changeImg(img,desc,ck){
	if(img != ''){
		var bien = trim(document.getElementById('sieuthi_bds_ct_l_img').innerHTML);
		bien = bien.toLowerCase();
		if(ck == 1){
			if(bien.indexOf('img') > 0){
				document.getElementById('sieuthi_bds_ct_l_img').innerHTML = '<img src="http://tango.vn/upload/'+ img +'" width="400" height="300" border="0">';
				document.getElementById('imgDesc').innerHTML = '<div style="font-size:13px; font-weight:bold;">'+desc+"</div>";
			}
		}
		else{
			
			document.getElementById('sieuthi_bds_ct_l_img').innerHTML = '<img src="http://tango.vn/upload/'+ img +'" width="400" height="300" border="0">';
			document.getElementById('imgDesc').innerHTML = '<div style="font-size:13px; font-weight:bold;">'+desc+"</div>";
		}
	}
}

function eramchangeImg(img){
	if(img != ''){
		var bien = trim(document.getElementById('img_large').innerHTML);			
		document.getElementById('img_large').innerHTML = '<img src="http://tango.vn/upload/'+ img +'" width="325" height="246" border="0">';
	}
}
//================================= Front_end - Register ========================================//

function changeCustomerType(){
	var ctype = document.getElementById('slt_CusType');
	if(ctype.value == 62){
		document.getElementById('tr_other').style.display = 'block';
	}
	else{
		document.getElementById('tr_other').style.display = 'none';
	}
}
function checkRegister(){
	var uid = document.getElementById('txtUid');
	var pwd = document.getElementById('txtPwd');
	var repwd = document.getElementById('txtRePwd');
	var email = document.getElementById('txtEmail');
	var other = document.getElementById('txtOther');
	var captcha = document.getElementById('txtCaptcha');
	var hdValue = document.getElementById('hdValue');
	var hdEvalue = document.getElementById('hdEValue');
	var slt_type = document.getElementById('slt_CusType');
	var hdCaptcha = document.getElementById('hdCaptcha');

	if(uid.value == ''){
		alert('Vui lòng nhập tên đăng nhập');
		uid.focus();
		return false;
	}
	if(pwd.value == '' || repwd.value == ''){
		alert('Vui lòng nhập đầy đủ mật khẩu và xác nhận mật khẩu');
		pwd.focus();
		return false;
	}
	if(pwd.value != repwd.value){
		alert('Mật khẩu và xác nhận mật khảu không giống nhau');
		repwd.focus();
		return false;
	}
	if(email.value == ''){
		alert('Vui lòng nhập email');
		email.focus();
		return false;
	}
	if(slt_type.value == 62){
		if(other.value == ''){
			alert('Vui lòng nhập Loại khách hàng');
			other.focus();
			return false;
		}
		
	}	
	if(!isEmail(email.value)){
		alert('Địa chỉ email không hợp lệ');
		email.focus();
		return false;
	}
	if(hdValue.value == '1'){
		alert('Tên đăng nhập tồn tại, vui lòng chọn tên khác');
		uid.focus();
		return false;
	}
	if(hdEvalue.value == '1'){
		alert('Email này đã tồn tại, vui lòng chọn địa chỉ email khác');
		email.focus();
		return false;
	}
	/*alert(hdCaptcha.value);*/
	if(captcha.value == '' || (captcha.value != '' && captcha.value.toLowerCase() != hdCaptcha.value.toLowerCase())){
		alert('Mã bảo vệ không đúng');
		captcha.focus();
		return false;
		
	}
}

function isEmail(s)
{
	if(s=="") return true;
	if(s.indexOf(" ")>0) return false;	//email co khoang trang
	if(s.indexOf("@")==-1) return false;	//email khong co dau @
	if(s.indexOf(".")==-1) return false;	//email khong co dau '.'
	if(s.indexOf("..")!=-1) return false;	//email co 2 dau '..' lien tiep
	if(s.indexOf("@")!=s.lastIndexOf("@")) return false;	//email co 2 dau '@'
	if(s.lastIndexOf(".")==s.length-1) return false;	//email co dau '.' cuoi chuoi
	var str="0123456789abcdefghijklmnopqrstuvwxyz+-*&^$#`~=@._";	//email khong thuoc cac ky tu trong str
	for(var j=0;j<s.length;j++)
		if(str.indexOf(s.charAt(j))==-1) return false;
		
	return true;
}

function check_ChangePassword(){
	var oldPwd = document.getElementById('txtOldPwd');
	var newPwd = document.getElementById('txtNewsPwd');
	var renewPwd = document.getElementById('txtReNewsPwd');
	var captcha = document.getElementById('txtCaptcha');
	var hdCaptcha = document.getElementById('hdCaptcha');
	if(oldPwd.value == ''){
		alert("Bạn vui lòng nhập mật khẩu hiện tại");
		oldPwd.focus();
		return false;
	}
	if(newPwd.value == ''){
		alert("Bạn vui lòng nhập mật khẩu mới");
		newPwd.focus();
		return false;
	}
	if(renewPwd.value == ''){
		alert("Bạn vui lòng nhập mật khẩu mới");
		renewPwd.focus();
		return false;
	}
	if(newPwd.value != renewPwd.value)
	{
		alert('Mật khẩu và xác nhận mật khẩu không trùng nhau');
		renewPwd.focus();
		return false;
	}
	if(captcha.value ==''){
		alert('Vui lòng nhập mã xác nhận');
		captcha.focus();
		return false;
	}
	if(hdCaptcha.value.toLowerCase() != captcha.value.toLowerCase()){
		alert('Mã xác nhận không đúng ');
		captcha.focus();
		return false;
	}
	
}
function checkChoiceProject(page){
	if(document.getElementById('chk_prj').checked == true){
		if(document.getElementById('slt_District').value == 0){
			alert('Bạn vui lòng chọn quận huyện trước khi chọn Khu vực dự án');			
			document.getElementById('chk_prj').checked = false;
		}
		else{			
			xmlhttpPostLocation('div_project',page,document.getElementById('slt_District').value,2,150);
		}		
	}
	else{
		document.getElementById('div_project').innerHTML ='';
	}
	
}

//load khu du an theo quan huyen
function changeProjectArea(page){
	xmlhttpPostLocation('div_project',page,document.getElementById('slt_District').value,0,160,1);
}

function checkVideo(sb){
	if(sb == 1){
		return sa.addVariable('autostart', 'true') + sa.write('sieuthi_bds_ct_l_img');
	}
}
function trim(val)
{
	return val.replace(/^\s+|\s+$/g,"");
}
function checkPhone(stringIn) {
	var i;	
	if ((stringIn.length<6) || (stringIn.length>30)){
		return false;
	}
	var validWorldPhoneChars="()-+ .";
	s=stripCharsInBag(stringIn,validWorldPhoneChars);
    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 checkArea(strArea) {
	var i;
	var validWorld=".";
	s=stripCharsInBag(strArea,validWorld);
    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;
}

/********
Ham loc cac ki tu cua chuoi
input:
	s: chuoi truyen vao
	bag: cac ki tu can loc
output : chuoi da duoc loc
************/
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 isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
	{
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
   return true;
}
function OpenWindow(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();
	
}
//input : date format ex:31/12/2006
function comparedate(sbeg,send)
{
	abeg = sbeg.split("/")
	aend = send.split("/")

	dbeg = abeg[0];
	if (abeg[0].substr(0,1) == "0")
		dbeg = abeg[0].substr(1,1);
	dend = aend[0];
	if (aend[0].substr(0,1) == "0")
		dend = aend[0].substr(1,1);

	mbeg = abeg[1];
	if (abeg[1].substr(0,1) == "0")
		mbeg = abeg[1].substr(1,1);
	mend = aend[1];
	if (aend[1].substr(0,1) == "0") {mend = aend[1].substr(1,1);}
	if (parseFloat(abeg[2]) > parseFloat(aend[2]))
	{
		return false;
	}
	else
	{
		if (parseFloat(abeg[2]) == parseFloat(aend[2]))
		{
			if (parseFloat(mbeg) > parseFloat(mend))
				return false;
			else if (parseFloat(dbeg) > parseFloat(dend) & parseFloat(mbeg) >= parseFloat(mend))
				return false;
		}
	}
	return true;
}
/*=============Ham kiem tra dinh dang ngay thang dd/mm/yyyy==========*/
function isDate(dateStr) 
{
	var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) 
	{
		alert("Vui lòng nhập ngày theo đúng định dạng dd/mm/yyyy.");
		return false;
	}

	month = matchArray[3]; // p@rse date into variables
	day = matchArray[1];
	year = matchArray[5];	
	if (day < 1 || day > 31) 
	{
		alert("Ngày phải từ 1 đến 31.");
		return false;
	}
	if (month < 1 || month > 12) 
	{ // check month range
		alert("Tháng phải từ 1 đến 12.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Tháng "+month+" không có 31 ngày!")
		return false;
	}

	if (month == 2) 
	{ // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) 
		{
			alert("Tháng 2 năm " + year + " không có " + day + " ngày!");
			return false;
		}
	}
	return true; // date is valid
}
//Kiem tra gia tri trong mot mang
function in_array(strneedle, arr)
{
    var found = false, key;
    for (key in arr) 
	{
        if (arr[key] == strneedle) 
		{
            found = true;
            break;
        }
    }
    return found;
}

//chi cho phep nhap: 0123456789.
function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode > 31 && (charCode < 46 || charCode >47) && (charCode < 48 || charCode > 57))
	return false;
	
	return true;
}
//chi nhap so: 0123456789
function onlyNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	return false;
	
	return true;
}
