var currencyMenuOpen = false;

/*NS.createNS("Utils");

Utils.setContent = function(el,content)
{
	if (el != null)
		el.innerHTML = content;
}

function g(id)
{
	return document.getElementById(id);
}

function s(el,content)
{
	Utils.setContent(el,content);
}*/

function windowSize()
{
	this.width = 0;
	this.height = 0;		
			
	if (typeof(window.innerWidth) == 'number')
	{
		this.width = window.innerWidth;
		this.height = window.innerHeight;
	}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		this.width = document.documentElement.clientWidth;
		this.height = document.documentElement.clientHeight;
	}
	else
	{
		this.width = document.body.clientWidth;
		this.height = document.body.clientHeight;
	}

	return this;
}	

function getWidth(el)
{
	if (typeof(el.offsetWidth) == 'number')
		return el.offsetWidth
	else
		return el.pixelWidth;
}
			
function getHeight(el)
{
	if (typeof(el.offsetHeight) == 'number')
		return el.offsetHeight
	else
		return el.pixelWidth;
}

function getOffsetPos(el,parentEl)
{
	var pos = {x:0,y:0};
	//el = el.offsetParent;
	//pos.x = - el.left;
	while(el)
	{
		pos.x += el.offsetLeft;
		pos.y += el.offsetTop;
		el = el.offsetParent;
		if (el == parentEl)
		 break;
	}
	
	return pos;
}

/*function getTop(el)
{
	return el.offsetTop;
}*/

function centerElement(el,parentEl)
{
	var pWidth = 0;
	var pHeight = 0;
	
	if (parentEl == null)
	{
		var ws = windowSize();
		pWidth = ws.width;
		pHeight = ws.height;
	}
	else
	{
		pWidth = getWidth(parentEl);
		pHeight = getHeight(parentEl);
	}
	
	var elwidth =  getWidth(el);
	var elheight = getHeight(el);
	
	el.style.left = ((pWidth - elwidth) / 2) + 'px';
	el.style.top = ((pHeight - elheight) / 2) + 'px';
}

function closeMessageBox()
{
	document.getElementById('alertbox').style.display = "none";
	document.getElementById('alertboxbg').style.display = "none";
}

function changeCurrency()
{
	var clist = document.getElementById('clist');
	var cid = clist.options[clist.selectedIndex].value;
	var from = escape(location.href);
	location.href = "/changelocale?monetary="+cid+"&frompage="+from;
}


function changeCountry(obj)
{
	//alert(obj.value);
	if (obj.value == "SE")
	{
		g("statearea").style.display = "none";
		g("nostate").value = "true";
	}
	else
	{
		g("statearea").style.display = "inline";
		g("nostate").value = "false";
	}
}

function openCurrencyMenu(e)
{
	currencyMenuOpen = true;
	//g('currencybox').style.display = "block";
	var list = g('clist').getElementsByTagName("LI");
	for (var i = 1; i < list.length; i++)
	{
		list[i].style.display = "block";
	}	
}

function closeCurrencyMenu()
{
	currencyMenuOpen = false;
	//g('currencybox').style.display = "none";
	document.onclick = null;
	var list = g('clist').getElementsByTagName("LI");
	for (var i = 1; i < list.length; i++)
	{
		list[i].style.display = "none";
	}
}

function toggleCurrencyMenu()
{
	if (currencyMenuOpen)
		closeCurrencyMenu()
	else
		openCurrencyMenu();
}

var WTYPE_CENTERED = 0;
var WTYPE_MAXIMIZED = 1;
var WTYPE_NORMAL = 2;

function createPopup(url,wName,type,xpVal,ypVal,h,w,autoFocus)
{
	var xpos = xpVal;
	var ypos = ypVal;
	
	if (type == undefined)
		type = WTYPE_CENTERED;
	
	if (autoFocus == undefined)
		autoFocus == false;

	if (isNaN(h)) h = 525;
	if (isNaN(w)) w = 700;
	
	if (isNaN(xpos)) xpos = 0;
	if (isNaN(ypos)) ypos = 0;
	
	if (type == WTYPE_CENTERED)
	{
		var sh = screen.availHeight;
		var sw = screen.availWidth;
		xpos = (sw / 2) - (w / 2);
		ypos = (sh / 2) - (h / 2);
	}
	else if (type == WTYPE_MAXIMIZED)
	{
		xpos = 0;
		ypos = 0;
		w = screen.availWidth;
		h = screen.availHeight;
	}
	
	var wnd = window.open(url,wName,'top='+ypos+',left='+xpos+',height='+h+',width='+w+',scrollbars=no,resizable=yes');

	if (autoFocus)
		wnd.focus();
	
	return wnd;
}

function popupUrl(url,wName,h,w)
{
	var popup = createPopup(url,wName,WTYPE_CENTERED,0,0,h,w,true);
}

function popupGame(url,wName,type)
{
	var popup = createPopup(url,wName,type,0,0,525,700,true);
	return false;
}

function formPopupGame(form,wName,type)
{
	popupGame('',wName,type);
	form.target = wName;
	return true;
}

function clearDefaultInput(field)
{
	if (field.defaultValue == field.value)
		field.value="";
}

function showCvvInfo(obj)
{
	var cvvinfo = g("cvvinfo");
	var pos = getOffsetPos(obj,cvvinfo.offsetParent);
	//alert(x+","+y);	
	cvvinfo.style.left = pos.x + 20 +  "px";
	cvvinfo.style.top = pos.y + 20 + "px";
	cvvinfo.style.visibility = "visible";
	//alert(cvvinfo.style.left);
}

function hideCvvInfo()
{
	g("cvvinfo").style.visibility = "hidden";
}

function submitFormOnce()
{
	document.Images.ok.disabled = true;
	document.Images.submit();
}

function joinGame(url,name,type)
{
	var wnd = popupGame(url,name,type);
	return false;
}
