var peticion = false; 
if (window.XMLHttpRequest) {
      peticion = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
            peticion = new ActiveXObject("Microsoft.XMLHTTP");
}

function ObtenerDatos(datos,divID) { 

	if(peticion) {
	     var obj = document.getElementById(divID); 
	
	     peticion.open("GET", datos); 
	     peticion.onreadystatechange = function()  { 
	     	if (peticion.readyState == 4) { 
	               obj.innerHTML = peticion.responseText; 
	          } 
	     } 
	peticion.send(null); 
	}else{
		alert('Fallo');
	}
}


function envia_rif()
{
	rif = document.getElementById('rif').value;
	ObtenerDatos('modulos/contratacionesQuery.php?rif='+rif,'content');
}

function enviaImagen(j)
{
	//alert(document.getElementById('nbimagen').value + document.getElementById('idconcurso').value)
	nbimagen = document.getElementById('nbimagen'+j).value;
	idconcurso = document.getElementById('idconcurso'+j).value;
	ObtenerDatosContrata("modulos/contratacionesQuery2.php?nbimagen="+nbimagen+"&idconcurso="+idconcurso,"content");

}

function enviaExisteRif()
{
	if ((document.getElementById('rif').value!='0') && (document.getElementById('rif').value!='') ){
		rif = document.getElementById('rif').value;
		nbimagen = document.getElementById('imagen').value;
		idconcurso = document.getElementById('idconcurso').value;
		//alert(rif+nbimagen+idconcurso)
		//ObtenerDatos("modulos/contratacionesQuery3.php?nbimagen="+nbimagen+"&rif="+rif+"&idconcurso="+idconcurso,'content');
		ObtenerDatosContrata("modulos/contratacionesQuery3.php?nbimagen="+nbimagen+"&rif="+rif+"&idconcurso="+idconcurso,"content");
	}else{
		alert("Tiene que escribir su RIF")
	}
}

function ObtenerDatosContrata(datos,divID) { 

	if(peticion) {
	     var obj = document.getElementById(divID); 
	
	     peticion.open("GET", datos); 
	     peticion.onreadystatechange = function()  { 
	     	if (peticion.readyState == 4) { 
	               obj.innerHTML = peticion.responseText; 
	          } 
	     } 
	peticion.send(null); 
	}else{
		alert('Fallo');
	}
}

function EnviarDatosContrata()
{
	rif_i = document.getElementById('rif_i').value;
    denominacion_i = document.getElementById('denominacion_i').value;
    snc_i = document.getElementById('snc_i').value;
    cedula_i = document.getElementById('cedula_i').value;
    nombre_i = document.getElementById('nombre_i').value;
    apellido_i = document.getElementById('apellido_i').value;
    direccion_i = document.getElementById('direccion_i').value;
    telefono_i = document.getElementById('telefono_i').value;
    fax_i = document.getElementById('fax_i').value;
    mail_i = document.getElementById('mail_i').value;
    imagen = document.getElementById('imagen').value;
    idconcurso = document.getElementById('idconcurso').value;
    
	ObtenerDatosContrata('modulos/descar.php?rif_i='+rif_i+'&denominacion_i='+denominacion_i+'&snc_i='+snc_i+'&cedula_i='+cedula_i+'&nombre_i='+nombre_i+'&apellido_i='+apellido_i+'&direccion_i='+direccion_i+'&telefono_i='+telefono_i+'&fax_i='+fax_i+'&mail_i='+mail_i+'&imagen='+imagen+'&idconcurso='+idconcurso,'content');

}


function numeros_entero(evt){
	var keyPressed = (evt.which) ? evt.which : evt.keyCode
	return !(keyPressed > 31 && (keyPressed < 48 || keyPressed > 57));
}

function CambiarEstilo(id) {
	var elementosMenu = getElementsByClassName(document, "li", "activo");
	for (k = 0; k< elementosMenu.length; k++) {
	elementosMenu[k].className = "inactivo";
	}
	var identity=document.getElementById(id);
	identity.className="activo";
}

/*
    function getElementsByClassName
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}




function buscarNoticia(url,pag){
	//alert(url)
	
	divname="result";
	
	
	dmt_fecha_actual_desde = document.getElementById('fechaTra').value;
	dmt_fecha_actual_hasta = document.getElementById('fechacul').value;
	
	titulo = document.getElementById('titulo').value;
		
	
	
	//alert(titulo+'-'+dmt_fecha_actual_desde+'-'+dmt_fecha_actual_hasta);
	 
        divname="result";
		http.open("GET", url+"?pag="+pag+"&titulo="+titulo+"&dmt_fecha_actual_desde="+dmt_fecha_actual_desde+"&dmt_fecha_actual_hasta="+dmt_fecha_actual_hasta, true);
				
	    http.onreadystatechange = handleHttpResponse;
		http.send(null);
        
		//alert(url+"?pag="+pag+"&lng_idmercado="+lng_idmercado+"&dmt_fecha_actual_desde="+dmt_fecha_actual_desde+"&dmt_fecha_actual_hasta="+dmt_fecha_actual_hasta+"&lng_idrenglon"+lng_idrenglon+"&lng_idrubro"+lng_idrubro+"&lng_idequivalencia"+lng_idequivalencia)
		return false;
	}
	




function buscarId_noticia(url,pag)
{
	divname="result";
	
	id_noticia = document.getElementById('id_noticia').value;
		
	http.open("GET", url+"?pag="+pag+"&id_noticia="+id_noticia, true);
	//alert( url+"?pag="+pag+"&id_noticia="+id_noticia);
    http.onreadystatechange = handleHttpResponse;
	http.send(null);
	
	
}

