/***********************************************
 Author by: Nguyen Minh Trieu Linh
 website: http://phpbasic.com
 ************************************************/

function changeCat(id){
	var allf = allFields.split(',');
	for(var i = 0;i<allf.length;i++) document.getElementById(allf[i]).style.display = 'none';
	if($aCat[id][0]!=''){
		var arr = $aCat[id][0].split(',');
		for(var i = 0;i<arr.length;i++) document.getElementById(arr[i]).style.display = '';
	}
	var type = document.getElementById('typeid');
	removeChild(type);
	if($aType[id]!=''){
		//var arr = $aType[id].split(',');
		for(i in $aType[id]) addChild(type,$aType[id][i],i,i==cur_typeid?true:false);//document.getElementById(aType[id][i]).style.display = '';
	}
}

function changeCity(id){
	var dist = document.getElementById('districtid');
	removeChild(dist);
	for(i in $aDist[id]) addChild(dist,$aDist[id][i],i,i==cur_districtid?true:false);//document.getElementById(aType[id][i]).style.display = '';
}


function addChild(o,text,value,selected){
	if(!o) return false;
	var node = document.createElement('option');
	if(selected) node.selected = true;
	node.text = text;
	node.value = value;
	try {
		o.add(node, null); 
	}catch(ex) {
		o.add(node); // IE only
	}
}

function removeChild(o){
	if(!o) return false;
	if (o.length > 0){
		for(var i=o.length-1;i>=0;i--) o.remove(i);
	}
}

function ShowPrice(value,id){
	value = value.replace('.0','');
	$('#showprice'+id).html(value);
}
