
$(document).ready(function() {  
 	
    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = $(this).attr('href');
     
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(document).width();
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect     
        $('#mask').fadeIn(1000);    
		$('#mask').fadeTo(0,0.8);    
		
     
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
               
        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).outerHeight(true)/2);
        $(id).css('left', winW/2-$(id).outerWidth(true)/2);
     
        //transition effect
        $(id).fadeIn(2000);
		 $(window).resize(function(){
		 
		 
		 
		         var maskHeight = $(document).height();
        var maskWidth = $(document).width();
		        var winH = $(window).height();
        var winW = $(window).width();
                $('#mask').css({'width':maskWidth,'height':maskHeight});
				$(id).css('top',  winH/2-$(id).outerHeight(true)/2);
        $(id).css('left', winW/2-$(id).outerWidth(true)/2);
          });  
     
    });
     
	
	 
    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .window').hide();
    });     
     
    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    });         

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);
}
 
 $('#membersloginform').ajaxForm({url:"/members/index.php",beforeSubmit: function(){
	 $("#memberslogin #loginloader").fadeIn(0);
 },
	success: function(result) { $("#memberslogin #loginloader").fadeOut(0); if (result.replace(/[^A-Za-z]/g, "") =="success") {window.location.replace("/members/members.php");}else{$("#membersbox #msg").html("INVALID PASSCODE"); setTimeout(function(){$("#membersbox #msg").html("PLEASE ENTER PASSCODE");},3000);   } }});
 $('#mail_list').ajaxForm({url:"/php/mailinglist.php",beforeSubmit: function(){
	 var donothing = false;
	 if ($("#mail_list #name").val()=="Name" || $("#mail_list #name").val().replace(/[^A-Za-z]/g, "") =="")
	 	{  if ( $("#mail_list #nameli").html().substr($("#mail_list #nameli").html().length-1,1)!="*") { $("#mail_list #name").after("*");} donothing=true;}
	 if (!isValidEmailAddress($("#mail_list #email").val())){
		 if ( $("#mail_list #emailli").html().substr($("#mail_list #emailli").html().length-1,1)!="*") { $("#mail_list #email").after("*");}
		 donothing=true;
		 	
		 
		 }
	if (donothing) {$("#ml-message").html("Invalid fields marked"); setTimeout(function(){$("#ml-message").html("JOIN THE MAILING LIST");},3000);}
	if (donothing) return false;
	 
	 },
 	success:function(result) { if (result.replace(/[^A-Za-z]/g, "") =="success") { $("#ml-message").html("Thank You!"); 
	
		if ( $("#mail_list #nameli").html().substr($("#mail_list #nameli").html().length-1,1)=="*") { $("#mail_list #nameli").html($("#mail_list #nameli").html().substr(0,$("#mail_list #nameli").html().length-1));} 
		if ( $("#mail_list #emailli").html().substr($("#mail_list #emailli").html().length-1,1)=="*") { $("#mail_list #emailli").html($("#mail_list #emailli").html().substr(0,$("#mail_list #emailli").html().length-1));}
	
	$("#mail_list #name").val("Name"); $("#mail_list #email").val("Email");  setTimeout(function(){$("#ml-message").html("JOIN THE MAILING LIST");},3000);  } }
	});

     
});

