
var confirmed = false

$(document).ready(function(){

        /* captures the submit event  */        
        $("form").submit(function(event){
            /* checks to see if there is anything in the email address feild  */
            if($("#mailemail").val().match(/^\s*$/)==null){
                /* if there is email is sent  */
                return true;
            }
            /* if false then popup is created */
            if(confirmed == false){
                $("body").append("<div id='popupBack'></div>");
                $("#popup").appendTo("body");
                $("#popup").wrap("<div id='wrapper' class='pop'></div>");
                $("#popupBack").addClass("opacitySemi");
            }
                     
            
            return confirmed;
            
        });
        
        /* clicking no then popup is removed and focus is set on the email field  */
            $(".no").click(function(){
                $("#popup").appendTo("#popupBox");
                $(".pop").remove();
                $("#popupBack").remove();
                $("#mailemail").focus();
                $("#mailemail").css({'border-color' : '#DD0000', '-moz-box-shadow' : '0 0 10px #EE0000', '-webkit-box-shadow' : '0 0 10px #EE0000'});
            });
            /* clicking yes then popup is removed and email is sent  */
            $(".yes").click(function(event){
                event.preventDefault();
                $("#popup").appendTo("#popupBox");
                $(".pop").remove();
                $("#popupBack").remove();
                confirmed = true;
                $("form").submit();
            });   
});
