var cuantos = [0,0,0,0,0,0];

function validLog(){
	if(document.getElementById('usuario').value==''){
		alert("Insgrese su nombre de usuario");
		document.getElementById('usuario').focus();
		return false;
	}
	if(document.getElementById('password').value==''){
		alert("Insgrese su clave");
		document.getElementById('password').focus();
		return false;
	}

	return true;
}

function recordar(){
	if(document.getElementById('email').value==''){
		alert("Insgrese su email");
		document.getElementById('email').focus();
		return false;
	}

	return true;

}

function verNivel(string,div){ //le envias el nombre del select y el div donde va el otro

	//alert(string);
	var nivel = document.getElementById(string).options[document.getElementById(string).selectedIndex].value;
	
	$j.ajax({ type: "GET", url: "js/niveles.php", data: "nivel="+nivel+"&nombre=area&style=width:150px;margin-left:10px;",
		success: function(msg){
			document.getElementById(div).innerHTML=msg;
		}
	});
}

function verOficina(select){ //le envias el nombre del select y el div donde va el otro

	//alert(string);
	var edificio = select.options[select.selectedIndex].value;
	
	$j.ajax({ type: "GET", url: "js/oficinas.php", data: "edificio="+edificio,
		success: function(msg){
			document.getElementById('verOficinasEdificio').innerHTML=msg;
		}
	});
}

function verSubtiposReclamo(select){ //le envias el nombre del select y el div donde va el otro

	//alert(string);
	var reclamo = select.options[select.selectedIndex].value;
	
	$j.ajax({ type: "GET", url: "js/reclamo.php", data: "reclamo="+reclamo+"&verSubtipo=si",
		success: function(msg){
			document.getElementById('verSubtipos').innerHTML=msg;
		}
	});
}

function verSubtiposReclamo3(select){ //le envias el nombre del select y el div donde va el otro

	//alert(string);
	var reclamo = select.options[select.selectedIndex].value;
	
	$j.ajax({ type: "GET", url: "js/reclamo.php", data: "reclamo="+reclamo+"&verSubtipo=si",
		success: function(msg){
			document.getElementById('verSubtipos2').innerHTML=msg;
		}
	});
}

function verSubtiposReclamo2(select){ //le envias el nombre del select y el div donde va el otro

	//alert(string);
	var reclamo = select.options[select.selectedIndex].value;
	
	$j.ajax({ type: "GET", url: "js/reclamo.php", data: "reclamo="+reclamo+"&asociar=si",
		success: function(msg){
			document.getElementById('verSubtipos').innerHTML=msg;
		}
	});
}


function verNivelSuperior(string,div){ //le envias el nombre del select y el div donde va el otro

	//alert(string);
	
	var nivel = document.getElementById(string).options[document.getElementById(string).selectedIndex].value-1;
	if (nivel>-1){
		//document.getElementById(string).style.display='block';
		$j.ajax({ type: "GET", url: "js/niveles.php", data: "nivel="+nivel+"&nombre=areaSuperior",
			success: function(msg){
				document.getElementById(div).innerHTML=msg;
			}
		});
	}
	else {
		document.getElementById(div).innerHTML = "";
	}
}


function verAsociado(){

		var tipo = document.getElementById('tipoReclamo').options[document.getElementById('tipoReclamo').selectedIndex].value;
		var subtipo = document.getElementById('subtipoReclamo').options[document.getElementById('subtipoReclamo').selectedIndex].value;
		var idxReclamo = document.getElementById('idxReclamo').value;

		//alert(subtipo);
		
		$j.ajax({ type: "GET", url: "js/reclamo.php", data: "tipo="+tipo+"&subtipo="+subtipo+"&idxReclamo="+idxReclamo+"&selectAsociar=si",
			success: function(msg){
				document.getElementById('verAsociado').innerHTML=msg;
			}
		});
}

function cambiarDescripcion(select){
	
		var idxReclamo = select.options[select.selectedIndex].value;
			
		$j.ajax({ type: "GET", url: "js/reclamo.php", data: "idxReclamo="+idxReclamo+"&descripcion=si",
			success: function(msg){
				
				document.getElementById('verDescripcionReclamo').innerHTML=msg;
			}
		});


}

function eliminarTipo(idTipo){
	$j.ajax({ type: "GET", url: "js/tipoReclamo.php", data: "idxTipo="+idTipo,
			success: function(msg){
				if (msg == 'ok'){ //Se puede eliminar a el y a sus subtipos
					//alert(msg)
					if(confirm('\xbfEst\xe1 seguro que desea eliminar el Tipo de Reclamo?')){
					window.location = 'index.php?p=baja-tipo&idxTipo='+idTipo+'&accion=delTipo';
					}
				}
				if (msg == 'padre') { // tiene subtipos con reclamos
					alert('Tiene subtipos asociados con Reclamos')
					//alert(msg)
				}
				if (msg == 'reclamos') { //tiene reclamos asociados
					alert('Tiene Reclamos asociados con Reclamos')
					//alert(msg)
				}
			}
	});
}

function agregarItem(tipo){ // 1 Area , 2 Empresa
	if (tipo == 1){
		var divPcipal = document.getElementById("areaOperativa");
		var name='area_'+area;
		area++;
	}
	else {
		var divPcipal = document.getElementById("areaEmpresa");
		var name='empresa_'+empresa;
		empresa++;
	}
	$j.ajax({ type: "GET", url: "js/actividades.php", data: "tipo="+tipo+"&name="+name,
		success: function(msg){
			var divSecundario = document.createElement("div");
				divSecundario.setAttribute("id", name);
				divSecundario.innerHTML = msg;
				divPcipal.appendChild(divSecundario);	
		}
	});
}

function eliminarItem(tipo,nombre){
	if (tipo == 1)
		var divPcipal = document.getElementById("areaOperativa");
	else var divPcipal = document.getElementById("areaEmpresa");
	
	divPcipal.removeChild(document.getElementById(nombre));
}

function borrarEdificioActividad(div){
		var pcipal = document.getElementById('areaEdificio')
		pcipal.removeChild(document.getElementById("edificioDiv"+div));
}
	
function masEdificiosActividad(){
	var cuantos=document.getElementById('cuantosEdificios').value;
	$j.ajax({ type: "GET", url: "js/edificios.php", data: "masEdificios=si&cuantos="+cuantos,
		success: function(msg){
		var 
			div = document.getElementById('areaEdificio')
			divEdificio = document.createElement('div');
			divEdificio.setAttribute('id',"edificioDiv"+cuantos);
			divEdificio.className = "campo";
			divEdificio.innerHTML=msg;
			div.appendChild(divEdificio);
			document.getElementById('cuantosEdificios').value++;
		}
	});
}

function verOficinas(select,cuantos){
	var edificio=select.options[select.selectedIndex].value;
	
	
	$j.ajax({ type: "GET", url: "js/edificios.php", data: "masOficinas=si&cuantos="+cuantos+"&idxEdificio="+edificio,
		success: function(msg){
		document.getElementById('masOficinas'+cuantos).innerHTML=msg;
		}
	});
}

