String.prototype.trim = function()
{
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

$(document).ready(function(){
					   
     $("#respostacadstro").hide(); 
	 
		$('#nome_cadastro').focus(function(){
										   
			 if($("#nome_cadastro").val().trim() == "Nome:"){
				 
				 	$("#nome_cadastro").val('');
					
				 }
											  
		 });
		
		$('#email_cadastro').focus(function(){
										   
			 if($("#email_cadastro").val().trim() == "E-mail:"){
				 
				 	$("#email_cadastro").val('');
					
				 }
											  
		 });
		
	
		
		$('.btn').click(function(){
		
			if ($("#nome_cadastro").val().trim() == "Nome:" || $("#nome_cadastro").val() == "") {
				
				$("#nome_error").attr({innerHTML: "Nome &eacute; obrigat&oacute;rio"});
				$("#nome_error").removeClass('somediv');
			
				return false;
			}
			else{
				$("#nome_error").attr({innerHTML: ""});
				$("#nome_error").addClass('somediv');
				
				}
				
				if ($("#email_cadastro").val().trim() == "E-mail:" || $("#email_cadastro").val() == "") {
				
				$("#email_error").attr({innerHTML: "E-mail &eacute; obrigat&oacute;rio"});
				$("#email_error").removeClass('somediv');
			
				return false;
			}
			else{
				$("#email_error").attr({innerHTML: ""});
				$("#email_error").addClass('somediv');
				
				}
		
			
			
			if ($("#email_cadastro").val().search("@") == -1 || $("#email_cadastro").val().search("[.*]") == -1) {
				
			$("#email_error").attr({innerHTML: "Digite um e-mail v&aacute;lido"});
			$("#email_error").removeClass('somediv');
		
			return false;
			
		  }
		  
		  else{
			  
				$("#email_error").attr({innerHTML: ""});
				$("#email_error").addClass('somediv');
			
			}
			
		
			$.post($("#url_cadastro").val(), { nomecampo:  $("#nome_cadastro").val(), emailcampo: $("#email_cadastro").val()}, 
			function(data){
				
			
				
				if (data == "existe") {
					alert('E-mail já cadastrado');
					return false;					
				}
				
				else{
					
					$("#respostacadstro").show('slow'); 
					$("#nome_cadastro").attr({value : ''});
					$("#email_cadastro").attr({value : ''});
					$("#respostacadstro").attr({innerHTML : ' Cadastro efetuado!'});
					
					}
				
			});
			
	
	});
		});
