/****************************************************/
/********************** JQUERY **********************/
/****************************************************/
$(document).ready( function() {
							
	//-----------------------------------------------//

	// SCRIPT validaÃ§Ã£o

	//-----------------------------------------------//

	$('form').submit( function() {

		$('.campo :input', this).each( function() { $(this).blur(); });

		

		var conta_erro = 0;

		$('.erro',this).each( function () { conta_erro ++; });

		if(conta_erro>0) { return false; }

		

		$('.c_captcha',this).hide();

		$('.campo span', this).removeClass('ok');

		//$('p.alerta',this).text('Mensagem enviada com sucesso!');

		

		//return false;

	});

	

	$('.campo :input','form').keydown( function(e) {

		if( ($(this).attr('name') == 'dia') || ($(this).attr('name') == 'mes') || ($(this).attr('name') == 'ano') || ($(this).attr('name') == 'cpf') || ($(this).attr('name') == 'ddd') || ($(this).attr('name') == 'numero') ){

			var whichCode = e.keyCode;

			if( whichCode<35 || (whichCode>40 && whichCode<48) || (whichCode>57 && whichCode<90) || (whichCode>105 && whichCode<112) || whichCode>123 ){

				if(whichCode!=9 && whichCode!=8 && whichCode!=16 && whichCode!=46){

					return false;

				}

			}

		}

		

	});

	

	$('.campo :input','form').keyup( function(e) {	

		if( ($(this).attr('name') == 'dia') || ($(this).attr('name') == 'mes') || ($(this).attr('name') == 'ddd') ){

			var parent = $(this).parent();

			var proximo = $('input:eq('+ ($('input',parent).index(this)+1) +')',parent);

			if( $(this).attr('maxlength') == $(this).val().length ){

				proximo.focus();

			}

		}

	});

	

	$('.campo :input','form').blur( function() {

		var parent = $(this).parent();

		var label = $('label',parent).text();

		var value = jQuery.trim($(this).val());

		if( $(this).attr('type') != 'file' ) { $(this).val(value); }

		if (value == null) { value = '' }

						

		if (label.indexOf('*') > -1) {

			if((value == '') || (value == 'off')) {

				$('span',parent).removeClass('ok');

				$('span',parent).addClass('erro');

			}

			else {

				$('span',parent).removeClass('erro');

				$('span',parent).addClass('ok');

			}

			

			if( $(this).attr('type') == 'checkbox' ){

				if( $(this).attr('checked') ){

					$('span',parent).removeClass('erro');

					$('span',parent).addClass('ok');

				}

				else{

					$('span',parent).removeClass('ok');

					$('span',parent).addClass('erro');

				}

			}

			

			if( $(this).attr('name') == 'cpf' ){

				var cpf = $(this).val();

				

				for(a=0;a<cpf.length;a++){

					if((cpf.charAt(a)=='.') || (cpf.charAt(a)=='-')){

						cpf = cpf.substring(0,cpf.indexOf(cpf.charAt(a)))+cpf.substring(cpf.indexOf(cpf.charAt(a))+1,cpf.length)

					}

				}

    

				if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999") { valido = 0; }

				else {					

					soma = 0;

					for(i = 0; i < 10; i ++) { soma += parseInt(cpf.charAt(i)) * (11 - i); }

					resto = 11 - (soma % 11);

					if(resto == 10 || resto == 11) { resto = 0; }					

					if(resto != parseInt(cpf.charAt(10))) { valido = 0; }

					else { valido = 1; }

				}

				

				if(valido == 0){

					$('span',parent).removeClass('ok');

					$('span',parent).addClass('erro');

				} 

				else{

					$('span',parent).removeClass('erro');

					$('span',parent).addClass('ok');

				}

			}

			

			if( ($(this).attr('name') == 'dia') || ($(this).attr('name') == 'mes') || ($(this).attr('name') == 'ano') ){

				var data = $(this).parent();

				data = $('input:eq(0)',data).val() + $('input:eq(1)',data).val() + $('input:eq(2)',data).val();

				

				dia = data.substring(0,2);

				mes = data.substring(2,4);

				ano = data.substring(4,8);

				var dataAtual = new Date();

				anoAtual = dataAtual.getFullYear();

				if( dia=='' || dia==0 || dia>31 || mes=='' || mes==0 || mes>12 || ano=='' || ano>(anoAtual-1) || ano<(anoAtual-200)){

					$('span',parent).removeClass('ok');

					$('span',parent).addClass('erro');

				}

			}

			

			

			if( $(this).attr('name').indexOf('email') > -1 ){

			  var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

			  if (! regmail.test(value) ) {

					$('span',parent).removeClass('ok');

					$('span',parent).addClass('erro');

			  }				

			}			

		  }

		

	});

		

	$('.campo select','form').change( function() {

		var parent = $(this).parent();

		var label = $('label',parent).text();

		var value = $(this).attr('value');

		

		if (label.indexOf('*') > -1) {

			if((value == 0) || (value == '')) {

				$('span',parent).removeClass('ok');

				$('span',parent).addClass('erro');

			}

			else {

				$('span',parent).removeClass('erro');

				$('span',parent).addClass('ok');

			}

		}

		

	});	
							
	//-----------------------------------------------//
	// SCRIPT para TV da HOME
	//-----------------------------------------------//
	var tvAtivo = 0;
	var tvSetTime = 0;
	function tvRandom(){
		if( tvAtivo < $('.canais li').length - 1 ) { tvAtivo ++; }
		else { tvAtivo = 0; }
		tvTrans();
	};
	function tvTrans(){		
		$('.lista li','.tv').removeClass('ativo');
		$('.lista li:eq('+tvAtivo+')','.tv').addClass('ativo');
		$('.canais li','.tv').removeClass('ativo');
		$('.canais li:eq('+tvAtivo+')','.tv').addClass('ativo');
		tvSetTime = setTimeout(function() { tvRandom() }, 5000);
	};
	$('.tv').ready(function() {						
		tvTrans();
	});
	$('.canais li','.tv').click(function() {
		clearTimeout(tvSetTime);
		tvAtivo = $('.canais li').index(this);
		tvTrans();
	});	
							
	$('.gallery a').lightBox();
	
})
/****************************************************/ 

function Banners()
	{
	var MNews = new Array();
	MNews[0]= '<img src="http://www.trawmac.com/_files/img/flash.jpg" width="716" height="233" />'
	MNews[1]= '<img src="http://www.trawmac.com/_files/img/flash1.jpg" width="716" height="233" />'
	MNews[2]= '<img src="http://www.trawmac.com/_files/img/flash2.jpg" width="716" height="233" />'
	MNews[3]= '<img src="http://www.trawmac.com/_files/img/flash3.jpg" width="716" height="233" />'
	MNews[4]= '<img src="http://www.trawmac.com/_files/img/flash4.jpg" width="716" height="233" />'
	MNews[5]= '<img src="http://www.trawmac.com/_files/img/flash5.jpg" width="716" height="233" />'
	MNews[6]= '<img src="http://www.trawmac.com/_files/img/flash6.jpg" width="716" height="233" />'
	var Numero = Math.floor(Math.random()*7); //Não esqueça de trocar aqui pelo nº de imagens q vc tem
	document.write(MNews[Numero]);
	}