function actualizarDatos(){
	
	if (compruebaCampos()){
		document.tienda.accion.value="ActualizarCarro";
		document.tienda.submit();
	}
	
}

function isNum(pNum){
	
	pNum=pNum*1;
	if (isNaN(pNum)){
		return false;
	}
	else{
		return true;
	}
}

function abreImagen(pImagen,pAncho,pAltura,pid){
	
	if (pAltura==""){
		pAltura=500;
	}
	else{
		if (pAltura>750){
			pAltura=750;
		}
		else{
			pAltura=pAltura+16;
		}
	}
	if (pAncho==""){
		pAncho=600;
	}
	else{
		if (pAncho>990){
			pAncho=990;
		}
		else{
			pAncho=pAncho+16;
		}
	}
	
	posleft=(devuelveTamanoPantalla(1)-pAncho)/2;
	postop=(devuelveTamanoPantalla(2)-pAltura)/2;
	
	ventana=window.open(pImagen,"FotoProducto"+pid,"height="+pAltura+", width="+pAncho+", left="+posleft+", top="+postop+" resizable=no, scrollbars=no");
	
}

function devuelveTamanoPantalla(pDimension){
	
	if (pDimension==1){ // ancho
	
		var iwidth=0;
	
		if (self.screen) {     // for NN4 and IE4
			iwidth = screen.width;

		}
		else{
			if (self.java) {   // for NN3 with enabled Java
				var jkit = java.awt.Toolkit.getDefaultToolkit();
				var scrsize = jkit.getScreenSize();
				iwidth = scrsize.width;
			}
		}
		return (iwidth);
	}
	else{
		
		var iheight=0;
		
		if (self.screen) {     // for NN4 and IE4
			iheight = screen.height
		}
		else{
			if (self.java) {   // for NN3 with enabled Java
				var jkit = java.awt.Toolkit.getDefaultToolkit();
				var scrsize = jkit.getScreenSize();
				iheight = scrsize.height; 
			}
		}
		return(iheight);
	}
	
}

function reiniciaFormulario(){
	
	document.tienda.reset();
	
}

function vaciarCesta(){
	
	document.tienda.accion.value="VaciarCarro";	
	document.tienda.submit();
	
}

function confirmaPago(pTipoPago){
	
	
	switch(pTipoPago){
		
		case 1:
			document.forms.tienda.accion.value="pagoTarjeta";
			break;
		case 3:
			document.forms.tienda.accion.value="pagoContraReembolso";
			break;
		default:
			return;
	}
	
	document.forms.tienda.submit();
	
}

function pulsarbusqueda(e) {
  	
	if(document.all){
		tecla=e.keyCode;
	}
	else{
		tecla=e.which;
	}
	if (tecla==13) buscaProducto();

}  

function pulsar(e) {

	if(document.all){
		tecla=e.keyCode;
	}
	else{
		tecla=e.which;
	}
	if (tecla==13) validaUsuarioCentro();

}


function pulsarcaja(e) {
	
	if(document.all){
		tecla=e.keyCode;
	}
	else{
		tecla=e.which;
	}
    if (tecla==13) validaUsuario();
    
}  

function pulsarrecordar(e){
	
	if(document.all){
		tecla=e.keyCode;
	}
	else{
		tecla=e.which;
	}
    if (tecla==13) validaRecordar();

}

function lanzaTPV() {
	
	vent=window.open('','tpv','width=740,height=650,scrollbars=yes,resizable=yes,status=yes,menubar=no,location=no');
	document.forms.compra.submit();
	
}

function seleccionaTipoPago(){
	
	document.forms.tienda.accion.value="tipoPago";
	document.forms.tienda.submit();
	
}

function finalizarProceso(){
	
	document.forms.tienda.accion.value="finalizarProceso";
	document.forms.tienda.submit();
	
}


function cambiaPrecio(pCaracteristicas,pPersonalizable){
	
	// Hay que comprobar todos los selects y recalcular
	
	if (pCaracteristicas!=""){
		
		aCaracteristicas=pCaracteristicas.split("|");
		iPrecio=document.forms.tienda.preciooriginal.value;
	
		for (var iContador=0;iContador<aCaracteristicas.length ;iContador++){
			
			strCaracteristica=aCaracteristicas[iContador];
			
			strValorSelect=eval("document.tienda."+strCaracteristica+"[document.forms.tienda."+strCaracteristica+".selectedIndex].value");
			if (strValorSelect!=0){

				iPosicionGuion=strValorSelect.indexOf("-");
		
				iPrecioSelect=strValorSelect.substr((iPosicionGuion+1));
		
				iPrecio=parseFloat(iPrecio)+parseFloat(iPrecioSelect);
			}
		}
	}
	
	// Personalizacion
	if (pPersonalizable){
		if (document.forms.tienda.dorsales.selectedIndex!=0){
			iPrecio=parseFloat(iPrecio)+parseFloat(document.forms.tienda.preciopersonalizacion.value);
		}
	}
	
	document.getElementById("preciototaletiqueta").innerHTML=iPrecio+" &euro;";
	
}

function seleccionaDorsal(obj){
  		
	texto=(obj.value).split("-");
  	if(texto[0]==0){
  		document.getElementById("textopersonal").readOnly=true;
		document.getElementById("textopersonaldorsal").readOnly=true;
		document.getElementById("textopersonal").style.backgroundColor="#dadada";
		document.getElementById("textopersonaldorsal").style.backgroundColor="#dadada";
		document.forms.tienda.textopersonaldorsal.value="";
  		document.forms.tienda.textopersonal.value="";
  	}
  	else{
  		if(texto[0]==999){
  			
  			document.getElementById("textopersonal").readOnly=false;
			document.getElementById("textopersonaldorsal").readOnly=false;
			document.getElementById("textopersonal").style.backgroundColor="#ffffff";
			document.getElementById("textopersonaldorsal").style.backgroundColor="#ffffff";
			document.forms.tienda.textopersonaldorsal.value="";
  			document.forms.tienda.textopersonal.value="";
  			
  		}
  		else{
  			document.forms.tienda.textopersonaldorsal.value=texto[0];
  			document.forms.tienda.textopersonal.value=texto[1];
 			document.getElementById("textopersonal").readOnly=true;
 			document.getElementById("textopersonaldorsal").readOnly=true;
 			document.getElementById("textopersonal").style.backgroundColor="#dadada";
			document.getElementById("textopersonaldorsal").style.backgroundColor="#dadada";
  		}
 		
	}
}