
	function GetXmlHttpObject(){
		var xmlHttp=null;
		try { xmlHttp=new XMLHttpRequest(); }
		catch (e){
			try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
			catch(e){  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  }
		}
		return xmlHttp;
	}
	
	function ajax(url,vars,element){ 
		var obj = document.getElementById(element)
		var xmlHttp
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request")
	 		return
	 	} 
		xmlHttp.onreadystatechange=function (){ 
			if (xmlHttp.readyState!=4 && xmlHttp.readyState!="complete"){				
				document.body.style.cursor="wait"
				window.status ='Loading...'
			 }else{ 
				document.body.style.cursor=""
				window.status ='Done'
				if(typeof(obj.innerHTML)!="undefined") obj.innerHTML=xmlHttp.responseText 
			 }
		}
		xmlHttp.open("POST",url,true)
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
		xmlHttp.send(vars)
	}
	
	function checkLoginForm(loitendangnhap,loimatkhau){
		var tendangnhap = document.login.username.value
		var matkhau 	= document.login.password.value
		var err			= ""
		if(tendangnhap=="" || tendangnhap.length<6 || tendangnhap.indexOf(' ')==0)
		err += '* '+loitendangnhap+'\n';
		if(matkhau=="" || matkhau.length<6 || matkhau.indexOf(' ')==0)
		err += '* '+loimatkhau+'\n';
		if(err==""){
			return true
		}else{
			alert(err)
			return false
		}
	}
	
	function getAllAddition(byName,group){
		var str = ""
		var arr = document.getElementsByName(byName)
		for(var i=0;i<arr.length;i++){ 
			if(arr[i].checked==true) str += arr[i].value + "," 
		}
		str += "0"
		group.value = str
	}
	
	function showErr(id,err){
		document.getElementById(id).innerHTML = '* '+err
		document.getElementById(id).style.fontSize = '10px'
		document.getElementById(id).style.color = '#FFFFFF'
		document.getElementById(id).style.padding = '5px'
		document.getElementById(id).style.marginTop = '5px'
		document.getElementById(id).style.backgroundColor = '#FF0000'
		document.getElementById(id).style.display='block'
	}
	function hideErr(id){
		document.getElementById(id).style.display='none'
	}
	function checkMsgaddForm(loiloaitin,loitieude,loiphude,loinhomtin,loichieudai,loichieurong,loisotang,loithuoctang,loisophongngu,loisophongvesinh,loidientichsudung,loidientichtongthe,loingorong,loitinhthanh,loigia){
		
		getAllAddition('addition',document.msgadd.phude)
		
		var loaitin 			= document.msgadd.loaitin.value
		var tieude 				= document.msgadd.tieude.value
		var phude 				= document.msgadd.phude.value
		var nhomtin				= document.msgadd.nhomtinnhadat_id.value
		var chieudai	 		= document.msgadd.chieudai.value
		var chieurong	 		= document.msgadd.chieurong.value
		var sotang		 		= document.msgadd.sotang.value
		var thuoctang	 		= document.msgadd.thuoctang.value
		var sophongngu 			= document.msgadd.sophongngu.value
		var sophongvesinh		= document.msgadd.sophongvesinh.value
		var dientichsudung 		= document.msgadd.dientichsudung.value
		var dientichtongthe 	= document.msgadd.dientichtongthe.value
		var ngorong		 		= document.msgadd.ngorong.value
		var tinhthanh			= document.msgadd.tinhthanh.value
		var gia					= document.msgadd.gia.value
		var err					= ""
		if(loaitin==""){ 
			showErr('loiloaitin',loiloaitin)
			err += '- '+loiloaitin+'\n'
		}else hideErr('loiloaitin')
		if(tieude=="" || tieude==" "){
			showErr('loitieude',loitieude)
			err += '- '+loitieude+'\n'
		}else hideErr('loitieude')
		
		var arr = phude.split(",")
		//alert('count:'+arr.length)
		if(phude=="" || phude=="0" || arr.length>11){
			showErr('loiphude',loiphude)
			err += '- '+loiphude+'\n'
		}else hideErr('loiphude')
		
		if(nhomtin==""){
			showErr('loinhomtin',loinhomtin)
			err += '- '+loinhomtin+'\n'
		}else hideErr('loinhomtin')
		if(chieudai!="" && isNaN(chieudai)){
			showErr('loichieudai',loichieudai)
			err += '- '+loichieudai+'\n'
		}else hideErr('loichieudai')
		if(chieurong!="" && isNaN(chieurong)){
			showErr('loichieurong',loichieurong)
			err += '- '+loichieurong+'\n'
		}else hideErr('loichieurong')
		if(sotang!="" && isNaN(sotang)){
			showErr('loisotang',loisotang)
			err += '- '+loisotang+'\n'
		}else hideErr('loisotang')
		
		if(thuoctang!="" && isNaN(thuoctang)){
			showErr('loithuoctang',loithuoctang)
			err += '- '+loithuoctang+'\n'
		}else hideErr('loithuoctang')
		
		if(sophongngu!=""&& isNaN(sophongngu)){
			showErr('loisophongngu',loisophongngu)
			err += '- '+loisophongngu+'\n'
		}else hideErr('loisophongngu')
		if(sophongvesinh!="" && isNaN(sophongvesinh)){
			showErr('loisophongvesinh',loisophongvesinh)
			err += '- '+loisophongvesinh+'\n'
		}else hideErr('loisophongvesinh')
		if(dientichsudung=="" || dientichsudung==0 || isNaN(dientichsudung)){
			showErr('loidientichsudung',loidientichsudung)
			err += '- '+loidientichsudung+'\n'
		}else hideErr('loidientichsudung')
		if(dientichtongthe!="" && isNaN(dientichtongthe)){
			showErr('loidientichtongthe',loidientichtongthe)
			err += '- '+loidientichtongthe+'\n'
		}else hideErr('loidientichtongthe')
		
		if(ngorong!="" && isNaN(ngorong)){
			showErr('loingorong',loingorong)
			err += '- '+loingorong+'\n'
		}else hideErr('loingorong')
		
		if(tinhthanh==""){
			showErr('loitinhthanh',loitinhthanh)
			err += '- '+loitinhthanh+'\n'
		}else hideErr('loitinhthanh')
		if(gia!="" && isNaN(gia)){
			showErr('loigia',loigia)
			err += '- '+loigia+'\n'
		}else hideErr('loigia')
		
		if(err=='') return true
		else{
			alert(err)
			return false
		}
			
	}
	
	
	
	function checkServicesAddForm(loitieude,loinhomtin,loidiachi,loiemail,loitinhthanh){
		
		var tieude 				= document.servicesadd.tieude.value
		var nhomtin				= document.servicesadd.nhomtindichvu_id.value
		var diachi 				= document.servicesadd.diachi.value
		var email 				= document.servicesadd.email.value
		var tinhthanh			= document.servicesadd.tinhthanh.value
		var err					= ''
		var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
		
		
		if(tieude=="" || tieude==" "){
			showErr('loitieude',loitieude)
			err += '- '+loitieude+'\n'
		}else hideErr('loitieude')
		
		if(nhomtin==""){
			showErr('loinhomtin',loinhomtin)
			err += '- '+loinhomtin+'\n'
		}else hideErr('loinhomtin')
		
		if(diachi=="" || diachi==" "){
			showErr('loidiachi',loidiachi)
			err += '- '+loidiachi+'\n'
		}else hideErr('loidiachi')
		
		if(!reg.test(email)){
			showErr('loiemail',loiemail)
			err += '- '+loiemail+'\n'
		}else hideErr('loiemail')
		
		if(tinhthanh==""){
			showErr('loitinhthanh',loitinhthanh)
			err += '- '+loitinhthanh+'\n'
		}else hideErr('loitinhthanh')
		
		if(err=='') return true
		else{
			alert(err)
			return false
		}
			
	}
	
	function checkAll(byName,check){
		var arr = document.getElementsByName(byName)
		for(var i=0;i<arr.length;i++){
			arr[i].checked = check
		}
	}
	function getAll(form,byName,group){
		var str = ""
		var arr = document.getElementsByName(byName)
		for(var i=0;i<arr.length;i++){ 
			if(arr[i].checked==true) str += arr[i].value + "," 
		}
		str += "0"
		group.value = str
		form.submit()
	}
	
	function getAll2(byName,group,action,session,err){
		var str=""
		var arr = document.getElementsByName(byName)
		for(var i=0;i<arr.length;i++){ 
			if(arr[i].checked==true) str += arr[i].value + "," 
		}
		document.getElementById(group).value = str
		if(session!="")	document.location.href='?nhadat=msg_save&action='+action+'&group='+str
		else alert(err)
	}
	function checkCustInfoForm(loihoten,loigioitinh,loiemail){
		if(document.getElementById('gtnam').checked==true){
			document.custinfo.gioitinh.value = 1
		}
		if(document.getElementById('gtnu').checked==true){
			document.custinfo.gioitinh.value = 0
		}
		if(document.custinfo.check.checked==true){
			document.custinfo.dongy.value = 1
		}else document.custinfo.dongy.value = 0
		var hoten = document.custinfo.hoten.value
		var email = document.custinfo.email.value
		var gioitinh = document.custinfo.gioitinh.value
		var err 		= ""
	
		var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
		
		if(hoten=="" || hoten.indexOf(' ')==0 || hoten.length<6) err += '* '+loihoten+'\n'
		if(gioitinh=='')err += '* '+loigioitinh+'\n'
		
		if(!reg.test(email)) err += "* "+loiemail+"\n"
		
		if(err==""){
			return true
		}else{
			alert(err)
			return false
		}
	}
	
	function checkChangePassForm(loimatkhau,loinhaplai){
		var matkhau = document.changepass.matkhau.value
		var nhaplai = document.changepass.nhaplai.value
		var err = ""
		if(matkhau=="" || matkhau.indexOf(' ')==0 || matkhau.length<6){
			err += "* "+loimatkhau+"\n"
		}
		if(nhaplai!=matkhau) err += "* " +loinhaplai+"\n"
		if(err==""){
			return true
		}else{
			alert(err)
			return false
		}
	}
	function showOrHide(id,btn){
		if(document.getElementById(id).style.display!='none'){
			document.getElementById(id).style.display='none'
			btn.className='btn'
		}
		else{
			document.getElementById(id).style.display='block'
			btn.className='btn1'
		}
	}
	
	function checkMsgSearchForm(loisotang,loisophongngu,loisophongvesinh,loidientich,loingorong,loigia){
		var action				= document.msgsearch.action.value
		var dientich 			= document.msgsearch.dientich.value
		var dientich2 			= document.msgsearch.dientich2.value
		
		var gia					= document.msgsearch.gia.value
		var gia2				= document.msgsearch.gia2.value
		var err					= ""
		
		if(action=="advanced" || action=="save"){
			
			var sotang		 		= document.msgsearch.sotang.value
			var sotang2		 		= document.msgsearch.sotang2.value
			
			var sophongngu 			= document.msgsearch.sophongngu.value
			var sophongngu2 		= document.msgsearch.sophongngu2.value
			
			var sophongvesinh		= document.msgsearch.sophongvesinh.value
			var sophongvesinh2		= document.msgsearch.sophongvesinh2.value
			
			var ngorong				= document.msgsearch.ngorong.value
			var ngorong2			= document.msgsearch.ngorong2.value
			
			if((sotang!=""&& isNaN(sotang)) || (sotang2!=""&& isNaN(sotang2)))	err += "* "+loisotang+"\n"
							
			if((sophongngu!=""&& isNaN(sophongngu)) || (sophongngu2!=""&& isNaN(sophongngu2)))	err += "* "+loisophongngu+"\n"
				
			
			if((sophongvesinh!=""&& isNaN(sophongvesinh)) || (sophongvesinh2!=""&& isNaN(sophongvesinh2)))	err += "* "+loisophongvesinh+"\n"
			
			if((ngorong!=""&& isNaN(ngorong)) || (ngorong2!=""&& isNaN(ngorong2)))	err += "* "+loingorong+"\n"
				
			
		}

		if((dientich!=""&& isNaN(dientich)) || (dientich2!=""&& isNaN(dientich2))) err += "* "+loidientich+"\n"
		
		if((gia!=""&& isNaN(gia)) || (gia2!=""&& isNaN(gia2)))	err += "* "+loigia+"\n"
					
		if(err=="") return true
		else{
			alert(err)
			return false
		}
			
	}
	
	
	
	function disableElement(){
		var x = document.register
		for(i=0;i<x.length;i++){
			if(i!=0) x.elements[i].disabled = 'disabled'
		}
	}
	
	function enableElement(){
		var x = document.register
		for(i=0;i<x.length;i++){
			if(i!=0) x.elements[i].disabled = ""
		}
	}

	function okCheck(){
		var check = document.register.agree
		if(check.checked==true)	enableElement() 
		else disableElement()
	}
	
	function checkRegisterForm(loihoten,loigioitinh,loiemail,loitendangnhap,loimatkhau,loinhaplai,loimabaove,mbv){
		
		if(document.getElementById('gtnam').checked==true) document.register.gioitinh.value=1
		if(document.getElementById('gtnu').checked==true) document.register.gioitinh.value=0
		if(document.register.acept.checked==true) document.register.dongy.value =1
		else document.register.dongy.value =0
			
		var hoten 		= document.register.hoten.value
		var email 		= document.register.email.value
		var tendangnhap	= document.register.tendangnhap.value
		var matkhau		= document.register.matkhau.value
		var nhaplai		= document.register.nhaplai.value
		var mabaove		= document.register.mabaove.value
		var gioitinh	= document.register.gioitinh.value
		var err 		= ""
		
		var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
		
		if(hoten=="" || hoten.indexOf(' ')==0 || hoten.length<6) err += '* '+loihoten+'\n'
		
		if(document.register.gioitinh.value=='')err += '* '+loigioitinh+'\n'
		
		if(!reg.test(email)) err += "* "+loiemail+"\n"
		
		if(tendangnhap=="" || tendangnhap.indexOf(' ')==0 || tendangnhap.length<6) err += '* '+loitendangnhap+'\n'
		
		if(matkhau=="" || matkhau.indexOf(' ')==0 || matkhau.lenght<6) err += '* '+loimatkhau+'\n'
		
		if(nhaplai!=matkhau) err += '* '+loinhaplai+'\n'
		
		if(mabaove!=mbv)  err += '* '+loimabaove+'\n'
		
		if(err==''){
			return true
		}else{
			alert(err)
			return false
		}
	}

	function checkContactForm(loitieude,loiemail){
		
		var tieude 				= document.contact.tieude.value
		var email 				= document.contact.email.value
		var err					= ''
		var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
		
		if(tieude=="" || tieude==" "){
			showErr('loitieude',loitieude)
			err += '- '+loitieude+'\n'
		}else hideErr('loitieude')
		
		if(!reg.test(email)){
			showErr('loiemail',loiemail)
			err += '- '+loiemail+'\n'
		}else hideErr('loiemail')
		
		if(err=='') return true
		else{
			alert(err)
			return false
		}
	}
	
	function checkForgotpassForm(loiemail,stringcode,loimabaove){
		var email 				= document.forgotpass.email.value
		var mabaove				= document.forgotpass.mabaove.value
		var err					= ''
		var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
		
		if(!reg.test(email)){
			showErr('loiemail',loiemail)
			err += '- '+loiemail+'\n'
		}else hideErr('loiemail')
		
		if(mabaove!=stringcode){
			showErr('loimabaove',loimabaove)
			err += '- '+loimabaove+'\n'
		}else hideErr('loimabaove')
		
		if(err=='') return true
		else{
			alert(err)
			return false
		}
		
	}