	$(function(){
		
		//corrige um bug na altura 
		if ($('#box-clickon').length){
			var altura = $('#body-in').height();
			$('#box-clickon').height(altura);
		}
		
		$('#btn-clickon').click(function(e){			
			var valor = $('#coupon').val();		
			var title = $('#coupon').attr('title');
			if (valor != title){
				
				$('#msg-clickon').hide().html('');				
				
				$.post("/app/clickon/checkValidCoupon", {
					coupon : $("#coupon").val(),
					username : $("#username").val(),
					password : $("#password").val()
				}, function(data) {
					if (data.length == 0) {
						document.forms["clickon"].submit();
					} else {
						$('#msg-clickon').css('display','inline-block').html( data );
					}
				});	
			}else {
				$('#msg-clickon').css('display','inline-block').html( 'Informe o cupom.' );
			}
			e.preventDefault();
		});
		
		$('#coupon').focus(function(){
			var valor = $(this).val();
			var title = $(this).attr('title');
			if ( valor == title ) $(this).val('');			
		}).blur(function(){
			var valor = $(this).val();
			var title = $(this).attr('title');			
			if ( valor == '' ) $(this).val($(this).attr('title')); 			
		});		
	});
