$(document).ready(function(){
	
	$('input:not(.cert-input), textarea').focus(function(){
		validaemail();	
	})
	
	$('#banner').cycle({
		 fx: 'fade',
		 delay:  -9000,
		 timeout: 9000,
		 speed: 5000,
		 pause: true
		});
		
	$('#banner-produtos').cycle({fx: 'fade',delay:  -7000,timeout: 6000,speed: 4000,pause: true});	
		
	$('#banner-servicos').cycle({fx: 'turnDown',delay:  -8000,timeout: 10000,speed: 5000,pause: true});	
		
		
	/*submenu contato*/
	$("#menu ul.top li a").hover(function() {
		 $(this).parent().find("ul.sub").slideDown('fast').show(); 
		 $(this).parent().hover(function() {  
		 }, function(){  
			 $(this).parent().find("ul.sub").slideUp('slow');
		 });  
	 });  	
		

	/*Serviços*/	
	$(".serv-info:not(:first)").hide();
	  $(".serv-box a").click(function(){
	   $(".serv-info:visible").slideUp("slow");
	   $(this).next('div').slideDown("slow");
	return false;
	});

	/*Certificados*/
	$('#certificados-solicitar').click(function(){
		var imgload = imgLoad('m');
		var user = $('#user').val();
		var pass = $('#pass').val();
		
		if(user && pass)
		{
			var url = 'certificacoes-ajax.php?user='+user+'&pass='+pass;
			$.ajax({
					url: url,
					dataType: 'html',
					type: 'GET',
					timeout: 10000,
					beforeSend: function(){
						 $('#certificados-retorno').fadeIn().html(imgload);
					},
					complete: function() {
					   $('#certificados-retorno').remove(imgload).fadeOut();
					},
					success: function(data, textStatus) {
					   $('#certificados-retorno').fadeIn('slow').html(data);
					},
					error: function(xhr , er) {
					}
			});
		}
	});
	
	
	
});


	
function imgLoad (x){
	 var a = '<img src="images/load'+x+'.gif"/>';
	 return a;
}



function mascara(Field, m, e) {

var Value = Field.value.replace( /\W/gi, "" ),i;

for (i = 0; i < Value.length; i ++) {
	 if (!/[#A9%]/.test(m.charAt(i))) {
	  Value = Value.splice(i, 1, m.charAt(i) + Value.charAt(i));
	 }
}

var ValueFormated = '';
for (i = 0; i < Value.length; i ++) {
  if (
  	  	 (m.charAt(i) == "A" && /[a-z]/i.test(Value.charAt(i))) ||
       (m.charAt(i) == "9" && /[0-9]/.test(Value.charAt(i))) ||
       (m.charAt(i) == "%" && /[0-9a-fA-F]/.test(Value.charAt(i))) ||
       (m.charAt(i) == "#" && /\w/.test(Value.charAt(i)))
		) {

  		ValueFormated += Value.charAt(i);

 }else if (m.charAt(i) == Value.charAt(i)){
   ValueFormated += Value.charAt(i);
 }
}

if (ValueFormated.replace( /\W/gi, "" ) == ''){
  ValueFormated = '';
}

Field.value = ValueFormated;
}

String.prototype.splice = function (i, offset, str) {
if (i < 0)
 i = this.length + i;

return this.substr(0, i) + (str || "") + this.substr(i + offset, this.length)
}


/*///////// EMAIL ////////////*/
function validaemail(){
			var cont = 0;
			var msg;
			
			
			/*: area :*/
			if( $('#area').val() == '') {
				$('#area').next('span').html('Informe a area de atuacao').fadeIn(1500);
				cont = cont + 1;
			}else $('#area').next('span').fadeOut(1500);
			
			/*: empresa :*/
			if( $('#empresa').val() == '') {
				$('#empresa').next('span').html('Informe a empresa').fadeIn(1500);
				cont = cont + 1;
			}else $('#empresa').next('span').fadeOut(1500);
			
			/*: nome :*/
			if( $('#nome').val() == '') {
				$('#nome').next('span').html('Preencha o seu nome').fadeIn(1500);
				cont = cont + 1;
			}else $('#nome').next('span').fadeOut(1500);
			

			/*: fone:*/
			if( $('#fone').val() == '' ) {
				$('#fone').next('span').html('Preencha o seu fone').fadeIn(1500);
				cont = cont + 1;	
			}else if ( $('#fone').val().length < 14) {	
				$('#fone').next('span').html('Fone incompleto').fadeIn(1500);
				cont = cont + 1;	
			}else $('#fone').next('span').fadeOut(1500);

			/*: email  */
			var vEmail;
			vEmail = $('#email').val();
			var eEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
			
			if($('#email').val()  == ""){	
						$('#email').next('span').html('Preencha seu e-mail').fadeIn(1500);
						cont = cont + 1;
			}else if ( !(eEmail.test(vEmail))) {
						$('#email').next('span').html('E-mail inv&aacute;lido').fadeIn(1500);
						cont = cont + 1;
			}else $('#email').next('span').fadeOut(1500);
			
			/*: mensagem  */
			if( $('#mensagem').val() == '' ) {
						$('#mensagem').next('span').html('Escreva sua mensagem').fadeIn(1500);
						cont = cont + 1;	
			}else $('#mensagem').next('span').fadeOut(1500);
			return cont;
}


function enviaremail() {
			
			var error = validaemail();
			if(error <= 0) {
				 document.getElementById('formContato').submit();
			}else return false;
}

