//Validación formularios y AJAX//
//-------------------------------//
//Validación contacto//
//-------------------------------//

function valida_contacto(){
	if( vacio(Contacto.nom.value) == false ) {     //tindria que comprobar tmb que l'usuari no stigui ja registrat
		alert("Introdueix una cadena de text en el nom")  
		return false 
	}	
	if (validar_mail2(Contacto.mail.value)==false){
		return false
	}
	if (vacio(Contacto.missatge.value)==false) {
		alert ("Ha d'escriure un missatge per poder enviar l'e-mail")
		return false
	}
	else{
		alert("El formulari s'ha omplert correctament")
	}
}

function validar_mail2(q){
	var posicioa=q.indexOf("@")
	var ultimpunt=q.lastIndexOf(".")
	if (posicioa<1 || ultimpunt-posicioa<2 || q.length==0){ //aqui faltaria mirar que la primera posició i la ultima siguin lletres
		alert ("El e-mail no és vàlid, introdueix un e-mail vàlid")
		return false
	}else{
		return true
	}
}

function vacio(q) {  
	var x=1
	for ( i = 0; i < q.length; i++ ) {  
		if ( q.charAt(i) != " " ) {  
			x=0;
			}  
		}  
	if (x== 0){
		return true
	}
	else{
		return false
	}
} 

//-------------------------------//
//Funciones Ajax//
//-------------------------------//
function loadXMLDoc(id)
{
	var url;
	if (id=="1")
	{ 
		this.url="ElGrup.html";
	}
	if (id=="2")
	{ 
		this.url="Properes_actuacions.php";
	}
	if (id=="3")
	{ 
		this.url="discografia.html";
	}
	if (id=="4")
	{ 
		this.url="LHavanera.html";
	}
	if (id=="5")
	{ 
		this.url="Contacto.html";
	}
	if (id=="8")
	{ 
		this.url="premsa.html";
	}
	if (id=="9")
	{ 
		this.url="Galeria.html";
	}
	
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
 	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("Info2").innerHTML=xmlhttp.responseText;
		}
	}

	xmlhttp.open("GET",this.url,true);

	xmlhttp.send();
}

function loadXMLDoc2(id)
{
	var url;
	if (id=="0")
	{ 
		this.url="SubirEntrada.html";
	}
	if (id=="1")
	{ 
		this.url="eliminarEntrada.php";
	}
	if (id=="2")
	{ 
		this.url="SubirActuacion.html";
	}
	if (id=="3")
	{ 
		this.url="EliminarActuacion.php";
	}
	
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
 	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("Info2").innerHTML=xmlhttp.responseText;
		}
	}

	xmlhttp.open("GET",this.url,true);

	xmlhttp.send();
}
