jQuery.validator.addMethod("phoneBR",function(value, element){
	var teste = /(^\d{2}\s\d{4}\-\d{4}$)/.test(value);
	return this.optional(element) || teste ;
},"O fone deve ser no formato '99 9999-9999' .");
var classeErro ='';

$(function(){
	$('#comment-form > div > #edit-subject-wrapper > label').html('Nome:');
	// tira os : do campo o que voce deseja	
	$('#webform-component-o_que_voce_deseja > div > label').html('O que você deseja? <span class="form-required" title="Este campo é obrigatório.">*</span>');

	//controla a exbicao do campo arquivo
	$('#webform-component-arquivo').hide();

	//implementa o lightbox
	$('#outras-fotos li a').lightBox();
	$('#block-block-1 div a').lightBox();
	

	// faz aparecer o campo file se clica em determinado rediobutton do formulario de contato	
	$('.form-radios div label input:radio').click(function(){
			if($(this).val() != 'comercial@planobaselubianca.com.br' && $(this).is(':checked')){
				$('#webform-component-arquivo').slideDown('slow');	
			}else{
				if($('#webform-component-arquivo').is(':visible')){
					$('#webform-component-arquivo').slideUp('slow');
				}
			}
	});
    
    // Remove o atributo title da foto dos clientes
    $( 'body.page-clientes img.imagecache-Foto_Clientes' ).removeAttr( 'title' );
	
	//valida o formulario de contato
	$('#webform-client-form-1').validate({
		rules: {
			"submitted[nome]":{required: true ,minlength: 3},
			"submitted[email]":{required:true,email:true},
			"submitted[telefone]":{required:true},
			//"submitted[telefoneextra]":{digits:true},
			"submitted[mensagem]":{required:true}
		},
		messages: {
			"submitted[nome]":{required: 'Campo obrigat&oacute;rio!', minlength: 'Pelo menos 03 letras.'},
			"submitted[email]":{required: 'Campo obrigat&oacute;rio!',email:'Email inv&aacute;lido.'},
			"submitted[telefone]":{required:'Campo obrigat&oacute;rio!', digitis:'Digite somente n&uacute;meros.'},
			//"submitted[telefoneextra]":{digitis:'Digite somente n&uacute;meros.'},
			"submitted[mensagem]":{required:'Campo obrigat&oacute;rio!'}
		},
		highlight: function(element, errorClass){
			$(element).prev().addClass(classeErro);
		},
		unhighlight: function(element, errorClass){
			$(element).prev().removeClass(classeErro);
		},
		errorPlacement: function(error, element){
			error.appendTo(element.prev());
		},
		errorElement: 'strong'
	});
	$('#comment-form').validate({
		rules: {
			"comment":{required: true}
		},
		messages: {
			"comment":{required: 'Por favor digite seu comentário.'}
		},
		highlight: function(element, errorClass){
			$(element).parent('span').parent('div').prev().addClass(classeErro)
		},
		unhighlight: function(element, errorClass){
			$(element).parent('span').parent('div').prev().removeClass(classeErro)
		},
		errorPlacement: function(error, element){
			error.appendTo(element.parent('span').parent('div').prev())
		},
		errorElement: 'strong'
	});
	
	$('#block-enews #node-90 .content p').html( '' );
	
	//
	// VALIDA O FORMULÁRIO DE ENEWS
	//
	$('#webform-client-form-90').validate({
		rules: {
			"submitted[nome]":{required: true ,minlength: 3},
			"submitted[email]":{required:true, email:true}
		},
		messages: {
			"submitted[nome]":{required: 'Campo obrigat&oacute;rio!', minlength: 'Pelo menos 03 letras.'},
			"submitted[email]":{required: 'Campo obrigat&oacute;rio!',email:'Email inv&aacute;lido.'}
		},
		highlight: function(element, errorClass){
			$(element).prev().addClass(classeErro);
		},
		unhighlight: function(element, errorClass){
			$(element).prev().removeClass(classeErro);
		},
		errorPlacement: function(error, element){
			error.appendTo(element.prev());
		},
		errorElement: 'strong',
		submitHandler: function(form) {
			$(form).ajaxSubmit();			
			$(form).slideUp(1500,function(){
				$('#block-enews #node-90 .content p').html('Seu e-mail foi cadastrado com sucesso!').fadeOut(2500,function(){
					$(form).resetForm();
					
					$( '#webform-client-form-90 input#edit-submitted-nome' ).val( 'nome' );
					$( '#webform-client-form-90 input#edit-submitted-email' ).val( 'e-mail' );
					
					$(form).slideDown('slow');
				});
			});
			
		} 
	});

	// Inicializa o valor dos campos nome e email do bloco de enews
	if( $( '#webform-client-form-90 input#edit-submitted-nome' ).val() == "" ) { $( '#webform-client-form-90 input#edit-submitted-nome' ).val( 'nome' ); }
	if( $( '#webform-client-form-90 input#edit-submitted-email' ).val() == "" ) { $( '#webform-client-form-90 input#edit-submitted-email' ).val( 'e-mail' ); }
	
	$( '#webform-client-form-90 input#edit-submitted-nome' ).click( function() {
		if( $( this ).val() == "nome" ) $( this ).val( '' );
	}).blur( function() {
		if( $( this ).val() == "" ) $( this ).val( "nome" );
	});
	
	$( '#webform-client-form-90 input#edit-submitted-email' ).click( function() {
		if( $( this ).val() == "e-mail" ) $( this ).val( '' );
	}).blur( function() {
		if( $( this ).val() == "" ) $( this ).val( "e-mail" );
	});
	
// faz as mudancas de valor no onfocus de determinados campos
	$('#form-extranet > input')
	.focus(function(){ 
		if($(this).val() == $(this).attr('id')){
			$(this).val('');
	}})
	.blur(function(){
		if($(this).val() == '' || $(this).val() == $(this).attr('id')){
			$(this).val($(this).attr('id'));
	}});
	
	$( 'label[for=edit-subject]' ).text( 'Assunto:' );
	
	$( '#comment-form #edit-upload' ).attr( 'size', '43' );
	
	$( '#comment-form #edit-upload-wrapper' ).append( $( '#edit-attach' ) );
	
	$( '#comment-form #edit-attach' ).mouseup( function(){ $( '#comment-form #edit-upload-wrapper' ).append( $( '#edit-attach' ) ); } );

});