function signupnew(siteid)
    {
              
       
        $("#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 },
                telephone:{ required: false, number: true, minlength: 10, maxlength: 10 },
                interests: "required",
                answer: "required",
                answer_count: { required: true, number: true }
                
            },
            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."
                },
                telephone: {
                    number: "Please only use numbers in this field.",
                    minlength: "Your phone number must consist of 10 characters.",
                    maxlength: "Your phone number must consist of 10 characters."
                },
                interests: "Please indicate your interests.",
                answer_count: "You can only enter 25 words or less for this question."
                
            }
            ,
            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(){
        //interests
        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);
        //gender
        var gender = '';
        if ($('#male').attr('checked')){  
            gender = 'M';
        }
        else{
            gender = 'F';
        }
        
        //text answer if has
        var answer = $('#answer').val();  
        if (typeof answer == 'undefined'){
            answer = '';    
        }
    
        action = mesh_encode("signupnew");
        action += "&firstname="     +escape($('#firstname').val());     
        action += "&lastname="      +escape($('#lastname').val());     
        action += "&email="         +escape($('#email').val());     
        action += "&gender="        +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());
        
        //hide variables    
        action += "&cid="           +escape($('#cid').val());
        action += "&cfid="          +escape($('#cfid').val());
        action += "&answer="        +escape(answer);
        action += "&cqid="          +escape($('#cqid').val());
        action += "&dura="          +escape($('#dura').val());
    
        // survey questions
        // check questions
            var answer_check_ids = $('#answer_check_ids').val(); 
                
            var garr = new Array();
            if (typeof answer_check_ids != 'undefined'){
            
                var answer_check_id = explode(",", answer_check_ids);
                for(var i=0;i<answer_check_id.length;i++){
                    var id = answer_check_id[i] ;
                    var g = document.getElementsByName('answer_check_'+id); 
                    for(var j=0;j<g.length;j++){   
                        if(g[j].checked){                         
                            garr.push(g[j].value); 
                        }
                    }
                }
                var gstr = implode(",",garr);
                if (gstr != ''){
                    action += "&answer_check_ids="+gstr;                    
                }
            }
            
            // text questions
            var answer_txt_ids = $('#answer_txt_ids').val(); 
            if (typeof answer_txt_ids != 'undefined'){
                //action += "&answer_txt_ids="+answer_txt_ids;               
                var flag = 0;
                var answer_txt_id = explode(",", answer_txt_ids);  
                for(i=0;i<answer_txt_id.length;i++){
                    var id = answer_txt_id[i];
                    var v = $('#answer_txt_'+id).val();
                    if (v != '' && typeof v != 'undefined'){                        
                        action += "&answer_txt_"+id+"="+v;
                        flag = 1;    
                    }
                                     
                    //action += "&answer_txt_"+id+"="+$('#answer_txt_'+id).val();                     
                }
                
                if (flag == 1){
                    action += "&answer_txt_ids="+answer_txt_ids;     
                }                
            }  
           
            // radio questions
            var answer_radio_ids = $('#answer_radio_ids').val(); 
                        
            var garr = new Array(); 
            if (typeof answer_radio_ids != 'undefined'){
                var answer_radio_id = explode(",", answer_radio_ids);    
                for(var i=0;i<answer_radio_id.length;i++){
                    var id = answer_radio_id[i] ;
                    var g = document.getElementsByName('answer_radio_'+id); 
                    for(var j=0;j<g.length;j++){   
                        if(g[j].checked){                                                     
                            garr.push(g[j].value); 
                        }
                    }                    
                }
                var gstr = implode(",",garr);
                if (gstr != ''){
                    action += "&answer_radio_ids="+gstr;   
                } 
                
            }
            
        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){
            common.redirectPage(html);
            
        }                                         
    }
    
    
    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);
                common.redirectPage(html);
            }

        /*    
        $.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");
                }
            });
            */
            
            
        }    
    }
    

