﻿f1.isRegistered = function() {
    return (Cookie.get('USER') == false) ? false : true;
}

f1.isLoggedIn = function() {
	return (Cookie.get('LOGIN') == false) ? false : true;
}

f1.followRegisteredLink = function() {
	if (f1.isRegistered()) {
		return true;
	}

	alert('Please sign in');

	return false;
}

f1.followLoggedInLink = function() {
	if (f1.isLoggedIn()) {
		return true;
	}

	alert('Please sign in');

	return false;
}

f1.hideSignIn = function() {
	var signIn = $('signinFormContainer');

	if (signIn) {
		signIn.setStyle('display', 'none');

		window.addEvent('domready', function() {
			signIn.setStyle('display', 'none');
		}
		)
	}
}

f1.showSignOut = function() {
    if (f1.isRegistered() && f1.isLoggedIn()) {
        var myAnchor = new Element('a', {
            'href': '#',
            'class': 'logout logout_link',
            'events': {
                'click': function(e) {
                    e = new Event(e).stop();
                    if ((window.location.href + "").indexOf(".formula1.com") > 0)
                        Cookie.remove('LOGIN', { path: '/', domain: '.formula1.com' });
                    else
                        Cookie.remove('LOGIN', { path: '/' });
                    window.location = window.location;
                }
            }
        }).setHTML('Sign out').injectTop($('wrapperContent'));
    }
}

function popup(url, title) {
    popupwindow = window.open(url, title, "location=1,status=1,scrollbars=1,width=400,height=400");
    popupwindow.moveTo(0, 0);
} 

window.addEvent('domready', f1.showSignOut);
