var bigPic=new Array();

function pageAlt() {
}

function verificarUnidadesPedido(i,valorAntiguo) {
	if (esValido(i,valorAntiguo)) document.forms["form"+i].submit();
}

function esValido(indice,valorAntiguo) {
	var campoModificado=document.forms["form"+indice].elements["cantidad"];
	var ubicacion; //Es el indice que nos indica donde está el carácter no válido.
	var enter = "\n";
	var caracteres = "1234567890";
	var contador = 0;
	for (var i=0; i < campoModificado.value.length; i++) {
	    ubicacion = campoModificado.value.substring(i, i + 1);
		if (caracteres.indexOf(ubicacion) != -1) contador++;
		else {
			alert("ERROR: Char '" + ubicacion + "' is not permited.\nNumbers only.");	  
			campoModificado.value=valorAntiguo;	  
			return false;
		}
	}
	return true;
}

function ValidarCamposRegistro() {
	var i=0;
	var camposVacios = false;
	while(i<12) {
		if (document.datos.elements[i].value=="") {
			document.datos.elements[i].style.border = "1px solid #FF0000";
			camposVacios = true;
		}
		else {
			document.datos.elements[i].style.border = "1px solid #000000";
		}
		i++
	}
	if (camposVacios==true) {
		alert("Todos los campos son obligatorios");
		return false;
	}
	
	if (document.datos.elements["password"].value!=document.datos.elements["password2"].value) {
		alert ("El password y la confirmación tienen que ser igual");
		return false;
	}
	
	if (!correoValido(document.datos.elements["email"].value)) {
		document.datos.element["email"].select;
		return false;
	}
	
	document.datos.submit();
}

function ValidarCamposPedido(numCampos) {
	var i=0;
	var camposVacios = false;
	while(i<numCampos) {
		if (document.datos.elements[i].value=="") {
			document.datos.elements[i].style.border = "1px solid #FF0000";
			camposVacios = true;
		}
		else {
			document.datos.elements[i].style.border = "1px solid #000000";
		}
		i++
	}
	if (camposVacios==true) {
		alert("Todos los campos son obligatorios");
		return false;
	}

	document.datos.submit();
}

function correoValido(email) {
	var valido1=true;
	var valido2=true;
	if(email.indexOf ('@') == -1) {
		alert("Introduzca una dirección de correo electrónico correcta.\n\nFalta \"@\"");
		valido1=false;
	} else if (email.indexOf ('.') == -1) { 
		alert("Introduzca una dirección de correo electrónico correcta.\n\nFalta \".\"");
		valido2=false;
	}
	var condicion=valido1&&valido2;
	return condicion;
}

function borrarCarrito() {
	document.carrito.action = "borrar_carrito.php";
	document.carrito.submit();
}

function actualizarCarrito() {
	document.carrito.action = "actualizar_carrito.php";
	document.carrito.submit();
}

function alertaActualizar () {
	var n = document.getElementById('bupdate');
//	n.src = "img/actualizaro.jpg";
	n.className = 'botonAlert';
//	n.style.backgroundColor = '#0000FF';
//	n.style.color = '#FFFFFF';
}

function alertaBorrar () {
	var n = document.getElementById('bdelete');
//	n.src = "img/borraro.jpg";
	n.className = 'botonAlert';
//	n.style.backgroundColor = '#0000FF';
//	n.style.color = '#FFFFFF';
}

function cantidad_minima (c) {
	if (c.value < 2) {
		alert("La cantidad minima es 2");
		c.value = '2';
	}
}

function ampliar(pos,first,ref) {
	if (!bigPic[pos]) bigPic[pos]=first;
	var newImg = new Image();
	newImg.src = bigPic[pos];
	var iHeight = newImg.height+40;
	var iWidth = newImg.width+40;
	var x=(screen.width-iWidth)/2;
	var y=(screen.height-iHeight-100);
	vent=window.open('fotoGrande.php?src='+bigPic[pos]+'&ref='+ref,'vent','scrollbars=auto,resizable=1,width='+iWidth+',height='+iHeight+',status=1,top=10,left=5');
	setTimeout("vent.focus()",100);
}
function ajustar_imagenes () {
	for (var i=0; i<document.images.length; i++) {
		if (document.images[i].width > 156) {
			document.images[i].height = (document.images[i].height * 156) / document.images[i].width;
			document.images[i].width = "156";
		}
	}
}

