$(function(){
	$('#titulo, #descricao, #descricao_2, #site, #key, #url').live('keyup', function(event){
		var valor = $(this).val(),
			id = $(this).attr('id'),
			ml = $(this).attr('maxlength'),
			tam = valor.length,
			restantes = ml - tam,
			url = $('#url').val();
			if(restantes >= 15){
				restantes = "<font color='green'>"+restantes+"</font> restantes";
			}
			if(restantes < 15 && restantes > 10){
				restantes = "<font color='orange'>"+restantes+"</font> restantes";
			}
			if(restantes <= 10 && restantes > 1){
				restantes = "<font color='red'>"+restantes+"</font> restantes";
			}
			if(restantes == 1 || restantes == 0){
				restantes = "<font color='red'>"+restantes+"</font> restante";
			}
		if(event.type == 'keyup'){
			$('*[rel="'+id+'"]').html(valor);
		}
		$('label[for="'+id+'"] .contador').html("("+restantes+")");
		$('#anuncio_pronto a, #anuncio_pronto_2 a').attr('href', url).attr('title', $('#titulo').val());
	})
	var c25 = "Apenas 25 caracteres",
		c35 = "Apenas 35 caracteres",
		virgula = "Separe as palavras por virgula",
		url = "Coloque aqui a url desejada",
		Objcss = {
			'color': '#BBB',
			'fontStyle': 'italic',
			'fontWeight': 'bold'
		};
	$('#titulo').val(c25).css(Objcss).focus(function(){
		if($(this).val() == c25){
			$(this).val("").css({
			color: '#333',
			fontStyle: 'normal',
			fontWeight: 'normal'
			});
		}else {
			
		}
	}).blur(function(){
		if($(this).val() == ""){
			$(this).val(c25).css(Objcss);
		} 
	})
	$('#descricao, #descricao_2, #site').val(c35).css(Objcss).focus(function(){
		if($(this).val() == c35){
			$(this).val("").css({
			color: '#333',
			fontStyle: 'normal',
			fontWeight: 'normal'
			});
		}else{
		
		}
	}).blur(function(){
		if($(this).val() == ""){
			$(this).val(c35).css(Objcss);
		}
	})
	$('#key').val(virgula).css(Objcss).focus(function(){
		if($(this).val() == virgula){
			$(this).val("").css({
			color: '#333',
			fontStyle: 'normal',
			fontWeight: 'normal'
			});
		}
	}).blur(function(){
		if($(this).val() == ""){
			$(this).val(virgula).css(Objcss);
		}
	})
	$('#url').val(url).css(Objcss).focus(function(){
		if($(this).val() == url){
			$(this).val("").css({
			color: '#333',
			fontStyle: 'normal',
			fontWeight: 'normal'
			});
		}
	}).blur(function(){
		if($(this).val() == ""){
			$(this).val(url).css(Objcss);
		}
	})
	$('#encomendar_link').click(function(){
		if($('#titulo').val() == c25 || $('#descricao').val() == c35 || $('#descricao_2').val() == c35 || $('#site').val() == c35 || $('#url').val() == url || $('#key').val() == virgula){
			alert("Preencha os campos antes de solicitar orçamento");
			return false;
		}
	})
});
