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 é obrigató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 é obrigató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álido"});
			$("#email_error").removeClass('somediv');
		
			return false;
			
		  }
		  
		  else{
			$("#email_error").attr({innerHTML: ""});
			$("#email_error").addClass('somediv');
			
			}
			
		
			$.post("action_cadastro.php", { 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 com sucesso !'});
					
					}
				
			});
			
	
	});
		});
