// JavaScript Document
// nb, this file is also used by the disclaimer pages

$(document).ready(function(){
	if(typeof FS_ajaxFeed == 'function') {
		home_ajax = new FS_ajaxFeed(['spotPriceCurrencies','totalGold'],"/ajax/home/",60000);
		home_ajax.loadAjaxData();
	}						   
	setBackTab();
});



function setBackTab(){ // when we use the back button from a country site to the homepage, then the url is #tab, so we should click the relevant tab
	if(document.location.hash){
		tab = document.location.hash.replace('#','');
		clickTab(tab);
	}
}

oldTab = 'home';
function clickTab(tab)
{
	$('#'+oldTab+'tab').removeClass('activeTab');
	$('#'+oldTab+'Info').hide();
	$('#'+tab+'tab').addClass('activeTab');
	$('#'+tab+'Info').show();
	oldTab = tab;
}

function agree_home(param)
{
	if(param == 'us')
	{
		set_cookie('us');
	}
	else
	{
		tb_show(null, '/message/lang/'+param+'/?homepage=true&KeepThis=true&TB_iframe=true&height=375&width=760&modal=true',null);
	}
		
}

function set_cookie(site)
{
	eraseCookie(site+'_agree');
	createCookie(site+'_agree',true,5);	
}

function createCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) 
{
	createCookie(name,"",-1);
}

function trim(str){
	return str.replace(/^\s+|\s+$/g, '');
}

