//////////////////////////////Funciones para reportes archivso de obleas nominadas////////////////////
////////////////////////////////PRUEBA///////////////////////////////////////////////////////////////

function CuadroEstado_1(TipoSujeto){
	
	switch (TipoSujeto)
  {
	case "PEC": 
          var CodigoSujeto=document.getElementById("Codigo_pec").value;
           var Fecha=document.getElementById("Fecha_pec");
               if(!vacio(CodigoSujeto))
                  {
                   if(!vacio(Fecha.value)) 
	                {
                    if(!valFecha(Fecha))
                     {
		             ajax=nuevoAjax();
                     ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarCuadroEstadoSujetosObleaNom.php", true);
                     ajax.onreadystatechange=function() 
                     { 
                      if (ajax.readyState==1)
	                   { 
		               document.getElementById("DetalleEstado").innerHTML="<h2>.....Cargando.....</h2>";
	                   } 
	                  if(ajax.readyState==4)
	                   { 
		              document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
	                   } 
                     }    
                     ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	                ajax.send("TipoSujeto="+TipoSujeto+"&CodigoSujeto="+CodigoSujeto+"&Fecha="+Fecha.value);
                   }
                   else
		             alert("Fecha inválida, Recuerde dd/mm/aaaa");
	              }
                  else
                   {
	               ajax=nuevoAjax();
                   ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarCuadroEstadoSujetosObleaNom.php", true);
                   ajax.onreadystatechange=function() 
                    { 
                    if (ajax.readyState==1)
	                 { 
		              document.getElementById("DetalleEstado").innerHTML="<h2>.....Cargando.....</h2>";
	                 } 
	                if (ajax.readyState==4)
	                 { 
		              document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
	                 } 
                   }  
                    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	                ajax.send("TipoSujeto="+TipoSujeto+"&CodigoSujeto="+CodigoSujeto+"&Fecha="+Fecha.value);   
	             }
			   }
			   else
                 {
				 ajax=nuevoAjax();
	             ajax.open("GET", "/SICGNC/blanco.php", true);
                 ajax.onreadystatechange=function() 
	              { 
		          if (ajax.readyState==4)
			       { 
			       document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
			       } 
	              }
                 ajax.send(null);	  
	             }					
	break;			 
		}
	
	}

function BajarArchError_C(Id,TipoSujeto)
{
	window.open("/SICGNC/ResultadoConsulta/BajarArchivoErrorC.php?Id="+Id+"&TipoSujeto="+TipoSujeto,"VentanaDonwload","width=200,height=200,scrollbars=yes"); 
}

//////////Esta función me abre una página que baja la asignacion de obleas  del PEC/////////////////
function BajarObleasAsignadas(Id)
{
	window.open("/SICGNC/ResultadoConsulta/BajarArchivoObleasAsignadas.php?Id="+Id,"VentanaDonwload","width=200,height=200,scrollbars=yes"); 
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function CargarLoteCilindrosVendidos()
{
 //alert(TipoOp);
    					var CodHomolog=document.getElementById("CodHomolog").value;
					   var NroSerie=document.getElementById("NroSerie").value;


if((CodHomolog!=0)) {
					  
					   ajax=nuevoAjax();
					   ajax.open("POST", "/SICGNC/ResultadoConsulta/CargaDetalleCilindrosLotes.php");
					   ajax.onreadystatechange=function() 
						{ 
						if (ajax.readyState==1)
						   {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						   }
					     if (ajax.readyState==4)
							{ 
							document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							} 
						}
					  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					  ajax.send("CodHomolog="+CodHomolog+"&NroSerie="+NroSerie);
}
 else {
	 
	 alert("Debe completar el campo correspodiente al CID.");
	 } 
}

function CargarLoteValvulasVendidas()
{
 //alert(TipoOp);
    					var CodHomolog=document.getElementById("CodHomolog").value;
					   var NroSerie=document.getElementById("NroSerie").value;


if((CodHomolog!=0)) {
					  
					   ajax=nuevoAjax();
					   ajax.open("POST", "/SICGNC/ResultadoConsulta/CargaDetalleValvulasLotes.php");
					   ajax.onreadystatechange=function() 
						{ 
						if (ajax.readyState==1)
						   {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						   }
					     if (ajax.readyState==4)
							{ 
							document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							} 
						}
					  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					  ajax.send("CodHomolog="+CodHomolog+"&NroSerie="+NroSerie);
}
 else {
	 
	 alert("Debe completar el campo correspodiente al CID.");
	 } 
}




function VerLotesCilindrosVendidos()
{
var Fabricante=document.getElementById("Codigo").value;
//alert(Fabricante);
 if((Fabricante!=0))
  {
    ajax=nuevoAjax();
 	ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarLotesCilindrosVendidosFab.php",true);
    ajax.onreadystatechange=function() 
	{ 
	if (ajax.readyState==1)
		    {
			 document.getElementById("DetalleVentaCilindros").innerHTML="<h2>.....Cargando......</h2>"
			}
	if (ajax.readyState==4)
		{ 
		document.getElementById("DetalleVentaCilindros").innerHTML=ajax.responseText;
		} 
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("Fabricante="+Fabricante);
  }
  else
     {
	  ajax=nuevoAjax();
	  ajax.open("GET", "/SICGNC/blanco.php", true);
      ajax.onreadystatechange=function() 
	   { 
		 if (ajax.readyState==4)
			 { 
			 document.getElementById("DetalleVentaCilindros").innerHTML=ajax.responseText;
			 } 
	   }
      ajax.send(null);
	}  
}


///////////////////////////////Ingreso al apretar Enter//////////////////////////////////////////////
function presionar(e)
	{
	//Esta parrte es para IE
	if (window.event)
	  {
	           if (window.event.keyCode==13)
		{ValidarClave();}// 
	  }
	  else
                    //Esto es para Firefox y creo otros navegadores
		if (e)
		{
		  if(e.which==13)
		  	{ValidarClave();}
		}
	}
	

	
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////Reporte Valvulas Venta Lotes/////////////////////////////////////////////////////
function CargarLoteValvulasVendidas()
{
 //alert(TipoOp);
    					var CodHomolog=document.getElementById("CodHomolog").value;
					   var NroSerie=document.getElementById("NroSerie").value;


if((CodHomolog!=0)) {
					  
					   ajax=nuevoAjax();
					   ajax.open("POST", "/SICGNC/ResultadoConsulta/CargaDetalleValvulasLotes.php");
					   ajax.onreadystatechange=function() 
						{ 
						if (ajax.readyState==1)
						   {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						   }
					     if (ajax.readyState==4)
							{ 
							document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							} 
						}
					  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					  ajax.send("CodHomolog="+CodHomolog+"&NroSerie="+NroSerie);
}
 else {
	 
	 alert("Debe completar el campo correspodiente al CID.");
	 } 
}


//////////////////////////////////////////////////////////////////////////////////////
////////////////////////Funciones Elementos Certificados///////////////////////////////////



function CargarFabricantes()
{

   ajax=nuevoAjax();
  ajax.open("POST","/SICGNC/Cargas/Accesorios/Reportes/CargaFabricante.php", true);
  ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{ 
              document.getElementById("fila_fab").innerHTML=ajax.responseText;
		    }
		}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   ajax.send(null);
  
}


//////////////////////FUNCIONES VENTA DE CILINDROS DE FAB A PEC////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////


function CompletarHastaCilindro() {
 var Desde=document.getElementById("Desde").value.toUpperCase();
 document.getElementById("Desde").value=Desde;
var  l=1;
var j=0;

//var CantCaracteres=Desde.length;
//var Hasta=Desde.substring(0,CantCaracteres-3);

  if (IsNumeric(Desde)==false) {
			   var j=0;
			   for(  var i = Desde.length;i>1; i--) { //recorro el numero de serie hasta que el cararcter no sea un numero
				var numero=Desde.substring(i-1);
				if(IsNumeric(numero)==true)
					{ j++;} else {break;}
				} // cierro for
							} 
				var CantidadModificable=Desde.length-j;
				// si la parte anteriro a la ultima letra o simbolo que no sea un numero no es igual en ambas numeros de serie lo rechazo
var Hasta=Desde.substring(0,CantidadModificable); 

//alert(Hasta);
document.getElementById("Hasta").value=Hasta;
//document.getElementById("Hasta").readOnly=true;

}

function fRight(cadena, n)
{   
 if (n <= 0)    
   		return "";   
 else if (n > String(cadena).length)      
		 return str;   
	  else {       var iLen = String(cadena).length;      
	   return String(cadena).substring(iLen, iLen - n);    }
}


function RestarNumeroSerieCilindros()
{
 var desde=document.getElementById("Desde").value;
 var hasta=document.getElementById("Hasta").value;
 var marca=document.getElementById("Marca").value;
 var total;
 var Desdeaux;
 var Hastaaux;
   //alert(Desdeaux);
 if ((desde.length==hasta.length)) { // para que los dos numeros de serie tengan la misma cantidad de caracteres 
 if ((!vacio(desde)) && (!vacio(hasta)))
  {  //1
		if (IsNumeric(desde)==false) {
			   var j=0;
			   for(  var i = desde.length;i>1; i--) { //recorro el numero de serie hasta que el cararcter no sea un numero
			// alert(i);
				var numero=desde.substring(i-1);
			//	alert(numero);
				//var patron=/[0-9]/;
					if(IsNumeric(numero)==true)
					{ j++;} else {break;}
				} // cierro for
				//alert (j);
				Desdeaux=fRight(desde,j);
  				Hastaaux=fRight(hasta,j); 
				
				
				} // cierro if de variable alfanumerica
			else {
				Desdeaux=desde;
  				Hastaaux=hasta;
					
				}	
				
 				total= (Hastaaux - Desdeaux)+1;
				//alert(total);	
				
				
				 if (total-1<0 ) {
	  alert("Valores inválidos por favor reingreselos.");
	  document.getElementById("Hasta").value=""; }
	else {
		   document.getElementById("Cantidad").value=total; 
		      }
  return;	
  }// cierro 1
  
 }// ciero 0
  else {alert("Valores inválidos por favor reingreselos, los numeros de serie deben tener la misma cantidad de caracteres");
    document.getElementById("Hasta").value="";}
}


function CargarRangoCilindros()
{
 var Pec=document.getElementById("Codigo").value;	
 var Marca=document.getElementById("Marca").value; 
 var NroCodigoHomologado_aux=document.getElementById("CodHomolog").value;
 var NroCodigoHomologado=NroCodigoHomologado_aux.split(";");
 var desde=document.getElementById("Desde").value;
 var hasta=document.getElementById("Hasta").value;
 var Cantidad=document.getElementById("Cantidad").value;
 var DesdeAux;
 var HastaAux;
 var total;
 var OK=true;


if(Pec==0)   {OK=false;document.getElementById("celda_pec").style.color="red";}else{ document.getElementById("celda_pec").style.color="black"; 	}
if(Marca==0)   {OK=false;document.getElementById("celda_marca_color").style.color="red";}else{ document.getElementById("celda_marca_color").style.color="black"; 	}			 
if(NroCodigoHomologado[0]==0)   {OK=false;document.getElementById("celda_CodHomologado_color").style.color="red";}else{ document.getElementById("celda_CodHomologado_color").style.color="black"; 	}	
if (vacio(desde)){  OK=false;document.getElementById("celda_Desde").style.color="red";}else{ document.getElementById("celda_Desde").style.color="black";}
if (vacio(hasta)){ OK=false;document.getElementById("celda_Hasta").style.color="red";}else{ document.getElementById("celda_Hasta").style.color="black";}

  
  
  	 if(NroCodigoHomologado[0]=="0")
	   {
		OK=false; 
		document.getElementById("celda_CodHomologado_color").style.color="red";
		}
	 else{ 
		  document.getElementById("celda_CodHomologado_color").style.color="black";
		  var FormatNroSerie=NroCodigoHomologado[1];
		  if (vacio(FormatNroSerie))
			   {
				 OK_FormatNroSerie=false;
			   		document.getElementById("celda_Desde").style.color="red";
				  document.getElementById("celda_Hasta").style.color="red";
				   alert("No EXISTE formato de numero de serie para el CID seleccionado.");
				   return;
			   }
		  else{
			   var patron =FormatNroSerie;	
			   //alert(Hasta.search(patron));
	 			//alert(patron);
			   if((desde.search(patron)) || (hasta.search(patron))) 
				 {
					 OK=false;
				  document.getElementById("celda_Desde").style.color="red";
				  document.getElementById("celda_Hasta").style.color="red";
				   alert("El formato de numero de serie no corresponde al CID.");
				   return;
				 }	 
			   else 
				  {
				   document.getElementById("celda_Desde").style.color="black";   
				   document.getElementById("celda_Hasta").style.color="black";   
				  }
			  }
	 	 }	 
  
  
  
  
  if (IsNumeric(desde)==false) {
			   var j=0;
			   for(  var i = desde.length;i>1; i--) { //recorro el numero de serie hasta que el cararcter no sea un numero
			
				var numero=desde.substring(i-1);
				if(IsNumeric(numero)==true)
					{ j++;} else {break;}
				} // cierro for
								
				var CantidadModificable=desde.length-j;
			// si la parte anterior a la ultima letra o simbolo que no sea un numero no es igual en ambas numeros de serie lo rechazo
			//alert(desde.substring(0,CantidadModificable));
		if  (desde.substring(0,CantidadModificable)!=hasta.substring(0,CantidadModificable))
				{
			 alert("Las letras correspondientes al numero de serie del cilindro deben ser las mismas");
			 OK=false;document.getElementById("Celda_Desde").style.color="red";
			 OK=false;document.getElementById("Celda_Hasta").style.color="red";
			 return;
			 }
				
				}
			else {var CantidadModificable=0;}	
				
				 // cierro if de variable alfanumerica
//alert(Cantidad);
if(OK)
   {
   	if(confirm("¿Está seguro del rango que va a cargar?"))
      {

    ajax=nuevoAjax();
    ajax.open("POST", "/SICGNC/Cilindros/AltaRangoCilindro.php",true);
    ajax.onreadystatechange=function() 
 	  { 
			
		if (ajax.readyState==4)
		 { 
			document.getElementById("DatosDelLote").innerHTML=ajax.responseText;
		 } 
	 }
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 ajax.send("desde="+desde+"&hasta="+hasta+"&Pec="+Pec+"&CodHomolog="+NroCodigoHomologado[0]+"&CantidadModificable="+CantidadModificable+"&Marca="+Marca+"&Cantidad="+Cantidad);
   }
   }
   else
       alert("Algunos campos están vacíos o mal cargados, verifíquelos los campos rojos");  
}





function DatosReventaCilindro(Marca,Codigo,Desde,Hasta,Pec)
{  
//alert(Pec);
/*alert(Codigo);
alert(Desde);*/

    ajax=nuevoAjax();
 	ajax.open("POST", "/SICGNC/Cilindros/DatosVentaCilindrosPEC.php",true);
 	ajax.onreadystatechange=function() 
  		 {
		 if (ajax.readyState==1)
		    {
			 document.getElementById("DatosRangoCilindro").innerHTML="<br><br><img  src='../Images/progress2.gif'>";
			}
		  
   		 if (ajax.readyState==4)
    		 { 
		      document.getElementById("DatosRangoCilindro").innerHTML=ajax.responseText;
		     } 
  		 } 
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("Marca="+Marca+"&Codigo="+Codigo+"&Desde="+Desde+"&Hasta="+Hasta+"&Pec="+Pec);

 }


function ReCargarRangoCilindros()
{
  var Pec=document.getElementById("Codigo").value;	
  var PecVendedor=document.getElementById("PecVendedor").value;	
  var Marca=document.getElementById("Marca").value;
  var FormatNroSerie=document.getElementById("FormatSerie").value;
  var NroCodigoHomologado=document.getElementById("CodHomolog").value;

  var CantidadCilindros=document.getElementById("CantidadCilindros").value;
  var DesdeAux;
  var HastaAux;
  var total;
  var OK=true;
  var celda;


var Cilindros=new Array();
var CilindroCompradosCod=new Array();
var CilindroCompradosNro=new Array();
var j=0;
for(var i=0;i<=CantidadCilindros;i++){
celda=document.getElementById("Cilindro"+i);
//alert(celda.style.backgroundColor);
if(celda.style.backgroundColor=="#99ffff") { //alert('llega');
CilindroCompradosCod[j]=document.getElementById("CilindroCompradosCod"+i).value
CilindroCompradosNro[j]=document.getElementById("CilindroCompradosNro"+i).value


j++;
}
}

 //alert(CilindroCompradosCod) ;
  
 //  alert(CilindroCompradosNro) ;
   if(Pec==0)   {OK=false;document.getElementById("celda_pec").style.color="red";}else{ document.getElementById("celda_pec").style.color="black"; 	}
  
 if(OK)
   {
   	if(confirm("¿ Está seguro del rango que va a cargar ?"))
      {

    ajax=nuevoAjax();
    ajax.open("POST", "/SICGNC/Cilindros/AltaRangoCilindroRevendidos.php",true);
    ajax.onreadystatechange=function() 
 	  { 
			
		if (ajax.readyState==4)
		 { 
			document.getElementById("DatosDelLote").innerHTML=ajax.responseText;
		 } 
	 }
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 ajax.send("Pec="+Pec+"&CodHomolog="+NroCodigoHomologado+"&Marca="+Marca+"&PecVendedor="+PecVendedor+"&CilindroCompradosCod="+CilindroCompradosCod+"&CilindroCompradosNro="+CilindroCompradosNro+"&CantCilindros="+j);
   }
   }
   else
       alert("Algunos campos están vacíos o mal cargados, verifíquelos los campos rojos");   
}



/////////////////////FIN////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////Venta de Valvulas cilindros/////////////////////////////////////////


function LevatarCodigoVentaElem(TipoComponente)
{
	var Fab=document.getElementById("Fab").value;
	//alert(Fab);
	var valor=document.getElementById("Marca").options[document.getElementById("Marca").selectedIndex].value;
	//alert(valor+"----"+TipoComponente);
	if(valor==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("CodHomolog");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="---Seleccionar---";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
	}
	else
	{
	//Código de Homologación según la marca y el tipo de componente
	    ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/CargarCodHomologVentaElementos.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				combo=document.getElementById("CodHomolog");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celda_CodHomologado").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("TipoComponente="+TipoComponente+"&Marca="+valor+"&Fab="+Fab);	
	}

}



function CompletarHastaValvula() {
 var Desde=document.getElementById("Desde").value.toUpperCase();
 document.getElementById("Desde").value=Desde;
var  l=1;
var j=0;
for( var i = 0; i < Desde.length; i++) {
var letra=Desde.substring(l,i);
var patron=/[A-Z]/;
    if(patron.test(letra)){
		//alert(Desde.charAt(i));
		 j++;}
l++
}
//alert(j);
var Hasta=Desde.substring(0,j);

//alert(Hasta);
document.getElementById("Hasta").value=Hasta;
//document.getElementById("Hasta").readOnly=true;

}


function CargarRangoValvulasCilindros()
{
  var Pec=document.getElementById("Codigo").value;	
  var Marca=document.getElementById("Marca").value;
  
 var NroCodigoHomologado_aux=document.getElementById("CodHomolog").value;
 var NroCodigoHomologado=NroCodigoHomologado_aux.split(";");
   var desde=document.getElementById("Desde").value;
  var hasta=document.getElementById("Hasta").value;
  var Cantidad=document.getElementById("Cantidad").value;



  var DesdeAux;
  var HastaAux;
  var total;
  var OK=true;


  
  
  
   if(Pec==0)   {OK=false;document.getElementById("celda_pec").style.color="red";}else{ document.getElementById("celda_pec").style.color="black"; 	}
   if(Marca==0)   {OK=false;document.getElementById("celda_marca_color").style.color="red";}else{ document.getElementById("celda_marca_color").style.color="black"; 	}			 
   if(NroCodigoHomologado[0]==0)   {OK=false;document.getElementById("celda_CodHomologado_color").style.color="red";}else{ document.getElementById("celda_CodHomologado_color").style.color="black"; 	}	
   
   if (vacio(desde)){  OK=false;document.getElementById("Celda_Desde").style.color="red";} 

//else{ document.getElementById("Celda_Desde").style.color="black";}

     if (vacio(hasta)){ OK=false;document.getElementById("celda_Hasta").style.color="red";}
//else{ document.getElementById("celda_Hasta").style.color="black";}

  
  
  	 if(NroCodigoHomologado[0]=="0")
	   {
		OK=false; 
		document.getElementById("celda_CodHomologado_color").style.color="red";
		}
	 else{ 
		  document.getElementById("celda_CodHomologado_color").style.color="black";
		  var FormatNroSerie=NroCodigoHomologado[1];
		  if (vacio(FormatNroSerie))
			   {
			 OK_FormatNroSerie=false;
			   document.getElementById("celda_Desde").style.color="red";
				  document.getElementById("celda_Hasta").style.color="red";
			   }
		  else{
			   var patron =FormatNroSerie;	
			   //alert(Hasta.search(patron));
	 			//alert(patron);
			   if((desde.search(patron)) || (hasta.search(patron))) 
				 {
					 OK=false;
				  document.getElementById("celda_Desde").style.color="red";
				  document.getElementById("celda_Hasta").style.color="red";
				 }	 
			   else 
				  {
				   document.getElementById("celda_Desde").style.color="black";   
				   document.getElementById("celda_Hasta").style.color="black";   
				  }
			  }
	 	 }	 
  
  
  
var  l=1;
var j=0;
for( var i = 0; i < desde.length; i++) {
var letra=desde.substring(l,i);
var letraH=hasta.substring(l,i);
var patron=/[A-Z]/;
    if(patron.test(letra)){
		 if (letra!=letraH) {
			 alert("Las letras correspondientes al numero de serie de la válvula deben ser las mismas");
			 OK=false;document.getElementById("Celda_Desde").style.color="red";
			 OK=false;document.getElementById("Celda_Hasta").style.color="red";
			 return;
			 }
		//alert(Desde.charAt(i));
		 j++;}
l++
}
 if(OK)
   {
   	if(confirm("¿ Está seguro del rango que va a cargar ?"))
      {

    ajax=nuevoAjax();
    ajax.open("POST", "/SICGNC/Cargas/AltaRangoValvulasCilindro.php",true);
    ajax.onreadystatechange=function() 
 	  { 
			
		if (ajax.readyState==4)
		 { 
			document.getElementById("DatosDelLote").innerHTML=ajax.responseText;
		 } 
	 }
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 ajax.send("desde="+desde+"&hasta="+hasta+"&Pec="+Pec+"&CodHomolog="+NroCodigoHomologado[0]+"&Cantidad="+Cantidad+"&Marca="+Marca+"&CantidadLetras="+j);
   }
   }
   else
       alert("Algunos campos están vacíos o mal cargados, verifíquelos los campos rojos");   
}




function LevantarLotesHomologados(Tipo)
{

//alert(Tipo);
 var NroCodigoHomologado_aux=document.getElementById("CodHomolog").value;
 var NroCodigoHomologado=NroCodigoHomologado_aux.split(";");

      ajax=nuevoAjax();
      ajax.open("POST", "/SICGNC/Cargas/MostrarLotesHomologadosPorCodigo.php", true);
      ajax.onreadystatechange=function() 
       { 
	    if (ajax.readyState==1)
	     { 
		  document.getElementById("DatosDelLote").innerHTML="<br><br><img  src='../Images/progress2.gif'>";
		 }
	   if (ajax.readyState==4)
        { 
	      document.getElementById("DatosDelLote").innerHTML=ajax.responseText;
	    } 
	 }
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("HomologCode="+NroCodigoHomologado[0]+"&Tipo="+Tipo);
  
}





function ReCargarRangoValvulasCilindros()
{
  var Pec=document.getElementById("Codigo").value;	
  var PecVendedor=document.getElementById("PecVendedor").value;	
  var Marca=document.getElementById("Marca").value;
  var FormatNroSerie=document.getElementById("FormatSerie").value;
  var NroCodigoHomologado=document.getElementById("CodHomolog").value;
  //var desde=document.getElementById("desde").value;
  //var hasta=document.getElementById("hasta").value;
 // var Cantidad=document.getElementById("Cantidad").value;

  var CantidadValvulas=document.getElementById("CantidadValvulas").value;
  var DesdeAux;
  var HastaAux;
  var total;
  var OK=true;
  var celda;








var Valvulas=new Array();
var ValvulasMarcadasCod=new Array();
var ValvulasMarcadasNro=new Array();
var j=0;
for(var i=0;i<=CantidadValvulas;i++){
celda=document.getElementById("Valvula"+i);
//alert(celda.style.backgroundColor);
if(celda.style.backgroundColor=="#99ffff") { //alert('llega');
ValvulasMarcadasCod[j]=document.getElementById("ValvulasCompradasCod"+i).value
ValvulasMarcadasNro[j]=document.getElementById("ValvulasCompradasNro"+i).value


j++;
}
}

 //alert(ValvulasMarcadasCod) ;
  
 //  alert(ValvulasMarcadasNro) ;
   if(Pec==0)   {OK=false;document.getElementById("celda_pec").style.color="red";}else{ document.getElementById("celda_pec").style.color="black"; 	}
  /* if(Marca==0)   {OK=false;document.getElementById("celda_marca_color").style.color="red";}else{ document.getElementById("celda_marca_color").style.color="black"; 	}			 
   if(NroCodigoHomologado[0]==0)   {OK=false;document.getElementById("celda_CodHomologado_color").style.color="red";}else{ document.getElementById("celda_CodHomologado_color").style.color="black"; 	}	
   
   if (vacio(desde)){  OK=false;document.getElementById("Celda_Desde").style.color="red";}else{ document.getElementById("Celda_Desde").style.color="black";}

     if (vacio(hasta)){ OK=false;document.getElementById("celda_Hasta").style.color="red";}else{ document.getElementById("celda_Hasta").style.color="black";}

  
  
  	 if(NroCodigoHomologado=="0")
	   {
		OK=false; 
		document.getElementById("celda_CodHomologado_color").style.color="red";
		}
	 else{ 
		  document.getElementById("celda_CodHomologado_color").style.color="black";
		
		  if (vacio(FormatNroSerie))
			   {
			 OK_FormatNroSerie=false;
			   document.getElementById("celda_Desde").style.color="red";
				  document.getElementById("celda_Hasta").style.color="red";
			   }
		  else{
			   var patron =FormatNroSerie;	
			   //alert(Hasta.search(patron));
	 			//alert(patron);
			   if((desde.search(patron)) || (hasta.search(patron))) 
				 {
					 OK=false;
				  document.getElementById("celda_Desde").style.color="red";
				  document.getElementById("celda_Hasta").style.color="red";
				 }	 
			   else 
				  {
				   document.getElementById("celda_Desde").style.color="black";   
				   document.getElementById("celda_Hasta").style.color="black";   
				  }
			  }
	 	 }	 
  
var  l=1;
var j=0;
for( var i = 0; i < desde.length; i++) {
var letra=desde.substring(l,i);
var letraH=hasta.substring(l,i);
var patron=/[A-Z]/;
    if(patron.test(letra)){
		 if (letra!=letraH) {
			 alert("Las letras correspondientes al numero de serie de la válvula deben ser las mismas");
			 OK=false;document.getElementById("Celda_Desde").style.color="red";
			 OK=false;document.getElementById("Celda_Hasta").style.color="red";
			 return;
			 }
		//alert(Desde.charAt(i));
		 j++;}
l++
}  */
 if(OK)
   {
   	if(confirm("¿ Está seguro del rango que va a cargar ?"))
      {

    ajax=nuevoAjax();
    ajax.open("POST", "/SICGNC/Cargas/AltaRangoValvulasCilindroRevendida_.php",true);
    ajax.onreadystatechange=function() 
 	  { 
			
		if (ajax.readyState==4)
		 { 
			document.getElementById("DatosDelLote").innerHTML=ajax.responseText;
		 } 
	 }
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 ajax.send("Pec="+Pec+"&CodHomolog="+NroCodigoHomologado+"&Marca="+Marca+"&PecVendedor="+PecVendedor+"&ValvulasMarcadasCod="+ValvulasMarcadasCod+"&ValvulasMarcadasNro="+ValvulasMarcadasNro+"&CantValvulas="+j);
   }
   }
   else
       alert("Algunos campos están vacíos o mal cargados, verifíquelos los campos rojos");   
}

function ilumina(id){ 

var celda=document.getElementById(id);
//alert(celda.style.backgroundColor);
       if(celda.style.backgroundColor==""){
		   celda.style.backgroundColor="#99FFFF"; return;
		   }
	/*  if(celda.style.backgroundColor=="#99FFFF") {
	  celda.style.backgroundColor="#FFFFFF"; return;
		   }	*/   
      
if(celda.style.backgroundColor=="#99ffff") {
	  celda.style.backgroundColor=""; return;
		   }	  


  } 




function DatosReventaValvula(Marca,Codigo,Desde,Hasta,Pec)
{  
//alert(Pec);
/*alert(Codigo);
alert(Desde);*/

    ajax=nuevoAjax();
 	ajax.open("POST", "/SICGNC/Cargas/DatosVentaValvulasCilindrosPEC.php",true);
 	ajax.onreadystatechange=function() 
  		 {
		 if (ajax.readyState==1)
		    {
			 document.getElementById("DatosRangoValvula").innerHTML="<br><br><img  src='../Images/progress2.gif'>";
			}
		  
   		 if (ajax.readyState==4)
    		 { 
		      document.getElementById("DatosRangoValvula").innerHTML=ajax.responseText;
		     } 
  		 } 
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("Marca="+Marca+"&Codigo="+Codigo+"&Desde="+Desde+"&Hasta="+Hasta+"&Pec="+Pec);

 }

//////////////////////////////Reportes Venta Valvulas Cilindro//////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
function VerLotesValvulasVendidas()
{
var Fabricante=document.getElementById("Codigo").value;
//alert(Fabricante);
 if((Fabricante!=0))
  {
    ajax=nuevoAjax();
 	ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarLotesValvulasVendidasFab.php",true);
    ajax.onreadystatechange=function() 
	{ 
	if (ajax.readyState==1)
		    {
			 document.getElementById("DetalleVentaValvulas").innerHTML="<h2>.....Cargando......</h2>"
			}
	if (ajax.readyState==4)
		{ 
		document.getElementById("DetalleVentaValvulas").innerHTML=ajax.responseText;
		} 
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("Fabricante="+Fabricante);
  }
  else
     {
	  ajax=nuevoAjax();
	  ajax.open("GET", "/SICGNC/blanco.php", true);
      ajax.onreadystatechange=function() 
	   { 
		 if (ajax.readyState==4)
			 { 
			 document.getElementById("DetalleVentaValvulas").innerHTML=ajax.responseText;
			 } 
	   }
      ajax.send(null);
	}  
}

/////////////////////////////////////////////////////////////////////////////////////////////


function RenovarPrototipo() 
{
var NCertificado=document.getElementById("NCertificado").value;
var Matricula=document.getElementById("Matricula").value;
var FEmision=document.getElementById("FEmision").value;
var FVencimiento=document.getElementById("FVencimiento").value;
var Observacion=document.getElementById("Observacion").value;


var Componente=document.getElementById("Codigo").value;
var Fabricante=document.getElementById("Fabricante").value;
var Marca=document.getElementById("Marca").value;
var Modelo=document.getElementById("Modelo").value;

var OK=true;





Param="NCertificado="+NCertificado+"&Matricula="+Matricula+"&FEmision="+FEmision+"&FVencimiento="+FVencimiento+"&Observacion="+Observacion+"&Componente="+Componente+"&Fabricante="+Fabricante+"&Marca="+Marca+"&Modelo="+Modelo;
//alert(Componente);

if(vacio(Observacion)){OK=false; document.getElementById("celda_Observaciones_color").style.color="red";}else{ document.getElementById("celda_Observaciones_color").style.color="black";}
if(vacio(NCertificado)){OK=false; document.getElementById("celda_NCertificado_color").style.color="red";}else{ document.getElementById("celda_NCertificado_color").style.color="black";}
  if(vacio(Matricula)){OK=false; document.getElementById("celda_Matricula_color").style.color="red";}else{ document.getElementById("celda_Matricula_color").style.color="black";}

  if(vacio(FEmision)){OK=false; document.getElementById("celda_FEmision_color").style.color="red";}else{ document.getElementById("celda_FEmision_color").style.color="black";}
  if(vacio(FVencimiento)){OK=false; document.getElementById("celda_FVencimiento_color").style.color="red";}else{ document.getElementById("celda_FVencimiento_color").style.color="black";}

  //if(vacio(Modelo)){OK=false; document.getElementById("celda_Modelo_color").style.color="red";}else{ document.getElementById("celda_Modelo_color").style.color="black";}



 

//alert(Param);
if(OK){
	 if (confirm("Esta seguro de los datos a cargar"))
    {
		 ajax=nuevoAjax();
		 ajax.open("POST", "/SICGNC/Cargas/Accesorios/R_PrototipoGNC.php",true);
		 ajax.onreadystatechange=function() 
	   	{ 
		document.getElementById('RenovacionPrototipo').innerHTML="<br><br><img  src='../../Images/progress2.gif'>";
		
		  if (ajax.readyState==4) {
			     if(ajax.status==200) {
					     document.getElementById('RenovacionPrototipo').innerHTML=ajax.responseText;
			     			           }
								  }
	  	 }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(Param);
}
}
else {
	 alert("Hay algunos campos que son obligatorios, verifique los campos en rojo");	
	}
}  






function CargarRenovacionPrototipo()
{
		var Codigo=document.getElementById("Codigo").value;
		var Marca=document.getElementById("Marca").value;
		var Fabricante=document.getElementById("Fabricante").value;
		var Modelo=document.getElementById("Modelo").value;
		var OK=true;
		var Param;
		//alert(Codigo);
		 if(Marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red"; }else{ document.getElementById("celda_marca_color").style.color="black";}
		if(Codigo=="0"){OK=false; document.getElementById("celda_producto_color").style.color="red"; }else{ document.getElementById("celda_producto_color").style.color="black";}
		if(Fabricante=="0"){OK=false; document.getElementById("celda_Fabricante_color").style.color="red";}else{ document.getElementById("celda_Fabricante_color").style.color="black";}
		
		Param="Fabricante="+Fabricante+"&Marca="+Marca+"&Codigo="+Codigo+"&Modelo="+Modelo;
		//alert(Param);
		
	if(OK) {	
		
		ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/DatosRenovacionPrototipo.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4){
					 if(ajax.status==200){
						//alert(Param);
					document.getElementById("CaracteristicasAccesorio").innerHTML=ajax.responseText;
					document.getElementById("Codigo").disabled=true;
					//document.getElementById("Marca").disabled=true;
					document.getElementById("Fabricante").disabled=true;
					
							
										} 
									}
		} 
		
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(Param);
	
		
	} else {
		
		alert("Complete los campos en coloreados en rojo.");
		}
}



function LimpiarCombos(){
	
	combo=document.getElementById("Fabricante");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="---Seleccionar---";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
	
		
		
	combo1=document.getElementById("Marca");
		combo1.length=0;
		var nuevaOpcion1=document.createElement("option"); 
		nuevaOpcion1.value=0;
		nuevaOpcion1.innerHTML="---Seleccionar---";
		combo1.appendChild(nuevaOpcion1);	
		combo1.value=0;
		
		combo2=document.getElementById("Modelo");
		combo2.length=0;
		var nuevaOpcion2=document.createElement("option"); 
		nuevaOpcion2.value=0;
		nuevaOpcion2.innerHTML="---Seleccionar---";
		combo2.appendChild(nuevaOpcion2);	
		combo2.value=0;	
	
	
	document.getElementById("CaracteristicasAccesorio").innerHTML="";
	}



function LevantaMarcaReporte()
{

  var TipoAccesorio=document.getElementById("Codigo").value;
  ajax=nuevoAjax();
  ajax.open("POST","/SICGNC/Cargas/Accesorios/Reportes/CargaMarca.php", true);
  ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{ 
              document.getElementById("fila_marca").innerHTML=ajax.responseText;
		    }
		}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   ajax.send("TipoAccesorio="+TipoAccesorio);
  
}




function ReporteCargarModeloPrototipo()
{

 var TipoAccesorio=document.getElementById("Codigo").value;
 var Marca=document.getElementById("Marca").value;
 var Fabricante=document.getElementById("Fabricante").value;
	if(Marca==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("Modelo");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="---Seleccionar---";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
	}
	else
	{
	//Marcas según tipo de dispositivo ********************************************************************
		ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/Reportes/CargaModelo.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				combo=document.getElementById("Modelo");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celda_modelo").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("TipoAccesorio="+TipoAccesorio+"&Marca="+Marca+"&Fabricante="+Fabricante);
	}
}


function ReporteCargarPrototipo()
{
		var Codigo=document.getElementById("Codigo").value;
		var Marca=document.getElementById("Marca").value;
		var Fabricante=document.getElementById("Fabricante").value;
		var Modelo=document.getElementById("Modelo").value;
		var OK=true;
		var Param;
		//alert(Codigo);
		 if(Marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red"; }else{ document.getElementById("celda_marca_color").style.color="black";}
		if(Codigo=="0"){OK=false; document.getElementById("celda_producto_color").style.color="red"; }else{ document.getElementById("celda_producto_color").style.color="black";}
		if(Fabricante=="0"){OK=false; document.getElementById("celda_Fabricante_color").style.color="red";}else{ document.getElementById("celda_Fabricante_color").style.color="black";}
		
		Param="Fabricante="+Fabricante+"&Marca="+Marca+"&Codigo="+Codigo+"&Modelo="+Modelo;
		//alert(Param);
		
	if(OK) {	
		
		ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/Reportes/DatosPrototipo.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4){
					 if(ajax.status==200){
						//alert(Param);
					document.getElementById("CaracteristicasAccesorio").innerHTML=ajax.responseText;
					//document.getElementById("Codigo").disabled=true;
					//document.getElementById("Marca").disabled=true;
					//document.getElementById("Fabricante").disabled=true;
					
							
										} 
									}
		} 
		
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(Param);
	
		
	} else {
		
		alert("Complete los campos en coloreados en rojo.");
		}
}




function EliminarDocPautas(Id,NombreArchivo,Fab,Marca,Modelo,Usuario,Codigo,Tipo){
/* tipo pueder ser 1 Pautas 2 folleto 3 Memoria 4 curva 5 manual inst 6 manual opera */

Param="Id="+Id+"&NombreArchivo="+NombreArchivo+"&Fab="+Fab+"&Marca="+Marca+"&Modelo="+Modelo+"&Usuario="+Usuario+"&Codigo="+Codigo+"&Tipo="+Tipo;
//alert(Param);
	if(confirm("¿Está seguro que desea eliminar el archivo?\n La eliminación será definitiva.")){
				
		ajax=nuevoAjax();
		ajax.open("POST", "BorrarDocumentosAccesorios.php", true);
		ajax.onreadystatechange=function(){ 
			if (ajax.readyState==4){	//alert(ajax.responseText);
			   document.getElementById("DocumentosAccesorios"+Tipo).innerHTML=ajax.responseText;
			}
	   }
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   ajax.send(Param); 		
	}
}
function HabilitarCargaDoc()
{
		var Codigo=document.getElementById("Codigo").value;
		var Modelo=document.getElementById("Modelo").value.toUpperCase( );
		if (!vacio(Modelo)) {
		//alert(Modelo);
		 if(Codigo!=110) {document.getElementById("Pautas").disabled=false;}
		document.getElementById("Modelo").value=Modelo
		document.getElementById("Modelo1").value=Modelo;
		document.getElementById("Modelo").disabled=true;
		if (Codigo==620) {	document.getElementById("Folleto").disabled=false;}
		if ((Codigo==430) || (Codigo==600) || (Codigo==200) || (Codigo==330) || (Codigo==400) || (Codigo==410)|| (Codigo==110) || (Codigo==120)) {	document.getElementById("Memoria").disabled=false;}
		if (Codigo==110) {	document.getElementById("CurvaCaudal").disabled=false;
							document.getElementById("ManualOper").disabled=false;
							document.getElementById("ManualInst").disabled=false;}
		
	} else { if(Codigo!=110){document.getElementById("Pautas").disabled=true;}
			if (Codigo==620) {document.getElementById("Folleto").disabled=true;}
			if ((Codigo==430) || (Codigo==600) || (Codigo==200) || (Codigo==330) || (Codigo==400) || (Codigo==410) || (Codigo==110) || (Codigo==120)) {	document.getElementById("Memoria").disabled=true;}
				if (Codigo==110) {	document.getElementById("CurvaCaudal").disabled=true;
									document.getElementById("ManualOper").disabled=true;
									document.getElementById("ManualInst").disabled=true;}
			}
}

function LevantaMarcaElem(TipoOp)
{
 //alert(TipoOp);
  var TipoAccesorio=document.getElementById("Codigo").value;
  ajax=nuevoAjax();
  ajax.open("POST","/SICGNC/Cargas/Accesorios/CargaMarca1.php", true);
  ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{ 
              document.getElementById("fila_marca").innerHTML=ajax.responseText;
		    }
		}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   ajax.send("TipoOp="+TipoOp+"&TipoAccesorio="+TipoAccesorio);
  
}




function CargarModeloPrototipo(TipoOp)
{// alert(TipoOp);

 var TipoAccesorio=document.getElementById("Codigo").value;
 var Marca=document.getElementById("Marca").value;
 var Fabricante=document.getElementById("Fabricante").value;
	if(Marca==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("Modelo");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="---Seleccionar---";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
	}
	else
	{
	//Marcas según tipo de dispositivo ********************************************************************
		ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/CargaModeloModificacion.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				combo=document.getElementById("Modelo");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celda_modelo").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("TipoAccesorio="+TipoAccesorio+"&Marca="+Marca+"&Fabricante="+Fabricante+"&TipoOp="+TipoOp);
	}
}

function CargarModificacionPrototipo()
{
		var Codigo=document.getElementById("Codigo").value;
		var Marca=document.getElementById("Marca").value;
		var Fabricante=document.getElementById("Fabricante").value;
		var Modelo=document.getElementById("Modelo").value;
		var OK=true;
		var Param;
		//alert(Codigo);
		 if(Marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red"; }else{ document.getElementById("celda_marca_color").style.color="black";}
		if(Codigo=="0"){OK=false; document.getElementById("celda_producto_color").style.color="red"; }else{ document.getElementById("celda_producto_color").style.color="black";}
		if(Fabricante=="0"){OK=false; document.getElementById("celda_Fabricante_color").style.color="red";}else{ document.getElementById("celda_Fabricante_color").style.color="black";}
		
		Param="Fabricante="+Fabricante+"&Marca="+Marca+"&Codigo="+Codigo+"&Modelo="+Modelo;
		//alert(Param);
		
	if(OK) {	
		
		ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/DatosModificacionPrototipo.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4){
					 if(ajax.status==200){
						//alert(Param);
					document.getElementById("CaracteristicasAccesorio").innerHTML=ajax.responseText;
					document.getElementById("Codigo").disabled=true;
					//document.getElementById("Marca").disabled=true;
					document.getElementById("Fabricante").disabled=true;
					
							
										} 
									}
		} 
		
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(Param);
	
		
	} else {
		
		alert("Complete los campos en coloreados en rojo.");
		}
}




function CargarModificacionLote()
{
		var Codigo=document.getElementById("Codigo").value;
		var Marca=document.getElementById("Marca").value;
		var Fabricante=document.getElementById("Fabricante").value;
		var Modelo=document.getElementById("Modelo").value;
		var OK=true;
		var Param;
		//alert(Codigo);
		 if(Marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red"; }else{ document.getElementById("celda_marca_color").style.color="black";}
		if(Codigo=="0"){OK=false; document.getElementById("celda_producto_color").style.color="red"; }else{ document.getElementById("celda_producto_color").style.color="black";}
		if(Fabricante=="0"){OK=false; document.getElementById("celda_Fabricante_color").style.color="red";}else{ document.getElementById("celda_Fabricante_color").style.color="black";}
		
		Param="Fabricante="+Fabricante+"&Marca="+Marca+"&Codigo="+Codigo+"&Modelo="+Modelo;
		//alert(Param);
		
	if(OK) {	
		
		ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/DatosModificacionLotes.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4){
					 if(ajax.status==200){
						//alert(Param);
					document.getElementById("CaracteristicasAccesorio").innerHTML=ajax.responseText;
					//document.getElementById("Codigo").disabled=true;
					//document.getElementById("Marca").disabled=true;
					//document.getElementById("Fabricante").disabled=true;
					
							
										} 
									}
		} 
		
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(Param);
	
		
	} else {
		
		alert("Complete los campos en coloreados en rojo.");
		}
}




function AltaLoteElementosCertificados(TipoDispositivo)
{
 var FechaAprobacion=document.getElementById("FechaAprobacion");
 var NroCertificado=document.getElementById("NroCertificado").value;
var Marca=document.getElementById("Marca").value;
 var Fabricante=document.getElementById("Fabricante").value;
/* if((TipoDispositivo!=100) && (TipoDispositivo!=200)&&(TipoDispositivo!=410) )	{
 var Modelo=document.getElementById("Modelo").value;
 //alert(Modelo);
 }*/ // se comenta porque todos los componentes ahora tienen CID
 var Desde=document.getElementById("Desde").value;
 var Hasta=document.getElementById("Hasta").value;
 var Cantidad=document.getElementById("Cantidad").value;
 var OK= true;
 var OK_FormatNroSerie=true; 
 
 if(valFecha(FechaAprobacion)){OK=false; document.getElementById("celda_FechaAprobacion").style.color="red";}else{ document.getElementById("celda_FechaAprobacion").style.color="black";}
 if(vacio(NroCertificado)){OK=false; document.getElementById("celda_nroCertificado").style.color="red";}else{ document.getElementById("celda_nroCertificado").style.color="black";}
 if(Marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red";}else{ document.getElementById("celda_marca_color").style.color="black";}
 if(vacio(Cantidad)){OK=false; document.getElementById("celda_Cantidad").style.color="red";}else{ document.getElementById("celda_Cantidad").style.color="black";}
var Param;





Param="TipoDispositivo="+TipoDispositivo+"&FechaAprobacion="+FechaAprobacion.value+"&NroCertificado="+NroCertificado+"&Desde="+Desde+"&Hasta="+Hasta+"&Cantidad="+Cantidad+"&Marca="+Marca+"&Fabricante="+Fabricante;
//alert (Param);
//if((TipoDispositivo==100) || (TipoDispositivo==200)||(TipoDispositivo==410) ){
	 var NroCodigoHomologado_aux=document.getElementById("CodHomolog").value;
	 var NroCodigoHomologado=NroCodigoHomologado_aux.split(";"); 
	var Modelo=NroCodigoHomologado[2];
	Param=Param+"&HomologCode="+NroCodigoHomologado[0];
	
	
	 if(NroCodigoHomologado[0]=="0")
	   {
		OK=false; 
		document.getElementById("celda_CodHomologado_color").style.color="red";
		}
	 else{ 
		  document.getElementById("celda_CodHomologado_color").style.color="black";
		  var FormatNroSerie=NroCodigoHomologado[1];
		  if (vacio(FormatNroSerie))
			   {
			 OK_FormatNroSerie=false;
			   document.getElementById("celda_Desde").style.color="red";
				  document.getElementById("celda_Hasta").style.color="red";
			   }
		  else{
			   var patron =FormatNroSerie;	
			   //alert(Hasta.search(patron));
	 			//alert(patron);
			   if((Desde.search(patron)) || (Hasta.search(patron))) 
				 {
					 OK_FormatNroSerie=false;
				  document.getElementById("celda_Desde").style.color="red";
				  document.getElementById("celda_Hasta").style.color="red";
				 }	 
			   else 
				  {
				   document.getElementById("celda_Desde").style.color="black";   
				   document.getElementById("celda_Hasta").style.color="black";   
				  }
			  }
	 	 }	  
//}

Param=Param+"&Modelo="+Modelo;
//alert(Param);
if (OK && OK_FormatNroSerie)
  {
   if(confirm("¿Está seguro de los datos a dar de Cargar?"))
	 {
      ajax=nuevoAjax();
      ajax.open("POST", "/SICGNC/Cargas/Accesorios/A_LoteDispositivo.php", true);
      ajax.onreadystatechange=function() 
       { 
	    if (ajax.readyState==1)
	     {
		  document.getElementById("AltaElementos").innerHTML="<br><br><img  src='../../Images/progress2.gif'>";
		 }
	   if (ajax.readyState==4)
        { 
	      document.getElementById("AltaElementos").innerHTML=ajax.responseText;
	    } 
	 }
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send(Param);
   }	
  }
  else
    {
	 if(!OK)
	  alert("Verifique los campos en rojo");
	 if(!OK_FormatNroSerie)
	   alert("Formato de Nro de Serie no se corresponde o todavía no fue dado de Alta"); 
	}

}


function SoloNumComa(nume,celda)
{ 
//alert(nume);
var nums = "0123456789."; 
//nume=nume.value;
nume = document.getElementById(celda); 
cadena = nume.value; 
//alert (cadena);
numCars = cadena.length; 
ultimo = cadena.charAt(numCars-1); 
if (nums.indexOf(ultimo) < 0) { 
nume.value = cadena.substr(0,numCars-1); 
} 
}

function SoloNum(nume,celda)
{ 
//alert(nume);
var nums = "0123456789"; 
//nume=nume.value;
nume = document.getElementById(celda); 
cadena = nume.value; 
//alert (cadena);
numCars = cadena.length; 
ultimo = cadena.charAt(numCars-1); 
if (nums.indexOf(ultimo) < 0) { 
nume.value = cadena.substr(0,numCars-1); 
} 
}

function ModificarLoteElementosCertificados(TipoDispositivo,FechaApAnt,CertificadoAnt,DesdeAnt,HastaAnt)
{
 var FechaAprobacion=document.getElementById("FechaAprobacion");
 var NroCertificado=document.getElementById("NroCertificado").value;
var Marca=document.getElementById("Marca").value;
 var Fabricante=document.getElementById("Fabricante").value;
 var Modelo=document.getElementById("Modelo").value;
 var Desde=document.getElementById("Desde").value;
 var Hasta=document.getElementById("Hasta").value;
 var Cantidad=document.getElementById("Cantidad").value;
  var Causa=document.getElementById("Causa").value;
 var OK= true;
 var OK_FormatNroSerie=true; 
 
 if(valFecha(FechaAprobacion)){OK=false; document.getElementById("celda_FechaAprobacion").style.color="red";}else{ document.getElementById("celda_FechaAprobacion").style.color="black";}
 if(vacio(NroCertificado)){OK=false; document.getElementById("celda_nroCertificado").style.color="red";}else{ document.getElementById("celda_nroCertificado").style.color="black";}
 if(Marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red";}else{ document.getElementById("celda_marca_color").style.color="black";}
 if(vacio(Cantidad)){OK=false; document.getElementById("celda_Cantidad").style.color="red";}else{ document.getElementById("celda_Cantidad").style.color="black";}
var Param;





Param="TipoDispositivo="+TipoDispositivo+"&FechaAprobacion="+FechaAprobacion.value+"&NroCertificado="+NroCertificado+"&Desde="+Desde+"&Hasta="+Hasta+"&Cantidad="+Cantidad+"&Marca="+Marca+"&Fabricante="+Fabricante+"&Modelo="+Modelo+"&FechaApAnt="+FechaApAnt+"&NroCertificadoAnt="+CertificadoAnt+"&DesdeAnt="+DesdeAnt+"&HastaAnt="+HastaAnt+"&Causa="+Causa;
//alert (Param);
if((TipoDispositivo==100) || (TipoDispositivo==200)||(TipoDispositivo==410) )	
{
	 var NroCodigoHomologado=document.getElementById("CodHomolog").value;
	
	//alert(FormatNroSerie);
	Param=Param+"&HomologCode="+NroCodigoHomologado;
	
	 if(NroCodigoHomologado=="0")
	   {
		OK=false; 
		document.getElementById("celda_CodHomologado_color").style.color="red";
		}
	 else{ 
		  document.getElementById("celda_CodHomologado_color").style.color="black";
		   var FormatNroSerie=document.getElementById("FormatoSerie").value;
		  if (vacio(FormatNroSerie))
			   {
			 OK_FormatNroSerie=false;
			   document.getElementById("celda_Desde").style.color="red";
			   document.getElementById("celda_Hasta").style.color="red";
			   }
		  else{
			    //alert(Hasta.search(FormatNroSerie));
	 			//alert(patron);
			   if((Desde.search(FormatNroSerie)) || (Hasta.search(FormatNroSerie))) 
				 {
					 OK_FormatNroSerie=false;
				  document.getElementById("celda_Desde").style.color="red";
				  document.getElementById("celda_Hasta").style.color="red";
				 }	 
			   else 
				  {
				   document.getElementById("celda_Desde").style.color="black";   
				   document.getElementById("celda_Hasta").style.color="black";   
				  }
			  }
	 	 }	  
}



if (OK && OK_FormatNroSerie)
  {
   if(confirm("¿Está seguro de los datos a dar de Cargar?"))
	 {
      ajax=nuevoAjax();
      ajax.open("POST", "/SICGNC/Cargas/Accesorios/M_LoteDispositivo.php", true);
      ajax.onreadystatechange=function() 
       { 
	    if (ajax.readyState==1)
	     {
		  document.getElementById("ModificacionLote").innerHTML="<br><br><img  src='../../Images/progress2.gif'>";
		 }
	   if (ajax.readyState==4)
        { 
	      document.getElementById("ModificacionLote").innerHTML=ajax.responseText;
	    } 
	 }
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send(Param);
   }	
  }
  else
    {
	 if(!OK)
	  alert("Verifique los campos en rojo");
	 if(!OK_FormatNroSerie)
	   alert("Formato de Nro de Serie no se corresponde o todavía no fue dado de Alta"); 
	}

}




function DetalleLoteAModificar(marca,modelo,tipoacc,fab,certificado,codigo,desde,hasta)
{


 ajax=nuevoAjax();
ajax.open("GET", "/SICGNC/Cargas/Accesorios/ModificarLotes.php?Marca="+marca+"&Modelo="+modelo+"&TipoAcc="+tipoacc+"&Fab="+fab+"&Certificado="+certificado+"&Codigo="+codigo+"&Desde="+desde+"&Hasta="+hasta,true);
  ajax.onreadystatechange=function() 
	{ 
	if (ajax.readyState==1)
		    {
			 document.getElementById("CaracteristicasAccesorio").innerHTML="<br><br><img  src='../../Images/progress2.gif'>";
			}
	if (ajax.readyState==4)
		{ 
		document.getElementById("CaracteristicasAccesorio").innerHTML=ajax.responseText;
		} 
	}
	ajax.send(null);

	}

function CargarBaja() 
{
	
var tipo=document.getElementById("Estado").value;
Param="tipo="+tipo;
		 ajax=nuevoAjax();
		 ajax.open("POST", "/SICGNC/Cargas/Accesorios/CargarBajaCertificado.php",true);
		 ajax.onreadystatechange=function() 
	   	{
			
		document.getElementById('id_Baja').innerHTML="<br><br><img  src='../../Images/progress2.gif'>";
		
		  if (ajax.readyState==4) {
			       if(ajax.status==200) {
					//alert(Param);
					     document.getElementById('id_Baja').innerHTML=ajax.responseText;
			     			           }
								  }
	  	 }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(Param);
}  








function CargarFormularioElementos()
{
		//var tipo=document.getElementById("TCert").options[document.getElementById("TCert").selectedIndex].value;
		//var Codigo=document.getElementById("Codigo").options[document.getElementById("Codigo").selectedIndex].value;
		
		
		var Organismo=document.getElementById("Organismo").value;
		var tipo=document.getElementById("TCert").value;
		var Codigo=document.getElementById("Codigo").value;
		var Marca=document.getElementById("Marca").value;
		var Fabricante=document.getElementById("Fabricante").value;
		var OK=true;
		var Param;
		//alert(Codigo);
		 if(Marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red"; }else{ document.getElementById("celda_marca_color").style.color="black";}
		if(Codigo=="0"){OK=false; document.getElementById("celda_producto_color").style.color="red"; }else{ document.getElementById("celda_producto_color").style.color="black";}
		if(Fabricante=="0"){OK=false; document.getElementById("celda_Fabricante_color").style.color="red";}else{ document.getElementById("celda_Fabricante_color").style.color="black";}
		/*if(tipo==1){
		if(vacio(Modelo)){OK=false; document.getElementById("celda_Modelo_color").style.color="red";}else{ document.getElementById("celda_Modelo_color").style.color="black";}
		}*/
		Param="tipo="+tipo+"&Codigo="+Codigo+"&Marca="+Marca+"&Fabricante="+Fabricante;
		//alert(Param);
		
	if(OK) {	
		
		ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/FormularioElementos.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4){
				if(ajax.status==200){
		
					document.getElementById("CaracteristicasAccesorio").innerHTML=ajax.responseText;
					document.getElementById("Codigo").disabled=true;
					//document.getElementById("Marca").disabled=true;
					document.getElementById("Fabricante").disabled=true;
					
				if(tipo==2 )	
					 {
					// if((Codigo==100) || (Codigo==200)||(Codigo==410) )	 {
							ValidarCodigo(Codigo,Organismo);// } else {ValidarModelo(Codigo);		}
					}
								
					
					
										} 
									}
		} 
		
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(Param);
	
		
	} else {
		
		alert("Complete los campos en coloreados en rojo.");
		}
}

function ValidarCodigo(TipoComponente,Organismo)
{
	var valor=document.getElementById("Marca").options[document.getElementById("Marca").selectedIndex].value;
	//alert(valor+"----"+TipoComponente);
	if(valor==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("CodHomolog");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="---Seleccionar---";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
	}
	else
	{
	//Código de Homologación según la marca y el tipo de componente
	    ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/CargarCodHomolog.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				combo=document.getElementById("CodHomolog");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celda_CodHomologado").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("TipoComponente="+TipoComponente+"&Marca="+valor+"&Organismo="+Organismo);	
	}

}

function ValidarModelo(TipoComponente)
{
	var valor=document.getElementById("Marca").options[document.getElementById("Marca").selectedIndex].value;
	//alert(valor+"----"+TipoComponente);
	if(valor==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("Modelo");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="---Seleccionar---";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
	}
	else
	{
	//Código de Homologación según la marca y el tipo de componente
	    ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/CargarModelo.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				combo=document.getElementById("Modelo");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celda_Modelo").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("TipoComponente="+TipoComponente+"&Marca="+valor);	
	}

}

////Levanta los modelos que todavía no tienen un código de homologación asignado/////////
function ModeloLibre()
{ 
 var TipoAccesorio=document.getElementById("Accesorio").value;
 var Marca=document.getElementById("Marca").value;
	if(Marca==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("Modelo");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="---Seleccionar---";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
	}
	else
	{
	//Marcas según tipo de dispositivo ********************************************************************
		ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/CargaModeloSinCodigo.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				combo=document.getElementById("Modelo");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celda_modelo").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("TipoAccesorio="+TipoAccesorio+"&Marca="+Marca);
	}
}

function ValidaCargaCodigoElem(TipoAccesorio)
{
/*Esta función carga un accesorio homologado*/
/*A partir de aquí están las variables comunes a todos los accesorios*/
 var HomologCode=document.getElementById("Codigo").value.toUpperCase( );
 var MarcaCode=document.getElementById("Marca").value;
 var Modelo=document.getElementById("Modelo").value.toUpperCase( );
 var OrgCode=document.getElementById("Organismo1").value;
 var FechaCertificacion=document.getElementById("FechaCertificacion");
 var MatriculaFabImp=document.getElementById("FaboImportador").value;
/*****************************************************************/
				
   if (!vacio(HomologCode) && (MarcaCode!=0) && !vacio(Modelo) && !valFecha(FechaCertificacion)){

	var Param;
	Param="Modelo="+Modelo+"&Codigo="+HomologCode+"&Marca="+MarcaCode+"&Organismo="+OrgCode+"&FechaCertificacion="+FechaCertificacion.value+"&FaboImportador="+MatriculaFabImp+"&Accesorio="+TipoAccesorio;
	//alert(Param)
	 ajax=nuevoAjax();
				  ajax.open("POST", "/SICGNC/Cargas/Accesorios/CargaAccesorios.php",true);
                   ajax.onreadystatechange=function() 
                    { 
                    if (ajax.readyState==4)
		              { 
		              document.getElementById("CaracteristicasAccesorio").innerHTML=ajax.responseText;
		              } 
	                }
	               ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	               ajax.send(Param);	
  }
  else
    {
		   alert ("La fecha o el código de homologación son erróneos");
				   }  
 


}



function MostrarDatosElementosSinCod(TipoAcc)
{
 var Marca=document.getElementById("Marca").value;
 var Modelo=document.getElementById("Modelo").value;
 if (vacio(Marca) || vacio(Modelo))
  {
   alert ("Faltan Datos");
  } 
  else
    {
 	ajax=nuevoAjax();
 	ajax.open("POST", "/SICGNC/Cargas/Accesorios/MostrarDatosElementosSinCodigo.php", true);
 	ajax.onreadystatechange=function() 
		{ 
		 if (ajax.readyState==4)
		   { 
			document.getElementById("CaracteristicasAccesorio").innerHTML=ajax.responseText;
		   } 
		}
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   ajax.send("Marca="+Marca+"&Modelo="+Modelo+"&TipoAcc="+TipoAcc);
	 }  
}



function AltaPrototipo() 
{
	
	
var NCertificado=document.getElementById("NCertificado").value;
var Matricula=document.getElementById("Matricula").value;
var FEmision=document.getElementById("FEmision").value;
var FVencimiento=document.getElementById("FVencimiento").value;
var Observacion=document.getElementById("Observacion").value;
var Componente=document.getElementById("Codigo").value;
var Fabricante=document.getElementById("Fabricante").value;
var Marca=document.getElementById("Marca").value;
var Modelo=document.getElementById("Modelo").value;
 var FormatoSerie=document.getElementById("FormatoSerie").value; 
var OK=true;

/*if(vacio(NCertificado)){OK=false; document.getElementById("celda_NCertificado_color").style.color="red";}else{ document.getElementById("celda_NCertificado_color").style.color="black";}
  if(vacio(Matricula)){OK=false; document.getElementById("celda_Matricula_color").style.color="red";}else{ document.getElementById("celda_Matricula_color").style.color="black";}

  if(vacio(FEmision)){OK=false; document.getElementById("celda_FEmision_color").style.color="red";}else{ document.getElementById("celda_FEmision_color").style.color="black";}
  if(vacio(FVencimiento)){OK=false; document.getElementById("celda_FVencimiento_color").style.color="red";}else{ document.getElementById("celda_FVencimiento_color").style.color="black";}
*/
  if(vacio(Modelo)){OK=false; document.getElementById("celda_Modelo_color").style.color="red";}else{ document.getElementById("celda_Modelo_color").style.color="black";}
if(FormatoSerie==0){OK=false; document.getElementById("celda_ForSerie").style.color="red";}else{ document.getElementById("celda_ForSerie").style.color="black";}	
Param="NCertificado="+NCertificado+"&Matricula="+Matricula+"&FEmision="+FEmision+"&FVencimiento="+FVencimiento+"&Observacion="+Observacion+"&Componente="+Componente+"&Fabricante="+Fabricante+"&Marca="+Marca+"&Modelo="+Modelo+"&FormatoSerie="+FormatoSerie;

//alert(Param);
 switch(Componente)
  {
    case '100':  var Capacidad=document.getElementById("Capacidad").value;
	             var NormaFab=document.getElementById("NormaFab").value;
				 var Diametro=document.getElementById("Diametro").value;
				 var Espesor=document.getElementById("Espesor").value;
				 var DurezaMin=document.getElementById("DurezaMin").value;
				 var DurezaMax=document.getElementById("DurezaMax").value;
				 var Longitud=document.getElementById("Longitud").value;
				 //var TipoRosca=document.getElementById("TipoRosca").value; 
				 
				 var Ansi=CheckToBit(document.getElementById("ansi"));
				 var Din=CheckToBit(document.getElementById("din"));
				 var Uni=CheckToBit(document.getElementById("uni"));
				 var Bs=CheckToBit(document.getElementById("bs"));
				 var Iram=CheckToBit(document.getElementById("iram"));
				 var Iso10=CheckToBit(document.getElementById("iso10"));
				 var Iso15=CheckToBit(document.getElementById("iso15"));
				 var Ngt=CheckToBit(document.getElementById("ngt"));
				 
				 
				 var Duracion=document.getElementById("Duracion").value;
				 var Material=document.getElementById("Material").value; 	
				 var Utilizacion=document.getElementById("Utilizacion").value;
				 var Tipo=document.getElementById("Tipo").value; 
				  var PresionTrabajo=document.getElementById("PresionTrabajo").value; 
			/*	 var Pautas=document.getElementById("Pautas").value; 
				
				 
		 
if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}*/
				 
							  
				
Param=Param+"&Capacidad="+Capacidad+"&NormaFab="+NormaFab+"&Diametro="+Diametro+"&Espesor="+Espesor+"&DurezaMin="+DurezaMin+"&Longitud="+Longitud+"&Duracion="+Duracion+"&Material="+Material+"&Utilizacion="+Utilizacion+"&Tipo="+Tipo+"&PresionTrabajo="+PresionTrabajo+"&DurezaMax="+DurezaMax+"&Ansi="+Ansi+"&Din="+Din+"&Uni="+Uni+"&Bs="+Bs+"&Iram="+Iram+"&Iso10="+Iso10+"&Iso15="+Iso15+"&Ngt="+Ngt;
      //alert (Param);        
   break;
   
   case '110':  var Etapas=document.getElementById("Etapas").value;
	             var NormaFab=document.getElementById("NormaFab").value;
				 var PresionMax=document.getElementById("PresionMax").value;
				 var PresionMin=document.getElementById("PresionMin").value;
				 var PresionDescarga=document.getElementById("PresionDescarga").value;
				 var TemperaturaSalida=document.getElementById("TemperaturaSalida1").value;
				 var TemperaturaSalida2=document.getElementById("TemperaturaSalida2").value;
				 var TemperaturaSalida3=document.getElementById("TemperaturaSalida3").value;
				 var TemperaturaSalida4=document.getElementById("TemperaturaSalida4").value;
				 var TemperaturaDescarga=document.getElementById("TemperaturaDescarga").value; 
				 var TElectrico=document.getElementById("TElectrico").value;
				 var TCombustion=document.getElementById("TCombustion").value; 	
				 var Potencia=document.getElementById("Potencia").value;
				/*var CurvaCaudal=document.getElementById("CurvaCaudal").value; 
				var Memoria=document.getElementById("Memoria").value; 
				var ManualInst=document.getElementById("ManualInst").value; 
				var ManualOper=document.getElementById("ManualOper").value;*/ 
				var AlmacenamientoIncorp=document.getElementById("AlmacenamientoIncorp").value;
				 var Cabina=document.getElementById("Cabina").value; 	
				 var PuenteM=document.getElementById("PuenteM").value;
				  var Pulmon=document.getElementById("Pulmon").value;
				
			
/*if(vacio(CurvaCaudal)){OK=false; document.getElementById("Celda_CurvaCaudal").style.color="red";}else{ document.getElementById("Celda_CurvaCaudal").style.color="black";}				
 if(vacio(Memoria)){OK=false; document.getElementById("Celda_Memoria").style.color="red";}else{ document.getElementById("Celda_Memoria").style.color="black";}
  if(vacio(ManualInst)){OK=false; document.getElementById("Celda_ManualInst").style.color="red";}else{ document.getElementById("Celda_ManualInst").style.color="black";}	
  if(vacio(ManualOper)){OK=false; document.getElementById("Celda_ManualOper").style.color="red";}else{ document.getElementById("Celda_ManualOper").style.color="black";}			*/					  
				
Param=Param+"&Etapas="+Etapas+"&NormaFab="+NormaFab+"&PresionMax="+PresionMax+"&PresionMin="+PresionMin+"&PresionDescarga="+PresionDescarga+"&TemperaturaSalida="+TemperaturaSalida+"&TemperaturaDescarga="+TemperaturaDescarga+"&TElectrico="+TElectrico+"&TCombustion="+TCombustion+"&Potencia="+Potencia+"&AlmacenamientoIncorp="+AlmacenamientoIncorp+"&Cabina="+Cabina+"&PuenteM="+PuenteM+"&Pulmon="+Pulmon+"&TemperaturaSalida2="+TemperaturaSalida2+"&TemperaturaSalida3="+TemperaturaSalida3+"&TemperaturaSalida4="+TemperaturaSalida4;
      //alert (Param);        
   break;   
   
   case '120':   var NormaFab=document.getElementById("NormaFab").value;
				 var Presion1=document.getElementById("Presion1").value;
				 var Presion2=document.getElementById("Presion2").value;
				 var Error=document.getElementById("Error").value;
				 var Especificacion=document.getElementById("Especificacion").value;
				/* var Memoria=document.getElementById("Memoria").value; 
				 var Pautas=document.getElementById("Pautas").value; 
				 
if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
 if(vacio(Memoria)){OK=false; document.getElementById("Celda_Memoria").style.color="red";}else{ document.getElementById("Celda_Memoria").style.color="black";}			*/	
				 
							  
				
Param=Param+"&NormaFab="+NormaFab+"&Presion1="+Presion1+"&Presion2="+Presion2+"&Error="+Error+"&Especificacion="+Especificacion;
      //alert (Param);        
   break;
   
   
   case '200': var NormaFab=document.getElementById("NormaFab").value;
   			   var Caudal=document.getElementById("Caudal").value;
   			   var Tipo=document.getElementById("Tipo").value;
			   var Etapas=document.getElementById("Etapas").value;
			   //var Motor=document.getElementById("Motor").value;  	
			   var CilindradaMax=CheckToBit(document.getElementById("CilindradaMax"));
			   var CilindradaMin=CheckToBit(document.getElementById("CilindradaMin"));
			   var Naftero=CheckToBit(document.getElementById("Naftero"));
			   var Diesel=CheckToBit(document.getElementById("Diesel"));
			   var Motocicleta=CheckToBit(document.getElementById("Motocicleta"));
			   var OtrosM=CheckToBit(document.getElementById("OtrosM"));
			   
			   var ConexionEntrada=document.getElementById("ConexionEntrada").value; 
			   var ConexionSalida=document.getElementById("ConexionSalida").value;
			  // var Memoria=document.getElementById("Memoria").value; 
			   //var Pautas=document.getElementById("Pautas").value; 
			  // var FormatoSerie=document.getElementById("FormatoSerie").value; 
				 
//if(FormatoSerie==0){OK=false; document.getElementById("celda_ForSerie").style.color="red";}else{ document.getElementById("celda_ForSerie").style.color="black";}		
				 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
 //if(vacio(Memoria)){OK=false; document.getElementById("Celda_Memoria").style.color="red";}else{ document.getElementById("Celda_Memoria").style.color="black";} 
				
				Param=Param+"&NormaFab="+NormaFab+"&Caudal="+Caudal+"&Tipo="+Tipo+"&Etapas="+Etapas+"&CilindradaMax="+CilindradaMax+"&ConexionEntrada="+ConexionEntrada+"&ConexionSalida="+ConexionSalida+"&CilindradaMin="+CilindradaMin+"&Naftero="+Naftero+"&Diesel="+Diesel+"&Motocicleta="+Motocicleta+"&OtrosM="+OtrosM;
  //  alert(Param);

    break;
  case '310':  var NormaFab=document.getElementById("NormaFab").value;
  			   var Diametro=document.getElementById("Diametro").value;
               var DispositivoSuje=document.getElementById("DispositivoSuje").value;
			   var Distancia=document.getElementById("Distancia").value;
			   var DiametroExterno=document.getElementById("DiametroExterno").value;
               var EspecificacionConector=document.getElementById("EspecificacionConector").value;
			  // var Pautas=document.getElementById("Pautas").value; 
				 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
				
	               Param=Param+"&NormaFab="+NormaFab+"&Diametro="+Diametro+"&DispositivoSuje="+DispositivoSuje+"&Distancia="+Distancia+"&DiametroExterno="+DiametroExterno+"&EspecificacionConector="+EspecificacionConector;
				 
  break;
  
  case '410':
  				var NormaFab=document.getElementById("NormaFab").value;
				var ConexionCilindro=document.getElementById("ConexionCilindro").value;
			 	var PresionServicio=document.getElementById("PresionServicio").value;
			 	var Material=document.getElementById("Material").value;
			 	var TiposValvula=document.getElementById("TiposValvula").value;
			 	var OtraConexion=document.getElementById("OtraConexion").value;
			 	var EspecificacionRosca=document.getElementById("EspecificacionRosca").value;
			 	var Torque=document.getElementById("Torque").value;
			 	//var Memoria=document.getElementById("Memoria").value; 
				//var Pautas=document.getElementById("Pautas").value; 
				//var FormatoSerie=document.getElementById("FormatoSerie").value; 
				 
//	if(FormatoSerie==0){OK=false; document.getElementById("celda_ForSerie").style.color="red";}else{ document.getElementById("celda_ForSerie").style.color="black";}		
				 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
// if(vacio(Memoria)){OK=false; document.getElementById("Celda_Memoria").style.color="red";}else{ document.getElementById("Celda_Memoria").style.color="black";} 
			 Param=Param+"&ConexionCilindro="+ConexionCilindro+"&PresionServicio="+PresionServicio+"&Material="+Material+"&TiposValvula="+TiposValvula+"&OtraConexion="+OtraConexion+"&EspecificacionRosca="+EspecificacionRosca+"&Torque="+Torque+"&NormaFab="+NormaFab;
		//	 alert(Param);

  break;
   case '300':  var NormaFab=document.getElementById("NormaFab").value;
               var RadioCurvatura=document.getElementById("RadioCurvatura").value;
			   
			   var DiametroInt=document.getElementById("DiametroInt").value;
               var DiametroExt=document.getElementById("DiametroExt").value;
			   var DispositivoSuje=document.getElementById("DispositivoSuje").value;
              
			 //   var Pautas=document.getElementById("Pautas").value; 
					 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
				      
				Param=Param+"&NormaFab="+NormaFab+"&RadioCurvatura="+RadioCurvatura+"&DiametroInt="+DiametroInt+"&DiametroExt="+DiametroExt+"&DispositivoSuje="+DispositivoSuje;
				 
  break;
  
   case '320':  var NormaFab=document.getElementById("NormaFab").value;
               var RadioCurvatura=document.getElementById("RadioCurvatura").value;
			   
			   var DiametroInt=document.getElementById("DiametroInt").value;
               var DiametroExt=document.getElementById("DiametroExt").value;
			   var Caracteristicas=document.getElementById("Caracteristicas").value;
              
			   // var Pautas=document.getElementById("Pautas").value; 
					 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
				      
				Param=Param+"&NormaFab="+NormaFab+"&RadioCurvatura="+RadioCurvatura+"&DiametroInt="+DiametroInt+"&DiametroExt="+DiametroExt+"&Caracteristicas="+Caracteristicas;
				 
  break;
  
  
    case '330': var NormaFab=document.getElementById("NormaFab").value;
				var DiametroBoquilla=document.getElementById("DiametroBoquilla").value;
                var DiametroConducto=document.getElementById("DiametroConducto").value;
				var Memoria=document.getElementById("Memoria").value; 
				 var Pautas=document.getElementById("Pautas").value; 
				 var LargoConducto=document.getElementById("LargoConducto").value;
                var AccesoriosSujecion=document.getElementById("AccesoriosSujecion").value;
				 
if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
 if(vacio(Memoria)){OK=false; document.getElementById("Celda_Memoria").style.color="red";}else{ document.getElementById("Celda_Memoria").style.color="black";} 
			 Param=Param+"&ConexionCilindro="+ConexionCilindro+"&PresionServicio="+PresionServicio+"&Material="+Material+"&TiposValvula="+TiposValvula+"&OtraConexion="+OtraConexion+"&EspecificacionRosca="+EspecificacionRosca+"&Torque="+Torque+"&NormaFab="+NormaFab;
				Param=Param+"&NormaFab="+NormaFab+"&DiametroBoquilla="+DiametroBoquilla+"&DiametroConducto="+DiametroConducto+"&LargoConducto="+LargoConducto+"&AccesoriosSujecion="+AccesoriosSujecion;
				 
  break;
   

  /* accesorios para conexion de tuberia alta presion*/
   case '340': var NormaFab=document.getElementById("NormaFab").value;
				var EspecificacionRosca=document.getElementById("EspecificacionRosca").value;
                var DiametroTuberia=document.getElementById("DiametroTuberia").value;
				var LongitudNiple=document.getElementById("LongitudNiple").value;
                var PresionTrabajo=document.getElementById("PresionTrabajo").value;
				var Tipo=document.getElementById("Tipo").value;
                var TratamientoCuerpo=document.getElementById("TratamientoCuerpo").value;
				var TratamientoRosca=document.getElementById("TratamientoRosca").value;
                var TratamientoVirola=document.getElementById("TratamientoVirola").value;
				var TratamientoTapon=document.getElementById("TratamientoTapon").value;
                var TratamientoTuerca=document.getElementById("TratamientoTuerca").value;
				
			//	var Memoria=document.getElementById("Memoria").value; 
				// var Pautas=document.getElementById("Pautas").value; 
				
/*				 
if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
 if(vacio(Memoria)){OK=false; document.getElementById("Celda_Memoria").style.color="red";}else{ document.getElementById("Celda_Memoria").style.color="black";} */
			 Param=Param+"&NormaFab="+NormaFab+"&EspecificacionRosca="+EspecificacionRosca+"&DiametroTuberia="+DiametroTuberia+"&LongitudNiple="+LongitudNiple+"&PresionTrabajo="+PresionTrabajo+"&Tipo="+Tipo+"&TratamientoCuerpo="+TratamientoCuerpo+"&TratamientoRosca="+TratamientoRosca+"&TratamientoVirola="+TratamientoVirola+"&TratamientoTapon="+TratamientoTapon+"&TratamientoTuerca="+TratamientoTuerca;
			
				 
  break;

  case '400':  var NormaFab=document.getElementById("NormaFab").value;
               var EspecificacionConexion=document.getElementById("EspecificacionConexion").value;
			   var EspecificacionInterconexion=document.getElementById("EspecificacionInterconexion").value;
			  // var Memoria=document.getElementById("Memoria").value; 
			//	var Pautas=document.getElementById("Pautas").value; 
				 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
// if(vacio(Memoria)){OK=false; document.getElementById("Celda_Memoria").style.color="red";}else{ document.getElementById("Celda_Memoria").style.color="black";} 
			         
				Param=Param+"&NormaFab="+NormaFab+"&EspecificacionConexion="+EspecificacionConexion+"&EspecificacionInterconexion="+EspecificacionInterconexion;
				 
  break;                 
  case '420':  
               var PresionServicio=document.getElementById("PresionServicio").value;
			   var Material=document.getElementById("Material").value;
			   var DispositivoSeguridad=document.getElementById("DispositivoSeguridad").value;
			   
				      
				Param=Param+"&PresionServicio="+PresionServicio+"&Material="+Material+"&DispositivoSeguridad="+DispositivoSeguridad;
				 
  break;                 
  case '430':   var NormaFab=document.getElementById("NormaFab").value;
  				var TensionTrabajo=document.getElementById("TensionTrabajo").value;
              	var PresionTrabajo=document.getElementById("PresionServicio").value;
			    var Rosca=document.getElementById("Rosca").value;
			    var Diametro=document.getElementById("Diametro").value;
			    var Potencia=document.getElementById("Potencia").value;
			    var TipoElecrtoValvula=document.getElementById("TipoElecrtoValvula").value;	
			//	var Memoria=document.getElementById("Memoria").value; 
			//	 var Pautas=document.getElementById("Pautas").value; 
				 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
// if(vacio(Memoria)){OK=false; document.getElementById("Celda_Memoria").style.color="red";}else{ document.getElementById("Celda_Memoria").style.color="black";} 		      
				Param=Param+"&TensionTrabajo="+TensionTrabajo+"&PresionTrabajo="+PresionTrabajo+"&Rosca="+Rosca+"&Diametro="+Diametro+"&Potencia="+Potencia+"&TipoElecrtoValvula="+TipoElecrtoValvula+"&NormaFab="+NormaFab;
				 
  break;    
  case '440':    var TesionTrabajo=document.getElementById("TensionTrabajo").value;
               var PresionServicio=document.getElementById("PresionServicio").value;
			   var Material=document.getElementById("Material").value;
			   var Diametro=document.getElementById("Diametro").value;
			   var Potencia=document.getElementById("Potencia").value;
			   				      
		
              Param=Param+"&TensionTrabajo="+TensionTrabajo+"&PresionServicio="+PresionServicio+"&Material="+Material+"&Diametro="+Diametro+"&Potencia="+Potencia;
				 
  break;                    
  case '500':  var NormaFab=document.getElementById("NormaFab").value;
         	   var TensionTrabajo=document.getElementById("TensionTrabajo").value;
               var Potencia=document.getElementById("Potencia").value;
			   // var Pautas=document.getElementById("Pautas").value; 
				 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
			   
				Param=Param+"&TensionTrabajo="+TensionTrabajo+"&NormaFab="+NormaFab+"&Potencia="+Potencia;
				 
  break;
  case '600':  //var AlcanceMin=document.getElementById("AlcanceMin").value;
  			  // var AlcanceMax=document.getElementById("AlcanceMax").value;
			   var NormaFab=document.getElementById("NormaFab").value;
			   var Clase=document.getElementById("Clase").value;
			   var Diametro=document.getElementById("Diametro").value;
			   var PresionMax=document.getElementById("PresionMax").value;
			   var PresionMin=document.getElementById("PresionMin").value;
			   var Orificio=document.getElementById("Orificio").value;
			   var Rosca=document.getElementById("Rosca").value;
			 //  var Memoria=document.getElementById("Memoria").value; 
			//	 var Pautas=document.getElementById("Pautas").value; 
				 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
// if(vacio(Memoria)){OK=false; document.getElementById("Celda_Memoria").style.color="red";}else{ document.getElementById("Celda_Memoria").style.color="black";} 		  
			   				      
			 Param=Param+"&NormaFab="+NormaFab+"&Clase="+Clase+"&Diametro="+Diametro+"&PresionMax="+PresionMax+"&PresionMin="+PresionMin+"&Orificio="+Orificio+"&Rosca="+Rosca;
				 
  break;
  case '610':  
  			 var Tipo=document.getElementById("Tipo").value; 	
  			 var NormaFab=document.getElementById("NormaFab").value;
             var Peso=document.getElementById("Peso").value;
			 var LongitudMin=document.getElementById("LongitudMin").value;
			  var LongitudMax=document.getElementById("LongitudMax").value;
             var DiametroMin=document.getElementById("DiametroMin").value;
			 var DiametroMax=document.getElementById("DiametroMax").value;
			  var CantidadSujetar=document.getElementById("CantidadSujetar").value;
		///	  var Pautas=document.getElementById("Pautas").value; 
				 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}			      
			Param=Param+"&Tipo="+Tipo+"&NormaFab="+NormaFab+"&Peso="+Peso+"&LongitudMin="+LongitudMin+"&LongitudMax="+LongitudMax+"&DiametroMin="+DiametroMin+"&DiametroMax="+DiametroMax+"&CantidadSujetar="+CantidadSujetar;
				 
  break;        
  case '620':  var NormaFab=document.getElementById("NormaFab").value;
			   var Motor=document.getElementById("Motor").value;
			   var Presion=document.getElementById("Presion").value;
			  // var Folleto=document.getElementById("Folleto").value; 
			 //  var Pautas=document.getElementById("Pautas").value; 
				 
//if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
// if(vacio(Folleto)){OK=false; document.getElementById("Celda_Folleto").style.color="red";}else{ document.getElementById("Celda_Folleto").style.color="black";} 	
			   				      
				Param=Param+"&NormaFab="+NormaFab+"&Motor="+Motor+"&Presion="+Presion;
		
		
break;
}		

//alert(Param);
if(OK) {
	 if (confirm("Esta seguro de los datos a cargar"))
    {
		 ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/Accesorios/A_PrototipoGNC.php",true);
		 ajax.onreadystatechange=function() 
	   	{ 
		document.getElementById('AltaElementos').innerHTML="<br><br><img  src='../../Images/progress2.gif'>";
		
		  if (ajax.readyState==4) {
			     if(ajax.status==200) {
					      document.getElementById('AltaElementos').innerHTML=ajax.responseText;
			     			           }
								  }
	  	 }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(Param);
	}
}
else {
	 alert("Hay algunos campos que son obligatorios, verifique los campos en rojo");	
	}
}  


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ModificarPrototipo() 
{
var NCertificado=document.getElementById("NCertificado").value;
var Matricula=document.getElementById("Matricula").value;
var FEmision=document.getElementById("FEmision").value;
var FVencimiento=document.getElementById("FVencimiento").value;
var Observacion=document.getElementById("Observacion").value;
var Estado=document.getElementById("Estado").value;

var Componente=document.getElementById("Codigo").value;
var Fabricante=document.getElementById("Fabricante").value;
var Marca=document.getElementById("Marca").value;
var Modelo=document.getElementById("Modelo").value;

var OK=true;

Param="NCertificado="+NCertificado+"&Matricula="+Matricula+"&FEmision="+FEmision+"&FVencimiento="+FVencimiento+"&Observacion="+Observacion+"&Componente="+Componente+"&Fabricante="+Fabricante+"&Marca="+Marca+"&Modelo="+Modelo+"&Estado="+Estado;
//alert(Componente);


if(vacio(Observacion)){OK=false; document.getElementById("celda_Observaciones_color").style.color="red";}else{ document.getElementById("celda_Observaciones_color").style.color="black";}

/*
if(vacio(NCertificado)){OK=false; document.getElementById("celda_NCertificado_color").style.color="red";}else{ document.getElementById("celda_NCertificado_color").style.color="black";}
  if(vacio(Matricula)){OK=false; document.getElementById("celda_Matricula_color").style.color="red";}else{ document.getElementById("celda_Matricula_color").style.color="black";}

  if(vacio(FEmision)){OK=false; document.getElementById("celda_FEmision_color").style.color="red";}else{ document.getElementById("celda_FEmision_color").style.color="black";}
  if(vacio(FVencimiento)){OK=false; document.getElementById("celda_FVencimiento_color").style.color="red";}else{ document.getElementById("celda_FVencimiento_color").style.color="black";}
*/
  //if(vacio(Modelo)){OK=false; document.getElementById("celda_Modelo_color").style.color="red";}else{ document.getElementById("celda_Modelo_color").style.color="black";}

if(Estado==0){
	var FBaja=document.getElementById("FBaja").value;
	Param=Param+"&FBaja="+FBaja;
	}

 switch(Componente)
  {
   case '100':  var Capacidad=document.getElementById("Capacidad").value;
	             var NormaFab=document.getElementById("NormaFab").value;
				 var Diametro=document.getElementById("Diametro").value;
				 var Espesor=document.getElementById("Espesor").value;
				var DurezaMin=document.getElementById("DurezaMin").value;
				 var DurezaMax=document.getElementById("DurezaMax").value
				 var Longitud=document.getElementById("Longitud").value;
				// var TipoRosca=document.getElementById("TipoRosca").value; 
				 
 				 var Ansi=CheckToBit(document.getElementById("ansi"));
				 var Din=CheckToBit(document.getElementById("din"));
				 var Uni=CheckToBit(document.getElementById("uni"));
				 var Bs=CheckToBit(document.getElementById("bs"));
				 var Iram=CheckToBit(document.getElementById("iram"));
				 var Iso10=CheckToBit(document.getElementById("iso10"));
				 var Iso15=CheckToBit(document.getElementById("iso15"));
				 var Ngt=CheckToBit(document.getElementById("ngt"));

				 var Duracion=document.getElementById("Duracion").value;
				 var Material=document.getElementById("Material").value; 	
				 var Utilizacion=document.getElementById("Utilizacion").value;
				 var Tipo=document.getElementById("Tipo").value; 
				 var PresionTrabajo=document.getElementById("PresionTrabajo").value; 
				 
							  
				
Param=Param+"&Capacidad="+Capacidad+"&NormaFab="+NormaFab+"&Diametro="+Diametro+"&Espesor="+Espesor+"&DurezaMin="+DurezaMin+"&Longitud="+Longitud+"&Duracion="+Duracion+"&Material="+Material+"&Utilizacion="+Utilizacion+"&Tipo="+Tipo+"&PresionTrabajo="+PresionTrabajo+"&DurezaMax="+DurezaMax+"&Ansi="+Ansi+"&Din="+Din+"&Uni="+Uni+"&Bs="+Bs+"&Iram="+Iram+"&Iso10="+Iso10+"&Iso15="+Iso15+"&Ngt="+Ngt;
      //alert (Param);        
   break;
   
      case '110':  var Etapas=document.getElementById("Etapas").value;
	             var NormaFab=document.getElementById("NormaFab").value;
				 var PresionMax=document.getElementById("PresionMax").value;
				 var PresionMin=document.getElementById("PresionMin").value;
				 var PresionDescarga=document.getElementById("PresionDescarga").value;
				 var TemperaturaSalida=document.getElementById("TemperaturaSalida").value;
				 var TemperaturaSalida2=document.getElementById("TemperaturaSalida2").value;
				 var TemperaturaSalida3=document.getElementById("TemperaturaSalida3").value;
				 var TemperaturaSalida4=document.getElementById("TemperaturaSalida4").value;
				 var TemperaturaDescarga=document.getElementById("TemperaturaDescarga").value; 
				 var TElectrico=document.getElementById("TElectrico").value;
				 var TCombustion=document.getElementById("TCombustion").value; 	
				 var Potencia=document.getElementById("Potencia").value;
				 	var AlmacenamientoIncorp=document.getElementById("AlmacenamientoIncorp").value;
				 var Cabina=document.getElementById("Cabina").value; 	
				 var PuenteM=document.getElementById("PuenteM").value;
				  var Pulmon=document.getElementById("Pulmon").value;
				
				 
							  
				
Param=Param+"&Etapas="+Etapas+"&NormaFab="+NormaFab+"&PresionMax="+PresionMax+"&PresionMin="+PresionMin+"&PresionDescarga="+PresionDescarga+"&TemperaturaSalida="+TemperaturaSalida+"&TemperaturaDescarga="+TemperaturaDescarga+"&TElectrico="+TElectrico+"&TCombustion="+TCombustion+"&Potencia="+Potencia+"&AlmacenamientoIncorp="+AlmacenamientoIncorp+"&Cabina="+Cabina+"&PuenteM="+PuenteM+"&Pulmon="+Pulmon+"&TemperaturaSalida2="+TemperaturaSalida2+"&TemperaturaSalida3="+TemperaturaSalida3+"&TemperaturaSalida4="+TemperaturaSalida4;
      //alert (Param);        
   break;
   
   
   case '120':   var NormaFab=document.getElementById("NormaFab").value;
				 var Presion1=document.getElementById("Presion1").value;
				 var Presion2=document.getElementById("Presion2").value;
				 var Error=document.getElementById("Error").value;
				 var Especificacion=document.getElementById("Especificacion").value;
				
				
				 
							  
				
Param=Param+"&NormaFab="+NormaFab+"&Presion1="+Presion1+"&Presion2="+Presion2+"&Error="+Error+"&Especificacion="+Especificacion;
      //alert (Param);        
   break;
   
   
   case '200': var NormaFab=document.getElementById("NormaFab").value;
   			   var Caudal=document.getElementById("Caudal").value;
   			   var Tipo=document.getElementById("Tipo").value;
			   var Etapas=document.getElementById("Etapas").value;
			  // var Motor=document.getElementById("Motor").value;  	
				 var CilindradaMax=CheckToBit(document.getElementById("CilindradaMax"));
			   var CilindradaMin=CheckToBit(document.getElementById("CilindradaMin"));
			   var Naftero=CheckToBit(document.getElementById("Naftero"));
			   var Diesel=CheckToBit(document.getElementById("Diesel"));
			   var Motocicleta=CheckToBit(document.getElementById("Motocicleta"));
			   var OtrosM=CheckToBit(document.getElementById("OtrosM"));
			   
				var ConexionEntrada=document.getElementById("ConexionEntrada").value; 
				var ConexionSalida=document.getElementById("ConexionSalida").value; 
				
			
				Param=Param+"&NormaFab="+NormaFab+"&Caudal="+Caudal+"&Tipo="+Tipo+"&Etapas="+Etapas+"&CilindradaMax="+CilindradaMax+"&ConexionEntrada="+ConexionEntrada+"&ConexionSalida="+ConexionSalida+"&CilindradaMin="+CilindradaMin+"&Naftero="+Naftero+"&Diesel="+Diesel+"&Motocicleta="+Motocicleta+"&OtrosM="+OtrosM;
				
				
    break;
  case '310':  var NormaFab=document.getElementById("NormaFab").value;
  			   var Diametro=document.getElementById("Diametro").value;
               var DispositivoSuje=document.getElementById("DispositivoSuje").value;
			   var Distancia=document.getElementById("Distancia").value;
			   var DiametroExterno=document.getElementById("DiametroExterno").value;
               var EspecificacionConector=document.getElementById("EspecificacionConector").value;
				
	               Param=Param+"&NormaFab="+NormaFab+"&Diametro="+Diametro+"&DispositivoSuje="+DispositivoSuje+"&Distancia="+Distancia+"&DiametroExterno="+DiametroExterno+"&EspecificacionConector="+EspecificacionConector;
				 
  break;
  
/* accesorios para conexion de tuberia alta presion*/
   case '340': var NormaFab=document.getElementById("NormaFab").value;
				var EspecificacionRosca=document.getElementById("EspecificacionRosca").value;
                var DiametroTuberia=document.getElementById("DiametroTuberia").value;
				var LongitudNiple=document.getElementById("LongitudNiple").value;
                var PresionTrabajo=document.getElementById("PresionTrabajo").value;
				var Tipo=document.getElementById("Tipo").value;
                var TratamientoCuerpo=document.getElementById("TratamientoCuerpo").value;
				var TratamientoRosca=document.getElementById("TratamientoRosca").value;
                var TratamientoVirola=document.getElementById("TratamientoVirola").value;
				var TratamientoTapon=document.getElementById("TratamientoTapon").value;
                var TratamientoTuerca=document.getElementById("TratamientoTuerca").value;
				
			//	var Memoria=document.getElementById("Memoria").value; 
				// var Pautas=document.getElementById("Pautas").value; 
				
/*				 
if(vacio(Pautas)){OK=false; document.getElementById("Celda_Pautas").style.color="red";}else{ document.getElementById("Celda_Pautas").style.color="black";}
 if(vacio(Memoria)){OK=false; document.getElementById("Celda_Memoria").style.color="red";}else{ document.getElementById("Celda_Memoria").style.color="black";} */
Param=Param+"&NormaFab="+NormaFab+"&EspecificacionRosca="+EspecificacionRosca+"&DiametroTuberia="+DiametroTuberia+"&LongitudNiple="+LongitudNiple+"&PresionTrabajo="+PresionTrabajo+"&Tipo="+Tipo+"&TratamientoCuerpo="+TratamientoCuerpo+"&TratamientoRosca="+TratamientoRosca+"&TratamientoVirola="+TratamientoVirola+"&TratamientoTapon="+TratamientoTapon+"&TratamientoTuerca="+TratamientoTuerca;
			
				 
  break;

  case '410':
  				var NormaFab=document.getElementById("NormaFab").value;
				var ConexionCilindro=document.getElementById("ConexionCilindro").value;
			 	var PresionServicio=document.getElementById("PresionServicio").value;
			 	var Material=document.getElementById("Material").value;
			 	var TiposValvula=document.getElementById("TiposValvula").value;
			 	var OtraConexion=document.getElementById("OtraConexion").value;
			 	var EspecificacionRosca=document.getElementById("EspecificacionRosca").value;
			 	var Torque=document.getElementById("Torque").value;
			 
			 Param=Param+"&ConexionCilindro="+ConexionCilindro+"&PresionServicio="+PresionServicio+"&Material="+Material+"&TiposValvula="+TiposValvula+"&OtraConexion="+OtraConexion+"&EspecificacionRosca="+EspecificacionRosca+"&Torque="+Torque+"&NormaFab="+NormaFab;

  break;
   case '300':  var NormaFab=document.getElementById("NormaFab").value;
               var RadioCurvatura=document.getElementById("RadioCurvatura").value;
			    var DiametroInt=document.getElementById("DiametroInt").value;
               var DiametroExt=document.getElementById("DiametroExt").value;
			   var DispositivoSuje=document.getElementById("DispositivoSuje").value;
				      
				Param=Param+"&NormaFab="+NormaFab+"&RadioCurvatura="+RadioCurvatura+"&DiametroInt="+DiametroInt+"&DiametroExt="+DiametroExt+"&DispositivoSuje="+DispositivoSuje;
				 
  break;
     case '320':  var NormaFab=document.getElementById("NormaFab").value;
               var RadioCurvatura=document.getElementById("RadioCurvatura").value;
			    var DiametroInt=document.getElementById("DiametroInt").value;
               var DiametroExt=document.getElementById("DiametroExt").value;
			     var Caracteristicas=document.getElementById("Caracteristicas").value;
				      
				Param=Param+"&NormaFab="+NormaFab+"&RadioCurvatura="+RadioCurvatura+"&DiametroInt="+DiametroInt+"&DiametroExt="+DiametroExt+"&Caracteristicas="+Caracteristicas;
		
  break;

  
    case '330': var NormaFab=document.getElementById("NormaFab").value;
				var DiametroBoquilla=document.getElementById("DiametroBoquilla").value;
                var DiametroConducto=document.getElementById("DiametroConducto").value;
				
				var LargoConducto=document.getElementById("LargoConducto").value;
                var AccesoriosSujecion=document.getElementById("AccesoriosSujecion").value;
	
				Param=Param+"&NormaFab="+NormaFab+"&DiametroBoquilla="+DiametroBoquilla+"&DiametroConducto="+DiametroConducto+"&LargoConducto="+LargoConducto+"&AccesoriosSujecion="+AccesoriosSujecion;
				 
  break;
   
  case '400':  var NormaFab=document.getElementById("NormaFab").value;
               var EspecificacionConexion=document.getElementById("EspecificacionConexion").value;
			   var EspecificacionInterconexion=document.getElementById("EspecificacionInterconexion").value;
			   
			         
				Param=Param+"&NormaFab="+NormaFab+"&EspecificacionConexion="+EspecificacionConexion+"&EspecificacionInterconexion="+EspecificacionInterconexion;
				 
  break;                 
  case '420':  
               var PresionServicio=document.getElementById("PresionServicio").value;
			   var Material=document.getElementById("Material").value;
			   var DispositivoSeguridad=document.getElementById("DispositivoSeguridad").value;
			   
				      
				Param=Param+"&PresionServicio="+PresionServicio+"&Material="+Material+"&DispositivoSeguridad="+DispositivoSeguridad;
				 
  break;                 
  case '430':   var NormaFab=document.getElementById("NormaFab").value;
  				var TensionTrabajo=document.getElementById("TensionTrabajo").value;
              	var PresionTrabajo=document.getElementById("PresionServicio").value;
			    var Rosca=document.getElementById("Rosca").value;
			    var Diametro=document.getElementById("Diametro").value;
			    var Potencia=document.getElementById("Potencia").value;
			    var TipoElecrtoValvula=document.getElementById("TipoElecrtoValvula").value;			      
				Param=Param+"&TensionTrabajo="+TensionTrabajo+"&PresionTrabajo="+PresionTrabajo+"&Rosca="+Rosca+"&Diametro="+Diametro+"&Potencia="+Potencia+"&TipoElecrtoValvula="+TipoElecrtoValvula+"&NormaFab="+NormaFab;
				 
  break;    
  case '440':    var TesionTrabajo=document.getElementById("TensionTrabajo").value;
               var PresionServicio=document.getElementById("PresionServicio").value;
			   var Material=document.getElementById("Material").value;
			   var Diametro=document.getElementById("Diametro").value;
			   var Potencia=document.getElementById("Potencia").value;
			   				      
		
              Param=Param+"&TensionTrabajo="+TensionTrabajo+"&PresionServicio="+PresionServicio+"&Material="+Material+"&Diametro="+Diametro+"&Potencia="+Potencia;
				 
  break;                    
  case '500':  var NormaFab=document.getElementById("NormaFab").value;
         	   var TensionTrabajo=document.getElementById("TensionTrabajo").value;
               var Potencia=document.getElementById("Potencia").value;
			   
				Param=Param+"&TensionTrabajo="+TensionTrabajo+"&NormaFab="+NormaFab+"&Potencia="+Potencia;
				 
  break;
  case '600': // var AlcanceMin=document.getElementById("AlcanceMin").value;
  			  // var AlcanceMax=document.getElementById("AlcanceMax").value;
			   var NormaFab=document.getElementById("NormaFab").value;
			   var Clase=document.getElementById("Clase").value;
			   var Diametro=document.getElementById("Diametro").value;
			   var PresionMax=document.getElementById("PresionMax").value;
			   var PresionMin=document.getElementById("PresionMin").value;
			   var Orificio=document.getElementById("Orificio").value;
			   var Rosca=document.getElementById("Rosca").value;
			   				      
			 Param=Param+"&NormaFab="+NormaFab+"&Clase="+Clase+"&Diametro="+Diametro+"&PresionMax="+PresionMax+"&PresionMin="+PresionMin+"&Orificio="+Orificio+"&Rosca="+Rosca;
				 
  break;
  case '610':  
  			 var Tipo=document.getElementById("Tipo").value; 	
  			 var NormaFab=document.getElementById("NormaFab").value;
             var Peso=document.getElementById("Peso").value;
			 var LongitudMin=document.getElementById("LongitudMin").value;
			  var LongitudMax=document.getElementById("LongitudMax").value;
             var DiametroMin=document.getElementById("DiametroMin").value;
			 var DiametroMax=document.getElementById("DiametroMax").value;	
			   var CantidadSujetar=document.getElementById("CantidadSujetar").value;		      
			Param=Param+"&Tipo="+Tipo+"&NormaFab="+NormaFab+"&Peso="+Peso+"&LongitudMin="+LongitudMin+"&LongitudMax="+LongitudMax+"&DiametroMin="+DiametroMin+"&DiametroMax="+DiametroMax+"&CantidadSujetar="+CantidadSujetar;
				 
  break;        
  case '620':  var NormaFab=document.getElementById("NormaFab").value;
			   var Motor=document.getElementById("Motor").value;
			   var Presion=document.getElementById("Presion").value;
			  
			   				      
				Param=Param+"&NormaFab="+NormaFab+"&Motor="+Motor+"&Presion="+Presion;
		
		
break;
}		

//alert(Param);
if(OK){
	 if (confirm("Esta seguro de los datos a cargar"))
    {
		 ajax=nuevoAjax();
		 ajax.open("POST", "/SICGNC/Cargas/Accesorios/M_PrototipoGNC.php",true);
		 ajax.onreadystatechange=function() 
	   	{ 
		document.getElementById('ModificacionElementos').innerHTML="<br><br><img  src='../../Images/progress2.gif'>";
		
		  if (ajax.readyState==4) {
			     if(ajax.status==200) {
					     document.getElementById('ModificacionElementos').innerHTML=ajax.responseText;
			     			           }
								  }
	  	 }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(Param);
}
}
else {
	 alert("Hay algunos campos que son obligatorios, verifique los campos en rojo");	
	}
}  






///////////////////////////////////////////////////////////////////////////
///////////Carga las Regiones correspodiente al PEC seleccionado/////////////////////////
function CargarRegion(TipoOp)
{

var pec=document.getElementById("Codigo").value;
var Str;
//alert(TipoOp);


if (pec=="0") {
	alert("Debe seleccionar alguna región.");
	return;
	}


if (TipoOp=="M" || TipoOp=="B") 
{
    ajax=nuevoAjax();
     ajax.open("POST", "/SICGNC/Cargas/MostrarRegionPEC.php",true);
     ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
		   { 
  
		    document.getElementById("Datos1").innerHTML=ajax.responseText;
		   } 
	   }
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

Str="pec="+pec+"&TipoOp="+TipoOp;
    ajax.send(Str);   
	}      
else
{
alert("Operación invalida");
}
}
////////////////////////////////////////////////////////////////////////////
function createMovableOptions1(fromBox,toBox,totalWidth,totalHeight,labelLeft,labelRight)
	{		
		fromObj = document.getElementById(fromBox);
		toObj = document.getElementById(toBox);
		
		//arrayOfItemsToSelect[arrayOfItemsToSelect.length] = toObj;

		
		fromObj.ondblclick = moveSingleElement;
		toObj.ondblclick = moveSingleElement;
              fromObj.onclick = DetalleTdM;
		
		fromBoxArray.push(fromObj);
		toBoxArray.push(toObj);
		
		var parentEl = fromObj.parentNode;
		
		var parentDiv = document.createElement('DIV');
		parentDiv.className='multipleSelectBoxControl';
		parentDiv.id = 'selectBoxGroup' + selectBoxIndex;
		parentDiv.style.width = totalWidth + 'px';
		parentDiv.style.height = totalHeight + 'px';
		parentEl.insertBefore(parentDiv,fromObj);
		
		
		var subDiv = document.createElement('DIV');
		subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
		fromObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px';

		var label = document.createElement('SPAN');
		label.innerHTML = labelLeft;
		subDiv.appendChild(label);
		
		subDiv.appendChild(fromObj);
		subDiv.className = 'multipleSelectBoxDiv';
		parentDiv.appendChild(subDiv);
		
		
		var buttonDiv = document.createElement('DIV');
		buttonDiv.style.verticalAlign = 'middle';
		buttonDiv.style.paddingTop = (totalHeight/2) - 50 + 'px';
		buttonDiv.style.width = '30px';
		buttonDiv.style.textAlign = 'center';
		parentDiv.appendChild(buttonDiv);
		
		var buttonRight = document.createElement('INPUT');
		buttonRight.type='button';
		buttonRight.value = '>';
		buttonDiv.appendChild(buttonRight);	
		buttonRight.onclick = moveSingleElement;	
		
		var buttonAllRight = document.createElement('INPUT');
		buttonAllRight.type='button';
		buttonAllRight.value = '>>';
		buttonAllRight.onclick = moveAllElements;
		buttonDiv.appendChild(buttonAllRight);		
		
		var buttonLeft = document.createElement('INPUT');
		buttonLeft.style.marginTop='10px';
		buttonLeft.type='button';
		buttonLeft.value = '<';
		buttonLeft.onclick = moveSingleElement;
		buttonDiv.appendChild(buttonLeft);		
		
		var buttonAllLeft = document.createElement('INPUT');
		buttonAllLeft.type='button';
		buttonAllLeft.value = '<<';
		buttonAllLeft.onclick = moveAllElements;
		buttonDiv.appendChild(buttonAllLeft);
		
		var subDiv = document.createElement('DIV');
		subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
		toObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px';

		var label = document.createElement('SPAN');
		label.innerHTML = labelRight;
		subDiv.appendChild(label);
				
		subDiv.appendChild(toObj);
		parentDiv.appendChild(subDiv);		
		
		toObj.style.height = (totalHeight - label.offsetHeight) + 'px';
		fromObj.style.height = (totalHeight - label.offsetHeight) + 'px';

			
		selectBoxIndex++;
		
	}
////////////////////////////////////////////////////////////////////////////
///////////Carga las Datos de la  Region seleccionada/////////////////////////
function CargarDatosRegion(Tipo)
{

var Region=document.getElementById("CodigoRegion").value;
//alert(Tipo);
var Str;

if (Region=="0") {
	alert("Debe seleccionar alguna región.");
	return;
	}

if (Tipo=="M" || Tipo=="B") 
{
    ajax=nuevoAjax();
     ajax.open("POST", "/SICGNC/Cargas/MostrarDatosRegionPEC.php",true);
     ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
		   { 
  
		    document.getElementById("Datos2").innerHTML=ajax.responseText;
			 createMovableOptions1("fromBox","toBox",560,130,'Talleres Disponibles','Talleres Seleccionados');
		   } 
	   }
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

Str="Region="+Region+"&Tipo="+Tipo;
//alert(Str);
    ajax.send(Str);         
		
}
else 
{
 alert("Operación Invalida");      
		
}
}
///////////////////////////////////////////////////////////////////////////////

/////////////////Funcion para dar de Alta,Baja o Modificar los Regiones de los PECs///////////////////////////////////////
function AltaModificacionRegionesRTR(TipoOp)
{
var RazonSocial=document.getElementById("Codigo").value;
if (RazonSocial=="0") {
	alert("Debe seleccionar el PEC al que le desea crear la Region");
	return;
	}
var RT=document.getElementById("CodigoRT").value;
var Nombres=document.getElementById("Nombre").value;
var Domicilio=document.getElementById("Domicilio").value;
var Provincia=document.getElementById("Provincia").value;
var Departamento=document.getElementById("Departamento").value;
var Localidad=document.getElementById("Localidad").value;
var CPostal=document.getElementById("CPostal").value;
var AreaTel=document.getElementById("AreaTel").value;
var Telefono=document.getElementById("Telefono").value;
//var TipoDocRTR=document.getElementById("tipodocRTR").value;
//var RTRNroDoc=document.getElementById("nrodocRTR").value;
selectTdMs();
var TdMs=document.getElementById("VectorTdMs").value;
var Observaciones=document.getElementById("Observaciones").value;
var OK=true;
Str="TipoOp="+TipoOp+"&RazonSocial="+RazonSocial+"&RT="+RT+"&Nombres="+Nombres+"&Domicilio="+Domicilio+"&Provincia="+Provincia+"&Departamento="+Departamento+"&Localidad="+Localidad+"&CPostal="+CPostal+"&AreaTel="+AreaTel+"&Telefono="+Telefono+"&TdMs="+TdMs+"&Observaciones="+Observaciones;
//alert(Str);
if (RazonSocial=="0") {
	alert("Debe seleccionar el PEC al que le desea crear la Region");
	return;
	}
if (TipoOp==1)
 {
   if(RazonSocial=="0"){OK=false; document.getElementById("celda_Pec").style.color="red";}else{ document.getElementById("celda_Pec").style.color="black";}
   if(RT=="0"){OK=false; document.getElementById("celda_RTRs").style.color="red";}else{ document.getElementById("celda_RTRs").style.color="black";}
   if(vacio(Nombres)){OK=false; document.getElementById("celda_Nombre").style.color="red";}else{ document.getElementById("celda_Nombre").style.color="black";}
  if(vacio(Domicilio)){OK=false; document.getElementById("celda_Domicilio").style.color="red";}else{ document.getElementById("celda_Domicilio").style.color="black";}
  if(Provincia=="0"){OK=false; document.getElementById("celda_Provincia").style.color="red";}else{ document.getElementById("celda_Provincia").style.color="black";}
  if(Departamento=="0"){OK=false; document.getElementById("celda_Departamento").style.color="red";}else{ document.getElementById("celda_Departamento").style.color="black";}
  if(Localidad=="0"){OK=false; document.getElementById("celda_Localidad").style.color="red";}else{ document.getElementById("celda_Localidad").style.color="black";}
  if(vacio(CPostal)){OK=false; document.getElementById("celda_CPostal").style.color="red";}else{ document.getElementById("celda_CPostal").style.color="black";}
  if(vacio(AreaTel)){OK=false; document.getElementById("celda_AreaTel").style.color="red";}else{ document.getElementById("celda_AreaTel").style.color="black";}
  if(vacio(Telefono)){OK=false; document.getElementById("celda_Telefono").style.color="red";}else{ document.getElementById("celda_Telefono").style.color="black";}

  if(OK)
  {
   if (confirm("Esta seguro de los datos a cargar"))
    {
     ajax=nuevoAjax();
     ajax.open("POST", "/SICGNC/Cargas/ABM_RegionesPEC.php",true);
     ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
		   { 
		    document.getElementById("Total").innerHTML=ajax.responseText;
		   } 
	   }
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var Str;
Str="TipoOp="+TipoOp+"&RazonSocial="+RazonSocial+"&RT="+RT+"&Nombres="+Nombres+"&Domicilio="+Domicilio+"&Provincia="+Provincia+"&Departamento="+Departamento+"&Localidad="+Localidad+"&CPostal="+CPostal+"&AreaTel="+AreaTel+"&Telefono="+Telefono+"&TdMs="+TdMs+"&Observaciones="+Observaciones;

   ajax.send(Str);
	}   
  }
  else
    {
	 alert("Hay algunos campos que son obligatorios, verifique los campos en rojo");
	}
 } 
if (TipoOp==2)
 {
	var Id_Region=document.getElementById("Region").value;
  if(RazonSocial=="0"){OK=false; document.getElementById("celda_Pec").style.color="red";}else{ document.getElementById("celda_Pec").style.color="black";}
  if(RT=="0"){OK=false; document.getElementById("celda_RTRs").style.color="red";}else{ document.getElementById("celda_RTRs").style.color="black";}
  if(vacio(Nombres)){OK=false; document.getElementById("celda_Nombre").style.color="red";}else{ document.getElementById("celda_Nombre").style.color="black";}
  if(vacio(Domicilio)){OK=false; document.getElementById("celda_Domicilio").style.color="red";}else{ document.getElementById("celda_Domicilio").style.color="black";}
  if(Provincia=="0"){OK=false; document.getElementById("celda_Provincia").style.color="red";}else{ document.getElementById("celda_Provincia").style.color="black";}
  if(Departamento=="0"){OK=false; document.getElementById("celda_Departamento").style.color="red";}else{ document.getElementById("celda_Departamento").style.color="black";}
  if(Localidad=="0"){OK=false; document.getElementById("celda_Localidad").style.color="red";}else{ document.getElementById("celda_Localidad").style.color="black";}
  if(vacio(CPostal)){OK=false; document.getElementById("celda_CPostal").style.color="red";}else{ document.getElementById("celda_CPostal").style.color="black";}
  if(vacio(AreaTel)){OK=false; document.getElementById("celda_AreaTel").style.color="red";}else{ document.getElementById("celda_AreaTel").style.color="black";}
  if(vacio(Telefono)){OK=false; document.getElementById("celda_Telefono").style.color="red";}else{ document.getElementById("celda_Telefono").style.color="black";}

  if(OK)
  {
   if (confirm("Esta seguro de los datos a cargar"))
    {
     ajax=nuevoAjax();
     ajax.open("POST", "/SICGNC/Cargas/ABM_RegionesPEC.php",true);
     ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
		   { 
		    document.getElementById("Total").innerHTML=ajax.responseText;
		   } 
	   }
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       var Str;
Str="TipoOp="+TipoOp+"&RazonSocial="+RazonSocial+"&RT="+RT+"&Nombres="+Nombres+"&Domicilio="+Domicilio+"&Provincia="+Provincia+"&Departamento="+Departamento+"&Localidad="+Localidad+"&CPostal="+CPostal+"&AreaTel="+AreaTel+"&Telefono="+Telefono+"&TdMs="+TdMs+"&Observaciones="+Observaciones+"&Region="+Id_Region;
		 //alert(Str); 
		  ajax.send(Str);}
	}   
   else
    {
	 alert("Hay algunos campos que son obligatorios, verifique los campos en rojo");
	}
 }
 if (TipoOp==3)
 {
	var Id_Region=document.getElementById("Region").value;
	var Causa=document.getElementById("causa").value;
  if(vacio(Causa)){OK=false; document.getElementById("celda_Causa").style.color="red";}else{ document.getElementById("celda_Causa").style.color="black";}
  if(OK)
  {
   if (confirm("¿Esta seguro de dar de Baja la Región?"))
    {
     ajax=nuevoAjax();
     ajax.open("POST", "/SICGNC/Cargas/ABM_RegionesPEC.php",true);
     ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
		   { 
		    document.getElementById("Total").innerHTML=ajax.responseText;
		   } 
	   }
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       var Str;

Str="TipoOp="+TipoOp+"&RazonSocial="+RazonSocial+"&RT="+RT+"&Nombres="+Nombres+"&Domicilio="+Domicilio+"&Provincia="+Provincia+"&Departamento="+Departamento+"&Localidad="+Localidad+"&CPostal="+CPostal+"&AreaTel="+AreaTel+"&Telefono="+Telefono+"&TdMs="+TdMs+"&Observaciones="+Observaciones+"&Causa="+Causa+"&Region="+Id_Region;
		 //alert(Str); 
		  ajax.send(Str);
		  }
	}   
   else
    {
	 alert("Hay algunos campos que son obligatorios, verifique los campos en rojo");
	 }
}
}

/////////////////Carga los TdM de los pec con que tienen relacion laboral/////////////////////////////////////
function selectTdMs()
{
 var obj = document.getElementById('toBox');
 var aux='';	
 for(var no=0;no<obj.options.length;no++){
  obj.options[no].selected = true;
  if(aux=='')
  {
  	aux=obj.options[no].value;
  }
  else
  {
  	aux= aux +';'+obj.options[no].value;
  }
 }
 document.getElementById('VectorTdMs').value=aux;
}
////////////////////////////////////////////////////////////////////////////
function DetalleTdM()
 {
  var CodigoSujeto= this.value;
  ajax=nuevoAjax();
  ajax.open("POST", "/SICGNC/Cargas/DescripcionTdM.php", true);
  ajax.onreadystatechange=function() 
    { 
	 if (ajax.readyState==4)
	  { 
	   document.getElementById("DescripcionTdM").innerHTML=ajax.responseText;
	  } 
	}
   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   ajax.send("CodigoSujeto="+CodigoSujeto);
}
////////////////////////////////////////////////////////////////////////////
///////////Carga los TDM correspodiente al PEC seleccionado/////////////////////////
function CargarTalleres()
{

var pec=document.getElementById("Codigo").value;
//alert(pec)
var Str;
    ajax=nuevoAjax();
     ajax.open("POST", "/SICGNC/Cargas/MostrarTalleresPEC.php",true);
     ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
		   { 
  
		    document.getElementById("Datos").innerHTML=ajax.responseText;
			  createMovableOptions1("fromBox","toBox",560,130,'Talleres Disponibles','Talleres Seleccionados');
		   } 
	   }
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

Str="pec="+pec;
//alert(Str);
    ajax.send(Str);         
		
}
//////////////////////////////////////////////////////////////////////////////////
//////////Esta función transforma un valor de un CheckBox en 1 o 0 dependiendo //
/////////de su valor de true o false/////////////////////////////////////////////
function CheckToBit(Check)
{
 if(Check.checked) return 1;
 else return 0;     
}
//////////////////////////////////////////////////////////////////////////////////////
///////////////////Autoriza el RTR por parte de personal del ENARGAS///////////////////////////////////////////////////////////
function AutorizarRTR(Tipo,Nro)
{/*
alert(Tipo);
alert(Nro);
*/

if(confirm("¿ Está seguro de Autorizar el RT Regional con el "+ Tipo +" "+ Nro + " ?"))
      {
 ajax=nuevoAjax();
ajax.open("GET", "/SICGNC/Cargas/AutorizacionRTRegionalPEC.php?Tipo="+Tipo+"&Nro="+Nro,true);
  ajax.onreadystatechange=function() 
	{ 
	if (ajax.readyState==1)
		    {
			 document.getElementById("AutorizacionRTR").innerHTML="<h2>.....Cargando......</h2>"
			}
	if (ajax.readyState==4)
		{ 
		document.getElementById("AutorizacionRTR").innerHTML=ajax.responseText;
		} 
	}
	ajax.send(null);

	}
}

///////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////Baja de Certificados de PECs y CRPCs por parte de los OC//////////////
function MostrarDatosBaja(Sujeto)
{
var CodigoSujeto=document.getElementById("CodigoSujeto").value;
if (CodigoSujeto=="0")
 {
      ajax=nuevoAjax();
      ajax.open("GET", "/SICGNC/blanco.php", true);
      ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
	      { 
		   document.getElementById("DatosSujeto").innerHTML=ajax.responseText;
	      } 
	   }
	 ajax.send(null);
 }
 else
    {
	  ajax=nuevoAjax();
      ajax.open("POST", "/SICGNC/Cargas/MostrarDatosSujetoBaja.php", true);
      ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==1)
	      {
		   document.getElementById("DatosSujeto").innerHTML="<h2>.....Cargando......</h2>";
	      }
	    if (ajax.readyState==4)
	      { 
		   document.getElementById("DatosSujeto").innerHTML=ajax.responseText;
	      } 
	   }
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 ajax.send("TipoSujeto="+Sujeto+"&CodigoSujeto="+CodigoSujeto);
	
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
function BajaCertificadoSujeto(TipoSujeto)
{
 var CodigoSujeto=document.getElementById("CodigoSujeto").value;
 var Razon=document.getElementById("RazonSocial").value;
 var Observaciones=document.getElementById("Observaciones").value;
 //alert(Observaciones);
 var OK=true;
 
 if(vacio(Observaciones)){OK=false; document.getElementById("celda_Observaciones").style.color="red";}else{ document.getElementById("celda_Observaciones").style.color="black";}

 if(OK)
  {
     if(confirm("¿Está seguro de los datos a dar de Baja al CRPC "+ Razon +" ?"))
	 {
       ajax=nuevoAjax();
       ajax.open("POST", "/SICGNC/Cargas/BajaCertificadoSujeto.php", true);
       ajax.onreadystatechange=function() 
	    { 
	     if (ajax.readyState==1)
	       {
		    document.getElementById("BajaCertificado").innerHTML="<h2>.....Cargando......</h2>";
	       }
	     if (ajax.readyState==4)
	       { 
		    document.getElementById("BajaCertificado").innerHTML=ajax.responseText;
	       } 
	    }
	  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	  ajax.send("TipoSujeto="+TipoSujeto+"&CodigoSujeto="+CodigoSujeto+"&Observaciones="+Observaciones); 
	 } 
  }
  else
      alert("El campo Observaciones es OBLIGATORIO.");
}


////////////////////////////////////////////////////////////////////////////
//////////////////Levanta los datos correspondiente al RTR////////////////////////////////////////
function LevantaDatos()
{
var RT=document.getElementById("Codigo").value;
//alert(RT);
//var nrodoc=document.getElementById("nrodoc").value;
//var tipodoc=document.getElementById("tipodoc").value;
var Str;
    ajax=nuevoAjax();
     ajax.open("POST", "/SICGNC/Cargas/MostrarDatosRTRegionalPEC.php",true);
     ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
		   { 
		    document.getElementById("Datos").innerHTML=ajax.responseText;
		    createMovableOptions("fromBox","toBox",560,130,'PECs Disponibles','PECs Seleccionados');
		   } 
	   }
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

Str="RT="+RT;
//alert(Str);
    ajax.send(Str);         
		
}
////////////////////////////////////////////////////////////////////////////////////////

////////////////////Funcion para dar de Alta,Baja o Modificar los RT regionales////////////////////////////////////////////////
function AltaModificacionRT(TipoOp)
{
var Apellido=document.getElementById("Apellido").value;
var Nombres=document.getElementById("Nombres").value;
var TipoDoc=document.getElementById("TipoDoc").value;
var NroDoc=document.getElementById("NroDoc").value;
//alert(NroDoc);
var Cuit=document.getElementById("Cuit_1").value+"-"+document.getElementById("Cuit_2").value+"-"+document.getElementById("Cuit_3").value;
var Domicilio=document.getElementById("Domicilio").value;
var Provincia=document.getElementById("Provincia").value;
var Departamento=document.getElementById("Departamento").value;
var Localidad=document.getElementById("Localidad").value;
var CPostal=document.getElementById("CPostal").value;
var AreaTel=document.getElementById("AreaTel").value;
var Telefono=document.getElementById("Telefono").value;
var Titulo=document.getElementById("Titulo").value;
var CjoProfesional=document.getElementById("CjoProfesional").value;
var MatProfesional=document.getElementById("MatProfesional").value;
var Licenciataria=document.getElementById("Licenciataria").value;
var MatriculaGas=document.getElementById("MatriculaGas").value;
var ALTART=document.getElementById("ALTART").value;
var Mail=document.getElementById("Mail").value;
var FOTODTOLEG=CheckToBit(document.getElementById("FOTODTOLEG"));
var CERTCJOPROF=CheckToBit(document.getElementById("CERTCJOPROF"));
var FOTOTITLEG=CheckToBit(document.getElementById("FOTOTITLEG"));
var AFIP1=CheckToBit(document.getElementById("AFIP1"));
var CERTDIST=CheckToBit(document.getElementById("CERTDIST"));
var CERTFIRMA=CheckToBit(document.getElementById("CERTFIRMA"));
var INSCAFIP=CheckToBit(document.getElementById("INSCAFIP"));
var LABORAL=CheckToBit(document.getElementById("LABORAL"));
var PagoMatri=CheckToBit(document.getElementById("PagoMatri"));
var LABORAL=CheckToBit(document.getElementById("LABORAL"));
var AREAFACSIMIL=document.getElementById("AREAFACSIMIL").value;
var FACSIMIL=document.getElementById("FACSIMIL").value;
var DDJJNORMATIVA=CheckToBit(document.getElementById("DDJJNORMATIVA"));
var INCTITPROF=CheckToBit(document.getElementById("INCTITPROF"));
var INSCAFIP=CheckToBit(document.getElementById("INSCAFIP"));
var DJJEXCLUSIVO=CheckToBit(document.getElementById("DJJEXCLUSIVO"));
var Observaciones=document.getElementById("Observaciones").value;
var Categoria=document.getElementById("Categoria").value;
selectPECs();
var Pecs=document.getElementById("VectorPECs").value;
var OK=true;

if (TipoOp==1)
 {
  if(vacio(Apellido)){OK=false; document.getElementById("celda_Apellido").style.color="red";}else{ document.getElementById("celda_Apellido").style.color="black";}
  if(vacio(Nombres)){OK=false; document.getElementById("celda_Nombres").style.color="red";}else{ document.getElementById("celda_Nombres").style.color="black";}
  if(!ValidarCuit(Cuit)){OK=false; document.getElementById("celda_Cuit").style.color="red";}else{ document.getElementById("celda_Cuit").style.color="black";}
  if(vacio(NroDoc)){OK=false; document.getElementById("celda_NroDoc").style.color="red";}else{ document.getElementById("celda_NroDoc").style.color="black";}
  if(vacio(Domicilio)){OK=false; document.getElementById("celda_Domicilio").style.color="red";}else{ document.getElementById("celda_Domicilio").style.color="black";}
  if(Provincia=="0"){OK=false; document.getElementById("celda_Provincia").style.color="red";}else{ document.getElementById("celda_Provincia").style.color="black";}
  if(Departamento=="0"){OK=false; document.getElementById("celda_Departamento").style.color="red";}else{ document.getElementById("celda_Departamento").style.color="black";}
  if(Localidad=="0"){OK=false; document.getElementById("celda_Localidad").style.color="red";}else{ document.getElementById("celda_Localidad").style.color="black";}
  if(vacio(CPostal)){OK=false; document.getElementById("celda_CPostal").style.color="red";}else{ document.getElementById("celda_CPostal").style.color="black";}
  if(vacio(AreaTel)){OK=false; document.getElementById("celda_AreaTel").style.color="red";}else{ document.getElementById("celda_AreaTel").style.color="black";}
  if(vacio(Telefono)){OK=false; document.getElementById("celda_Telefono").style.color="red";}else{ document.getElementById("celda_Telefono").style.color="black";}
  if(vacio(Titulo)){OK=false; document.getElementById("celda_Titulo").style.color="red";}else{ document.getElementById("celda_Titulo").style.color="black";}
  if(vacio(CjoProfesional)){OK=false; document.getElementById("celda_CjoProfesional").style.color="red";}else{ document.getElementById("celda_CjoProfesional").style.color="black";}
  if(vacio(MatProfesional)){OK=false; document.getElementById("celda_MatProfesional").style.color="red";}else{ document.getElementById("celda_MatProfesional").style.color="black";}
  if(Licenciataria=="0"){OK=false; document.getElementById("celda_Licenciataria").style.color="red";}else{ document.getElementById("celda_Licenciataria").style.color="black";}
  if(vacio(MatriculaGas)){OK=false; document.getElementById("celda_MatriculaGas").style.color="red";}else{ document.getElementById("celda_MatriculaGas").style.color="black";}
  if(vacio(Categoria)){OK=false; document.getElementById("celda_Categoria").style.color="red";}else{ document.getElementById("celda_Categoria").style.color="black";}

  if(OK)
  {
   if (confirm("Esta seguro de los datos a cargar"))
    {
     ajax=nuevoAjax();
     ajax.open("POST", "/SICGNC/Cargas/ABM_RTRegionalPEC.php",true);
     ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
		   { 
		    document.getElementById("Datos").innerHTML=ajax.responseText;
		   } 
	   }
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var Str;
Str="TipoOp="+TipoOp+"&Apellido="+Apellido+"&Nombres="+Nombres+"&TipoDoc="+TipoDoc+"&NroDoc="+NroDoc+"&Cuit="+Cuit+"&Domicilio="+Domicilio+"&Provincia="+Provincia+"&Departamento="+Departamento+"&Localidad="+Localidad+"&CPostal="+CPostal+"&AreaTel="+AreaTel+"&Telefono="+Telefono+"&Titulo="+Titulo+"&CjoProfesional="+CjoProfesional+"&MatProfesional="+MatProfesional+"&Licenciataria="+Licenciataria+"&MatriculaGas="+MatriculaGas+"&ALTART="+ALTART+"&FOTODTOLEG="+FOTODTOLEG+"&CERTCJOPROF="+CERTCJOPROF+"&FOTOTITLEG="+FOTOTITLEG+"&AFIP1="+AFIP1+"&CERTDIST="+CERTDIST+"&CERTFIRMA="+CERTFIRMA+"&LABORAL="+LABORAL+"&PagoMatri="+PagoMatri+"&AREAFACSIMIL="+AREAFACSIMIL+"&DDJJNORMATIVA="+DDJJNORMATIVA+"&INCTITPROF="+INCTITPROF+"&INSCAFIP="+INSCAFIP+"&DJJEXCLUSIVO="+DJJEXCLUSIVO+"&Pecs="+Pecs+"&FACSIMIL="+FACSIMIL+"&Mail="+Mail+"&Observaciones="+Observaciones;
    ajax.send(Str+"&Categoria="+Categoria);
	}   
  }
  else
    {
	 alert("Hay algunos campos que son obligatorios, verifique los campos en rojo");
	}
 } 
if (TipoOp==2)
 {
  if(vacio(Apellido)){OK=false; document.getElementById("celda_Apellido").style.color="red";}else{ document.getElementById("celda_Apellido").style.color="black";}
  if(vacio(Nombres)){OK=false; document.getElementById("celda_Nombres").style.color="red";}else{ document.getElementById("celda_Nombres").style.color="black";}
  if(!ValidarCuit(Cuit)){OK=false; document.getElementById("celda_Cuit").style.color="red";}else{ document.getElementById("celda_Cuit").style.color="black";}
  if(vacio(NroDoc)){OK=false; document.getElementById("celda_NroDoc").style.color="red";}else{ document.getElementById("celda_NroDoc").style.color="black";}
  if(vacio(Domicilio)){OK=false; document.getElementById("celda_Domicilio").style.color="red";}else{ document.getElementById("celda_Domicilio").style.color="black";}
  if((Provincia=="0") || (Provincia=="")){OK=false; document.getElementById("celda_Provincia").style.color="red";}else{ document.getElementById("celda_Provincia").style.color="black";}
  if(Departamento=="0" || (Departamento=="")){OK=false; document.getElementById("celda_Departamento").style.color="red";}else{ document.getElementById("celda_Departamento").style.color="black";}
  if(Localidad=="0" || (Localidad=="")) {OK=false; document.getElementById("celda_Localidad").style.color="red";}else{ document.getElementById("celda_Localidad").style.color="black";}
  if(vacio(CPostal)){OK=false; document.getElementById("celda_CPostal").style.color="red";}else{ document.getElementById("celda_CPostal").style.color="black";}
  if(vacio(AreaTel)){OK=false; document.getElementById("celda_AreaTel").style.color="red";}else{ document.getElementById("celda_AreaTel").style.color="black";}
  if(vacio(Telefono)){OK=false; document.getElementById("celda_Telefono").style.color="red";}else{ document.getElementById("celda_Telefono").style.color="black";}
  if(vacio(Titulo)){OK=false; document.getElementById("celda_Titulo").style.color="red";}else{ document.getElementById("celda_Titulo").style.color="black";}
  if(vacio(CjoProfesional)){OK=false; document.getElementById("celda_CjoProfesional").style.color="red";}else{ document.getElementById("celda_CjoProfesional").style.color="black";}
  if(vacio(MatProfesional)){OK=false; document.getElementById("celda_MatProfesional").style.color="red";}else{ document.getElementById("celda_MatProfesional").style.color="black";}
  if(Licenciataria=="0"){OK=false; document.getElementById("celda_Licenciataria").style.color="red";}else{ document.getElementById("celda_Licenciataria").style.color="black";}
  if(vacio(MatriculaGas)){OK=false; document.getElementById("celda_MatriculaGas").style.color="red";}else{ document.getElementById("celda_MatriculaGas").style.color="black";}
  if(vacio(Categoria)){OK=false; document.getElementById("celda_Categoria").style.color="red";}else{ document.getElementById("celda_Categoria").style.color="black";}
  var INHABILITAR=CheckToBit(document.getElementById("INHABILITAR"));
  //alert (INHABILITAR);
  if(OK)
  {
   if (confirm("Esta seguro de los datos a cargar"))
    {
     ajax=nuevoAjax();
     ajax.open("POST", "/SICGNC/Cargas/ABM_RTRegionalPEC.php",true);
     ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
		   { 
		    document.getElementById("Datos").innerHTML=ajax.responseText;
		   } 
	   }
	   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       //var Str;
       if(INHABILITAR==1)
        {
        alert("Recuerde que va a inhabilitar al Responsable Técnico");
        Str="TipoOp=3&TipoDoc="+TipoDoc+"&NroDoc="+NroDoc+"&Observaciones="+Observaciones;   
		ajax.send(Str);
       }
       else{
		 Str="TipoOp="+TipoOp+"&Apellido="+Apellido+"&Nombres="+Nombres+"&TipoDoc="+TipoDoc+"&NroDoc="+NroDoc+"&Cuit="+Cuit+"&Domicilio="+Domicilio+"&Provincia="+Provincia+"&Departamento="+Departamento+"&Localidad="+Localidad+"&CPostal="+CPostal+"&AreaTel="+AreaTel+"&Telefono="+Telefono+"&Titulo="+Titulo+"&CjoProfesional="+CjoProfesional+"&MatProfesional="+MatProfesional+"&Licenciataria="+Licenciataria+"&MatriculaGas="+MatriculaGas+"&ALTART="+ALTART+"&FOTODTOLEG="+FOTODTOLEG+"&CERTCJOPROF="+CERTCJOPROF+"&FOTOTITLEG="+FOTOTITLEG+"&AFIP1="+AFIP1+"&CERTDIST="+CERTDIST+"&CERTFIRMA="+CERTFIRMA+"&LABORAL="+LABORAL+"&PagoMatri="+PagoMatri+"&AREAFACSIMIL="+AREAFACSIMIL+"&DDJJNORMATIVA="+DDJJNORMATIVA+"&INCTITPROF="+INCTITPROF+"&INSCAFIP="+INSCAFIP+"&DJJEXCLUSIVO="+DJJEXCLUSIVO+"&Pecs="+Pecs+"&FACSIMIL="+FACSIMIL+"&Mail="+Mail+"&Observaciones="+Observaciones+"&INHABILITAR="+INHABILITAR;
          ajax.send(Str+"&Categoria="+Categoria);
		  }
	}   
  }
  else
    {
	 alert("Hay algunos campos que son obligatorios, verifique los campos en rojo");
	}
 }
}
////////////////////////////////////////////////////////////////////////////////////////

//////////////////////Consulta del Ultimo Rango de Obleas vendidas a PEC/////////////////////////////////
function ObleasVendidasAPec()
{
 var PecCode=document.getElementById("Codigo").value;
  
 if(PecCode!=0)
  {
    ajax=nuevoAjax();
 	ajax.open("GET", "/SICGNC/ResultadoConsulta/DetalleObleasVendidasAPecs.php?PecCode="+PecCode,true);
    ajax.onreadystatechange=function() 
	{ 
	if (ajax.readyState==1)
		    {
			 document.getElementById("ObleasVendidasAPecs").innerHTML="<h2>.....Cargando......</h2>"
			}
	if (ajax.readyState==4)
		{ 
		document.getElementById("ObleasVendidasAPecs").innerHTML=ajax.responseText;
		} 
	}
	ajax.send(null);
  }
  else
     {
	  ajax=nuevoAjax();
	  ajax.open("GET", "/blanco.php", true);
      ajax.onreadystatechange=function() 
	   { 
		 if (ajax.readyState==4)
			 { 
			 document.getElementById("ObleasVendidasAPecs").innerHTML=ajax.responseText;
			 } 
	   }
      ajax.send(null);
	}  
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////
function btnImprimir() {
	if (document.getElementById('DivNoHayDatos')!=undefined) {
		alert('No se seleccionaron datos para imprimir.');
		return;
	}
	if (confirm("¿Está seguro que desea imprimir?"))
		window.open('PlantillaImpresion.php','',"Scrollbars=1,Toolbar=0,Resizable=1,width=200, height=10, top=50, left=50,status=no");		
}




//////////////Completa la fecha y la valida/////////////////////////////////
////////////////////////////////////////////////////////////////////////////
function CambioFecha(fechaT){
	ftext=fechaT.value;
	if (Vacio(ftext)){
		return;
	}
	dia=ftext.substring(0,ftext.indexOf("/",0));
	mes=ftext.substring(dia.length+1,ftext.indexOf("/",dia.length+1));
  	ano=ftext.substring(dia.length+1+mes.length+1,10)
	//alert(dia.length);
	if(dia.length==1) {
		dia="0"+dia;
	}
	if(mes.length==1) {
		mes="0"+mes;
	}
	if(ano.length==2) {
		ano="20"+ano;
	}
	if(ano.length==1) {
		ano="200"+ano;
	}
	fechaT.value=dia+"/"+mes+"/"+ano;
	if (Fecha(fechaT.value)==false) {
		alert('Fecha Invalida');
    	fechaT.focus(); 
		return;
	}
}

function Fecha(ftext){ 
    if ((ftext.substr(2,1) != "/") && (ftext.substr(5,1) != "/")) {
		return false;	
	}      
	for (i=0; i<10; i++) {	
		if (((ftext.substr(i,1)<"0") || (ftext.substr(i,1)>"9")) && (i != 2) && (i != 5)) {
			return false;
		}  
	}
	a = ftext.substr(6,4);
	m = ftext.substr(3,2);
    d = ftext.substr(0,2);
    if((a < 1900) || (a > 2050) || (m < 1) || (m > 12) || (d < 1) || (d > 31)) {
		return false;
	} else {
		if((a%4 != 0) && (m == 2) && (d > 28)) {
			return false; // Año no viciesto y es febrero y el dia es mayor a 28
		} else {
			if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29))) {
			         return false;      				  	 
			}  
		}
	}
	return true;
} 

function fchAno(ftext){ 
    if ((ftext.substr(2,1) != "/") && (ftext.substr(5,1) != "/")) {
		return 0;	
	}      
	for (i=0; i<10; i++) {	
		if (((ftext.substr(i,1)<"0") || (ftext.substr(i,1)>"9")) && (i != 2) && (i != 5)) {
			return 0;
		}  
	}
	a = ftext.substr(6,4);
	m = ftext.substr(3,2);
    d = ftext.substr(0,2);
	
	return a;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
function Vacio(text) {
        for ( i = 0; i < text.length; i++ ) {
                if ( text.charAt(i) != " " ) {
                        return false
                }
        }
        return true
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////Validar y Encritar Clave//////////////////////////////
function ValidarClave()
{
 var User=document.getElementById("Usuario");
 var Pass=document.getElementById("Clave");
 
 if(vacio(User.value) || vacio(Pass.value))
   alert("Debe Ingresar el Usuario y el Password");
 else
    {
     Pass.value=hex_md5(Pass.value);		
     document.FormularioLogin.submit();		


/* var fecha;
fecha="4"
var fecha1= new Date();
var diames=fecha1.getDate();
var mes=fecha1.getMonth();
//alert(fecha1)
//alert(mes)
 if ((fecha > diames && mes=='8') || (fecha == diames  && mes=='8'))
	 {
		 AvisoCorteElectrico();
		 }*/

/* var fecha;
fecha="29"
var fecha1= new Date();
var diames=fecha1.getDate();
//alert(diames)
 if ((fecha > diames) || (fecha == diames))
	 {
		 AvisoCorteElectrico();
		 }	*/

/*var fecha;
var fecha1= new Date();
var diames=fecha1.getDate();
var mes=fecha1.getMonth();
//alert(diames)
//alert(mes)

 if ((diames <=8) )
	 {
		 AvisoManteniemientoD();
		 }*/

}
 
}

function AvisoManteniemientoD()
{
open("Ayudas/Aviso_Mantenimiento.php", "vaviso", "width=450,height=400,directories=no,toolbar=no")
}

//////////////////////////////////////////////////////////////////////////////////////////
function AvisoCorteElectrico()
{
open("Ayudas/Aviso8_GrupoElectro.php", "vaviso", "width=450,height=400,directories=no,toolbar=no")
}
//////////////////////////////////////////////////////////////////////////////////////////






function Contexto()
{
//Esta función verifica el contexto del cliente y da recomendaciones.
var ancho;
var alto;
var explorador;
var version;

ancho=screen.width;
alto=screen.height;
explorador=navigator.appName;
version=navigator.appVersion;

if(ancho<800 && alto<600)
 {
  alert("Para utilizar esta página se necesita una resolución mayor o igual a 800x600");
  setTimeout ("location.href='http://www.enargas.gov.ar'", 1000);
 }
 
/*if(explorador!="Microsoft Internet Explorer")
 {
  alert("Se recomienda el Uso de Internet Explorer 6.x");
 }*/ 
 
}

function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}
/*****************************Alta Talleres***************************************/
/****************************Agregar PECs*****************************************/
/*	var fromBoxArray = new Array();
	var toBoxArray = new Array();
	var selectBoxIndex = 0;*/
//var arrayOfItemsToSelect = new Array();
var fromBoxArray = new Array();
var toBoxArray = new Array();
var selectBoxIndex = 0;

function selectPECs()
{
 var obj = document.getElementById('toBox');
 var aux='';	
 for(var no=0;no<obj.options.length;no++){
  obj.options[no].selected = true;
  if(aux=='')
  {
  	aux=obj.options[no].value;
  }
  else
  {
  	aux= aux +';'+obj.options[no].value;
  }
 }
 document.getElementById('VectorPECs').value=aux;
}


function DetalleTdM()
 {
  var CodigoSujeto= this.value;
  ajax=nuevoAjax();
  ajax.open("POST", "/SICGNC/Cargas/DescripcionTdM.php", true);
  ajax.onreadystatechange=function() 
    { 
	 if (ajax.readyState==4)
	  { 
	   document.getElementById("DescripcionTdM").innerHTML=ajax.responseText;
	  } 
	}
   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   ajax.send("CodigoSujeto="+CodigoSujeto);
}

function DetallePEC()
 {
  var CodigoSujeto= this.value;
  ajax=nuevoAjax();
  ajax.open("POST", "/SICGNC/Cargas/DescripcionPEC.php", true);
  ajax.onreadystatechange=function() 
    { 
	 if (ajax.readyState==4)
	  { 
	   document.getElementById("DescripcionPEC").innerHTML=ajax.responseText;
	  } 
	}
   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   ajax.send("CodigoSujeto="+CodigoSujeto);
}


	function moveSingleElement()
	{
		var selectBoxIndex = this.parentNode.parentNode.id.replace(/[^\d]/g,'');
		var tmpFromBox;
		var tmpToBox;
		if(this.tagName.toLowerCase()=='select'){			
			tmpFromBox = this;
			if(tmpFromBox==fromBoxArray[selectBoxIndex])tmpToBox = toBoxArray[selectBoxIndex]; else tmpToBox = fromBoxArray[selectBoxIndex];
		}else{
		
			if(this.value.indexOf('>')>=0){
				tmpFromBox = fromBoxArray[selectBoxIndex];
				tmpToBox = toBoxArray[selectBoxIndex];			
			}else{
				tmpFromBox = toBoxArray[selectBoxIndex];
				tmpToBox = fromBoxArray[selectBoxIndex];	
			}
		}
		
		for(var no=0;no<tmpFromBox.options.length;no++){
			if(tmpFromBox.options[no].selected){
				tmpFromBox.options[no].selected = false;
				tmpToBox.options[tmpToBox.options.length] = new Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value);
				
				for(var no2=no;no2<(tmpFromBox.options.length-1);no2++){
					tmpFromBox.options[no2].value = tmpFromBox.options[no2+1].value;
					tmpFromBox.options[no2].text = tmpFromBox.options[no2+1].text;
					tmpFromBox.options[no2].selected = tmpFromBox.options[no2+1].selected;
				}
				no = no -1;
				tmpFromBox.options.length = tmpFromBox.options.length-1;
											
			}			
		}
		
		
		var tmpTextArray = new Array();
		for(var no=0;no<tmpFromBox.options.length;no++){
			tmpTextArray.push(tmpFromBox.options[no].text + '___' + tmpFromBox.options[no].value);			
		}
		tmpTextArray.sort();
		var tmpTextArray2 = new Array();
		for(var no=0;no<tmpToBox.options.length;no++){
			tmpTextArray2.push(tmpToBox.options[no].text + '___' + tmpToBox.options[no].value);			
		}		
		tmpTextArray2.sort();
		
		for(var no=0;no<tmpTextArray.length;no++){
			var items = tmpTextArray[no].split('___');
			tmpFromBox.options[no] = new Option(items[0],items[1]);
			
		}		
		
		for(var no=0;no<tmpTextArray2.length;no++){
			var items = tmpTextArray2[no].split('___');
			tmpToBox.options[no] = new Option(items[0],items[1]);			
		}
	}

	
	function sortAllElement(boxRef)
	{
		var tmpTextArray2 = new Array();
		for(var no=0;no<boxRef.options.length;no++){
			tmpTextArray2.push(boxRef.options[no].text + '___' + boxRef.options[no].value);			
		}		
		tmpTextArray2.sort();		
		for(var no=0;no<tmpTextArray2.length;no++){
			var items = tmpTextArray2[no].split('___');
			boxRef.options[no] = new Option(items[0],items[1]);			
		}		
		
	}
	function moveAllElements()
	{
		var selectBoxIndex = this.parentNode.parentNode.id.replace(/[^\d]/g,'');
		var tmpFromBox;
		var tmpToBox;		
		if(this.value.indexOf('>')>=0){
			tmpFromBox = fromBoxArray[selectBoxIndex];
			tmpToBox = toBoxArray[selectBoxIndex];			
		}else{
			tmpFromBox = toBoxArray[selectBoxIndex];
			tmpToBox = fromBoxArray[selectBoxIndex];	
		}
		
		for(var no=0;no<tmpFromBox.options.length;no++){
			tmpToBox.options[tmpToBox.options.length] = new Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value);			
		}	
		
		tmpFromBox.options.length=0;
		sortAllElement(tmpToBox);
		
	}
	
	
	/* This function highlights options in the "to-boxes". It is needed if the values should be remembered after submit. Call this function onsubmit for your form */
	function multipleSelectOnSubmit()
	{
		for(var no=0;no<arrayOfItemsToSelect.length;no++){
			var obj = arrayOfItemsToSelect[no];
			for(var no2=0;no2<obj.options.length;no2++){
				obj.options[no2].selected = true;
			}
		}
		
	}
	
	function createMovableOptions(fromBox,toBox,totalWidth,totalHeight,labelLeft,labelRight)
	{		
		fromObj = document.getElementById(fromBox);
		toObj = document.getElementById(toBox);
		
		//arrayOfItemsToSelect[arrayOfItemsToSelect.length] = toObj;

		
		fromObj.ondblclick = moveSingleElement;
		toObj.ondblclick = moveSingleElement;
              fromObj.onclick = DetallePEC;
		
		fromBoxArray.push(fromObj);
		toBoxArray.push(toObj);
		
		var parentEl = fromObj.parentNode;
		
		var parentDiv = document.createElement('DIV');
		parentDiv.className='multipleSelectBoxControl';
		parentDiv.id = 'selectBoxGroup' + selectBoxIndex;
		parentDiv.style.width = totalWidth + 'px';
		parentDiv.style.height = totalHeight + 'px';
		parentEl.insertBefore(parentDiv,fromObj);
		
		
		var subDiv = document.createElement('DIV');
		subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
		fromObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px';

		var label = document.createElement('SPAN');
		label.innerHTML = labelLeft;
		subDiv.appendChild(label);
		
		subDiv.appendChild(fromObj);
		subDiv.className = 'multipleSelectBoxDiv';
		parentDiv.appendChild(subDiv);
		
		
		var buttonDiv = document.createElement('DIV');
		buttonDiv.style.verticalAlign = 'middle';
		buttonDiv.style.paddingTop = (totalHeight/2) - 50 + 'px';
		buttonDiv.style.width = '30px';
		buttonDiv.style.textAlign = 'center';
		parentDiv.appendChild(buttonDiv);
		
		var buttonRight = document.createElement('INPUT');
		buttonRight.type='button';
		buttonRight.value = '>';
		buttonDiv.appendChild(buttonRight);	
		buttonRight.onclick = moveSingleElement;	
		
		var buttonAllRight = document.createElement('INPUT');
		buttonAllRight.type='button';
		buttonAllRight.value = '>>';
		buttonAllRight.onclick = moveAllElements;
		buttonDiv.appendChild(buttonAllRight);		
		
		var buttonLeft = document.createElement('INPUT');
		buttonLeft.style.marginTop='10px';
		buttonLeft.type='button';
		buttonLeft.value = '<';
		buttonLeft.onclick = moveSingleElement;
		buttonDiv.appendChild(buttonLeft);		
		
		var buttonAllLeft = document.createElement('INPUT');
		buttonAllLeft.type='button';
		buttonAllLeft.value = '<<';
		buttonAllLeft.onclick = moveAllElements;
		buttonDiv.appendChild(buttonAllLeft);
		
		var subDiv = document.createElement('DIV');
		subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
		toObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px';

		var label = document.createElement('SPAN');
		label.innerHTML = labelRight;
		subDiv.appendChild(label);
				
		subDiv.appendChild(toObj);
		parentDiv.appendChild(subDiv);		
		
		toObj.style.height = (totalHeight - label.offsetHeight) + 'px';
		fromObj.style.height = (totalHeight - label.offsetHeight) + 'px';

			
		selectBoxIndex++;
		
	}


////////////////////////////////Fin Agregar PECs//////////////////////////////////////	
///////////////////////////////Mostrar Ayuda/////////////////////////////////////////
function MostrarAyuda(TipoAyuda)
{
 if(TipoAyuda=="CargaTaller")
   window.open("/SICGNC/Ayudas/Ayuda_Alta.php","VentanaAyudaCargaTaller","width=590,height=400,scrollbars=YES"); 
 if(TipoAyuda=="ModificacionTaller")
   window.open("/SICGNC/Ayudas/Ayuda_Modifica.php","VentanaAyudaModificacionTaller","width=590,height=400,scrollbars=YES");
 if(TipoAyuda=="BajaTaller")
   window.open("/SICGNC/Ayudas/Ayuda_Baja.php","VentanaAyudaBajaTaller","width=590,height=400,scrollbars=YES");
if(TipoAyuda=="IDIOC")
   window.open("/SICGNC/Ayudas/Ayuda_IDIOc.php","VentanaAyudaIDIOC","width=590,height=400,scrollbars=YES");
}
////////////////////////////////////////////////////////////////////////////////////
/****************************Alta RTs************************************************/
function MostrarFormNewRT(Nuevo)
{
 //*****************Si IdRTTaller es 0 Muestra el Formulario Vacío*************/
 var TipoDoc=document.getElementById("TipoDoc").value;
 var NumDoc=document.getElementById("NroDocumento").value; 
 window.open("/SICGNC/Cargas/MostrarDatosRTTaller.php?Nuevo="+Nuevo+"&TipoDoc="+TipoDoc+"&NumDoc="+NumDoc,"VentanaDatosRT","width=400,height=300,scrollbars=YES");
  }
 
function SacarRTs()
{
 document.getElementById("RTsAgregados").options[document.getElementById("RTsAgregados").selectedIndex]=null;
} 
//////////////////////////////Fin RTs/////////////////////////////////////////////////
/**************************Validaciones para la el Alta del Taller***************************/
//////////////////////////si Tipo es 1 es un alta normal si es 0 /////////////////////
function AltaModificacionTaller(Tipo)
{
 if (Tipo==1) //Es un Alta Tipo==2 es una modificacion
  {
   var CodigoTaller=document.getElementById("CodigoTaller").value; 
   var Cuit=document.getElementById("Cuit").value; 
   var BocaExpendio=document.getElementById("BocaExpendio").value; 
   var RazonSocial=document.getElementById("RazonSocial").value; 
   var Telefono=document.getElementById("Telefono").value; 
   var Direccion=document.getElementById("Direccion").value; 
   var Fax=document.getElementById("Fax").value; 
   var Localidad=document.getElementById("Localidad").value; 
   var Departamento=document.getElementById("Departamento").value; 
   var Email=document.getElementById("Email").value; 
   var Provincia=document.getElementById("Provincia").value; 
   var CPostal=document.getElementById("CPostal").value; 
   var FechaCertificacion=document.getElementById("FechaCertificacion"); 
   var Vencimiento=document.getElementById("Vencimiento"); 
   var Observaciones=document.getElementById("Observaciones").value; 
   selectPECs();
   //agrego los pecs y luego los asigno a una variable
   var Pecs=document.getElementById("VectorPECs").value; 
   var OK=true;
   var OKPECs=true;
   var OKRTs=true;  
   //Asigno los RTs
   var RTs=new Array();
   var obj = document.getElementById('RTsAgregados');
   for(var no=0;no<obj.options.length;no++)
    {  
     RTs[no]=obj.options[no].value;
    }
   /////////////////////
   ///////////////Validaciones de Campos///////////////////////////
   if(ValidarCodigoTaller(CodigoTaller)){OK=false; document.getElementById("celda_CodigoTaller").style.color="red";}else{ document.getElementById("celda_CodigoTaller").style.color="black";}
     //alert(OK);
  if(!ValidarCuit(Cuit)){OK=false; document.getElementById("divCuit").style.color="red";}else{ document.getElementById("divCuit").style.color="black";}
     // alert(OK);
   if(ValidarBocaExpendio(BocaExpendio)){OK=false; document.getElementById("divCaja").style.color="red";}else{ document.getElementById("divCaja").style.color="black";}   if(vacio(RazonSocial) || ValidarCaracteresRaros(RazonSocial)){OK=false; document.getElementById("celda_RazonSocial").style.color="red";}else{ document.getElementById("celda_RazonSocial").style.color="black";}
      //alert(OK);
   if(vacio(Telefono) || ValidarCaracteresRaros(Telefono)){OK=false; document.getElementById("celda_Telefono").style.color="red";}else{ document.getElementById("celda_Telefono").style.color="black";}
       //alert(OK);
   if(vacio(Direccion) || ValidarCaracteresRaros(Direccion)){OK=false; document.getElementById("celda_Direccion").style.color="red";}else{ document.getElementById("celda_Direccion").style.color="black";}


  if(Provincia=="0" || Departamento=="0" || Localidad=="0")
     {
     OK=false; 
     document.getElementById("celda_Departamento").style.color="red";
     document.getElementById("celda_Localidad").style.color="red";
     document.getElementById("celda_Provincia").style.color="red";
     }
   else
    {
     document.getElementById("celda_Departamento").style.color="black";
     document.getElementById("celda_Localidad").style.color="black";
     document.getElementById("celda_Provincia").style.color="black";
    }
     //alert(OK);
   if(vacio(CPostal)){OK=false; document.getElementById("celda_CPostal").style.color="red";}else{ document.getElementById("celda_CPostal").style.color="black";}
      // alert(OK);  
   if (!valFecha(FechaCertificacion) && !valFecha(Vencimiento))
     {
	  document.getElementById("celda_Vencimiento").style.color="black";
	  document.getElementById("celda_FechaCertificacion").style.color="black";
	  }
   else{ 
      OK=false;
      document.getElementById("celda_Vencimiento").style.color="red";
	  document.getElementById("celda_FechaCertificacion").style.color="red";
	  } 
	 
     //alert(OK);
   if(vacio(Pecs)){OKPECs=false; document.getElementById("celda_Pecs").style.color="red";}else{ document.getElementById("celda_Pecs").style.color="black";}
   if(RTs.length==0){OKRTs=false;}
   

   

/*   alert(OK);
   alert(OKPECs);
   alert(OKRTs);*/

   if(OK && OKPECs && OKRTs)
    {
	 if(confirm("¿Está seguro de los datos a Cargar?"))
	  {
       ajax=nuevoAjax();
       ajax.open("POST", "/SICGNC/Cargas/ABM_Taller.php", true);
       ajax.onreadystatechange=function() 
	    { 
	     if (ajax.readyState==1)
	       {
		    document.getElementById("AltaTaller").innerHTML="<h2>.....Cargando......</h2>"
	       }
	     if (ajax.readyState==4)
	       { 
		    document.getElementById("AltaTaller").innerHTML=ajax.responseText;
	       } 
	    }
	  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	  ajax.send("Tipo=1&CodigoTaller="+CodigoTaller+"&Cuit="+Cuit+"&CPostal="+CPostal+"&FechaCertificacion="+FechaCertificacion.value+"&BocaExpendio="+BocaExpendio+"&RazonSocial="+RazonSocial+"&Telefono="+Telefono+"&Direccion="+Direccion+"&Localidad="+Localidad+"&Provincia="+Provincia+"&CPostal="+CPostal+"&Fax="+Fax+"&Email="+Email+"&Observaciones="+Observaciones+"&Vencimiento="+Vencimiento.value+"&PECs="+Pecs+"&RTs="+RTs+"&Id_Departamento="+Departamento);
	  }
    }
    else
	   alert ("Datos Incompletos");
 }
 if(Tipo==2) //Modificacion Taller
  {
     var CodigoTaller=document.getElementById("CodigoTaller").value; 
     var Cuit=document.getElementById("Cuit").value; 
     var BocaExpendio=document.getElementById("BocaExpendio").value; 
     var RazonSocial=document.getElementById("RazonSocial").value; 
     var Telefono=document.getElementById("Telefono").value; 
     var Direccion=document.getElementById("Direccion").value; 
     var Fax=document.getElementById("Fax").value; 
     var Localidad=document.getElementById("Localidad").value; 
     var Departamento=document.getElementById("Departamento").value;
     var Email=document.getElementById("Email").value; 
     var Provincia=document.getElementById("Provincia").value; 
     var CPostal=document.getElementById("CPostal").value; 
     var FechaCertificacion=document.getElementById("FechaCertificacion"); 
     var Vencimiento=document.getElementById("Vencimiento"); 
     var Observaciones=document.getElementById("Observaciones").value; 
	 var Renovacion=document.getElementById("Renovacion").value; 
	 var Otros=document.getElementById("Otros").value; 
     selectPECs();
     //agrego los pecs y luego los asigno a una variable
     var Pecs=document.getElementById("VectorPECs").value; 
     var OK=true;
     var OKPECs=true;
     var OKRTs=true;  
     //Asigno los RTs
     var RTs=new Array();
     var obj = document.getElementById('RTsAgregados');
     for(var no=0;no<obj.options.length;no++)
      {  
       RTs[no]=obj.options[no].value;
      }

  /* alert(CodigoTaller);
   alert(Cuit);
   alert(BocaExpendio);
   alert(RazonSocial);
   alert(Telefono);
   alert(Direccion);
   alert(Fax);
   alert(Localidad);
   alert(Email);
   alert(Provincia);
   alert(CPostal);
   alert(FechaCertificacion);
   alert(Vencimiento);
   alert(Observaciones);
   alert(Renovacion);
   alert(Otros);*/
 
   /////////////////////
   ///////////////Validaciones de Campos///////////////////////////
   if(!ValidarCuit(Cuit)){OK=false; document.getElementById("celda_CuityCaja").style.color="red";}else{ document.getElementById("celda_CuityCaja").style.color="black";}
   if(vacio(RazonSocial) || ValidarCaracteresRaros(RazonSocial)){OK=false; document.getElementById("celda_RazonSocial").style.color="red";}else{ document.getElementById("celda_RazonSocial").style.color="black";}
   if(vacio(Telefono) || ValidarCaracteresRaros(Telefono)){OK=false; document.getElementById("celda_Telefono").style.color="red";}else{ document.getElementById("celda_Telefono").style.color="black";}
   if(vacio(Direccion) || ValidarCaracteresRaros(Direccion)){OK=false; document.getElementById("celda_Direccion").style.color="red";}else{ document.getElementById("celda_Direccion").style.color="black";}
  
   
   if((Provincia=="0") || (Departamento=="0") || (Localidad=="0"))
     {
     OK=false; 
     document.getElementById("celda_Departamento").style.color="red";
     document.getElementById("celda_Localidad").style.color="red";
     document.getElementById("celda_Provincia").style.color="red";
     }
   else
    {
     document.getElementById("celda_Departamento").style.color="black";
     document.getElementById("celda_Localidad").style.color="black";
     document.getElementById("celda_Provincia").style.color="black";
    }

   if(vacio(CPostal)){OK=false; document.getElementById("celda_CPostal").style.color="red";}else{ document.getElementById("celda_CPostal").style.color="black";}
       
   if (!valFecha(FechaCertificacion) && !valFecha(Vencimiento))
     {
	  document.getElementById("celda_Vencimiento").style.color="black";
	  document.getElementById("celda_FechaCertificacion").style.color="black";
	  }
   else{ 
      OK=false;
      document.getElementById("celda_Vencimiento").style.color="red";
	  document.getElementById("celda_FechaCertificacion").style.color="red";
	  } 
	 
   if(vacio(Pecs)){OKPECs=false; document.getElementById("celda_Pecs").style.color="red";}else{ document.getElementById("celda_Pecs").style.color="black";}
   if(RTs.length==0){OKRTs=false;}
   
  if(OK && OKPECs && OKRTs)
    {
	 if(confirm("¿Está seguro de los datos a Cargar?"))
	  {
      ajax=nuevoAjax();
      ajax.open("POST", "/SICGNC/Cargas/ABM_Taller.php", true);
      ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==1)
	      {
		   document.getElementById("ModificacionTaller").innerHTML="<h2>.....Cargando......</h2>"
	      }
	    if (ajax.readyState==4)
	      { 
		   document.getElementById("ModificacionTaller").innerHTML=ajax.responseText;
	      } 
	   }
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 ajax.send("Tipo=2&Renovacion="+Renovacion+"&Otros="+Otros+"&CodigoTaller="+CodigoTaller+"&Cuit="+Cuit+"&CPostal="+CPostal+"&FechaCertificacion="+FechaCertificacion.value+"&BocaExpendio="+BocaExpendio+"&RazonSocial="+RazonSocial+"&Telefono="+Telefono+"&Direccion="+Direccion+"&Localidad="+Localidad+"&Provincia="+Provincia+"&CPostal="+CPostal+"&Fax="+Fax+"&Email="+Email+"&Observaciones="+Observaciones+"&Vencimiento="+Vencimiento.value+"&PECs="+Pecs+"&RTs="+RTs+"&Id_Departamento="+Departamento);
    }
   }	
    else
	   alert ("Datos Incompletos");
  }
}  

function ValidarCaracteresRaros(Cadena)
{
 var patron=/;|#|"|&|@|\$|'|\||%|\*|\{|\}|~|\+|\[|\]|\^|\?|¿|¡|!/;
 return patron.test(Cadena);
}

function ValidarCodigoTaller(CodigoTaller)
{
var patron=/^\d{4}$/;
    if(CodigoTaller.search(patron)) 
	  return true;
	  else
	      return false; 
}

function ValidarBocaExpendio(Valor)
{
var patron=/^\d{4}$/;
    if(Valor.search(patron)) 
	  return true;
	  else
	      return false; 
}

////////////////////////////////////Cargar Provincias, Dtos, Localidades///////////////
///////////////////////////////Dtos segun la provincia////////////////////////////////
function CargarDepartamento()
{
	var CodigoProvincia=document.getElementById("Provincia").options[document.getElementById("Provincia").selectedIndex].value;
	if(CodigoProvincia==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("Departamento");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="----Seleccionar----";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
		
		combo2=document.getElementById("Localidad");
		combo2.length=0;
		var nuevaOpcion2=document.createElement("option"); 
		nuevaOpcion2.value=0;
		nuevaOpcion2.innerHTML="----Seleccionar----";
		combo2.appendChild(nuevaOpcion2);	
		combo2.value=0;
		combo2.disabled=true;
	}
	else
	{
	//Código de Homologación según la marca y el tipo de componente
	    ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/CargarDepartamentos.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				combo=document.getElementById("Departamento");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celdaDepartamento").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("CodigoProvincia="+CodigoProvincia);	
	}

}

function CargarLocalidad(CodigoProvincia)
{
	var CodigoDepartamento=document.getElementById("Departamento").options[document.getElementById("Departamento").selectedIndex].value;
	if(CodigoDepartamento==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("Localidad");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="----Seleccionar----";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
	}
	else
	{
	//Código de Homologación según la marca y el tipo de componente
	    ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/CargarLocalidad.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				combo=document.getElementById("Localidad");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celdaLocalidad").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("CodigoProvincia="+CodigoProvincia+"&CodigoDepartamento="+CodigoDepartamento);	
	}

}

//////////////////////////////Fin Alta Taller//////////////////////////////////////////

//////////////////////////////Modificacion Taller//////////////////////////////////////
function MuestraDatosTaller()
{
  var CodigoTaller=document.getElementById("CodigoTaller").value;
  var Renovacion=document.getElementById("Renovacion");
  var Otros=document.getElementById("Otros");

 if(CodigoTaller!="0")
   {
   if (Renovacion.checked || Otros.checked) 
	  {
	    if(Renovacion.checked)
		  Renovacion.value=1;
		else  
		  Renovacion.value=0;
		  
		if(Otros.checked)
		   Otros.value=1;
		else
		   Otros.value=0;      
        document.FormularioTaller.submit();
	 }	 
	else
	    alert("Debe Ingresar algún tipo de modificación");   
 }	
}

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Baja Talleres y Carga de No Certificados////////////////
function BajaTaller_NoCertificacion()
{
/*Con esta función muestro los datos de un taller a dar de baja si me ingresan un 
código de taller distinto de cero o muestro un formulario para dar de baja un taller 
que no certifico si el codigo de taller es cero*/
var CodigoTaller=document.getElementById("CodigoTaller").value;
ajax=nuevoAjax();
ajax.open("POST", "/SICGNC/Cargas/B_DatosTallerABaja.php", true);
ajax.onreadystatechange=function() 
  { 
   if (ajax.readyState==1)
	 {
	  document.getElementById("DatosTallerABaja").innerHTML="<h2>.....Cargando......</h2>"
	  }
   if (ajax.readyState==4)
	 { 
	  document.getElementById("DatosTallerABaja").innerHTML=ajax.responseText;
	 } 
  }
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
if (CodigoTaller=="0")
  ajax.send("Tipo=3");  
else
   ajax.send("Tipo=4&CodigoTaller="+CodigoTaller);  
}

function BajaTaller(TipoBaja)
{

if (TipoBaja=="4")
 {
   var Observaciones=document.getElementById("Observaciones").value;
   var OK=true;
   if (vacio(Observaciones))
     {
	  OK=false;
	  document.getElementById("celda_Observaciones").style.color="red";
	  }
   else
      { 
	  document.getElementById("celda_Observaciones").style.color="black";
      }
  if(OK)	
    {  
     if(confirm("¿ Esta seguro de los datos del taller a dar de baja ?")) 
         document.BajaTallerHabilitado.submit();
	}
  else
      alert("Debe indicar una observación por la baja del Taller"); 	 
 }
if (TipoBaja=="3") 
 {
   var RazonSocial=document.getElementById("RazonSocial").value;
   var Cuit=document.getElementById("Cuit").value;
   var BocaExpendio=document.getElementById("BocaExpendio").value;
   var Direccion=document.getElementById("Direccion").value;
   var Localidad=document.getElementById("Localidad").value;
   var Provincia=document.getElementById("Provincia").value;
   var Departamento=document.getElementById("Departamento").value;
   var CPostal=document.getElementById("CPostal").value;
   var Telefono=document.getElementById("Telefono").value;
   var Fax=document.getElementById("Fax").value;
   var Email=document.getElementById("Email").value;
   var Observaciones=document.getElementById("Observaciones").value;
   var FechaNoCertificacion=document.getElementById("FechaNoCertificacion");
   var OK=true;
  
   if(!ValidarCuit(Cuit)){OK=false; document.getElementById("celda_CuityCaja").style.color="red";}else{ document.getElementById("celda_CuityCaja").style.color="black";}
   if(ValidarBocaExpendio(BocaExpendio)){OK=false; document.getElementById("celda_CuityCaja").style.color="red";}else{ document.getElementById("celda_CuityCaja").style.color="black";}
   if(vacio(RazonSocial) || ValidarCaracteresRaros(RazonSocial)){OK=false; document.getElementById("celda_RazonSocial").style.color="red";}else{ document.getElementById("celda_RazonSocial").style.color="black";}
   if(vacio(Telefono) || ValidarCaracteresRaros(Telefono)){OK=false; document.getElementById("celda_Telefono").style.color="red";}else{ document.getElementById("celda_Telefono").style.color="black";}
   if(vacio(Direccion) || ValidarCaracteresRaros(Direccion)){OK=false; document.getElementById("celda_Direccion").style.color="red";}else{ document.getElementById("celda_Direccion").style.color="black";}
   /*if(vacio(Localidad) || ValidarCaracteresRaros(Localidad)){OK=false; document.getElementById("celda_Localidad").style.color="red";}else{ document.getElementById("celda_Localidad").style.color="black";}
   if(Provincia=="0"){OK=false; document.getElementById("celda_Provincia").style.color="red";}else{ document.getElementById("celda_Provincia").style.color="black";}*/
   if(vacio(CPostal)){OK=false; document.getElementById("celda_CPostal").style.color="red";}else{ document.getElementById("celda_CPostal").style.color="black";}
   if(vacio(Observaciones)){OK=false; document.getElementById("celda_Observaciones").style.color="red";}else{ document.getElementById("celda_Observaciones").style.color="black";}
   
   if(Provincia=="0" || Departamento=="0" || Localidad=="0")
     {
     OK=false; 
     document.getElementById("celda_Departamento").style.color="red";
     document.getElementById("celda_Localidad").style.color="red";
     document.getElementById("celda_Provincia").style.color="red";
     }
   else
    {
     document.getElementById("celda_Departamento").style.color="black";
     document.getElementById("celda_Localidad").style.color="black";
     document.getElementById("celda_Provincia").style.color="black";
    }

   if (!valFecha(FechaNoCertificacion))
     {
	  document.getElementById("celda_FechaNoCertificacion").style.color="black";
	  }
   else{ 
      OK=false;
	  document.getElementById("celda_FechaNoCertificacion").style.color="red";
	  } 

   if(OK)
    { 
	  if(confirm("¿Está seguro de los datos a Cargar?"))
	   {
	   ajax=nuevoAjax();
       ajax.open("POST", "/SICGNC/Cargas/ABM_Taller.php", true);
       ajax.onreadystatechange=function() 
	    { 
	     if (ajax.readyState==1)
	       {
		    document.getElementById("DatosTallerABaja").innerHTML="<h2>.....Cargando......</h2>";
	       }
	     if (ajax.readyState==4)
	       { 
		    document.getElementById("DatosTallerABaja").innerHTML=ajax.responseText;
	       } 
	    }
	  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	  ajax.send("Tipo=3&Cuit="+Cuit+"&CPostal="+CPostal+"&FechaNoCertificacion="+FechaNoCertificacion.value+"&BocaExpendio="+BocaExpendio+"&RazonSocial="+RazonSocial+"&Telefono="+Telefono+"&Direccion="+Direccion+"&Localidad="+Localidad+"&Provincia="+Provincia+"&CPostal="+CPostal+"&Fax="+Fax+"&Email="+Email+"&Observaciones="+Observaciones);
	  }
    }
    else
	   alert ("Existen Datos Incompletos, Verifique los campos en Rojo");
 }
}

///////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////Alta de Certificados de PECs y CRPCs por parte de los OC//////////////
function MostrarDatosSujeto(Sujeto)
{
var CodigoSujeto=document.getElementById("CodigoSujeto").value;
if (CodigoSujeto=="0")
 {
      ajax=nuevoAjax();
      ajax.open("GET", "/SICGNC/blanco.php", true);
      ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==4)
	      { 
		   document.getElementById("DatosSujeto").innerHTML=ajax.responseText;
	      } 
	   }
	 ajax.send(null);
 }
 else
    {
	  ajax=nuevoAjax();
      ajax.open("POST", "/SICGNC/Cargas/MostrarDatosSujeto.php", true);
      ajax.onreadystatechange=function() 
	   { 
	    if (ajax.readyState==1)
	      {
		   document.getElementById("DatosSujeto").innerHTML="<h2>.....Cargando......</h2>";
	      }
	    if (ajax.readyState==4)
	      { 
		   document.getElementById("DatosSujeto").innerHTML=ajax.responseText;
	      } 
	   }
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 ajax.send("TipoSujeto="+Sujeto+"&CodigoSujeto="+CodigoSujeto);
	
	}
}

function AltaCertificadoSujeto(TipoSujeto)
{
 var CodigoSujeto=document.getElementById("CodigoSujeto").value;
 var NroCertificado=document.getElementById("NroCertificado").value;
 var MatriculaOC=document.getElementById("MatriculaOC").value;
 var Vencimiento=document.getElementById("Vencimiento");
 var Observaciones=document.getElementById("Observaciones").value;
 var OK=true;
 
 if(vacio(NroCertificado) || ValidarCaracteresRaros(NroCertificado)){OK=false; document.getElementById("celda_NroCertificado").style.color="red";}else{ document.getElementById("celda_NroCertificado").style.color="black";}
 if(vacio(MatriculaOC) || ValidarCaracteresRaros(MatriculaOC)){OK=false; document.getElementById("celda_MatriculaOrganismo").style.color="red";}else{ document.getElementById("celda_MatriculaOrganismo").style.color="black";}
 if(valFecha(Vencimiento)){OK=false; document.getElementById("celda_Vencimiento").style.color="red";}else{ document.getElementById("celda_Vencimiento").style.color="black";}
 if(vacio(Observaciones)){OK=false; document.getElementById("celda_Observaciones").style.color="red";}else{ document.getElementById("celda_Observaciones").style.color="black";}
 

 if(OK)
  {
     if(confirm("¿Está seguro de los datos a dar de Alta?"))
	 {
       ajax=nuevoAjax();
       ajax.open("POST", "/SICGNC/Cargas/AltaCertificadoSujeto.php", true);
       ajax.onreadystatechange=function() 
	    { 
	     if (ajax.readyState==1)
	       {
		    document.getElementById("AltaCertificado").innerHTML="<h2>.....Cargando......</h2>";
	       }
	     if (ajax.readyState==4)
	       { 
		    document.getElementById("AltaCertificado").innerHTML=ajax.responseText;
	       } 
	    }
	  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	  ajax.send("TipoSujeto="+TipoSujeto+"&CodigoSujeto="+CodigoSujeto+"&NroCertificado="+NroCertificado+"&MatriculaOC="+MatriculaOC+"&Vencimiento="+Vencimiento.value+"&Observaciones="+Observaciones);  
	 } 
  }
  else
      alert("Algunos campos están vacíos o están mal ingresados. Verifique los campos en rojo");
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
function CargaDetalle(TipoConsulta,Dispositivo)
{
 //Para el caso de que dispositivo sea cero, no lo uso 
 //pero me sirve para no repetir tanto el case
    switch (TipoConsulta)
	{
	 case "Documento": var TipoDoc=document.getElementById("TipoDoc").value;
					   var NumDoc=allTrim(document.getElementById("NumDoc").value); 
					   var patron=/^\d{2}-\d{8}-\d{1}|\d{2}-\d{8}\/\d{1}|\d{6,8}$/;
    				  if(!NumDoc.search(patron)){					   
					   ajax=nuevoAjax();
					   ajax.open("POST", "/SICGNC/CargaDetalle.php", true);
					   ajax.onreadystatechange=function() 
						{ 
						 if (ajax.readyState==1)
						   {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						   }
					     if (ajax.readyState==4)
							{ 
							document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							} 
						}
					  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					  ajax.send("codigo1="+TipoConsulta+"&codigo2="+TipoDoc+"&codigo3="+NumDoc);
					  }
					  else{
					       alert("Datos Ingresados no válidos");
						   document.getElementById("NumDoc").value="";
					      }
	 break;
	 case "Dispositivo":var Marca=document.getElementById("Marca").value;
					    var NroSerie=document.getElementById("NroSerie").value; 
					    ajax=nuevoAjax();
					    ajax.open("POST", "/SICGNC/CargaDetalle.php", true);
					    ajax.onreadystatechange=function() 
						 { 
						  if (ajax.readyState==1)
						   {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						   }
					      if (ajax.readyState==4)
							 { 
							 document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							 } 
						 }
					    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					    ajax.send("codigo1="+TipoConsulta+"&codigo2="+Marca+"&codigo3="+NroSerie+"&codigo4="+Dispositivo);
	 break;
	 case "Oblea":     var Aux=allTrim(document.getElementById("Oblea").value);
	                   var patron=/^\d{6,8}|M\d{6}|\d{8}\/08$/;
					   var Oblea;
    				   if(!Aux.search(patron)){ 
					     patron=/^M\d{6}$/;
						 patron2=/^\d{8}\/08$/;
						 if(!Aux.search(patron) || !Aux.search(patron2))
						   if (!Aux.search(patron))
						     Oblea=TranfObleaMoto(Aux);
						   else
						     Oblea=TranfObleaRepetida(Aux); 
						 else
						   Oblea=Aux;
					     ajax=nuevoAjax();
					     ajax.open("POST", "/SICGNC/CargaDetalle.php", true);
					     ajax.onreadystatechange=function() 
						  { 
						   if (ajax.readyState==1)
						    {
						     document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						    }
					       if (ajax.readyState==4)
							 { 
							 document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							 } 
						 }
					   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					   ajax.send("codigo1="+TipoConsulta+"&codigo2="+Oblea);}
					  else{
					      alert("Datos Ingresados no válidos"); 
						  document.getElementById("Oblea").value="";
						  }
	 break;

     case "ObleaAnterior":/*var ObleaAnterior=allTrim(document.getElementById("ObleaAnterior").value);
	                      var patron=/^\d{6,8}|M\d{5}$/;
    				      if(!ObleaAnterior.search(patron)){ 
						     patron=/^M\d{5}$/;
						     if(!ObleaAnterior.search(patron))
						       ObleaAnterior=TranfObleaMoto(ObleaAnterior);
                                          else
                                     
					        ajax=nuevoAjax();
					        ajax.open("POST", "/SICGNC/CargaDetalle.php", true);
					        ajax.onreadystatechange=function() 
						     { 
						      if (ajax.readyState==1)
						       {
						        document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						       }
					          if (ajax.readyState==4)
							   { 
							    document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							   } 
						    }
					       ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					       ajax.send("codigo1="+TipoConsulta+"&codigo2="+ObleaAnterior);}
					      else{
					         alert("Datos Ingresados no válidos"); 
						  document.getElementById("ObleaAnterior").value="";
						   }*/
				 var Aux=allTrim(document.getElementById("ObleaAnterior").value);
	                   var patron=/^\d{6,8}|M\d{6}|\d{8}\/08$/;
					   var Oblea;
    				   if(!Aux.search(patron)){ 
					     patron=/^M\d{6}$/;
						 patron2=/^\d{8}\/08$/;
						 if(!Aux.search(patron) || !Aux.search(patron2))
						   if (!Aux.search(patron))
						     Oblea=TranfObleaMoto(Aux);
						   else
						     Oblea=TranfObleaRepetida(Aux); 
						 else
						   Oblea=Aux;
					     ajax=nuevoAjax();
					     ajax.open("POST", "/SICGNC/CargaDetalle.php", true);
					     ajax.onreadystatechange=function() 
						  { 
						   if (ajax.readyState==1)
						    {
						     document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						    }
					       if (ajax.readyState==4)
							 { 
							 document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							 } 
						 }
					   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					   ajax.send("codigo1="+TipoConsulta+"&codigo2="+Oblea);}
					  else{
					      alert("Datos Ingresados no válidos"); 
						  document.getElementById("ObleaAnterior").value="";
						  }




	 break;
	 case "Lotes":     var Marca=document.getElementById("Marca").value;
					   var CodigoHomologacion=document.getElementById("CodigoHomologacion").value;
					   var NroSerie=document.getElementById("NroSerie").value; 
					   ajax=nuevoAjax();
					   ajax.open("POST", "/SICGNC/CargaDetalle.php");
					   ajax.onreadystatechange=function() 
						{ 
						if (ajax.readyState==1)
						   {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						   }
					     if (ajax.readyState==4)
							{ 
							document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							} 
						}
					  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					  ajax.send("codigo1="+TipoConsulta+"&codigo2="+Marca+"&codigo3="+CodigoHomologacion+"&codigo4="+NroSerie+"&codigo5="+Dispositivo);
	 break;
 	 case "RegistroIDI": var Marca=document.getElementById("Marca").value;
					   	 var NroSerie=document.getElementById("NroSerie").value; 
					     ajax=nuevoAjax();
					     ajax.open("POST", "/SICGNC/CargaDetalle.php", true);
					     ajax.onreadystatechange=function() 
					    	{
							if (ajax.readyState==1)
						   {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						   } 
					       if (ajax.readyState==4)
							 { 
							  document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							 } 
						    }
					  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					  ajax.send("codigo1="+TipoConsulta+"&codigo2="+Marca+"&codigo3="+NroSerie+"&codigo4="+Dispositivo);
	 break;	 
	 case "RegistroCRPC": var Marca=document.getElementById("Marca").options[document.getElementById("Marca").selectedIndex].value;
					      var NroSerie=document.getElementById("NroSerie").value; 
					      ajax=nuevoAjax();
					      ajax.open("POST", "/SICGNC/CargaDetalle.php", true);
					      ajax.onreadystatechange=function() 
					    	 { 
							 if (ajax.readyState==1)
						     {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						     }
					        if (ajax.readyState==4)
							  { 
							   document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							  } 
						     }
					      ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					      ajax.send("codigo1="+TipoConsulta+"&codigo2="+Marca+"&codigo3="+NroSerie);
	 break;	 
	  case "Dominio":     var Dominio=allTrim(document.getElementById("Dominio").value);
	                    //  if(!ValidarDominio(Dominio))
				//		  {
						   ajax=nuevoAjax();
					       ajax.open("POST", "/SICGNC/CargaDetalle.php", true);
					       ajax.onreadystatechange=function() 
						    { 
						     if (ajax.readyState==1)
						    {
						     document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						    }
					         if (ajax.readyState==4)
							  { 
							  document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							  } 
						    }
					      ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					      ajax.send("codigo1="+TipoConsulta+"&codigo2="+Dominio);
					//	  }
					/*	 else
						   {
						   alert("Datos Ingresados no válidos"); 
						   document.getElementById("Dominio").value="";
						   }*/
	 break;
 	case "Certificado": var NroCert=document.getElementById("NroCert").value;
					     var patron=/^([A-Z]{4}|[A-Z]{3}[0-9]|[a-z]{4}|[a-z]{3}[0-9])\d{6}$/;
				if(!NroCert.search(patron)){					   
					   ajax=nuevoAjax();
					   ajax.open("POST", "/SICGNC/CargaDetalle.php", true);
					   ajax.onreadystatechange=function() 
						{ 
						 if (ajax.readyState==1)
						   {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						   }
						 /*if (ajax.readyState==2)
						   {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando2......</h2>"
						   }
 							if (ajax.readyState==3)
						   {
						    document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando3.....</h2>"
						   }*/
					     if (ajax.readyState==4)
							{ 
							document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							} 
						}
					  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					  ajax.send("codigo1="+TipoConsulta+"&codigo2="+NroCert);
					  }
					  else{
					       alert("El dato ingresado no corresponde con el formato de los Certificados");
						   document.getElementById("NroCert").value="";
					      }
	 break;	 	 
	}
}
/**************************Lotes de Dispositivos*************************************/
function AltaLoteDispositivos(TipoDispositivo)
{
 var FechaAprobacion=document.getElementById("FechaAprobacion");
 var NroCertificado=document.getElementById("NroCertificado").value;
 var Marca=document.getElementById("Marca").options[document.getElementById("Marca").selectedIndex].value;
 var NroCodigoHomologado_aux=document.getElementById("CodHomolog").value;
 var NroCodigoHomologado=NroCodigoHomologado_aux.split(";");
 var Desde=document.getElementById("Desde").value;
 var Hasta=document.getElementById("Hasta").value;
 var Cantidad=document.getElementById("Cantidad").value;
 var OK= true;
 var OK_FormatNroSerie=true; 
 
 if(valFecha(FechaAprobacion)){OK=false; document.getElementById("celda_FechaAprobacion").style.color="red";}else{ document.getElementById("celda_FechaAprobacion").style.color="black";}
 if(vacio(NroCertificado)){OK=false; document.getElementById("celda_nroCertificado").style.color="red";}else{ document.getElementById("celda_nroCertificado").style.color="black";}
 if(Marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red";}else{ document.getElementById("celda_marca_color").style.color="black";}
 if(vacio(Cantidad)){OK=false; document.getElementById("celda_Cantidad").style.color="red";}else{ document.getElementById("celda_Cantidad").style.color="black";}

 if(NroCodigoHomologado[0]=="0")
   {
    OK=false; 
    document.getElementById("celda_CodHomologado_color").style.color="red";
	}
 else{ 
      document.getElementById("celda_CodHomologado_color").style.color="black";
      var FormatNroSerie=NroCodigoHomologado[1];
	  if (vacio(FormatNroSerie))
           {
	     OK_FormatNroSerie=false;
           }
	  else{
	       var patron =FormatNroSerie;	
 
           if((Desde.search(patron)) || (Hasta.search(patron))) 
		     {
		         OK_FormatNroSerie=false;
			  document.getElementById("celda_Desde").style.color="red";
			  document.getElementById("celda_Hasta").style.color="red";
		     }	 
		   else 
		      {
			   document.getElementById("celda_Desde").style.color="black";   
			   document.getElementById("celda_Hasta").style.color="black";   
		      }
		  }
	  }	  
 
 if (OK && OK_FormatNroSerie)
  {
   if(confirm("¿Está seguro de los datos a dar de Cargar?"))
	 {
      ajax=nuevoAjax();
      ajax.open("POST", "/SICGNC/Cargas/CargarLoteDispositivo.php", true);
      ajax.onreadystatechange=function() 
       { 
	    if (ajax.readyState==1)
	     {
		  document.getElementById("DatosDelLote").innerHTML="<h2>.....Cargando......</h2>"
		 }
	   if (ajax.readyState==4)
        { 
	      document.getElementById("DatosDelLote").innerHTML=ajax.responseText;
	    } 
	 }
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("TipoDispositivo="+TipoDispositivo+"&FechaAprobacion="+FechaAprobacion.value+"&NroCertificado="+NroCertificado+"&HomologCode="+NroCodigoHomologado[0]+"&Desde="+Desde+"&Hasta="+Hasta+"&Cantidad="+Cantidad);
   }	
  }
  else
    {
	 if(!OK)
	  alert("Verifique los campos en rojo");
	 if(!OK_FormatNroSerie)
	   alert("Formato de Nro de Serie no se corresponde o todavía no fue dado de Alta"); 
	}

}

/************************* Registro IDI ******************************************/
IdRegistroIDIRadio=0;
IdRegistroCausaRadio=0;

function Valida_MarcaParaIDI(TipoOp)
{
    var valor=document.getElementById("Componente").options[document.getElementById("Componente").selectedIndex].value;
	if(valor==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("Marca");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="---Seleccionar---";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
		
		combo2=document.getElementById("CodHomolog");
		combo2.length=0;
		var nuevaOpcion2=document.createElement("option"); 
		nuevaOpcion2.value=0;
		nuevaOpcion2.innerHTML="---Seleccionar---";
		combo2.appendChild(nuevaOpcion2);	
		combo2.value=0;
		combo2.disabled=true;
		
	  if (TipoOp=="Alta")
	     {	
			combo3=document.getElementById("Causa");
			combo3.length=0;
			var nuevaOpcion3=document.createElement("option"); 
			nuevaOpcion3.value=0;
			nuevaOpcion3.innerHTML="---Seleccionar---";
			combo3.appendChild(nuevaOpcion3);	
			combo3.value=0;
			combo3.disabled=true;
		}
		//CasilleroNroSerie=document.getElementById("NroSerie");
		//CasilleroNroSerie.disabled=true;
	}
	else
	{
	//Marcas según tipo de dispositivo  y causa*********************************************************
		ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/CargarMarcas.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
				combo=document.getElementById("Marca");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celda_marca").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("TipoComponente="+valor);
		
	 if(TipoOp=="Alta")
	  {	
		ajax_2=nuevoAjax();
		ajax_2.open("POST", "/SICGNC/Cargas/CargarCausas.php", true);
		ajax_2.onreadystatechange=function() 
		{ 
			if (ajax_2.readyState==1)
			{
				combo_2=document.getElementById("Causa");
				combo_2.length=0;
				var nuevaOpcion_2=document.createElement("option"); 
				nuevaOpcion_2.value=0; 
				nuevaOpcion_2.innerHTML="Cargando...";
				combo_2.appendChild(nuevaOpcion_2); 
				combo_2.disabled=true;	
			}
			if (ajax_2.readyState==4)
			{ 
				document.getElementById("celda_Causa").innerHTML=ajax_2.responseText;
			} 
		}
		ajax_2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax_2.send("TipoComponente="+valor);
	  }	
	}
}










function Valida_MarcaParaIDICilindroExt(TipoOp)
{
    var valor=document.getElementById("Componente").options[document.getElementById("Componente").selectedIndex].value;
	if(valor==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("Marca");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="---Seleccionar---";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
		
		combo2=document.getElementById("CodHomolog");
		combo2.length=0;
		var nuevaOpcion2=document.createElement("option"); 
		nuevaOpcion2.value=0;
		nuevaOpcion2.innerHTML="---Seleccionar---";
		combo2.appendChild(nuevaOpcion2);	
		combo2.value=0;
		combo2.disabled=true;
		
	}
	else
	{
	/*Marcas según tipo de dispositivo  y causa*/
		ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/CargarMarcas.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
				combo=document.getElementById("Marca");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celda_marca").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("TipoComponente="+valor);
}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function CompletarHasta() {
 var NroSerieD=document.getElementById("NroSerieD").value;
document.getElementById("NroSerieH").value=NroSerieD;
}

function AutorizarRTR(Tipo,Nro)
{/*
alert(Tipo);
alert(Nro);
*/

if(confirm("¿ Está seguro de Autorizar el RT Regional con el "+ Tipo +" "+ Nro + " ?"))
      {
 ajax=nuevoAjax();
ajax.open("GET", "/SICGNC/Cargas/AutorizacionRTRegionalPEC.php?Tipo="+Tipo+"&Nro="+Nro,true);
  ajax.onreadystatechange=function() 
	{ 
	if (ajax.readyState==1)
		    {
			 document.getElementById("AutorizacionRTR").innerHTML="<h2>.....Cargando......</h2>"
			}
	if (ajax.readyState==4)
		{ 
		document.getElementById("AutorizacionRTR").innerHTML=ajax.responseText;
		} 
	}
	ajax.send(null);

	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////

function AltaIDICilindroExt()
{
 var componente=document.getElementById("Componente").value;
 var NroSerieD=document.getElementById("NroSerieD").value;
 var NroSerieH=document.getElementById("NroSerieH").value;
 var marca=document.getElementById("Marca").value;
 var codHomolog_aux=document.getElementById("CodHomolog").value;
 var codHomolog=codHomolog_aux.split(";");
 var fechaDenuncia=document.getElementById("FechaDenuncia").value;
 var causa=document.getElementById("Causa").value;
 var DesdeAux;
 var DesdeAux1=null;
 var HastaAux1=null;
 var HastaAux;
 var OK=true;
 var OKCausa=true;

if (marca=="FABE") {
	if (IsNumeric(NroSerieD)==false) {
	 DesdeAux=NroSerieD.substring(0,2);
	 DesdeAux4=NroSerieD.substring(3,7);
	 DesdeAux2=NroSerieD.substring(8,11);
	 // NroSerieD=parseInt(NroSerieD,10);
	 NroSerieD=DesdeAux+DesdeAux4+DesdeAux2;
	  }
	if (IsNumeric(NroSerieH)==false ){
	 HastaAux=NroSerieH.substring(0,2);
	 HastaAux4=NroSerieH.substring(3,7);
	 HastaAux2=NroSerieH.substring(8,11);
	 NroSerieH=HastaAux+HastaAux4+HastaAux2;
	//NroSerieH=parseInt(NroSerieH,10);
	}
	}
if (marca=="MATI") {
		if (IsNumeric(NroSerieD)==false) {
	 DesdeAux1=NroSerieD.substring(0,2);
	 DesdeAux=NroSerieD.substring(2,6);
	 NroSerieD=DesdeAux; 
	 }
	 if (IsNumeric(NroSerieH)==false){
	 HastaAux1=NroSerieH.substring(0,2);
	 HastaAux=NroSerieH.substring(2,6);
	 NroSerieH=HastaAux;}
	}
if (marca=="PASQ"){
		if (IsNumeric(NroSerieD)==false){
	 DesdeAux1=NroSerieD.substring(0,1);
	 DesdeAux=NroSerieD.substring(1,7);
	 NroSerieD=DesdeAux; 
	 }
	 if (IsNumeric(NroSerieH)==false) {
	HastaAux1=NroSerieH.substring(0,1);
	//alert(HastaAux1);
	 HastaAux=NroSerieH.substring(1,7);
	  NroSerieH=HastaAux;}
	}
if (marca=="DALM"){
		if (IsNumeric(NroSerieD)==false) {
	DesdeAux=NroSerieD.substring(0,1);
	 DesdeAux1=NroSerieD.substring(2,8);
	 NroSerieD=DesdeAux+DesdeAux1;
	 }
	 if (IsNumeric(NroSerieH)==false) {
		HastaAux=NroSerieH.substring(0,1);
	 HastaAux1=NroSerieH.substring(2,8);
	  NroSerieH=HastaAux+HastaAux1;
	  }
	}
if (marca=="TOIL"){
	 if (IsNumeric(NroSerieD)==false) {
	 DesdeAux1=NroSerieD.substring(0,1);
	 DesdeAux=NroSerieD.substring(1,8);
	 NroSerieD=DesdeAux; 
	 }
	 if (IsNumeric(NroSerieH)==false) {
	HastaAux1=NroSerieH.substring(0,1);
	//alert(HastaAux1);
	 HastaAux=NroSerieH.substring(1,8);
	 NroSerieH=HastaAux;}
	}
if (marca=="MATS") {
	if (IsNumeric(NroSerieD)==false) {
	 DesdeAux1=NroSerieD.substring(0,3);
	 DesdeAux=NroSerieD.substring(3,7);
	 NroSerieD=DesdeAux; 
	 }
	 if (IsNumeric(NroSerieH)==false) {
	HastaAux1=NroSerieH.substring(0,3);
	//alert(HastaAux1);
	 HastaAux=NroSerieH.substring(3,7);
	 NroSerieH=HastaAux;}
	}
//alert(NroSerieD);

 if (componente=="0"){OK=false; document.getElementById("celda_componente").style.color="red";}else{ document.getElementById("celda_componente").style.color="black";}
 if (marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red";}else{ document.getElementById("celda_marca_color").style.color="black";}
 if (causa=="0"){OK=false; document.getElementById("celda_Causa_color").style.color="red";}else{ document.getElementById("celda_Causa_color").style.color="black";}
 if (NroSerieD==""){OK=false; document.getElementById("celda_nroSerieD").style.color="red";}else{ document.getElementById("celda_nroSerieD").style.color="black";}
 if (NroSerieH==""){OK=false; document.getElementById("celda_nroSerieH").style.color="red";}else{ document.getElementById("celda_nroSerieH").style.color="black";}
 if (codHomolog[0]=="0"){OK=false; document.getElementById("celda_CodHomologado_color").style.color="red";}else{ document.getElementById("celda_CodHomologado_color").style.color="black";}
 if(valFecha(document.getElementById("FechaDenuncia"))){OK=false; document.getElementById("celda_fechaDenuncia").style.color="red";}else{ document.getElementById("celda_fechaDenuncia").style.color="black";}	

if (causa!="32")
    {OKCausa=false; document.getElementById("celda_Causa_color").style.color="red";}else{ document.getElementById("celda_Causa_color").style.color="black";}
	
 
 if (OK && OKCausa)
    {
	 if (confirm("¿ Esta seguro de los datos a cargar ?"))
	 {
	 ajax=nuevoAjax();
	 ajax.open("POST", "/SICGNC/Cargas/CargarAltaRegIDICilExt.php", true);
 	 ajax.onreadystatechange=function() 
   		{ 
	 	 if (ajax.readyState==4)
	       { 
		    document.getElementById("DatosDelComponente").innerHTML=ajax.responseText;
            //document.getElementById("ImprimirComponente").innerHTML="<a href=javascript:imprSelec('DatosDelComponente') ><img src='../Images/print1.ico' width='20' height='20' alt='Imprimir'></a>";
	         document.getElementById("ImprimirComponente").innerHTML="<a href=javascript:btnImprimir()><img src='../Images/print1.ico' width='20' height='20' alt='Imprimir'></a>";

		     } 
        }  
 	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("Componente="+componente+"&NroSerieD="+NroSerieD+"&NroSerieH="+NroSerieH+"&CodHomolog="+codHomolog[0]+"&FechaDenuncia="+fechaDenuncia+"&Causa="+causa+"&HastaAux1="+HastaAux1+"&DesdeAux1="+DesdeAux1+"&marca="+marca);
	}
   }
   else
   if(!OK)
	 alert("Algunos Campos están incompletos verifique los campos en Rojo o están mal ingresados."); 
   if(!OKCausa)
	 alert("La causa debe ser Cilindro enviado al exterior,no comercializable en la Argentina"); 	
}
function IsNumeric(expression)  
 {  
	return (String(expression).search(/^\d+$/) != -1);  
 } 

function GuardarId(Id,opcion)
{
 if(opcion=="Causa")
   IdRegistroCausaRadio=Id;
 if(opcion=="IDI")
   IdRegistroIDIRadio=Id;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Valida_Codigo(TipoComponente)
{
	var valor=document.getElementById("Marca").options[document.getElementById("Marca").selectedIndex].value;
	
	if(valor==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("CodHomolog");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); 
		nuevaOpcion.value=0;
		nuevaOpcion.innerHTML="---Seleccionar---";
		combo.appendChild(nuevaOpcion);	
		combo.value=0;
		combo.disabled=true;
	}
	else
	{
	//Código de Homologación según la marca y el tipo de componente
	    ajax=nuevoAjax();
		ajax.open("POST", "/SICGNC/Cargas/CargarCodHomolog.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				combo=document.getElementById("CodHomolog");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); 
				nuevaOpcion.value=0; 
				nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); 
				combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("celda_CodHomologado").innerHTML=ajax.responseText;
			} 
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("TipoComponente="+TipoComponente+"&Marca="+valor);	
	}

}

function BuscarVehiculo()
{
  var Componente=document.getElementById("Componente").options[document.getElementById("Componente").selectedIndex].value;
  var Marca=document.getElementById("Marca").options[document.getElementById("Marca").selectedIndex].value;
  var CodHomolog_Aux=document.getElementById("CodHomolog").value;
  var CodHomolog=CodHomolog_Aux.split(";");
  var NroSerie=document.getElementById("NroSerie").value;
  var Dominio=document.getElementById("Dominio").value;

 ajax=nuevoAjax();
 ajax.open("POST", "/SICGNC/Cargas/MostrarComponenteIDI.php", true);
 ajax.onreadystatechange=function() 
   { 
     if (ajax.readyState==1)
      {
		document.getElementById("DatosDelComponente").innerHTML="<h2>.....Buscando......</h2>";
	  }
	 if (ajax.readyState==4)
	    { 
		  document.getElementById("DatosDelComponente").innerHTML=ajax.responseText;
	     } 
   }  
 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 if( (Componente==0) || (Marca==0) || (CodHomolog==0) || (NroSerie==0) ) {
    
    ajax.send("Dominio="+Dominio);	
  }
 if( (Componente!=0) && (Marca!=0) && (CodHomolog[0]!=0) && (NroSerie!=0) )   {
   
   ajax.send("TipoComponente="+Componente+"&CodHomologComponente="+CodHomolog[0]+"&NroSerieComponente="+NroSerie);
 }
}

function BajaIDI()
{


if (!(document.getElementById("C1").checked) && (!(document.getElementById("C2").checked) ) && !(document.getElementById("C3").checked) ) {
 alert("Debe seleccionar la causa de la baja de la denuncia.");
 return;

}
 var registro=document.getElementById(IdRegistroIDIRadio).value;
 var solicitante=document.getElementById("Solicitante").options[document.getElementById("Solicitante").selectedIndex].value;
 var Causa=document.getElementById(IdRegistroCausaRadio).value;
 var OK=true;
 

 
/*Caso en que no seleccionen ningún solicitante para la baja del registro idi contiente el login del usuario y el tipo
ej ENARGAS;ADM*/
/*Caso en que no elijan ningún registro a dar de baja contiene el código del componente, el código de homologación y el Nro de Serie
ej 100;ch02;2525*/
/* Caso en que no elijan ninguna causa de baja
ej 1 ó 2 ó 3*/

if(solicitante==0 || registro==0 ||  Causa==0)
   OK=false;

 if (OK)
    {
	 if(confirm("¿Está seguro de los datos a Cargar"))
	 {
	  ajax=nuevoAjax();
	  ajax.open("POST", "/SICGNC/Cargas/CargarBajaRegIDI.php", true);
 	  ajax.onreadystatechange=function() 
   		 { 
		  if (ajax.readyState==1)
	         {
		     document.getElementById("DatosDelComponente").innerHTML="<h2>.....Dando de Baja......</h2>";
	        }
	 	  if (ajax.readyState==4)
	        { 
		    document.getElementById("DatosDelComponente").innerHTML=ajax.responseText;
	        } 
         }  
 	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("UserSolicitante="+solicitante+"&RegistroBaja="+registro+"&CodigoCausa="+Causa);
   }  	
  }
 else
	   alert("Debe seleccionar el usuario soliciatante.");
}

function AltaIDIOC()
{
 var componente=document.getElementById("Componente").value;
 var nroSerieDesdeAlfa=document.getElementById("NroDesdeAlfa").value;
 var nroSerieHastaAlfa=document.getElementById("NroHastaAlfa").value;
 var nroSerieDesdeEntero=document.getElementById("NroDesdeEntero").value;
 var nroSerieHastaEntero=document.getElementById("NroHastaEntero").value;
 var marca=document.getElementById("Marca").value;
 var codHomolog_aux=document.getElementById("CodHomolog").value;
 var codHomolog=codHomolog_aux.split(";");
 var causa=document.getElementById("Causa").value;
 var OK=true;
 var OKCausa=true;
 
//Alta en el registro IDI puede suceder de carga de denuncia sin fecha y sin dominio

 if (componente=="0"){OK=false; document.getElementById("celda_componente").style.color="red";}else{ document.getElementById("celda_componente").style.color="black";}
 if (marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red";}else{ document.getElementById("celda_marca_color").style.color="black";}
 if (causa=="0"){OK=false; document.getElementById("celda_Causa_color").style.color="red";}else{ document.getElementById("celda_Causa_color").style.color="black";}
 if (vacio(nroSerieDesdeEntero) /*|| ValidaCaracteresRaros(nroSerieDesdeEntero)*/){OK=false; document.getElementById("celda_NroDesde").style.color="red";}else{ document.getElementById("celda_NroDesde").style.color="black";}
 if (vacio(nroSerieHastaEntero) /*|| ValidaCaracteresRaros(nroSerieHastaEntero)*/){OK=false; document.getElementById("celda_NroHasta").style.color="red";}else{ document.getElementById("celda_NroDesde").style.color="black";}
 //if (vacio(nroSerieHastaAlfa) /*|| ValidaCaracteresRaros(nroSerieHastaAlfa)*/){OK=false; document.getElementById("celda_NroDesde").style.color="red";}else{ document.getElementById("celda_NroDesde").style.color="black";}
 //if (vacio(nroSerieDesdeAlfa) /*|| ValidaCaracteresRaros(nroSerieDesdeAlfa)*/){OK=false; document.getElementById("celda_NroHasta").style.color="red";}else{ document.getElementById("celda_NroDesde").style.color="black";}
 if (codHomolog[0]=="0"){OK=false; document.getElementById("celda_CodHomologado_color").style.color="red";}else{ document.getElementById("celda_CodHomologado_color").style.color="black";}

/* if(nroSerieDesdeAlfa!=nroSerieHastaAlfa)
 {
   OK=false; 
   document.getElementById("celda_NroDesde").style.color="red";
   document.getElementById("celda_NroHasta").style.color="red";
   }	
 else{ 
     document.getElementById("celda_NroDesde").style.color="black";
	 document.getElementById("celda_NroHasta").style.color="black";
	 }*/
	 
 if (!(nroSerieDesdeEntero<=nroSerieHastaEntero))
   {
    OK=false; 
	document.getElementById("celda_NroDesde").style.color="red";
	document.getElementById("celda_NroHasta").style.color="red";
   }	
 else{ 
     document.getElementById("celda_NroDesde").style.color="black";
	 document.getElementById("celda_NroHasta").style.color="black";
	 }
  	
 if ((causa!="14")&&(causa!="7"))
    {OKCausa=false; document.getElementById("celda_Causa_color").style.color="red";}else{ document.getElementById("celda_Causa_color").style.color="black";}
	
 if (OK && OKCausa)
    {
	 if (confirm("¿ Esta seguro de los datos a cargar ?"))
	 {
	 ajax=nuevoAjax();
	 ajax.open("POST", "/SICGNC/Cargas/CargarAltaRegIDISICGNC.php", true);
 	 ajax.onreadystatechange=function() 
   		{
		 if (ajax.readyState==1)
	       { 
		    document.getElementById("DatosDelComponente").innerHTML="<h2>.....Cargando en IDI......</h2>";
	       }  
	 	 if (ajax.readyState==4)
	       { 
		    document.getElementById("DatosDelComponente").innerHTML=ajax.responseText;
	       } 
        }  
 	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("Tipo=2&Componente="+componente+"&NroSerieDesdeAlfa="+nroSerieDesdeAlfa+"&NroSerieDesdeEntero="+nroSerieDesdeEntero+"&NroSerieHastaAlfa="+nroSerieHastaAlfa+"&NroSerieHastaEntero="+nroSerieHastaEntero+"&CodHomolog="+codHomolog[0]+"&Causa="+causa);
	}
   }
   else
      if(!OK)
	     alert("Algunos Campos están incompletos verifique los campos en Rojo o están mal ingresados."); 
	  if(!OKCausa)
	     alert("La causa debe ser No Apto para su instalación"); 	
}

function AltaIDI()
{
 var componente=document.getElementById("Componente").value;
 var nroSerie=document.getElementById("NroSerie").value;
 var dominio=document.getElementById("Dominio").value;
 var marca=document.getElementById("Marca").value;
 var codHomolog_aux=document.getElementById("CodHomolog").value;
 var codHomolog=codHomolog_aux.split(";");
 var fechaDenuncia=document.getElementById("FechaDenuncia").value;
 var causa=document.getElementById("Causa").value;
 var OK=true;
 
//Alta en el registro IDI puede suceder de carga de denuncia sin fecha y sin dominio

 if (componente=="0"){OK=false; document.getElementById("celda_componente").style.color="red";}else{ document.getElementById("celda_componente").style.color="black";}
 if (marca=="0"){OK=false; document.getElementById("celda_marca_color").style.color="red";}else{ document.getElementById("celda_marca_color").style.color="black";}
 if (causa=="0"){OK=false; document.getElementById("celda_Causa_color").style.color="red";}else{ document.getElementById("celda_Causa_color").style.color="black";}
 if (nroSerie==""){OK=false; document.getElementById("celda_nroSerie").style.color="red";}else{ document.getElementById("celda_nroSerie").style.color="black";}
 if (codHomolog[0]=="0"){OK=false; document.getElementById("celda_CodHomologado_color").style.color="red";}else{ document.getElementById("celda_CodHomologado_color").style.color="black";}

 if((causa!="14") && (causa!="15") && (causa!="7") && (causa!="11"))
   if (vacio(dominio)){OK=false; document.getElementById("celda_Dominio").style.color="red";}else{ document.getElementById("celda_Dominio").style.color="black";} 

 if ((causa=="13")||(causa=="6"))
   {
    if(valFecha(document.getElementById("FechaDenuncia"))){OK=false; document.getElementById("celda_fechaDenuncia").style.color="red";}else{ document.getElementById("celda_fechaDenuncia").style.color="black";}	
   }
 
 if (OK)
    {
	 if (confirm("¿ Esta seguro de los datos a cargar ?"))
	 {
	 ajax=nuevoAjax();
	 ajax.open("POST", "/SICGNC/Cargas/CargarAltaRegIDISICGNC.php", true);
 	 ajax.onreadystatechange=function() 
   		{ 
	 	 if (ajax.readyState==4)
	       { 
		    document.getElementById("DatosDelComponente").innerHTML=ajax.responseText;
            //document.getElementById("ImprimirComponente").innerHTML="<a href=javascript:imprSelec('DatosDelComponente') ><img src='../Images/print1.ico' width='20' height='20' alt='Imprimir'></a>";
	        document.getElementById("ImprimirComponente").innerHTML="<a href=javascript:btnImprimir()><img src='../Images/print1.ico' width='20' height='20' alt='Imprimir'></a>";

	       } 
        }  
 	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("Tipo=1&Componente="+componente+"&NroSerie="+nroSerie+"&Dominio="+dominio+"&CodHomolog="+codHomolog[0]+"&FechaDenuncia="+fechaDenuncia+"&Causa="+causa);
	}
   }
   else
	  alert("Algunos Campos están incompletos verifique los campos en Rojo"); 
}

function GuardarId(Id,opcion)
{
 if(opcion=="Causa") {
   IdRegistroCausaRadio=Id;
   }
   
 if(opcion=="IDI"){
   IdRegistroIDIRadio=Id;
     document.getElementById("Aceptar").disabled=false;
   }
}


/******************************Termino de Funciones del IDI***************************************************/
/********************************Funciones Varias*********************************************************/
/**************Función para validar el cuit, si es correcto devuelve true, sino false****************/
function ValidarCuit(nro) 
{
 var suma;
 var resto;
 var verif;
 var NroCuit=nro.split('-');
 var NroCuitAux=NroCuit[0]+NroCuit[1]+NroCuit[2];
 var pos = NroCuitAux.split('');
 
 if (! /^\d{11}$/.test(NroCuitAux)) 
   return false;

 while (true) {
   suma = (pos[0] * 5 + pos[1] * 4 + pos[2] * 3 +
   pos[3] * 2 + pos[4] * 7 + pos[5] * 6 +
   pos[6] * 5 + pos[7] * 4 + pos[8] * 3 + pos[9] * 2);
   resto = suma % 11;

   if (resto == 0) 
    {
     verif = 0;
     break;
    } 
    else 
	   if (resto == 1 && (pos[1] == 0 || pos[6] == 7)) {
          pos[1] = 4;
          continue;
         }
       else {
         verif = 11 - resto;
         break;
       }
 }
 return pos[10] == verif;
}
/***************************************Fin Función para validar el Cuit***********************/
/*****************************función que verifica si el campo está vacio, si está vacio
devuelve true, sino false*******************************************************************/
function vacio(q) {
        for ( i = 0; i < q.length; i++ ) {
                if ( q.charAt(i) != " " ) {
                        return false;
                }
        }
        return true;
}
/**********************************Fin Función vacio*****************************************/
/******************************Función que verifica si una fecha es correcta****************
si es correcta devuelve false e incorrecta true*********************************************/
function esDigito(sChr){ 
    var sCod = sChr.charCodeAt(0); 
    return ((sCod > 47) && (sCod < 58)); 
   } 

   function valSep(oTxt){ 
    var bOk = false; 
    var sep1 = oTxt.value.charAt(2); 
    var sep2 = oTxt.value.charAt(5); 
    bOk = bOk || ((sep1 == "-") && (sep2 == "-")); 
    bOk = bOk || ((sep1 == "/") && (sep2 == "/")); 
    return bOk; 
   } 

   function finMes(oTxt){ 
    var nMes = parseInt(oTxt.value.substr(3, 2), 10); 
    var nAno = parseInt(oTxt.value.substr(6), 10); 
    var nRes = 0; 
    switch (nMes){ 
     case 1: nRes = 31; break; 
     case 2: nRes = 28; break; 
     case 3: nRes = 31; break; 
     case 4: nRes = 30; break; 
     case 5: nRes = 31; break; 
     case 6: nRes = 30; break; 
     case 7: nRes = 31; break; 
     case 8: nRes = 31; break; 
     case 9: nRes = 30; break; 
     case 10: nRes = 31; break; 
     case 11: nRes = 30; break; 
     case 12: nRes = 31; break; 
    } 
    return nRes + (((nMes == 2) && (nAno % 4) == 0)? 1: 0); 
   } 

   function valDia(oTxt){ 
    var bOk = false; 
    var nDia = parseInt(oTxt.value.substr(0, 2), 10); 
    bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt))); 
    return bOk; 
   } 

   function valMes(oTxt){ 
    var bOk = false; 
    var nMes = parseInt(oTxt.value.substr(3, 2), 10); 
    bOk = bOk || ((nMes >= 1) && (nMes <= 12)); 
    return bOk; 
   } 

   function valAno(oTxt){ 
    var bOk = true; 
    var nAno = oTxt.value.substr(6); 
    bOk = bOk && ((nAno.length == 2) || (nAno.length == 4)); 
    if (bOk){ 
     for (var i = 0; i < nAno.length; i++){ 
      bOk = bOk && esDigito(nAno.charAt(i)); 
     } 
    } 
    return bOk; 
   } 

   function valFecha(oTxt)
   { 
    var bOk = true; 
    if (oTxt.value != "")
	{ 
      bOk = bOk && (valAno(oTxt)); 
      bOk = bOk && (valMes(oTxt)); 
      bOk = bOk && (valDia(oTxt)); 
      bOk = bOk && (valSep(oTxt)); 
      if (!bOk)
	   { 
      //alert("Fecha inválida"); 
	    return true; //fecha incorrecta
       //oTxt.value = ""; 
      //oTxt.focus(); 
       } 
	   else return false; //fecha correcta 
    } else return true; //fecha incorrecta
 } 
////////////////////////////////Fin función validar fecha//////////////////////////////////////
/*************Función que valida el Dominio nuevo, si es correcto devuelve false
si es incorrecto dvuelve true************************************************************/
function ValidarDominio(Dominio)
{
var patron=/^[A-Z][A-Z][A-Z]\d{3}|[A-Z]\d{6,7}$/
    if(Dominio.search(patron)) 
	  return true;
	  else
	      return false; 
}


/////////////////////////////////////////////////////////////////////////////////////////////


function RestarNumeroSerie()
{
 var desde=document.getElementById("Desde").value;
 var hasta=document.getElementById("Hasta").value;
 var total;
 var Desdeaux
 var Hastaaux;
 // alert(parseInt(desde));
  if ((!vacio(desde)) && (!vacio(hasta)))
  {  

				var  l=1;
				var j=0; 
				  for( var i = 0; i < desde.length; i++) {
				var letra=desde.substring(l,i);
				var patron=/[A-Z]/;
					if(patron.test(letra)){
						 j++;}
				l++
				}
				  
				  DesdeAux=parseInt(desde.substring(j,11),10);
				  HastaAux=parseInt(hasta.substring(j,11),10);
				 // alert(DesdeAux);
				  total= (HastaAux - DesdeAux)+1;
 
     if (total-1<0 )
	  alert("Valores inválidos por favor reingreselos");
	else
		   document.getElementById("Cantidad").value=total;  
  return;
  }
}



/////////////////////////////Fin función valida dominio************************************/
////////////////////////////////////////////////////////////////////////////////////////////
function VerEstadoObleasPEC()
{
var PecCode=document.getElementById("Codigo").value;
var Ano=document.getElementById("Ano").value;

 if((PecCode!=0) && (!vacio(Ano)))
  {
//alert(Ano);
    ajax=nuevoAjax();
 	ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarCuadroEstadoPecs.php",true);
    ajax.onreadystatechange=function() 
	{ 
	if (ajax.readyState==1)
		    {
			  document.getElementById("BtnAceptar").disabled=true;	
			 document.getElementById("DetalleEstadoObleas").innerHTML="<h2>.....Cargando......</h2>"
			}
	if (ajax.readyState==4)
		{ 
		document.getElementById("DetalleEstadoObleas").innerHTML=ajax.responseText;
		document.getElementById("BtnAceptar").disabled=false;
		} 
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("PecCode="+PecCode+"&Anno="+Ano);

  }
  else
     {
	  ajax=nuevoAjax();
	  ajax.open("GET", "/SICGNC/blanco.php", true);
      ajax.onreadystatechange=function() 
	   { 
		 if (ajax.readyState==4)
			 { 
			 document.getElementById("DetalleEstadoObleas").innerHTML=ajax.responseText;
			 } 
	   }
      ajax.send(null);
	}  
}
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
function OperacionDePECporTalleres()
{
var PecCode=document.getElementById("PecCode").value;


 if((PecCode!=0))
  {
    ajax=nuevoAjax();
 	ajax.open("POST", "/SICGNC/ResultadoConsulta/CantidadDeOperacionesTalleresPEC.php",true);
    ajax.onreadystatechange=function() 
	{ 
	if (ajax.readyState==1)
		    {
			 document.getElementById("DetalleOperacionDePECporTalleres").innerHTML="<h2>.....Cargando......</h2>"
			}
	if (ajax.readyState==4)
		{ 
		document.getElementById("DetalleOperacionDePECporTalleres").innerHTML=ajax.responseText;
		} 
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("PecCode="+PecCode);
  }
  else
     {
	  ajax=nuevoAjax();
	  ajax.open("GET", "/SICGNC/blanco.php", true);
      ajax.onreadystatechange=function() 
	   { 
		 if (ajax.readyState==4)
			 { 
			 document.getElementById("DetalleOperacionDePECporTalleres").innerHTML=ajax.responseText;
			 } 
	   }
      ajax.send(null);
	}  
}
////////////////////////////////////////////////////////////////////////////////////////////
function ListadoTalleresNoCertifBaja()
{
 var Provincia=document.getElementById("Provincia").value;
//alert(Provincia);
 ajax=nuevoAjax();
 ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarTalleresNoCertifBaja.php", true);
 ajax.onreadystatechange=function() 
   { 
    if (ajax.readyState==1)
	    { 
		  document.getElementById("DetalleDeTalleres").innerHTML="<h2>.....Buscando.....</h2>";
	     } 
	 if (ajax.readyState==4)
	    { 
		  document.getElementById("DetalleDeTalleres").innerHTML=ajax.responseText;
	     } 
   }  
 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 ajax.send("Provincia="+Provincia);
}
////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Borrar espacios en Blanco de una cadena//////////////////////
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)); 
    } 
////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////Consultar la Marca Según el Código de Homologación que me pasan///////
function ConsultarMarca ()
{
 var Componente=document.getElementById("Componente").value;
 var HomologCode=document.getElementById("HomologCode").value;
//alert(Provincia);
 ajax=nuevoAjax();
 ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarMarca.php", true);
 ajax.onreadystatechange=function() 
   { 
    if (ajax.readyState==1)
	    { 
		  document.getElementById("DetalleMarca").innerHTML="<h2>.....Buscando.....</h2>";
	     } 
	 if (ajax.readyState==4)
	    { 
		  document.getElementById("DetalleMarca").innerHTML=ajax.responseText;
	     } 
   }  
 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 ajax.send("Componente="+Componente+"&HomologCode="+HomologCode);	
}
////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////Alta Cédula Mercosur//////////////////////////////////////
function  AltaCedulaMercosur()
{
 var NroOblea=allTrim(document.getElementById("NroOblea").value);
 var Dominio=allTrim(document.getElementById("Dominio").value);
 var CedulaMercosur=allTrim(document.getElementById("CedulaMercosur").value);
 var patron=/^\d{6,8}$/;
 
/* alert(NroOblea);
 alert(Dominio);
 alert(CedulaMercosur);*/
if(!ValidarDominio(Dominio) && !NroOblea.search(patron))
  {
  ajax=nuevoAjax();
  ajax.open("POST", "/SICGNC/Cargas/ABM_CedulaMercosur.php", true);
  ajax.onreadystatechange=function() 
    { 
     if (ajax.readyState==1)
	     { 
		   document.getElementById("DetalleCedulaMercosur").innerHTML="<h2>.....Cargando.....</h2>";
	     } 
	 if (ajax.readyState==4)
	     { 
		  document.getElementById("DetalleCedulaMercosur").innerHTML=ajax.responseText;
	     } 
    }  
 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 ajax.send("NroOblea="+NroOblea+"&Dominio="+Dominio+"&CedulaMercosur="+CedulaMercosur);	
 } 
 else{
	 alert("Datos Ingresados no válidos");
     document.getElementById("NroOblea").value="";
	 document.getElementById("Dominio").value="";
	 document.getElementById("CedulaMercosur").value="";
	}
}
/////La función a continuación me muestra el cuadro de estado de los CRPC o PEC/////
/////Muestra para el caso de los CRPCs si su importación fue procesada y el reporte de errores
/////para el caso de los PECs lo mismo, se puede elegir una fecha que es opcional, en caso
/////de que la fecha este vacia se muestran los últimos 5 procesos.
/*function CuadroEstadoSujeto(TipoSujeto)
{
 var CodigoSujeto=document.getElementById("Codigo").value;
 var Fecha=document.getElementById("Fecha");
 
 if(TipoSujeto=="CRPC")
  {
   if(!vacio(CodigoSujeto))
     {
      if (!vacio(Fecha.value)) 
	    {
         if (!valFecha(Fecha))
          {
		   ajax=nuevoAjax();
           ajax.open("GET", "/SICGNC/ResultadoConsulta/MostrarCuadroEstadoSujetos.php?TipoSujeto="+TipoSujeto+"&CodigoSujeto="+CodigoSujeto+"&Fecha="+Fecha.value, true);
           ajax.onreadystatechange=function() 
            { 
             if (ajax.readyState==1)
	          { 
		      document.getElementById("DetalleEstado").innerHTML="<h2>.....Cargando.....</h2>";
	          } 
	         if (ajax.readyState==4)
	          { 
		      document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
	          } 
            }    
           ajax.send(null);
         }
         else
		   alert("Fecha inválida, Recuerde dd/mm/aaaa");
	   }
      else
       {
	    ajax=nuevoAjax();
        ajax.open("GET", "/SICGNC/ResultadoConsulta/MostrarCuadroEstadoSujetos.php?TipoSujeto="+TipoSujeto+"&CodigoSujeto="+CodigoSujeto+"&Fecha="+Fecha.value, true);
        ajax.onreadystatechange=function() 
          { 
           if (ajax.readyState==1)
	        { 
		    document.getElementById("DetalleEstado").innerHTML="<h2>.....Cargando.....</h2>";
	        } 
	       if (ajax.readyState==4)
	        { 
		    document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
	        } 
         }  
        ajax.send(null);	   
	   }
   }
   else
    {
	 ajax=nuevoAjax();
	 ajax.open("GET", "/SICGNC/blanco.php", true);
     ajax.onreadystatechange=function() 
	   { 
		 if (ajax.readyState==4)
			 { 
			 document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
			 } 
	   }
      ajax.send(null);	  
	}
 }
}*/
function CuadroEstadoSujeto(TipoSujeto)
{
	
 switch (TipoSujeto)
  {
	case "CRPC": 
	            var CodigoSujeto=document.getElementById("Codigo_crpc").value;
                var Fecha=document.getElementById("Fecha_crpc");
				 if(!vacio(CodigoSujeto))
                  {
                   if(!vacio(Fecha.value)) 
	                {
                    if(!valFecha(Fecha))
                     {
		             ajax=nuevoAjax();
                     ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarCuadroEstadoSujetos.php", true);
                     ajax.onreadystatechange=function() 
                     { 
                      if (ajax.readyState==1)
	                   { 
		               document.getElementById("DetalleEstado").innerHTML="<h2>.....Cargando.....</h2>";
	                   } 
	                  if(ajax.readyState==4)
	                   { 
		              document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
	                   } 
                     }    
                    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	                ajax.send("TipoSujeto="+TipoSujeto+"&CodigoSujeto="+CodigoSujeto+"&Fecha="+Fecha.value);
                   }
                   else
		             alert("Fecha inválida, Recuerde dd/mm/aaaa");
	              }
                  else
                   {
	               ajax=nuevoAjax();
                   ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarCuadroEstadoSujetos.php",true);
                   ajax.onreadystatechange=function() 
                    { 
                    if (ajax.readyState==1)
	                 { 
		              document.getElementById("DetalleEstado").innerHTML="<h2>.....Cargando.....</h2>";
	                 } 
	                if (ajax.readyState==4)
	                 { 
		              document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
	                 } 
                   }  
                    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	                ajax.send("TipoSujeto="+TipoSujeto+"&CodigoSujeto="+CodigoSujeto+"&Fecha="+Fecha.value);	   
	             }
			   }
			   else
                 {
				 ajax=nuevoAjax();
	             ajax.open("POST", "/SICGNC/blanco.php", true);
                 ajax.onreadystatechange=function() 
	              { 
		          if (ajax.readyState==4)
			       { 
			       document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
			       } 
	              }
                 ajax.send(null);	  
	             } 
	break;
case "PEC": 
          var CodigoSujeto=document.getElementById("Codigo_pec").value;
           var Fecha=document.getElementById("Fecha_pec");
               if(!vacio(CodigoSujeto))
                  {
                   if(!vacio(Fecha.value)) 
	                {
                    if(!valFecha(Fecha))
                     {
		             ajax=nuevoAjax();
                     ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarCuadroEstadoSujetos.php", true);
                     ajax.onreadystatechange=function() 
                     { 
                      if (ajax.readyState==1)
	                   { 
		               document.getElementById("DetalleEstado").innerHTML="<h2>.....Cargando.....</h2>";
	                   } 
	                  if(ajax.readyState==4)
	                   { 
		              document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
	                   } 
                     }    
                     ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	                ajax.send("TipoSujeto="+TipoSujeto+"&CodigoSujeto="+CodigoSujeto+"&Fecha="+Fecha.value);
                   }
                   else
		             alert("Fecha inválida, Recuerde dd/mm/aaaa");
	              }
                  else
                   {
	               ajax=nuevoAjax();
                   ajax.open("POST", "/SICGNC/ResultadoConsulta/MostrarCuadroEstadoSujetos.php", true);
                   ajax.onreadystatechange=function() 
                    { 
                    if (ajax.readyState==1)
	                 { 
		              document.getElementById("DetalleEstado").innerHTML="<h2>.....Cargando.....</h2>";
	                 } 
	                if (ajax.readyState==4)
	                 { 
		              document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
	                 } 
                   }  
                    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	                ajax.send("TipoSujeto="+TipoSujeto+"&CodigoSujeto="+CodigoSujeto+"&Fecha="+Fecha.value);   
	             }
			   }
			   else
                 {
				 ajax=nuevoAjax();
	             ajax.open("GET", "/SICGNC/blanco.php", true);
                 ajax.onreadystatechange=function() 
	              { 
		          if (ajax.readyState==4)
			       { 
			       document.getElementById("DetalleEstado").innerHTML=ajax.responseText;
			       } 
	              }
                 ajax.send(null);	  
	             }					
	break;			 
		}
}

//////////////////////Alta de Archivos con las declaraciones de PECs y CRPCs///////////
//esta función da de alta un archivo con las declaraciones de PECs y CRPCs////////////
function AltaArchivoSujeto(TipoSujeto)
{
 if(TipoSujeto=="CRPC")  
  {
   var file=document.getElementById("file").value;		  
   if (!vacio(file))
    {
	 document.FormAltaCRPC.submit();
    }
    else
	   alert("Archivo inválido");
  }

  if(TipoSujeto=="CRPC_old")  
  {
   var file=document.getElementById("file1").value;		  
  // alert (file);
   if (!vacio(file))
    {
	 document.FormAltaCRPC1.submit();
    }
    else
	   alert("Archivo inválido");
  }
 if(TipoSujeto=="PEC")  
  {
   var Usr=document.getElementById("Usr").value;		  
   var Cil=document.getElementById("Cil").value;		  
   var Reg=document.getElementById("Reg").value;
   var ValCil=document.getElementById("ValCil").value;
   if (!vacio(Usr) && !vacio(Cil) && !vacio(Reg) && !vacio(ValCil))
    {
	 document.FormAltaPEC.submit();
    }
    else
	   alert("Archivos Inválidos");
  }


if(TipoSujeto=="PECINH")  
  {
   var Usr=document.getElementById("Usr").value;		  
   var Cil=document.getElementById("Cil").value;		  
   var Reg=document.getElementById("Reg").value;
   var ValCil=document.getElementById("ValCil").value;
    var Observaciones=document.getElementById("Observaciones").value;
   if (!vacio(Usr) && !vacio(Cil) && !vacio(Reg) && !vacio(ValCil))
    {  if (!vacio(Observaciones)){ 
	 document.ImportarArchENBDPEC_Inha.submit(); } else {
		  if(vacio(Observaciones)){ document.getElementById("celda_Obs").style.color="red";
		  alert("Debe completar el campo de observaciones.");}
		  }
    }
    else
	   alert("Archivos Inválidos");
  }

if(TipoSujeto=="PEC_Asig")  
  {
   var Usr=document.getElementById("Usr").value;		  
   var Cil=document.getElementById("Cil").value;		  
   var Reg=document.getElementById("Reg").value;
   var ValCil=document.getElementById("ValCil").value;
   if (!vacio(Usr) && !vacio(Cil) && !vacio(Reg) && !vacio(ValCil))
    {
	 document.FormAltaPEC_Asig.submit();
    }
    else
	   alert("Archivos Inválidos");
  }




}
//////////Esta función me habre una página que baja el Error del PEC o CRPC/////////////////
function BajarArchError(Id,TipoSujeto)
{
	window.open("/SICGNC/ResultadoConsulta/BajarArchivoError.php?Id="+Id+"&TipoSujeto="+TipoSujeto,"VentanaDonwload","width=200,height=200,scrollbars=yes"); 
}

//////////Carga de Accesorios de GNC por parte de los OCs////////////////////////////////
/////////Esta función Carga las Marcas Disponibles /////////////////////////////////////

function valida_Marca(TipoOp)
{
 
  ajax=nuevoAjax();
  ajax.open("GET","/SICGNC/Cargas/Accesorios/CargaMarca.php", true);
  ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{ 
              document.getElementById("fila_marca").innerHTML=ajax.responseText;
		    }
		}
   ajax.send(null);
  
}

///////////Esta función Activa un div con las caracteristicas correspondientes según el tipo
/////////// de Accesorio
function ActivaDiv()
{
		var valor=document.getElementById("Accesorio").options[document.getElementById("Accesorio").selectedIndex].value;
		ajax=nuevoAjax();
		ajax.open("GET", "/SICGNC/Cargas/Accesorios/CargaDiv.php?codigo="+valor, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{ 
				
				document.getElementById("CaracteristicasAccesorio").innerHTML=ajax.responseText;
			} 
		}
		ajax.send(null);
}

function ValidaCargaAccesorios(TipoAccesorio)
{
/*Esta función carga un accesorio homologado*/
/*A partir de aquí están las variables comunes a todos los accesorios*/
 //var HomologCode=document.getElementById("Codigo").value.toUpperCase( );
 var MarcaCode=document.getElementById("Marca").value;
 var Modelo=document.getElementById("Modelo").value.toUpperCase( );
// var OrgCode=document.getElementById("Organismo").value;
 var MatriculaFabImp=document.getElementById("FaboImportador").value;
 var ConexionCilindro=document.getElementById("ConexionCilindro").value;
 var PresionServicio=document.getElementById("PresionServicio").value;
 var Material=document.getElementById("Material").value;
 var TiposValvula=document.getElementById("TiposValvula").value;
 var OtraConexion=document.getElementById("OtraConexion").value;
/*****************************************************************/
 if(TipoAccesorio!=0){
   if ((MarcaCode!=0) && !vacio(Modelo) && !vacio(MatriculaFabImp) && !vacio(ConexionCilindro) && !vacio(PresionServicio) && !vacio(Material) && !vacio(TiposValvula) && !vacio(OtraConexion)){
  switch(TipoAccesorio)
  {
   case "410": 
				if(confirm("Esta seguro de los datos a dar de Alta")){
                   ajax=nuevoAjax();
				   ajax.open("POST", "/SICGNC/Cargas/Accesorios/CargaAccesorios.php",true);
                   ajax.onreadystatechange=function() 
                    { 
                    if (ajax.readyState==4)
		              { 
		              document.getElementById("HomologValvulaCilindro").innerHTML=ajax.responseText;
		              } 
	                }
	               ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	               ajax.send("Modelo="+Modelo+"&Marca="+MarcaCode+"&FaboImportador="+MatriculaFabImp+"&ConexionCilindro="+ConexionCilindro+"&PresionServicio="+PresionServicio+"&Material="+Material+"&TiposValvula="+TiposValvula+"&OtraConexion="+OtraConexion+"&Accesorio=410");
				   }
				 
  break;
  }
 }else
      alert("Algunos de los datos ingresados son inválidos o faltan, todos son obligatorios");
}else
     alert("Debe Ingresar un Accesorio");

}
/*funcion para transformar la oblea de la moto*/
function TranfObleaMoto(Oblea)
{
 var Aux;
 
 Aux=parseInt(Oblea.substring(1,7),10);
 Aux=Aux+100000000;
 
 return Aux;
	
}
/*funcion para transformar la oblea Repetida*/
function TranfObleaRepetida(Oblea)
{
 var Aux;
 
 Aux=parseInt(Oblea.substring(0,8),10);
 Aux=Aux+200000000;
 
 return Aux;
	
}

/****************************************Generar Disco de Errores PECs***************************/

function GenerarDiscoErrores(TipoError)
{
 var CodigoSujeto=document.getElementById("Codigo").value;
 if(CodigoSujeto==0)
   alert("Ingrese Un Sujeto válido");
 else
     {
	   myWin = open("/SICGNC/ResultadoConsulta/GenerarArchivoErroresPECs.php?TipoError="+TipoError+"&CodigoSujeto="+CodigoSujeto,"displayWindow","width=100,height=100,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes");
	  }
	 
}

/************************************************************************************************/
/***********************Descargar Detalle Obleas por Taller*************************************/
function DevolverDetalleConsultaObleasXFecha()
{
 var FInicial=document.getElementById("FInicial");	
 var CodigoTaller=document.getElementById("CodigoTaller").value;	

 if (!valFecha(FInicial) && !vacio(CodigoTaller))
 {
 ajax=nuevoAjax();
 ajax.open("POST", "/SICGNC/ResultadoConsulta/EncabezadoConsultaObleasXRangoFechas.php",true);
 ajax.onreadystatechange=function() 
  { 
   if (ajax.readyState==4)
    { 
     document.getElementById("Detalle").innerHTML=ajax.responseText;
     } 
  } 
  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  ajax.send("FInicial="+FInicial.value+"&CodigoTaller="+CodigoTaller);
  }
  else
    {
	 alert("Algunas de las fecha han sido mal cargadas");
	}
}
function DescargarObleasXRangoFechas(FInicial,Taller)
{
	window.open("/SICGNC/ResultadoConsulta/DetalleConsultaObleasXFecha.php?FInicial="+FInicial+"&CodigoTaller="+Taller,"VentanaDonwload","width=1,height=1,scrollbars=NO"); 
}
/************************************************************************************************/
function CargaDetalle1(TipoConsulta,Dispositivo)
{
 //Para el caso de que dispositivo sea cero, no lo uso 
 //pero me sirve para no repetir tanto el case
    switch (TipoConsulta)
	{
	 	  case "Dominio":     var Dominio=allTrim(document.getElementById("Dominio").value);
	                    //  if(!ValidarDominio(Dominio))
				//		  {
						   ajax=nuevoAjax();
					       ajax.open("POST", "/SICGNC/CargaDetalle1.php", true);
					       ajax.onreadystatechange=function() 
						    { 
						     if (ajax.readyState==1)
						    {
						     document.getElementById("DetallePrevio").innerHTML="<h2>.....Buscando......</h2>"
						    }
					         if (ajax.readyState==4)
							  { 
							  document.getElementById("DetallePrevio").innerHTML=ajax.responseText;
							  } 
						    }
					      ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					      ajax.send("codigo1="+TipoConsulta+"&codigo2="+Dominio);
		 break;	 
	}
}
function DetalleOperacion1(Pec,Cuit,Num,Taller,Usuario,Grupo,Valor_Consulta,Tipo_Consulta)
{ 
//alert (Tipo_Consulta);
if ((Tipo_Consulta=='Regulador') || (Tipo_Consulta=='Cilindro') || (Tipo_Consulta=='Válvula Cilindro'))
{
var Valor_ConsultaSerie=document.getElementById("Valor_ConsultaSerie").value;	
//alert(Valor_ConsultaSerie);
	window.open("/SICGNC/ResultadoConsulta/Detalle.php?Pec="+Pec+"&Cuit="+Cuit+"&Num="+Num+"&Taller="+Taller+"&Usuario="+Usuario+"&Grupo="+Grupo+"&Tipo_Consulta="+Tipo_Consulta+"&Valor_Consulta="+Valor_Consulta+"&Valor_ConsultaSerie="+Valor_ConsultaSerie,"VentanaDonwload","scrollbars=yes,status=yes,resizable=yes"); 
}
else 
{
window.open("/SICGNC/ResultadoConsulta/Detalle.php?Pec="+Pec+"&Cuit="+Cuit+"&Num="+Num+"&Taller="+Taller+"&Usuario="+Usuario+"&Grupo="+Grupo+"&Tipo_Consulta="+Tipo_Consulta+"&Valor_Consulta="+Valor_Consulta,"VentanaDonwload","scrollbars=yes,resizable=yes,status=yes"); 
}
}

function DetalleOperacionConError(Pec,Cuit,Num,Taller,Usuario,Grupo,Valor_Consulta,Tipo_Consulta)
{ 

 var window_width = 800;
 var window_height = 880;
 var window_top = (screen.height-window_height)/2;
 var window_left = (screen.width-window_width)/2;
 var atributos= 'resizable=no,scrollbars=yes,status=yes';  
 

//alert (Tipo_Consulta);
if ((Tipo_Consulta=='Regulador') || (Tipo_Consulta=='Cilindro') || (Tipo_Consulta=='Válvula Cilindro'))
{
var Valor_ConsultaSerie=document.getElementById("Valor_ConsultaSerie").value;	
//alert(Valor_ConsultaSerie);
	window.open("/SICGNC/ResultadoConsulta/DetalleError.php?Pec="+Pec+"&Cuit="+Cuit+"&Num="+Num+"&Taller="+Taller+"&Usuario="+Usuario+"&Grupo="+Grupo+"&Tipo_Consulta="+Tipo_Consulta+"&Valor_Consulta="+Valor_Consulta+"&Valor_ConsultaSerie="+Valor_ConsultaSerie,"VentanaDonwload","scrollbars=yes,resizable=yes,status=yes"); 
}
else 
{
window.open("/SICGNC/ResultadoConsulta/DetalleError.php?Pec="+Pec+"&Cuit="+Cuit+"&Num="+Num+"&Taller="+Taller+"&Usuario="+Usuario+"&Grupo="+Grupo+"&Tipo_Consulta="+Tipo_Consulta+"&Valor_Consulta="+Valor_Consulta,"VentanaDonwload","scrollbars=yes,resizable=yes,status=yes"); 
}
}
