// MENU Y SUBMENU
function mostrarmenu(cual) {
	document.getElementById('menudesplegado'+cual).style.visibility='visible';
}
function ocultarmenu(cual) {
	document.getElementById('menudesplegado'+cual).style.visibility='hidden';
}

// VALIDAR BUSCADRO DE ARTICULOS QUE NO ESTE VACIO
function validarbusqueda() {
		var f = document.buscarticulo;
		if (f.palabra.value==''){
			alert('No hay nada que buscar');
		} else {
		document.buscarticulo.submit();
		}
}

// DESACTIVAR ENTER PARA LOS FORMUALRIOS
function pulsar(e) {
  tecla = (document.all) ? e.keyCode : e.which;
  return (tecla != 13);
}


// COMPRUEBA DATOS DE FACTURACION
function compruebafacturacion() {
	
	if(document.datos.factdiferente.checked) {
		document.datos.factnombre.disabled = false;
		document.datos.factdninifcif.disabled = false;
		document.datos.factdireccion.disabled = false;
		document.datos.factcp.disabled = false;
		document.datos.factpoblacion.disabled = false;
		document.datos.factprovinciaauto.disabled = false;
		document.datos.factprovinciamanual.disabled = false;
		document.datos.factpais.disabled = false;
		document.datos.factnombre.value = '';
	} else {
		document.datos.factnombre.disabled = true;
		document.datos.factdninifcif.disabled = true;
		document.datos.factdireccion.disabled = true;
		document.datos.factcp.disabled = true;
		document.datos.factpoblacion.disabled = true;
		document.datos.factprovinciaauto.disabled = true;
		document.datos.factprovinciamanual.disabled = true;
		
		document.datos.factpais.disabled = true;
		if (document.datos.nombrefiscal.value != ''){
			document.datos.factnombre.value = document.datos.nombrefiscal.value;
		} else {
			document.datos.factnombre.value = document.datos.nombre.value + ' ' + document.datos.apellidos.value;
		}
		document.datos.factdninifcif.value = document.datos.dninifcif.value; 
		document.datos.factdireccion.value = document.datos.direccion.value;
		document.datos.factcp.value = document.datos.cp.value;
		document.datos.factpoblacion.value = document.datos.poblacion.value;
		if (document.datos.factpais.value == 60){
			document.datos.factprovinciaauto.value = document.datos.provinciaauto.value;
			document.datos.factprovinciamanual.value = '';
		} else {
			document.datos.factprovinciamanual.value = document.datos.provinciamanual.value;
		}
		document.datos.factpais.value = document.datos.pais.value;
	}
}

// COMPRUEBA DATOS DE ENVÍO
function compruebadatosenvio() {
	if (document.datos.envdiferente.checked) {
			document.datos.envnombre.disabled = false;
			document.datos.envdireccion.disabled = false;
			document.datos.envcp.disabled = false;
			document.datos.envpoblacion.disabled = false;
			document.datos.envprovinciaauto.disabled = false;
			document.datos.envprovinciamanual.disabled = false;
			document.datos.envpais.disabled = false;
			document.datos.envnombre.value = '';
	} else {
			document.datos.envnombre.disabled = true;
			document.datos.envdireccion.disabled = true;
			document.datos.envcp.disabled = true;
			document.datos.envpoblacion.disabled = true;
			document.datos.envprovinciaauto.disabled = true;
			document.datos.envprovinciamanual.disabled = true;
			document.datos.envpais.disabled = true;
			if (document.datos.nombrefiscal.value != ''){
				document.datos.envnombre.value = document.datos.nombrefiscal.value;
			} else {
				document.datos.envnombre.value = document.datos.nombre.value + ' ' + document.datos.apellidos.value;
			}
			document.datos.envdireccion.value = document.datos.direccion.value;
			document.datos.envcp.value = document.datos.cp.value;
			document.datos.envpoblacion.value = document.datos.poblacion.value;
			if (document.datos.envpais.value == 60){
				document.datos.envprovinciaauto.value = document.datos.provinciaauto.value;
				document.datos.envprovinciamanual.value = '';
			} else {
				document.datos.envprovinciamanual.value = document.datos.provinciamanual.value;
			}
			document.datos.envpais.value = document.datos.pais.value;
	}
}

/* COMPROBAR PAIS Y PROVINCIA */
function compruebapais(pais) {
	if (document.datos.pais.value == 60){
			document.getElementById('provinciainput').style.display='none';
			document.getElementById('provinciaselect').style.display='';
		} else {
			document.getElementById('provinciainput').style.display='';
			document.getElementById('provinciaselect').style.display='none';
	}
	if (document.datos.factpais.value == 60){
			document.getElementById('factprovinciainput').style.display='none';
			document.getElementById('factprovinciaselect').style.display='';
		} else {
			document.getElementById('factprovinciainput').style.display='';
			document.getElementById('factprovinciaselect').style.display='none';
	}
	if (document.datos.envpais.value == 60){
			document.getElementById('envprovinciainput').style.display='none';
			document.getElementById('envprovinciaselect').style.display='';
		} else {
			document.getElementById('envprovinciainput').style.display='';
			document.getElementById('envprovinciaselect').style.display='none';
	}
}

function calcularimportefinal(iva, lang) {
	
	if(lang==''){
		txt_1='Importe base: ';
		txt_2='IVA: ';
		txt_3='Importe total: ';
	} else {
		txt_1='Price: ';
		txt_2='Taxes: ';
		txt_3='Total Price: ';
	}
	
		var total = 0;
		document.getElementById('mostrarimporte').innerHTML = txt_1+document.getElementById(document.tarifa.modalidad.value+'-'+document.tarifa.tarificacion.value).value+' €';
		if (document.tarifa.iva.value == 0){
			var total = ((document.getElementById(document.tarifa.modalidad.value+'-'+document.tarifa.tarificacion.value).value)/100)*(100+parseFloat(iva));
			document.getElementById('mostrariva').innerHTML = txt_2+iva+'%';
		} else {
			var total = document.getElementById(document.tarifa.modalidad.value+'-'+document.tarifa.tarificacion.value).value;
			document.getElementById('mostrariva').innerHTML = '';
		}
		
		document.getElementById('mostrartotal').innerHTML = txt_3+(Math.round(total*100)/100)+' €';
		document.tarifa.importefinal.value = Math.round(total*100)/100;
	
	}
	

var win = null;
function openWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=no'
	win = window.open(mypage,myname,settings)
}