//*****************************************
//**************** MARCAS *****************
//*****************************************
function fValidarDatosMarca(strOpcion){
	strNombre = document.frmMarcas.txtNombre.value;
	if (strNombre=="") {alert(fM("IntroduzcaNombreMarca"));return;}
	if(strOpcion == "n"){
		strImagen=document.frmMarcas.txtImagen.value;
		if (strImagen=="") {alert(fM("IntroduzcaImagen"));return;}
	}
	document.frmMarcas.submit();
}
//****************************************
function fAseguraBorrarMarca(){
	intCuantos=document.frmLista.Cuantos.value;
	i=0;
	sw=0;
	if (intCuantos=="1"){if (document.frmLista.marca.checked){sw=1;}
	}else{
		while (i<intCuantos){
			if (document.frmLista.marca[i].checked){sw=1;}
			i++;
		}
	}
	if (sw=="1"){
		if (confirm(fM("SeguroBorrarMarcas"))){document.frmLista.submit();}
		else{return;}
	}else{alert(fM("SeleccioneMarca"));return;}
}
//****************************************
function fAsegurarBorrarUnaMarca(intCodigo){if (confirm(fM("SeguroBorrarMarca"))){location.href='index.asp?pg=4&CodMarca='+intCodigo}}
//****************************************
function fValidarBuscar (){document.frmBuscar.submit();}
//****************************************
function fLimpiarBuscadorMarcas(){document.frmBuscar.txtNombre.value="";return;}
//*****************************************
//*************** FAMILIAS ****************
//*****************************************
function fAseguraBorrarImagen (intCodFamilia){
	if(confirm(fM("SeguroBorrarImagen"))){
		location.href='index.asp?pg=20&CodFamilia='+intCodFamilia;
	}else{
		return;
	}
}
//*****************************************
function fValidarDatosFamilia(){
	sw=0;
	i=1;
	intCuantos = document.frmFamilias.Cuantos.value;
	while (i<=intCuantos){
		if(eval('document.frmFamilias.txtNombre'+i+'.value')!=""){sw++;}
		i++;
	}
	
	if (sw==0) {alert(fM("IntroduzcaNombreFamiliaIdioma"));return;}
	fRellenarFamiliasVacias (intCuantos);
	document.frmFamilias.submit();
}
//****************************************
function fRellenarFamiliasVacias (intCuantos){
	i=1;
	while (i<=intCuantos){
		strIdioma = eval('document.frmFamilias.Idioma'+i+'.value');
		switch (strIdioma){
			case "es": strES = eval('document.frmFamilias.txtNombre'+i+'.value');break;
			case "pt": strPT = eval('document.frmFamilias.txtNombre'+i+'.value');break;
		}
		i++;
	}
	
	
	if (strES != ""){strIdioma = strES ;}else{if (strPT != ""){strIdioma = strPT ;}}
	
	if(strES==""){strES=strIdioma;}
	if(strPT==""){strPT=strIdioma;}
	
	i=1;
	while (i<=intCuantos){
		strIdioma = eval('document.frmFamilias.Idioma'+i+'.value');
		switch (strIdioma){
			case "es": eval('document.frmFamilias.txtNombre'+i+'.value=strES'); break;
			case "pt": eval('document.frmFamilias.txtNombre'+i+'.value=strPT'); break;
		}
		i++;
	}
}
//****************************************
//function fAseguraBorrarFamilia(){
//	intCuantos=document.frmLista.Cuantos.value;
//	i=0;
//	sw=0;
//	if (intCuantos=="1"){if (document.frmLista.familia.checked){sw=1;}
//	}else{
//		while (i<intCuantos){
//			if (document.frmLista.familia[i].checked){sw=1;}
//			i++;
//		}
//	}
//	if (sw=="1"){
//		if (confirm(fM("SeguroBorrarFamilias"))){document.frmLista.submit();}
//		else{return;}
//	}else{alert(fM("SeleccioneFamilia"));return;}
//}
//****************************************
function fAsegurarBorrarUnaFamilia(intCodigo){if (confirm(fM("SeguroBorrarFamilia"))){location.href='index.asp?pg=9&CodFamilia='+intCodigo}}
//****************************************
function fValidarBuscar (){document.frmBuscar.submit();}
//****************************************
function fLimpiarBuscadorFamilias(strIdioma){
	document.frmBuscar.cboIdioma.value=strIdioma;
	document.frmBuscar.txtNombre.value="";
	document.frmBuscar.CodMarca.value="0";
	return;
}
//*****************************************
//*************** MODELOS *****************
//****************************************
function fAseguraBorrarModelo(){
	intCuantos=document.frmLista.Cuantos.value;
	i=0;
	sw=0;
	if (intCuantos=="1"){if (document.frmLista.chkModelo.checked){sw=1;}
	}else{
		while (i<intCuantos){
			if (document.frmLista.chkModelo[i].checked){sw=1;}
			i++;
		}
	}
	if (sw=="1"){
		if (confirm(fM("SeguroBorrarModelos"))){document.frmLista.submit();}
		else{return;}
	}else{alert(fM("SeleccioneModelo"));return;}
}
//*************************************************
function fCargarFamilias (strForm,strRelacion,strDonde,intSelecciona,strPrimero){
	intCodigo = eval('document.'+strForm+'.'+strRelacion+'.value');
	strCombo=strForm + "." + strDonde;
	if (intCodigo != "0"){
		strArray="Familia";
		intLongArray = eval("aint"+strArray+intCodigo+".length");
		if (intLongArray==0){
			if (strPrimero != ""){
				strPrimero = "-- " + fM("NoHayFamilias") + " --";
			}
		}
		fVaciarCombo(strCombo);
		if (strPrimero == "multiple"){
			for (i=0;i<intLongArray-1;i++){
				eval("document."+strCombo+".options[i]=new Option(astr"+strArray+intCodigo+"[i+1],aint"+strArray+intCodigo+"[i+1])");
			}
		}else{
			eval("document."+strCombo+".options[0]=new Option('','0')");
			for (i=1;i<intLongArray;i++){
				eval("document."+strCombo+".options[i]=new Option(astr"+strArray+intCodigo+"[i],aint"+strArray+intCodigo+"[i])");
			}
		}
	}else{
		fVaciarCombo(strCombo);
		eval("document."+strCombo+".options[0]=new Option('"+strPrimero+"','0')");
	}
	
	if (intSelecciona != ""){eval("document."+strCombo+".value="+intSelecciona);}
}
//*************************************
function fVaciarCombo(strCombo)
{	intContadorcillo=0;
	strAuxiliar="document."+strCombo+".options.length";
	intTotal=(eval(strAuxiliar));
	while (intTotal>intContadorcillo)
	{	
		eval("document."+strCombo+".options[0]=null");
		intContadorcillo++;
	}
}
//****************************************
function fLimpiarBuscadorModelos(strIdioma){
	document.frmBuscar.cboIdioma.value=strIdioma;
	document.frmBuscar.txtNombre.value="";
	document.frmBuscar.txtReferencia.value="";
	document.frmBuscar.CodMarca.value="0";
	strCombo = "frmBuscar.CodFamilia";
	strPrimero = "-- " + fM("Todas") + " --";
	fVaciarCombo(strCombo);
	eval("document."+strCombo+".options[0]=new Option('"+strPrimero+"','0')");
	return;
}
//****************************************
function fLimpiarBuscadorRefs (){
	document.frmBuscar.txtTexto.value="";
	document.frmBuscar.txtRef.value="";
	return;
}
//****************************************
function fValidarDatosModelo (strOpcion){
	//VALIDAMOS LOS DATOS GENEREALES DEL MODELO
	//if (document.frmModelo.cboMarca.value=="0"){alert(fM("SeleccioneMarca"));return;}
	if (document.frmModelo.CodFamilia.value=="0"){alert(fM("SeleccioneFamilia"));return;}
	if (document.frmModelo.txtNombre.value==""){alert(fM("IntroduzcaNombreModelo"));return;}
	if (document.frmModelo.txtTexto.value==""){alert(fM("IntroduzcaDescripcion"));return;}
	if (document.frmModelo.hdnImagen2.value!="" || document.frmModelo.txtImagen2.value!=""){
		if (document.frmModelo.hdnImagen.value=="" && document.frmModelo.txtImagen.value==""){
			alert(fM("IntroduzcaImagenParaImagen2"));return;
		}
		if (document.frmModelo.txtAlt.value==""){
			alert(fM("IntroduzcaDescCortaWai"));return;
		}
	}
	
	document.frmModelo.submit();
}
//******************************************
function fAsegurarBorrarBloque (intBloque,intCodBloque,intCodModelo,strCodIdioma){
	intOrden = eval('document.frmModelo.cboOrden'+intBloque+'.value');
	if (intOrden==1){strMensaje = fM("SeguroBorrarBloque1");}else{strMensaje = fM("SeguroBorrarBloque");}
	if(confirm(strMensaje)){
		location.href = "index.asp?pg=16&CodModelo="+intCodModelo+"&CodBloque="+intCodBloque+"&CodIdioma="+strCodIdioma;
	}else{return;}
}
//******************************************
function fVerAlineaciones (intBloque){
	strTexto = eval('document.frmModelo.txtTexto'+intBloque+'.value');
	strFoto = eval('document.frmModelo.txtImagen'+intBloque+'.value');
	strFoto2 = eval('document.frmModelo.Imagen'+intBloque+'.value');
	strCapa1 = 'divIzquierda'+intBloque;
	strCapa2 = 'divDerecha'+intBloque;
	strCapa3 = 'divCentro'+intBloque;
	
	MM_showHideLayers (strCapa1,'','hidden');
	MM_showHideLayers (strCapa2,'','hidden');
	MM_showHideLayers (strCapa3,'','hidden');
	if (strFoto != "" || strFoto2 != ""){
		MM_showHideLayers (strCapa1,'','show');
		MM_showHideLayers (strCapa2,'','show');
		if (strTexto == ""){
			MM_showHideLayers (strCapa3,'','show');
		}
	}
}
//******************************************
function fAsegurarBorrarFicha (strOpcion,intModelo,strIdioma){
	switch (strOpcion) {
		case "t" : {strMensaje = fM("SeguroBorrarFichaTecnica");}break;
		case "s" : {strMensaje = fM("SeguroBorrarFichaSeguridad");}break;
		case "m" : {strMensaje = fM("SeguroBorrarManual");}break;
		case "v" : {strMensaje = fM("SeguroBorrarVideo");}break;
		case "i" : {
			if (document.frmModelo.hdnImagen2.value!="" || document.frmModelo.txtImagen2.value!=""){
				alert("Para borrar la imagen del modelo, debes borrar primero la imagen ampliada.");return;
			}else{
				strMensaje = fM("SeguroBorrarImagen");
			}
			break;
		}
		case "i2" : {strMensaje = fM("SeguroBorrarImagen");}break;
	}
	if(confirm(strMensaje)){location.href="index.asp?pg=15&Tipo="+strOpcion+"&CodModelo="+intModelo+"&CodIdioma="+strIdioma;}
	else{return;}
}
//******************************************
function fAsegurarBorrarImagenBloque (intCodBloque,intModelo,strIdioma){
	if(confirm(fM("SeguroBorrarImagen"))){location.href="index.asp?pg=17&CodBloque="+intCodBloque+"&CodModelo="+intModelo+"&CodIdioma="+strIdioma;}
	else{return;}
}
//******************************************
function fAsegurarBorrarUnModelo (intCodModelo,strCodIdioma){
	if(confirm(fM("SeguroBorrarModelo"))){location.href="index.asp?pg=13&CodModelo="+intCodModelo+"&CodIdioma="+strCodIdioma;}
	else{return;}
}
//******************************************
function fValidarDatosLote (){
	if(document.frmLote.txtNum.value==""){alert(fM("IntroduzcaNumLote"));return;}
	if(document.frmLote.txtPdf.value=="" && document.frmLote.hdnPdf.value==""){alert(fM("IntroduzcaPDFBoletin"));return;}
	document.frmLote.submit();
}
//******************************************
function fAsegurarBorrarUnLote (){
	if (confirm("AVISO: Si borra un lote y no exite en otros idioma, se eliminarán las relaciones a él asignadas.\n¿Está seguro que desea borrar este lote en este idioma?")){
		intCodLote = document.frmLote.CodLote.value;
		strCodIdioma = document.frmLote.CodIdioma.value;
		location.href='index.asp?pg=33&CodLote='+intCodLote+'&CodIdioma='+strCodIdioma;	}else{
		return;
	}
}
//******************************************
//**************** WEB *********************
//******************************************
function fValidarUnidades (){
	if(document.frmComprar.txtUnidades.value==""){alert(fM("IntroduzcaCantidad"));return;}
	if(isNaN(document.frmComprar.txtUnidades.value)){alert(fM("CantidadNumerico"));return;}
	document.frmComprar.submit ();
}
//***********************************************
function fSubirFamilia (){
	cuantos = document.frmModelo.CodFamilia.options.length;
	Seleccionado = document.frmModelo.CodFamilia.selectedIndex;
	Seleccionado = Seleccionado + 1;
	SeleccionadoM = Seleccionado - 1;
	if (document.frmModelo.CodFamilia.selectedIndex != 0){
		Valor1=document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex].text;
		Valor2=document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex-1].text;
		Cod1=document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex].value;
		Cod2=document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex-1].value;
		document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex].text=Valor2;
		document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex-1].text=Valor1;
		document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex].value=Cod2;
		document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex-1].value=Cod1;
		
		b=0;
		strOrdenF = "";
		while (cuantos>b){
			strOrdenF = strOrdenF + ", " + document.frmModelo.CodFamilia.options[b].value;
			b++;
		}
		document.frmModelo.arrOrdenF.value=strOrdenF;

		document.frmModelo.CodFamilia.selectedIndex=document.frmModelo.CodFamilia.selectedIndex-1;
		
	}
}
//***********************************************
function fBajarFamilia (){
	cuantos = document.frmModelo.CodFamilia.options.length;
	if (cuantos != document.frmModelo.CodFamilia.selectedIndex){
		Valor1=document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex].text;
		Valor2=document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex+1].text;
		Cod1=document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex].value;
		Cod2=document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex+1].value;
		document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex].text=Valor2;
		document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex+1].text=Valor1;
		document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex].value=Cod2;
		document.frmModelo.CodFamilia.options[document.frmModelo.CodFamilia.selectedIndex+1].value=Cod1;
		
		b=0;
		strOrdenF = "";
		while (cuantos>b){
			strOrdenF = strOrdenF + ", " + document.frmModelo.CodFamilia.options[b].value;
			b++;
		}
		document.frmModelo.arrOrdenF.value=strOrdenF;
		document.frmModelo.CodFamilia.selectedIndex=document.frmModelo.CodFamilia.selectedIndex+1;
	}
}
//***********************************************
function fSubirSubFamilia (){
	cuantos = document.frmModelo.CodSubFamilia.options.length;
	Seleccionado = document.frmModelo.CodSubFamilia.selectedIndex;
	Seleccionado = Seleccionado + 1;
	SeleccionadoM = Seleccionado - 1;
	if (document.frmModelo.CodSubFamilia.selectedIndex != 0){
		Valor1=document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex].text;
		Valor2=document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex-1].text;
		Cod1=document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex].value;
		Cod2=document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex-1].value;
		document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex].text=Valor2;
		document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex-1].text=Valor1;
		document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex].value=Cod2;
		document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex-1].value=Cod1;
		
		b=0;
		strOrdenSF = "";
		while (cuantos>b){
			strOrdenSF = strOrdenSF + ", " + document.frmModelo.CodSubFamilia.options[b].value;
			b++;
		}
		document.frmModelo.arrOrdenF.value=strOrdenSF;
		document.frmModelo.CodSubFamilia.selectedIndex=document.frmModelo.CodSubFamilia.selectedIndex-1;
	}
}
//***********************************************
function fBajarSubFamilia (){
	cuantos = document.frmModelo.CodSubFamilia.options.length;
	if (cuantos != document.frmModelo.CodSubFamilia.selectedIndex){
		Valor1=document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex].text;
		Valor2=document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex+1].text;
		Cod1=document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex].value;
		Cod2=document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex+1].value;
		document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex].text=Valor2;
		document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex+1].text=Valor1;
		document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex].value=Cod2;
		document.frmModelo.CodSubFamilia.options[document.frmModelo.CodSubFamilia.selectedIndex+1].value=Cod1;
		
		b=0;
		strOrdenSF = "";
		while (cuantos>b){
			strOrdenSF = strOrdenSF + ", " + document.frmModelo.CodSubFamilia.options[b].value;
			b++;
		}
		document.frmModelo.arrOrdenF.value=strOrdenSF;
		document.frmModelo.CodSubFamilia.selectedIndex=document.frmModelo.CodSubFamilia.selectedIndex+1;
	}
}
//***********************************************
function fSubirSubSubFamilia (){
	cuantos = document.frmModelo.CodSubSubFamilia.options.length;
	Seleccionado = document.frmModelo.CodSubSubFamilia.selectedIndex;
	Seleccionado = Seleccionado + 1;
	SeleccionadoM = Seleccionado - 1;
	if (document.frmModelo.CodSubSubFamilia.selectedIndex != 0){
		Valor1=document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex].text;
		Valor2=document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex-1].text;
		Cod1=document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex].value;
		Cod2=document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex-1].value;
		document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex].text=Valor2;
		document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex-1].text=Valor1;
		document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex].value=Cod2;
		document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex-1].value=Cod1;
		
		b=0;
		strOrdenSSF = "";
		while (cuantos>b){
			strOrdenSSF = strOrdenSSF + ", " + document.frmModelo.CodSubSubFamilia.options[b].value;
			b++;
		}
		document.frmModelo.arrOrdenSSF.value=strOrdenSSF;
		document.frmModelo.CodSubSubFamilia.selectedIndex=document.frmModelo.CodSubSubFamilia.selectedIndex-1;
		
	}
}
//***********************************************
function fBajarSubSubFamilia (){
	cuantos = document.frmModelo.CodSubSubFamilia.options.length;
	if (cuantos != document.frmModelo.CodSubSubFamilia.selectedIndex){
		Valor1=document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex].text;
		Valor2=document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex+1].text;
		Cod1=document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex].value;
		Cod2=document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex+1].value;
		document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex].text=Valor2;
		document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex+1].text=Valor1;
		document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex].value=Cod2;
		document.frmModelo.CodSubSubFamilia.options[document.frmModelo.CodSubSubFamilia.selectedIndex+1].value=Cod1;
		
		b=0;
		strOrdenSSF = "";
		while (cuantos>b){
			strOrdenSSF = strOrdenSSF + ", " + document.frmModelo.CodSubSubFamilia.options[b].value;
			b++;
		}
		document.frmModelo.arrOrdenSSF.value=strOrdenSSF;
		document.frmModelo.CodSubSubFamilia.selectedIndex=document.frmModelo.CodSubSubFamilia.selectedIndex+1;
	}
}
//****************************************************
function fValidarBuscarLote (){
	if(document.frmBuscar.txtBuscarLote.value==""){alert(fM("IntroduzcaNumLote"));return;}
	document.frmBuscar.submit();
}
//****************************************************
function fLimpiarBuscadorLotes (){
	document.frmBuscar.txtNum.value="";
	return;
}
//******************************************
function fAseguraBorrarFichaRef (intRef,strIdioma){
	strMensaje = fM("SeguroBorrarFichaRef");
	if(confirm(strMensaje)){location.href="index.asp?pg=39&CodRef="+intRef+"&CodIdioma="+strIdioma;}
	else{return;}
}