// JavaScript Document
	function Limpar2()
	{
		document.form2.reset();
		document.form2.cnpjdest.focus();
	}
	
	function Vai2()
	{
		if (document.form2.cnpjdest.value == "")
		{
			alert("Informe o CNPJ do destinatário.");
			return;
		}
		
		if ( (document.form2.cnpjdest.value.length > 11) && (document.form2.senha.value == "") )
		{
			alert( "Informe a Senha." );
			return;
		}
		
		document.form2.submit();
	}
	
	
	
	
	
	$(document).ready(function()
	{
			
			


		
		$('#SelectTipoRastreamento').change(function()
		{
			$('form').hide();
			$('#form' + $(this).val()).show();
			
			$('#tituloTipo').text( 'Rastreamento pelo ' + $('#SelectTipoRastreamento option:selected').text().toLowerCase() )
			
		});
		
		$('#vaiRemetente').click(function()
		{
			
			var cnpjRem 	= $('#cnpjRem').val();
			var senhaRem	= $('#senhaRem').val();
			var tipoBusca	= $('#tipoBuscaRem').val();
			
			
			
			if( senhaRem != ""  && cnpjRem != "" ) {
				
				$('#aguarde').css( 'display', 'inline' );
				
				$.post('baixa_rastreamento.php', { 'cnpj' : cnpjRem, 'senha' : senhaRem, 'tipoBusca': tipoBusca }, 
				function( data )
				{
					
					$('.tabela-rastreado').html( data ).css('display', 'none');
					//$('.tabela-rastreado tr td[valign=top]').remove(); $('.tabela-rastreado table:eq(2)').text()
					
					var destinatario	= $('.tabela-rastreado table:eq(2)').html();

					var rastreado 		= $('.tabela-rastreado table:eq(3)').html();
					
					//alert(rastreado)
					
					$('.tabela-rastreado').html( '<table>' + rastreado + '</table>' ).css( 'display', 'inline' );
					
					$('.tabela-rastreado td').attr( 'valign', 'top');
					
					$('.tabela-rastreado').prepend( '<div>' + destinatario + '</div><br />' ).append( '<br /><div style="text-align:left;">Processado por: <a href="http://www.ssw.inf.br/apresentacao.asp" target="_blank" class="sswinfbr3">www.ssw.inf.br</a></div>' );
					
					$('div p[class=rastreamento]').css( 'text-align', 'left' );
					
					$('a[class=rastreamento]').each(function() {
						
						var vetGets = $(this).attr( 'href' ).split('?');
						arquivo = 'carregar.php?'+ vetGets[1] + '&iframe=true&width=600&height=550' ;
						
						$(this).attr( 'href', arquivo ).attr('rel','prettyPhoto[iframe-op1]');
						//$(this).prettyPhoto();
						
					});
					
					
					$("a[rel^='prettyPhoto']").prettyPhoto();
					
					$("a[onclick*='comprovante.asp']").each(function()
					{
						onclickEmail = $(this).attr('onClick') ;
						var vetLink = onclickEmail.split('\'');
						$(this).attr( 'href', 'http://www.ssw.inf.br'+vetLink[1]).attr('target', '_blank').removeAttr('onclick');
						
					})
					
					
										
					
					$("a[href*='ssw_resultSSW_pag.asp']").live('click', function()
					{	
						
						var href = $(this).attr('href').replace('http://direcional.olyva.com.br/','')
						
						$('.tabela-rastreado').html('').text('Aguarde...');
						
						$.post('carrega.paginacao.php', {'pagina': href}, function(data)
						{
							
							$('.tabela-rastreado').html( data ).css('display', 'none');
							
							var destinatario	= $('.tabela-rastreado table:eq(2)').html();
							
							var rastreado 		= $('.tabela-rastreado table:eq(3)').html();
							
							
							$('.tabela-rastreado').html( '<table>' + destinatario + '</table><table>' + rastreado + '</table>' ).css( 'display', 'inline' );
							
							
							
							$('a[class=rastreamento]').each(function() {
								
								var vetGets = $(this).attr( 'href' ).toLowerCase().split('?');
								arquivo = 'carregar.php?'+ vetGets[1] + '&iframe=true&width=600&height=550' ;
								
								$(this).attr( 'href', arquivo ).attr('rel','prettyPhoto[iframe-op1]');
								
								
								
							});
								
							$("a[onclick*='comprovante.asp']").each(function()
							{
								onclickEmail = $(this).attr('onClick') ;
								var vetLink = onclickEmail.split('\'');
								$(this).attr( 'href', 'http://www.ssw.inf.br'+vetLink[1]).attr('target', '_blank').removeAttr('onclick');
								
							})
							
							$("a[rel^='prettyPhoto']").prettyPhoto();
							
							
						}, 'html' );
						
						
						
						return false;
						
						
						
					});
					
					
					
					
					$('#aguarde').css( 'display', 'none' );
						
				}, 'html');
				
			} else {
				
				alert('Preencha todos os campos!');
				return false;
				
			}
			
		});
		
		$('#vaiPagador').click(function()
		{
			
			var cnpjPag 	= $('#cnpjPag').val();
			var senhaPag	= $('#senhaPag').val();
			var tipoBusca	= $('#tipoBuscaPag').val();
			
			
			
			if( senhaPag != ""  && cnpjPag != "" ) {
				
				$('#aguarde').css( 'display', 'inline' );
				
				$.post('baixa_rastreamento.php', { 'cnpj' : cnpjPag, 'senha' : senhaPag, 'tipoBusca': tipoBusca }, 
				function( data )
				{
						
					
					$('.tabela-rastreado').html( data ).css('display', 'none');
					//$('.tabela-rastreado tr td[valign=top]').remove(); $('.tabela-rastreado table:eq(2)').text()
					
					var destinatario	= $('.tabela-rastreado table:eq(2)').html();

					var rastreado 		= $('.tabela-rastreado table:eq(3)').html();
					
					//alert(rastreado)
					
					$('.tabela-rastreado').css( 'display', 'inline' ).html( '<table>' + rastreado + '</table>' );
					
					$('.tabela-rastreado td').attr( 'valign', 'top');
					
					$('.tabela-rastreado').prepend( '<div>' + destinatario + '</div><br />' ).append( '<br /><div style="text-align:left;">Processado por: <a href="http://www.ssw.inf.br/apresentacao.asp" target="_blank" class="sswinfbr3">www.ssw.inf.br</a></div>' );
					
					$('div p[class=rastreamento]').css( 'text-align', 'left' );
					
					$('a[class=rastreamento]').each(function() {
						
						var vetGets = $(this).attr( 'href' ).toLowerCase().split('?');
						arquivo = 'carregar.php?'+ vetGets[1] + '&iframe=true&width=600&height=550' ;
						
						$(this).attr( 'href', arquivo ).attr('rel','prettyPhoto[iframe-op1]');
						
						$(this).prettyPhoto()
					});
					
					//$("a[rel^='prettyPhoto']").prettyPhoto();
										
					$("a[onclick*='comprovante.asp']").each(function()
					{
						onclickEmail = $(this).attr('onClick') ;
						var vetLink = onclickEmail.split('\'');
						$(this).attr( 'href', 'http://www.ssw.inf.br'+vetLink[1]).attr('target', '_blank').removeAttr('onclick');
						
					})
					
										
					
					$("a[href*='ssw_resultSSW_pag.asp']").live('click', function()
					{	
						
						var href = $(this).attr('href').replace('http://www.direcionaltransportes.com.br/','')
						
						$('.tabela-rastreado').html('').text('Aguarde...');
						
						$.post('carrega.paginacao.php', {'pagina': href}, function(data)
						{
							
							
							$('.tabela-rastreado').html( data ).css('display', 'none');
							
							var destinatario	= $('.tabela-rastreado table:eq(2)').html();
							
							var rastreado 		= $('.tabela-rastreado table:eq(3)').html();
							
							
							$('.tabela-rastreado').html( '<table>' + destinatario + '</table><table>' + rastreado + '</table>' ).css( 'display', 'inline' );
							
							
							
							$('a[class=rastreamento]').each(function() {
								
								var vetGets = $(this).attr( 'href' ).toLowerCase().split('?');
								arquivo = 'carregar.php?'+ vetGets[1] + '&iframe=true&width=600&height=550' ;
								
								$(this).attr( 'href', arquivo ).attr('rel','prettyPhoto[iframe-op1]');
								
								
								
							});
								
							$("a[onclick*='comprovante.asp']").each(function()
							{
								onclickEmail = $(this).attr('onClick') ;
								var vetLink = onclickEmail.split('\'');
								$(this).attr( 'href', 'http://www.ssw.inf.br'+vetLink[1]).attr('target', '_blank').removeAttr('onclick');
								
							})
							
							$("a[rel^='prettyPhoto']").prettyPhoto();
							
							
						}, 'html' );
						
						
						
						return false;
						
						
						
					});
					
					
					$('#aguarde').css( 'display', 'none' );
					
				}, 'html');
				
			} else {
				
				alert('Preencha todos os campos!');
				return false;
				
			}
			
		});
		//$('#linkPrint');
	
		$('#sads').prettyPhoto();	
		$('#vaiDestinatario').click(function()
		{
			
			var cnpjdest 	= $('#cnpjdest').val();
			var senha		= $('#senha').val();
			var tipoBusca	= $('#tipoBuscaDest').val();
			
			
			
			if( senha != ""  && cnpjdest != "" ) {
				
				$('#aguarde').css( 'display', 'inline' );
				
				$.post('baixa_rastreamento.php', { 'cnpj' : cnpjdest, 'senha' : senha, 'tipoBusca': tipoBusca }, 
					function( data )
					{
							
						$('.tabela-rastreado').html( data ).css('display', 'none');
						//$('.tabela-rastreado tr td[valign=top]').remove(); $('.tabela-rastreado table:eq(2)').text()
						
						var destinatario	= $('.tabela-rastreado table:eq(2)').html();
	
						var rastreado 		= $('.tabela-rastreado table:eq(3)').html();
						
						//alert(rastreado)
						
						$('.tabela-rastreado').css( 'display', 'inline' ).html( '<table>' + rastreado + '</table>' );
						
						$('.tabela-rastreado td').attr( 'valign', 'top');
						
						$('.tabela-rastreado').prepend( '<div>' + destinatario + '</div><br />' ).append( '<br /><div style="text-align:left;">Processado por: <a href="http://www.ssw.inf.br/apresentacao.asp" target="_blank" class="sswinfbr3">www.ssw.inf.br</a></div>' );
						
						$('div p[class=rastreamento]').css( 'text-align', 'left' );
						
						$('a[class=rastreamento]').each(function() {
							
							var vetGets = $(this).attr( 'href' ).split('?');
							arquivo = 'carregar.php?'+ vetGets[1] + '&iframe=true&width=600&height=550' ;
							
							$(this).attr( 'href', arquivo ).attr('rel','prettyPhoto[iframe-op1]');
							//$(this).prettyPhoto();
							
						});
						
						$("a[rel^='prettyPhoto']").prettyPhoto();
						
						
						
						
						$('#aguarde').css( 'display', 'none' );
						
						
						
						$("a[onclick*='comprovante.asp']").each(function()
						{
						
						
							onclickEmail = $(this).attr('onClick');//alert(onclickEmail);
							var vetLink = onclickEmail.split('\'');
							$(this).attr( 'href', 'http://www.ssw.inf.br'+vetLink[1]).attr('target', '_blank').removeAttr('onclick');
							
						})
						
						
										
					
					$("a[href*='ssw_resultSSW_pag.asp']").live('click', function()
					{	
						
						var href = $(this).attr('href').replace('http://internet.direcionaltransportes/','')
						
						$('.tabela-rastreado').html('').text('Aguarde...');
						
						$.post('carrega.paginacao.php', {'pagina': href}, function(data)
						{
							
							$('.tabela-rastreado').html( data ).css('display', 'none');
							
							var destinatario	= $('.tabela-rastreado table:eq(2)').html();
							
							var rastreado 		= $('.tabela-rastreado table:eq(3)').html();
							
							
							$('.tabela-rastreado').html( '<table>' + destinatario + '</table><table>' + rastreado + '</table>' ).css( 'display', 'inline' );
							
							
							
							$('a[class=rastreamento]').each(function() {
								
								var vetGets = $(this).attr( 'href' ).toLowerCase().split('?');
								arquivo = 'carregar.php?'+ vetGets[1] + '&iframe=true&width=600&height=550' ;
								
								$(this).attr( 'href', arquivo ).attr('rel','prettyPhoto[iframe-op1]');
								
								
								
							});
								
							$("a[onclick*='comprovante.asp']").each(function()
							{
								
								
								onclickEmail = $(this).attr('onClick') ;
								var vetLink = onclickEmail.split('\'');
								$(this).attr( 'href', 'http://www.ssw.inf.br'+vetLink[1]).attr('target', '_blank').removeAttr('onclick');
								
							})
							
							$("a[rel^='prettyPhoto']").prettyPhoto();
							
							
						}, 'html' );
						
						
						
						return false;
						
						
						
					});
						
							
					}, 'html');
				
			}
			
			
		});
		
		
		if( window.location.href.indexOf("#") ) {
			
			var local = window.location.href.split("#");
			
			if( local[1] == "Remetente" ) {
				
				$('#SelectTipoRastreamento').val('Remetente').trigger('change')
				$('#vaiRemetente').trigger('click');
				
			} else if( local[1] == "Destinatario" ) {
			
				$('#SelectTipoRastreamento').val('Destinatario').trigger('change')
				$('#vaiDestinatario').trigger('click');
				
			} else if( local[1] == "Pagador" ) {
				
				$('#SelectTipoRastreamento').val('Pagador').trigger('change')
				$('#vaiPagador').trigger('click');
				
			}
			/*abre(local[1]);*/

		}	

		
	});
