<!--
  var formatoFecha = 'dd/mm/yyyy';	// Formato de fecha que vamos a utilizar
  
  // Función de validación de email
  function emailValido(valor) {
	 if(valor == "") return true;
	var EmailOk = true;
	var AtSym = valor.indexOf('@');
	var Period = valor.lastIndexOf('.');
	var Space = valor.indexOf(' ');
	var Length = valor.length - 1;
	if ((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space  != -1)) {  
		  EmailOk = false;
	}
	return EmailOk;
  }
  
  // Función de validación de fecha
  function fechaValida(valor) {
  	var formatoFechaReg = formatoFecha;
  	formatoFechaReg = formatoFechaReg.replace('dd','([0-2][0-9]|3[0-1])');
  	formatoFechaReg = formatoFechaReg.replace('mm','(0[0-9]|1[0-2])');
  	formatoFechaReg = formatoFechaReg.replace(/y/g,'[0-9]');
  	formatoFechaReg = "^" + formatoFechaReg + "$";
  	var ExpReg = new RegExp(formatoFechaReg);
  	var fechaOK = ExpReg.test(valor);
  	return fechaOK;
  }
  
  // Función de validación de fotos
  function fotoValida(valor) {
	var formatoFoto = "^(.*)(\\\\|/)[\\w:/_-]+\\.(jpeg|jpg|gif)$";
  	var ExpRegFoto = new RegExp(formatoFoto,"i");
  	var fotoOK = ExpRegFoto.test(valor);
  	return fotoOK;
  }
  
  // Función de validación de fotos
  function precioValido(valor) {
	var formatoPrecio = "^[0-9]+(,[0-9]{1,2})?$";
  	var ExpRegPrecio = new RegExp(formatoPrecio,"i");
  	var precioOK = ExpRegPrecio.test(valor);
  	return precioOK;
  }
  
  function checkForm(frm) {
    for(i=0;i<frm.length;i++) {
    	campoForm = frm.elements[i];
		if(campoForm.disabled == false) {
			var datosCheck = campoForm.id.split('#');
			texto_explicativo = "";
			if(datosCheck[2])
				texto_explicativo = datosCheck[2];
			if(datosCheck[0].indexOf('*') != -1) {
				if(campoForm.value == "") {
					if (document.location.href.match("surinenglish")){
						switch(datosCheck[1])
						{
							case "Nick":
								english="Screen name";
							break;
							case "Sexo":
								english="Sex";
							break;
							case "Edad":
								english="Age";
							break;
							case "Email":
								english="E-mail";
							break;
							default:
								english="Postcode";
							break;
						}
 	 					alert('field ' + english + ' incomplete');
					}else {
						alert('No has rellenado el campo ' + datosCheck[1]);
					}
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('numero') != -1) {
				if(isNaN(campoForm.value)) {
					if (document.location.href.match("surinenglish")){
					switch(datosCheck[1])
						{
							case "Edad":
								english="Age";
							break;
							default:
								english="Postcode";
							break;
						}
 	 					alert('The field ' + english + ' must be a number');
					}else {
						alert('El campo ' + datosCheck[1] + ' tiene que ser numérico.' + texto_explicativo);
					}
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('email') != -1) {
				if(!emailValido(campoForm.value)) {
					alert('El campo ' + datosCheck[1] + ' tiene que ser un email');
					campoForm.focus();
					return false;
				}
			}
			if((datosCheck[0].indexOf('fecha') != -1) && (campoForm.value != "")) {
				if(!fechaValida(campoForm.value)) {
					alert('El formato del campo ' + datosCheck[1] + ' no es válido');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('checkbox') != -1) {
				if(campoForm.checked == false) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
			}
			if(datosCheck[0].indexOf('radio') != -1) {
				var radioCheck = 0;
				eval('var radioElemento = frm.' + campoForm.name);
				for(j=0;j<radioElemento.length;j++) {
					if(radioElemento[j].checked) {
						radioCheck = 1;
						break;
					}
				}
				if(radioCheck == 0) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
			}
			if(datosCheck[0].indexOf('select') != -1) {
				if(campoForm.selectedIndex == 0) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
			}
			if(datosCheck[0].indexOf('selectMultiple') != -1) {
				seleccion = 0
				for(j=1;j<campoForm.length;j++) {
					if(campoForm.options[j].selected == true)
						seleccion = 1
				}
				if(seleccion == 0) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
			}
			var expReg = /[^A-Za-z0-9ñÑáéíóúÁÉÍÓÚüÜ_\s\¿\?\¡\!\<\>\.\,\:\;\(\)\@\#\$\€\%\&\\\/\*\=\+\-\{\}\[\]\ç\º\ª]/i;
			if(datosCheck[0].indexOf('parsear') != -1) {
				if(expReg.test(campoForm.value)) {
					alert('El campo ' + datosCheck[1] + ' no es válido\n');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('min') != -1) {
				posicion = datosCheck[0].indexOf('min') + 3;
				limite = "0";
				while((!isNaN(datosCheck[0].substring(posicion,posicion + 1))) && (posicion < datosCheck[0].length)) {
					limite = limite + datosCheck[0].substring(posicion,posicion + 1);
					posicion = posicion + 1;
				}
				limite = parseInt(limite,10);
				if(campoForm.value.length < limite) {
					alert('El campo ' + datosCheck[1] + ' tiene que tener al menos ' + limite + ' caracteres\n');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('max') != -1) {
				posicion = datosCheck[0].indexOf('max') + 3;
				limite = "0";
				while((!isNaN(datosCheck[0].substring(posicion,posicion + 1))) && (posicion < datosCheck[0].length)) {
					limite = limite + datosCheck[0].substring(posicion,posicion + 1);
					posicion = posicion + 1;
				}
				limite = parseInt(limite,10);
				if(campoForm.value.length > limite) {
					alert('El campo ' + datosCheck[1] + ' tiene que como máximo ' + limite + ' caracteres\n');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('foto') != -1) {
				if((campoForm.value != "") && !fotoValida(campoForm.value)) {
					alert('El formato de la foto no es correcta. Verifique que es un JPEG o un GIF o que el nombre no tiene espacios, acentos o caracteres extraños.');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('acepto') != -1) {
				if(campoForm.checked == false) {
					alert('Tienes que aceptar las condiciones');
					return false;
				}
			}
			if(datosCheck[0].indexOf('precio') != -1) {
				if((campoForm.value != "") && !precioValido(campoForm.value)) {
					alert('El formato del precio no es correcto. El formato correcto es 1000,11.');
					campoForm.focus();
					return false;
				}
			}
		}
    }
    return true;
  }
  
  function createRequestObject() {
		var ro;
		var browser = navigator.appName;

		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}  
	
function getParametros(formu) {
		var parametros = "";
		for(var i=0;i<formu.length;i++) {
			if(formu.elements[i].type == "button" || formu.elements[i].type == "reset" || formu.elements[i].type == "submit") continue;
			
			if(parametros != "") {
				if (formu.elements[i].type == "radio" || formu.elements[i].type == "checkbox") {
					if (formu.elements[i].checked) {
						parametros += "&" + formu.elements[i].name + "=" + formu.elements[i].value;	
					}
				}
				else {
					parametros += "&" + formu.elements[i].name + "=" + encodeURIComponent(formu.elements[i].value);
				}
			}
			else {
				if (formu.elements[i].type == "radio" || formu.elements[i].type == "checkbox") {
					if (formu.elements[i].checked) {
						parametros += formu.elements[i].name + "=" + formu.elements[i].value;	
					}
				}
				else {
					parametros += formu.elements[i].name + "=" + encodeURIComponent(formu.elements[i].value);
				}
			}
		}	
		return parametros;
	}

  
  function enviarPregunta() { 
		var frm = document.frmPregunta;	
		if(checkForm(frm)) {
			var httpPost = createRequestObject();
			httpPost.open("post", "/consultorios/preguntar.php", true);
			httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			httpPost.onreadystatechange = function () {
				if(httpPost.readyState == 4){
					if (httpPost.responseText) {
						actualizaFormuPregunta(httpPost.responseText);
					}
				}
			}
			httpPost.send(getParametros(frm));
		}
	}
	function actualizaFormuPregunta(response) {
		if(response){
			window.document.getElementById("divformuenvio").innerHTML = response;
			window.document.getElementById("presentaformulario").style.display = 'none';
		}	
	}
	
	function oculta_mensaje() {
		window.document.getElementById("divformuenvio").innerHTML ="";
		window.document.frmPregunta.reset();
		window.document.getElementById("presentaformulario").style.display = 'block';
	}
//-->
