
function embedFlash(ubicacion,pelicula,ancho,alto,desc){
     document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ancho+'" height="'+alto+'" title="'+desc+'">');
      document.write('<param name="movie" value="'+ubicacion+pelicula+'.swf" />');
      document.write('<param name="quality" value="high" />');
      document.write('<param name="wmode" value="transparent" />');
      document.write('<embed src="'+ubicacion+pelicula+'.swf" width="'+ancho+'" height="'+alto+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>');
     document.write('</object>');
}

function comprueba_formulario() {
	
	if (document.forms['presupuesto'].elements['nombre'].value == "") {
		alert ("\n Por favor rellene el campo nombre.");
		document.forms['contacto'].elements['email'].focus();
		return false;
	}
	
	return true;
	
}


function Validar() {
	if (document.forms['contacto'].elements['email'].value == "") {
		alert ("\n Por favor introduzca una cuenta de correo.")
		document.forms['contacto'].elements['email'].focus();
		return false;
	}
	if (document.forms['contacto'].elements['email'].value.indexOf ('@',0) == -1 ||
	document.forms['contacto'].elements['email'].value.indexOf ('.',0) == -1) {
		alert ("\n Debe utilizar una cuenta de correo valida.")
		document.forms['contacto'].elements['email'].select();
		document.forms['contacto'].elements['email'].focus();
		return false;
	}
	return true;
}




function abrir( web, alto, ancho ) {
	if ( window.pantmsg ) { pantmsg.close(); }
	pantmsg = open(web, 'pantmsg',"top=" + (screen.height - alto) / 2 + ",left=" + (screen.width - ancho) / 2 + ",toolbar=no,width=" + ancho + ",height=" + alto + ",directories=no,status=no,scrollbars=auto,resize=no,menubar=no");
	pantmsg.focus();
}


var form = "";
var submitted = false;
var error = false;
var error_message = "";

function check_input(field_name, field_size, message) {
	if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
		var field_value = form.elements[field_name].value;

		if (field_value == '' || field_value.length < field_size) {
			error_message = error_message + "* " + message + "\n";
			error = true;
		}
	}
}

function check_radio(field_name, message) {
	var isChecked = false;

	if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
		var radio = form.elements[field_name];

		for (var i=0; i<radio.length; i++) {
			if (radio[i].checked == true) {
				isChecked = true;
				break;
			}
		}

		if (isChecked == false) {
			error_message = error_message + "* " + message + "\n";
			error = true;
		}
	}
}

function check_select(field_name, field_default, message) {
	if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
		var field_value = form.elements[field_name].value;

		if (field_value == field_default) {
			error_message = error_message + "* " + message + "\n";
			error = true;
		}
	}
}

function check_password(field_name_1, field_name_2, field_size, message_1, message_2) {
	if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
		var password = form.elements[field_name_1].value;
		var confirmation = form.elements[field_name_2].value;

		if (password == '' || password.length < field_size) {
			error_message = error_message + "* " + message_1 + "\n";
			error = true;
		} else if (password != confirmation) {
			error_message = error_message + "* " + message_2 + "\n";
			error = true;
		}
	}
}

function check_password_new(field_name_1, field_name_2, field_name_3, field_size, message_1, message_2, message_3) {
	if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
		var password_current = form.elements[field_name_1].value;
		var password_new = form.elements[field_name_2].value;
		var password_confirmation = form.elements[field_name_3].value;

		if (password_current == '' || password_current.length < field_size) {
			error_message = error_message + "* " + message_1 + "\n";
			error = true;
		} else if (password_new == '' || password_new.length < field_size) {
			error_message = error_message + "* " + message_2 + "\n";
			error = true;
		} else if (password_new != password_confirmation) {
			error_message = error_message + "* " + message_3 + "\n";
			error = true;
		}
	}
}

function check_form(form_name) {
	if (submitted == true) {
		alert("Ya ha enviado el formulario. Pulse Aceptar y espere a que termine el proceso.");
		return false;
	}

	error = false;
	form = form_name;
	error_message = "Hay errores en su formulario!\nPor favor, haga las siguientes correciones:\n\n";

	check_input("Nombre", 2, "Su Nombre debe tener al menos 2 letras.");
	check_input("Apellidos", 5, "Sus Apellidos deben tener al menos 5 letras.");
	check_input("DNI", 5, "Su DNI debe tener al menos 5 letras.");

	check_input("Email", 6, "Su direccion de E-Mail debe tener al menos 6 letras.");
	check_input("Direccion", 5, "Su direccion debe tener al menos 5 letras.");
	check_input("CP", 4, "Su codigo postal debe tener al menos 4 letras.");
	check_input("Ciudad", 3, "Su poblacion debe tener al menos 3 letras.");

	check_input("Provincia", 2, "Su provincia debe tener al menos 2 letras.");

	check_select("Pais", "", "Debe seleccionar un pais de la lista desplegable.");

	check_input("Telefono", 9, "Su numero de telefono debe tener al menos 9 letras.");

	check_password("password", "confirmation", 5, "Su contraseña debe tener al menos 5 letras.", "La confirmación de la contraseña debe ser igual a la contraseña.");
	check_password_new("password_current", "password_new", "password_confirmation", 5, "Su contraseña debe tener al menos 5 letras.", "Su contraseña nueva debe tener al menos 5 letras.", "La confirmacion de su contraseña debe coincidir con su contraseña nueva.");

	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}

}



