var hcf_regions = {};var hcf_cities = {};

/*
function cDepartments(city) {
	this.ccity = city;
	this.cityblocks = {};
	this.inited = false;


	this.init = function (cityid) {
		if (cityid) {
			this.ccity = cityid;
			this.citylnk = document.getElementById('lnk'+this.ccity);
		}
		this.inited = true;
	}


	this.showCity = function(cityid,mode) {
		var el = document.getElementById('cityblock'+cityid);
		if (el) {
			el.style.display = mode ? 'block' : 'none';
		}
	}

	this.selectCity = function (cityid,lnk) {
		if (this.inited) {
			if (cityid.value) {
				cityid = cityid.value;
			}


			if (this.ccity) {
				this.showCity(this.ccity,false);
				this.citylnk.className = '';
			}
			this.ccity = cityid;
			this.citylnk = lnk;
			this.citylnk.className = 'selected';
			this.showCity(cityid,true);

		}

	}
}
*/
function removeNode(node){
	//var d = document.getElementById('ccity');
	var olddiv = document.getElementById(node);
	olddiv.parentNode.removeChild(olddiv);	
}

function showOne(item){
	document.getElementByID(item).style.display.inline; 
}

function cDepartments (id) {
	this.root = document.getElementById(id);
	this.city = [];	this.net = [];
	this.cities = 0;this.nets = 0;
	this.current_city = -1;this.current_net = 0;
	this.citysel = document.getElementById('ccity');

	this.init = function(cityid) {
		var i,j,k;
		var ct = /city_(\d+)/;
		var nt = /netw_(\d+)/;
		var rez;
		if (this.root) {
			var elements = this.root.getElementsByTagName('div');
			if (elements) {
				j = 0;k = 0;
				for (i in elements) {
					if (elements[i].className != undefined) {
						if (rez = elements[i].className.match(ct)) {
							//console.log('city_ found');
							this.city[rez[1]] = elements[i];
							//if (rez[1] == cityid) this.current_city = k;
 							//this.city[j] = elements[i];
							k++;
						} else if (rez = elements[i].className.match(nt)) {
							if (this.net[rez[1]] == undefined) {
								this.net[rez[1]] = [];
							}
							this.net[rez[1]][j] = elements[i];
							j++;
						}
					}
				}
				this.cities = k;
				this.nets = j;
			}
		}
		if (cityid) {
			this.citylnk = document.getElementById('lnk'+cityid);
			this.setCity(cityid,this.citylnk);

		}
	}

	this.setCity = function (cIndex,lnk) {
		var link;
		var link,i,net;
		if (cIndex == 0) {
			this.showAllCity();
			this.showAllNet();
			this.current_city = 0;
			this.showAllSelvac();
		} else {
			if (this.current_city == 0) {
				//console.log(this.current_city);
				this.hideAllCity();
			} else {
				if (this.city[this.current_city]) {
					//console.log(this.city[this.current_city]);
					this.city[this.current_city].style.display = 'none';
					if (this.citylnk) {
						this.citylnk.className = '';
					}
					document.getElementById('selvac' + this.current_city).style.display = 'none';
				}

			}
			if (this.city[cIndex]) {
				//alert('inline');
				this.city[cIndex].style.display = 'inline';
				this.current_city = cIndex;
				if (this.citysel.value != cIndex) {
					for (var i = 0; i< this.citysel.options.length;i++) {
						if (this.citysel.options[i].value == cIndex) {
							this.citysel.selectedIndex = i;
							break;
						}

					}
				}
				var curcity = document.getElementById('selvac' + cIndex);
				curcity.style.display = 'inline';
				//alert('displaying selvac element');
				if (lnk) {
					this.citylnk = lnk;
				} else {
					this.citylnk = this.citylnk = document.getElementById('lnk'+cIndex);
				}

				if (this.citylnk) this.citylnk.className = 'selected';
				this.showAllNet();
			}
		}
	}
	this.setNet = function (cIndex) {
		var link,i,net;
		if (cIndex == 0) {
			this.showAllNet();
			this.current_net = 0;
		} else {
			if (this.current_net == 0) {
				this.hideAllNet();
			} else {
				if (this.net[this.current_net]) {
					net = this.net[this.current_net];
					for (var i in net) net[i].style.display = 'none';
				}
			}
			if (this.net[cIndex]) {
				net = this.net[cIndex];
				for (var i in net) net[i].style.display = 'inline';
				this.current_net = cIndex;
			}
		}
	}
	this.showAllNet = function () {
		var net;
		for(var i in this.net) {
			net = this.net[i];
			//console.log(net);
			for (var k in net) net[k].style.display = 'inline';
		}
	}
	this.hideAllNet = function () {
		var net;
		for(var i in this.net) {
			net = this.net[i];
			for (var k in net) net[k].style.display = 'none';
		}
	}
	this.showAllCity = function () {
		var city;
		for(var i in this.city) {
			this.city[i].style.display = 'inline';
		}
	}

	this.hideAllCity = function () {
		var city;
		for(var i in this.city) {
			this.city[i].style.display = 'none';
		}
	}
	
	this.hideAllsetOne = function (network){
		this.hideAllNet();
		//alert(network);
		var t = document.getElementById(network);
		//alert(t);
		t.style.display = 'inline';
	}
	this.showAllSelvac = function (){
		var vac = /selvac(\d+)/;
		for (var i in vac) {
			//console.log('displaying selvac element: ');
			//console.log(vac);
			document.getElementById(vac[i]).style.display = 'inline';
		}
	}

}
