// JavaScript Document

/* quita borde punteado de los links --- by Anxo------------------------------------------------------------------------*/
function noplink() {
	lnks=document.getElementsByTagName("a").length;
	for (i=0;i<lnks;i++)
	document.getElementsByTagName("a").item(i).onfocus=new Function(" (this.blur)?this.blur():NULL;")
}

/* calcula el precio de venta ---------------------------------------------------------------------------*/
function  calcularPrecioVenta(){
	
	if(document.getElementById('precio').value!=''){pvp=precio=parseFloat(document.getElementById('precio').value);}
	if(document.getElementById('iva').value!=''){
			pvp=Math.round((precio*(1+(parseFloat(document.getElementById('iva').value)/100)))*100)/100;
			document.getElementById('iva_incluido').innerHTML="IVA incluído";
	}else{document.getElementById('iva_incluido').innerHTML="+ IVA";}
	
	if(isNaN(pvp)){document.getElementById('precio_venta').innerHTML='';}
	else{document.getElementById('precio_venta').innerHTML=pvp+' €';}
}

/* abre una imagen en un pop-up ---------------------------------------------------------------------------*/
function abrirImagen(root, img, ancho, alto){
	url=((root!='')?root+'/':'')+"mostrar_img.php?img="+img;
	window.open(url , 'img', 'width='+ancho+', height='+alto+', menubar=no,location=no,resizable=no,scrollbars=yes,status=no');	
}

/*********************************************/
function cargarImagenCabecera(root, id_img){
	root.getElementById('img_cabecera').src='imgs/imgs_cabecera/img_'+id_img+'.jpg';
}

/*********************************************/

/* modifica las opciones de los desplegables de Categoría y Marca de producto en función de la familia de producto seleccionada */
function cambiarDesplegablesCategoriaMarca(familia){

	// cambiamos el desplegable de las marcas en función de la familia indicada
	marcas=new Array(
			new Array('moto', new Array(new Array('yamaha', 'Yamaha'), new Array('aprilia', 'Aprilia'), new Array('hyosung', 'Hyosung'), new Array('sym', 'Sym'))),
			new Array('coche sin carné', new Array(new Array('ligier', 'Ligier'), new Array('microcar', 'Microcar'))),
			new Array('quad', new Array(new Array('hyosung', 'Hyosung'), new Array('ligier', 'Ligier'))),
			new Array('casco', new Array(new Array('agv', 'agv'), new Array('airoh', 'Airoh'), new Array('astyle', 'A-Style'), new Array('bks', 'bks'), new Array('cms', 'CMS'), new Array('hebo', 'Hebo'), new Array('hellokitty', 'Hello Kitty'), new Array('nolan', 'Nolan'), new Array('nzi', 'NZI'), new Array('schuberth', 'Schuberth'), new Array('shiro', 'Shiro'), new Array('xlite', 'X-lite'))),
			new Array('ropa', new Array(new Array('alpinestars', 'Alpinestars'), new Array('bikers', 'Bikers'), new Array('bks', 'bks'), new Array('garibaldi', 'Garibaldi'), new Array('hebo', 'Hebo'), new Array('held', 'Held'), new Array('ixon', 'Ixon'), new Array('levior', 'Levior'), new Array('miline', 'Miline'), new Array('sidi', 'SIDI'), new Array('tucano', 'Tucano Urbano'))),
			new Array('accesorios moto', new Array(new Array('bel-ray', 'Bel-Ray'), new Array('givi', 'Givi'), new Array('hebo', 'Hebo'), new Array('held', 'Held'), new Array('luma', 'Luma'), new Array('motogp', 'MotoGP'), new Array('polini', 'Polini'), new Array('puig', 'Puig'), new Array('shad', 'Shad'), new Array('spaan', 'Spaan')))
			);
	
	for(i=0; i<(marcas.length); i++){
		if(marcas[i][0]==familia){
			for(j=0;j<(marcas[i][1].length); j++){
				op = document.createElement("OPTION");
				op.value = marcas[i][1][j][0]; 
				op.text = marcas[i][1][j][1];
  				document.getElementById('marca_producto').options[j] = op;
			}
		}	
	}
	if(document.getElementById('marca_producto').options.length>j){
		k=document.getElementById('marca_producto').options.length;
		while(k>j){k--;
			document.getElementById('marca_producto').options[k]=null;		
			
		}	
	}
	
	// cambiamos el desplegable de las categorias en función de la familia indicada
	categorias=new Array(
				new Array('moto', new Array(new Array('125cc_scooter', '125 cc scooter'), new Array('maxi_scooter', 'Maxi scooter'), new Array('supersport', 'Supersport'), new Array('touring', 'Touring'), new Array('50cc', '50 cc'), new Array('125cc', '125 cc'), new Array('cruisser', 'Cruisser'), new Array('aventura', 'Aventura'))),
				new Array('quad', new Array(new Array('atv', 'ATV'), new Array('deportivo', 'Deportivo'), new Array('infantil', 'Infantil'))),
				new Array('casco', new Array(new Array('abiertos', 'Abiertos'), new Array('abatibles', 'Abatibles'), new Array('cross', 'Cross'), new Array('integrales', 'Integrales'), new Array('trial', 'Trial'), new Array('otros', 'Otros'))),
				new Array('ropa', new Array(new Array('guantes', 'Guantes'), new Array('textil', 'Textil'), new Array('piel', 'Piel'), new Array('botas', 'Botas'), new Array('agua', 'Agua'), new Array('termicos', 'Térmicos'), new Array('complementos', 'Complementos'), new Array('otros', 'Otros'))),
				new Array('accesorios moto', new Array(new Array('equipajes', 'Equipajes'), new Array('parabrisas', 'Parabrisas'), new Array('otros', 'Otros')))
				);
	categoria_encontrada=false;
	for(i=0; i<(categorias.length); i++){
		if(categorias[i][0]==familia){
			categoria_encontrada=true;
			for(j=0;j<(categorias[i][1].length); j++){
				op = document.createElement("OPTION");
				op.value = categorias[i][1][j][0]; 
				op.text = categorias[i][1][j][1];
  				document.getElementById('categoria_producto').options[j] = op;
			}
		}	
	}
	if(i==(categorias.length) && !categoria_encontrada){
		j=0;	
	}
	
	if(document.getElementById('categoria_producto').options.length>j){
		k=document.getElementById('categoria_producto').options.length;
		while(k>j){k--;
			document.getElementById('categoria_producto').options[k]=null;		
			
		}	
	}


}
