/*
window.addEvent('domready',function(){
	$$('.header span').addEvent('click', function(e){
		alert("let's go");						 
	});
	
	loadContent('newwebsite/php/news.php','bloc');
	
});

function loadContent(address,div)
{
	var options = {
			url: address, 	
			method : 'get', 
			update: $(div),
			evalScripts: true,					
			onRequest: function() {	
				$(div).innerHTML='<img src="newwebsite/gfx/loadinfo.gif" width="16px" height="16px" border="0" alt="loading" style="width:16px;height:16px;margin:5px;">';
			},									
			onSuccess: function() {	
				//$(div).fade('hide').fade('in');	
			}
		};									
	var monObjetAjax= new Request.HTML(options);
	monObjetAjax.send();
}
*/
$(document).ready(function(){
  $("#email").keyup(function(){
    var email = $("#email").val();
    if(email != 0)
    {
      if(isValidEmailAddress(email))
      {
      $("#validEmail").css({ "background-image": "url('newwebsite/gfx/validyes.png')" });
      }
      else
      {
      $("#validEmail").css({ "background-image": "url('newwebsite/gfx/validno.png')" });
      }
    }
    else
    {
      $("#validEmail").css({ "background-image": "none" });
    }
  });

  $('#send').click(function() {
    var email = $("#email").val();
    if(isValidEmailAddress(email)){
      $.ajax({
        type: 'POST',
	cache:false,
        data: decodeURIComponent($('#subscribeform').serialize()+'&emailconfirm='+email),
        url: 'http://mailinglist.2gtl.net/?p=subscribe&id=3',
        success: function(){
	  			$('#content').text('Your newsletter subscription has been registered, thank you for joining our mailing list.');
        }
      });
    }
    else
    {
      alert('Invalid email address, please check your email.');
    }
    event.preventDefault();
    return false;
  });
});

function isValidEmailAddress(emailAddress) {
  var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
  return pattern.test(emailAddress);
}
