function go(url) {
	window.location.href = url;
}

function displayBlock(e) {
	if(e)
		setDisplay(e, 'block');
}

function changeBlock(whichBlock) {
	try {
		setDisplay(whichBlock, 'block');
	} catch (e) {
		throw new Error(e.name  + " in function changeBlock(); passed variable whichBlock ('"+ whichBlock +"') could not be found. " + e.message);
	}
}

function rowOver(e, hover, row) {
	e.className = hover ? 'hover' : row;
}

function addOver(e, hover) {
	e.className = hover ? 'hover' : 'basic';
}

function changeText(theElement, newText) {
	$(theElement).innerHTML = newText;
}

function cancelOrder() {
	hide('cancelOrder');
	setDisplay('cancelOrderPrompt', 'block');
	$('physical').className='item-detail cancel';
}

function resetOrder() {
	setDisplay('cancelOrder', 'block');
	hide('cancelOrderPrompt');
	$('physical').className='item-detail';
}

function selFloat(str){
	return str.replace(/[\s+$]/g, "");
}

function simplePost(url) {
	Sarissa.formPostRequest(HTTP.setURLParams({'rxhtml':'true'}, url), null, null, function() {
		window.location.reload();
	});
}

function enableLegalCheck(checkbox, text, enabledClass) {
	$(checkbox).disabled = false;
	$(text).className = enabledClass;
}

function submitDeleteForm(form) {
	simplePost(form.action + form.entryId.value);
}

function setGameDefaultPlatformMac(gameCount, platformText) { // TODO generalize, see games.xsl
	for (var i = 1; i <= gameCount; i++) {
		var elemPlatform = $('changeTextPlatform' + i);
		if (elemPlatform) {
			elemPlatform.innerHTML = platformText;
			var gWin = $('gWin' + i);
			if(gWin) {
				setBgPos(gWin, '0px');
				setBgPos($('gMac' + i), '-31px');
			}
		}
	}
}

function openCashLink(transId){
	window.open("https://pg.billgate.net/bank/blt_cashlink.jsp?TRXID=" + transId, "Window","width=380, height=580, status=yes, scrollbars=no,resizable=yes, menubar=no");
}


/*
	This make that Cursor can pass the next SSN input when the first SSN input has enough data  in KR.
*/
function KRcursorPass(objf,obfs) {
	objf.value.length ==  6 ? document.getElementById(obfs).focus() : '';
}
function krGameNote(licenseId) {
	if ((game == 'WAR3' || game == 'W3XP' || game == 'D2DV' || game == 'D2XP') && (licenseId == '88' || licenseId == '79'))	{
	show('krMsg');
	} else {
	hide('krMsg');
	}
}

var totali, di

function hidefl() {
	if(!totali) return; 
	
	for(di=1;di<=totali;di++){ 
		document.getElementById("fl_"+di).style.display = "none";
	}
}

function ladd(id, targbox){ 
	if(Browser.mac) { 
		targel = document.getElementById("lid_"+id);
		targel.style.background = "url("+targbox+") no-repeat"; 
		return; 
	}
	
	if(!totali || totali<id){ 
		totali = id 
	}
		
	hidefl(); 
	
	document.getElementById("fl_"+id).style.display = "block";
	
	var so = new SWFObject("../_images/lvlup.swf", "lvl"+id, "400", "400", "7");
	
	so.addParam("wmode", "transparent");
	so.addParam("allowScriptAccess","always");
	so.write("fl_"+id);
	
	setTimeout(function(){
		targel = document.getElementById("lid_"+id);
		targel.style.background = "url("+targbox+") no-repeat";
	},700);
}


function convertCancel() {
	$j("#convert-target-page").attr("value", "cancel" );
	$j("#convert-submit").submit();
}

function keytest_auth(ev){
	if(window.event) keynum = ev.keyCode;
	else if(ev.which) keynum = ev.which;
	
	keychar = String.fromCharCode(keynum);
	
	if(keychar == '-') return false;
}

var keypaste_errortext;
function keytest_paste(ev){
	if(window.event) keynum = ev.keyCode;
	else if(ev.which) keynum = ev.which;
	
	keychar = String.fromCharCode(keynum);

	keypaste_errortext = (!keypaste_errortext) ? "Error" : keypaste_errortext;

	if(keynum == 86 && (ev.ctrlKey && !ev.altKey)){
		setTimeout(function(){alert(keypaste_errortext);},100); 
		return false;
	}
}

var bnet = {
	tooltip : {
		element : null,
		setText : function(event, ele, text, optionalMarginTop){
	
			if(bnet.tooltip.element == null)
				bnet.tooltip.element = document.getElementById('tooltip');
	
			var windowHeight = (window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight;
			var windowWidth	 = (window.innerWidth) ? window.innerWidth : document.documentElement.clientWidth;
			var scrollLeft	 = (self.pageXOffset) ? self.pageXOffset : document.documentElement.scrollLeft;
			var scrollTop	 = (self.pageYOffset) ? self.pageYOffset : document.documentElement.scrollTop;
				
			//boolean to see if we use mouse position or not
			var useMousePosition = false;
						
			//get x,y position of element we want to give tooltip
			var xPos = bnet.xPos(ele)
			var yPos = bnet.yPos(ele)
			
			//set the tooltip text
			bnet.tooltip.element.innerHTML = text;
			
			//if it goes to 0,0 then use mouse position
			if(((xPos - scrollLeft) <= 0) && ((yPos - scrollTop) <= 0)){
				useMousePosition =  true;
			}
		
			if(useMousePosition == true){
				xPos = event.pageX + 7;
				yPos = event.pageY + 15;
			}else{
				
				var tooltipWidth  = $j(bnet.tooltip.element).outerWidth();
				var tooltipHeight = $j(bnet.tooltip.element).outerHeight();
				var itemWidth 	  = $j(ele).outerWidth();
				var itemHeight 	  = $j(ele).outerHeight();
				
				//x position
				if((itemWidth + xPos + tooltipWidth + 5) > windowWidth){
					xPos = xPos - tooltipWidth - 5;			
				}else{
					xPos = xPos + itemWidth + 5;
				}
				
				//y position 
				yPos = yPos - (tooltipHeight/2);				
				
				//test if it will go (below the fold)
				if((yPos + tooltipHeight) > windowHeight + scrollTop){			
					yPos = windowHeight - tooltipHeight + scrollLeft;			
				}				
				
				//above fold (check last)
				yPos = (yPos < scrollTop) ? scrollTop : yPos;								
			}
			
			//add even so that tooltip disappears when moused out 
			addEvent(ele,"mouseout",function() {$j(bnet.tooltip.element).hide(); })
		
			if(optionalMarginTop)
				yPos = yPos + optionalMarginTop;
				
			
			//set x,y (left,top)
			$j(bnet.tooltip.element).css("left",xPos);
			$j(bnet.tooltip.element).css("top",yPos);
			$j(bnet.tooltip.element).show();			
		}			
	},
	xPos : function(obj){
		var curleft = 0;
	    if(obj.offsetParent)
	        while(1){
	          curleft += obj.offsetLeft;
	          if(!obj.offsetParent)
	            break;
	          obj = obj.offsetParent;
	        }
	    else if(obj.x)
	        curleft += obj.x;
	    return curleft;	
	},
	yPos : function(obj){
		var curtop = 0;
	    if(obj.offsetParent)
	        while(1){
	          curtop += obj.offsetTop;
	          if(!obj.offsetParent)
	            break;
	          obj = obj.offsetParent;
	        }
	    else if(obj.y)
	        curtop += obj.y;
	    return curtop;		
	},
	scrollAccept : {
		scroll : function(node, checkboxID){
			//if scrolled to bottom, show/enable checkbox
			if(node.scrollTop >= (node.scrollHeight - node.offsetHeight)){				
				$j("#" + checkboxID).removeAttr("disabled","false").css("visibility","visible").parent().addClass("enabled");				
			}
		},
		accept : function(checkbox){
						
			$j(checkbox).parent().bind('mousedown', function() { return false } )
			
			if(checkbox.checked)
			{
				$j(checkbox).parent().addClass("accepted");
				
				if(bnet.scrollAccept.validateCheckboxes(checkbox)){
					$j("a.submit").removeClass("submitDisabled");
					$j("a.submit").click(function(){
						Form.submit(this);
					});
				}				
			}
			//otherwise disable submit button
			else
			{
				$j(checkbox).parent().removeClass("accepted").addClass("enabled");
				$j("a.submit").addClass("submitDisabled");
				$j("a.submit").unbind("click");				
			}
			
			return false;
		},
		validateCheckboxes : function(node)
		{
			//check all checkboxes within form
			var form = Form.getForm(node);
			
			var allChecked = true;
			
			$j(".scrollContainer input.legalCheckbox",form).each(function(){
				if(!this.checked){	
					allChecked = false;
					return false;
				}
			});
			
			return allChecked;
		}
	},
	//confirmation dialogue box
	confirmationBox :
	{
		show : function()
		{
			var confBox = $j("#confirmationBox");
			
			//bind blackout click
			$j("#blackout").click(function(){
				bnet.confirmationBox.close()
			});
			
			//adjustments for ie6
			if(Browser.ie6){
				var newHeight = $j(window).height()+$j(window).scrollTop();
				$j('#blackout').attr("style","height: " + newHeight + "px");
				$j('#confirmationBox .confirmationForm').attr("style","margin-top:"+($j(window).scrollTop()+150)+"px;");
			}
			
			//show blackout and confirmation box 
			bnet.blackout.show();
			confBox.show();
		},
		close : function(){
			$j("#confirmationBox").hide();
			bnet.blackout.hide();
		}
	},
	blackout : {
		show : function(){
			$j("#blackout").show();
		},
		hide : function(){
			$j("#blackout").hide();
		}
	}
}

