function getElementsByNameIE(tag, name) {
     var elements	= document.getElementsByTagName(tag);
     var array	 	= new Array();
     for(i = 0,iarray = 0; i < elements.length; i++) {
          att = elements[i].getAttribute("name");
          if(att == name) {
               array[iarray] = elements[i];
               iarray++;
          }
     }
     return array;
}

function showHide(save)
{
	var object;
	var doc = document.getElementsByName("showHide");
	var IE	= getElementsByNameIE("div","showHide");
	for(var i = 0; i < IE.length; i++)
	{
		IE[i].style.display='none';
		IE[i].style.visibility='hidden';
	}
	/*for(var i = 0; i < doc.length; i++)
	{
		doc.item(i).style.display='none';
		doc.item(i).style.visibility='hidden';
	}*/
	
	document.getElementById(save).style.display='block';
	document.getElementById(save).style.visibility='visible';
}

function setTitle(v) {
	if(typeof(parent.document) != 'undefined' && typeof(parent.document) != 'unknown' && typeof(parent.document.title) == 'string') {
		parent.document.title = "Elite Avengers :: " + v;
	}
}
/*
document.onkeydown = hotKey;
function hotKey(e) {
	var theKey;
	if(window.event) {
		theKey			= window.event.keyCode;
		var realKey		= String.fromCharCode(theKey);
		if(window.event.altKey && window.event.shiftKey) {
			if(realKey == 'c' || realKey == 'C')
				window.location			= 'crimes.php';
			else if(realKey == 'g' || realKey == 'G')
				window.location			= 'gta.php';
			else if(realKey == 'b' || realKey == 'B')
				window.location			= 'handdruk.php';
		}
	} else if(e) {
		theKey			= e.which;
		var realKey		= String.fromCharCode(theKey);
		if(e.altKey && e.shiftKey) {
			if(realKey == 'c' || realKey == 'C')
				window.location			= 'crimes.php';
			else if(realKey == 'g' || realKey == 'G')
				window.location			= 'gta.php';
			else if(realKey == 'b' || realKey == 'B')
				window.location			= 'handdruk.php';
		}
	}
	return true;
}*/

var lastValue = new Array();
var disabled = false;
function number_format(whatElement)
{
	// Disable on right click
	if(!disabled)
	{
		var currentValue = whatElement.value;
		if(currentValue != lastValue[whatElement.name])
		{
			// Remember the last value so we don't double check the same thing
			lastValue[whatElement.name] = currentValue;
			
			if(currentValue.match(/^[1-9]{1}[0-9,]*?$/))
			{
				if(whatElement.style.color == 'red' && typeof(whatElement.originalColor) != "undefined")
					whatElement.style.color = whatElement.originalColor;
				
				if(currentValue.split(',').length > 1)
				{
					thousands = currentValue.split(',');
					currentValue = thousands.join('');
				}
				
				if(!isNaN(currentValue))
				{
					for(i=0; i<Math.floor((currentValue.length-(1+i))/3); i++)
						currentValue = currentValue.substring(0, (currentValue.length - (4 * i + 3))) + ',' + currentValue.substring(currentValue.length - (4 * i + 3));
					
					whatElement.value = currentValue;
					lastValue[whatElement.name] = currentValue;
				}
			}
			else if(currentValue.match(/^[0]*[1-9]{1}[0-9,]*?$/))
			{
				if(whatElement.style.color == 'red' && typeof(whatElement.originalColor) != "undefined")
					whatElement.style.color = '';
				
				if(currentValue.split(',').length > 1)
				{
					thousands = currentValue.split(',');
					currentValue = thousands.join('');
				}
				whatElement.value = Math.round(currentValue);
			}
			else
			{
				if(currentValue == '')
				{
					if(whatElement.style.color == 'red' && typeof(whatElement.originalColor) != "undefined")
						whatElement.style.color = whatElement.originalColor;
				}
				else
				{
					if(typeof(whatElement.style.color) != "undefined")
						whatElement.originalColor = whatElement.style.color;
					else
						whatElement.originalColor = '';
					whatElement.style.color = 'red';
				}
			}
		}
	}
}

function disable(e) {
	if(!e) var e = window.event;
	var targ;
	if(e.target)
		targ = e.target;
	else if(e.srcElement)
		targ = e.srcElement;
	if(targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode
	if(parseInt(navigator.appVersion)>3) {
		var clickType=1;
		if (navigator.appName=="Netscape")
			clickType=e.which;
		else
			clickType=event.button;
		if(clickType!=1 && targ.className.indexOf('number_format') != -1)
		{
			if(targ.style.color == 'red' && targ.originalColor)
				targ.style.color = targ.originalColor;
			disabled = true;
		}
	}
	return true;
}

function trim(v) {
	v			= v.replace(/^\s+/,''); 
	v			= v.replace(/\s+$/,'');
	return v;
}

function getRadioValue(radioGroup)
{
	var returnVal = false;
	var IE	= getElementsByNameIE("input",radioGroup);
	for(var i = 0; i < IE.length; i++)
	{
		 if (IE[i].checked)
		 {
			 returnVal = IE[i].value;
		 }
	}
	return returnVal;
}

function throwSnowball() {
	var myHeight = 0;
	if(typeof(window.innerWidth) == 'number')
		myHeight = window.innerHeight;
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
		myHeight = document.documentElement.clientHeight;
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
		myHeight = document.body.clientHeight;
	
	var posY						= typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
	snowballDIV						= document.getElementById('snowballDIVID');
	snowballDIV.innerHTML			= "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" id=\"theSnowball\" align=\"middle\" style=\"width: 80%; height: "+myHeight+"px; left: 10%;\"><param name=\"wmode\" value=\"transparent\" /><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"allowFullScreen\" value=\"false\" /><param name=\"movie\" value=\"/Snowball.swf\" /><param name=\"menu\" value=\"false\" /><param name=\"quality\" value=\"high\" /><param name=\"scale\" value=\"exactfit\" /><param name=\"wmode\" value=\"transparent\" />	<embed src=\"/Snowball.swf\" menu=\"false\" quality=\"high\" scale=\"exactfit\" wmode=\"transparent\" style=\"width: 80%; height: "+myHeight+"px; left: 10%;\" name=\"theSnowball\" align=\"middle\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object>";
	snowballDIV.style.display		= "block";
	snowballDIV.style.height		= myHeight+"px";
	snowball						= document.getElementById('theSnowball');
	snowball.style.height			= myHeight+"px";
	setTimeout("hideSnowball();", 2000);
	return;
}

function hideSnowball() {
	snowballDIV						= document.getElementById('snowballDIVID');
	snowballDIV.innerHTML			= "";
	snowballDIV.style.display		= "none";
	return;
}

function AddEvent(obj, type, fn)
{
	if(obj.attachEvent)
	{
		obj['e' + type + fn] = fn;
		obj[type + fn] = function(){ obj['e'+type+fn](window.event); };
		obj.attachEvent('on' + type, obj[type + fn]);
	}
	else
		obj.addEventListener(type, fn, false);
}
function RemoveEvent(obj, type, fn)
{
	if(obj.detachEvent)
	{
		obj.detachEvent('on' + type, obj[type + fn]);
		obj[type+fn] = null;
	}
	else
		obj.removeEventListener(type, fn, false);
}

AddEvent(document, 'mousedown ', disable);