var links = new Array("todos");

function montaCompartilhe(div, nome)
{
	var endereco	= escape(location.href);
	var titulo		= escape(document.title);
	var pasta_img	= "/stock_car/goodyear_90_anos/img_compartilhe";
		
	if(links[0] == "todos")
	{
		links = new Array("email", "twitter", "delicious", "facebook", "digg", "reddit", "linkk", "websapiens", "dihitt", "linkto", "ueba", "linkloko", "blogosfera", "eucurti", "brasilsource", "domelhor", "ouvidizer", "jasabia", "inchicks", "google", "technorati", "blogmarks", "spurl", "delirious", "live", "linkagogo", "yahoo", "scuttle")
	}
	
	var compartilhe = "<ul>";
	for (i = 0; i <= links.length; i++)
	{
		l = links[i];
		if(l == "email"){
			compartilhe+= 	"<li><a href='javascript:' onclick='MontaEmail(document.getElementById(\"" + div.id + "\"), " + nome + ");' /><img src='"+ pasta_img +"/email.gif'>" + ((!nome) ? "" : " Enviar Email") + "</a></li>";
		}		
		if(l == "twitter"){
			compartilhe+= 	"<li><a target='_blank' href='http://twitthis.com/twit?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/twitter.gif'>" + ((!nome) ? "" : " TwitThis") + "</a></li>";
		}
		if(l == "delicious"){
			compartilhe+= 	"<li><a target='_blank' href='http://del.icio.us/save?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/delicious.gif'>" + ((!nome) ? "" : " Delicious") + "</a></li>";
		}
		if(l == "facebook"){
			compartilhe+=	"<li><a target='_blank' href='http://www.facebook.com/share.php?u=" + endereco +"' ><img src='"+ pasta_img +"/facebook.gif'>" + ((!nome) ? "" : " Facebook") + "</a></li>"
		}
		if(l == "digg"){
			compartilhe+= 	"<li><a target='_blank' href='http://digg.com/submit?phase=2&url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/digg.gif'>" + ((!nome) ? "" : " Digg") + "</a></li>";
		}		
		if(l == "reddit"){
			compartilhe+= 	"<li><a target='_blank' href='http://reddit.com/submit?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/reddit.gif'>" + ((!nome) ? "" : " Reddit") + "</a></li>";
		}
		if(l == "linkk"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.linkk.com.br/submit.php?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/linkk.gif'>" + ((!nome) ? "" : " Linkk") + "</a></li>";
		}
		if(l == "websapiens"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.websapiens.net/submit.php?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/websapiens.gif'>" + ((!nome) ? "" : " Websapiens") + "</a></li>";
		}
		if(l == "dihitt"){
			compartilhe+= 	"<li><a target='_blank' href='http://dihitt.com.br/submit.php?url=" + endereco + "?&title=" + titulo + "' /><img src='"+ pasta_img +"/dihitt.gif'>" + ((!nome) ? "" : " Dihitt") + "</a></li>";
		}
		if(l == "linkto"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.linkto.com.br/site.enviaNoticia.php?title=" + titulo + "&url=" + endereco + "' /><img src='"+ pasta_img +"/linkto.gif'>" + ((!nome) ? "" : " LinkTo") + "</a></li>";
		}
		if(l == "ueba"){
			compartilhe+= 	"<li><a target='_blank' href='http://ueba.com.br/NovoLink?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/ueba.gif'>" + ((!nome) ? "" : " Ueba") + "</a></li>";
		}
		if(l == "linkloko"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.linkloko.com.br/submit.php?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/linkloko.gif'>" + ((!nome) ? "" : " Linkloko") + "</a></li>";
		}
		if(l == "blogosfera"){
			compartilhe+= 	"<li><a target='_blank' href='http://blogosfera.portaldasnoticias.com/submit.php?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/blogosfera.gif'>" + ((!nome) ? "" : " Blogosfera") + "</a></li>";
		}
		if(l == "eucurti"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.eucurti.com.br/submit.php?&url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/digg.gif'>" + ((!nome) ? "" : " Digg") + "</a></li>";
		}
		if(l == "brasilsource"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.brasilsource.net/submit.php?&url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/brasilsource.gif'>" + ((!nome) ? "" : " Brasil Source") + "</a></li>";
		}
		if(l == "domelhor"){		
			compartilhe+= 	"<li><a target='_blank' href='http://www.domelhor.net/submit.php?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/domelhor.gif'>" + ((!nome) ? "" : " Domelhor") + "</a></li>";
		}
		if(l == "ouvidizer"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.ouvidizer.com/submit.php?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/ouvidizer.gif'>" + ((!nome) ? "" : " Ouvidizer") + "</a></li>";
		}
		if(l == "jasabia"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.jasabia.com.br/submit.php?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/jasabia.gif'>" + ((!nome) ? "" : " Jasabia") + "</a></li>";	
		}
		if(l == "inchicks"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.inchicks.com/story_submit.php?u=" + endereco + "&t=" + titulo + "' /><img src='"+ pasta_img +"/inchicks.gif'>" + ((!nome) ? "" : " Inchicks") + "</a></li>";
		}
		if(l == "google"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.google.com/bookmarks/mark?op=add&bkmk=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/google.gif'>" + ((!nome) ? "" : " Google") + "</a></li>";
		}
		if(l == "technorati"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.technorati.com/cosmos/search.html?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/technorati.gif'>" + ((!nome) ? "" : " Technorati") + "</a></li>";
		}
		if(l == "blogmarks"){
			compartilhe+= 	"<li><a target='_blank' href='http://blogmarks.net/my/new.php?mini=1&simple=1&url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/blogmarks.gif'>" + ((!nome) ? "" : " Blogmarks") + "</a></li>";
		}
		if(l == "spurl"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.spurl.net/spurl.php?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/spurl.gif'>" + ((!nome) ? "" : " Spurl") + "</a></li>";
		}
		if(l == "delirious"){
			compartilhe+= 	"<li><a target='_blank' href='http://de.lirio.us/rubric/post?uri=" + endereco + ";title=" + titulo + ";when_done=go_back' /><img src='"+ pasta_img +"/delirious.gif'>" + ((!nome) ? "" : " Delirious") + "</a></li>";
		}
		if(l == "live"){
			compartilhe+= 	"<li><a target='_blank' href='https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/live.gif'>" + ((!nome) ? "" : " Live") + "</a></li>";
		}
		if(l == "linkagogo"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.linkagogo.com/go/AddNoPopup?url=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/linkagogo.gif'>" + ((!nome) ? "" : " Linkagogo") + "</a></li>";
		}
		if(l == "yahoo"){
			compartilhe+= 	"<li><a target='_blank' href='http://myweb2.search.yahoo.com/myresults/bookmarklet?u=" + endereco + "&t=" + titulo + "' /><img src='"+ pasta_img +"/yahoo.gif'>" + ((!nome) ? "" : " Yahoo MyWeb") + "</a></li>";
		}
		if(l == "scuttle"){
			compartilhe+= 	"<li><a target='_blank' href='http://www.scuttle.org/bookmarks.php/maxpower?action=add&address=" + endereco + "&title=" + titulo + "' /><img src='"+ pasta_img +"/scuttle.gif'>" + ((!nome) ? "" : " Scuttle") + "</a></li>";
		}
	}
	compartilhe+= "</ul>";
	div.innerHTML = compartilhe;
}

function MontaEmail(div, nome)
{
	var email = "<form method='post' id='compartilhe_email'>";
	email+= 	"<div id='email_compartilhe'>";
	email+= 		"<table>";
	email+=				"<tr><td id='campos'>Seu Nome: </td><td><input type='text' size=30 id='compartilhe_nome' ><span id='compartilhe_obrigatorio'>*</span></td></tr>";
	email+=				"<tr><td>Seu E-mail: </td><td><input type='text' id='compartilhe_email' size=30></td></tr>";
	email+=				"<tr><td>Nome Amigo: </td><td><input type='text' id='compartilhe_nome_destino' size=30><span id='compartilhe_obrigatorio'>*</span></td></tr>";
	email+=				"<tr><td>E-mail Amigo: </td><td><input type='text' id='compartilhe_email_destino' size=30><span id='compartilhe_obrigatorio'>*</span></td></tr>";
	email+=				"<tr><td>&nbsp;</td><td><a href='javascript:' onclick='verificaEmail()' id='compartilhe_enviar'>Enviar</a>"
	email+=				"<a href='javascript:' onclick='montaCompartilhe(document.getElementById(\"" + div.id + "\"), " + nome + ");' id='compartilhe_voltar'>Voltar</a>  <span id='compartilhe_obrigatorio_texto'>* campos obrigatórios</span></td></tr>";
	email+= 		"</table>";
	email+= 	"</div>";	
	email+= "</form>";
	div.innerHTML = email;
}

function verificaEmail()
{
	form = document.getElementById("compartilhe_email")	
	nome = form.compartilhe_nome;
	email = form.compartilhe_email;
	nome_destino = form.compartilhe_nome_destino;
	email_destino = form.compartilhe_email_destino;
	
	
	if(!nome.value || nome.value.length < 4){
		alert("Preencha seu Nome!");
		nome.focus();
		return;
	}
	if(!nome_destino.value || nome_destino.value.length < 4){
		alert("Preencha o Nome do Destinatário!");
		nome_destino.focus();
		return;
	}
	if(email.value.length > 0){
		email_p1 = email.value.split("@")
		if(email_p1.length > 1)	{
			email_p2 = email_p1[1].split(".");
			if(!email_p2[1])
			{
				alert("Preencha o seu E-mail Corretamente");
				email.focus();
				return;
			}	
		}
		else{
			alert("Preencha o seu E-mail Corretamente");
			email.focus();
			return;
		}
	}	
	
	if(!email_destino.value || email_destino.value.length < 4){
		alert("Preencha o E-mail Destino!");
		email_destino.focus();
		return;
	}
	else{
		email_destino_p1 = email_destino.value.split("@")
		if(email_destino_p1.length > 1)	{
			email_destino_p2 = email_destino_p1[1].split(".");
			if(!email_destino_p2[1])
			{
				alert("Preencha o E-mail Destino Corretamente");
				email_destino.focus();
				return;
			}	
		}
		else{
			alert("Preencha o E-mail Destino Corretamente");
			email_destino.focus();
			return;
		}
	}	
		
	enviaEmail(nome, email, nome_destino, email_destino);
}

function enviaEmail(nome, email, nome_destino, email_destino)
{
	vars = 'endereco=' + escape(location.href) + '&titulo=' + escape(document.title) + '&nome=' + escape(nome.value) + '&email=' + email.value + '&nome_destino=' + escape(nome_destino.value) + '&email_destino=' + escape(email_destino.value);
	$.ajax({
		type: "POST",
		url: "/stock_car/goodyear_90_anos/includes/envia_email_compartilhe.asp",
		data: vars,
		success: function(){
				nome.value = '';
				email.value = '';
				nome_destino.value = '';
				email_destino.value = '';
				alert('Mensagem enviada!');
		},
		error: function(){
			alert("Erro ao enviar mensagem!");
		}
	});
}

function exibeCompartilhe(div){
	if(div.style.display == "block"){
		div.style.display = "none"
	}
	else{
		div.style.display = "block"
	}
}