function busca(){
  valor = $(this).val()
  switch(valor){
    case "procurar":
      $(this).val('')
      break
    case "":
      $(this).val('procurar')
      break
  }
}
function remover () {
  var hrefantiga = $(this).attr("href")
  href = hrefantiga.split("?")
  var elm = $(this).parents("tr")
  var elmTotal = $("#total")
  if(confirm('Você deseja remover essa indicação?')){
    $.post(href[0],
        { key: href[1] },
        function(data) {
          elm.remove();
          elmTotal.text(data);
        }
    )
  }
  return false;
}
function textCounter() {
  maxlimit = 255
  if (this.value.length > maxlimit)
    this.value = this.value.substring(0, maxlimit)

}
$(document).ready(function(){
  $("#tabs").tabs()
  $('input#q').click(busca)
  $('input#q').blur(busca)
  $(".treinamento").cycle()
  $("#idiomas").hover(function(){
    $("#idiomas span").fadeIn("slow")
  },
  function(){
    $("#idiomas span").fadeOut("slow")
  })

  $("#conteudo input, textarea, select").focus(
    function () {
      $(this).css({ "background-color":"#f0f0f0", "border-color":"#333" })
    }
  )

  $("#conteudo input, textarea, select").blur(
    function () {
      $(this).css({"background-color":"#fff", "border-color":"#ccc" })
    }
  )

  $(".delete").click(remover)

  $("[name=telefone]").mask("(99) 9999-9999")
  $("[name=cpf]").mask("999.999.999-**")
  $("[name=cep]").mask("99999-999")
  $("[name=cnpj]").mask("99.999.999/9999-99")
  $(".data input").mask("99/99/9999")

  $("textarea").keyup(textCounter)

  if($('#estado').get(0)){
    new dgCidadesEstados({
    estado: $('#estado').get(0),
    cidade: $('#cidade').get(0),
    change: true
    })
  }
  
  $('.readonly').focus(function(){
    $(this).blur()
  })
  
  
  $(".colorbox").live("click", function () {
	var link = $(this).attr("href")
  $.fn.colorbox({width:"990px", height:"650px", iframe:true, href: link})
    return false
  })
  
  
})

