
var worldURL = "http://world-cdn.taatu.com/";
var backendURL = "http://world.taatu.com/";
var IE6 = $.browser.msie && $.browser.version.substr(0,1) == 6 && !window.XMLHttpRequest, oldIE = IE6 || ($.browser.msie && $.browser.version.substr(0,1) == 7);

/************************************
LAUNCH WEBSITE
************************************/
function launch_web(country,language,regstep)
{
	var _width = 1000;
	var _height = 680;
	var _top = (screen.height-_height)/2 ; 
	var _left = (screen.width-_width)/2 ; 
	
	properties = "top="+_top+",left="+_left+",width="+_width+",height="+_height+",menubar=no,scrollbars=no,statusbar=no";
	
	// T-Link
	if(document.getElementById("loginContentSwf")) {
		var tlink = document.getElementById("loginContentSwf").getTLink();
		var tlinkParam = (tlink == '' || tlink == undefined) ? '' : '&tlink='+tlink;
	}
	
	if((country!="")&&(language!=""))
	{
		setCookie('taatu_country',country,365);
		setCookie('taatu_language',language,365) ;
		var regstepParam = (regstep == '' ? '' : '&regstep='+regstep);
				 
		window.open( worldURL + 'taatuworld/index.html?country='+country+'&language='+language+regstepParam+tlinkParam+getReferrer()+getParams()+ getmapping(language),'Taatu',properties);
	}
	else
	{
		var regstepParam = (regstep == '' ? '' : 'regstep='+regstep);
		window.open( worldURL + 'taatuworld/index.html?'+regstepParam+'&language='+selectedLanguage+tlinkParam+getReferrer()+getParams()+ getmapping(language),'Taatu',properties);
	}
}


function launch_rpx(country,language,regstep)
{
	var _width = 1000;
	var _height = 680;
	var _top = (screen.height-_height)/2 ; 
	var _left = (screen.width-_width)/2 ; 
	
	properties = "top="+_top+",left="+_left+",width="+_width+",height="+_height+",menubar=no,scrollbars=no,statusbar=no";
	
	// T-Link
	if(document.getElementById("loginContentSwf")) {
		var tlink = document.getElementById("loginContentSwf").getTLink();
		var tlinkParam = (tlink == '' || tlink == undefined) ? '' : '&tlink='+tlink;
	}
	var regstr="";
	if (regstep!="")
	{
		regstr = "&authprovider="+regstep;
	}
	
	window.open( backendURL + 'taatu/twtools/interfaces/login.php?lang='+language+tlinkParam+getReferrer()+getParams()+getmapping(language)+regstr,'Taatu',properties);
}


function changeStateButton(state, button)
{
	if(document.getElementById("loginContentSwf")) {
		document.getElementById("loginContentSwf").changeButtonState(state, button);
	}
}

/************************************
GET REFERRER
************************************/

function getReferrer()
{
	if (document.referrer&&document.referrer!="")
	{
		return '&referer='+escape(document.referrer);
	}
	else
	{
		return '';
	}
}

/************************************
GET COOKIE
************************************/
function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return null
}

/************************************
SET COOKIE
************************************/
function setCookie(cookieName,cookieValue,nDays) 
{
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	
	document.cookie = cookieName+"="+escape(cookieValue)
                 + ";path=/;expires="+expire.toGMTString();
}

/************************************
CHECK COOKIE
************************************/
function checkCookie()
{
	if(!checkLanguageCountry())
	{
		taatu_language=getCookie('taatu_language');
		taatu_country=getCookie('taatu_country');
	}
}


/************************************
SET LANG
************************************/
function setLang(langValue)
{
  setCookie('preferredLanguage', langValue, 5000);
  window.location.reload();
}


/************************************
GET PARAMS
************************************/
function getParams()
{
    p = location.href.split("?")[1];
    s = "";
    var nb=Math.random()*10000;
    if (p) {
      s = "&" + p.replace('&amp;', '\&')+'&cacheKiller='+nb;
    }
    else
    {
    }
    
    return s
}
/************************************
get a mapping if there is none
************************************/
function getmapping(language){
    var r="";
    var arVars=  getUrlVars();
    if(!arVars['mapping'])
    {
        r="&mapping=taatu_"+language.toLowerCase();
    }
    return r;
}
/************************************
returns URL variables  an associative array.
************************************/
function getUrlVars()
{   
    var vars = [];
    var hash=new Array();
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

/************************************
checkLanguageCountry
************************************/
function checkLanguageCountry()
{
	p = location.href.split("?")[1];
	
    if(p) 
	{
		if((p.indexOf("language")!=-1)&&(p.indexOf("country")!=-1)) 
		{
			return true;
		}
	}
	return false;	
}

/************************************
enableMapButton
************************************/
function enableMapButton(map)
{
	p = map.split("_");
	
	for(var i = 0; i < p.length; i++)
	{
		$('#'+p[i]).css("visibility", "visible");
	}
}

/************************************
displayNews
************************************/
function displayNews(xml)
{	
	NewsBox(xml);
}


//
var selectedCountry = '';
var selectedLanguage= '';