function ajaxRequest() {
  var ajaxObject=false;
  try { ajaxObject = new ActiveXObject("Msxml2.XMLHTTP"); } 
  catch (e) {
    try { ajaxObject = new ActiveXObject("Microsoft.XMLHTTP"); } 
    catch (E) { ajaxObject = false; }
  }

  if (!ajaxObject && typeof XMLHttpRequest!='undefined') {
    ajaxObject = new XMLHttpRequest();
  }
  
  return ajaxObject;
}

function contact( fichero, envia, aImgAjax, refe) 
{
	if (envia == 1)//Comprobamos campos obligatorios
	{
		//valido el nombre
	    if (document.contacto.apellidos.value.length==0){
	       alert("Tiene que escribir su nombre")
	       document.contacto.nombre.focus()
	       return 0;
		}
		

	    //valido el mail
		if ((document.contacto.mail.value.indexOf ('@', 0) == -1)||(document.contacto.mail.value.length < 5)) {
			alert("Escriba una dirección de correo válida en el campo email")
		    document.contacto.mail.focus()
			return 0;
		}
		//valido el Textearea
	    if (document.contacto.texto.value.length==0){
	       alert("El Campo Texto no puede estar vacio")
	       document.contacto.texto.focus()
	       return 0;
		}
		var apellidos =document.contacto.apellidos.value;
		var direccion =document.contacto.direccion.value;
		var codigopostal =document.contacto.codigopostal.value;
		var poblacion =document.contacto.poblacion.value;
		var provincia =document.contacto.provincia.value;
		var telefono =document.contacto.telefono.value;
		var mail =document.contacto.mail.value;
		var texto =document.contacto.texto.value;
		var fdesde =document.contacto.fdesde.value;
		var fhasta =document.contacto.fhasta.value;


	}
	document.getElementById('formcontact').innerHTML = '<center><img src="' + aImgAjax + '"></center>';
	ajax = ajaxRequest();
	ajax.open("GET", fichero +'?apellidos=' + apellidos + '&refe=' + refe + '&direccion=' + direccion + '&codigopostal=' + codigopostal + '&poblacion=' + poblacion + '&provincia=' + provincia + '&telefono=' + telefono + '&mail=' + mail + '&fdesde=' + fdesde + '&fhasta=' + fhasta + '&texto=' + texto + '&envia=' + envia, true);
	ajax.onreadystatechange = function() 
	{
		if ( ajax.readyState == 4 ) 
		{
			document.getElementById('formcontact').innerHTML = ajax.responseText;
		}
	}
		ajax.send(null);
}

function actuafoto( fichero, aImgAjax, foto)
{
	document.getElementById('foto').innerHTML = '<center><img src="' + aImgAjax + '"></center>';
	ajax2 = ajaxRequest();
	ajax2.open("GET", fichero +'?foto= '+ foto, true);
	ajax2.onreadystatechange = function() 
	{
		if ( ajax2.readyState == 4 ) 
		{
			document.getElementById('foto').innerHTML = ajax2.responseText;
		}
	}
		ajax2.send(null);
}

