///////////////////////////////////////////////////////////////////////////
///////////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();
		 }	*/
}
 
}
//////////////////////////////////////////////////////////////////////////////////////////
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("celda_CuityCaja").style.color="red";}else{ document.getElementById("celda_CuityCaja").style.color="black";}
       //alert(OK);
   if(ValidarBocaExpendio(BocaExpendio)){OK=false; document.getElementById("celda_CuityCaja").style.color="red";}else{ document.getElementById("celda_CuityCaja").style.color="black";}
       //alert(OK); 
   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_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()
{
 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 Registro a dar de baja, el usuario soliciatante y la causa de baja");
}

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;
}

/******************************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; 
}
/////////////////////////////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("DetalleEstadoObleas").innerHTML="<h2>.....Cargando......</h2>"
			}
	if (ajax.readyState==4)
		{ 
		document.getElementById("DetalleEstadoObleas").innerHTML=ajax.responseText;
		} 
	}
	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");
  }

}
//////////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"); 
}
}