/*
SCRIPT PARA O ESTILO DO MENSAXE DE ALERTA
*/


/************************************

	Custom Alert Demonstration
	version 1.0
	last revision: 02.02.2005
	steve@slayeroffice.com

	Should you improve upon this source please
	let me know so that I can update the version
	hosted at slayeroffice.

	Please leave this notice in tact!

************************************/

var ALERT_TITLE = "Dato incorrecto";
var ALERT_BUTTON_TEXT = "Aceptar";

if(document.getElementById) {
	window.alert = function(txt) {
		createCustomAlert(txt);
	}
}

function createCustomAlert(txt) {
	d = document;

	if(d.getElementById("modalContainer")) return;

	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	mObj.style.height = d.documentElement.scrollHeight + "px";
	
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
	alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
	alertObj.style.visiblity="visible";

	h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode(ALERT_TITLE));

	msg = alertObj.appendChild(d.createElement("p"));
	msg.appendChild(d.createTextNode(txt));

	btn = alertObj.appendChild(d.createElement("a"));
	btn.id = "closeBtn";
	btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	btn.href = "javascript:close();";
	btn.onclick = function() { removeCustomAlert();return false; }

	
}

function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}



// Script para comprobar que los campos obligatorios se introducen.

function isEmpty(strfield1, strfield2, strfield3) {

//campo nombre
strfield1 = document.forms[0].nombre.value
//campo telefono
strfield2 = document.forms[0].telefono.value
//campo comentario
strfield3 = document.forms[0].comentario.value


  //campo referencia
    if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
    {
    alert("Deberá introducir su Nombre y Apellidos.");
    document.forms[0].nombre.focus();
    return false;
    }

  //campo nombre
    if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ')
    {
    alert("Deberá introducir su teléfono para que nos pongamos en contacto con usted.");
    document.forms[0].telefono.focus();
    return false;
    }
  //campo telefono  
    if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ')
    {
    alert("Deberá introducir el comentario.");
    document.forms[0].comentario.focus();
    return false;
    }
  
    return true;
}


//comprobacion de correo
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  strEmail = document.forms[0].email.value;

    if (strEmail.search(validRegExp) == -1) 
   {
      alert('Deberá introducir correctamente su       e-mail.');
      document.forms[0].email.focus();
      return false;
    } 
    return true; 
}


//comprobamos campos

function check(form){
  if (isEmpty(form.nombre)){
  	if (isEmpty(form.telefono)){
  		if (isEmpty(form.comentario)){
				if (isValidEmail(form.email)){
		 	 	return true;
	    		}
	    }
	}
  }
return false;
}
