function radio_check(obj,msg) //kiem tra day radio button co duoc chon hay khong
{	
	var flag=false;
	for(var i=0;i<obj.length;i++)
		{
			if(obj[i].checked==true)				
				{	flag=true;
					return true;							
				}
		}
	if (flag==false) 
		{	alert(msg);
			return false;
		}
}
function isEmail (obj)
	{ 
		var i = 1;
		var t = true;
		var sLength = obj.value.length;		
		while ((i < sLength) && (obj.value.charAt(i) != "@"))
		{ 
			i++;
		}
		if ((i >= sLength) || (obj.value.charAt(i) != "@"))
			t = false;
		else i += 2;
		while ((i < sLength) && (obj.value.charAt(i) != "."))
		{ 
			i++;
		}
		if ((!t) || (i >= sLength - 1) || (obj.value.charAt(i) != "."))
		{
		  return false; 
		} 		
}
function test_null(obj,msg)
{
	if (obj.value=="")
		{
		alert(msg);
		obj.focus();
		return false;
		}
}
function test_mail(obj,msg)
{
	if(isEmail(obj)==false)
			{
					alert(msg+"\'"+obj.value+"\'")
					obj.focus();
					return false;
			}
}
function Equal_string(obj1,obj2,msg)
{
	if(obj1.value!=obj2.value)
			{
					alert(msg);
					obj2.focus();
					return false;
			}
}

function test_number(obj,msg)
{
	if(isNaN(obj.value))
			{
					alert(msg);
					obj.focus();
					return false;
			}
}

 function check_country(countryid)
 {
 	var objbang=document.getElementById("bangtp")
	var objbang1=document.getElementById("bangtp1")
 	if (countryid!="VN") 		
		{
			objbang.style.display = 'none';
			objbang1.style.display = '';		
		}
	else
		{	
			objbang.style.display = '';
			objbang1.style.display = 'none';
		}
		
 }
function country_onchange(countryid,id,table1,table2)
 {
 	var objbang=document.getElementById(table1)
	var objbang1=document.getElementById(table2)
 	if (countryid!=id) 		
		{
			objbang.style.display = 'none';
			objbang1.style.display = '';		
		}
	else
		{	
			objbang.style.display = '';
			objbang1.style.display = 'none';
		}
		
 }

function city_null(countryid,objcity,msg1,objstate,msg2)
{
		if (countryid!="VN")
		{
				if(objstate.value=="")
					{						
						alert(msg2);
						objstate.focus();
						return false;
					}							
		}
		else
		{
				if(objcity.value=="")
					{						
						alert(msg1);
						objcity.focus();
						return false;
					}
		}
}
function swapOptions(array_id,obj)
{
	sel = obj;
	lis = eval("district" + array_id);
	val = eval("districtid" + array_id);
	for(i=sel.length-1;i>=0;i--)
		sel.options[i] = null
		sel.options[0] = new Option(lis[0],val[0],"","true")
		for(i=1;i<lis.length;i++)
			sel.options[i] = new Option(lis[i],val[i]);
			//obj.value = value;
}

function swapOptions_update(array_id,obj,districtid)
{
	
	if (array_id != "")
	{
		sel=obj
		lis=eval("district"+array_id);
		val=eval("districtid"+array_id);
		  for (i=sel.length-1; i>=0; i--)                           
			sel.options[i] = null                                 
			sel.options[0] = new Option(lis[0],val[0], "", "true")
			for (i=1; i<lis.length; i++)
			  if (districtid==0)                            
				sel.options[i] = new Option(lis[i],val[i])            
			  else{
			    sel.options[i] = new Option(lis[i],val[i]);
				if(i==districtid)
					sel.options[i].selected = true;
			  }
	}
}
function ConvertFont(str){
  if (str.length > 0){
    var sourcestr,desstr,tempstr;
	var n;
	var pos;
	pos = 0;
	nIndex = 0;
	sourcestr = str;
	desstr = '';
	do{
	 if((sourcestr.substr(pos,1)=="&")&&(sourcestr.substr(pos+1,1)=="#")){
	   nIndex = sourcestr.indexOf(";",pos);
	   tempstr = sourcestr.substr(pos+2,nIndex-(pos+2));
	   desstr = desstr + String.fromCharCode(parseInt(tempstr));
	   pos = nIndex;
	 }
	 else
	 	desstr = desstr + sourcestr.substr(pos,1);
	 	pos = pos + 1;
	}
	while (pos < sourcestr.length);
  }
  return(desstr);
}
