    function chkEmail()
    {
        
        var email = escape($('#email').val());
        var action = 'action='+mesh_encode('chkemail')+'&email='+email;
        
         var html = $.ajax({
            type:'post',
            url: "modules/subscriber/callback.php",
            data: action,
            cache: false,
            async: false 
        }).responseText;     
        
        result = eval('('+html+')');
        try {
            if(result.success == 1 || result.success == 'true')
            {
                return true;
            }
            else{
                if(result.errmsg){
                    alert(result.errmsg);
                    $('#email').val('');
                    $('#email').focus();
                    return false;
                }
                else{
                    $('#email').val('');
                    $('#email').focus();
                    return false;
                }
            }
        } catch(e){
            $('#email').val('');
            $('#email').focus();
            return false;
        }        
        
    }    
    
    function signupNew()
    {
        /*
        if(!chkEmail()){
           return false;
        }
        */
        if($('#interests input:checked').size() != 0){
           $('#hdInterestsError').val('1');
        }
        else{
            $('#hdInterestsError').val('');
        }

		$("#signup").validate({
			messages: {
				suburb: "<font color='red'>This field is required for you to receive year round savings.</font>",
				address: "<font color='red'>This field is required for you to receive year round savings.</font>",
				state: "<font color='red'>This field is required for you to receive year round savings.</font>"
			}
		});

        var result = $("#signup").valid();

        if(result == true)
        {
            var SecCode = chkSecureCode($('#code').val());
            if(SecCode)
            {
            
                //for interests
                var g = document.getElementsByName('interests');
                var garr = new Array();
                var gstr = '';
                for(var i=0;i<g.length;i++)   
                {   
                  if(g[i].checked && g[i].value)
                  {   
                      garr.push(g[i].value);       
                  }
                }
                gstr = implode(",",garr);
                 
                         
                var action = mesh_encode('newsignup');
         
                action += '&firstname='+escape($('#firstname').val()); 
                action += '&lastname='+escape($('#lastname').val()); 
                action += '&email='+escape($('#email').val());
                action += '&gender='+escape($('#gender').val()); 
                action += '&dob=' + ($('#birthyear').val()+'-00-00'); 
                action += '&homepost=' + (($('#homepost').val()=='undefined' || !$('#homepost').val())?'':escape($('#homepost').val())); 
                action += '&workpost=' + (($('#workpost').val()=='undefined' || !$('#workpost').val())?'':escape($('#workpost').val()));
                action += '&telephone='+escape($('#telephone').val());
                action += '&address='+escape($('#address').val());
                action += '&suburb='+escape($('#suburb').val());     
                action += '&state=' + (($('#state').val()=='undefined' || !$('#state').val())?'':escape($('#state').val()));
                action += '&interests='+gstr; 
                
                var eonly = $('#eonly:checked').val(); 
                if(eonly == '1'){
                    action += '&eonly='+eonly;     
                }
                
                var param     = 'action='+action+'&x=' + (new Date()).valueOf();
                
                    $.ajax({
                            type:'post',
                            url: "modules/subscriber/callback.php",
                            data: param,   
                            cache: false,
                            success: function(html){
                                $("#table-sub").html(html);
                                $("#table-sub").fadeIn("slow");
                                }
                            });
                        
            }
            else{
                
            }                        
        }       
    }



    function unSub()
    {

        $("#fmunsub").validate({
            rules: {
                email: { required: true, email: true }
            },
            messages: {
                email: {
                    required: "<font color='red'>Please enter your email address.</font>",
                    email: "<font color='red'>Please enter a valid email address.</font>"
                }
            }
        });        
    }


    
    function getInterests()
    {
        //for groups
        var g = document.getElementsByName('interests');
        var garr = new Array();
        var gstr = '';
        for(var i=0;i<g.length;i++)   
        {   
          if(g[i].checked)
          {   
              garr.push(g[i].value);       
          }
        }
        gstr = implode(",",garr);
             
                 
        $('#hdInterests').val(gstr);
    }
    
    function chkSecureCode(val){
            var params = 'action='+mesh_encode('securecheck')+'&code='+val;
            var html = $.ajax({
                type:'post',
                url: 'modules/subscriber/callback.php',
                data: params,
                cache: false,
                async: false
            }).responseText;

            result = eval('('+html+')');
            try {
                if(result.success == 1 || result.success == 'true'){
                    return true;
                }
                else{
                    if(result.errmsg){
                        alert(result.errmsg);
                        return false;
                    }
                    else{
                        return false; 
                    }
                }
            } catch(e){
                return false; 
            } 
    }    