// popup new window
function popup(URL) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=1600,height=1200,left = 0,top = 0');");
}

function popupSpecific(address, width, height, scrollbar, resizable) 
{
	var screenX = screen.width
	var screenY = screen.height
	if (resizable == undefined){
		resizable = 0;
	}
	var x = (screenX - width)/2;
	var y = (screenY - height)/3;
	var random_num = (Math.round((Math.random()*9)+1));
	
	var popup = window.open(address,"popup"+random_num,"resizable="+resizable+" ,scrollbars="+scrollbar+",width=" + width + ",height=" + height + ", top=" + y + ", left=" + x);
	popup.focus();
}

function flashPutHref(href) 
{
	parent.location.hash = href;
}

function flashPutTitle(title) 
{
	parent.document.title = title;
}

var isMSIE = navigator.appName.indexOf("Microsoft") != -1;
var userAgent = navigator.userAgent.toLowerCase();

if (userAgent.indexOf('safari') != -1)
{
	isMSIE = true;	
}

if (!isMSIE && userAgent.indexOf('safari') == -1)
{
	var hashArray = parent.location.toString().split('#');
	var queryString = hashArray[1];
	
	window.setInterval(checkHash,100);
}

function checkHash()
{
	var newHashArray = parent.location.toString().split('#');
	var newQueryString = newHashArray[1];
	
	if (queryString != newQueryString)
	{
		queryString = newQueryString;
		setFlashVariables('flashMovie',queryString);
	}
}

//setInterval(checkSizeAndUpdateScrolls,100);

function checkSizeAndUpdateScrolls()
{
	if (navigator.appName=="Netscape")
	{
 		winW = window.innerWidth;
  		winH = window.innerHeight;
	}
	if (navigator.appName.indexOf("Microsoft")!=-1) 
	{
 		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;
	}
	
	if(winW < 990 && winH < 580)
	{
		document.getElementById('flashContent').style.width = 990;
		document.getElementById('flashContent').style.height = 580;
	}
	else if (winW >= 990 && winH < 580)
	{
		document.getElementById('flashContent').style.height = 580;
	}
	else if (winW < 990 && winH >= 580)
	{
		document.getElementById('flashContent').style.width = 990;
	}
	else
	{
		document.getElementById('flashContent').style.width = '100%';
		document.getElementById('flashContent').style.height = '100%';
	}
}

function getCookie() 
{
	var name = 'lda';	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	
	if ( ( !start ) &&
	(name != document.cookie.substring( 0, name.length)))
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	
	return unescape( document.cookie.substring(len,end));
}

function getCookieData() 
{
    var dc = document.cookie;
    var prefix = "lda=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length; 
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(country,language,year,month,day) 
{
	var name = 'lda';
	var value = 'passed=true#country='+country+'#language='+language+'#year='+year+'#month='+month+'#day='+day;
	var expires = 0;
	var path = '/';
	var domain = '';
	var secure = '';
	
	
	// when using test lda page redirect to simple html page
	
	if(document.title == "LDA - TEST")
	{
		location.href = 'lda_nobranding_completed.htm';
	}
	else
	{
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime(today.getTime());
	
		var expires_date = new Date( today.getTime() + (expires) );
	
		document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
		
		location.href = 'flashPage.html';
	}
	
}

intImage = 1;
function swapImage() 
{
	switch (intImage) 
	{
		case 1:
		   document.getElementById('topImage').src = "images/error_top_over.gif";
		   intImage = 2;
		   return(false);
		case 2:
		   document.getElementById('topImage').src = "images/error_top_up.gif";
		   intImage = 1;
		   return(false);
	 }
}
	
var path = "";
function UpdatePlayer(playerName, matchID)
{
	//alert(path + '/players/bio.rails')
	var myAjax = new Ajax.Updater(
						{success: 'playerProfile'}, 
						path + '/players/bio.rails', 
						{
							method: 'post', 
							parameters: "playername=" + playerName + "&matchID=" + matchID + "&isAsync=true", 
							onFailure: reportError,
							evalScripts: true
						});	
	
}

function reportError(message)
{
	alert(message);
}