var expandir, contraer
expandir = -1
contraer = -1
var aBorrar = new Array()

function Descolgar(tabla, nro, tabla2, param){
	var encontrado 
	var i
	encontrado = 0
  	for(i=0; i < aBorrar.length; i++){			
			if (aBorrar[i] == param){				
				expandir = 1
				encontrado = 1
				aBorrar[i] = aBorrar[aBorrar.length];
				i = aBorrar.length;
			}
 	}
 	i = aBorrar.length
	if (encontrado == 0){
		aBorrar[i] = param
		expandir = -1
	}
	if (expandir == -1){
		eval("window.document.getElementById(\"" + tabla + "\").style.display =''")
		expandir = nro	
	}else{
		if (tabla2 != ""){
			eval("window.document.getElementById(\"" + tabla2 + "\").style.display ='none'")
			eval("window.document.getElementById(\"" + tabla + "\").style.display ='none'")		
			expandir = -1
		}
		eval("window.document.getElementById(\"" + tabla + "\").style.display ='none'")
		expandir = -1
	}
}

function llamo(dequien){
		//alert (dequien);
		
	if (dequien == "inv"){
		//document.forms.busqueda.target = "mainFrame";
		document.forms.busqueda.action = "#";
		document.forms.busqueda.submit();
	}
	if (dequien == "goo"){
		//action="http://www.google.com/search" target="_blank"
		document.forms.busqueda.target = "_blank";
		document.forms.busqueda.action = "http://www.google.com/search";
		document.forms.busqueda.submit();		
	}	
}

function muestro_info(dequien){
		//alert (dequien);
	if (dequien == 1){
		var dir = window.document.getElementById("dir_info1").value;
    	//alert (dir);		
	}
	if (dequien == 2){
		var dir = window.document.getElementById("dir_info2").value;
    	//alert (dir);		
	}	
		document.forms.form_inform.target = "_blank";
		document.forms.form_inform.action = dir;
		document.forms.form_inform.submit();	
}

function muestro_tramite(dequien){
		//alert (dequien);
	/*if (dequien == 1){
		var dir = window.document.getElementById("dir_info1").value;
    	//alert (dir);			}
	if (dequien == 2){
		var dir = window.document.getElementById("dir_info2").value;
    	//alert (dir);		
	}	*/
    var link="guia_tramites.php";
		document.forms.form_tramite.target = "_self";
		document.forms.form_tramite.action = link;
		document.forms.form_tramite.submit();	
}

function validarEntero(valor){ 
		if (valor == ""){
			   return valor 
		} 
		//Compruebo si es un valor numérico 
		if (valor != ""){
		    valor = parseInt(valor) //intento convertir a entero. si era un entero no le afecta, si no lo era lo intenta convertir 
			if (isNaN(valor)) { 
			   //entonces (no es numero) devuelvo el valor cadena vacia 
			   return false; 
			}else{ 
			   //En caso contrario (Si era un número) devuelvo el valor 
			   return valor 
			} 
		}
	
} 

function datos_validos(){
	var valida=0;
    if (document.resoluciones.nro_resol_buscar.value!=""){
	    if (!validarEntero(document.resoluciones.nro_resol_buscar.value)){
				alert("Por favor ingrese un numero entero.");
				document.resoluciones.nro_resol_buscar.focus();
	            document.resoluciones.nro_resol_buscar.select();
	  			valida=1;
		}
    }
    if (document.resoluciones.anio_resol_buscar.value!=""){
	    if (!validarEntero(document.resoluciones.anio_resol_buscar.value)){
				alert("Por favor ingrese un numero entero.");
				document.resoluciones.anio_resol_buscar.focus();
	            document.resoluciones.anio_resol_buscar.select();
	  			valida=1;
		}
    }    
	return valida;
}

function saludo(){
	 alert("holaaaaa");
}

///////////////FUNCIONES PARA PROVINCIA Y DEPARTAMENTO

//funcion que viene del select provincia
function seleccion_provincia(quien){
	// alert("selecciono provincia");
	//alert (quien);
	if (quien=='industria'){
		var i = document.getElementById('sel_provincia_cons').selectedIndex;
		var valor = document.getElementById('sel_provincia_cons').options[i].value;
	}
	if (quien=='defensa'){
		var i = document.getElementById('sel_provincia_cons_def').selectedIndex;
		var valor = document.getElementById('sel_provincia_cons_def').options[i].value;
	}	
	if (quien=='impresores'){
		var i = document.getElementById('sel_provincia_cons_imp').selectedIndex;
		var valor = document.getElementById('sel_provincia_cons_imp').options[i].value;
	}	
	//alert (valor);
	sndPro(valor,quien);
}

//funcion que selecciona el departamento
function sndPro(provincia,quien){
	//alert (provincia+" "+quien);
	if (quien=='industria'){
		var thetd = document.getElementById('departamento_comb'); // the td de departamento
		var thetd_d = document.getElementById('localidad_comb'); // the td de localidad
		var proid = parseInt(provincia);
	}
	if (quien=='defensa'){
		var thetd = document.getElementById('departamento_comb_def'); // the td de departamento
		var thetd_d = document.getElementById('localidad_comb_def'); // the td de localidad
		var proid = parseInt(provincia);
	}	
	if (quien=='impresores'){
		var thetd = document.getElementById('departamento_comb_imp'); // the td de departamento
		var thetd_d = document.getElementById('localidad_comb_imp'); // the td de localidad
		var proid = parseInt(provincia);
	}	
	
	if(provincia == 0)
	{
		thetd.innerHTML = '';
		thetd_d.innerHTML = '';
		return false;
	}	
	thetd.innerHTML = '<div class="loading"><strong>Cargando...</strong></div>'; //departamento
	thetd_d.innerHTML = '<div class="loading"><strong>Cargando...</strong></div>'; //localidad
	//alert('ajax.php?p='+proid,'provincia');
	makeRequest('ajax.php?p='+proid+'&quien='+quien,'provincia',quien);
}

//funcion que viene del select departamento
function seleccion_departamento(quien){		
	//alert ("quien en dpto: "+quien);
	if (quien=='industria'){	
		var ip = document.getElementById('sel_provincia_cons').selectedIndex;
		var valorp = document.getElementById('sel_provincia_cons').options[ip].value;
		var i = document.getElementById('sel_departamento_cons').selectedIndex;
		var valor = document.getElementById('sel_departamento_cons').options[i].value;
	}	
	
	if (quien=='defensa'){	
		var ip = document.getElementById('sel_provincia_cons_def').selectedIndex;
		var valorp = document.getElementById('sel_provincia_cons_def').options[ip].value;
		var i = document.getElementById('sel_departamento_cons_def').selectedIndex;
		var valor = document.getElementById('sel_departamento_cons_def').options[i].value;
	}	
	
	if (quien=='impresores'){	
		var ip = document.getElementById('sel_provincia_cons_imp').selectedIndex;
		var valorp = document.getElementById('sel_provincia_cons_imp').options[ip].value;
		var i = document.getElementById('sel_departamento_cons_imp').selectedIndex;
		var valor = document.getElementById('sel_departamento_cons_imp').options[i].value;
	}
		
	sndDpto(valor,valorp,quien); 
}

//funcion que selecciona las localidades
function sndDpto(departamento, provincia,quien){
	//alert (departamento+" "+provincia);
	if (quien=='industria'){	
		var thetd = document.getElementById('localidad_comb'); // the td de cantones
		var proid = parseInt(provincia);
		var dptoid = parseInt(departamento);
	}	
	if (quien=='defensa'){	
		var thetd = document.getElementById('localidad_comb_def'); // the td de cantones
		var proid = parseInt(provincia);
		var dptoid = parseInt(departamento);
	}
	if (quien=='impresores'){	
		var thetd = document.getElementById('localidad_comb_imp'); // the td de cantones
		var proid = parseInt(provincia);
		var dptoid = parseInt(departamento);
	}	
	
	if(departamento == 0){
		thetd.innerHTML = '';
		return false;
	}
	thetd.innerHTML = '<div class="loading"><strong>Cargando...</strong></div>';
	makeRequest('ajax.php?p='+proid+'&d='+dptoid+'&quien='+quien,'departamento',quien);
}

var http_request = false;	//provincias
var http_request_d = false; //departamento 

//funcion que selecciona el tipo de navegador
function makeRequest(url,seleccion,quien){
	//alert ("estoy en el make: "+url+ "quien: "+quien);
	if(seleccion=='provincia'){
		http_request = false;
    	if (window.XMLHttpRequest){ // Mozilla, Safari,...
	    	http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType){
	            http_request.overrideMimeType('text/html');
	         }
		}
		else if (window.ActiveXObject){ // IE
			try{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");				
			}
			catch (e){
	        	try{
	               http_request = new ActiveXObject("Microsoft.XMLHTTP");
	            }
	            catch (e) {}
			}
      	}
		if (!http_request){
	    	alert('No se pudo crear la instancia XMLHTTP');
	        return false;
		}else{			//alert ("todo bien el request: "+http_request);
		}	
			
		if (quien=='industria'){	
			http_request.onreadystatechange = alertContents_ind;
		}	
		if (quien=='defensa'){	
			http_request.onreadystatechange = alertContents_def;
		}	
		if (quien=='impresores'){	
			http_request.onreadystatechange = alertContents_imp;
		}			
		
	    http_request.open('GET', url, true);
	    http_request.send(null);
    }
    else{
    	http_request_d = false;
    	if (window.XMLHttpRequest){ // Mozilla, Safari,...    	
	    	http_request_d = new XMLHttpRequest();
			if (http_request_d.overrideMimeType){
	            http_request_d.overrideMimeType('text/html');
	         }
		}
		else if (window.ActiveXObject){ // IE
			try{
				http_request_d = new ActiveXObject("Msxml2.XMLHTTP");				
			}
			catch (e){
	        	try{
	               http_request_d = new ActiveXObject("Microsoft.XMLHTTP");
	            }
	            catch (e) {}
			}
      	}      	
		if (!http_request_d){
	    	alert('No se pudo crear la instancia XMLHTTP');
	        return false;
		}else{			//alert ("todo bien el request: "+http_request_d);
		}		
		
		if (quien=='industria'){	
			http_request_d.onreadystatechange = alertContents_d_ind;
		}	
		if (quien=='defensa'){	
			http_request_d.onreadystatechange = alertContents_d_def;
		}	
		if (quien=='impresores'){	
			http_request_d.onreadystatechange = alertContents_d_imp;
		}			
		
		http_request_d.open('GET', url, true);
	    http_request_d.send(null);
    }      
}

//funcion que llena el select de departamento
function changeTextPro( div2show, text,quien){
	//alert(quien);
    // Detect Browser
	id = parseInt(div2show);
    var IE = (document.all) ? 1 : 0;
    var DOM = 0;
    if (parseInt(navigator.appVersion) >=5) {DOM=1};
    // Grab the content from the requested "div" and show it in the "container"
	if (quien=='industria'){    
	    if (DOM){
	        //var viewer = document.getElementById('sel_departamento_cons');       //innerHTML sirve para "escribir" dentro de un elemento HTML
	        document.getElementById('departamento_comb').innerHTML = text;        //viewer.innerHTML = text;        
	    }
	    else if(IE){
		        document.all['departamento_comb'].innerHTML = text;
	    }
	}	  
	if (quien=='defensa'){    
	    if (DOM){
	        //var viewer = document.getElementById('sel_departamento_cons');       //innerHTML sirve para "escribir" dentro de un elemento HTML
	        document.getElementById('departamento_comb_def').innerHTML = text;        //viewer.innerHTML = text;        
	    }
	    else if(IE){
		        document.all['departamento_comb_def'].innerHTML = text;
	    }
	}	

	if (quien=='impresores'){    
	    if (DOM){
	        //var viewer = document.getElementById('sel_departamento_cons');       //innerHTML sirve para "escribir" dentro de un elemento HTML
	        document.getElementById('departamento_comb_imp').innerHTML = text;        //viewer.innerHTML = text;        
	    }
	    else if(IE){
		        document.all['departamento_comb_imp'].innerHTML = text;
	    }
	}	
}  

//funcion que llena las localidades
function changeTextDpto( div2show, text, quien){
	//alert("entro al dpto "+text);
    // Detect Browser
	id = parseInt(div2show);
    var IE = (document.all) ? 1 : 0;
    var DOM = 0;
    if (parseInt(navigator.appVersion) >=5) {DOM=1};
	if (quien=='industria'){
	    if (DOM){
	        //var viewer = document.getElementById('sel_localidad_cons');      // viewer.innerHTML = text;
	       document.getElementById('localidad_comb').innerHTML = text;
	    }
	    else if(IE){
			document.all['localidad_comb'].innerHTML = text;
	    }
	}  
	if (quien=='defensa'){
	    if (DOM){
	        //var viewer = document.getElementById('sel_localidad_cons');      // viewer.innerHTML = text;
	       document.getElementById('localidad_comb_def').innerHTML = text;
	    }
	    else if(IE){
			document.all['localidad_comb_def'].innerHTML = text;
	    }
	}  	 

	if (quien=='impresores'){
	    if (DOM){
	        //var viewer = document.getElementById('sel_localidad_cons');      // viewer.innerHTML = text;
	       document.getElementById('localidad_comb_imp').innerHTML = text;
	    }
	    else if(IE){
			document.all['localidad_comb_imp'].innerHTML = text;
	    }
	} 	
}

function valor_departamento(){
	var i = document.all.sel_departamento_cons.selectedIndex;
	var id_departamento = document.all.sel_departamento_cons.options[i].value;
}  

//funcion que llena el select de departamento
function alertContents_ind(){	
	//alert (http_request.readyState);	//alert('dentro del alertContents.');	
	if (http_request.readyState == 4){		
    	if (http_request.status == 200){
			//alert (http_request.status);			//alert (http_request.responseText);
    		result = http_request.responseText;
			var update = new Array();
			if(result.indexOf('|') != -1){
				update = result.split('|');
				changeTextPro(update[0], update[1],'industria');
			}        //  alert('NO Hubo un problema en ejecutar la peticion.');
         } else{ 
            alert('Hubo un problema en ejecutar la peticion.');
        }
	}
}

//funcion que llena las localidades
function alertContents_d_ind(){
	//alert (http_request.readyState);	//alert('dentro del alertContents_d.');
	if (http_request_d.readyState == 4){
    	if (http_request_d.status == 200){
            result = http_request_d.responseText;
			var update = new Array();
			if(result.indexOf('|') != -1){
				update = result.split('|');
				changeTextDpto(update[0], update[1],'industria');
			}
         } else{
            alert('Hubo un problema en ejecutar la peticion.');
         }
	}
}

//funcion que llena el select de departamento
function alertContents_def(){	
	//alert (http_request.readyState);	//alert('dentro del alertContents.');	
	if (http_request.readyState == 4){		
    	if (http_request.status == 200){
			//alert (http_request.status);			//alert (http_request.responseText);
    		result = http_request.responseText;
			var update = new Array();
			if(result.indexOf('|') != -1){
				update = result.split('|');
				changeTextPro(update[0], update[1],'defensa');
			}        //  alert('NO Hubo un problema en ejecutar la peticion.');
         } else{ 
            alert('Hubo un problema en ejecutar la peticion.');
        }
	}
}

//funcion que llena las localidades
function alertContents_d_def(){
	//alert (http_request.readyState);	//alert('dentro del alertContents_d.');
	if (http_request_d.readyState == 4){
    	if (http_request_d.status == 200){
            result = http_request_d.responseText;
			var update = new Array();
			if(result.indexOf('|') != -1){
				update = result.split('|');
				changeTextDpto(update[0], update[1],'defensa');
			}
         } else{
            alert('Hubo un problema en ejecutar la peticion.');
         }
	}
}

//funcion que llena el select de departamento
function alertContents_imp(){	
	//alert (http_request.readyState);	//alert('dentro del alertContents.');	
	if (http_request.readyState == 4){		
    	if (http_request.status == 200){
			//alert (http_request.status);			//alert (http_request.responseText);
    		result = http_request.responseText;
			var update = new Array();
			if(result.indexOf('|') != -1){
				update = result.split('|');
				changeTextPro(update[0], update[1],'impresores');
			}        //  alert('NO Hubo un problema en ejecutar la peticion.');
         } else{ 
            alert('Hubo un problema en ejecutar la peticion.');
        }
	}
}

//funcion que llena las localidades
function alertContents_d_imp(){
	//alert (http_request.readyState);	//alert('dentro del alertContents_d.');
	if (http_request_d.readyState == 4){
    	if (http_request_d.status == 200){
            result = http_request_d.responseText;
			var update = new Array();
			if(result.indexOf('|') != -1){
				update = result.split('|');
				changeTextDpto(update[0], update[1],'impresores');
			}
         } else{
            alert('Hubo un problema en ejecutar la peticion.');
         }
	}
}


/* funciones para la paginacion de resultados */

function objetoAjax(){
 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 Pagina(nropagina){
 //donde se mostrará los registros
 divContenido = document.getElementById('contenido');
 
 ajax=objetoAjax();
 //uso del medoto GET indicamos el archivo que realizará el proceso de paginar junto con un valor que representa el nro de pagina
// alert (nropagina);
 
 ajax.open("POST", "./11.php?pag="+nropagina);
 divContenido.innerHTML= '<img src="./img/cargando.gif">';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   //mostrar resultados en esta capa
   divContenido.innerHTML = ajax.responseText
  }
 }
 //como hacemos uso del metodo GET colocamos null ya que enviamos el valor por la url ?pag=nropagina
 ajax.send(null)
}


function validar_impresores(){
    //expresion regular para telefonos
    //permite campos vacios y guiones
  //  var er_tlfono = /(^[0-9\s\+\-])+$/;   
  
     /* var er_tlfono = /^[0-9]{2,3}-? ?[0-9]{6,7}$/;

    //comprueba campo tlfono de formu
    //usa el metodo test de expresion regular
    if(!er_tlfono.test(formu.telefono.value)) {
       alert('Campo TELEFONO no válido.')
       return false    //no submit
    }*/
  
    //expresion regular para emails
    var er_email = /^(.+\@.+\..+)$/;  

    //comprueba el campo email de formu
    //usa metodo test de la expresion regular
    if(!er_email.test(formu.email.value)) {
       alert('Campo E-MAIL no válido.')
       return false    //no submit
    }
/*
    //expresion regular para emails
    var er_cuit = /^(.+\@.+\..+)$/;  

    //comprueba el campo email de formu
    //usa metodo test de la expresion regular
    if(!er_email.test(formu.email.value)) {
       alert('Campo E-MAIL no válido.')
       return false    //no submit
    }    
    */

    var isValid = false;
        var value = formu.cuit.value;
        
        if(value.match(/^\d{2}\-\d{8}\-\d{1}$/)) {
          /*  var sum = 11 - ((value[0] * 5 + value[1] * 4 + value[3] * 3 +
                value[4] * 2 + value[5] * 7 + value[6] * 6 + value[7] * 5 +
                value[8] * 4 + value[9] * 3 + value[10] * 2) % 11)
            sum = (sum==10)? 0 : sum;
            if(value[12] == sum) {
                isValid= true
            }else{
		       alert('Campo CUIT no válido.')
		       return false    //no submit            	
            }*/
        }else{
		    alert('Campo CUIT no válido.')
		    return false    //no submit        	
        }
        
        
    // Verifico el dato de representante este cargado    
	if(document.getElementById("razon_social").value == '' || document.getElementById("cuit").value == '' || document.getElementById("domicilio").value == '' || document.getElementById("responsable").value == '' || document.getElementById("dni").value == '' || document.getElementById("telefono").value == '' || document.getElementById("email").value == '' || document.getElementById("sel_provincia_cons_imp").value == '' || document.getElementById("sel_departamento_cons_imp").value == '' || document.getElementById("sel_localidad_cons_imp").value == '') {
	   alert('Verifique que los datos obligatorios (*) esten cargados.')
		return false;
	}         

        // Verifico que aceptos las condiciones
        
	acuerdo = document.getElementById("acuerdo");
	if( !acuerdo.checked ) {
	   alert('Debe estar de acuerdo con el envio.')
		return false;
	}    

    return true         //pasa al submit
    
}


