/*!
 * Application JavaScript Library v1.4.2
 * Roxelane B.V.
 *
 * Copyright 2010, 2011
 * Date: Mon Dec 12 19:43:33 2010 -0500
 */

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var gUnity3dParameters = "";
var gSubDomainStr = "www";
var gBaseURLStr = "http://"+gSubDomainStr+".wosworldcup.com/" ;
var gScriptURLStr = "http://"+gSubDomainStr+".wosworldcup.com/wcodbt/" ;
var gImagesURLStr = "http://"+gSubDomainStr+".wosworldcup.com/Images/" ;
var gApplicationIdStr = 6;
 
var gUrlParameters = 
{
	'APPID' 	: 6,
	'REGION' 	: 1,
	'USERID' 	: 'Unknown',
	'PAGEID' 	: 0,
	'DEBUG' 	: 0,
	'LANGID' 	: 'EN'
} ;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Hash()
{
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
   
	this.removeItem = function(in_key)
	{
		var tmp_previous;
		if (typeof(this.items[in_key]) != 'undefined') {
			this.length--;
			var tmp_previous = this.items[in_key];
			delete this.items[in_key];
		}
	   
		return tmp_previous;
	}

	this.getItem = function(in_key) {
		return this.items[in_key];
	}

	this.setItem = function(in_key, in_value)
	{
		var tmp_previous;
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}
			else {
				tmp_previous = this.items[in_key];
			}

			this.items[in_key] = in_value;
		}
	   
		return tmp_previous;
	}

	this.hasItem = function(in_key)
	{
		return typeof(this.items[in_key]) != 'undefined';
	}

	this.clear = function()
	{
		for (var i in this.items) {
			delete this.items[i];
		}

		this.length = 0;
	}
}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ExtractParameterList(pParameterStr,pSeperator)
{
	var lParameters = pParameterStr.split(pSeperator);
	var lParameterArray = new Array();
	for (var lIndex=0; lIndex < lParameters.length; lIndex++) {
		var lPosition = lParameters[lIndex].indexOf('=');
		if (lPosition > 0) {
			var lKey = lParameters[lIndex].substring(0,lPosition);
			var lValue = lParameters[lIndex].substring(lPosition+1);
			lParameterArray[lKey] = lValue;
		}
	}
	return lParameterArray;
	
}
function ExtractParameter(pParameterArray,pKey, pExpectedValue)
{
	try
	{
		if(pParameterArray.hasOwnProperty(pKey))
		{
			return pParameterArray[pKey];
		}
	}
	catch(e)
	{
		return pExpectedValue;
	}
}
function ExtractFloatParameter(pParameterArray,pKey, pExpectedValue)
{
	try
	{
		var lString = ExtractParameter(pParameterArray,pKey, pExpectedValue);
		return parseFloat(lString);
	}
	catch(e)
	{
		return pExpectedValue;
	}
}
function ExtractIntParameter(pParameterArray,pKey, pExpectedValue)
{
	try
	{
		var lString = ExtractParameter(pParameterArray,pKey, pExpectedValue);
		return parseInt(lString);
	}
	catch(e)
	{
		return pExpectedValue;
	}
}

function GetParameters()
{
	var lQueryStr = window.location.search.substring(1);
	var lParameters = lQueryStr.split('&');
	for (var lIndex=0; lIndex < lParameters.length; lIndex++) {
		var lPosition = lParameters[lIndex].indexOf('=');

		if (lPosition > 0) {
			var lKey = lParameters[lIndex].substring(0,lPosition);
			var lValue = lParameters[lIndex].substring(lPosition+1);
			gUrlParameters[lKey] = lValue;
		}
	}
}

function GetParameter(pKey, pExpectedValue)
{
	if(gUrlParameters.hasOwnProperty(pKey))
	{
		return gUrlParameters[pKey];
	}
	return pExpectedValue;
}
function SetParameter(pKey, pValue)
{
		gUrlParameters[pKey] = pValue;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function GetScriptURL(pScriptStr,pArgStr)
{
	return gScriptURLStr+pScriptStr+"?A="+gApplicationIdStr +"&"+pArgStr;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GenerateFancyBox( pURLStr, pWidth, pHeight)
{
//	alert('url='+pURLStr.replace("@","?"));
	var lDiv = document.getElementById("hiddenclicker");
	lDiv.href = pURLStr.replace("@","?");
  $('#hiddenclicker').trigger('click');
  return pURLStr;
}
function GetFancyBoxSizeStr()
{
	var lWidth= $(window).width() ;
	var lHeight = $(window).height();
	var lFBWidth = 0.7*lWidth;
	var lFBHeight = 0.7*lHeight-80;
	return "W="+parseInt(lFBWidth)+"px&H="+parseInt(lFBHeight)+ "px" ;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
function SetCookie( pNameStr, pValueStr)
{
	// maak een datum aan 
	var EndDate = new Date(); 
	// tel hier een maand bij op 
	EndDate.setYear(EndDate.getYear() + 2); 

	document.cookie = pNameStr+"="+escape(pValueStr)+";expires="+EndDate+";path=/"; 
}

function GetCookie( pNameStr )
{ 

	var lCookieStr = document.cookie;
	var lSearchStr = pNameStr + "=";
	var lStartIndex = lCookieStr.indexOf(lSearchStr, 0); 
 	if(lStartIndex == -1)
	{ 
    		return false; 
	}
	else
	{
		lStartIndex += lSearchStr.length; 
		var lEindIndex = lCookieStr.indexOf(";", lStartIndex); 
		if(lEindIndex == -1)
		{
			lEindIndex = lCookieStr.length;
		}
		return unescape(lCookieStr.substring(lStartIndex, lEindIndex)); 
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function LoadXml(pURLStr)
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					return "Error";
				}
	 		}
	}
	xmlHttp.onreadystatechange = 
		function()
		{
			if(xmlHttp.readyState==4)
			{
				return xmlHttp.responseText;
			}
		} ;
	xmlHttp.open("GET",pURLStr,false);
	xmlHttp.send(null);
	return "Ok";
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GetFontStr(pFontNameStr,pFontSize,pFontColor,pStr)
{
	return '<font face="'+pFontNameStr+'" color="'+pFontColor+'" size="'+pFontSize+'">'+pStr+'</font>' ;
}
function GetFontStrS(pFontSize,pStr)
{
	return '<font size="'+pFontSize+'">'+pStr+'</font>' ;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Popup windows, and popup blocker detection..
var lPopupWindow = null;
function OpenPopupWindow(pURLStr,pTitleStr,pWidth,pHeight,pFeaturesStr)
{
	var lWidth= $(window).width() ;
	var lHeight = $(window).height();
	var lWindowX = parseInt((lWidth-pWidth)/2);
	var lWindowY = parseInt((lHeight-pHeight)/2);
//	alert("OpenPopupWindow:"+lWindowX + ","+lWindowY);
	if (lWindowX < 0) lWindowX = 0;
	if (lWindowY < 0) lWindowY = 0;

	var lSettingsStr = 'height=' + pHeight + ',';
	lSettingsStr += 'width=' + pWidth + ',';
	lSettingsStr += 'top=' + lWindowY + ',';
	lSettingsStr += 'left=' + lWindowX + ',';
	lSettingsStr += pFeaturesStr;
//	alert("OpenPopupWindow:"+lSettingsStr);
	lPopupWindowCalled = false ;
	lPopupWindow = window.open(pURLStr,pTitleStr,lSettingsStr);
//	lPopupWindow.window.focus();

	if ( lPopupWindow!=null)
	{
		return "Ok";
	}

	return "Err";
}
var lCheckPopupBlockedDone = false;
var lPopupAllowed = false ;
function CheckPopupBlocked() {
	lCheckPopupBlockedDone = false;
	lPopupAllowed = false ;	
 	setTimeout(function(){doCheckPopupBlocked(lPopupWindow);}, 3000);
}

function PopupWindowCheckIsDone()
{
	if(lCheckPopupBlockedDone)
	{
    return "true" ;
  }
  return "false";
}
function PopupWindowIsAllowed()
{
	if(lPopupAllowed)
	{
    return "true" ;
  }
  return "false";
}


function doCheckPopupBlocked(poppedWindow) {

    var result = false;
		var lReasonStr = "" ;
    try {
        if (typeof poppedWindow == 'undefined') {
            // Safari with popup blocker... leaves the popup window handle undefined
            lReasonStr = " Safari with popup blocker... leaves the popup window handle undefined";
            result = true;
        }
        else if (poppedWindow && poppedWindow.closed) {
            // This happens if the user opens and closes the client window...
            // Confusing because the handle is still available, but it's in a "closed" state.
            // We're not saying that the window is not being blocked, we're just saying
            // that the window has been closed before the test could be run.
            result = false;
        }
        else if (poppedWindow && poppedWindow.outerWidth == 0) {
            // This is usually Chrome's doing. The outerWidth (and most other size/location info)
         // will be left at 0, EVEN THOUGH the contents of the popup will exist (including the
         // test function we check for next). The outerWidth starts as 0, so a sufficient delay
         // after attempting to pop is needed.
					lReasonStr = "This is usually Chrome's doing. ";

            result = true;
        }
        else if (poppedWindow && poppedWindow.LoadContent) {
            // This is the actual test. The client window should be fine.
            result = false;
        }
        else {
            // Else we'll assume the window is not OK
						lReasonStr = " Else we'll assume the window is not OK";
            result = true;
        }

    } catch (err) {
        //if (console) {
        //    console.warn("Could not access popup window", err);
        //}
    }

    if(!result)
    {
			poppedWindow.LoadContent();
    }

	lCheckPopupBlockedDone = true ;
	if (result == false)
		lPopupAllowed = true ;
}

function PopupWindowIsOpen()
{
  if (lPopupWindow!=null && !lPopupWindow.closed )
  {
    return "true" ;
  }
  return "false";

}

function PopupWindowIsClosed()
{
  if (!lPopupWindow || lPopupWindow==null || lPopupWindow.closed)
  {
    return "true" ;
  }
  return "false";
}

function ClosePopupWindow()
{
  if (!lPopupWindow || lPopupWindow==null || lPopupWindow.closed)
  {
    return "false" ;
  }
  lPopupWindow.close();
  lPopupWindow = null;
  return "true";
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Browser detection..
function IsIE8Browser() {
    var rv = -1;
    var ua = navigator.userAgent;
    var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null) {
        rv = parseFloat(RegExp.$1);
    }
    return (rv == 4);
}

function GetBrowserName()
{
	return navigator.appName; 
}

function GetBrowserVersionX()
{
	return navigator.appVersion; 
}

function GetBrowserVersion()
{
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
	{
		//test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 		var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 		if (ffversion>=3)
  		return "FF:3";
 		else if (ffversion>=2)
		  return "FF:2";
		else if (ffversion>=1)
		  return "FF:1";
	}

	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		if (ieversion>=8 || IsIE8Browser())
			return "IE:8";
		else if (ieversion>=7)
			return "IE:7";
		else if (ieversion>=6)
			return "IE:6";
		else if (ieversion>=5)
			return "IE:5";
	}

	if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
	{ //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
		var oprversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		if (oprversion>=10)
			return "OP:10";
		else if (oprversion>=9)
			return "OP:9";
		else if (oprversion>=8)
			return "OP:8";
		else if (oprversion>=7)
			return "OP:7";
  	return "unknown:0";	
	}

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Load the URL Parameters..
GetParameters() ;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

