function formatToClockTime(iSeconds){
	var endHour 	= Math.floor( iSeconds/3600);
	var endMinutes 	= Math.floor( (iSeconds - endHour * 3600) / 60);
	var endSeconds 	= iSeconds - endMinutes * 60 - endHour * 3600;
	
	// Format
	endHour 	= endHour < 10 		? '0'+endHour 		: endHour;
	endMinutes 	= endMinutes < 10 	? '0'+endMinutes 	: endMinutes;
	endSeconds 	= endSeconds < 10 	? '0'+endSeconds 	: endSeconds;
	
	return endHour+':'+endMinutes+':'+endSeconds;
}

function toggleViewWeapons(viewElement){
	calcMaterialAufwand();
	
	var viewChoice 				= document.getElementById(viewElement+'Choice');
	var viewChoiceControl 		= document.getElementById(viewElement+'ChoiceControl');
	
	var ballChoice 				= document.getElementById('normalBallChoice');
	var ballChoiceControl 		= document.getElementById('normalBallChoiceControl');
	var crystalChoice 			= document.getElementById('crystalChoice');
	var crystalChoiceControl 	= document.getElementById('crystalChoiceControl');	
	var shrapnelChoice 			= document.getElementById('shrapnelChoice');
	var shrapnelChoiceControl 	= document.getElementById('shrapnelChoiceControl');
	
	var openImageCSS 			= 'url(\'/img/global/weapon/arrow_up.jpg\')';
	var closeImageCSS 			= 'url(\'/img/global/weapon/arrow_down.jpg\')';
	
	if(ballChoice)		ballChoice.style.display 	 = 'none';
	if(crystalChoice)	crystalChoice.style.display  = 'none';
	if(shrapnelChoice)	shrapnelChoice.style.display = 'none';
	
	if(ballChoiceControl) 		ballChoiceControl.style.backgroundImage 	= closeImageCSS;
	if(crystalChoiceControl) 	crystalChoiceControl.style.backgroundImage 	= closeImageCSS;
	if(shrapnelChoiceControl) 	shrapnelChoiceControl.style.backgroundImage = closeImageCSS;
	
	viewChoice.style.display 					= 'block'; 
	viewChoiceControl.style.backgroundImage 	= openImageCSS;
	
	return true;
}

function getElementsByClassName(className) {
    var muster = new RegExp("(^| )" + className + "($| )");
    var alles = document.getElementsByTagName("*");
    var gefunden = new Array();
    var i;

    for (i=0; i < alles.length; i++) {
        if (alles[i] && alles[i].className && alles[i].className != "") {
            if (alles[i].className.match(muster))
                gefunden[gefunden.length] = alles[i];
        }
    }

    return gefunden;
}

function translate(s)
{
	return s;
}

var browserType = 'unknown';
if (navigator.userAgent.match(/Opera/)) {
	browserType = 'opera';
} else if (navigator.userAgent.match(/MSIE/)) {
	browserType = 'ie';
} else if (navigator.userAgent.match(/Mozilla/)) {
	browserType = 'ns';
}


function domGet(id)

{

	if (typeof(id) != 'string') {

		return id;

	} else {

		return document.getElementById(id);

	}

}



function domGetChild(obj, id)

{

	for (var i=0; i<obj.childNodes.length; i++) {

		var n = obj.childNodes[i];

		if (n.nodeType != 1) continue;

		if (n.id == id) return n;

		var r = domGetChild(n, id);

		if (r != false) return r;

	}

	return false;

}



function domGetBody()

{

	var tmp = document.getElementsByTagName('BODY');

	return tmp[0];

}



function domGetOffset(obj)

{

	obj = domGet(obj);

	var offset = { x:0, y:0 };

	if (obj.offsetX) return { x:obj.offsetX, y:obj.offsetY };

	while (obj) {

		offset.x += obj.offsetLeft;

		offset.y += obj.offsetTop;

		obj = obj.offsetParent;

	}

	return offset;

}



function domFireEvent(obj, name)

{

	if (browserType == 'ns') {

//		var evnt = createEventObject(); //obj.ownerDocument.createEventObject();

//		evnt.initEvent(name.slice(2), false, false);

//		obj.dispatchEvent(evnt);

/*

		if (!event) event = obj.ownerDocument.createEventObject();

		event.initEvent(name.slice(2), false, false);

		obj.dispatchEvent(event);

*/		

		if (typeof(obj[name]) == 'function') {

			obj[name]();

		} else if (obj.getAttribute(name)) {

			eval(obj.getAttribute(name));

		}

	} else {

		obj.fireEvent(name, window.event);

	}

}



function domAttachEvent(obj, name, handler)

{

	if (browserType == 'ns') {

		obj.addEventListener(name.slice(2), handler, false);

	} else {

		obj.attachEvent(name, handler);

	}

}



function domDetachEvent(obj, name, handler)

{

	if (browserType == 'ns') {

		obj.removeEventListener(name.slice(2), handler, false);

	} else {

		obj.removeEvent(name, handler);

	}

}



function domOnLoad(handler)

{

	domAttachEvent(window, 'onload', handler);

}



function domEventGetCoords()

{

	if (window.event) {

		return { x:window.event.clientX, y:window.event.clientY };

	} else {

		return { x:window.nsevent.pageX, y:window.nsevent.pageY };

	}

}



function domEventGetTarget()

{

	if (window.event) {

		return window.event.srcElement;

	} else {

		return window.nsevent.target;

	}

}



function domEventPreventDefault()

{

	if (window.event) { 

		window.event.returnValue = false; 

	} else {

		window.nsevent.preventDefault();

	}

}



function domEventCancelBubble()

{

	if (window.event) { 

		window.event.cancelBubble = true; 

	} else {

		window.nsevent.stopPropagation();

	}

}



function domGetParent(obj, tagName)

{

	if (!tagName) {

		while (obj && obj.nodeType && obj.nodeType != 1) obj = obj.parentNode;

	} else {

		while (obj && obj.tagName && obj.tagName.toLowerCase() != tagName.toLowerCase()) obj = obj.parentNode;

	}

	return obj;

}



function domGetPrevious(obj, tagName)

{

	obj = domGet(obj);

	while (true) {

		if (obj.nodeType == 1) {

			if (typeof(tagName) == 'object') {

				for (var i=0; i<tagName.length; i++) if (tagName[i].toLowerCase() == obj.tagName.toLowerCase()) return obj;

			} else if (typeof(tagName) == 'string') {

				if (tagName.toLowerCase() == obj.tagName.toLowerCase()) return obj;

			} else {

				return obj;

			}

		}

		if (obj.previousSibling) {

			obj = obj.previousSibling;

		} else if (obj.parentNode) {

			obj = obj.parentNode;

		} else {

			return null;

		}

	}

}



function domGetNext(obj, tagName)

{

	obj = domGet(obj);

	while (true) {

		if (obj.nodeType == 1) {

			if (typeof(tagName) == 'object') {

				for (var i=0; i<tagName.length; i++) if (tagName[i].toLowerCase() == obj.tagName.toLowerCase()) return obj;

			} else if (typeof(tagName) == 'string') {

				if (tagName.toLowerCase() == obj.tagName.toLowerCase()) return obj;

			} else {

				return obj;

			}

		}

		if (obj.nextSibling) {

			obj = obj.nextSibling;

		} else if (obj.parentNode) {

			obj = obj.parentNode;

		} else {

			return null;

		}

	}

}



function domSetAlpha(obj, alpha)

{

	obj = domGet(obj);

	if (document.addEventListener) {

		obj.style.MozOpacity = parseInt(alpha)/100;

	} else {

		obj.style.filter = 'alpha(opacity='+parseInt(alpha)+', finishopacity=0, style=0)';

	}

}



function domRemove(obj)

{

	obj = domGet(obj);

	obj.parentNode.removeChild(obj);

}











var gDomSetFlashVarQueue = new Array();

var gDomSetFlashVarTimer = false;



function domSetFlashVarTimer()

{

	if (gDomSetFlashVarQueue.length == 0) {

		clearInterval(gDomSetFlashVarTimer);

		gDomSetFlashVarTimer = false;

		return;

	}

	var queueItem = gDomSetFlashVarQueue.pop();

	try {

		queueItem.obj.SetVariable(queueItem.name, queueItem.value);

	} catch (e) {

	}

	try {

		queueItem.obj.SetVariable('c.'+queueItem.name, queueItem.value);

	} catch (e) {

	}

	queueItem.count--;

	if (queueItem.count > 0) {

		gDomSetFlashVarQueue.unshift(queueItem);

	}

}



function domSetFlashVar(id, name, value)

{

	var obj = false;

	if (document.embeds) obj = document.embeds[id];

	if (!obj) obj = document.getElementById(id);

	if (!obj) return;

	var queueItem = new Object();

	queueItem.obj = obj;

	queueItem.name = name;

	queueItem.value = value;

	queueItem.count = 3;

	gDomSetFlashVarQueue.unshift(queueItem);

	if (!gDomSetFlashVarTimer) {

		gDomSetFlashVarTimer = setInterval('domSetFlashVarTimer()', 20);

	}

}





if (browserType == 'ns') {

	document.addEventListener('mousedown', function(e) { window.nsevent=e; }, true);

	document.addEventListener('mouseup', function(e) { window.nsevent=e; }, true);

	document.addEventListener('mousemove', function(e) { window.nsevent=e; }, true);

	document.addEventListener('click', function(e) { window.nsevent=e; }, true);

	document.addEventListener('keyup', function(e) { window.nsevent=e; }, true);

	document.addEventListener('keydown', function(e) { window.nsevent=e; }, true);

	document.addEventListener('keypressed', function(e) { window.nsevent=e; }, true);

	document.addEventListener('blur', function(e) { window.nsevent=e; }, true);

	document.addEventListener('focus', function(e) { window.nsevent=e; }, true);

}



////////////////////////////////////////////////////////////////////////////////

function popup(width, height, name, url)
{
	if (!url) {
		var a = domGetParent(domEventGetTarget(), 'A');
		if (a) url = a.href;
	}
	if (url) {
		if (!name) name = '';
		var w = window.open(url, name, 'width='+width+',height='+height+',menubar=no,location=no,status=yes,toolbar=no');
		if (w) {
			w.focus();
			if (window.event || window.nsevent) {
				domEventPreventDefault();
				domEventCancelBubble();
			}
			return false;
		}
	}
	return false;
}
function popupAbo(width, height, name, url)
{
	if (!url) {
		var a = domGetParent(domEventGetTarget(), 'A');
		if (a) url = a.href;
	}
	if (url) {
		if (!name) name = '';
		var w = window.open(url, name, 'width='+width+',height='+height+',menubar=no,location=no,status=yes,toolbar=no');
		if (w) {
			w.focus();
			if (window.event || window.nsevent) {
				domEventPreventDefault();
				domEventCancelBubble();
			}
			return false;
		}
	}
}

function popupClose(reload)
{
	if (window.opener) {
		if (reload) if (window.opener.location) window.opener.location.reload();
		window.close();
	} else {
		history.back();
	}
}

/*
function resizeTo(w, h)
{
	var cw = (browserType == 'ie') ? document.body.clientWidth : window.innerWidth;
	var ch = (browserType == 'ie') ? document.body.clientHeight : window.innerHeight;
//	if (browserType == 'ie') window.moveBy(-Math.max(w-cw, 0), -Math.max(h-ch, 0));
	if (w > 500 || h > 500) window.moveTo(20, 20);
	window.resizeBy(w-cw, h-ch);
	alert("test");
}
*/
////////////////////////////////////////////////////////////////////////////////

function changeButtons(welchen) {
	var image = welchen.src;
	var endung = (image.substr(image.length-3,3));
	if((image.substr(image.length-5,1)) == 0)  var teil = 1;
	else teil = 0;
	var newImage = (image.substring(0,image.length-5)) + teil + "." +endung;
	welchen.src = newImage;
}
/*
var F1;
function popup(ziel,breite,hoehe) {
	if(F1 && !F1.closed) {
		F1.close();
	}
	F1 = window.open(ziel, "Fenster1", "width="+breite+",height="+hoehe+",left=0,top=0");
}
*/


function bilderVorladen() {
	document.Vorladen = new Array();
	if(document.images) {
		for(var i = 0; i < bilderVorladen.arguments.length; i++) {
			document.Vorladen[i] = new Image();
			document.Vorladen[i].src = bilderVorladen.arguments[i];
		}
	}
}

var System = {
    
    showLayer: function(elem){
        if($(elem)){
            $(elem).show();
        }
    },
    
    hideLayer: function(elem){
        if($(elem)){
            $(elem).hide();
        }
    },
    
    unlockWMShipDesign: function(shipDesignID){
        if(parseInt(shipDesignID) && $('WMCoins_wannaBuyItem').value.length > 0){
            shipDesignID = parseInt(shipDesignID);
            var confirmMessage = $('WMCoins_wannaBuyItem').value;
            if(confirm(confirmMessage)){
                $('buyWMShipDesignValue').value = shipDesignID;
                $('buyWMShipDesign').submit();
            }
        }
    }
}




