$(document).ready(function() {
	$(".png").ifixpng();
	$('#boxScroll').jScrollPane({ scrollbarWidth: 11, scrollbarMargin: 32, showArrows: true });
	$('#boxScrollCadastro').jScrollPane({ scrollbarWidth: 11, scrollbarMargin: 32, showArrows: true });
	$('#boxScrollaBrasif').jScrollPane({ scrollbarWidth: 11, scrollbarMargin: 32, showArrows: true });
	$('#boxScrollDicas').jScrollPane({ scrollbarWidth: 11, scrollbarMargin: 32, showArrows: true });
	
	$scrollReg = setTimeout('$("#boxScrollRegulamento").jScrollPane({ scrollbarWidth: 11, scrollbarMargin: 32, showArrows: true })', 100);
	$scrollReg = setTimeout('$("#boxScrollNotaFiscal").jScrollPane({ scrollbarWidth: 11, scrollbarMargin: 32, showArrows: true })', 100);
	//$url = $("a.thickbox").attr("href");
	//$("a.thickbox").attr("href", $url + "?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=427&width=926&modal=true" );
	//$("a.thickbox.cad").attr("href", $url + "?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=100&width=333&modal=true" );
	
	$("#flashBannerBrasif").flash({src: '/swf/banner_brasif.swf',width: 523, height: 219, wmode: 'transparent'});
	
	$("a.regulamento").click(function(){
		tb_show('', 'tb/regulamento.aspx?keepThis=true&TB_iframe=true&width=926&height=427&modal=true', false);
		return false;
	});
	
	$("#formCadastro").validate({ errorContainer: $('.msgVerifique'),//validacao form de cadastro.
		submitHandler: function() {//enviar dados do cadastro, abre tickbox de sucesso.
			$.ajax({  
				data: $("#formCadastro").serialize(), 
				dataType: "json",
				url: '/Cadastro/Save.ashx',
				type: 'post',
				success: function(json) {
					if(json.msg == "OK"){
						tb_show('', 'tb/cadastroSucesso.aspx?keepThis=true&TB_iframe=true&width=333&height=100&modal=true', false);
						$("#boxPJ, #boxPF, table#cadastroEndereco, table#cadastroSatisfacao").clearForm();
					}else{
						tb_show('', 'tb/cadastroErro.aspx?keepThis=true&TB_iframe=true&width=333&height=100&modal=true', false);
					}
				}  
			}); 
		}
	});
	
	$("input[name='nomeFiscal']").click(function(){//verifica form de pf e pj de cadastro.
	$valor = $(this).val();//adiciona e remove campos obrigatorios.
	$("#boxPJ, #boxPF").hide();
		switch($valor){
			case 'boxPJ':
				$("#boxPF").find(".requiredPF").removeClass("required");
				$("#boxPJ").find(".requiredPJ").addClass("required");
			break;
			case 'boxPF':
				$("#boxPJ").find(".requiredPJ").removeClass("required");
				$("#boxPF").find(".requiredPF").addClass("required");
			break;
		}
		$("#boxPJ, #boxPF, table#cadastroEndereco, table#cadastroSatisfacao").clearForm();
		$("#" + $valor).show();
	});//verifica form de pf e pj de cadastro.
	
	$("#formNotaFiscal").validate({ errorContainer: $('.msgVerifique'),//validacao form nota fiscal da index.
		submitHandler: function() {//enviar dados de notafiscal abre tickbox.
			$cnpj = $("#notaCnpj").val();
			$cpf = $("#notaCpf").val();
			tb_show('', 'tb/pontosNotaFiscal.aspx?cpf='+ $cpf +'&cnpj='+ $cnpj +'&keepThis=true&TB_iframe=true&width=380&height=300&modal=true', false);
		}
	});//valida form nota fiscal da index.
	
	$("input[name='notaFiscal']").click(function(){//verifica form de pf e pj da home.
		$valor = $(this).val();//zera valores de pf e pj.
		$("#boxPJ, #boxPF").hide();
		$("#notaCnpj, #notaCpf").val("");
		switch($valor){
			case 'boxPJ':
				$("#boxPF").find(".requiredPF").removeClass("required");
				$("#boxPJ").find(".requiredPJ").addClass("required");
			break;
			case 'boxPF':
				$("#boxPJ").find(".requiredPJ").removeClass("required");
				$("#boxPF").find(".requiredPF").addClass("required");
			break;
		}
		$("input#notaCnpj, input#notaCpf").clearForm();
		$("#" + $valor).show();
	});//verifica form de pf e pj da home.

	$(".money").maskMoney({ showSymbol: false, decimal: ",", thousands: "." });
		
	$("input.data").mask("99/99/9999");
    $("input.tel").mask("99-99999999");
    $("input.cep").mask("99999-999");
    $("input.cpf").mask("999.999.999-99");
	$("input.cnpj").mask("99.999.999/9999-99");
	
	//maxlengh
	$("textarea.maxlength").maxlength({
			'feedback' : '.charsLeft'
	});
	
	/*Google analytics*/
	$("a[href='http://www.brasifmaquinas.com.br/']").click(function(){
		pageTracker._trackPageview('/G1/brasif.com.br');
	});
});

$.fn.clearForm = function() {
	$(this).find(':text, :password, textarea').attr('value', '').removeClass("error").end().find(':checkbox, :radio').attr('checked', false).removeClass("error").end().find('select').attr('selectedIndex', -1).removeClass("error");
}
