﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

function validateName(n) {
	if ("Name" == n ||
		""     == n) 
	return false;
	
	return true;
}

function validateEmail(e) {
	if ("EMail" == e ||
		""     == e ) 
	return false;
	
	return true;
}


$(document).ready(function(){
	//global vars
    var inputBoxes = $(".text");
	var inputBox1 = $("#nl_name");
	var inputBox2 = $("#nl_email");
	var inputBox1Default = "Name";
	var inputBox2Default = "EMail";	
	
	//Effects for both inputBox
	inputBoxes.focus(function(e){
		$(this).addClass("active");
	});
	inputBoxes.blur(function(e){
		$(this).removeClass("active");
	});
		
	//inputBox2 show/hide default text if needed
	inputBox1.focus(function(){
		if($(this).attr("value") == inputBox1Default) $(this).attr("value", "");
	});
	inputBox1.blur(function(){
		if($(this).attr("value") == "") $(this).attr("value", inputBox1Default);
	});

    //inputBox2 show/hide default text if needed
	inputBox2.focus(function(){
		if($(this).attr("value") == inputBox2Default) $(this).attr("value", "");
	});
	inputBox2.blur(function(){
		if($(this).attr("value") == "") $(this).attr("value", inputBox2Default);
	});
	
	$("#nl_form").submit(function(event) {
		event.preventDefault();
  		var name = $("#nl_name").attr("value");
		var email = $("#nl_email").attr("value");
	    
		if (!validateName(name)) {
			alert("Geben sie einen Namen ein!");
			return;
		}
		
		if (!validateEmail(email)) {
			alert("Geben sie eine gültige EMailadresse ein!");
			return;
		}
		var dataString = 'name='+ name + '&email=' + email;
		//alert (dataString);return false;
		$.ajax({
      	type: "POST",
      	url: "bin/addNL.php",
      	data: dataString,
      	success: function(data) {
		$('#nl_form').html("<div id='nl_message'></div>");
        $('#nl_message').html(data)
        .hide()
        .fadeIn(1000, function() {
          $('#nl_message');
        });
      }
     });
  });

});



