
   
function clubApproveClubApplications(){
    function approve(){
        var applicationsformAction = document.getElementById('applicationsform_action');
        applicationsformAction.value = "approve";
        var form = document.getElementById('applicationsform');
        form.submit();
    }
    confirmbox({msg:'Accept the selected club applications', onok: approve});
}


function clubDisapproveClubApplications(){
    function disApprove(){
        var applicationsformAction = document.getElementById('applicationsform_action');
        applicationsformAction.value = "disapprove";
        var form = document.getElementById('applicationsform');
        form.submit();
    }
    confirmbox({msg:'Reject the selected club applications', onok: disApprove});
}

function deleteClub(clubid){
    function doDelete(){
        document.location = "/community/clubmanagement?action=deleteclub&clubid="+clubid;
    }
    confirmbox({msg:'Delete club', onok: doDelete});
}

function undeleteClub(clubid){
    function doUndelete(){
        document.location = "/community/clubmanagement?action=undeleteclub&clubid="+clubid;
    }
    confirmbox({msg:'Cancel deletion', onok: doUndelete});
}


function createApplicationPaging(clubid){
    return function applicationPaging(itemIndex, itemsOnPage, isFirstCall){
        if (!isFirstCall){
            document.location = "/community/club_admin_members.jsp?clubid="+clubid+"&offset="+itemIndex;
        }
    }
}


function createMembersPaging(clubid){
    return function applicationPaging(itemIndex, itemsOnPage, isFirstCall){
        if (!isFirstCall){
            document.location = "/community/club_admin_members.jsp?clubid="+clubid+"&membersoffset="+itemIndex;
        }
    }
}
                                                                 
function changeClubMembership(accountid, role, modelname, clubid, userRole, membersoffset, accountElement){
    var account_info = accountElement.getAttribute("accountdata");
    var bodytxt = '<div class="theme4">'+buildModelNameBar(modelname, account_info, accountid, '#545454')+'</div>'+
                  '<div style="float:left;padding-right:5px;padding-bottom:7px;"><a account=\"'+account_info+
		          '\" modelname=\"'+modelname+
				  '\" class=\"avatar_mugshot_lnk\"><div>'+
				  '<b style=\"background-image:url(\'/dollservlet.png?model='+accountid+
				  '&large=1#filter\')\"></b></div></a></div>';
    bodytxt += '<div style="padding-top:7px;">';			    
    switch (role){
        case 4:
            bodytxt += '<img src="http://de408.watagame.com/images/icons/club_role_4.png" style="vertical-align: text-top;" title="Top Manager"/> Top Manager';
            break;
        case 6:
            bodytxt += '<img src="http://de408.watagame.com/images/icons/club_role_6.png" style="vertical-align: text-top;" title="Manager"/> Manager';
            break;
        case 8:
            bodytxt += '<img src="http://de408.watagame.com/images/icons/club_role_8.png" style="vertical-align: text-top;" title="Member"/> Member';
            break;
    }
    bodytxt += "</div>";
    bodytxt += "<div class=\"clear\"></div>";
    var headertxt = 'Edit club membership';

    bodytxt = bodytxt.replaceAll('\\n', '');
    headertxt = headertxt.replaceAll('\\n', '');

    var msgboxtype = MsgBoxType.CONFIRM;
    var changemembershipurl = "/community/clubmanagement?clubid="+clubid+"&accountid="+accountid+"&action=changemembership&membersoffset="+membersoffset+"&newrole=";

    bodytxt += '<table style="width:100%"><tr><td>';
    bodytxt += new Button('<nobr>Ban member</nobr>', msgboxtype.getButtonType(), {id:"msgbox_ok", width:"100px",alignment:"center", title:"Ban the member from the club and prevent her from applying for membership in the club the next 30 days!", onclick:"closeMsgBox();document.location='"+changemembershipurl+"16';"}).genButton();
    if (userRole < 4 && role!=4){
        bodytxt += "<div class=\"clear\" style=\"padding-top:7px;\"></div>"+new Button('<nobr>Set role to top manager</nobr>', msgboxtype.getButtonType(), {id:"msgbox_ok", width:"100px",alignment:"center", onclick:"closeMsgBox();document.location='"+changemembershipurl+"4';"}).genButton();
    }
    if (userRole < 6 && role!=6){
        bodytxt += "<div class=\"clear\" style=\"padding-top:7px;\"></div>"+new Button('<nobr>Set role to manager</nobr>', msgboxtype.getButtonType(), {id:"msgbox_ok", width:"100px", alignment:"center", onclick:"closeMsgBox();document.location='"+changemembershipurl+"6';"}).genButton();
    }
    if (userRole < 8 && role!=8){
        bodytxt += "<div class=\"clear\" style=\"padding-top:7px;\"></div>"+new Button('<nobr>Set role to member</nobr>', msgboxtype.getButtonType(), {id:"msgbox_ok",width:"100px", alignment:"center",onclick:"closeMsgBox();document.location='"+changemembershipurl+"8';"}).genButton();
    }
    bodytxt += '</td><td style="width:100%;" align="right" valign="bottom">';
    bodytxt += new Button('Cancel', MsgBoxType.CONFIRM.getButtonType(), {alignment:"right",width:"100px",icon:'http://de408.watagame.com/images/buttons/icons_white/cross.png#png8',onclick:"closeMsgBox();return false;"}).genButton();
    bodytxt += '</td></tr></table>';


	pushExistingMsgBoxToQueue();
    queue[0] = initmsgbox(msgboxtype, headertxt, bodytxt, "");
    showMsgBox();

    postprocess_element(document.getElementById('msgbox'));
    var msgboxBottom = document.getElementById('msgbox_bottom');

    msgboxBottom.style.height = isIE()?15:"15px"; //adjust message box
}

function initClubHome(size,lengthNewestClubs){
    var pageChanged = function(itemIndex, itemsOnPage, isFirstCallback) {
		if (!isFirstCallback) {
			loadContent(25,"&offset="+itemIndex,"target_most_active");
		}
	}
    var pageChangedNewest = function(itemIndex, itemsOnPage, isFirstCallback) {
		if (!isFirstCallback) {
			loadContent(26,"&offset="+itemIndex+"&length="+lengthNewestClubs,"target_newest");
		}
	}

    
	var pageTool = new PageTool("paging_most_active", ButtonColor.DARK_PINK, 5, pageChanged, true, 8, Math.min(80,size));
	var pageTool2 = new PageTool("paging_newest", ButtonColor.DARK_PINK, 2, pageChangedNewest, false, lengthNewestClubs, Math.min(80,size));
}

function validateClubSearch() {
    var searchQueryField = document.getElementById("search_query");
    if (searchQueryField.value.length > 0)
	{
	    var args = "&search=" + encodeURIComponent(searchQueryField.value) + "";

        var orderby = document.getElementById('search_order');
        var orderByValue = orderby.options[orderby.selectedIndex].value;
		args += "&searchOrder="+orderByValue;

		loadContent(29, args, 'search_result');
    }
}