var uploader;
var uploader2;
var war_mapcount = 0;

$(document).ready(function(){
	
	$('#login_text').hide();
	$('#login_img').click(function() {
		if ($("#login_text").is(":hidden")) {
			$('#login_text').slideDown('slow', function() {
			    // Animation complete.
				$('#login_img').attr("src", "images/login_up.jpg"); 
			});
		} else {
			$('#login_text').slideUp('slow', function() {
				// Animation complete.
				$('#login_img').attr("src", "images/login.jpg"); 
			});
		}
	});
	
	$('.squad > .pic ').click(function() {
		var id = $(this).attr("id");
		if ($("#" + id + "_slide").is(":hidden")) {
			$.ajax({
				   type: "POST",
				   url: "helper/getsquadmember.php",
				   data: "squad=" + id,
				   async: true,
				   success: function(msg){
			   			document.getElementById(id + "_slide").innerHTML = msg;
				     }
				}); 
			$("#" + id + "_slide").slideDown('slow', function() {
			    // Animation complete.
			});
		} else {
			$("#" + id + "_slide").slideUp('slow');
		}
	});
	
        $('#slider').bxSlider({
            ticker:true,
            tickerSpeed: 2500,
            tickerHover: true      
            });
        
      //Tabs
        var $edit = $('#edittabs').tabs();
    	
    	$("#news_text").cleditor({
            width:        550, // width not including margins, borders or padding
            height:       300
            });
    	
    	$("#about_text").cleditor({
            width:        550, // width not including margins, borders or padding
            height:       300
            });
    
    	$("#topic_text").cleditor({
            width:        500, // width not including margins, borders or padding
            height:       300
            });
    	
    	$("#reply_text").cleditor({
            width:        500, // width not including margins, borders or padding
            height:       300
            });
    	
    	$("#event_text").cleditor({
            width:        500, // width not including margins, borders or padding
            height:       300
            });
    	
    	$("#mov_info").cleditor({
            width:        500, // width not including margins, borders or padding
            height:       300
            });
    	
    	$("#page1_text").cleditor({
            width:        500, // width not including margins, borders or padding
            height:       350
            })
    	
 // Dialog		
 	$('#confirmDialog').dialog({
		autoOpen: false,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
			}
		}
 	});	
    	
    $('#confirmPostDialog').dialog({
    		autoOpen: false,
    		buttons: {
    			"Ok": function() {
    				$(this).dialog("close");
    			}
    		}
     });	
 	
 	$( "#confirmDialog" ).bind( "dialogclose", function(event, ui) {
		location.reload(true);
	});
 	
 	$('#confirmEditDialog').dialog({
		autoOpen: false,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
			}
		}
 	});	
 	
 	$( "#confirmEditDialog" ).bind( "dialogclose", function(event, ui) {
		location.reload(true);
	});
 	
 	$('#edit').dialog({
		autoOpen: false,
		width: 750,
		height: 510,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				var selected = $('#edittabs').tabs('option', 'selected'); // => 0
				if(selected != 4 && selected != 5) {
					//Personal information
					$.ajax({
						   type: "POST",
						   url: "helper/editpersonal.php",
						   data: "user=" + document.getElementById("user_id").value + "&title=" + encodeURIComponent(document.getElementById('title').options[document.getElementById('title').selectedIndex].value) + 
						   			"&vorname=" + encodeURIComponent(document.getElementById("vorname").value) + "&nachname=" + encodeURIComponent(document.getElementById("nachname").value) +
						   			"&gender=" + encodeURIComponent(document.getElementById("gender").options[document.getElementById("gender").selectedIndex].value) + "&bday=" + encodeURIComponent(document.getElementById("bday").value) +
						   			"&bmonth=" + encodeURIComponent(document.getElementById("bmonth").value) + "&byear=" + encodeURIComponent(document.getElementById("byear").value) +
						   			"&location=" + encodeURIComponent(document.getElementById("location").options[document.getElementById("location").selectedIndex].value) + "&homepage=" + encodeURIComponent(document.getElementById("homepage").value) +
						   			"&about_text=" + encodeURIComponent(document.getElementById("about_text").value) +
						   			"&clan=" + encodeURIComponent(document.getElementById("clanname").value) + "&irc=" + encodeURIComponent(document.getElementById("irc").value) +
						   			"&clanhist=" + encodeURIComponent(document.getElementById("clanhist").value) + "&cpu=" + encodeURIComponent(document.getElementById("cpu").value) +
						   			"&ram=" + encodeURIComponent(document.getElementById("ram").value) + "&mainboard=" + encodeURIComponent(document.getElementById("mainboard").value) +
						   			"&monitor=" + encodeURIComponent(document.getElementById("monitor").value) + "&graphic=" + encodeURIComponent(document.getElementById("graphic").value) + 
						   			"&sound=" + encodeURIComponent(document.getElementById("sound").value) + "&keyboard=" + encodeURIComponent(document.getElementById("keyboard").value) +
						   			"&mouse=" + encodeURIComponent(document.getElementById("mouse").value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmEditDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				} else if (selected == 4) {
					//Change PW
					$.ajax({
						   type: "POST",
						   url: "helper/editUserPassword.php",
						   data: "user=" + document.getElementById("user_id").value +
						   			"&curpw=" + MD5(document.getElementById("curpw").value) + "&newpw=" + MD5(document.getElementById("newpw").value) +
						   			"&newpwconfirm=" + MD5(document.getElementById("newpwconfirm").value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$( "#confirmEditDialog" ).bind( "dialogclose", function(event, ui) {
										location.href="main.html";
									});
									$('#confirmEditDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				} else if (selected == 5) {
					//Admin
					zusatz = "";
					for (i = 0; i < document.groupform.group.length; i++) {
						if(document.groupform.group[i].checked == true) {
							zusatz += document.groupform.group[i].value+"|";
						}
					}
					$.ajax({
						   type: "POST",
						   url: "helper/editUserRights.php",
						   data: "user=" + document.getElementById("user_id").value +
						   			"&newswriter=" + document.getElementById("newswrite").checked + "&newsadmin=" + document.getElementById("newsadm").checked +
						   			"&newsletteradmim=" + document.getElementById("newsletteradm").checked + "&pollsadmin=" + document.getElementById("pollsadm").checked +
						   			"&forumadmin=" + document.getElementById("forumadm").checked + "&modadmin=" + document.getElementById("modadm").checked + 
						   			"&cwsadmin=" + document.getElementById("cwsadm").checked + "&feedbackadmin=" + document.getElementById("feedbackadm").checked + 
						   			"&useradmin=" + document.getElementById("useradm").checked + "&pageadmin=" + document.getElementById("pageadm").checked +
						   			"&filesadmin=" + document.getElementById("filesadm").checked + "&cashadmin=" + document.getElementById("cashadm").checked +
						   			"&galleryadmin=" + document.getElementById("galleryadm").checked + "&serveradmin=" + document.getElementById("serveradm").checked +
						   			"&superadmin=" + document.getElementById("superadm").checked +
						   			"&groups=" + encodeURIComponent(zusatz),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmEditDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				} else {
					alert("ERROR!");
				}
				
			}
		}
 	});	
	
	$('#news_add').dialog({
		autoOpen: false,
		width: 650,
		height: 550,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				var selected = $('#edittabs').tabs('option', 'selected'); // => 0
				if(selected == 0) {
					$.ajax({
						   type: "POST",
						   url: "helper/postnews.php",
						   data: "rubric=" + encodeURIComponent(document.news_editor.rubric.options[document.news_editor.rubric.selectedIndex].value) +
						   			"&headline=" + encodeURIComponent(document.news_editor.headline.value) + "&text=" + encodeURIComponent(document.news_editor.news_text.value) +
						   			"&published=" + encodeURIComponent(document.news_editor.published.checked) + "&comment=" + encodeURIComponent(document.news_editor.comments.checked) +
						   			"&intern=" + encodeURIComponent(document.news_editor.intern.checked),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				} else if(selected == 2) {
					$.ajax({
						   type: "POST",
						   url: "helper/newsrubric.php",
						   data: "rubric=" + encodeURIComponent(document.news_rubric.rubric.options[document.news_rubric.rubric.selectedIndex].value) +
						   			"&name=" + encodeURIComponent(document.news_rubric.name.value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						});
				}
			}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
			});
	
	$('#reply_news').dialog({
		autoOpen: false,
		width: 600,
		height: 450,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/addnewsreply.php",
					   data: "news=" + encodeURIComponent(document.news_reply.newsid.value) + "&text=" + encodeURIComponent(document.news_reply.reply_text.value) + 
					   		"&poster=" + encodeURIComponent(document.news_reply.user_id.value) + "&postid=" + encodeURIComponent(document.news_reply.postid.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
								$('#confirmDialog').dialog('open');
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}
		}
	});
	
	$('#news_edit').dialog({
		autoOpen: false,
		width: 650,
		height: 550,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
					$.ajax({
						   type: "POST",
						   url: "helper/postnews.php",
						   data: "rubric=" + encodeURIComponent(document.news_editor.rubric.options[document.news_editor.rubric.selectedIndex].value) +
						   			"&headline=" + encodeURIComponent(document.news_editor.headline.value) + "&text=" + encodeURIComponent(document.news_editor.news_text.value) +
						   			"&published=" + encodeURIComponent(document.news_editor.published.checked) + "&comment=" + encodeURIComponent(document.news_editor.comments.checked) +
						   			"&intern=" + encodeURIComponent(document.news_editor.intern.checked) + "&newsID=" + encodeURIComponent(document.news_editor.newsid.value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
			}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#delete_news_posts').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				zusatz = "";
				plength = document.newschange.selposts.length;
				if (plength == undefined) {
					zusatz = document.newschange.selposts.value;
				} else {
					for (i = 0; i < document.newschange.selposts.length; i++) {
						if (document.newschange.selposts[i].checked == true) {
							zusatz += document.newschange.selposts[i].value+"|";
						}
					}
				}
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delnewsposts.php",
					   data: "ids=" + encodeURIComponent(zusatz),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.reload(true);
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#edit_squads').dialog({
		autoOpen: false,
		width: 700,
		height: 510,
		zIndex: 999,
		modal: true,
		stack: false,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				var selected = $('#edittabs').tabs('option', 'selected'); // => 0
				if(selected == 0) {
					//Add squad
					$.ajax({
						   type: "POST",
						   url: "helper/addsquad.php",		//encodeURIComponent(document.getElementById("location").options[document.getElementById("location").selectedIndex].value)
						   data: "squadname=" + encodeURIComponent(document.getElementById("name").value) + "&abbr=" + encodeURIComponent(document.getElementById("abbr").value) + "&game=" + encodeURIComponent(document.getElementById("game").options[document.getElementById("game").selectedIndex].value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmEditDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				} else if (selected == 1) {
					//Edit Squad
					$.ajax({
						   type: "POST",
						   url: "helper/editsquad.php",		//encodeURIComponent(document.getElementById("location").options[document.getElementById("location").selectedIndex].value)
						   data: "squadID=" + encodeURIComponent(document.getElementById("squad_id").options[document.getElementById("squad_id").selectedIndex].value) 
								  + "&abbr=" + encodeURIComponent(document.getElementById("editabbr").value) + "&squadname=" + encodeURIComponent(document.getElementById("editname").value) + "&game=" + encodeURIComponent(document.getElementById("editgame").options[document.getElementById("editgame").selectedIndex].value)
								   + "&sort=" + encodeURIComponent(document.getElementById("editsort").value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmEditDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				} else if (selected == 3) {
					//Add game
					$.ajax({
						   type: "POST",
						   url: "helper/addgame.php",		//encodeURIComponent(document.getElementById("location").options[document.getElementById("location").selectedIndex].value)
						   data: "gamename=" + encodeURIComponent(document.getElementById("games_name").value) + "&icon=" + encodeURIComponent(document.getElementById("game_icon").value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmEditDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				}
				
			}
		}
 	});
	
	$('#add_topic').dialog({
		autoOpen: false,
		width: 600,
		height: 450,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/addtopic.php",
					   data: "topic=" + encodeURIComponent(document.topic_add.topic.value) + "&text=" + encodeURIComponent(document.topic_add.topic_text.value) + 
					   		"&poster=" + encodeURIComponent(document.topic_add.user_id.value) + "&bID=" + encodeURIComponent(document.topic_add.bID.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
								$('#confirmDialog').dialog('open');
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}
		}
	});
	
	$('#reply_topic').dialog({
		autoOpen: false,
		width: 600,
		height: 450,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/addreply.php",
					   data: "topic=" + encodeURIComponent(document.topic_reply.topic.value) + "&text=" + encodeURIComponent(document.topic_reply.reply_text.value) + 
					   		"&poster=" + encodeURIComponent(document.topic_reply.user_id.value) + "&topicID=" + encodeURIComponent(document.topic_reply.topicID.value) +
					   		"&postid=" + encodeURIComponent(document.topic_reply.postid.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
								$('#confirmDialog').dialog('open');
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}
		}
	});
	
	$('#add_entry').dialog({
		autoOpen: false,
		width: 600,
		height: 470,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				
				if (document.add_gbentry.s3capcha != undefined) {
					for (i=0;i<5;i++){
					    if (document.add_gbentry.s3capcha[i].checked){
					    	Text=document.add_gbentry.s3capcha[i].value;
					    }
					}
				} else {
					Text = "user";
				}
				
				$.ajax({
					   type: "POST",
					   url: "helper/addgbentry.php",
					   data: "text=" + encodeURIComponent(document.add_gbentry.entry_text.value) + "&name=" + encodeURIComponent(document.add_gbentry.name.value) + 
					   	"&spam=" + encodeURIComponent(Text),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
								$('#confirmDialog').dialog('open');
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}
		}
	});
	
	$('#delete_gb').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				zusatz = "";
				for (i = 0; i < document.delposts.deleteposts.length; i++) {
					if (document.delposts.deleteposts[i].checked == true) {
						zusatz += document.delposts.deleteposts[i].value+"|";
					}
				}
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delgbentry.php",
					   data: "ids=" + enocdeURIComponent(zusatz),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.reload(true);
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#delete_topic').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/deltopic.php",
					   data: "id=" + encodeURIComponent(document.threadchange.topic.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.reload(true);
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#delete_posts').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				zusatz = "";
				plength = document.threadchange.selposts.length;
				if (plength == undefined) {
					zusatz = document.threadchange.selposts.value;
				} else {
					for (i = 0; i < document.threadchange.selposts.length; i++) {
						if (document.threadchange.selposts[i].checked == true) {
							zusatz += document.threadchange.selposts[i].value+"|";
						}
					}
				}
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delposts.php",
					   data: "ids=" + encodeURIComponent(zusatz),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.reload(true);
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#edit_forum').dialog({
		autoOpen: false,
		width: 700,
		height: 510,
		zIndex: 999,
		modal: true,
		stack: false,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				var selected = $('#edittabs').tabs('option', 'selected'); // => 0
				if(selected == 0) {
					//Category
					zusatz = "";
					for (i = 0; i < document.catform.elements['cat_read[]'].length; i++) {
						if (document.catform.elements['cat_read[]'].options[i].selected == true) {
							zusatz += document.catform.elements['cat_read[]'].options[i].value+" , ";
						}
					}

					$.ajax({
						   type: "POST",
						   url: "helper/forumcategory.php",		
						   data: "cat=" + encodeURIComponent(document.catform.category.options[document.catform.category.selectedIndex].value) + "&name=" + encodeURIComponent(document.getElementById("cat_name").value) +
						   		"&read=" + encodeURIComponent(zusatz) + "&sort=" + encodeURIComponent(document.getElementById('cat_sort').value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				} else if (selected == 1) {
					//Board
					zusatz = "";
					zusatz2 = "";
					for (i = 0; i < document.boardform.elements['board_read[]'].length; i++) {
						if (document.boardform.elements['board_read[]'].options[i].selected == true) {
							zusatz += document.boardform.elements['board_read[]'].options[i].value+" , ";
						}
					}
					for (i = 0; i < document.boardform.elements['board_write[]'].length; i++) {
						if (document.boardform.elements['board_write[]'].options[i].selected == true) {
							zusatz2 += document.boardform.elements['board_write[]'].options[i].value+" , ";
						}
					}

					$.ajax({
						   type: "POST",
						   url: "helper/forumboard.php",		
						   data: "board=" + encodeURIComponent(document.boardform.board.options[document.boardform.board.selectedIndex].value) + "&name=" + encodeURIComponent(document.getElementById("board_name").value) +
						   		"&read=" + encodeURIComponent(zusatz) + "&write=" + encodeURIComponent(zusatz2) + "&sort=" + encodeURIComponent(document.getElementById('board_sort').value) +
						   		"&cat=" + encodeURIComponent(document.boardform.board_category.options[document.boardform.board_category.selectedIndex].value) + "&info="+ encodeURIComponent(document.boardform.board_info.value) ,
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						});  
				} else if (selected == 2) {
					//Group
					$.ajax({
						   type: "POST",
						   url: "helper/forumgroup.php",		
						   data: "group=" + encodeURIComponent(document.groupform.group.options[document.groupform.group.selectedIndex].value) + "&name=" + encodeURIComponent(document.getElementById("group_name").value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						});  
				}
				
			}
		}
 	});
	
	$('#reply_war').dialog({
		autoOpen: false,
		width: 600,
		height: 450,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/addwarreply.php",
					   data: "war=" + encodeURIComponent(document.war_reply.warid.value) + "&text=" + encodeURIComponent(document.war_reply.reply_text.value) + 
					   		"&poster=" + encodeURIComponent(document.war_reply.user_id.value) + "&postid=" + encodeURIComponent(document.war_reply.postid.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
								$('#confirmDialog').dialog('open');
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}
		}
	});
	
	$('#reply_mov').dialog({
		autoOpen: false,
		width: 600,
		height: 450,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/addmovreply.php",
					   data: "movie=" + encodeURIComponent(document.mov_reply.movid.value) + "&text=" + encodeURIComponent(document.mov_reply.reply_text.value) + 
					   		"&poster=" + encodeURIComponent(document.mov_reply.user_id.value) + "&postid=" + encodeURIComponent(document.mov_reply.postid.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
								$('#confirmDialog').dialog('open');
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}
		}
	});
	
	$('#delete_mov_posts').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				zusatz = "";
				plength = document.movchange.selposts.length;
				if (plength == undefined) {
					zusatz = document.movchange.selposts.value;
				} else {
					for (i = 0; i < document.movchange.selposts.length; i++) {
						if (document.movchange.selposts[i].checked == true) {
							zusatz += document.movchange.selposts[i].value+"|";
						}
					}
				}
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delmovposts.php",
					   data: "ids=" + encodeURIComponent(zusatz),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.reload(true);
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#reply_article').dialog({
		autoOpen: false,
		width: 600,
		height: 450,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/addarticlereply.php",
					   data: "article=" + encodeURIComponent(document.article_reply.articleid.value) + "&text=" + encodeURIComponent(document.article_reply.reply_text.value) + 
					   		"&poster=" + encodeURIComponent(document.article_reply.user_id.value) + "&postid=" + encodeURIComponent(document.article_reply.postid.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
								$('#confirmPostDialog').dialog('open');
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}
		}
	});
	
	$('#delete_article_posts').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				zusatz = "";
				plength = document.articlechange.selposts.length;
				if (plength == undefined) {
					zusatz = document.articlechange.selposts.value;
				} else {
					for (i = 0; i < document.articlechange.selposts.length; i++) {
						if (document.articlechange.selposts[i].checked == true) {
							zusatz += document.articlechange.selposts[i].value+"|";
						}
					}
				}
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delarticleposts.php",
					   data: "ids=" + encodeURIComponent(zusatz),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.reload(true);
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#delete_war_posts').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				zusatz = "";
				plength = document.warchange.selposts.length;
				if (plength == undefined) {
					zusatz = document.warchange.selposts.value;
				} else {
					for (i = 0; i < document.warchange.selposts.length; i++) {
						if (document.warchange.selposts[i].checked == true) {
							zusatz += document.warchange.selposts[i].value+"|";
						}
					}
				}
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delwarposts.php",
					   data: "ids=" + encodeURIComponent(zusatz),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.reload(true);
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#add_war').dialog({
		autoOpen: false,
		width: 600,
		height: 600,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				maps = "";
				hs = "";
				os = "";
				hometeam = "";
				
				for (i = 1; i <= war_mapcount; i++) {
					maps += document.getElementById('map'+i).value+"|";
					hs += document.getElementById('homescore'+i).value+"|";
					os += document.getElementById('opposcore'+i).value+"|";
				}
				for (i = 0; i < document.war_add.elements['hometeam[]'].length; i++) {
					if (document.war_add.elements['hometeam[]'].options[i].selected == true) {
						hometeam += document.war_add.elements['hometeam[]'].options[i].value+"|";
					}
				}

				if(document.war_add.date.value == "" || document.war_add.time.value == "" || document.war_add.opponent.value == "" || document.war_add.league.value == "") {
					alert ("You did not give sufficient information to add a war.");
				} else {
					$(this).dialog("close");
					$.ajax({
						   type: "POST",
						   url: "helper/addwar.php",
						   data: "squad=" + encodeURIComponent(document.war_add.squad.options[document.war_add.squad.selectedIndex].value) + "&date=" + encodeURIComponent(document.war_add.date.value)
						   		+ "&time=" + encodeURIComponent(document.war_add.time.value) + "&opponent=" + encodeURIComponent(document.war_add.opponent.value)
						   		+ "&clantag=" + encodeURIComponent(document.war_add.clantag.value) + "&country=" + encodeURIComponent(document.war_add.country.options[document.war_add.country.selectedIndex].value)
						   		+ "&page=" + encodeURIComponent(document.war_add.page.value) + "&league=" + encodeURIComponent(document.war_add.league.value)
						   		+ "&leaguehp=" + encodeURIComponent(document.war_add.leaguehp.value) + "&matchlink=" + encodeURIComponent(document.war_add.matchlink.value)
						   		+ "&oppoteam=" + encodeURIComponent(document.war_add.oppoteam.value) + "&hometeam=" + encodeURIComponent(hometeam)
						   		+ "&maps=" + encodeURIComponent(maps) + "&hs=" + encodeURIComponent(hs) + "&os=" + encodeURIComponent(os)
						   		+ "&server=" + encodeURIComponent(document.war_add.server.value) + "&castserver=" + encodeURIComponent(document.war_add.castserver.value)
						   		+ "&castpage=" + encodeURIComponent(document.war_add.castpage.value) + "&report=" + encodeURIComponent(document.war_add.report.value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
					   				location.reload(true);
					   			} else {
									alert(msg);
								}
						     }
						}); 
				}
			}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#edit_war').dialog({
		autoOpen: false,
		width: 600,
		height: 600,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				maps = "";
				hs = "";
				os = "";
				hometeam = "";
				
				for (i = 1; i <= war_mapcount; i++) {
					maps += document.getElementById('map'+i).value+"|";
					hs += document.getElementById('homescore'+i).value+"|";
					os += document.getElementById('opposcore'+i).value+"|";
				}
				for (i = 0; i < document.war_edit.elements['hometeam[]'].length; i++) {
					if (document.war_edit.elements['hometeam[]'].options[i].selected == true) {
						hometeam += document.war_edit.elements['hometeam[]'].options[i].value+"|";
					}
				}

				if(document.war_edit.date.value == "" || document.war_edit.time.value == "" || document.war_edit.opponent.value == "" || document.war_edit.league.value == "") {
					alert ("You did not give sufficient information to edit the war.");
				} else {
					$(this).dialog("close");
					$.ajax({
						   type: "POST",
						   url: "helper/editwar.php",
						   data: "war=" + encodeURIComponent(document.war_edit.war_id.value) + "&squad=" + encodeURIComponent(document.war_edit.squad.options[document.war_edit.squad.selectedIndex].value) + "&date=" + encodeURIComponent(document.war_edit.date.value)
						   		+ "&time=" + encodeURIComponent(document.war_edit.time.value) + "&opponent=" + encodeURIComponent(document.war_edit.opponent.value)
						   		+ "&clantag=" + encodeURIComponent(document.war_edit.clantag.value) + "&country=" + encodeURIComponent(document.war_edit.country.options[document.war_edit.country.selectedIndex].value)
						   		+ "&page=" + encodeURIComponent(document.war_edit.page.value) + "&league=" + encodeURIComponent(document.war_edit.league.value)
						   		+ "&leaguehp=" + encodeURIComponent(document.war_edit.leaguehp.value) + "&matchlink=" + encodeURIComponent(document.war_edit.matchlink.value)
						   		+ "&oppoteam=" + encodeURIComponent(document.war_edit.oppoteam.value) + "&hometeam=" + encodeURIComponent(hometeam)
						   		+ "&maps=" + encodeURIComponent(maps) + "&hs=" + encodeURIComponent(hs) + "&os=" + encodeURIComponent(os)
						   		+ "&server=" + encodeURIComponent(document.war_edit.server.value) + "&castserver=" + encodeURIComponent(document.war_edit.castserver.value)
						   		+ "&castpage=" + encodeURIComponent(document.war_edit.castpage.value) + "&report=" + encodeURIComponent(document.war_edit.report.value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
					   				location.reload(true);
					   			} else {
									alert(msg);
								}
						     }
						}); 
				}
			}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#screen').dialog({
		autoOpen: false,
		width: 600,
		height: 600,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				var selected = $('#edittabs').tabs('option', 'selected'); // => 0
				if(selected == 1) {
					zusatz = "";
					slength = document.screenshots.selscreen.length;
					if (slength == undefined) {
						slength = 1;
						zusatz = document.screenshots.selscreen.value;
					} else {
						for (i = 0; i < slength; i++) {
							if (document.screenshots.selscreen[i].checked == true) {
								zusatz += document.screenshots.selscreen[i].value+"|";
							}
						}
					}

					$.ajax({
						type: "POST",
						url: "helper/delscreens.php",
						data: "war=" + encodeURIComponent(document.war_edit.war_id.value) + "&screens=" + encodeURIComponent(zusatz),
						async: false,
						success: function(msg){
								if(msg == "done") {
									location.reload(true);
								} else {
									alert(msg);
								}
						    }
					}); 
				}
			}, 
			"Cancel": function() {
				$(this).dialog("close"); 
			}
		}
	});
	
	$('#delete_news').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delnews.php",
					   data: "news=" + encodeURIComponent(document.news_editor.newsid.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.href="main.html";
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#delete_event').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delevent.php",
					   data: "event=" + encodeURIComponent(document.event.id.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.href="calendar.html";
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#delete_award').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delaward.php",
					   data: "award=" + encodeURIComponent(document.award_del.id.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.href="awards.html";
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#edit_server').dialog({
		autoOpen: false,
		width: 700,
		height: 510,
		zIndex: 999,
		modal: true,
		stack: false,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				var selected = $('#edittabs').tabs('option', 'selected'); // => 0
				if(selected == 0) {
					//Add squad
					$.ajax({
						   type: "POST",
						   url: "helper/addserver.php",		//encodeURIComponent(document.getElementById("location").options[document.getElementById("location").selectedIndex].value)
						   data: "servname=" + encodeURIComponent(document.getElementById("name").value) + "&game=" + encodeURIComponent(document.getElementById("game").options[document.getElementById("game").selectedIndex].value)
						   			+ "&ip=" + encodeURIComponent(document.getElementById("ip").value) + "&sort=" + encodeURIComponent(document.getElementById("sort").value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmEditDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				} else if (selected == 1) {
					//Edit Squad
					$.ajax({
						   type: "POST",
						   url: "helper/addserver.php",		//encodeURIComponent(document.getElementById("location").options[document.getElementById("location").selectedIndex].value)
						   data: "serverID=" + encodeURIComponent(document.getElementById("editserver").options[document.getElementById("editserver").selectedIndex].value) 
								   + "&servname=" + encodeURIComponent(document.getElementById("editname").value) + "&game=" + encodeURIComponent(document.getElementById("editgame").options[document.getElementById("editgame").selectedIndex].value)
								   + "&ip=" + encodeURIComponent(document.getElementById("editip").value) + "&sort=" + encodeURIComponent(document.getElementById("editsort").value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmEditDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				} else if (selected == 2) {
					//Add game
					$.ajax({
						   type: "POST",
						   url: "helper/delserver.php",		//encodeURIComponent(document.getElementById("location").options[document.getElementById("location").selectedIndex].value)
						   data: "serverID=" + encodeURIComponent(document.getElementById("delserver").options[document.getElementById("delserver").selectedIndex].value) ,
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmEditDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						}); 
				}
				
			}
		}
 	});
	
	$('#movie_add').dialog({
		autoOpen: false,
		width: 600,
		height: 510,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/addmovie.php",
					   data: "title=" + encodeURIComponent(document.movie.title.value) + "&link=" + encodeURIComponent(document.movie.link.value) + 
					   "&info=" + encodeURIComponent(document.movie.mov_info.value) + "&image=" + encodeURIComponent(document.movie.image.value) +
					   "&width=" + encodeURIComponent(document.movie.width.value) + "&height=" + encodeURIComponent(document.movie.height.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				$('#confirmDialog').dialog('open');
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#movie_edit').dialog({
		autoOpen: false,
		width: 600,
		height: 510,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/addmovie.php",
					   data: "movID=" + encodeURIComponent(document.movie.movID.value) + "&title=" + encodeURIComponent(document.movie.title.value) + 
					   "&link=" + encodeURIComponent(document.movie.link.value) + "&info=" + encodeURIComponent(document.movie.mov_info.value) + 
					   "&image=" + encodeURIComponent(document.movie.image.value) +
					   "&width=" + encodeURIComponent(document.movie.width.value) + "&height=" + encodeURIComponent(document.movie.height.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				$('#confirmDialog').dialog('open');
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#movie_del').dialog({
		autoOpen: false,
		width: 600,
		height: 210,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delmovie.php",
					   data: "movID=" + encodeURIComponent(document.movie.movID.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.href="movies.html";
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#confirmDialog').find('input').keypress(function(e) {
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
			$(this).parent().parent().parent().parent().find('.ui-dialog-buttonpane').find('button:first').click(); /* Assuming the first one is the action button */
			return false;
		}
	});
	
	$('#confirmEditDialog').find('input').keypress(function(e) {
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
			$(this).parent().parent().parent().parent().find('.ui-dialog-buttonpane').find('button:first').click(); /* Assuming the first one is the action button */
			return false;
		}
	});
	// Dialog Link
	$('#dialog_link').click(function(){
		$('#news_add').dialog('open');
		$('#news_text').cleditor()[0].refresh();
		return false;
		});

	$('#dialog_link').hover(
			function() { $(this).addClass('ui-state-hover'); }, 
			function() { $(this).removeClass('ui-state-hover'); }
		);
	
	$('#search_user input[name="username"]').liveSearch({url: 'helper/searchuser?username='});
	
	$("a[rel=screenshots]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	$( "#date" ).datepicker({ dateFormat: 'yy-mm-dd' });
	$( "#start" ).datepicker({ dateFormat: 'yy-mm-dd' });
	$( "#end" ).datepicker({ dateFormat: 'yy-mm-dd' });
	
	$(".mid_forum").each(function(){
		var id = $(this).attr('id');
		$(this).qtip({
		   content: {
		      url: 'helper/gettopiccontent.php',
		      data: { id:  id},
		      method: 'get'
		   },
		   position: {
		      corner: {
		         target: 'rightBottom',
		         tooltip: 'topLeft'
		      }
		   },
		   style: { 
			      name: 'dark' // Inherit from preset style
		   }
		});
	});
	
	$('#event_add').dialog({
		autoOpen: false,
		width: 650,
		height: 550,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
					$.ajax({
						   type: "POST",
						   url: "helper/postevent.php",
						   data: "name=" + encodeURIComponent(document.event.evname.value) +
						   			"&start=" + encodeURIComponent(document.event.start.value) + "&end=" + encodeURIComponent(document.event.end.value) +
						   			"&info=" + encodeURIComponent(document.event.event_text.value) ,
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						});
			}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
			});
	
	$('#award_add').dialog({
		autoOpen: false,
		width: 350,
		height: 250,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
					$.ajax({
						   type: "POST",
						   url: "helper/postaward.php",
						   data: "event=" + encodeURIComponent(document.award.event.value) +
						   			"&place=" + encodeURIComponent(document.award.place.options[document.award.place.selectedIndex].value) + "&date=" + encodeURIComponent(document.award.date.value) +
						   			"&info=" + encodeURIComponent(document.award.info.value) + "&link=" + encodeURIComponent(document.award.link.value),
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						});
			}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
			});
	
	$('#article_add').dialog({
		autoOpen: false,
		width: 700,
		height: 580,
		zIndex: 999,
		modal: true,
		stack: false,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				var amount = $('#edittabs').tabs("length");// => 0
				if(amount < 2) {
					alert("Error, too less tabs");
				} else  {
					var i = 1;
					var pages = "";
					
					while (i < amount) {
						pages += "&title"+i+"=" + encodeURIComponent(document.getElementById("headline"+i).value);
						pages += "&text"+i+"=" + encodeURIComponent(document.getElementById("page"+i+"_text").value);
						i++;
					}
					$.ajax({
						   type: "POST",
						   url: "helper/addarticle.php",		
						   data: "headline=" + encodeURIComponent(document.getElementById("headline").value) + "&rubric=" + encodeURIComponent(document.art_form.rubric.options[document.art_form.rubric.selectedIndex].value) +
						   		"&published="+ encodeURIComponent(document.art_form.published.checked) + "&head=" + encodeURIComponent(document.art_form.head.checked) + "&image=" + encodeURIComponent(document.art_form.image.value) + pages,
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						});  
				}
				
			}
		}
 	});
	
	$('#article_edit').dialog({
		autoOpen: false,
		width: 700,
		height: 580,
		zIndex: 999,
		modal: true,
		stack: false,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				var amount = $('#edittabs').tabs("length");// => 0
				if(amount < 2) {
					alert("Error, too less tabs");
				} else  {
					var i = 1;
					var pages = "";
					
					while (i < amount) {
						pages += "&title"+i+"=" + encodeURIComponent(document.getElementById("headline"+i).value);
						pages += "&text"+i+"=" + encodeURIComponent(document.getElementById("page"+i+"_text").value);
						pages += "&id"+i+"=" + encodeURIComponent(document.getElementById("page"+i+"_id").value);
						i++;
					}
					$.ajax({
						   type: "POST",
						   url: "helper/editarticle.php",		
						   data: "article=" + encodeURIComponent(document.art_form.articleID.value) + "&headline=" + encodeURIComponent(document.getElementById("headline").value) + "&rubric=" + encodeURIComponent(document.art_form.rubric.options[document.art_form.rubric.selectedIndex].value) +
						   		"&published="+ encodeURIComponent(document.art_form.published.checked) + "&head=" + encodeURIComponent(document.art_form.head.checked) + "&image=" + encodeURIComponent(document.art_form.image.value) + pages,
						   async: false,
						   success: function(msg){
					   			if(msg == "done") {
									$('#confirmDialog').dialog('open');
					   			} else {
									alert(msg);
								}
						     }
						});  
				}
				
			}
		}
 	});
	
	$('#article_pub').dialog({
		autoOpen: false,
		width: 700,
		height: 580,
		zIndex: 999,
		modal: true,
		stack: false,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
			}
		}
 	});
	
	$('#delete_article').dialog({
		autoOpen: false,
		width: 600,
		height: 120,
		zIndex: 999,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					   type: "POST",
					   url: "helper/delarticle.php",
					   data: "article=" + encodeURIComponent(document.article_del.id.value),
					   async: false,
					   success: function(msg){
				   			if(msg == "done") {
				   				location.href="articles.html";
				   			} else {
								alert(msg);
							}
					     }
					}); 
				}, 
			"Cancel": function() {
				$(this).dialog("close"); 
				} 
			}
	});
	
	$('#load_msg').dialog({
		autoOpen: false,
		zIndex: 999,
		disabled: true,
		modal: true,
		closeOnEscape: false,
		show: 'slide'
	});
	
	$('div .cal-war').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250
	});
	
	$('div .cal-event').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250
	});
	
    });


function check_nick(nick) {
	$.ajax({
   type: "GET",
   url: "checks/check_nick.php",
   data: "nick=" + nick,
   success: function(msg){
		if (msg == "ok") {
			document.getElementById("check_nick").innerHTML = "<img src='images/icons/success.png' width='14' height='14' alt='Success' /> OK";
			
		}
		else if (msg == "error") {
			document.getElementById("check_nick").innerHTML = "<img src='images/icons/fail.png' width='14' height='14' alt='Error' /> Wrong format.";
		}
		else {
			document.getElementById("check_nick").innerHTML = "<img src='images/icons/fail.png' width='14' height='14' alt='Already taken' /> Already taken.";
		}
   }
 });
}

function check_mail(mail) {
	$.ajax({
   type: "GET",
   url: "checks/check_mail.php",
   data: "mail=" + mail + "&exists=0",
   success: function(msg){
		if (msg == "ok") {
			document.getElementById("check_mail").innerHTML = "<img src='images/icons/success.png' width='14' height='14' alt='Success' /> OK";
			
		}
		else if (msg == "error" || msg == "wrong format") {
			document.getElementById("check_mail").innerHTML = "<img src='images/icons/fail.png' width='14' height='14' alt='Error' /> Wrong format.";
		}
		else {
			document.getElementById("check_mail").innerHTML = "<img src='images/icons/fail.png' width='14' height='14' alt='Already taken' /> Already taken.";
		}
   }
 });
}

function check_mail_exists(mail) {
	$.ajax({
   type: "GET",
   url: "checks/check_mail.php",
   data: "mail=" + mail + "&exists=1",
   success: function(msg){
		if (msg == "ok") {
			document.getElementById("check_mail").innerHTML = "<img src='images/icons/success.png' width='14' height='14' alt='Success' /> OK";
			
		}
		else if (msg == "error" || msg == "wrong format") {
			document.getElementById("check_mail").innerHTML = "<img src='images/icons/fail.png' width='14' height='14' alt='Error' /> Wrong format.";
		}
		else {
			document.getElementById("check_mail").innerHTML = "<img src='images/icons/fail.png' width='14' height='14' alt='Already taken' /> Unknown email adress.";
		}
   }
 });
}


function changeSub(name) {
	  document.getElementById('news').style.display = "none";
	  document.getElementById('atoon').style.display = "none";
	  document.getElementById('comm').style.display = "none";
	  document.getElementById('misc').style.display = "none";
	  
	  document.getElementById(name).style.display = "block";
}

function addBuddy(user, buddy) {
	$( "#confirmDialog" ).bind( "dialogclose", function(event, ui) {
			location.reload(true);
		});
	$.ajax({
		   type: "POST",
		   url: "helper/addbuddy.php",
		   data: "user=" + user + "&buddy=" +buddy ,
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		}); 
}

function delBuddy(user, buddy) {
	$( "#confirmDialog" ).bind( "dialogclose", function(event, ui) {
			location.reload(true);
		});
	$.ajax({
		   type: "POST",
		   url: "helper/delbuddy.php",
		   data: "user=" + user + "&buddy=" +buddy ,
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		}); 
}

function createSquadUploader(){            
    uploader = new qq.FileUploader({
        element: document.getElementById('uploadSquadPicture'),
        action: 'helper/uploadsquadpic.php',
        debug: false,
        params: {
            squadname: document.getElementById("name").value
        }
    });   
    uploader2 = new qq.FileUploader({
        element: document.getElementById('uploadSquad2Picture'),
        action: 'helper/uploadsquadpic.php',
        debug: true,
        params: {
            squadname: document.getElementById("editname").value
        } 
    });  
}

function createRubricUploader(){            
    uploader = new qq.FileUploader({
        element: document.getElementById('uploadRubricPicture'),
        action: 'helper/uploadrubricpic.php',
        debug: false,
        params: {
            rubric: 0
        }
    });    
}


     
function createProfileUploader(){            
    var uploader = new qq.FileUploader({
        element: document.getElementById('uploadUserPicture'),
        action: 'helper/uploaduserpic.php',
        debug: false,
        params: {
            userID: '{$profile.id}',
            userNICK: '{$profile.nick}'
        },
        onComplete: function(id, fileName, responseJSON){
        	location.reload(true);
        }
    });           
}

function createSquadUploader(){            
    uploader = new qq.FileUploader({
        element: document.getElementById('uploadSquadPicture'),
        action: 'helper/uploadsquadpic.php',
        debug: false,
        params: {
            squadname: document.getElementById("name").value
        }
    });   
    uploader2 = new qq.FileUploader({
        element: document.getElementById('uploadSquad2Picture'),
        action: 'helper/uploadsquadpic.php',
        debug: true,
        params: {
            squadname: document.getElementById("editname").value
        } 
    });  
}

function createWarUploader(wid){            
    var uploader = new qq.FileUploader({
        element: document.getElementById('uploadWarPicture'),
        action: 'helper/uploadwarpic.php',
        debug: false,
        params: {
            warID: wid
        },
        onComplete: function(id, fileName, responseJSON){
        	location.href="war-"+wid+"-1-1.html";
        }
    });           
}

function updateSquad() {
	var selectedSquad = document.getElementById("squad_id").options[document.getElementById("squad_id").selectedIndex].value;
	$.ajax({
		   type: "POST",
		   url: "helper/getsquad.php",		
		   data: "squadid=" + encodeURIComponent(selectedSquad),
		   async: false,
		   success: function(msg){
			    msg = msg.split("|");
	   			if(msg[0] == "done") {
					//Set Information
	   				document.getElementById("editname").value = msg[1];
	   				document.getElementById("editabbr").value = msg[4];
	   				for (i=0;i<document.getElementById('editgame').length;i++)
	   				{

	   					if (msg[2] == document.getElementById('editgame').options(i).value)
			   				{
			   				document.getElementById('editgame').options(i).selected = true;
			   				break;
			   				}
	   				}
	   				document.getElementById("editsort").value = msg[3];
	   				uploader2.setParams({
	   				   squadname: msg[1] 
	   				});
	   			} else {
					alert(msg);
				}
		     }
		});
}

function updateServer() {
	var selectedServer = document.getElementById("editserver").options[document.getElementById("editserver").selectedIndex].value;
	if (selectedServer != "") {
		$.ajax({
			   type: "POST",
			   url: "helper/getserver.php",		
			   data: "serverid=" + encodeURIComponent(selectedServer),
			   async: false,
			   success: function(msg){
				    msg = msg.split("|");
		   			if(msg[0] == "done") {
						//Set Information
		   				document.getElementById("editname").value = msg[1];
		   				for (i=0;i<document.getElementById('editgame').length;i++)
		   				{
	
		   					if (msg[2] == document.getElementById('editgame').options(i).value)
				   				{
				   				document.getElementById('editgame').options(i).selected = true;
				   				break;
				   				}
		   				}
		   				document.getElementById("editsort").value = msg[3];
		   				document.getElementById("editip").value = msg[4];
		   				uploader2.setParams({
		   				   squadname: msg[1] 
		   				});
		   			} else {
						alert(msg);
					}
			     }
			});
	}
}

function addUserToSquad(user, squadID){            
	$.ajax({
		   type: "POST",
		   url: "helper/addUserToSquad.php",
		   data: "user=" + user + "&squad=" + squadID ,
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmEditDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		});         
}

function delUserFromSquad(user, squadID){            
	$.ajax({
		   type: "POST",
		   url: "helper/delUserFromSquad.php",
		   data: "user=" + user + "&squad=" + squadID ,
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmEditDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		});         
}

function deleteSquad(squadID){            
	$.ajax({
		   type: "POST",
		   url: "helper/deleteSquad.php",
		   data: "squad=" + squadID ,
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmEditDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		});         
}

function changeThread(threadid) {
	if(document.threadchange.option.options[document.threadchange.option.selectedIndex].value == "del") {
		$('#delete_posts').dialog('open');
	} else if (document.threadchange.option.options[document.threadchange.option.selectedIndex].value == "delt") {
		$('#delete_topic').dialog('open');
	} else if (document.threadchange.option.options[document.threadchange.option.selectedIndex].value == "sticky") {
		$.ajax({
			   type: "POST",
			   url: "helper/topic_sticky.php",
			   data: "id=" + threadid,
			   async: false,
			   success: function(msg){
		   			if(msg == "done") {
						location.reload(true);
		   			} else {
						alert(msg);
					}
			     }
			});  
	} else if (document.threadchange.option.options[document.threadchange.option.selectedIndex].value == "close") {
		$.ajax({
			   type: "POST",
			   url: "helper/topic_close.php",
			   data: "id=" + threadid ,
			   async: false,
			   success: function(msg){
		   			if(msg == "done") {
						location.reload(true);
		   			} else {
						alert(msg);
					}
			     }
			});  
	}
}

function quote(id) {
	text = document.getElementById('text'+id).innerHTML.replace(/\[quote\](.*)\[\/quote\]/, "");
	document.topic_reply.reply_text.value = "[quote]"+text+"[/quote]";
	document.topic_reply.postid.value = 'none';
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully replied to the topic!</p>";
}

function edit_post(id) {
	document.topic_reply.postid.value = id;
	document.topic_reply.reply_text.value = document.getElementById('text'+id).innerHTML;
	document.topic_reply.topic.value = document.getElementById('title'+id).innerHTML;
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully edited the post!</p>";
}

function reply_post(title) {
	document.topic_reply.postid.value = 'none';
	document.topic_reply.reply_text.value = "";
	document.topic_reply.topic.value = title;
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully replied to the topic!</p>";
}


function changecat(select) {
	if(select.selectedIndex == 0) {
		//new
		document.getElementById('cat_name').value="";
		for(i = 0; i < document.catform.elements['cat_read[]'].length; i++) {
			if(i == 0) {
				document.catform.elements['cat_read[]'].options[i].selected = true;
			} else {
				document.catform.elements['cat_read[]'].options[i].selected = false;
			}
		}
		document.getElementById('cat_sort').value = "999";
	} else {
		document.getElementById('cat_name').value=select.options[select.selectedIndex].text;
		allowed = document.getElementById('cat'+select.options[select.selectedIndex].value).innerHTML;
		
		for(i = 0; i < document.catform.elements['cat_read[]'].length; i++) {
			if(allowed.indexOf(document.catform.elements['cat_read[]'].options[i].value) != -1) {
				document.catform.elements['cat_read[]'].options[i].selected = true;
			} else {
				document.catform.elements['cat_read[]'].options[i].selected = false;
			}
		}
		document.getElementById('cat_sort').value = document.getElementById('cats'+select.options[select.selectedIndex].value).innerHTML;
	}
}

function changeboard(select) {
	if(select.selectedIndex == 0) {
		//new
		document.getElementById('board_name').value="";
		document.getElementById('board_info').value="";
		for(i = 0; i < document.boardform.elements['board_read[]'].length; i++) {
			if(i == 0) {
				document.boardform.elements['board_read[]'].options[i].selected = true;
			} else {
				document.boardform.elements['board_read[]'].options[i].selected = false;
			}
		}
		for(i = 0; i < document.boardform.elements['board_write[]'].length; i++) {
			if(i == 0) {
				document.boardform.elements['board_write[]'].options[i].selected = true;
			} else {
				document.boardform.elements['board_write[]'].options[i].selected = false;
			}
		}
		document.boardform.board_category.selectedIndex = 0;
		document.getElementById('board_sort').value = "999";
	} else {
		document.getElementById('board_name').value=select.options[select.selectedIndex].text;
		document.getElementById('board_info').value=document.getElementById('boardi'+select.options[select.selectedIndex].value).innerHTML;
		allowed = document.getElementById('boardr'+select.options[select.selectedIndex].value).innerHTML;
		
		for(i = 0; i < document.boardform.elements['board_read[]'].length; i++) {
			if(allowed.indexOf(document.boardform.elements['board_read[]'].options[i].value) != -1) {
				document.boardform.elements['board_read[]'].options[i].selected = true;
			} else {
				document.boardform.elements['board_read[]'].options[i].selected = false;
			}
		}
		allowed = document.getElementById('boardw'+select.options[select.selectedIndex].value).innerHTML;
		for(i = 0; i < document.boardform.elements['board_write[]'].length; i++) {
			if(allowed.indexOf(document.boardform.elements['board_write[]'].options[i].value) != -1) {
				document.boardform.elements['board_write[]'].options[i].selected = true;
			} else {
				document.boardform.elements['board_write[]'].options[i].selected = false;
			}
		}
		for(i = 0; i < document.boardform.elements['board_category'].length; i++) {
			if(document.boardform.elements['board_category'].options[i].value == document.getElementById('boardc'+select.options[select.selectedIndex].value).innerHTML) {
				document.boardform.elements['board_category'].options[i].selected = true;
			} else {
				document.boardform.elements['board_category'].options[i].selected = false;
			}
		}
		document.getElementById('board_sort').value = document.getElementById('boards'+select.options[select.selectedIndex].value).innerHTML;
	}
}

function changegroup(select) {
	if(select.selectedIndex == 0) {
		//new
		document.getElementById('group_name').value="";
	} else {
		document.getElementById('group_name').value=select.options[select.selectedIndex].text;
	}
}

function del_forum_cat() {
	$.ajax({
		   type: "POST",
		   url: "helper/delforumcategory.php",		
		   data: "cat=" + encodeURIComponent(document.catform.category.options[document.catform.category.selectedIndex].value),
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		}); 
}

function del_forum_board() {
	$.ajax({
		   type: "POST",
		   url: "helper/delforumboard.php",		
		   data: "board=" + encodeURIComponent(document.boardform.board.options[document.boardform.board.selectedIndex].value),
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		}); 
}

function del_forum_group() {
	$.ajax({
		   type: "POST",
		   url: "helper/delforumgroup.php",		
		   data: "group=" + encodeURIComponent(document.groupform.group.options[document.groupform.group.selectedIndex].value),
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		}); 
}

function quote_war(id) {
	text = document.getElementById('text'+id).innerHTML.replace(/\[quote\](.*)\[\/quote\]/, "");
	document.war_reply.reply_text.value = "[quote]"+text+"[/quote]";
	document.war_reply.postid.value = 'none';
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully replied!</p>";
}

function edit_war_post(id) {
	document.war_reply.postid.value = id;
	document.war_reply.reply_text.value = document.getElementById('text'+id).innerHTML;
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully edited the post!</p>";
}

function reply_war_post() {
	document.war_reply.postid.value = 'none';
	document.war_reply.reply_text.value = "";
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully replied to the war!</p>";
}

function quote_news(id) {
	text = document.getElementById('text'+id).innerHTML.replace(/\[quote\](.*)\[\/quote\]/, "");
	document.news_reply.reply_text.value = "[quote]"+text+"[/quote]";
	document.news_reply.postid.value = 'none';
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully replied!</p>";
}

function edit_news_post(id) {
	document.news_reply.postid.value = id;
	document.news_reply.reply_text.value = document.getElementById('text'+id).innerHTML;
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully edited the post!</p>";
}

function reply_news_post() {
	document.news_reply.postid.value = 'none';
	document.news_reply.reply_text.value = "";
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully replied to the news!</p>";
}

function quote_mov(id) {
	text = document.getElementById('text'+id).innerHTML.replace(/\[quote\](.*)\[\/quote\]/, "");
	document.mov_reply.reply_text.value = "[quote]"+text+"[/quote]";
	document.mov_reply.postid.value = 'none';
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully replied!</p>";
}

function edit_mov_post(id) {
	document.mov_reply.postid.value = id;
	document.mov_reply.reply_text.value = document.getElementById('text'+id).innerHTML;
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully edited the post!</p>";
}

function reply_mov_post() {
	document.mov_reply.postid.value = 'none';
	document.mov_reply.reply_text.value = "";
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully replied to the movie!</p>";
}

function changeWar() {
		$('#delete_war_posts').dialog('open');
}

function changeNews() {
	$('#delete_news_posts').dialog('open');
}

function changeMov() {
	$('#delete_mov_posts').dialog('open');
}


function changeSquad(select, page) {
	index = select.selectedIndex;
	location.href = "wars-" + select.options[index].value + "-" + page + ".html";
}

function changeArticle() {
	$('#delete_article_posts').dialog('open');
}

function reply_article_post() {
	document.article_reply.postid.value = 'none';
	document.article_reply.reply_text.value = "";
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully replied to the article!</p>";
}

function quote_article(id) {
	text = document.getElementById('text'+id).innerHTML.replace(/\[quote\](.*)\[\/quote\]/, "");
	document.article_reply.reply_text.value = "[quote]"+text+"[/quote]";
	document.article_reply.postid.value = 'none';
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully replied!</p>";
}

function edit_article_post(id) {
	document.article_reply.postid.value = id;
	document.article_reply.reply_text.value = document.getElementById('text'+id).innerHTML;
	document.getElementById('confirmDialog').innerHTML = "<p>Succesfully edited the post!</p>";
}


function addRow(tableID) {
    
    war_mapcount++;
	 
    var table = document.getElementById(tableID);

    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);

    var cell1 = row.insertCell(0);
    var element1 = document.createElement("input");
    element1.type = "text";
    element1.id = "map"+war_mapcount;
    cell1.appendChild(element1);

    var cell2 = row.insertCell(1);
    var element2 = document.createElement("input");
    element2.type = "text";
    element2.size = "5";
    element2.id = "homescore"+war_mapcount;
    cell2.appendChild(element2);

    var cell3 = row.insertCell(2);
    var element3 = document.createElement("input");
    element3.type = "text";
    element3.size = "5";
    element3.id = "opposcore"+war_mapcount;
    cell3.appendChild(element3);

}

function deleteRow(tableID) {
    try {
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;

    if(rowCount > 1) {
    	table.deleteRow(rowCount-1);
    	war_mapcount--;
    }

    }catch(e) {
        alert(e);
    }
}

function setMapcount(count) {
	war_mapcount = count;
}

function fastpublish(news) {
	$.ajax({
		   type: "POST",
		   url: "helper/publishnews.php",		
		   data: "news=" + encodeURIComponent(news),
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		}); 
}

function publishArticle(news) {
	$.ajax({
		   type: "POST",
		   url: "helper/publisharticle.php",		
		   data: "article=" + encodeURIComponent(news),
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		}); 
}

function rubricChange() {
	selected = document.news_rubric.rubric.selectedIndex;
	if (selected != 0)
		document.news_rubric.name.value = document.news_rubric.rubric.options[selected].text;
	else
		document.news_rubric.name.value = "";
}

function delRubric() {
	$.ajax({
		   type: "POST",
		   url: "helper/delrubric.php",		
		   data: "rubric=" + encodeURIComponent(document.news_rubric.rubric.options[document.news_rubric.rubric.selectedIndex].value),
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
					$('#confirmDialog').dialog('open');
	   			} else {
					alert(msg);
				}
		     }
		}); 
}

function rubricInit() {
	createRubricUploader();  
	setRubricUploadParam();
}

function setRubricUploadParam() {
	uploader.setParams({
		   rubric: document.rubric_pic.rubric.options[document.rubric_pic.rubric.selectedIndex].value
		});
}

//Server functions
function stopServer(serverId) {
	//While sending show load image
	$('#load_msg').modal({
		minHeight: 400,
		modal: true,
		escClose: false,
		onOpen: function (dialog) {
		dialog.overlay.fadeIn('slow', function () {
			dialog.data.hide();
			dialog.container.fadeIn('slow', function () {
				dialog.data.slideDown('slow');
			});
		});
	}});
	
	setTimeout("stopServerAjax("+serverId+")", 3000);
}

function stopServerAjax(serverId) {
	//Send command with ajax
	$.ajax({
		   type: "POST",
		   url: "helper/stopServer.php",		
		   data: "serverId=" + encodeURIComponent(serverId),
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
	   				$.modal.close();
	   				location.reload(true);
	   			} else {
					alert(msg + "\n Plz reload the page.");
				}
		     }
		}); 
}

function startServer(serverId) {
	//While sending show load image
	$('#load_msg').modal({
		minHeight: 400,
		modal: true,
		escClose: false,
		onOpen: function (dialog) {
		dialog.overlay.fadeIn('slow', function () {
			dialog.data.hide();
			dialog.container.fadeIn('slow', function () {
				dialog.data.slideDown('slow');
			});
		});
	}});
	
	setTimeout("startServerAjax("+serverId+")", 3000);
}

function startServerAjax(serverId) {
	//Send command with ajax
	$.ajax({
		   type: "POST",
		   url: "helper/startServer.php",		
		   data: "serverId=" + encodeURIComponent(serverId),
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
	   				$.modal.close();
	   				location.reload(true);
	   			} else {
					alert(msg + "\n Plz reload the page.");
				}
		     }
		}); 
}

function rateMov(movID) {
	$('input',document.rate_mov).each(function(){
		   if(this.checked) rating = this.value;
	});
	
	//Send command with ajax
	$.ajax({
		   type: "POST",
		   url: "helper/rateMovie.php",		
		   data: "movId=" + encodeURIComponent(movID) + "&rating=" + encodeURIComponent(rating),
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
	   				location.reload(true);
	   			} else {
					alert(msg + "\n Plz reload the page.");
				}
		     }
		});
}

function rateArt(artID) {
	$('input',document.rate_art).each(function(){
		   if(this.checked) rating = this.value;
	});
	
	//Send command with ajax
	$.ajax({
		   type: "POST",
		   url: "helper/rateArticle.php",		
		   data: "artId=" + encodeURIComponent(artID) + "&rating=" + encodeURIComponent(rating),
		   async: false,
		   success: function(msg){
	   			if(msg == "done") {
	   				location.reload(true);
	   			} else {
					alert(msg + "\n Plz reload the page.");
				}
		     }
		});
}

function addArticlePage() {
	var amount = $('#edittabs').tabs("length");
	$('#edittabs').append("<div id='page" + (amount) + "' style='text-align: left'>" +
			"	<form name='page"+amount+"' action='#'>" +
			"	<input type='hidden' id='page"+amount+"_id' value='0'>" +
			"	<div style='display: table'>" +
			"		<div style='display: table-row'>" +
			"			<div style='display: table-cell; width: 150px'>" +
			"				Title:" +
			"			</div>" +
			"			<div style='display: table-cell'>" +
			"				<input type='text' id='headline"+amount+"' maxlength='255' />" +
			"			</div>" +
			"		</div>" +
			"		<div style='display: table-row'>" +
			"			<div style='display: table-cell; width: 150px'>" +
			"				Text:" +
			"			</div>" +
			"			<div style='display: table-cell'>" +
			"				<textarea id='page"+amount+"_text' rows='25# cols='60'></textarea>" +
			"			</div>" +
			"		</div>" +
			"	</div>" +
			"	</form>" +
			"</div>");
	$("#edittabs").tabs("add","#page"+(amount),"Page "+(amount));
	$("#page"+amount+"_text").cleditor({
        width:        500, // width not including margins, borders or padding
        height:       350
        })
	$("#page"+amount+"_text").cleditor()[0].refresh();
	
}
