/***********************************************
 Author by: Nguyen Minh Trieu Linh
 website: http://phpbasic.com
 ************************************************/

var cur_cityid = ''
var cur_districtid = ''

function changeCity(id,cur_districtid){
	var dist = document.getElementById('districtid');
	removeChild(dist);
	for(var icaredist = 0;  icaredist<$aDist[id].length; icaredist++) if(typeof $aDist[id][icaredist] != 'undefined') addChild(dist,$aDist[id][icaredist],icaredist,icaredist==cur_districtid?true:false);//document.getElementById(aType[id][i]).style.display = '';
}

function changeCategory(id,cur_districtid){
	var dist = document.getElementById('subcatid');
	removeChild(dist);
	for(var icaredist = 0;  icaredist<$aSubCat[id].length; icaredist++) if(typeof $aSubCat[id][icaredist] != 'undefined') addChild(dist,$aSubCat[id][icaredist],icaredist,icaredist==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);
	}
}

// Post Vote
function post_voted(id,vote,htmlid){
	$.post('app/vote.php', { "id": id, "vote": vote }, function(data) { 
			 $('#'+htmlid).css({width: parseInt(vote)*20});												
		});

}
function question_voted(id,vote,htmlid){
	$.post('app/vote.php?type=2', { "id": id, "vote": vote }, function(data) { 
			 $('#'+htmlid).css({width: parseInt(vote)*20});												
		});

}


///////Email
function isEmail(s)
{if(s=="") return false;
if(s.indexOf(" ")>0) return false;
if(s.indexOf("@")==-1)return false;
var i=1; var sLength=s.length;
if(s.indexOf(".")==-1) return false;
if(s.indexOf("..")!=-1)return false;
if(s.indexOf("@")!=s.lastIndexOf("@")) return false;
if(s.lastIndexOf(".")==s.length-1)return false;
var str="abcdefghikjlmnopqrstuvwxyz-@._0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(var j=0;j<s.length;j++)
if(str.indexOf(s.charAt(j))==-1)
return false;return true;
}