	var emailServices = new Object();
	emailServices['gmail'] = 'gmail.com';
	emailServices['hotmail'] = 'hotmail.com';
	emailServices['yahoo'] = 'yahoo.com';
	emailServices['aol'] = 'aol.com';

	var head = null;

var defaultTexts = new Object();

//------------ Omniture Tracking -------------
function onmi_trackClick(linkName) {
/*
	linkName += ' click';
	var s=s_gi(s_account);
	s.linkTrackVars="eVar1,events";
	s.linkTrackEvents="event4";
	s.eVar1=linkName;
	s.events="event4";
	s.tl(this,'o',linkName.toLowerCase()); 
*/
}
//------------ End Omniture Tracking -------------

function loadJSDynamic(jsUrl, onLoad) {
	var jscript = document.createElement('script');
	jscript.type = 'text/javascript';
	jscript.src = jsUrl;

	if( onLoad != null) {
		jscript.onload = onLoad;
		jscript.onReadyStateChange = onLoad;
	}

	if( head == null ) {
		head = document.getElementsByTagName("head")[0];
	}

	if( head !=null ) {
		head.appendChild(jscript);
	}
}

function switchShowFilters(id)
{
	var id_img = id + "HeaderImg";
	var id_list = id + "List";
	//var arr_list = new Array("rewardsFilterCategoryList", "rewardsFilterPointsList", "rewardsFilterBrandList");
	if (id == "rewardsFilterCategory")
	{
		swapList('rewardsFilterCategoryList');
		swapHeader('rewardsFilterCategory', '/images/btn_filter_category');
		collapse('rewardsFilterBrandList');
		swapHeader('rewardsFilterBrand', '/images/btn_filter_brand');
		collapse('rewardsFilterPointsList');
		swapHeader('rewardsFilterPoints', '/images/btn_filter_points');
	}
	if (id == "rewardsFilterPoints")
	{
		swapList('rewardsFilterPointsList');
		swapHeader('rewardsFilterPoints', '/images/btn_filter_points');
		collapse('rewardsFilterCategoryList');
		swapHeader('rewardsFilterCategory', '/images/btn_filter_category');
		collapse('rewardsFilterBrandList');
		swapHeader('rewardsFilterBrand', '/images/btn_filter_brand');
	}
	if (id == "rewardsFilterBrand")
	{
		swapList('rewardsFilterBrandList');
		swapHeader('rewardsFilterBrand', '/images/btn_filter_brand');
		collapse('rewardsFilterPointsList');
		swapHeader('rewardsFilterPoints', '/images/btn_filter_points');
		collapse('rewardsFilterCategoryList');
		swapHeader('rewardsFilterCategory', '/images/btn_filter_category');
	}
}


function collapse(id)
{
	if (document.getElementById(id).style.display == "block")
	{
		document.getElementById(id).style.display = "none";
	}
}


function swapList(id)
{
	if (document.getElementById(id).style.display == "block")
	{
		document.getElementById(id).style.display = "none";
	}
	else
	{
		document.getElementById(id).style.display = "block";
	}
}


function swapHeader(id, img)
{
	if (document.getElementById(id + 'List').style.display == "block")
	{
		document.getElementById(id + 'HeaderImg').src = img + "_on.png";
	}
	else
	{
		document.getElementById(id + 'HeaderImg').src = img + "_off.png";
	}
}

function preload(images)
{
	if (document.images)
	{
		var i = 0;
		var imageArray = new Array();
		imageArray = images.split(',');
		var imageObj = new Image();
		for(i=0; i<=imageArray.length-1; i++)
		{
			//document.write('<img src="' + imageArray[i] + '" />');// Write to page (uncomment to check images)
			imageObj.src=images[i];
		}
	}
}

function overlayReward(num)
{
	//document.getElementById("featuredReward" + num).style.display = 'none';
	x = (num*125)+442;
	document.getElementById("featuredRewardOverlay" + num).style.display = 'inline';
	document.getElementById("featuredRewardOverlay" + num).style.top = '495';
	document.getElementById("featuredRewardOverlay" + num).style.left = x;
}

function hideOverlayReward(num)
{
	document.getElementById("featuredRewardOverlay" + num).style.display = 'none';
	//document.getElementById("featuredReward" + num).style.display = 'block';
}

function overlayFeatured(num)
{
	x = ((num-1)*198)+157;
	var overlay = $("rewardsFeaturedOverlay" + num);
	overlay.setStyle({
		display: 'inline',
		top: 222,
		left: x
	});

	/*
	document.getElementById("rewardsFeaturedOverlay" + num).style.display = 'inline';
	document.getElementById("rewardsFeaturedOverlay" + num).style.top = 222;
	document.getElementById("rewardsFeaturedOverlay" + num).style.left = x;
	*/
	//alert('this should be an overlay');
}

function hideOverlayFeatured(num)
{
	document.getElementById("rewardsFeaturedOverlay" + num).style.display = 'none';
}

function earnWizard(id)
{
	document.getElementById('earnWizardImg').src = id;
}

//--------------------| Textboxes, default text


function clearDefault(elId) {
	$(elId).removeClassName('defaultText');

	if($F(elId) == defaultTexts[elId]) {
		$(elId).value = '';
	}

}

function updateDefaultOnFocus() {
	var elId = this.id;
	var defaultText = defaultTexts[elId];

	$(elId).removeClassName('defaultText');

	if($F(elId) == defaultText) {
		$(elId).value = '';
	}

}

function updateDefaultOnBlur() {
	var elId = this.id;
	var defaultText = defaultTexts[elId];


	if(!$(elId).present()) {
		$(elId).value = defaultText;
		$(elId).addClassName('defaultText');
	}

}


function setDefaultText(elId, defaultText) {
	defaultTexts[elId] = defaultText;

	var myElement = $(elId);
	if( myElement != null ) {
		myElement.observe('focus', updateDefaultOnFocus);
		myElement.observe('blur', updateDefaultOnBlur);

		if(!myElement.present()) {
			myElement.addClassName('defaultText');
			myElement.value = defaultText;
		}
	}
}

//---------------------| Lightboxes
function showRegformLightbox() {
	var s=s_gi(s_account);
	s.linkTrackVars="events";
	s.linkTrackEvents="event1";
	s.events="event1";
	s.tl(this,'o','Signup Form Shown'); 
	
	showLightbox('/account/register');
}

function showRegform2Lightbox() {
	showLightbox('/account/regform2');
}

function showInviteLightbox() {

	linkName = 'Invite My Friends click';
	var s=s_gi(s_account);
	s.linkTrackVars="eVar1,events";
	s.linkTrackEvents="event4";
	s.eVar1=linkName;
	s.events="event4";
	s.tl(this,'o',linkName.toLowerCase()); 

	showLightbox('/invitations/login');
}

function showMillionaireLightbox() {
	showLightbox('/millionaire/index');
}

function showLightbox(url) {
		new Ajax.Updater('lightbox', url, {
			evalScripts: true,
			onComplete: function() { 
				$('lightbox').setStyle({display: 'none'});
				$('lightboxOverlay').setStyle({display: 'block'});
				Effect.Grow('lightbox', {duration: 0.5, direction: 'top-left'});
			}
		});

    var arrayPageSize = this.getPageSize();
    $('lightboxOverlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
    $('lightboxTint').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });	
    
    

	Effect.Appear('lightboxTint', {duration: 0.75, from: 0, to: 0.2});
}

function closeLightbox() {
	Effect.Shrink('lightbox', {duration: 0.5, direction: 'top-left', afterFinish: hideOverlay});
	Effect.Fade('lightboxTint', {duration: 0.75, from: 0.2, to: 0});	
}

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

function hideOverlay() {
	$('lightboxOverlay').setStyle({display: 'none'});
	$('lightbox').innerHTML = '';
}

//--------------------------------------------------------------------
// showLogin
// Type: Common
//
// params: 
//      service - Label name for service, will identify the service
//				  to the user using this string
//		action -  url to post the form
//
//		title -	title of the content
//		content - body of the content
//
//--------------------------------------------------------------------

function showNeedToBeLoggedIn(forAction) { 
	alert('Please log in at the top of the page to ' + forAction);

/*
	var loginDiv = new Element('div', {'id': 'serviceLogin', 'class': 'overlayContainer', 'style': 'width: 400px; height: 110px; margin-top: 250px'});
	loginDiv.appendChild(new Element('div', {'class': 'overlaySubhead', 'style': 'color: black; font-size: large;'}).update('Please log in at the top of the page to ' + forAction));

	// Add the buttons
	var btnDiv = new Element('div', {'style': 'text-align: center; margin-top: 25px;'});
	var closeLink = new Element('a', {'href': '#', 'onclick': 'closeLightbox(); return false;'});
	var closeImg = new Element('img', {'src': '/images/btn_close.png', 'alt': 'Close'});
	closeLink.appendChild(closeImg);
	btnDiv.appendChild(closeLink);
	
	loginDiv.appendChild(btnDiv);
	
	$('lightbox').appendChild(loginDiv);
	$('lightbox').setStyle({display: 'none'});
	$('lightboxOverlay').setStyle({display: 'block'});
	Effect.Grow('lightbox', {duration: 0.5, direction: 'top-left'});	
	Effect.Appear('lightboxTint', {duration: 0.75, from: 0, to: 0.2});
*/

}


//-----------------| Facebook login
function finishFBLogin() {
	new Ajax.Request('/account/facebook_login', {
		method: 'get',
		evalJS: true,
		onSuccess: function(transport) {
			var json = transport.responseText.evalJSON(true);

			if(json.peer2_login === true) {
				window.location = window.location;
			} else if(  json.can_reg === true ) {
				showLightbox('/account/register');
			} else {
				// If something bad happened, the backend will have set the 
				// proper flash error message, direct the user to login to
				// be able to see it
				window.location.href = '/account/login';
			}
		},
		onException: function(request, exception) {
			alert('exception: ' + exception);
		}
	});
}

//-----------------| Invitation stuff
	function updateEmailService(service) {
		$('serviceAt').update('@' + emailServices[service]);
		$('service').value = service;
	 }

	function selectAllCheckboxes(target) {
		var selectAlls = $$('.selectAllTarget');

		for(var i=0; i < selectAlls.length; i++) {
			selectAlls[i].checked = target.checked;
		}
	}
	
	
//--------------------------------------------------------------------------------
// Borrowed from Lightbox
// http://www.huddletogether.com/projects/lightbox2/#download
//--------------------------------------------------------------------------------
function getPageSize() {
	        
    var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}
