/* Desenvolvido por Guilherme Augusto Madaleno - zatec@ymail.com */
	/* Função para pingar servidores zatec.us */
	
	$.pingServer = function(pingID, barDiv) 
	{
		$.ajax
		({
			url: 		"http://www.zatecus.com/support.json",
			type: 		"POST",
			data:		"tool=ping&pid=" + pingID,
			dataType: 	"json",
			success: 	function(callBack)
			{
				switcher = false;
				if (callBack.ping)
				{
					$(barDiv).html(callBack.ping);
					if (callBack.ping <= 20)
					{
						$(barDiv).css('width', '10%');
						$(barDiv).css('backgroundColor', 'green');
					}
					else if (callBack.ping <= 40)
					{
						$(barDiv).css('width', '20%');
						$(barDiv).css('backgroundColor', 'green');
					}
					else if (callBack.ping <= 60)
					{
						$(barDiv).css('width', '30%');
						$(barDiv).css('backgroundColor', 'green');
					}
					else if (callBack.ping <= 80)
					{
						$(barDiv).css('width', '40%');
						$(barDiv).css('backgroundColor', 'green');
					}
					else if (callBack.ping <= 100)
					{
						$(barDiv).css('width', '50%');
						$(barDiv).css('backgroundColor', 'orange');
					}
					else if (callBack.ping <= 130)
					{
						$(barDiv).css('width', '60%');
						$(barDiv).css('backgroundColor', 'orange');
					}
					else if (callBack.ping <= 160)
					{
						$(barDiv).css('width', '70%');
						$(barDiv).css('backgroundColor', 'orange');
					}
					else if (callBack.ping <= 200)
					{
						$(barDiv).css('width', '70%');
						$(barDiv).css('backgroundColor', 'orange');
					}
					else if (callBack.ping <= 250)
					{
						$(barDiv).css('width', '90%');
						$(barDiv).css('backgroundColor', 'red');
					}
					else
					{
						$(barDiv).css('width', '100%');
						$(barDiv).css('backgroundColor', 'red');	
					}
				}
				else
				{
					$(barDiv).html('9999');
					$(barDiv).css('width', '100%');
					$(barDiv).css('backgroundColor', 'red');
				}
			}
		});	
	};
	
	/* Função para montar e-mail */
	
	$.noSpam = function (email, mount, hide)
	{
		if (email)
		{
			email = email.replace(' em ', '@');
			email = email.replace(' ponto ', '.');
			$(mount).html('<a href="mailto:' + email + '" style="color: #666;">' + email + '</a>');
		}
		else
			$(hide).hide();	
	};

	$(document).ready(function() 
	{
		
		/* Monta meu e-mail prevenindo spam */
		
		$.noSpam(pleaseNoSpam, 'span#mountEmail', 'p#hideEmail');
		$.noSpam(pleaseNoSpam2, 'span#mountEmail2', 'p#hideEmail2');	
		
		/* Para pingar os servidores da zatec.us */
	
		$.pingServer('ping1', 'div#ping1 div#progbar');
		$.pingServer('ping2', 'div#ping2 div#progbar');
		
		setInterval(function()
		{
			$.pingServer('ping1', 'div#ping1 div#progbar');
			$.pingServer('ping2', 'div#ping2 div#progbar');
		}, 3000);
		
		/* Para abrir janelinha de status */
		
		$('#statusWindow').click(function()
		{
			var url = $(this).attr('href');
			var janela = window.open(url, 'status', 'width=390,height=360,left=60,top=60,scrollbars=1,resizable=0,status=0,toolbar=0,location=0,menubar=0,directories=0');
			janela.focus();
			return false;
		});
		
	});
