function getXMLHTTPRequest() {

try {
req = new XMLHttpRequest(); /* p.e. Firefox */
} catch(e) {
  try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
  /* algunas versiones IE */
  } catch (e) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    /* algunas versiones IE */
    } catch (E) {
      req = false;
    }
  }
}
return req;

}
var http = getXMLHTTPRequest();

//Correccion del PASO 1 del formulario 
function corrige(nombre, apellidos, empresa, email, telf){
	
	var mensaje="";

	if(nombre==""){
		mensaje=" - You must insert your Name.\n";
	}
	if(apellidos==""){
		mensaje+=" - You must insert your Surname.\n";
	}
	if(empresa=="" && nombre==""){
		mensaje+=" - You must insert your Company Name.\n";
	}
	if(!validarEmail(email)){
		mensaje+=" - The email address are not correct.\n";
	}
	if(telf<9){
		mensaje+=" - You must insert a Contact Phone.\n";
	}
	
	if(mensaje==""){
		var myurl = 'presupuesto_p2.php';
  
		myRand = parseInt(Math.random()*999999999999999);
		// saltarse la cache
	   
	   var modurl = myurl+"?rand="+myRand+"&nombre="+encodeURIComponent(nombre)+"&apellidos="+encodeURIComponent(apellidos)+"&empresa="+encodeURIComponent(empresa)+"&email="+email+"&telf="+telf;
	
	   http.open("GET", modurl, true);
	   http.onreadystatechange = useHttpResponse_Paso2;
	   http.send(null);
		}else{
			alert("The quote entered are wrong: \n"+ mensaje);
	}
}

function useHttpResponse_Paso2(){
   //Selecciona el div donde ira todo el contenido que se obtenga
   var area = document.getElementById("contenido");
   
   if (http.readyState == 4) {
	   if(http.status == 200) {
		
		//Mete en el div contenido, el contenido de la pagina consultada
	    area.innerHTML = http.responseText;
		
	   }
	}
  else
  {
	  area.innerHTML = '<img src="imagenes/cargando.gif" style="position:absolute;left:32%;top:40%;" />';
  }
}

function FinalizaPresup(nombre, apellidos, empresa, email, telf, servicio, extension, idioma1, idioma2, numpalab, tematica, plazo, comentarios){
	
		var errores="";
	
		if(servicio=='')
			errores=" - You must select a service. \n";
		
		if(idioma1=='')
			errores+=" - You must select a Source Language. \n";
		
		if(idioma1!='' && idioma2=='')
			errores+=" - You must select a Target Language. \n";
			
		if(tematica=='')
			errores+=" - You must indicate the Subject Matter. \n";
			
		if(plazo=='')
			errores+=" - You must indicate de Deadline. \n";
			
		if (errores=='')
		{
	
			var myurl = 'final_presup.php';
	  
			myRand = parseInt(Math.random()*999999999999999);
			// saltarse la cache
		   
		   var modurl = myurl+"?rand="+myRand+"&nombre="+encodeURIComponent(nombre)+"&apellidos="+encodeURIComponent(apellidos)+"&empresa="+encodeURIComponent(empresa)+"&email="+email+"&telf="+telf+"&servicio="+encodeURIComponent(servicio)+"&extension="+extension+"&idioma1="+encodeURIComponent(idioma1)+"&idioma2="+encodeURIComponent(idioma2)+"&numpalab="+numpalab+"&tematica="+encodeURIComponent(tematica)+"&plazo="+plazo+"&comentarios="+encodeURIComponent(comentarios);
		
		   http.open("GET", modurl, true);
		   http.onreadystatechange = useHttpResponse_EndPresup;
		   http.send(null);
		}
		else
		{
			alert("The quote entered are wrong: \n"+ errores);	
		}
}

function useHttpResponse_EndPresup(){
   //Selecciona el div donde ira todo el contenido que se obtenga
   var area = document.getElementById("contenido");
   
   if (http.readyState == 4) {
	   if(http.status == 200) {
		
		//Mete en el div contenido, el contenido de la pagina consultada
	    area.innerHTML = http.responseText;
		
	   }
	}
  else
  {
	  area.innerHTML = '<img src="imagenes/cargando.gif" style="position:absolute;left:32%;top:40%;" />';
  }
}


// Corrección del Correo 
function validarEmail(email) {

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		return true;
	} else {
		return false;
	}
	//return true;
}


/* Permite la entrada de numeros */
/*function solo_numeros(){
	var key=window.event.keyCode;
	if (key < 48 || key > 57){
		window.event.keyCode=0;
	}
}*/

/* Permite un texto máximo hasta 300 carácteres */
function longitud_maxima_300(){
	if (form1.comentario.value.length > 300){ 
		alert('Ha superat el tamany màxim permes');
		form1.comentario.value=form1.comentario.value.substring(0,300);
	}
}
