function check_login(form) {
	if (isBlank(form.user, "Por favor, introduce tu usuario")) { return false; }
	if (isBlank(form.pass, "Por favor, introduce tu contraseña")) { return false; }
	
	return true;
}

function check_cart_add(form) {
	if (isBlank(form.quantity, "Por favor entra un cantidad")) { return false; }
	if (isNaN(form.quantity.value)) {
		alert("La cantidad no es válido");
		form.quantity.select();
		form.quantity.focus();
		return false;	
	}	
	
	return true;
}

function check_envio(form) {	
	if (isBlank(form.remitente, "Por favor entra el remitente")) { return false; }
	if (isBlank(form.ship_address, "Por favor entra el dirección")) { return false; }
	if (isBlank(form.ship_city, "Por favor entra el población")) { return false; }
	if (isBlank(form.ship_country, "Por favor entra el país")) { return false; }
	if (isBlank(form.ship_postal_code, "Por favor entra el codigo postal")) { return false; }
	
	return true;
}

function check_pass_change(form) {
	if (isBlank(form.old_pass, "Introduce tu contraseña actual")) { return false; }
	if (isBlank(form.new_pass, "Introduce una nueva contraseña")) { return false; }
	if (isBlank(form.new_verify, "Verifica la nueva contraseña")) { return false; }
	
	if (form.new_pass.value.length < 6) {
		alert("La nueva contraseña debe tener al menos 6 cifras");
		form.new_pass.focus();
		form.new_pass.select();
		return false;
	}
	
	if (form.new_pass.value != form.new_verify.value) {
		alert("La contraseña y el de verificación no son iguales");
		form.new_verify.focus();
		form.new_verify.select();
		return false;
	}
	
	return true;
}

function check_pass_reset(form) {
	if (isBlank(form.user, "Por favor, introduce tu usuario")) { return false; }
	
	return true;
}

function check_soporte(form) {
	if (isValue(form.ckb_id, "-1", "Por favor, eliga la categoría de soporte")) { return false; }
	if (isBlank(form.tema, "Introduce el tema de soporte")) { return false; }
	if (isBlank(form.contenido, "Introduce el descripción del soporte")) { return false; }
	
	return true;
}

function check_user(form) {
	if (isBlank(form.phone, "Introduce el numero de teléfono")) { return false; }
	if (isBlank(form.contact_address, "Introduce el dirección de contacto")) { return false; }
	if (isBlank(form.contact_postal_code, "Introduce el codigo postal de contacto")) { return false; }
	if (isBlank(form.contact_city, "Introduce el población de contacto")) { return false; }
	
	if (isBlank(form.ship_address, "Introduce el dirección de envío")) { return false; }
	if (isBlank(form.ship_postal_code, "Introduce el codigo postal de envío")) { return false; }
	if (isBlank(form.ship_city, "Introduce el población de envío")) { return false; }
	
	return true;
}


function format_uri(textarea,replaceWith) { 
	textarea.value = encodeURI(textarea.value);
	
	for(i=0; i<textarea.value.length; i++){ 
		if(textarea.value.indexOf("%0D%0A") > -1){ 
		//Windows encodes returns as \r\n hex
			textarea.value=textarea.value.replace("%0D%0A",replaceWith);
		}
		else if(textarea.value.indexOf("%0A") > -1){ 
		//Unix encodes returns as \n hex
			textarea.value=textarea.value.replace("%0A",replaceWith);
		}
		else if(textarea.value.indexOf("%0D") > -1){ 
		//Macintosh encodes returns as \r hex
			textarea.value=textarea.value.replace("%0D",replaceWith);
		}
	
	}

	textarea.value=unescape(textarea.value);
	
	return true;
}

function isBlank(obj, message) {
	if (obj.value == "") {
		alert(message);
		obj.focus();
		return true;
	}
	
	return false;
}

function isBlankNoFocus(obj, message) {
	if (obj.value == "") {
		alert(message);
		return true;
	}
	
	return false;
}

function isValue(obj, value, message) {
	if (obj.value == value) {
		alert(message);
		obj.focus();
		return true;
	}
	
	return false;
}

function isValidAddress(addr) {
	index1 = addr.indexOf("@");
	if (index1 <= 0) {
		return false;
	}
	index2 = addr.indexOf(".", index1);
	if (index2 < index1) {
		return false;
	}
	
	//must be at least a period and 2 characters at the end
	if (index2 == addr.length-1 || index2 == addr.length-2) {
		return false;
	}
	return true;
}
