//Se encarga de controlar el cambio de Pais -> Departamento -> Provincia -> Distrito
//Autor : Manuel Chavez Castro - manuel_chc@hotmail.com
// ******************* Defino variables globales
var cats = new Array();
var catsIndex = -1;
var itemsIndex = -1;
var subitemsIndex = -1;

// ******************** Primer Nivel *************************
// Defino un objeto o estructura de objeto (CAT) de nombre igual a "name" e longuitud igual a "0"
function makeCat(name)
{	this.name = name;
	this.length = 0;
}

// Creo el objeto (CAT) e inicializo a -1 la variable "itemsIndex" e sumo catsIndex++ de uno en uno
function newCat(name)
{	catsIndex++;
	itemsIndex = -1;
	cats[catsIndex] = new makeCat(name);
}
	
// ******************** Segundo Nivel *************************
// Defino un objeto o estructura de objeto (ITEM) con dos propiedades
function makeItem(name)
{	this.name = name;
	this.length = 0;
}

// Creo el objeto (ITEM) e inicializo a -1 la variable "itemsIndex"
function newItem(name)
{	itemsIndex++;
	subitemsIndex = -1;
	cats[catsIndex][itemsIndex] = new makeItem(name);
	cats[catsIndex].length++;
}

// ******************** Tercer Nivel *************************
// Defino un objeto o estructura de objeto (SUBITEM) con dos propiedades
function makeSubItem(name, value)
{	this.name = name;
	this.value = value;
}

// Creo el objeto (SUBITEM)
function newSubItem(name, value)
{	subitemsIndex++;
	cats[catsIndex][itemsIndex][subitemsIndex] = new makeSubItem(name, value);
	cats[catsIndex][itemsIndex].length++;
}

//~ modificado: 04:28 p.m. 14/08/2007
// Funcion que me muestra las provincias del departamento seleccionado
function relateItems(cat) {
	if (cat > 0) {
		// Si la longuitud del array cat es mayor a cero
		catsIndex = cat - 1;
		frmDatos.cod_ubigeo.value = cats[catsIndex][0][0].value;
	}
	//~ itemsIndex = 0;
}

//~ modificado: 04:28 p.m. 14/08/2007
function relateSubItems(item)
{	// Si el navegador es Netscape y version 3 o superior
	if (item > 0)
	{	// Si la longuitud del array cat es mayor a cero
		itemsIndex = item - 1;
		with (frmDatos.cod_ubigeo)
		{	// Trabajar con el objeto "cod_ubigeo" del documento "m"
			for (var i = options.length; i > 1; i--)
			{	// Empezar desde el final (de sus opciones) e ir anulandolas
				options[i] = null;
			}
			for (var i = 0; i < cats[catsIndex][itemsIndex].length; i++)
			{	// Desde el inicio hasta la longuitud de la variable array (cogo el indice correspondiente seleccionado)
				// agrego su contenido
				//options[i + 1] = new Option(cats[catsIndex][itemsIndex][i].name);
				options[i + 1] = new Option(cats[catsIndex][itemsIndex][i].name,cats[catsIndex][itemsIndex][i].value); 
			}
			//~ options[0].selected = true; // Selecciono la primera opcion
			options[1].selected = true; // Selecciono la primera opcion
		}
	}
	itemsIndex = 0;
}
	
newCat('LA PAZ');
	newItem('LA PAZ');
		newSubItem('LA PAZ', '010101');
newCat('SANTA CRUZ');
	newItem('SANTA CRUZ');
		newSubItem('SANTA CRUZ', '020101');
newCat('COCHABAMBA');
	newItem('COCHABAMBA');
		newSubItem('COCHABAMBA', '030101');
newCat('SUCRE');
	newItem('SUCRE');
		newSubItem('SUCRE', '040101');
newCat('TARIJA');
	newItem('TARIJA');
		newSubItem('TARIJA', '050101');
newCat('PANDO');
	newItem('PANDO');
		newSubItem('PANDO', '060101');
newCat('ORURO');
	newItem('ORURO');
		newSubItem('ORURO', '070101');
newCat('POTOSI');
	newItem('POTOSI');
		newSubItem('POTOSI', '080101');
newCat('BENI');
	newItem('BENI');
		newSubItem('BENI', '090101');
newCat('CHUQUISACA');
	newItem('CHUQUISACA');
		newSubItem('CHUQUISACA', '100101');
