function delete_cat(id_cat)
{
	if(confirm("Esta seguro de eliminar esta Area de contenido ?"))	
	{
			mostrarContenido('del_cat.php?id='+id_cat,'r=1');
	}
	else
	{
		return false;
	}

}
function delete_subcat(id_subcat)
{
	if(confirm("Esta seguro de eliminar esta Sub Area de contenido ?"))	
	{
			mostrarContenido('del_subcat.php?id='+id_subcat,'r=1');
	}
	else
	{
		return false;
	}

}

function mostrarContenido(archivo,variables){

	a=new nuevoAjax();
	a.open("POST", archivo,true);
	a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	a.send(variables);
	
	a.onreadystatechange=function() 
	{
		if (a.readyState==4)
			{
				if(a.responseText == "Error al eliminar el area de contenido intentelo mas tarde.")
				{
					alert(a.responseText);
					window.location.reload();
				}
				else
				{
					window.location.reload();
				}
			}	
	}
}

function cargar_cor(pr)
{
	mostrarContenidocordenadas('carga_pr.php?id_p='+pr,'a=1','pr');
}

function mostrarContenidocordenadas(archivo,variables,contenedor){
	
	var codigo = "<div style=margin-top:25px align=center><img src='indicator.gif' /></div>";
	var cont=document.getElementById(contenedor);
	a=new nuevoAjax();
	a.open("POST", archivo,true);
	a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	a.send(variables);
	cont.innerHTML = codigo;
	a.onreadystatechange=function() {
		if (a.readyState==4) {

			cont.innerHTML =a.responseText;
			
			setTimeout(funcion,3000);
		}
	}
}

function encuesta(archivo,variables){
	
	//var codigo = "<div style=margin-top:25px align=center><img src='indicator.gif' /></div>";
	//var cont=document.getElementById(contenedor);
	a=new nuevoAjax();
	a.open("POST", archivo,true);
	a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	a.send(variables);
	//cont.innerHTML = codigo;
	a.onreadystatechange=function() {
		if (a.readyState==4) {

			alert(a.responseText);
			
			
		}
	}
}


function nuevoAjax (){
	var xmlhttp=false;
	try{
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
      try{
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }catch(E){
       xmlhttp = false;
      }
    }
    if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
       xmlhttp = new XMLHttpRequest();
    }
	return xmlhttp;
}


// Variables para setear
onload=function() 
{
	cAyuda=document.getElementById("mensajesAyuda");
	cNombre=document.getElementById("ayudaTitulo");
	cTex=document.getElementById("ayudaTexto");
	
	ayuda=new Array();
	ayuda[":: Minerales ::"]="Para seleccionar mas de un Mineral mantenga oprimida la tecla Ctrl y haga clic en los minerales que desea seleccionar.";
	ayuda[":: Municipios ::"]="Para seleccionar mas de un Municipio mantenga oprimida la tecla Ctrl y haga clic en los Municipios que desea seleccionar.";
	ayuda[":: Municipios ::"]="Para seleccionar mas de un Municipio mantenga oprimida la tecla Ctrl y haga clic en los Municipios que desea seleccionar.";
	ayuda[":: Municipios ::"]="Para seleccionar mas de un Municipio mantenga oprimida la tecla Ctrl y haga clic en los Municipios que desea seleccionar.";
	
	
	
}
// Mensajes de ayuda

if(navigator.userAgent.indexOf("MSIE")>=0) navegador=0;
else navegador=1;

function colocaAyuda(event)
{
	if(navegador==0)
	{
		var corX=window.event.clientX+document.documentElement.scrollLeft;
		var corY=window.event.clientY+document.documentElement.scrollTop;
	}
	else
	{
		var corX=event.clientX+window.scrollX;
		var corY=event.clientY+window.scrollY;
	}
	cAyuda.style.top=corY+20+"px";
	cAyuda.style.left=corX+15+"px";
}

function ocultaAyuda()
{
	cAyuda.style.display="none";
	if(navegador==0) 
	{
		document.detachEvent("onmousemove", colocaAyuda);
		document.detachEvent("onmouseout", ocultaAyuda);
	}
	else 
	{
		document.removeEventListener("mousemove", colocaAyuda, true);
		document.removeEventListener("mouseout", ocultaAyuda, true);
	}
}

function muestraAyuda(event, campo)
{
	colocaAyuda(event);
	
	if(navegador==0) 
	{ 
		document.attachEvent("onmousemove", colocaAyuda); 
		document.attachEvent("onmouseout", ocultaAyuda); 
	}
	else 
	{
		document.addEventListener("mousemove", colocaAyuda, true);
		document.addEventListener("mouseout", ocultaAyuda, true);
	}
	
	cNombre.innerHTML=campo;
	cTex.innerHTML=ayuda[campo];
	cAyuda.style.display="block";
	cAyuda.style.background = "#FFF";
}





function valida_email()
{
	if((document.getElementById('mail').value.indexOf('@')==-1)||(document.getElementById('mail').value.indexOf('.')==-1)){
			alert("- Por favor digite un E-mail valido");
			afectar('mail');
	}
}
function nuevoAjax (){
	var xmlhttp=false;
	try{
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
      try{
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }catch(E){
       xmlhttp = false;
      }
    }
    if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
       xmlhttp = new XMLHttpRequest();
    }
	return xmlhttp;
}

function env(val,bus)
{
mostrarContenido('tipo_campo.php?nombre='+val+'&bus='+bus,'resultado_c1','u=true','<div style=margin-top:25px align=center><img src=load.gif /></div>')	
}
function env1(val,bus)
{
mostrarContenido('tipo_campo.php?nombre='+val+'&bus='+bus,'resultado_c2','u=true','<div style=margin-top:25px align=center><img src=load.gif /></div>')	
}
function desabilita()
{
	if(document.getElementById("u1").value == "")
	{
			document.getElementById("b2").disabled = "disabled";
				
	}
	else
	{
		document.getElementById("b2").disabled = "";
	}
	
}

function enviar_form_sol()
{
	var b1 = document.getElementById("b1").value;
	var rb1	= document.getElementById("1b1").value;
	var u1= document.getElementById("u1").value;
	var b2= document.getElementById("b2").value;
	var rb2= document.getElementById("1b2").value;
	var condi;
	
	parent.window.cargar_iframe('expedientes/menu_solicitudes.php?p1='+b1+"&rp1="+rb1+"&u="+u1+"&p2="+b2+"&rp2="+rb2,'tab3');
	
}


function mostrarContenido1(archivo,contenedor,variables,codigo){

	var cont=document.getElementById(contenedor);
	a=new nuevoAjax();
	a.open("POST", archivo,true);
	a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	a.send(variables);
	cont.innerHTML = codigo;
	a.onreadystatechange=function() {
		if (a.readyState==4) {
			//alert(a.responseText);
			
			cont.innerHTML =a.responseText;
			
			setTimeout(funcion,3000);
	 		calendario1();
		}
	}
}
function mostrarContenido_seg(archivo,contenedor,variables){
	var codigo = "<div style=margin-top:25px align=center><img src='../img/load.gif' /></div>";
	var num = document.getElementById("n_dep").value;
	variables = "num="+num;
	a=new nuevoAjax();
	a.open("POST", archivo,true);
	a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	a.send(variables);
	contenedor.innerHTML = codigo;
	a.onreadystatechange=function() {
		if (a.readyState==4) {
			//alert(a.responseText);
			
			document.getElementById(contenedor).innerHTML =a.responseText;
			//alert(a.responseText);
		}
	}
}

function calendario1(){
	 var cal = Calendar.setup({
          onSelect: function(cal) { cal.hide() }
      });
      cal.manageFields("calendar", "fecha_rad", "%Y-%m-%d");
	  cal.manageFields("calendar1", "f_ini", "%Y-%m-%d");
	  cal.manageFields("calendar2", "f_fin", "%Y-%m-%d");

	}

function mostrarContenidosol(contenedor,codigo){

	var crit = document.getElementById("criterio").value;
	var val = document.getElementById("valor").value;
	variables = "crit="+crit+"&val="+val;
	archivo ="res_solicitud.php?"+variables;
	var cont=document.getElementById(contenedor);
	a=new nuevoAjax();
	a.open("GET", archivo,true);
	a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	a.send(variables);
	cont.innerHTML = codigo;
	a.onreadystatechange=function() {
		if (a.readyState==4) {
			cont.innerHTML = a.responseText;
			setTimeout(funcion,3000);
	 	}
	}
}


function funcion(){}

function cargar_iframe(url,tab)
{
	document.getElementById("tabsj").src = url;	
	if(tab == "tab_1")
	{
		document.getElementById(tab).className = "current";
		document.getElementById("tab_2").className = "";
	}
	if(tab == "tab_2")
	{
		document.getElementById(tab).className = "current";
		document.getElementById("tab_1").className = "";
	}
	
	
}

function cargar_iframe1(url,tab)
{
	document.getElementById("tabsj").src = url;	
	if(tab == "tab_1")
	{
		document.getElementById(tab).className = "current";
		document.getElementById("tab_2").className = "";
		document.getElementById("tab_3").className = "";
	}
	if(tab == "tab_2")
	{
		document.getElementById(tab).className = "current";
		document.getElementById("tab_1").className = "";
		document.getElementById("tab_3").className = "";
	}
	if(tab == "tab_3")
	{
		document.getElementById(tab).className = "current";
		document.getElementById("tab_1").className = "";
		document.getElementById("tab_2").className = "";
	}
	
	
}

function class_menu(tab)
{
	
	if(tab == "tab_1")
	{
		document.getElementById(tab).className = "current";
		document.getElementById("tab_2").className = "";
		document.getElementById("tab_3").className = "";

}
	if(tab == "tab_2")
	{
		document.getElementById(tab).className = "current";
		document.getElementById("tab_1").className = "";
		document.getElementById("tab_3").className = "";

	}
	if(tab == "tab_3")
	{
		document.getElementById(tab).className = "current";
		document.getElementById("tab_2").className = "";
		document.getElementById("tab_1").className = "";
	}
}



function buscarcliente(limite){
	var variables ="limite="+limite;
mostrarContidoFuncion('res_clientes.php?q=1','resultado',variables,'<div style=margin-top:25px align=center><img src="../img/load.gif" /></div>');
}

function buscarpre(limite){
	var variables ="limite="+limite;
mostrarContidoFuncion('res_clientes.php?q=1','resultado',variables,'<div style=margin-top:25px align=center><img src="../img/load.gif" /></div>');
}

function buscarnoti(limite){
	var variables ="limite="+limite;
mostrarContidoFuncion('res_noti.php?q=1','resultado',variables,'<div style=margin-top:25px align=center><img src="../img/load.gif" /></div>');
}

function buscardes(limite){
	var variables ="limite="+limite;
mostrarContidoFuncion('res_noti.php?q=1','resultado',variables,'<div style=margin-top:25px align=center><img src="../img/load.gif" /></div>');
}


function buscarprensa(limite){
	var variables ="limite="+limite;
mostrarContidoFuncion('res_noti.php?q=1','resultado',variables,'<div style=margin-top:25px align=center><img src="../img/load.gif" /></div>');
}

function buscaradmin(limite){
	var variables ="limite="+limite;
	mostrarContidoFuncion('res_admin.php?q=1','resultado',variables,'<div style=margin-top:25px align=center><img src="../img/load.gif" /></div>');
}
function buscarvideo(limite){
	var variables ="limite="+limite;
	mostrarContidoFuncion('res_admin.php?q=1','resultado',variables,'<div style=margin-top:25px align=center><img src="../img/load.gif" /></div>');
}


function buscarclientes(limite){
	var variables ="limite="+limite;
	mostrarContidoFuncion('res_cli.php?q=1','resultado',variables,'<div style=margin-top:25px align=center><img src="../img/load.gif" /></div>');
}

function buscargaleria(limite,l,t){
	var variables ="loc="+l+"&limite="+limite+"&t="+t;
	mostrarContidoFuncion('p_galeria.php','resultado',variables,'<div style=margin-top:25px align=center><img src="contenidos/img/load.gif" /></div>');
}


function buscargaleriapa(limite){
	var variables ="limite="+limite;
	mostrarContidoFuncion('menu_p_a.php','result',variables,'<div style=margin-top:25px align=center><img src="contenidos/img/load.gif" /></div>');
}

function buscargaleriapn(limite){
	var variables ="limite="+limite;
	mostrarContidoFuncion('menu_p_n.php','result',variables,'<div style=margin-top:25px align=center><img src="contenidos/img/load.gif" /></div>');
}

function buscargaleriap(limite){
	var variables ="limite="+limite;
	mostrarContidoFuncion('menu.php','result',variables,'<div style=margin-top:25px align=center><img src="contenidos/img/load.gif" /></div>');
}



function buscaruser(limite){
	var variables ="limite="+limite;
	mostrarContidoFuncion('listado_usuarios.php?q=1','resultado1',variables,'<div style=margin-top:25px align=center><img src="../img/load.gif" /></div>');
}

function buscarproy(limite){
	var variables ="limite="+limite;
	mostrarContidoFuncion('consulta_p.php?q=1','resultado1',variables,'<div style=margin-top:25px align=center><img src="../img/load.gif" /></div>');
}


function mostrarContidoFuncion(archivo,contenedor,variables,codigo){
	var cont=document.getElementById(contenedor);
	a=new nuevoAjax();
	a.open("POST", archivo,true);
	a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	a.send(variables);
	cont.innerHTML = codigo;
	a.onreadystatechange=function() {
		if (a.readyState==4) {
			cont.innerHTML = a.responseText;
			setTimeout(Acc,1000);
	 	}
	}
}

function Acc(){}

function validar_campos_cliente(){
	
var	mensaje = "Faltan los siguientes campos:  \n\n";
		

	if(document.getElementById('nombres').value == ""){
		afectar('nombres');
		mensaje=mensaje+"- Nombres de cliente \n";
	}

	if(document.getElementById('iden').value == ""){
		afectar('iden');
		mensaje=mensaje+"- Identificacion de cliente \n";
	}
	if(document.getElementById('user').value == ""){
		afectar('user');
		mensaje=mensaje+"- Nombre de usuario \n";
	}
	if(document.getElementById('pass').value == ""){
		afectar('pass');
		mensaje=mensaje+"- Contraseņa \n";
	}
	if(document.getElementById('estado').value == 0){
		afectar('estado');
		mensaje=mensaje+"- Estado \n";
	}
	if(document.getElementById('tipo').value == 0){
		afectar('tipo');
		mensaje=mensaje+"- Tipo de cliente \n";
	}
	

if (mensaje != "Faltan los siguientes campos:  \n\n")
		{
			alert(mensaje);
			return false;
		}

}

function validar_campos_admin(){
	
var	mensaje = "Faltan los siguientes campos:  \n\n";
		

	if(document.getElementById('nombres').value == ""){
		afectar('nombres');
		mensaje=mensaje+"- Nombres \n";
	}
	if(document.getElementById('apellidos').value == ""){
		afectar('apellidos');
		mensaje=mensaje+"- Apellidos\n";
	}
	if(document.getElementById('tipo').value == 0){
		afectar('tipo');
		mensaje=mensaje+"- Tipo de administrador \n";
	}
	if(document.getElementById('user').value == ""){
		afectar('user');
		mensaje=mensaje+"- Nombre de usuario \n";
	}
	if(document.getElementById('pass').value == ""){
		afectar('pass');
		mensaje=mensaje+"- Contraseņa \n";
	}
	if(document.getElementById('estado').value == 0){
		afectar('estado');
		mensaje=mensaje+"- Estado \n";
	}
	

if (mensaje != "Faltan los siguientes campos:  \n\n")
		{
			alert(mensaje);
			return false;
		}

}

function afectar(campo){
	document.getElementById(campo).style.background ='#000066';
	document.getElementById(campo).style.color = '#FFFFFF';
}





function seleccionar_cli()
{
f = document.forms[0];
sels = [];
nsels = [];
s = f["asigna[]"];
for (i = 0, s = f["asigna[]"], total = s.length; i < total; i ++)
 {
     if (s[i].checked)
	 { 
	 	sels.push(s[i].value);
		
	 }
    
 }
      
        	parametros = sels.join(",");
       
			var variables = "q=1";
			
mostrarcli("lista_cli.php?valores="+parametros,'contenedor_cli',variables);
		
	
}
function mostrarcli(archivo,contenedor,variables){
	
	
 var xajax=new nuevoAjax();
 var ruta=archivo;
 xajax.open("POST",ruta,true);
 xajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 xajax.send(variables);
 xajax.onreadystatechange=function(){

  if(xajax.readyState==4){
     funcion=xajax.responseText;
	 //alert(funcion);
     window.opener.document.getElementById(contenedor).innerHTML=funcion;
	 window.close();
  }	
 }
}


function buscar_municipio1(){
	departamento1 = document.getElementById('departamento1').value;
	sUrl = encodeURIComponent('buscar_municipio.php') + "?departamento=" + departamento1;
	var oScript = document.createElement("script");
	oScript.src = sUrl;
	document.body.appendChild(oScript);
}
function buscar_municipio2(){
	departamento2 = document.getElementById('departamento2').value;
	sUrl = encodeURIComponent('buscar_municipio2.php') + "?departamento=" + departamento2;
	var oScript = document.createElement("script");
	oScript.src = sUrl;
	document.body.appendChild(oScript);
}
function buscar_municipio3(){
	departamento3 = document.getElementById('departamento3').value;
	sUrl = encodeURIComponent('buscar_municipio3.php') + "?departamento=" + departamento3;
	var oScript = document.createElement("script");
	oScript.src = sUrl;
	document.body.appendChild(oScript);
}
function removeFullOptions(field){
	var x=document.getElementById(field);
	while(x.length>0){
  	x.remove(x.length-1);
	}
}
function insertOption(id,data,value,ciudad)
{
  var y=document.createElement('option');
  y.text=data;
  y.value=value;
  var x=document.getElementById(id);
  if(ciudad==value)
  	y.selected='selected';
  try
  {
    x.add(y,null); // standards compliant
  }catch(ex){x.add(y); // IE only
    }
}

function canon_area()
{

	if(document.getElementById("area").checked)
	{

		document.getElementById("canon").style.display = "inline";
	}
	else
	{
		document.getElementById("canon").style.display = "none";	
	}
}

function calculo_canon()
{
	th1 = document.getElementById("hec").value * 10000 / 1;
	 th2 = parseInt(th1) + parseInt(document.getElementById("mtadi").value);
	
	
	document.getElementById("tot").value = th2;
	
	var SMD = document.getElementById("SMM").value / 30;

//****************************************
var mi_numero=SMD;
mi_numero=mi_numero*100;
mi_numero=Math.floor(mi_numero);
mi_numero=mi_numero/100;

//*****************************************


	document.getElementById("SMD").value = mi_numero;
	
	var th =  th2 *1 / 10000;
	
	valor_final = 1 * mi_numero * th;
	
	gtot = formatNumber(Math.round(valor_final),'$ ');
	
	document.getElementById("anualidad").value =gtot;
	
	//var test1 = formatNumber('119938096'); // devuelve 5,123,456,789.25
//var test2 = formatNumber(119938096,'$'); // devuelve $1,234.15


}

 	function formatNumber(num,prefix)
	{
		prefix = prefix ||' ';
		num += '';
		var splitStr = num.split('.');
		var splitLeft = splitStr[0];
		var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '';
		var regx = /(\d+)(\d{3})/;
		while (regx.test(splitLeft))
		{
			splitLeft = splitLeft.replace(regx, '$1' + ',' + '$2');
		}
		return prefix + splitLeft + splitRight;
	}

function terminos_seg()
{

	if(document.getElementById("terminos").checked)
	{

		document.getElementById("content").style.display = "inline";
	}
	else
	{
		document.getElementById("content").style.display = "none";	
	}
}

function display_dep(num)
{
	if(num==0)
	{
		document.getElementById("dep1").style.display = "none";
		document.getElementById("dep2").style.display = "none";
		document.getElementById("dep3").style.display = "none";
	}
	if(num==1)
	{
		document.getElementById("dep1").style.display = "inline";
		document.getElementById("dep2").style.display = "none";
		document.getElementById("dep3").style.display = "none";
	}
	if(num==2)
	{
		document.getElementById("dep1").style.display = "none";
		document.getElementById("dep2").style.display = "inline";
		document.getElementById("dep3").style.display = "none";
	}
	if(num==3)
	{
		document.getElementById("dep1").style.display = "none";
		document.getElementById("dep2").style.display = "none";
		document.getElementById("dep3").style.display = "inline";
	}
	
}
