function signupnew()
    {
              
       
        $("#signup").validate({
            rules: {
                firstname: "required",
                lastname: "required",
                email: { required: true, email: true },
                gender: "required",
                birthyear: "required",
                state: "required",
                homepost: { required: true, number: true, minlength: 4, maxlength: 4 },
                workpost: { required: true, number: true, minlength: 4, maxlength: 4 },
                interests: "required"
            },
            messages: {
                firstname: "Please enter your first name.",
                lastname: "Please enter your last name.",
                email: {
                    required: "Please enter your email address.",
                    email: "Please enter a valid email address."
                },
                gender: "Please select your gender.",
                birthyear: "Please select your year of birth.",
                state: "Please select your state.", 
                homepost: {
                    required: "Please enter your home postcode.",
                    number: "Please only use numbers in this field.",
                    minlength: "Your postcode must consist of 4 characters.",
                    maxlength: "Your postcode must consist of 4 characters."
                },
                workpost: {
                    required: "Please enter your work postcode.",
                    number: "Please only use numbers in this field.",
                    minlength: "Your postcode must consist of 4 characters.",
                    maxlength: "Your postcode must consist of 4 characters."
                },
                interests: "Please indicate your interests."
            }
            ,
            submitHandler: function() {
                //signCompetition();                
                checkSecurity();
            }
        });      
        
    }
    function checkSecurity(){
    
        action = mesh_encode("checkSecurity");    
        action += "&security="+escape($('#security').val());  
        var param     = 'action='+action+'&x=' + (new Date()).valueOf(); 
        
        var html = $.ajax({
                type:'post',
                url: "modules/competition/callback.php",
                data: param,
                cache: false,
                async: false 
            }).responseText; 
           
        result = eval('('+html+')');
        if(result.success == 0 || result.success == 'false'){
            $("#securityCheck").html(result.errmsg);      
        }
        else{
            signCompetition();
        }    
    }
    function signCompetition(){
        var gender = '';
        var g = document.getElementsByName('gender');
        for(var j=0;j<g.length;j++){   
            if(g[j].checked){                                                     
                gender = g[j].value; 
            }
        } 
        
    
            action = mesh_encode("signupnew");
            action += "&firstname="+escape($('#firstname').val());     
            action += "&lastname="+escape($('#lastname').val());     
            action += "&email="+escape($('#email').val());     
            action += "&gender="+escape(gender);     
            action += "&birthyear="+escape($('#birthyear').val());     
            action += "&homepost="+escape($('#homepost').val());     
            action += "&workpost="+escape($('#workpost').val());     
            action += "&telephone="+escape($('#telephone').val());
            action += "&address="+escape($('#address').val());
            action += "&suburb="+escape($('#suburb').val());
            action += "&state="+escape($('#state').val());
            action += "&interests="+escape($('#hdInterests').val());
            action += "&cid="+escape($('#cid').val());
            action += "&cfid="+escape($('#cfid').val());
            
            //action += "&answer="+escape($('#answer').val());
            //action += "&cqid="+escape($('#cqid').val());
            //action += "&dura="+escape($('#dura').val());
            var cid = escape($('#cid').val());
            var ref = '';
            
            
            var param     = 'action='+action+'&x=' + (new Date()).valueOf(); 
            //alert("sssssss " + param);
            //return;
            
            var html = $.ajax({
                type:'post',
                url: "modules/competition/callback.php",
                data: param,
                cache: false,
                async: false 
            }).responseText; 
           
           result = eval('('+html+')');
            
           
            if(result.success == 0 || result.success == 'false'){
                $("#competition_x").html(result.errmsg);
            }
            else if (result.success == 1){
            	if (result.optiondata == 1){
            		common.redirectPage(html); 
            	}
            	else if (result.optiondata == 2){
            		skipSendFriend2(cid, ref);	
            	}
            }
            
            
                                                        
    }
    
    
    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 && g[i].value)
          {   
              garr.push(g[i].value);       
          }
        }
        gstr = implode(",",garr);
                 
        $('#hdInterests').val(gstr);

    }
    
    function skipSendFriend2(cid, ref){    	
    	
        
        
        var params = 'action=' + mesh_encode('custThanks2');
        params += '&cid=' + cid;
        params += '&ref=' + ref;
        params += '&x=' + (new Date()).valueOf();
        
        $.ajax({
            type: 'post',
            url: 'modules/competition/callback.php',
            data: params,
            cache: false,
            success: function(html){
                $("#competition_x").html(html);
            }
        });	
        
        
        	
    	
        
    }
    
    function skipSendFriend(cid, ref){
    	
       	var param     = 'action='+mesh_encode('custThanks')+'&cid='+cid+'&ref='+ref;
    	var check = '1';

        $.ajax({
            type:'post',
            url: "modules/competition/callback.php",
            data: param,   
            cache: false,
            success: function(html){                    
                $("#page").html(html);
                //$("#competition_x").html(html); 
                check = '0';
            }
        });	
        
        if (check == '1') {
	    	var message = '<h1>Thank you</h1><p class="subheading">Congratulations your entry has been submitted, good luck!</p><p><a href="/">Click here</a> to return.</p>';
    		$("#page").html(message);
        	$("#table-sub").fadeIn("slow");
        }
    }
    function sendfriend(){
    
        var result = $('#friend').valid();
        if(result == true){
        	var cid = escape($('#cid').val());
        	var ref = escape($('#ref').val());
        	
        	
            action = mesh_encode("sendfriend");
            action += "&name="+escape($('#name').val()); 
            action += "&email="+escape($('#email').val()); 
            action += "&cid="+cid; 
            
            action += "&name1="+escape($('#name1').val()); 
            action += "&name2="+escape($('#name2').val()); 
            action += "&name3="+escape($('#name3').val()); 
            
            action += "&email1="+escape($('#email1').val()); 
            action += "&email2="+escape($('#email2').val()); 
            action += "&email3="+escape($('#email3').val()); 
            
            action += "&message="+escape($('#message').val()); 
            action += "&ref="+ref; 
            
            var param     = 'action='+action+'&x=' + (new Date()).valueOf(); 
            //alert("sss" + param);
            //return;
        	var html = $.ajax({
                type:'post',
                url: "modules/competition/callback.php",
                data: param,
                cache: false,
                async: false 
            }).responseText; 
           
           result = eval('('+html+')');
           
            if(result.success == 0 || result.success == 'false'){               
                $("#errorMsg").html(result.errmsg);                
            }
            else{            	
            	skipSendFriend(cid, ref);
            }

        /*    
        $.ajax({
            type:'post',
            url: "modules/competition/callback.php",
            data: param,   
            cache: false,
            success: function(html){                    
                $("#page").html(html);
            }
        });	
        */
            /*
            $.ajax({
                type:'post',
                url: "modules/competition/callback.php",
                data: param,   
                cache: false,
                success: function(html){
                    $("#page").html(html);
                    $("#table-sub").fadeIn("slow");
                }
            });
            */
            
            
        }    
    }
 
