$(document).ready(function() {
	var com = document.getElementById("caja-comparte");
	document.getElementById("btn_comparte").onclick = function(){
	    if (com.style.visibility == "hidden") {
	        com.style.display = "block";
	        com.style.visibility = "visible";
	        document.getElementById("caja-ayuda").style.display = "none";
	    }
	    else {
	        com.style.visibility = "hidden";
	        document.getElementById("caja-comparte").style.display = "none";
	    }
	    
	    document.getElementById("btn_cerrar_comparte").onclick = function(){
	        document.getElementById("caja-comparte").style.visibility = "hidden";
	    };
	    cambiarTab("pestana2", "tab2");
	};
	
	var ayu = document.getElementById("caja-ayuda");
	document.getElementById("btn_ayuda").onclick = function(){
	    if (ayu.style.visibility == "hidden") {
	        ayu.style.display = "block";
	        ayu.style.visibility = "visible";
	        document.getElementById("caja-comparte").style.display ="none";
	    }
	    else {
	        ayu.style.visibility = "hidden";
	    }
	    
	    document.getElementById("btn_cerrar_ayuda").onclick = function(){
	        ayu.style.visibility = "hidden";
	    };
	};
});

function limpiarCasillas(casillas,estilo){
	for(i=0;i<casillas.length;i++){
		document.getElementById(casillas[i]).className=estilo;
	}
}

function validarMail(id){
	casilla=document.getElementById(id);
	var ok=1;
	var es_email=/^(.+\@.+\..+)$/;
	if(!es_email.test(casilla.value)) { ok=0; }
	
	return ok;
}

function validacionAlfabetica(id,min_digitos){
	var ok=1;
	var patron=/[^a-zA-Z \-αινσϊΑΙΝΣΪρΡ]/;
	casilla=document.getElementById(id);
	txt=casilla.value;
	
	if(min_digitos!=""){
		if(casilla.value.length<min_digitos) { ok=0; }
	}
	if(casilla.value.length<1) { ok=0; }
	if(patron.test(txt)) { ok=0; }
	return ok;
} 

function alertarErrores(error){
	casilla=document.getElementById(error[0][0]);
	casilla.focus();
	casilla.className="error";
	alert(error[0][1]);
} 

function enviarComparte(){
	var errores = new Array();
	limpiarCasillas(["para","nombre","email"],'');
	
	if(!validarMail("para")){ ok=0; errores.push(["para","Debes ingresar el e-mail del destinatario."]); }
	if(!validacionAlfabetica("nombre","3")){ ok=0; errores.push(["nombre","Debes ingresar tu nombre."]); }
	if(!validarMail("email")){ ok=0; errores.push(["email","Debes ingresar tu e-mail."]); }
	
	if(errores.length){
		alertarErrores(errores);
	}
	else{
		var str = "para="+document.getElementById('para').value+"&";
		str += "nombre="+document.getElementById('nombre').value+"&";
		str += "email="+document.getElementById('email').value;
		$('frm-comparte').fade(1,0);
		$('ajax-enviando').fade(0,1);
		makePOSTRequest('/envio_mail/envio_social.iws', str, 'ajax-enviando', 'ajax-sent', 'frm-comparte');
	}
}

function cambiarTab(pestana, tab){
	    
    var tabs = ["tab1", "tab2"];
    var pestanas = ["pestana1", "pestana2"];
    for (i = 0 ; i < tabs.length ; i++) {
        document.getElementById(tabs[i]).style.display = "none";
        document.getElementById(pestanas[i]).className = "";
    }
    document.getElementById(tab).style.display = "block";
    document.getElementById(pestana).className = "activa";
}