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



function ObtenerDatos(datos,divID) { 
//alert(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 mostrardiv() {
	cerrar();
	document.getElementById("registro_i_f").style.display = 'display'
}
function cerrar(){
//alert('cerrar');
	document.getElementById("registro_i_f3").style.display='none';
	document.getElementById("registro_i_f2").style.display='none';
	document.getElementById("registro_i_f2").style.visibility = 'hidden'
	document.getElementById("registro_i_f").style.display = 'none';
	
}
function mostrardiv2() {
	cerrar();
	document.getElementById("registro_i_f2").style.display = 'display'
}
function mostrardiv3() {
	cerrar();
	document.getElementById("registro_i_f3").style.display = 'display'
}
function mostrardiv4() {
	cerrar();
	document.getElementById("registro_i_f4").style.display = 'display'
}
//--------------------------------------------------------------------------------------------

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 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;
	concurso = document.getElementById('concurso'+j).value;
	ObtenerDatosContrata("modulos/contratacionesQuery2.php?nbimagen="+nbimagen+"&idconcurso="+idconcurso+"&concurso="+concurso,'pagina_dinamica','lateralDerecho.php','lateral');

}
function retroceder(datos,divID) 
{ 

	div = document.getElementById('registro_i_f');
	div.style.display='none';

	//alert(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 enviaExisteRif()
{

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

function ObtenerDatosContrata(datos,divID) { 
//alert(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_ic = document.getElementById('telefono_icS').value + document.getElementById('telefono_ic').value;
    telefono_io = document.getElementById('telefono_ioS').value + document.getElementById('telefono_io').value;
    fax_i = document.getElementById('telefono_ifS').value + document.getElementById('fax_i').value;
    mail_i = document.getElementById('mail_i').value;
    imagen = document.getElementById('imagen').value;
    idconcurso = document.getElementById('idconcurso').value;
    nacionalidad_i = document.getElementById('nacionalidad_i').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_ic='+telefono_ic+'&telefono_io='+telefono_io+'&fax_i='+fax_i+'&mail_i='+mail_i+'&imagen='+imagen+'&idconcurso='+idconcurso+'&nacionalidad_i='+nacionalidad_i,'pagina_dinamica','lateralDerecho.php','lateral');

}

function validar()
{
	var s ;
	if (document.fvalida.rif_i.value.length==0){
	alert("Tiene que escribir su RIF")
	document.fvalida.rif_i.value.focus()
	return 0;
	}
	
	if (document.fvalida.denominacion_i.value.length < 3){
	alert("Tiene que escribir su denominación.")
	document.fvalida.denominacion_i.focus()
	return 0;
	}
	
	if ((document.fvalida.snc_i.value.length < 3) || (document.fvalida.snc_i.value.length > 12)){
	alert("Tiene que escribir el SNC")
	document.fvalida.snc_i.focus()
	return 0;
	}
	
	if ((document.fvalida.nacionalidad_i.value.length==0) ){
	alert("Tiene que seleccionar su nacionalidad")
	document.fvalida.nacionalidad_i.focus()
	return 0;
	}
	
	if ((document.fvalida.cedula_i.value.length < 6) || (document.fvalida.cedula_i.value.length > 8)){
	alert("Tiene que escribir su cédula")
	document.fvalida.cedula_i.focus()
	return 0;
	}
	
	s = lTrim(document.fvalida.nombre_i.value);
	//alert(s.length)
	if ((s.length < 3)){
	alert("Tiene que escribir su nombre")
	document.fvalida.nombre_i.focus()
	return 0;
	}
	
	if (document.fvalida.apellido_i.value.length < 3){
	alert("Tiene que escribir su apellido")
	document.fvalida.apellido_i.focus()
	return 0;
	}
	
	if (document.fvalida.direccion_i.value.length < 5){
	alert("Tiene que escribir su dirección")
	document.fvalida.direccion_i.focus()
	return 0;
	}
	
	
	if (document.fvalida.telefono_ic.value.length < 7){
	alert("Tiene que escribir su telefono celular")
	document.fvalida.telefono_ic.focus()
	return 0;
	}
	
	
	if (document.fvalida.telefono_io.value.length < 7){
	alert("Tiene que escribir su telefono de oficina")
	document.fvalida.telefono_io.focus()
	return 0;
	}
	
	
	if (document.fvalida.fax_i.value.length < 7){
	alert("Tiene que escribir su telefono-fax")
	document.fvalida.fax_i.focus()
	return 0;
	}
	
	if (document.fvalida.mail_i.value.length==0){
	alert("Tiene que escribir su correo electronico")
	document.fvalida.mail_i.focus()
	return 0;
	}
	if (document.fvalida.mail_i.value.length > 0){
		if(!valEmail(document.fvalida.mail_i.value)){
		alert('la direcci�n de correo no es correcta');
		document.fvalida.mail_i.focus()
	return 0;
		
		}
		
	}
		
	alert("Gracias por Participar.");
    document.fvalida.submit(); 
    document.getElementById('descarga').innerHTML="<BR/><BR/><BR/><a href='../publiarchivos/PLIEGO HCM CA-01-2012 - 28-12-11 CJ.pdf'><font size='3' color='#297509'><b><I>DESCARGAR PLIEGO</I></b></font></a><BR/><BR/>";
    
}

function valEmail(valor){    // Cortes�a de http://www.ejemplode.com
    //re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    re=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}

function lTrim(sStr){
	 while (sStr.charAt(0) == " ")
	  sStr = sStr.substr(1, sStr.length - 1);
	 return sStr;
	}
function rTrim(sStr){
 while (sStr.charAt(sStr.length - 1) == " ")
  sStr = sStr.substr(0, sStr.length - 1);
 return sStr;
}
function allTrim(sStr){
 return rTrim(lTrim(sStr));
}


function url(url)
{
	
	document.getElementById('formularios').style.display='inline';
	document.getElementById('pagina_dinamica').style.display='none';
	divname="pagina_dinamica";	
	//http.open("GET",url+"?valor="+valor, true);
	http.open("GET",url, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}




//mascaras:
var patron = new Array(2,2,4)
var patron2 = new Array(3,3,2,2)
var patron3 = new Array(1,8,1)


//mascara(this,'-',patron3,true)numeros
//mascara(this,'-',patron3,false)letras
function mascara(d,sep,pat,nums){
if(d.valant != d.value){
	val = d.value
	largo = val.length
	val = val.split(sep)
	val2 = ''
	
	for(r=0;r<val.length;r++){
		val2 += val[r]	
	}
	if(nums){
		for(z=0;z<val2.length;z++){
			if(isNaN(val2.charAt(z))){
				letra = new RegExp(val2.charAt(z),"g")
				val2 = val2.replace(letra,"")
			}
		}
	}
	
	//adicional ,javascript:this.value=this.value.toUpperCase()
	if(nums==false)
	{
		for(z=0;z<val2.length;z++)
		{
			if((val2[0] != 'J') && (val2[0] != 'V') && (val2[0] != 'G'))
			{
				letra = new RegExp(val2.charAt(z),"g")
				val2 = val2.replace(letra,"")
			}
			
			for(z=1;z<val2.length;z++)
			{	
				if(isNaN(val2.charAt(z)))
				{
					letra = new RegExp(val2.charAt(z),"g")
					val2 = val2.replace(letra,"")
				}
			}
		}
	}
	
	
	
	val = ''
	val3 = new Array()
	for(s=0; s<pat.length; s++){
		val3[s] = val2.substring(0,pat[s])
		val2 = val2.substr(pat[s])
	}
	for(q=0;q<val3.length; q++){
		if(q ==0){
			val = val3[q]
		}
		else{
			if(val3[q] != ""){
				val += sep + val3[q]
				}
		}
	}
	d.value = val
	d.valant = val
	}
}


function Solo_Numerico(variable){
    Numer=parseInt(variable);
    if (isNaN(Numer)){
        return "";
    }
    return Numer;
}
    
function ValNumero(Control){
    Control.value=Solo_Numerico(Control.value);
}


var nav4 = window.Event ? true : false;
function acceptNum(evt)
{
	// NOTA: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
	var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57) || key == 46);
}


function alfanumerico(obj){
	var tecla = window.event.keyCode;
	if(65<=tecla && tecla<=90 || 97<=tecla && tecla<=122 || 48<=tecla && tecla<=57){
	}else{
	window.event.keyCode=0;
	}
}




function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function esAlfabetico(checkString)
{
    newString = "";
    count = 0;

    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);

        if ((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z" ) || (ch = " ")) {
            newString += ch;
        }
    }

    return newString;
}
