function Amigo(){

	
}

Amigo.prototype.enviar = function($link, $tipo){


	var txt_tu_nombre = document.getElementById("txt_tu_nombre").value 
	var txt_amigo_nombre = document.getElementById("txt_amigo_nombre").value 
	var txt_tu_email = document.getElementById("txt_tu_email").value 
	var txt_amigo_email = document.getElementById("txt_amigo_email").value 
	
	while (txt_tu_nombre.charAt(0) == " "){
		txt_tu_nombre = txt_tu_nombre.substring(1, txt_tu_nombre.length); 
		document.getElementById("txt_tu_nombre").value = txt_tu_nombre.substring(1, txt_tu_nombre.length); 
    }
	while (txt_amigo_nombre.charAt(0) == " "){
		txt_amigo_nombre = txt_amigo_nombre.substring(1, txt_amigo_nombre.length); 
		document.getElementById("txt_amigo_nombre").value = txt_amigo_nombre.substring(1, txt_amigo_nombre.length); 
    }
	while (txt_tu_email.charAt(0) == " "){
		txt_tu_email = txt_tu_email.substring(1, txt_tu_email.length); 
		document.getElementById("txt_tu_email").value = txt_tu_email.substring(1, txt_tu_email.length); 
    }
	while (txt_amigo_email.charAt(0) == " "){
		txt_amigo_email = txt_amigo_email.substring(1, txt_amigo_email.length); 
		document.getElementById("txt_amigo_email").value = txt_amigo_email.substring(1, txt_amigo_email.length); 
    }
	
	
//error_tu_nombre
//error_amigo_nombre
//error_tu_email
//error_amigo_email
	


document.getElementById("error_tu_nombre").innerHTML = "&nbsp;"
document.getElementById("error_amigo_nombre").innerHTML = "&nbsp;"
document.getElementById("error_tu_email").innerHTML = "&nbsp;"
document.getElementById("error_amigo_email").innerHTML = "&nbsp;"


	var error = false;
	var txt_error = "";

	if(txt_tu_nombre==""){
		document.getElementById("error_tu_nombre").innerHTML = "Ingresa el nombre."
		//document.getElementById("error_tu_nombre").style.display = "block" 
		error = true;
	}
	
	if(txt_tu_email==""){
		document.getElementById("error_tu_email").innerHTML = "Ingresa el e-mail."
	//	document.getElementById("error_tu_email").style.display = "block"
		error = true;
	}
	
	if(!this.emailchek(txt_tu_email) && txt_tu_email!=""){
		document.getElementById("error_tu_email").innerHTML = "Ingresa un e-email correcto."
	//	document.getElementById("error_tu_email").style.display = "block"
		error=true;
	}
	//
	
	
	
	if(txt_amigo_nombre==""){
		document.getElementById("error_amigo_nombre").innerHTML = "Ingresa el nombre."
	//	document.getElementById("error_amigo_nombre").style.display = "block" 
		error = true;
	}
	
	if(txt_amigo_email==""){
		document.getElementById("error_amigo_email").innerHTML = "Ingresa el e-mail."
	//	document.getElementById("error_amigo_email").style.display = "block"
		error = true;
	}
	
	if(!this.emailchek(txt_amigo_email) && txt_amigo_email!=""){
		document.getElementById("error_amigo_email").innerHTML = "Ingresa un e-email correcto."
	//	document.getElementById("error_amigo_email").style.display = "block"
		error=true;
	}


	if(error){
		return
	}
	
	
	document.getElementById("btn_enviar_amigo").value = "Enviando..."
	document.getElementById("btn_enviar_amigo").disabled = true
	
var contenidoAmigo = document.getElementById("txt_contenido_amigo").innerHTML
	var txt_comentario = document.getElementById("txt_comentario").value

	petision("div.enviar_amigo.send.php", "div_envian_amigo", "POST", "tu_nombre="+txt_tu_nombre+"&amigo_nombre="+txt_amigo_nombre+"&tu_email="+txt_tu_email+"&amigo_email="+txt_amigo_email+"&tipo="+$tipo+"&contenido="+contenidoAmigo+"&comentario="+txt_comentario + "&link="+$link, "", "", 1);
	/////////////////////////////////////////////////////////////////////////////
	abrir_carga()


	
}


Amigo.prototype.emailchek = function(str){

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		 
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		
		    return false
		 }

 		 return true					
	}
