Kashub's Code Barn - "cos"

podświetlone jako plsql (dodał(a) Cossack @ 2009-03-24 18:50:35)

Twoja wyszukiwarka
T-Mobile
Podświetl ten kod w:
Ostatnio dodane:
Losowe wpisy:
var timeDiff = NULL;
var timeStart = NULL;
 
// Mausposition
var mx = 0;
var my = 0;
 
var resis = NEW Object();
var timers = NEW ARRAY();
 
IF(document.addEventListener)
	document.addEventListener("mousemove", watchMouse, TRUE);
ELSE
	document.onmousemove = watchMouse;
 
FUNCTION watchMouse(e) {
	IF(e) {
		mx = e.clientX;
		my = e.clientY;
	}
	ELSE {
		mx = window.event.clientX;
		my = window.event.clientY;
	}
 
	var info = document.getElementById("info");
	IF(info != NULL && info.style.visibility == "visible") {
		map_move();
	}
}
 
/**
 * Title-Tag setzen
 */
FUNCTION setImageTitles() {
	//var imgs = fetch_tags(document, 'img');
	FOR (var i = 0; i < document.images.LENGTH; i++)
	{
		var image = document.images[i];
		IF (!image.title && image.alt != '')
		{
			image.title = image.alt;
		}
	}
}
 
FUNCTION setCookie(name, VALUE) {
	document.cookie = name+"="+VALUE;
}
 
FUNCTION popup(url, width, height) {
	wnd = window.OPEN(url, "popup", "width="+width + ",height="+height + ",left=150,top=150,resizable=yes");
	wnd.focus();
}
 
FUNCTION popup_scroll(url, width, height) {
	wnd = window.OPEN(url, "popup", "width="+width + ",height="+height + ",left=150,top=100,resizable=yes,scrollbars=yes");
	wnd.focus();
}
 
 
FUNCTION addTimer(element, endTime, reload) {
	var timer = NEW Object();
	timer['element'] = element;
	timer['endTime'] = endTime;
	timer['reload'] = reload;
	timers.push(timer);
}
 
FUNCTION startTimer() {
	var serverTime = getTime(document.getElementById("serverTime"));
	timeDiff = serverTime-getLocalTime();
	timeStart = serverTime;
 
	// Nach span mit der Klasse timer und timer_replace suchen
	var spans = document.getElementsByTagName("span");
	FOR(var i=0; i<spans.LENGTH; i++) {
		var span = spans[i];
		IF(span.className == "timer" || span.className == "timer_replace") {
			startTime = getTime(span);
			IF(startTime != -1)
				addTimer(span, serverTime+startTime, (span.className == "timer"));
		}
	}
 
	startResTicker('wood');
	startResTicker('stone');
	startResTicker('iron');
 
	window.setInterval("tick()", 1000);
}
 
FUNCTION startResTicker(resName) {
	var element = document.getElementById(resName);
	var START = parseInt(element.firstChild.nodeValue);
	var MAX = parseInt(document.getElementById("storage").firstChild.nodeValue);
	var prod = element.title/3600;
 
	var res = NEW Object();
	res['name'] = resName;
	res['start'] = START;
	res['max'] = MAX;
	res['prod'] = prod;
	resis[resName] = res;
}
 
FUNCTION tickRes(res) {
	var resName = res['name'];
	var START = res['start'];
	var MAX = res['max'];
	var prod = res['prod'];
 
	var now = NEW DATE();
	var TIME = (now.getTime()/1000+timeDiff)-timeStart;
	var CURRENT = Math.MIN(Math.FLOOR(START+prod*TIME), MAX);
	var element = document.getElementById(resName);
	element.firstChild.nodeValue = CURRENT;
 
	IF(CURRENT == MAX) {
		element.setAttribute('class', 'warn');
	}
}
 
FUNCTION tick() {
	tickTime();
	FOR(var res IN resis) {
		tickRes(resis[res]);
	}
	FOR(var timer=0;timer<timers.LENGTH;timer++){
		var remove = tickTimer(timers[timer]);
		IF(remove) {
			timers.splice(timer, 1);
		}
	}
}
 
FUNCTION tickTime() {
	var serverTime = document.getElementById("serverTime");
	IF(serverTime != NULL) {
		var TIME = getLocalTime()+timeDiff;
		formatTime(serverTime, TIME, TRUE);
	}
}
 
FUNCTION tickTimer(timer) {
	var TIME = timer['endTime']-(getLocalTime()+timeDiff);
 
	IF(timer['reload'] && TIME < 0) {
		document.location.href = document.location.href.REPLACE(/action=\w*/, '');
		formatTime(timer['element'], 0, FALSE);
		RETURN TRUE;
	}
 
	IF (!timer['reload'] && TIME <= 0)
	{
		// Timer ausblenden und Alternativ-Text anzeigen
		var parent = timer['element'].parentNode;
		parent.nextSibling.style.display = 'inline'; // Nachfolger des Parent einblenden
		parent.parentNode.removeChild(parent); // Parent entfernen
 
		RETURN TRUE;
	}
 
	formatTime(timer['element'], TIME, FALSE);
	RETURN FALSE;
}
 
FUNCTION getLocalTime() {
	var now = NEW DATE();
	RETURN Math.FLOOR(now.getTime()/1000)
}
 
FUNCTION getTime(element) {
	// Zeit auslesen
	IF(element.firstChild.nodeValue == NULL) RETURN -1;
	var part = element.firstChild.nodeValue.split(":");
 
	// Führende Nullen entfernen
	FOR(var j=1; j<3; j++) {
		IF(part[j].charAt(0) == "0")
			part[j] = part[j].substring(1, part[j].LENGTH);
	}
 
	// Zusammenfassen
	var hours = parseInt(part[0]);
	var minutes = parseInt(part[1]);
	var seconds = parseInt(part[2]);
	var TIME = hours*60*60+minutes*60+seconds;
	RETURN TIME;
}
 
FUNCTION formatTime(element, TIME, clamp) {
	// Wieder aufsplitten
	var hours = Math.FLOOR(TIME/3600);
	IF(clamp) hours = hours%24;
	var minutes = Math.FLOOR(TIME/60) % 60;
	var seconds = TIME % 60;
 
	var timeString = hours + ":";
	IF(minutes < 10)
		timeString += "0";
	timeString += minutes + ":";
	IF(seconds < 10)
		timeString += "0";
	timeString += seconds;
 
	element.firstChild.nodeValue = timeString;
 
	IF(timeString == '0:00:00') {
		incrementDate();
	}
}
 
FUNCTION incrementDate() {
	currentDate = gid('serverDate').firstChild.nodeValue;
	splitDate = currentDate.split('/');
 
	DATE = splitDate[0];
	MONTH = splitDate[1] - 1;
	YEAR = splitDate[2];
 
	dateObject = NEW DATE(YEAR, MONTH, DATE);
	dateObject.setDate(dateObject.getDate()+1);
 
	dateString = '';
 
	DATE = dateObject.getDate();
	MONTH = dateObject.getMonth() + 1;
	YEAR = dateObject.getFullYear();
 
	IF(DATE < 10)
		dateString += "0";
	dateString += DATE + "/";
	IF(MONTH < 10)
		dateString += "0";
	dateString += MONTH + "/";
	dateString += YEAR;
 
 
	gid('serverDate').firstChild.nodeValue=dateString;
 
 
}
 
FUNCTION selectAll(form, checked) {
	FOR(var i=0; i<form.LENGTH; i++) {
		form.elements[i].checked = checked;
	}
}
 
/**
 * Im Adelshof für alle Dörfer Nichts/Maximum auswählen
 */
var MAX = TRUE;
FUNCTION selectAllMax(form, textMax, textNothing) {
	FOR(var i=0; i<form.LENGTH; i++) {
		var SELECT = form.elements[i];
		IF(SELECT.selectedIndex != NULL) {
			IF(MAX)
				SELECT.selectedIndex = SELECT.length-2;
			ELSE
				SELECT.VALUE = 0;
		}
	}
 
	MAX = MAX ? FALSE : TRUE;
 
	anchor = document.getElementById('select_anchor_top');
	anchor.firstChild.nodeValue = MAX ? textMax : textNothing;
	anchor = document.getElementById('select_anchor_bottom');
	anchor.firstChild.nodeValue = MAX ? textMax : textNothing;
 
	changeBunches(form);
}
 
FUNCTION changeBunches(form) {
	var SUM = 0;
	FOR(var i=0; i<form.LENGTH; i++) {
		var SELECT = form.elements[i];
		IF(SELECT.selectedIndex != NULL) {
			SUM += parseInt(SELECT.VALUE);
		}
	}
 
	setText(gid('selectedBunches_bottom'), SUM);
	setText(gid('selectedBunches_top'), SUM);
}
 
FUNCTION redir(href) {
	window.location.href = href;
}
 
FUNCTION setText(element, text) {
	var textNode = document.createTextNode(text);
	element.removeChild(element.firstChild);
	element.appendChild(textNode);
}
 
var old_extra_text = NULL;
var extra_info_timeout = NULL;
var map_info_data = NEW Object();
FUNCTION map_popup(title, bonus_image, bonus_text, points, owner, ally, village_groups, moral, village_id, source_id, last_attack_date, last_attack_dot, last_attack_max_loot) {
	setText(gid("info_title"), title);
 
	var info_bonus_image = gid("info_bonus_image");
	var info_bonus_text = gid("info_bonus_text");
	IF(bonus_image != '') {
		info_bonus_image.firstChild.src = bonus_image;
		info_bonus_text.firstChild.firstChild.innerHTML = bonus_text;
		info_bonus_image.style.display = '';
		info_bonus_text.style.display = '';
	}
	ELSE {
		info_bonus_image.style.display = 'none';
		info_bonus_text.style.display = 'none';
	}
 
	setText(gid("info_points"), points);
	IF(owner != NULL) {
		setText(gid("info_owner"), owner);
		gid("info_owner_row").style.display = '';
		gid("info_left_row").style.display = 'none';
	}
	ELSE {
		gid("info_owner_row").style.display = 'none';
		gid("info_left_row").style.display = '';
	}
 
	IF(ally != NULL) {
		gid("info_ally_row").style.display = '';
		setText(gid("info_ally"), ally);
	}
	ELSE {
		gid("info_ally_row").style.display = 'none';
	}
 
	IF(village_groups) {
		gid("info_village_groups_row").style.display = '';
		setText(gid("info_village_groups"), village_groups);
	} ELSE {
		gid("info_village_groups_row").style.display = 'none';
	}
 
	IF(moral && gid('map_popup_moral') && gid('map_popup_moral').checked) {
		gid("info_moral_row").style.display = '';
		setText(gid("info_moral"), moral + '%');
	} ELSE {
		gid("info_moral_row").style.display = 'none';
	}
 
	IF(last_attack_date && last_attack_dot) {
		gid("info_last_attack_row").style.display = '';
		IF (last_attack_max_loot) {
			gid("info_last_attack").innerHTML = '<img alt="" src="graphic/' + last_attack_dot + '" /> <img alt="" src="graphic/' + last_attack_max_loot + '" /> ' + last_attack_date;
		} ELSE {
			gid("info_last_attack").innerHTML = '<img alt="" src="graphic/' + last_attack_dot + '" /> ' + last_attack_date;
		}
	} ELSE {
		gid("info_last_attack_row").style.display = 'none';
	}
 
	var show_info = village_id != FALSE &&
		(gid('map_popup_res').checked ||
		gid('map_popup_pop').checked ||
		gid('map_popup_trader').checked ||
		gid('map_popup_units').checked ||
		gid('map_popup_units_times').checked);
 
	IF(show_info) {
		gid('info_extra_info').style.display = '';
		IF(old_extra_text == NULL) {
			old_extra_text = gid('info_extra_info').firstChild.firstChild.nodeValue;
		} ELSE {
			gid('info_extra_info').firstChild.innerHTML = old_extra_text;
		}
		IF(map_info_data[village_id] == NULL) {
			extra_info_timeout = window.setTimeout("map_info_get(" + village_id + ", " + source_id + ")", 500);
		} ELSE {
			map_info(village_id);
		}
 
	} ELSE {
		gid('info_extra_info').style.display = 'none';
	}
 
	map_move();
	var info = gid("info");
	info.style.visibility = "visible";
}
 
FUNCTION map_kill() {
	var info = document.getElementById("info");
	info.style.visibility = "hidden";
	IF(extra_info_timeout != NULL) {
		window.clearTimeout(extra_info_timeout);
	}
}
 
FUNCTION map_move() {
	var info_content = $("info_content"); // gid() nicht möglich, da sonst IE7 kein Element zurück gibt.
	var info = $("info");
 
	IF(window.pageYOffset)
		scrollY = window.pageYOffset;
	ELSE
		scrollY = document.BODY.scrollTop;
 
	// Sicherstellen, dass Popup nicht vom rechten Rand abgeschnitten wird
	var popup_size = info_content.getCoordinates();
	var window_width = window.getWidth();
	// getWidth funktioniert im IE6 nur wenn XHTML strict
	IF(!window_width){
		window_width = document.BODY.clientWidth;
	}
	var margin_right = window_width - mx;
 
	IF(margin_right > popup_size.width + 5) {
		info.style.left = mx + 5 + "px";
	} ELSE {
		info.style.left = window_width - popup_size.width + "px";
	}
 
	// Unterer Rand des Popups soll nicht Mauszeiger überlappen
	var popup_top =  my - popup_size.height - 5 + scrollY;
	info.style.top = popup_top + "px";
}
 
FUNCTION map_info_get(village_id, source_id)
{
	var url = 'game.php?screen=overview&xml&village=' + village_id + '&source=' + source_id;
	var t = get_sitter_player()
	IF(t) {
		url = url + '&t=' + t;
	}
 
	var map_info_callback = NEW Object();
	map_info_callback.complete = FUNCTION(req) {
		var village_data = NEW Object();
		var village = req.responseXML.firstChild;
		WHILE (village != NULL && village.nodeType != 1) {
			village = village.nextSibling;
		}
		IF(village.firstChild.nodeName == 'error') {
			var error = village.firstChild.nodeValue;
			alert(error);
		}
		village_data['id'] = parseInt(village.getAttribute('id'));
		FOR(var i = 0; i < village.childNodes.LENGTH; i++) {
			village_data[village.childNodes[i].nodeName] = village.childNodes[i].firstChild.nodeValue;
		}
		map_info_data[village_data['id']] = village_data;
		map_info(village_data['id']);
	}
 
	ajaxAsync(url, NULL, map_info_callback);
}
 
FUNCTION map_info(village_id)
{
	var village_data = map_info_data[village_id];
	var xhtml = '<table>';
 
	// Rohstoffe
	IF(gid('map_popup_res').checked && (village_data['wood'] || village_data['stone'] || village_data['iron'] || village_data['storage_max'])) {
		xhtml += '<tr><td colspan="2"><table><tr>';
		IF (village_data['wood']) xhtml += '<td><img src="' + image_base + '/holz.png" />' + village_data['wood'] + '</td>';
		IF (village_data['stone']) xhtml += '<td><img src="' + image_base + '/lehm.png" />' + village_data['stone'] + '</td>';
		IF (village_data['iron']) xhtml += '<td><img src="' + image_base + '/eisen.png" />' + village_data['iron'] + '</td>';
		IF (village_data['storage_max']) xhtml += '<td><img src="' + image_base + '/res.png" />' + village_data['storage_max'] + '</td>';
		xhtml += '</tr></table></td></tr>';
	}
 
 
	var pop_xhtml = FALSE;
	IF(gid('map_popup_pop').checked && village_data['pop_max']) {
		pop_xhtml = '<img src="' + image_base + '/face.png" />' + village_data['pop'] + '/' + village_data['pop_max'];
	}
 
	var trader_xhtml = FALSE;
	IF(gid('map_popup_trader').checked && village_data['trader_current']) {
		trader_xhtml = '<img src="' + image_base + '/overview/trader.png" />' + village_data['trader_current'] + '/' + village_data['trader_total'];
	}
 
	// Bevölkerung und Haendler
	IF(pop_xhtml || trader_xhtml) {
		xhtml += '<tr><td colspan="2"><table><tr>';
		xhtml += xhtml_column_builder(pop_xhtml, trader_xhtml);
		xhtml += '</tr></table></td></tr>';
	}
 
	IF(gid('map_popup_units').checked || gid('map_popup_units_times').checked) {
		uh_xhtml = '<tr><td colspan="2"><table style="border:1px solid #DED3B9" cellpadding="0" cellspacing="0"><tr class="center">';
		var i=0;
		FOR(var prop IN village_data) {
			IF((prop.SUBSTR(0, 4) == 'unit') && ((village_data[prop] != 0) || (gid('map_popup_units_times').checked && village_data['time_'+prop]))) {
				var bgcolor = ((i%2) == 0) ? 'F8F4E8' : 'DED3B9';
				uh_xhtml += '<td style="padding:2px;background-color:#'+bgcolor+'"><img src="' + image_base + '/unit/' + prop + '.png" alt="" /></td>';
				i++;
			}
		}
 
		i=0;
		units=0;
		un_xhtml='';
 
		FOR(var prop IN village_data) {
			IF(prop.SUBSTR(0, 4) == 'unit' && village_data[prop] != 0 && gid('map_popup_units').checked) {
				var bgcolor = ((i%2) == 0) ? 'F8F4E8' : 'DED3B9';
				un_xhtml += '<td style="padding:2px;background-color:#'+bgcolor+'">'+village_data[prop]+'</td>';
				i++;
				units++;
			} ELSE IF (gid('map_popup_units_times').checked && village_data['time_'+prop]) {
				var bgcolor = ((i%2) == 0) ? 'F8F4E8' : 'DED3B9';
				un_xhtml += '<td style="padding:2px;background-color:#'+bgcolor+'">&#160;</td>';
				i++;
			}
		}
 
		i=0;
		times=0;
		ut_xhtml='';
 
		IF(gid('map_popup_units_times').checked) {
			FOR(var prop IN village_data) {
				IF(prop.SUBSTR(0, 9) == 'time_unit' && village_data[prop] != 0) {
					var bgcolor = ((i%2) == 0) ? 'F8F4E8' : 'DED3B9';
					ut_xhtml += '<td style="padding:2px;font-size: 9px;background-color:#'+bgcolor+'">' + village_data[prop] +'</td>';
					i++;
					times++;
				}
			}
		}
 
		IF (units > 0 || times > 0) {
			xhtml += uh_xhtml;
 
			IF (units > 0) {
				xhtml += '</tr><tr class="center">';
				xhtml += un_xhtml;
			}
 
			IF (times	> 0) {
				xhtml += '</tr><tr class="center">';
				xhtml += ut_xhtml;
			}
			xhtml += '</tr></table></tr></td></tr>';
		}
	}
	xhtml += '</table>';
	gid('info_extra_info').firstChild.innerHTML = xhtml;
	map_move();
}
 
FUNCTION xhtml_column_builder(col1, col2) {
	var xhtml = '';
	xhtml += '<tr>';
	IF(col1 && col2) {
		xhtml += '<td>' + col1 + '</td><td>' + col2 + '</td>';
	} ELSE {
		IF(col1) {
			xhtml += '<td colspan="2">' + col1 + '</td>';
		} ELSE {
			xhtml += '<td colspan="2">' + col2 + '</td>';
		}
	}
	xhtml += '</tr>';
	RETURN xhtml;
}
 
FUNCTION toggle_map_popup_options() {
	IF(gid('map_popup_options').style.display == 'none') {
		gid('map_popup_options').style.display = '';
	} ELSE {
		gid('map_popup_options').style.display = 'none';
	}
}
 
FUNCTION gid(id) {
	RETURN document.getElementById(id);
}
 
FUNCTION mapScroll(x, y) {
	width = 10;
	height = 10;
	url = "map.php?x="+x+"&y="+y+"&width="+width+"&height="+height;
	req = ajaxSync(url);
	villages = req.responseXML.firstChild.childNodes;
	FOR(var i=0; i<villages.LENGTH; i++) {
		v = villages[i];
		IF(v.nodeType != 1) continue;
		IF(v.nodeName != "v") continue;
 
		mapSetTile(3, 0, v);
	}
}
 
FUNCTION mapSetTile(x, y, v) {
	tile = gid("tile_" + x + "_" + y);
	IF(v != NULL) {
		alert(v.getAttribute("href"));
		//tile.className = v.className;
		tile.replaceChild(v, tile.firstChild);
	}
	ELSE {
		img = document.createElement("img");
		img.src = "graphic/map/map_free.png";
		tile.replaceChild(img, tile.firstChild);
	}
}
 
FUNCTION insertCoord(form, element) {
	// Koordinaten auslesen
	part = element.VALUE.split("|");
	IF(part.LENGTH != 2) RETURN;
	x = parseInt(part[0]);
	y = parseInt(part[1]);
	form.x.VALUE = x;
	form.y.VALUE = y;
}
 
FUNCTION insertCoordNew(form, element) {
	// Koordinaten auslesen
	part = element.VALUE.split(":");
	IF(part.LENGTH != 3) RETURN;
	form.con.VALUE = parseInt(part[0]);
	form.sec.VALUE = parseInt(part[1]);
	form.sub.VALUE = parseInt(part[2]);
}
 
FUNCTION insertUnit(input, COUNT) {
	IF(input.VALUE != COUNT)
		input.VALUE=COUNT;
	ELSE
		input.VALUE='';
}
 
FUNCTION insertNumber(input, COUNT) {
	IF(input.VALUE != COUNT)
		input.VALUE=COUNT;
	ELSE
		input.VALUE='';
}
 
FUNCTION insertBBcode(textareaID, startTag, endTag) {
		var input = $(textareaID);
		input.focus();
 
		/* für Internet Explorer */
		IF(typeof document.selection != 'undefined') {
			 /* Einfügen */
			var RANGE = document.selection.createRange();
			var insText = RANGE.text;
			RANGE.text = startTag + insText + endTag;
 
			/* Cursorposition anpassen */
			RANGE = document.selection.createRange();
			IF (insText.LENGTH == 0) {
				RANGE.move('character', -endTag.LENGTH);
			} ELSE {
				RANGE.moveStart('character', startTag.LENGTH + insText.LENGTH + endTag.LENGTH);
			}
			RANGE.SELECT();
		}
 
		/* für neuere auf Gecko basierende Browser */
		ELSE IF(typeof input.selectionStart != 'undefined') {
			/* Einfügen */
			var START = input.selectionStart;
			var END = input.selectionEnd;
			var insText = input.VALUE.substring(START, END);
			input.VALUE = input.VALUE.SUBSTR(0, START) + startTag + insText + endTag + input.VALUE.SUBSTR(END);
 
			/* Cursorposition anpassen */
			var pos;
			IF (insText.LENGTH == 0) {
				pos = START + startTag.LENGTH;
			} ELSE {
				pos = START + startTag.LENGTH + insText.LENGTH + endTag.LENGTH;
			}
			input.selectionStart = pos;
			input.selectionEnd = pos;
		}
}
 
FUNCTION selectTarget(x, y) {
	document.forms["units"].elements["x"].VALUE = x;
	document.forms["units"].elements["y"].VALUE = y;
	inlinePopupClose();
}
 
FUNCTION selectTargetCoord(con, sec, sub) {
	document.forms["units"].elements["con"].VALUE = con;
	document.forms["units"].elements["sec"].VALUE = sec;
	document.forms["units"].elements["sub"].VALUE = sub;
	inlinePopupClose();
}
 
FUNCTION insertAdresses(TO, CHECK) {
	opener.document.forms["header"].TO.VALUE += TO;
	IF(CHECK) {
		var mass_mail = opener.document.forms["header"].mass_mail;
		IF(mass_mail)
			mass_mail.checked='checked';
	}
}
 
FUNCTION selectVillage(id) {
	var href = opener.location.href;
	IF(href.search(/village=\w*/) != -1)
		href = href.REPLACE(/village=\w*/, 'village='+id);
	ELSE
		href += '&village='+id;
	href = href.REPLACE(/action=\w*/, '');
	opener.location.href = href;
	window.CLOSE();
}
 
FUNCTION overviewShowLevel() {
	labels = overviewGetLabels();
	FOR(var i=0, len=labels.LENGTH; i < len; i++) {
		var label = labels[i];
		IF(!label) continue;
		label.style.display = 'inline';
	}
}
 
FUNCTION overviewHideLevel() {
	labels = overviewGetLabels();
	FOR(var i=0, len=labels.LENGTH; i < len; i++) {
		var label = labels[i];
		IF(!label) continue;
		label.style.display = 'none';
	}
}
 
FUNCTION overviewGetLabels() {
	labels = ARRAY();
	labels.push(gid("l_main"));
	labels.push(gid("l_place"));
	labels.push(gid("l_wood"));
	labels.push(gid("l_stone"));
	labels.push(gid("l_iron"));
	labels.push(gid("l_statue"));
	labels.push(gid("l_wall"));
	labels.push(gid("l_farm"));
	labels.push(gid("l_hide"));
 
	labels.push(gid("l_storage"));
	labels.push(gid("l_market"));
 
	labels.push(gid("l_barracks"));
	labels.push(gid("l_stable"));
	labels.push(gid("l_garage"));
	labels.push(gid("l_church"));
	labels.push(gid("l_church_f"));
	labels.push(gid("l_snob"));
	labels.push(gid("l_smith"));
 
	RETURN labels;
}
 
FUNCTION insertMoral(moral) {
	opener.document.getElementById('moral').VALUE = moral;
}
 
FUNCTION resetAttackerPoints(points) {
	document.getElementById('attacker_points').VALUE = points;
}
 
FUNCTION resetDefenderPoints(points) {
	document.getElementById('defender_points').VALUE = points;
}
 
FUNCTION resetDaysPlayed(days) {
	document.getElementById('days_played').VALUE = days;
}
 
FUNCTION editGroup(GROUP_ID) {
	var href = opener.location.href;
	href = href.REPLACE(/&action=edit_group&edit_group=\d+&h=([a-z0-9]+)/, '');
	href = href.REPLACE(/&edit_group=\d+/, '');
	overview = opener.document.getElementById('overview');
	IF(overview && overview.VALUE.search(/(combined|prod|units|buildings|tech)/) != -1) {
		opener.location.href = href + '&edit_group=' + GROUP_ID;
	}
	window.CLOSE();
}
 
FUNCTION toggleExtended()
{
	var extended = document.getElementById('extended');
	IF(extended.style.display == 'block') {
		extended.style.display = 'none';
		document.getElementsByName('extended')[0].VALUE = 0;
	} ELSE {
		extended.style.display = 'block';
		document.getElementsByName('extended')[0].VALUE = 1;
	}
}
 
FUNCTION resizeIGMField(TYPE)
{
	field = document.getElementsByName('text')[0];
	old_size = parseInt(field.getAttribute('rows'));
	IF(TYPE == 'bigger') {
		field.setAttribute('rows',	old_size + 3);
	} ELSE IF(TYPE == 'smaller') {
		IF(old_size >= 4) {
			field.setAttribute('rows', old_size - 3);
		}
	}
}
 
/**
 * @param edit ID des anzuzeigenden Edit-Elements
 * @param label ID des zu versteckenden Label-Elements
 */
FUNCTION editToggle(label, edit) {
	gid(edit).style.display = '';
	gid(label).style.display = 'none';
}
 
FUNCTION toggle_visibility(id) {
	var element = document.getElementById(id);
	IF(element.style.display == 'block')
		element.style.display = 'none';
	ELSE
		element.style.display = 'block';
}
 
FUNCTION toggle_visibility_by_class(classname, display) {
	var toggleAll = $(document.BODY).getElements('[class$='+classname+']');
	IF (display == 'table-row')
		display = '';
	toggleAll.each(FUNCTION(item){
		IF(item.getStyle('display') == 'none')
			item.setStyle('display', display);
		ELSE
			item.setStyle('display', 'none');
	});
}
 
FUNCTION urlEncode(string) {
	RETURN encodeURIComponent(string);
}
 
/**
 *
 */
FUNCTION editSubmit(label, labelText, edit, editInput, url) {
	var data = gid(editInput).VALUE;
	data = urlEncode(data);
 
	var req = ajaxSync(url, 'text='+data);
 
	gid(edit).style.display = 'none';
	setText(gid(labelText), req.responseText);
	gid(label).style.display = '';
}
 
FUNCTION editSubmitNew(label, labelText, edit, editInput, url) {
	var data = gid(editInput).VALUE;
	var jSonRequest = NEW Request.JSON({url: url, onComplete: FUNCTION(response_data) {
		response_data = JSON.DECODE(response_data);
 
		IF(response_data.error) {
			alert(response_data.error);
		} ELSE {
			gid(edit).style.display = 'none';
			setText(gid(labelText), response_data.text);
			gid(label).style.display = '';
		}
	}}).post({json: JSON.encode({text:data})});
}
 
FUNCTION inlinePopup(name, url, options) {
	var popup_position_x = mx + options.offset_x;
	var popup_position_y = my + options.offset_y;
 
	$('inline_popup').setStyle('display', 'block');
	$('inline_popup').setStyle('left', popup_position_x + 'px');
	$('inline_popup').setStyle('top', popup_position_y + 'px');
 
	inlinePopupReload(name, url, options);
}
 
FUNCTION inlinePopupReload(name, url, options) {
	// Even better would be a solution WITH automatic throbber creation.
	var req = NEW Request({
		url: url,
		onRequest: FUNCTION() {
		 IF(options.empty_errors)
			 $('error').empty();
 
		 $('inline_popup_content').empty();
		 $('inline_popup_content').appendChild(NEW Element(
			 'img',
			 {
				 'src': options.image_base + '/throbber.gif',
				 'alt': 'Loading...'
			 }
		 ));
		},
		onSuccess: FUNCTION(reponseText, responseXML) {
		 $('inline_popup_content').empty();
		 $('inline_popup_content').innerHTML = reponseText;
		}
	}).send();
}
 
FUNCTION inlinePopupClose() {
		$('inline_popup').setStyle('display', 'none');
}
 
FUNCTION add_forum_share(edit_input, forum_id, url) {
	var ally_tag = gid(edit_input).VALUE;
 
	var jSonRequest = NEW Request.JSON({url: url, onComplete: FUNCTION(response_data) {
		response_data = JSON.DECODE(response_data);
		IF(response_data.error) {
			$('error').empty();
			$('error').innerHTML = response_data.error;
			$('error').setStyle('display', '');
		} ELSE {
			$('shared_'+forum_id).empty();
			$('shared_'+forum_id).innerHTML = response_data.new_shares;
			$('add_shares_link_'+forum_id).setStyle('display', 'none');
			$('edit_shares_link_'+forum_id).setStyle('display', '');
			inlinePopupClose();
		}
	}}).post({json: JSON.encode({ally_tag:ally_tag, forum_id:forum_id})});
}
 
FUNCTION remove_forum_shares(label_text, forum_id, url) {
	var remove = NEW ARRAY();
	$$('#checkboxes input').each (FUNCTION (box){
		IF(box.checked) 
			remove.push(box.VALUE);
	});
	remove = JSON.encode(remove);
 
	var jSonRequest = NEW Request.JSON({url: url, onComplete: FUNCTION(response_data) {
		response_data = JSON.DECODE(response_data);
 
		IF(response_data.error) {
			$('error').empty();
			$('error').innerHTML = response_data.error;
			$('error').setStyle('display', '');
		} ELSE {
			$(label_text).empty();
 
			IF(response_data.new_shares)
				$(label_text).innerHTML = response_data.new_shares;
			ELSE { 
				$('add_shares_link_'+forum_id).setStyle('display', '');
				$('edit_shares_link_'+forum_id).setStyle('display', 'none');
			}
 
			inlinePopupClose();
		}
 
	}}).post({json: JSON.encode({remove:remove, forum_id:forum_id})});
}
 
FUNCTION bb_color_picker_gencaller (fn,arg) {
	var f = FUNCTION () {
		fn(arg);
	};
	RETURN f;
}
 
FUNCTION bb_color_set_color (col) {
	var g = gid("bb_color_picker_preview");
	var inp = gid("bb_color_picker_tx");
	g.style.color = "rgb("+col[0]+","+col[1]+","+col[2]+")";
	var rr = col[0].toString(16);
	var gg = col[1].toString(16);
	var bb = col[2].toString(16);
	rr = rr.length<2?"0"+rr:rr;
	gg = gg.length<2?"0"+gg:gg;
	bb = bb.length<2?"0"+bb:bb;
	inp.VALUE = "#"+rr+gg+bb;
}
 
FUNCTION bb_color_pick_color (colordiv) {
	var col = colordiv.rgb;
 
	FOR (var l=0;l<6;l++) {
		FOR (var h=1;h<6;h++) {
			var cell = gid("bb_color_picker_"+h+l);
			IF (!cell) alert("bb_color_picker_"+h+l);
			var ll = l/3.0;
			var hh = h/4.5;
			hh=Math.pow(hh,.5);
			var light = Math.MAX(0,(255*ll-255));
			var r = Math.FLOOR(Math.MAX(0,Math.MIN(255, (col[0]*ll*hh + 255*(1-hh)) + light)));
			var g = Math.FLOOR(Math.MAX(0,Math.MIN(255, (col[1]*ll*hh + 255*(1-hh)) + light)));
			var b = Math.FLOOR(Math.MAX(0,Math.MIN(255, (col[2]*ll*hh + 255*(1-hh)) + light)));
			cell.style.backgroundColor = "rgb("+r+","+g+","+b+")";
			cell.rgb = [r,g,b];
			cell.onclick = bb_color_picker_gencaller(bb_color_set_color,[r,g,b]);
		}
	}
}
 
FUNCTION bb_color_picker_textchange () {
	var inp = gid("bb_color_picker_tx");
	var g = gid("bb_color_picker_preview");
	try {
		g.style.color = inp.VALUE;
	} catch (e) {
		/*no error report if user types wrong code*/
	}
}
 
FUNCTION bb_color_picker_toggle (assign) {
	var inp = gid("bb_color_picker_tx");
	inp.onkeyup  = bb_color_picker_textchange;
	IF (assign) {
		insertBBcode('message', '[color='+inp.VALUE+']', '[/color]');
		toggle_visibility('bb_color_picker');
		RETURN;
	}
	var colors = [gid("bb_color_picker_c0"),gid("bb_color_picker_c1"),gid("bb_color_picker_c2"),gid("bb_color_picker_c3"),gid("bb_color_picker_c4"),gid("bb_color_picker_c5")];
	colors[0].rgb = [255,0,0];
	colors[1].rgb = [255,255,0];
	colors[2].rgb = [0,255,0];
	colors[3].rgb = [0,255,255];
	colors[4].rgb = [0,0,255];
	colors[5].rgb = [255,0,255];
	FOR (i=0;i<=5;i++) {
		colors[i].onclick = bb_color_picker_gencaller(bb_color_pick_color,colors[i]);
	}
	bb_color_pick_color(colors[0]);
	toggle_visibility('bb_color_picker');
}
 
FUNCTION showElement(name) {
	gid(name).style.display = '';
}
 
FUNCTION get_sitter_player()
{
 
	var t_regexp = /(\?|&)t=(\d+)/;
	var matches = t_regexp.exec(location.href + "");
	IF(matches) {
		RETURN parseInt(matches[2]);
	} ELSE {
		RETURN FALSE;
	}
}
 
FUNCTION igm_to_show(url)
{
	var igm_to = gid('igm_to');
	gid('igm_to_content').innerHTML = ajaxSync(url, NULL).responseText;
	igm_to.style.display = 'inline';
}
 
FUNCTION igm_to_hide()
{
	var igm_to = gid('igm_to');
	igm_to.style.display = 'none';
}
 
FUNCTION igm_to_insert_adresses(list) {
	gid('to').VALUE += list;
}
 
FUNCTION igm_to_addresses_clear() {
	gid('to').VALUE = '';
}
 
FUNCTION xProcess(xelement, yelement) {
	xvalue = gid(xelement).VALUE;
	yvalue = gid(yelement).VALUE;
 
	IF(xvalue.indexOf("|") != -1) {
		xypart = xvalue.split("|");
		x = parseInt(xypart[0]);
 
		IF(xypart[1].LENGTH == 0)
			y = '';
		ELSE		
			y = parseInt(xypart[1]);
 
		gid(xelement).VALUE = x;
		gid(yelement).VALUE = y;
		RETURN;
	}
 
	IF(xvalue.LENGTH == 3 && yvalue.LENGTH == 0)
		gid(yelement).focus();
}
 
FUNCTION _(t) {
	IF(lang[t]) {
		RETURN lang[t];
	} ELSE {
		RETURN t;
	}
}
 
FUNCTION swap_image(img_id, src_new) {
	$(img_id).src = src_new;
}
 
FUNCTION change_url_by_parameters (parametersettings) {
	var params = window.location.search.substring(1, window.location.search.LENGTH);
 
	var params_arr = params.split('&');
 
	var new_params = NEW ARRAY();
	FOR (i = 0; i < params_arr.LENGTH; i++) {
		param = params_arr[i].split('=');
		param_name  = param[0];
		param_value = param[1];
 
		// Parameter, die gleich wieder angehaengt werden filtern, damit sie nicht doppelt vorkommen
		IF (parametersettings[param_name] == NULL) {
			new_params.push(param_name +'='+ param_value);
		}
	}
	FOR (key IN parametersettings) {
		new_params.push(key +'='+ parametersettings[key]);
	}
	// ARRAY wieder zu url zusammensetzen
	new_params = new_params.join('&');
 
	url = window.location.href.split('?')[0] + '?' + new_params;
 
	window.location.href = url;
}
 
FUNCTION map_toggle_politicalmap(checkbox, h, x, y) {
	change_url_by_parameters({
		'action':'save_politicalmap',
		'h':h,
		'x':x,
		'y':y,
		'politicalmap':checkbox.checked?1:0
	});
}
 
FUNCTION map_toggle_belief_radius(checkbox, h, x, y) {
	change_url_by_parameters({
		'action':'save_belief',
		'h':h,
		'x':x,
		'y':y,
		'belief':checkbox.checked?1:0
	});
}
 
| Foteliki samochodowe | | Sklep z oponami | | Opony zimowe | | karma dla psa - sklep | | Skracacz linków | | Przenieś bloga z onetu | | Wklejacz kodów | | Pionowe opisy |