﻿
function getLang() {
	var nameEQ = 'playtv_language' + "=";
	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 setLang(L) {
	var date = new Date();
	date.setTime(date.getTime()+604800000);
	document.cookie = 'playtv_language='+escape(L)+'; expires='+date.toGMTString()+'; path=/';
}
function twoToFour(lang) {
	switch(lang) {
		case 'de': return 'de_DE'; break;
		case 'fr': return 'fr_FR'; break;
		case 'es': return 'es_ES'; break;
		case 'it': return 'it_IT'; break;
		case 'au': return 'en_AU'; break;
		case 'en': default: return 'en_GB';
	}
}
function footerSetup() {
	$('#lang_select').change(function() {
		var lang = $(this).val();
		setLang(lang);
		window.location = '/'+twoToFour(lang)+'/';
	});
	$('a.popup').each(function() {
		$(this).click(function() {
			var loc = $(this).attr('href');
			window.open( loc,'popup','width=670, height=450, scrollbars=yes, resizable=1' );
			return false;
		});
	});
	$('a.popup_small').each(function() {
		$(this).click(function() {
			var loc = $(this).attr('href');
			window.open( loc,'popup','width=300, height=300, scrollbars=yes, resizable=1' );
			return false;
		});
	});
}

$(document).ready(function() {
	$('#page_questions #content p').each(function() {
		if( $(this).children('b').length == 0 ) {
			$(this).hide();
		}
	});
	$('#page_questions #content p b').css('cursor', 'pointer');
	$('#page_questions #content p b').click(function() {
		$(this).parent().next('p').toggle();
	});
	footerSetup();
});
function setLanguage(lang) {
	switch(lang) {
		case 'de':
			setLang(lang);
			$('#footer_content li.first img').attr('src', '/images/de_flag.gif');
			$('#lang_select').val('de');
			$('#footer_content .corp').html('<a href="/de_DE/popUps/corporate.html" target="popup" class="popup_small">Über uns</a>');
			$('#footer_content .terms').html('<a href="/de_DE/popUps/terms.html" target="popup" class="popup">Nutzungsbedingungen</a>');
			$('#footer_content .priv').html('<a href="/de_DE/popUps/privacy.html" target="popup" class="popup">Datenschutzerklärung</a>');
			$('#footer_content .playstation').html('<a href="http://de.playstation.com" target="playstation">eu.playstation.com</a>');
		break;
		
		case 'fr':
			setLang(lang);
			$('#footer_content li.first img').attr('src', '/images/fr_flag.gif');
			$('#lang_select').val('fr');
			$('#footer_content .corp').html('<a class="popup_small" target="popup" href="/fr_FR/popUps/corporate.html">À propos</a>');
			$('#footer_content .terms').html('<a class="popup" target="popup" href="/fr_FR/popUps/terms.html">Conditions d\'utilisation</a>');
			$('#footer_content .priv').html('<a class="popup" target="popup" href="/fr_FR/popUps/privacy.html">Politique de confidentialité</a>');
			$('#footer_content .playstation').html('<a target="playstation" href="http://fr.playstation.com">eu.playstation.com</a>');
		break;
		
		case 'es':
			setLang(lang);
			$('#footer_content li.first img').attr('src', '/images/es_flag.gif');
			$('#lang_select').val('es');
			$('#footer_content .corp').html('<a href="/es_ES/popUps/corporate.html" target="popup" class="popup_small">Acerca de nosotros</a>');
			$('#footer_content .terms').html('<a href="/es_ES/popUps/terms.html" target="popup" class="popup">Condiciones de uso</a>');
			$('#footer_content .priv').html('<a href="/es_ES/popUps/privacy.html" target="popup" class="popup">Política de privacidad</a>');
			$('#footer_content .playstation').html('<a href="http://es.playstation.com" target="playstation">eu.playstation.com</a>');
		break;
		
		case 'it':
			setLang(lang);
			$('#footer_content li.first img').attr('src', '/images/it_flag.gif');
			$('#lang_select').val('it');
			$('#footer_content .corp').html('<a class="popup_small" target="popup" href="/it_IT/popUps/corporate.html">Informazioni su</a>');
			$('#footer_content .terms').html('<a class="popup" target="popup" href="/it_IT/popUps/terms.html">Termini di utilizzo</a>');
			$('#footer_content .priv').html('<a class="popup" target="popup" href="/it_IT/popUps/privacy.html">Tutela della privacy</a>');
			$('#footer_content .playstation').html('<a target="playstation" href="http://it.playstation.com">eu.playstation.com</a>');
		break;
		
		case 'en':
			setLang(lang);
			$('#footer_content li.first img').attr('src', '/images/en_flag.gif');
			$('#lang_select').val('en');
			$('#footer_content .corp').html('<a href="/en_GB/popUps/corporate.html" target="popup" class="popup_small">About Us</a>');
			$('#footer_content .terms').html('<a href="/en_GB/popUps/terms.html" target="popup" class="popup">Terms of Use</a>');
			$('#footer_content .priv').html('<a href="/en_GB/popUps/privacy.html" target="popup" class="popup">Privacy Policy</a>');
			$('#footer_content .playstation').html('<a href="http://uk.playstation.com" target="playstation">eu.playstation.com</a>');
		break;

		case 'au':
			setLang(lang);
			$('#footer_content li.first img').attr('src', '/images/au_flag.gif');
			$('#lang_select').val('au');
			$('#footer_content .corp').html('<a href="/en_AU/popUps/corporate.html" target="popup" class="popup_small">About Us</a>');
			$('#footer_content .terms').html('<a href="/en_AU/popUps/terms.html" target="popup" class="popup">Terms of Use</a>');
			$('#footer_content .priv').html('<a href="/en_AU/popUps/privacy.html" target="popup" class="popup">Privacy Policy</a>');
			$('#footer_content .playstation').html('<a href="http://au.playstation.com" target="playstation">au.playstation.com</a>');
		break;
	}
	
	// Re bind the on change
	footerSetup();
}