function Gen_SpazezLink() {

	$('spacez_link').innerHTML = "...";

	if (check_subdom($('wlspaces_link').value) != null) {
		$('spacez_link').innerHTML = "<a target='_blank' href='http://" + $('wlspaces_link').value + ".spazez.de'><img src='/images/accept.png' height=16 width=16>&nbsp;http://" + $('wlspaces_link').value + ".spazez.de</a>";
	} else {
		$('spacez_link').innerHTML = "<img src='/images/delete.png' height=16 width=16>&nbsp;Uuupppss...da stimmt was nicht.<br>Kontrolliere noch mal die Eingabe.";
	}	
}

function check_subdom(subdom) {
	var regex = new RegExp('[a-zA-Z0-9][a-zA-Z0-9._-]*');
	return regex.exec(subdom);
}

function RefreshActualBlogEntries() {

	document.getElementById("lastentries").innerHTML = "<img src=\"/images/progress_loading.gif\" height=\"16\" width=\"16\">";
	
	new Ajax.Request("/php/xmlparser_lastentries.php", {method: 'get', onSuccess: function(transport, json) { 
		
		cont_lastentries = "<ul>";
		
		for (i=0; i<json.amount; i++) {
			cont_lastentries += "<li><strong>" + json.entry_titles[i] + "</strong><br>";
			cont_lastentries += "Bisheriger Link: <a target=\"_blank\" href=\"" + json.entry_links[i] + "\">" + json.entry_links[i] + "</a><br>";
			cont_lastentries += "Neuer Link:<span style=\"margin-left:28px\"></span><input old_value=\"" + json.entry_links[i] + "\" name=\"newurl_" + i + "\" type=\"text\" style=\"width: 400px\"></li>";
		}
		
		cont_lastentries += "</ul>";

		document.getElementById("lastentries").innerHTML = cont_lastentries;
	
	} });
}

function CheckUsername() {

	document.getElementById("username_status").innerHTML = "<img src=\"/images/progress_loading.gif\" height=\"16\" width=\"16\">";
	chk_link = "/php/check_username.php?uname=" + document.getElementById("username").value;
	
	new Ajax.Request(chk_link, {method: 'get', onSuccess: function(transport, json) { 
		
		if (json.amount == 0) {
			chk_status = "<img src=\"/images/accept.png\">";
		} else {
			chk_status = "<img src=\"/images/delete.png\">";
		}
		
		document.getElementById("username_status").innerHTML = chk_status + "&nbsp;" + json.answer;
	
	} });
}

function CheckEmail() {

	document.getElementById("email_status").innerHTML = "<img src=\"/images/progress_loading.gif\" height=\"16\" width=\"16\">";
	chk_link = "/php/check_email.php?email=" + document.getElementById("email").value;
	
	new Ajax.Request(chk_link, {method: 'get', onSuccess: function(transport, json) { 
		
		if (json.amount == 0) {
			chk_status = "<img src=\"/images/accept.png\" height=\"16\" width=\"16\">";
		} else {
			chk_status = "<img src=\"/images/delete.png\" height=\"16\" width=\"16\">";
		}
		
		document.getElementById("email_status").innerHTML = chk_status + "&nbsp;" + json.answer;
	
	} });
}

function CheckPass() {

	if (document.getElementById("password").value == document.getElementById("password2").value) {
		chk_status = "<img src=\"/images/accept.png\" height=\"16\" width=\"16\">&nbsp;OK";
	} else {
		chk_status = "<img src=\"/images/delete.png\" height=\"16\" width=\"16\">&nbsp;Nicht identisch!";
	}

	document.getElementById("password_status").innerHTML = chk_status;
	
}

function GetUserImageFromSpace(van_url) {

	document.getElementById("userimage").innerHTML = "<img src=\"/images/progress_loading.gif\" height=\"16\" width=\"16\">";
	document.getElementById("age").innerHTML = "<img src=\"/images/progress_loading.gif\" height=\"16\" width=\"16\">";
	document.getElementById("gender").innerHTML = "<img src=\"/images/progress_loading.gif\" height=\"16\" width=\"16\">";

	chk_link = "/php/xmlparser_userdata.php?van_url=" + van_url;
	
	new Ajax.Request(chk_link, {method: 'get', onSuccess: function(transport, json) { 
		
		document.getElementById("userimage").innerHTML = "<img src=\"" + json.image_url + "\">";
		document.getElementById("age").innerHTML = json.age;
		document.getElementById("gender").innerHTML = json.gender;
	
	} });
}

function Set_SL_offline(i) {
	document.getElementById("status_SpazezLink_" + i).innerHTML = "<img src='/images/progress_loading.gif' height=\"16\" width=\"16\">";

	new Ajax.Request('/php/ax_sl_offon.php?status=0&id=' + i, {method: 'get', onSuccess: function(transport, json) { 
		document.getElementById("status_SpazezLink_" + json.id).innerHTML = "<a href=\"javascript:Set_SL_online(" + json.id + ");\"><img alt=\"Per Klick online schalten\" src=\"/images/spacez_link_off.png\" width=\"16\" height=\"16\"></a>";
	} });
	
}

function Set_SL_online(i) {
	document.getElementById("status_SpazezLink_" + i).innerHTML = "<img src='/images/progress_loading.gif' height=\"16\" width=\"16\">";

	new Ajax.Request('/php/ax_sl_offon.php?status=1&id=' + i, {method: 'get', onSuccess: function(transport, json) { 
		document.getElementById("status_SpazezLink_" + json.id).innerHTML = "<a href=\"javascript:Set_SL_offline(" + json.id + ");\"><img alt=\"Per Klick offline schalten\" src=\"/images/spacez_link.png\" width=\"16\" height=\"16\"></a>";
	} });
	
}

function Check_Code(i) {
	document.getElementById("status_wls_" + i).innerHTML = "<img src='/images/progress_loading.gif' height=\"16\" width=\"16\">";

	chk_link = "/php/wlspace_checkcode.php?wls_id=" + i;

	new Ajax.Request(chk_link, {method: 'get', onSuccess: function(transport, json) { 
		
		document.getElementById("status_wls_" + json.id).innerHTML = json.image;
	
	} });
}

function create_sample_url() {
	sample = "http://" + document.getElementById("wlspace").options[document.getElementById("wlspace").selectedIndex].text + ".spazez.de/" + encodeURI(document.getElementById('new_url').getAttribute('value'));
	document.getElementById("sample_url").innerHTML = "<a target=\"_blank\" href=\"" + sample + "\">" + sample + "</a>";
}

function create_sample_url_edit() {
	sample = "http://" + document.getElementById("van_url").getAttribute('value') + ".spazez.de" + encodeURI(document.getElementById('new_url').getAttribute('value'));
	document.getElementById("sample_url").innerHTML = "<a target=\"_blank\" href=\"" + sample + "\">" + sample + "</a>";
}

function check_van_url() {
	target = document.getElementById('old_url').getAttribute('value');
	
	var start = target.indexOf(":");
	if (start==-1) { start=0 } else { start=7};
	var end = target.indexOf(".");
	
	van_url = target.substring(start, end);
	boolfound = false;
	
	for (i=0; i<document.getElementById("wlspace").length; i++) {
		if (document.getElementById("wlspace").options[i].text == van_url) {
			document.getElementById("wlspace").selectedIndex = i;
			document.getElementById("wlspace_id").value = document.getElementById("wlspace").options[i].value;
			document.getElementById("new_url").disabled = false;
			document.getElementById('wrong_spacesurl').style.display = 'none';
			boolfound = true;
		}
	}
	
	if (!boolfound) {
		document.getElementById("new_url").disabled = true;
		document.getElementById('wrong_spacesurl').style.display = 'block';
	}

}

function Top5_Statistics() {

	document.getElementById("top5_statistics").innerHTML = "<table class=\"fixedTable\" style=\"width: 100%\"><tr><td><img alt=\"Bitte warten\" src=\"/images/progress_loading.gif\" width=\"16\" height=\"16\"></td></tr></table>";

	lnk = "/php/ax_topstatistics.php?amount=5";

	new Ajax.Request(lnk, {method: 'get', onSuccess: function(transport, json) { 
		
		cont = "<table class=\"fixedTable\" style=\"width: 100%\">";

		if (json.amount == 0) {
				cont += "<tr><td colspan=\"5\">" + json.comment + "</td></tr>";
		} else {
			for (i=0; i < json.amount; i++) {
				cont += "<tr><td style=\"width: 20px\">" + json.icon[i] + "</td>";
				cont += "<td style=\"width: 50px\">" + json.count[i] + "</td>";
				cont += "<td style=\"width: 50%\"><a target=\"_blank\" href=\"" + json.SpazezLink_url[i] + "\">" + json.SpazezLink[i] + "</a></td>";
				cont += "<td style=\"width: 50%\">" + json.referrer[i] + "</td>";
				cont += "<td style=\"width: 125px\">" + json.timestamp[i] + "</td></tr>";
			}
		}

		cont += "</table>";
		document.getElementById("top5_statistics").innerHTML = cont;
	
	} });

}

function AX_RecentSpazezLinksVisited() {
	document.getElementById("content_RecentSpazezLinksVisited").innerHTML = "<img src='/images/progress_loading.gif' height=\"16\" width=\"16\">";

	new Ajax.Request("/php/ax_recentslsvisited.php?amount=5", {method: 'get', onSuccess: function(transport, json) { 
		
		cont = "<table style=\"width: 100%\">";

		for (i=0; i < json.amount; i++) {
			cont += "<tr><td style=\"width: 20px\">" + json.icons[i] + "</td>";
			cont += "<td>" + json.SpazezLinks[i] + "</td></tr>";
		}

		cont += "</table>";
		document.getElementById("content_RecentSpazezLinksVisited").innerHTML = cont;
	
	} });

}

function AX_MyRecentSpazezLinksVisited() {
	document.getElementById("content_MyRecentSpazezLinksVisited").innerHTML = "<img src='/images/progress_loading.gif' height=\"16\" width=\"16\">";

	new Ajax.Request("/php/ax_myrecentslsvisited.php?amount=5", {method: 'get', onSuccess: function(transport, json) { 
		
		cont = "<table style=\"width: 100%\">";

		for (i=0; i < json.amount; i++) {
			cont += "<tr><td style=\"width: 20px\">" + json.icons[i] + "</td>";
			cont += "<td>" + json.SpazezLinks[i] + "</td></tr>";
		}

		cont += "</table>";
		document.getElementById("content_MyRecentSpazezLinksVisited").innerHTML = cont;
	
	} });

}

function AX_LatestMembers() {
	document.getElementById("content_LatestMembers").innerHTML = "<img src='/images/progress_loading.gif' height=\"16\" width=\"16\">";

	new Ajax.Request("/php/ax_latestmembers.php?amount=5", {method: 'get', onSuccess: function(transport, json) { 
		
		cont = "<table style=\"width: 100%\">";

		for (i=0; i < json.amount; i++) {
			cont += "<tr><td style=\"width: 20px\">" + json.icons[i] + "</td>";
			cont += "<td>" + json.members[i] + "</td></tr>";
		}

		cont += "</table>";
		document.getElementById("content_LatestMembers").innerHTML = cont;
	
	} });
}

function AX_PublicSwitch(f) {
	document.getElementById('public_' + f).innerHTML = "<img src='/images/progress_loading.gif' height=\"16\" width=\"16\">";

	new Ajax.Request("/php/ax_publicswitch.php?field=" + f, {method: 'get', onSuccess: function(transport, json) { 
		
		document.getElementById(json.field).innerHTML = '<img src=\"/images/group' + json.status + '.png\" width=\"16\" height=\"16\">';
	
	} });

}

function AX_MyRecentVisitors() {

}

function AX_RecentComments() {
	document.getElementById("comments").innerHTML = "<img src='/images/progress_loading.gif' height=\"16\" width=\"16\">";

	new Ajax.Request("/php/ax_recentcomments.php?amount=5", {method: 'get', onSuccess: function(transport, json) { 
		
		cont="";
		for (i=0; i < json.amount; i++) {
			cont += "<li><a title=\"" + json.unames[i] + "\" href=\"/php/viewprofile.php?id=" + json.uids[i] + "\"><img alt=\"" + json.unames[i] + "\" src=\"/images/user" + json.ugenders[i] + ".png\" width=\"16\" height=\"16\">&nbsp;" + json.comments[i] + "</li>";
		}

		document.getElementById("comments").innerHTML = cont;
	
	} });
}

function AX_GetActualSpaces(market) {

	document.getElementById("pre_lang").innerHTML = document.getElementById("cont_" + market).innerHTML;
	document.getElementById("pre_lang_refresh").onclick = new Function("AX_GetActualSpaces('" + market + "');");;
	Effect.BlindUp(document.getElementById('lang'));
	
	document.getElementById("directory").innerHTML = "<img src='/images/progress_loading.gif' height=\"16\" width=\"16\">&nbsp;Einen kleinen Moment Geduld bitte...";

	link = "/php/ax_getactualspaces.php?amount=100&mkt=" + market;
	new Ajax.Request(link, {method: 'get', onSuccess: function(transport, json) { 
		
		cont = "<table style=\"width: 100%\" cellspacing=\"5\"><tr>";
		j=0;

		for (i=0; i < json.amount; i++) {

			if (j < 4) {
				j++;
			} else {
				j=1;
				cont += "</tr><tr>";
			}

			cont += "<td valign=\"top\" style=\"text-align: center\"><a title=\"" + json.spaces_names[i] + "\" href=\"" + json.spaces_links[i] + "\"><img alt=\"" + json.spaces_names[i] + "\" src=\"/php/ax_getspaceimage.php?url=" + json.spaces_links[i] + "\" width=\"64\" height=\"64\"></a>&nbsp;<a title=\"RSS-Feed\" href=\"" + json.spaces_feeds[i] + "\"><img src=\"/images/feed.png\" width=\"16\" height=\"16\"></a><br /><a title=\"" + json.spaces_names[i] + "\" href=\"" + json.spaces_links[i] + "\">" + json.spaces_names[i] + "</a></td>";

		}
		cont += "</tr></table>";

		document.getElementById("directory").innerHTML = cont;
		SNAP_COM.shot.Rescan();
		
	} });
}