
function Validar(){
var Grupo=document.getElementById('cmbGrupo');
var Modelo=document.getElementById('IdModelo');

if (Modelo.value == '') {
alert('Debe seleccionar un modelo');
return false;}

if (Grupo.selectedIndex == 0) {
alert('Debe seleccionar un grupo');
return false;}


return true;

}

function MuestraCmbPiezas () 
{
		window.document.getElementById('cmbPiezas').style.visibility = '';
		window.document.getElementById('txtTipear').style.visibility = 'hidden';
		window.document.getElementById('lblTipear').style.color = '';
		window.document.getElementById('lblSeleccionar').style.color = 'red';
		window.document.getElementById('txtTipear').value= '' ;
}		
function MuestraTxtPieza () 
{
	
		window.document.getElementById('cmbPiezas').style.visibility  = 'hidden';
		window.document.getElementById('txtTipear').style.visibility = '';
		window.document.getElementById('lblTipear').style.color = 'red';
		window.document.getElementById('lblSeleccionar').style.color = '';
		window.document.getElementById('cmbPiezas').selectedIndex=0;
		window.document.getElementById('IdPieza').value = 'Seleccione Pieza' ;
}	

function MuestraDetalles(vrp,vconjunto,vpiezacra,vpieza){
popup_detalles_pieza(vrp,vconjunto,vpiezacra,vpieza);
return true;
}

function Ver_Datos_Auto(vrp,vmarca,vmodelo,vtipo,vano,vconjunto,valtamotor){
var rp=document.getElementById('TxtBRp');
var marca = document.getElementById('TxtbMarca');
var modelo = document.getElementById('TxtModelo');
var tipo = document.getElementById('TxtTipo');
var ano = document.getElementById('txtAno');
var Dtgrid=document.getElementById('DtPiezas');
var altamotor=document.getElementById('txtAltaMotor');

rp.value=vrp;
marca.value=vmarca;
modelo.value=vmodelo;
tipo.value=vtipo;
ano.value=vano;
if(valtamotor==0){
altamotor.value='NO';
}else
{
altamotor.value='SI';
}




return true;
}

function popup_detalles_pieza(vrp,vconjunto,vpiezacra,vpieza){
    var opciones="'foto_window','title=Imagen,top=50,left=50,width=349,height=500,titlebar=no,resizable=no,toolbar=no,status=no,location=no,menubar=no,scrollbars=yes'"
    //var opciones="toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, width=655, height=480, top=85, left=140";
    var pag = window.open('wfrmImagenes.aspx?'+ '&RP=' + vrp + '&Conjunto=' + vconjunto + '&PiezaCra=' + vpiezacra + '&Pieza=' + vpieza, "Detalle",opciones);
 
}


function toBin(num) {
	//	base = 2;
	return num.toString(2);
	
}

function mostrar_subgrupos(grupo, subgrupo, pieza,hdnGrupo,hdnSubGrupo,hdnPieza) {
	if (grupo.selectedIndex != 0) {
		subgrupo.length=0;
		subgrupo.length=SGV[grupo.selectedIndex - 1][0].length + 1;
		subgrupo.options[0].value='';
		subgrupo.options[0].text='Seleccione Subgrupo';
		for (var i=1;i<subgrupo.length;i++) {
			subgrupo.options[i].value=SGV[grupo.selectedIndex - 1][0][i-1];
			subgrupo.options[i].text=SGV[grupo.selectedIndex - 1][1][i-1];
		}
		subgrupo.selectedIndex = 0;
		hdnGrupo.value=grupo.value;
		hdnSubGrupo.value='';
		hdnPieza.value='';
	}
	else
	{
		subgrupo.length=0;
		subgrupo.length=1;
		hdnGrupo.value='';
	}
	pieza.length=0;
	return true;
}

function mostrar_piezas(grupo, subgrupo, pieza, hdnsubgrupo, hdn,HdnTxt) {
	if (subgrupo.selectedIndex != 0) {
		hdnsubgrupo.value = subgrupo.value;
		pieza.length=0;
		pieza.length=P[grupo.selectedIndex - 1][subgrupo.selectedIndex - 1][0].length + 1;
		pieza.options[0].value='';
		pieza.options[0].text='Seleccione Pieza';
		for (var i=1;i<pieza.length;i++) {
			pieza.options[i].value=P[grupo.selectedIndex - 1][subgrupo.selectedIndex - 1][0][i-1];
			pieza.options[i].text=P[grupo.selectedIndex - 1][subgrupo.selectedIndex - 1][1][i-1];
		}
		pieza.selectedIndex = 0
		seleccionar_pieza(grupo, subgrupo, pieza, hdn,HdnTxt);
	}
	else
	{
		pieza.length=0;
		pieza.length=1;
		hdn.value='';
		hdnsubgrupo.value='';
	}
	return true;
}

function seleccionar_pieza(grupo, subgrupo, pieza, hdn,HdnTxt) {

	hdn.value=(pieza.selectedIndex==-1)?'':pieza[pieza.selectedIndex].value;
return true;
}

function Mostrar_Modelos(){
//A0 Marca
//A1 Modelo desde
//A2 Modelo Cantidad
	Set_hdnMarca() 
	   
	hdnModelo = window.document.getElementById ('IdModelo');
	window.document.getElementById ('cmbModelos').options.length = 0;
	//window.document.getElementById ('cmbTipos').options.length = 0;
	//window.document.getElementById ('cmbAnio').options.length = 0;
	window.document.getElementById ('cmbModelos').options.length = eval(A2[eval(window.document.getElementById ('cmbMarcas').selectedIndex)]);

	var h=0;
	var desde=eval(A1[eval(window.document.getElementById ('cmbMarcas').selectedIndex)]);
	var hasta=eval(A1[eval(window.document.getElementById ('cmbMarcas').selectedIndex)]) + eval(A2[eval(window.document.getElementById ('cmbMarcas').selectedIndex)]);
	
	for(i=desde;i<hasta;i++){ 
		window.document.getElementById ('cmbModelos').options[h].text = A3[i];
		window.document.getElementById ('cmbModelos').options [h].value = A4[i]; 
		h++;
	}
	hdnModelo.value='';
	window.document.getElementById ('cmbModelos').selectedIndex = -1;
	window.document.getElementById('txtHTipo').value = ''; 
	window.document.getElementById('txtHAnio').value = '';

}
function Mostrar_Modelos_B(){
//A0 Marca
//A1 Modelo desde
//A2 Modelo Cantidad
Set_hdnMarca()
	window.document.getElementById ('cmbModelos').options.length = 0;
	window.document.getElementById ('cmbModelos').options.length = eval(A2[eval(window.document.getElementById ('cmbMarcas').selectedIndex)]);

	var h=0;
	var desde=eval(A1[eval(window.document.getElementById ('cmbMarcas').selectedIndex)]);
	var hasta=eval(A1[eval(window.document.getElementById ('cmbMarcas').selectedIndex)]) + eval(A2[eval(window.document.getElementById ('cmbMarcas').selectedIndex)]);

	for(i=desde;i<hasta;i++){ 
		window.document.getElementById ('cmbModelos').options[h].text = A3[i];
		window.document.getElementById ('cmbModelos').options [h].value = i; 
		h++;
	}
	window.document.getElementById ('cmbModelos').selectedIndex = -1;
}

function Mostrar_Anios(){
    Set_hdnModelo()
    
}

function Mostrar_Tipos(){
//A8 Desc_Tipo
//A9 Codia
//A10 Año Desde
//A11 Cantidad Años
//A12 Equip
	Set_hdnAnio();
	window.document.getElementById('cmbTipos').options.length = 0;

	var h = 0;
	var AnioD = 0;
	var AnioH = 0;
	var Anio = eval(window.document.getElementById('cmbAnio').options[window.document.getElementById('cmbAnio').selectedIndex].value);
	var desde = eval(A4[window.document.getElementById('cmbModelos').options[window.document.getElementById('cmbModelos').selectedIndex].value]);
	var hasta = eval(A4[window.document.getElementById('cmbModelos').options[window.document.getElementById('cmbModelos').selectedIndex].value]) + eval(A5[window.document.getElementById('cmbModelos').options[window.document.getElementById('cmbModelos').selectedIndex].value]);
	for ( i=desde; i<hasta; i++){

		AnioD = Get_Anio(eval(A10[i]));
		AnioH = AnioD + eval(A11[i]) - 1;

		if ((Anio >= AnioD) && (Anio <= AnioH)){
			window.document.getElementById('cmbTipos').options.length++;
			window.document.getElementById('cmbTipos').options [h].text = A8[i];
			window.document.getElementById('cmbTipos').options [h].value = eval(A9[i]);
			h++;
		}
	}

	//window.document.getElementById('txtHVehic').value = 'False';
	window.document.getElementById ('cmbTipos').selectedIndex = -1;
	window.document.getElementById('txtHTipo').value = ''; //Ésto va para que el txtHTipo esté vacío siempre a menos que los datos del coche estén completos


}

function Set_hdnTipo(){
//CARGA EN EL HIDDEN EL VALOR SELECCIONADO DEL TIPO
	window.document.getElementById('txtHTipo').value = window.document.getElementById ('cmbTipos').options[window.document.getElementById ('cmbTipos').selectedIndex].text;
	window.document.getElementById('IdTipo').value = window.document.getElementById ('cmbTipos').options[window.document.getElementById ('cmbTipos').selectedIndex].value;
	mostrar_eqipamiento();
}

function Set_hdnAnio(){
//CARGA EN EL HIDDEN EL VALOR SELECCIONADO DEL ANIO
	window.document.getElementById('txtHAnio').value = window.document.getElementById ('cmbAnio').options[window.document.getElementById ('cmbAnio').selectedIndex].text;
	window.document.getElementById('IdAnio').value = window.document.getElementById ('cmbAnio').options[window.document.getElementById ('cmbAnio').selectedIndex].value;
}

function Set_hdnModelo(){
//CARGA EN EL HIDDEN EL VALOR SELECCIONADO DEL MODELO
	window.document.getElementById('txtHVehic').value = window.document.getElementById ('cmbModelos').options[window.document.getElementById ('cmbModelos').selectedIndex].text;
	window.document.getElementById('IdModelo').value = window.document.getElementById ('cmbModelos').options[window.document.getElementById ('cmbModelos').selectedIndex].value;
}
function Set_hdnMarca(){
//CARGA EN EL HIDDEN EL VALOR SELECCIONADO DEL MArca
	window.document.getElementById('txtHMarca').value = window.document.getElementById ('cmbMarcas').options[window.document.getElementById ('cmbMarcas').selectedIndex].text;
	window.document.getElementById('IdMarca').value = window.document.getElementById ('cmbMarcas').options[window.document.getElementById ('cmbMarcas').selectedIndex].value;
}

function Set_hdnPieza(){
//CARGA EN EL HIDDEN EL VALOR SELECCIONADO DE La PIEZA
	window.document.getElementById('txtHPieza').value = window.document.getElementById ('cmbPiezas').options[window.document.getElementById ('cmbPiezas').selectedIndex].text;
	window.document.getElementById('IdPieza').value = window.document.getElementById ('cmbPiezas').options[window.document.getElementById ('cmbPiezas').selectedIndex].value;
}

function Get_Anio(val){
	if (val < 50){
		val = 2000 + val;
	}else{
		val = 1900 + val;
	}
	return val;
}


