    $(document).ready(function(){

$("#frmEnviarOrc").validate({

rules: {
    valorOrc: {required:true,
				valorMinimoOrcamento:true},
/*
    email: {
        required: true,
        email: true,
    },
*/
    descCurtaOrc: "required",
    tituloOrc: "required"	
},

messages: {
    tituloOrc: " * Informe um título",
    descCurtaOrc: " * Informe uma breve descrição",	
    valorOrc: {required:" * Informe um valor"},
/*    email: {
        required: "Dude, you want the newsletter, but you didn't enter an email address?",
        email: "Email addresses are of the form user@host. Not yourRstupid."
    },
    name: {
        required: "Stand up for your comments or go home.",
        minlength: jQuery.format("You need to use at least {0} characters for your name.")
    }
	*/
}


});

$.validator.addMethod("valorMinimoOrcamento", function(value, element) {
    return this.optional(element) || (parseFloat(value.replace(/[^\d]+/gi,'')) > 10000);
}, " * O valor mínimo é de R$ 100,00");
////

 $(".css-swapBarra").live('click', function() {
esta=this;
//	 alert($(this).attr("class"));
/*if ($(this).attr("class").match(/on/)){
      this.src = this.src.replace("_off","_on");
    } else {
      this.src = this.src.replace("_on","_off");
    }
    $(this).toggleClass("on");
*/
$('.css-swapBarra').each(function(index) {
	if(this != esta){
		
	if ($(this).hasClass('orcItemAtivo')){
      $(this).removeClass('orcItemAtivo');
	  $('#orcTab_'+$(this).attr("rel")).hide();
	}
	}
});
	
	$('#orcTab_'+$(this).attr("rel")).show();
      $(this).addClass('orcItemAtivo');

	
  });
  
  ///
  $(".btnOrcDetalhesMais").click(function(){
	  $('#orcDivDetalhes_'+$(this).attr('alt')).toggle();
	  $(this).toggleClass('btnOrcDetalhesMenos');
  });
  ////
	$("#btnEnviarOrc").click(function(){
 	$.ajax({type: "POST", url: "ajaxOrcamento.php",
    data: "funcao=enviarOrcamento&" + $('#frmEtapa2').serialize(),
	  dataType: "json",
				success:
					function(data){
						if(data.valido=='1'){
							$('#divOrcEnviado').show();
							$('#divEtapa2,#divBtnEditarOrc').hide();
						}
					},
				error:
					function(){
						
					}
			}); 
	});
	
	///
	$("#btnConversacaoEnviar").click(function(){
 	$.ajax({type: "POST", url: "ajaxOrcamento.php",
    data: "funcao=adMsgOrcamento&" + $('#frmMsgConversacao').serialize(),
	  dataType: "json",
				success:
					function(data){
						if(data.valido=='1'){
							$('#divOrcConversacao').append(data.msgHtml);
							$('#msgOrc').val('');
							$('#msgOrc_'+data.idMsg).css('border','2px solid #f8f8f8');
						}
					},
				error:
					function(){
						
					}
			}); 
	});
	/////

	$("#btnOrcSalvarContrato").click(function(){
 	$.ajax({type: "POST", url: "ajaxOrcamento.php",
    data: "funcao=aceitarCondicoes&" + $('#frmOrcContrato').serialize(),
	  dataType: "json",
				success:
					function(data){
						if(data.valido=='1'){
							$('#statusSalvarContrato').append('Informações salvas com sucesso!');
						}
					},
				error:
					function(){
						
					}
			}); 
	});
		
	////// 
	});
	///////// fim jquery


	function carregaConversacao(idOrc){
 	$.ajax({type: "POST", url: "ajaxOrcamento.php",
    data: "funcao=novasMsgs&idOrc=" + idOrc,
	  dataType: "json",
				success:
					function(data){
						if(data.valido=='1'){
		   $('#divOrcConversacao').append(data.msgHtml);
		   $('#msgOrc_'+data.idMsg).css({'border':'#f8f8f8 2px solid'});
		   $('#msgOrc_'+data.idMsg).hide().slideDown("slow");
		   if(data.msgHtml != null){
			$.titleAlert('Nova mensagem recebida!', {interval:1000, originalTitleInterval:200});
		   }
						}
					},
				error:
					function(){
						
					}
			}); 
		
	}
	
	/////
function maskDinheiro(w,e,m,r,a){
// Cancela se o evento for Backspace
if (!e) var e = window.event
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
// Variáveis da função
var txt  = (!r) ? w.value.replace(/[^\d]+/gi,'') : w.value.replace(/[^\d]+/gi,'').reverse();
var mask = (!r) ? m : m.reverse();
var pre  = (a ) ? a.pre : "";
var pos  = (a ) ? a.pos : "";
var ret  = "";
if(code == 9 || code == 8 || txt.length == mask.replace(/[^#]+/g,'').length) return false;
// Loop na máscara para aplicar os caracteres
for(var x=0,y=0, z=mask.length;x<z && y<txt.length;){
if(mask.charAt(x)!='#'){
ret += mask.charAt(x); x++; } 
else {
ret += txt.charAt(y); y++; x++; } }
// Retorno da função
ret = (!r) ? ret : ret.reverse()        
w.value = pre+ret+pos; }
// Novo método para o objeto 'String'
String.prototype.reverse = function(){
return this.split('').reverse().join(''); };
	
