$('#loginformsend').live('click', function() {
  var email = $('input[name=loginemail]').val();
  var pw    = $('input[name=loginpw]').val();
  if (!IsValidEmail(email) && pw != ''){
        $('#inlogdiv').append('<span id="temp">ongeldig emailadres</span>');
        $('#temp').delay(800).fadeOut(function() {
            $(this).remove();
        });
  } else {
    $.ajax({
		type: "POST",
		url: "modules/TespelduynInlog/ajax/Accountlogin.php",
		data: "email="+ email+ "&pw="+ pw,
		success: function(data){ 
            //$('#inlogdiv').append(data);			
            if(data == 1) {
                window.location = $('#loginlink').val();
            } else {
                $('#inlogdiv').append('<span id="temp">'+data+'</span>');
                $('#temp').delay(800).fadeOut(function() {
                    $(this).remove();
                });
            }
		}
	});    
  }
  
  
  
  
  return false;
});

$(document).ready(function() {
    //kijk of er info van bedrijf is.
    $('input[name=z_bedrijf]').blur(function(){
        $.ajax({
    		type: "POST",
    		url: "modules/TespelduynInlog/ajax/CheckCompany.php",
    		data: "companyname="+ $(this).val(),
    		success: function(data){ 
                //$('#inlogdiv').append(data);			
                if(data == 1) {
                    //window.location = $('#loginlink').val();
                } else {
                    alert(data);
                }
    		}
    	}); 
    });
    //kijk of email a bestaan
    $('input[name=z_mail]').blur(function(){
        $.ajax({
    		type: "POST",
    		url: "modules/TespelduynInlog/ajax/CheckAccount.php",
    		data: "mail="+ $(this).val(),
    		success: function(data){ 
                alert(data);
    		}
    	}); 
    });

//reset name for input fields with the class focus_value
    //get the title and use it as value if empty
    $('.focus_value').focus(function(){
        var current_value = $(this).attr('value');
        var current_title = $(this).attr('title');
        if(current_value == current_title) {
            $(this).val('');
        }
    }); 
    
    $('.focus_value').blur(function(){
        var current_value = $(this).attr('value');
        var current_title = $(this).attr('title');
        
        if(current_value == '') {
            $(this).attr('value', current_title);
        }
    });

});

function changefield(){
	document.getElementById("passwordbox").innerHTML = "<input id=\"loginpw\" type=\"password\" name=\"loginpw\" tabindex=\"1\"/>";
	setTimeout("document.getElementById(\"loginpw\").focus();", 10);
	
}

function IsValidEmail(email){
    var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    return filter.test(email);
}
