function selectEmbedText( anEvent , sender )
{
	sender.select();
}

function rolloverstate(boxName,msgbox){
    document.getElementById(boxName).style.display='none';
    document.getElementById(msgbox).style.display='block';
}

function rolloutstate(boxName,msgbox){
	
	document.getElementById(msgbox).style.display='none';
	document.getElementById(boxName).style.display='block';	
}



function omniLinkCall(element,omniTag) {
	setOmniValues(element,'o',omniTag,'','','',0,'','');
	}

/*** TAB SWITCHER ***/
var tabSwitcher = new Class({
	initialize: function(containerId,defaultPane) {
		this.myPanes = $(containerId).getElements('.pane');
		this.myTabs = $(containerId).getElements('.tabs li a');
		this.myTabs.each(function(tabItem) {
			if (tabItem.hasClass(defaultPane)) {
				tabItem.addClass('on');
			}
			tabItem.addEvent("click", function(event) {
				this.showTab(tabItem);
				return false;	
			}.bind(this));
		}.bind(this));	
		this.myPanes.each(function(paneItem) {
			if (paneItem.hasClass(defaultPane)) {
				paneItem.addClass('on');
			}
		});	
	},
	showTab: function(tabTarget) {
		this.myTabs.each(function(tabItem) {
			tabItem.removeClass('on');
		}.bind(this));
		this.myPanes.each(function(paneItem) {
			if (paneItem.hasClass(tabTarget.className)) {
				paneItem.addClass('on');
			} else {
				paneItem.removeClass('on');	
			}
		}.bind(this));
		tabTarget.addClass('on');
	}
});


var globalOverlay = new Class({
	initialize: function(triggerId,targetId,active) {
		this.myTrigger = $(triggerId);
		this.myTarget = $(targetId);
		this.myTrigger.addEvent("click", function(event) {
			this.loadSelector();
			event = new Event(event).stop();
		}.bind(this));	
		if (active == "true") {
			this.loadSelector();
		} 
	},
	loadSelector: function() {
        this.showOverlay();
	},
	showOverlay: function() {
		this.myTarget.setStyle('display','block');
	},
	hideOverlay: function() {
		this.myTarget.setStyle('display','none');
	}
});

var selectLocale = new Class({
	initialize: function(selectorId,targetId) {
		(document.location.href.search(/ea.com/) > 0) ? this.myDomain = ".ea.com" : this.myDomain = "";
		this.mySelector = $(selectorId);
		this.myTarget = $(targetId);
		this.myClose = $(targetId).getElement('.close');
		this.myLinks = this.mySelector.getElements('a');
		this.myClose.addEvent("click", function(event) {
			this.hideOverlay();
			event = new Event(event).stop();
		}.bind(this));
		this.myLinks.each(function(linkItem) {
			linkItem.addEvent("click", function(event) {
				var localeCode = linkItem.hreflang;
				this.setLocale(localeCode);
				if (linkItem.href == "http://shift.needforspeed.com/") {
					this.hideOverlay();
					event = new Event(event).stop();
				} 
			}.bind(this));
		}.bind(this));
	},
	setLocale: function(localeCode) {
		Cookie.set('nfsshift_locale', localeCode, {duration: "14", domain: this.myDomain});
	},
	hideOverlay: function() {
		this.myTarget.setStyle('display','none');	
	}
});

function confirmExtLegal(){
	var acceptsTerms = "You are about to leave the Electronic Arts website and go to a website owned by a third party.  Electronic Arts is not responsible for content on third party sites, and our privacy policy does not apply to their information collection practices.  Press OK to access the linked site or press CANCEL to return to your original page.";
	return confirm(acceptsTerms);	
}
function confirmLegal(){
	var acceptsTerms = "Terms & Conditions of Downloading Materials\n\nThe materials provided on this web site are provided \"as is\" without warranties of any kind.  Electronic Arts Inc., its subsidiaries, divisions, affiliates and licensors (\"EA\") disclaim all warranties, either express of implied, including but not limited to, warranties of merchantability and fitness for a particular purpose. To the extent allowed by applicable law, in no event will EA be liable for damages of any kind to your hardware, peripherals or software programs as a result of your download or use of our materials.\n\n You may download one copy of the materials onto a single computer for your personal, non-commercial, home use only, provided you keep intact all copyright, trademark and other proprietary notices.  No materials from this web site may be copied, reproduced, modified, republished, uploaded, posted, transmitted, broadcast or distributed in any way without the express written consent of EA.  Unauthorized use of the materials is a violation of EA's copyright and constitutes infringement of EA's proprietary rights.\n\nTo use these materials, you must agree to the above terms and conditions.  To accept this agreement and proceed with the download, click \"OK\" or click \"Cancel\" to decline.";	
	return confirm(acceptsTerms);
}


/*** QUICKNAV CODE ***/
var quickNav = new Class({
    initialize: function(containerID,eTrigger){
		this.navBox = $(containerID);
		if(!this.navBox) {
			return;	
		}		
		this.trigger = this.navBox.getElement('.starter');
		this.menu = this.navBox.getElement('.secondary');
		this.outerMenu = this.navBox.getElement('.triggerBox');
		this.menu.style.visibility = "visible";

		this.menuEffect = new Fx.Slide(this.menu, {
			duration: 300,
			transition: Fx.Transitions.Cubic.easeIn
		});

		this.menuEffect.hide();

		if (eTrigger == "hover") {

			this.trigger.addEvent("mouseenter", function(e) {
				this.menuEffect.stop();		
				this.outerMenu.addClass('openTrigger');
				if(!this.trigger.hasClass('isActive')){
					this.trigger.addClass('isActive');
				}
				this.menuEffect.slideIn();
			}.bind(this));

			this.outerMenu.addEvent("mouseleave", function(e) {
				this.menuEffect.stop();										   
				this.menuEffect.slideOut().chain(function() {
					this.outerMenu.removeClass('openTrigger');
				}.bind(this));
				if(this.trigger.hasClass('isActive')){
					this.trigger.removeClass('isActive');
				}
			}.bind(this));

		} else if (eTrigger == "click") {

			this.trigger.addEvent("click", function(e) {
				e = new Event(e);													
				this.menuEffect.toggle();
				e.stop();
			}.bind(this));

		}


	}

});


/*** IE HOVER FIX ***/
var ieHoverFix = new Class({
    initialize: function(containerID){
		this.container = $(containerID);
		this.navItems = this.container.getElements('.hoverfix');
		this.navItems.each(function(navItem, index) {
			navItem.addEvent("mouseenter", function(event) {
				navItem.addClass("hover");
			}.bind(this));
			navItem.addEvent("mouseleave", function(event) {
				navItem.removeClass("hover");
			}.bind(this));
		}.bind(this));
	}
});


// function for showing poll results
function submitPollVote() {
	$('pollform').send({
		onSuccess: function(html) {
			$('pollQuestion').innerHTML = html;
		},
		onFailure: function(html) {
			console.log("I'd be displaying an error now");
		},
		onUpdate: function() {
			$('pollQuestion').innerHTML = '<p>Loading...</p>';
		}
	});
}

// gus functions
function personaRedirect() {
	var returnTo = encodeURIComponent(this.document.location);
	var personaLink = $('gusChangePersona').getProperty('href');
	if (personaLink.indexOf('?') > -1) {
		if (personaLink.indexOf('&') > -1) {
			personaLink = personaLink + "&";
		}
	} else {
		personaLink = personaLink + "?";
	}
	this.document.location = personaLink + "surl=" + returnTo;
}
function logoutRedirect() {
	var returnTo = encodeURIComponent(this.document.location);
	var logoutLink = $('gus_logout_link').getProperty('href');
	if (logoutLink.indexOf('?') > -1) {
		if (logoutLink.indexOf('&') > -1) {
			logoutLink = logoutLink + "&";
		}
	} else {
		logoutLink = logoutLink + "?";
	}
	this.document.location = logoutLink + "&surl=" + returnTo;
}
function loginRedirect() {
	var returnTo = encodeURIComponent(this.document.location);
	var loginLink = $('gus_login_link').getProperty('href');
	this.document.location = loginLink + "&surl=" + returnTo;
}
function registerRedirect() {
	var returnTo = encodeURIComponent(this.document.location);
	var regLink = $('gus_register_link').getProperty('href');
	this.document.location = regLink + "&surl=" + returnTo;
}

function openPopup(url, name, width, height, status, scrollbars, moreProperties) {
	var agent = navigator.userAgent.toLowerCase();
	var x, y = 0;
	if (screen) {
      x = (screen.availWidth - width) / 2;
      y = (screen.availHeight - height) / 2;
   }
   if (!status) status = '';

	// Adjust width if scrollbars are used (pc places scrollbars inside the content area; mac outside)
	width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;

	var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');

	winReference = window.open(url, name, properties);
	return winReference;
}

window.addEvent('domready', function() {
	if ($defined($('gus_ea'))) {
		var gusNavEAMenu = new quickNav('gus_ea','click');
	}
	if ($defined($('gus_welcome')) && $defined($('gusWelcome'))) {
		if (loggedinMenuActive) var gusNavWelcomeMenu = new quickNav('gus_welcome','click');
	}
});
