// gates.js
// js-file to get the referrer on loading and place an element if referrer
// matchs condition
// 16.01.2007 Floor SA: sb

// -----------------------------------------------

function checkReferrer()	{
	console.log('checkReferrer');

	var cookieinfo = getCookie('gatereferrer');
	var referrer = document.referrer;
	
	var date=new Date;
	date.setFullYear(date.getFullYear()+10);

	if (referrer.match(/au.dartfish.com/) || referrer.match(/dartfish.com.au/)) {
		setCookie('gatereferrer','au',null,'/');
		setCookie('langmenu','en',date,'/');
		showGateInfo('au');
	}
	else if (referrer.match(/dartfish.cz/)) {
		setCookie('gatereferrer','cz',null,'/');
		setCookie('langmenu','en',date,'/');
		showGateInfo('cz');
	}
	else if (referrer.match(/dartfish.dk/)) {
		setCookie('gatereferrer','dk',null,'/');
		setCookie('langmenu','en',date,'/');
		showGateInfo('dk');
	}
	else if (referrer.match(/dartfish.fi/)) {
		setCookie('gatereferrer','fi',null,'/');
		setCookie('langmenu','en',date,'/');
		showGateInfo('fi');
	}
	else if (referrer.match(/jp.dartfish.com/) || referrer.match(/dartfish.co.jp/)) {
		setCookie('gatereferrer','jp',null,'/');
		setCookie('langmenu','en',date,'/');
		showGateInfo('jp');
	}
	else if (referrer.match(/kr.dartfish.com/) || referrer.match(/dartfish.co.kr/)) {
		setCookie('gatereferrer','kr',null,'/');
		setCookie('langmenu','en',date,'/');
		showGateInfo('kr');
	}
	else if (referrer.match(/dartfish.ru/)) {
		setCookie('gatereferrer','ru',null,'/');
		setCookie('langmenu','en',date,'/');
		showGateInfo('ru');
	}
	else if (referrer.match(/dartfish.se/)) {
		setCookie('gatereferrer','se',null,'/');
		setCookie('langmenu','en',date,'/');
		showGateInfo('se');
	}
	else if (referrer.match(/uk.dartfish.com/) || referrer.match(/dartfish.co.uk/)) {
		setCookie('gatereferrer','uk',null,'/');
		setCookie('langmenu','en',date,'/');
		showGateInfo('uk');
	}
	else if (referrer.match(/us.dartfish.com/) || referrer.match(/dartfish.us/)) {
		setCookie('gatereferrer','us',null,'/');
		setCookie('langmenu','en',date,'/');
		showGateInfo('us');
	}
	else if (cookieinfo)	{
		showGateInfo(cookieinfo);
	}
}

// -----------------------------------------------

function showGateInfo(gate)	{
	/*console.log('showGateInfo',gate);
	//alert('ups');
	console.log($('gateretourn'));
	
	if (gate == 'au')
		new Element('a', {
		    'href': 'http://mootools.net',
   			'class': 'gateau',
			'id': 'logogate'

		}).inject($('gateretourn'),'before');
	else if (gate == 'cz')
		new Insertion.Before('gateretourn', '<a href="http://www.dartfish.cz" id="logogate" class="gatecz"></a>');
	else if (gate == 'dk')
		new Insertion.Before('gateretourn', '<a href="http://www.dartfish.dk" id="logogate" class="gatedk"></a>');
	else if (gate == 'fi')
		new Insertion.Before('gateretourn', '<a href="http://www.dartfish.fi" id="logogate" class="gatefi"></a>');
	else if (gate == 'jp')
		new Insertion.Before('gateretourn', '<a href="http://www.dartfish.co.jp" id="logogate" class="gatejp"></a>');
	else if (gate == 'kr')
		new Insertion.Before('gateretourn', '<a href="http://www.dartfish.co.kr" id="logogate" class="gatekr"></a>');
	else if (gate == 'ru')
		new Insertion.Before('gateretourn', '<a href="http://www.dartfish.ru" id="logogate" class="gateru"></a>');
	else if (gate == 'se')
		new Insertion.Before('gateretourn', '<a href="http://www.dartfish.se" id="logogate" class="gatese"></a>');
	else if (gate == 'uk')
		new Insertion.Before('gateretourn', '<a href="http://www.dartfish.co.uk" id="logogate" class="gateuk"></a>');
	else if (gate == 'us')
		new Insertion.Before('gateretourn', '<a href="http://www.dartfish.us" id="logogate" class="gateus"></a>');
		*/
}

//addEvent(window, "load", checkReferrer);