/*
 Desenvolvido por Ronnie Garcia
 www.ronniegarcia.com.br
 Criação de websites/sistemas entre outros
 ronninho.garcia@gmail.com
*/
function limitChars(textid, limit, infodiv){
	var text = $('#'+textid).val(); 
	var textlength = text.length;
	if(textlength > limit){
	  $('#' + infodiv).html('Vo&ecirc; n&atilde;o pode escrever mais de '+limit+' letras!');
	  $('#'+textid).val(text.substr(0,limit));
	  return false;
	} else {
	  $('#' + infodiv).html('Voc&ecirc; tem '+ (limit - textlength) +' letras faltando.');
	  return true;
	}
}

/* Recebe parametros e centraliza os Pop Ups na tela */
function PopUpCentralizado(nomepagina, titulopagina, w, h, scroll) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height=' + h + ', width = ' + w + ', top = ' + wint + ', left = ' + winl + ', scrollbars = ' + scroll + ', location=no, status=no';
  win = window.open(nomepagina, titulopagina, winprops);
  if (parseInt(navigator.appVersion)  >= 4) {
      win.window.focus();
  }
}

$(function(){
  $('#apresentacao').keyup(function(){
	limitChars('apresentacao', 500, 'info');
  })
});

$(function(){
  $('#apresentacao2').keyup(function(){
	limitChars('apresentacao2', 500, 'info2');
  })
});
$(document).ready(function() {
	$(document)[0].oncontextmenu = function() {return false;}
	$(document).bind("contextmenu",function(e){return false;});
	//$("#parceirodados").hide();
	$("select#perfil").change(function(){
	  if($("select#perfil").val()!="casal"){
		$("#parceirodados").slideUp("slow");
	  } else {
		$("#parceirodados").slideDown("slow");
	  }
	});
	
	$("span#fotoedit").click(function() {
	  if(confirm("Deseja apagar esta foto ?")){
		  $('div#div' + this.title).fadeOut("slow");
		  $.ajax({type: "GET",
			url: "pages/delfoto.php?id="+this.title,
			cache: false,
			success: function(html){
			  $("span#apaga").empty().append(html);
			}
		  });
		  return false;
	  }
	  return false;
	});

	$("td#dados").click(function() {
	  PopUpCentralizado('http://www.esblog.com.br/pages/perfil.php?id=' + this.title, 'perfil', '640', '480', 'yes');
	});
	$("#contato_msg").click(function() {
	  PopUpCentralizado('http://www.esblog.com.br/pages/msg.php?id=' + $(this).attr("class"), 'perfil', '640', '480', 'yes');
	});
	$("img.dados").click(function() {
	  PopUpCentralizado('http://www.esblog.com.br/pages/perfil.php?id=' + this.title, 'perfil', '640', '480', 'yes');
	});
});