function foo() {
}
function buyLoggedIn(storeName, offerId, type, amount, event) {
	document.getElementById('storeInfo').innerHTML = storeName;
	if (type == 'percentage') {
		document.getElementById('cashbackInfo').innerHTML = amount + '% of anything you buy';
	} else {
		document.getElementById('cashbackInfo').innerHTML = amount + '$ ';
	}
	
	document.getElementById('textLoggedIn').style.display = 'block';
	document.getElementById('textLoggedOut').style.display = 'none';
	if (existsCookie('noInfoBox'))
		location.href = 'http://' + location.host + '/company/offerRedirect.do?offerId=' + offerId;
	else
		displayInfoBox(offerId, event, true);
}
function buyLoggedOut(offerId, event) {
	document.getElementById('textLoggedIn').style.display = 'none';
	document.getElementById('textLoggedOut').style.display = 'block';
	if (existsCookie('noInfoBox'))
		location.href = 'http://' + location.host + '/company/offerRedirect.do?offerId=' + offerId;
	else
		displayInfoBox(offerId, event, false);
}
function displayInfoBox(offerId, event, loggedIn) {
	if (event.stopPropagation) {
		 event.stopPropagation(); 
	} else {
		event.cancelBubble = true;
	}
	
	if (document.getElementById('evilForm')) {
		document.getElementById('evilForm').style.display = 'none';
	}
	
	var shade = document.getElementById('shade');
	var infoBox = document.getElementById('infoBox');
	
/*	if (document.all) {
		shade.className = 'shadeIe';
		infoBox.className = 'infoBoxIe';
	}*/
	
	if (window.innerWidth) {
		// Phi = 1.618
		// 1 / 1.618 = .618
		// 1 / (1 - .618) = 2.62
		infoBox.style.marginTop = (window.pageYOffset + Math.round(window.innerHeight / 2.62) - 150) + 'px';
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		infoBox.style.marginTop = (document.documentElement.scrollTop + Math.round(document.documentElement.clientHeight / 2.62) - 150) + 'px';
	}
	else if (document.body.clientWidth) {
		infoBox.style.marginTop = (document.body.scrollTop + Math.round(document.body.clientHeight / 2.62) - 150) + 'px';		
	}
	
	shade.style.width = document.documentElement.scrollWidth + 'px';
	shade.style.height = document.documentElement.scrollHeight + 'px';
	shade.style.display = 'block';

	document.getElementById('continueButton').href = '/company/offerRedirect.do?offerId=' + offerId;
	document.getElementById('continueButton').onclick = function() {
		shade.style.display = 'none';
		if (!loggedIn) {
			displayStopSignStores(offerId);
			return false;
		}
		if (document.getElementById('evilForm')) {
			document.getElementById('evilForm').style.display = 'block';
		}
		openWindow(this.href);
		return false;
	}
	document.getElementById('cancelButton').onclick = function() {
		shade.style.display = 'none';
		return false;
	}

	shade.onclick = function() {
		shade.style.display = 'none';
	}
	infoBox.onclick = function(event) {
		if(!event) event = window.event;
		if (event.stopPropagation) {
			 event.stopPropagation(); 
		} else {
			event.cancelBubble = true;
		}
	}
	infoBox.getElementsByTagName('input')[0].onchange = function(event) {
		if (this.checked) createCookie('noInfoBox', '1', 365);
		else removeCookie('noInfoBox');
	}
}
function buyLoggedIn2(storeName, offerId, type, amount) {
	document.getElementById('storeInfo').innerHTML = storeName;
	if (type == 'percentage') {
		document.getElementById('cashbackInfo').innerHTML = amount + '% of anything you buy';
	} else {
		document.getElementById('cashbackInfo').innerHTML = amount + '$ ';
	}
	
	document.getElementById('textLoggedIn').style.display = 'block';
	document.getElementById('textLoggedOut').style.display = 'none';
	if (existsCookie('noInfoBox'))
		location.href = 'http://' + location.host + '/company/offerRedirect.do?productid=' + offerId;
	else
		displayInfoBox2(offerId);
}

function buyLoggedIn3(storeName, offerId, type, amount, offerMsg) {
	document.getElementById('storeInfo').innerHTML = storeName;
	if (type == 'percentage') {
		document.getElementById('cashbackInfo').innerHTML = amount + '% of anything you buy';
	} else {
		document.getElementById('cashbackInfo').innerHTML = amount + '$ ';
	}
	
	document.getElementById('textLoggedIn').style.display = 'block';
	document.getElementById('textLoggedOut').style.display = 'none';
	if (existsCookie('noInfoBox'))
		location.href = 'http://' + location.host + '/company/offerRedirect.do?productid=' + offerId;
	else
		displayInfoBox3(offerId, offerMsg, 1);
}

function buyLoggedOut2(offerId) {
	document.getElementById('textLoggedIn').style.display = 'none';
	document.getElementById('textLoggedOut').style.display = 'block';
	if (existsCookie('noInfoBox'))
		location.href = 'http://' + location.host + '/company/offerRedirect.do?productid=' + offerId;
	else
		displayInfoBox2(offerId);
}
function buyLoggedOut3(offerId, offerText) {
	document.getElementById('textLoggedIn').style.display = 'none';
	document.getElementById('textLoggedOut').style.display = 'block';
	if (existsCookie('noInfoBox'))
		location.href = 'http://' + location.host + '/company/offerRedirect.do?productid=' + offerId;
	else
		displayInfoBox3(offerId, offerText, 0);
}
function displayInfoBox2(offerId) {
	var shade = document.getElementById('shade');
	var infoBox = document.getElementById('infoBox');
	
/*	if (document.all) {
		shade.className = 'shadeIe';
		infoBox.className = 'infoBoxIe';
	}*/
	
	if (window.innerWidth) {
		infoBox.style.marginTop = (window.pageYOffset + Math.round(window.innerHeight / 2.62) - 150) + 'px';
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		infoBox.style.marginTop = (document.documentElement.scrollTop + Math.round(document.documentElement.clientHeight / 2.62) - 150) + 'px';
	}
	else if (document.body.clientWidth) {
		infoBox.style.marginTop = (document.body.scrollTop + Math.round(document.body.clientHeight / 2.62) - 150) + 'px';		
	}
	
	shade.style.width = document.documentElement.scrollWidth + 'px';
	shade.style.height = document.documentElement.scrollHeight + 'px';
	shade.style.display = 'block';

	document.getElementById('continueButton').href = '/company/offerRedirect.do?productid=' + offerId;
	document.getElementById('continueButton').onclick = function() {
		shade.style.display = 'none';
		openWindow(this.href);
		return false;
	}
	document.getElementById('cancelButton').onclick = function() {
		shade.style.display = 'none';
		return false;
	}

	shade.onclick = function() {
		shade.style.display = 'none';
	}
	infoBox.onclick = function(event) {
		if(!event) event = window.event;
		if (event.stopPropagation) {
			 event.stopPropagation(); 
		} else {
			event.cancelBubble = true;
		}
	}
	infoBox.getElementsByTagName('input')[0].onchange = function(event) {
		if (this.checked) createCookie('noInfoBox', '1', 365);
		else removeCookie('noInfoBox');
	}
}

function displayInfoBox3(offerId, offerMsg, loggedIn) {
	var shade = document.getElementById('shade');
	var infoBox = document.getElementById('infoBox');

/*	if (document.all) {
		shade.className = 'shadeIe';
		infoBox.className = 'infoBoxIe';
	}*/
	
	if (window.innerWidth) {
		infoBox.style.marginTop = (window.pageYOffset + Math.round(window.innerHeight / 2.62) - 150) + 'px';
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		infoBox.style.marginTop = (document.documentElement.scrollTop + Math.round(document.documentElement.clientHeight / 2.62) - 150) + 'px';
	}
	else if (document.body.clientWidth) {
		infoBox.style.marginTop = (document.body.scrollTop + Math.round(document.body.clientHeight / 2.62) - 150) + 'px';		
	}
	
	shade.style.width = document.documentElement.scrollWidth + 'px';
	shade.style.height = document.documentElement.scrollHeight + 'px';
	shade.style.display = 'block';
	
	insertOfferMessage('offerText', offerMsg);

	/*if (offerMsg.length > 0)
		document.getElementById('offerText').innerHTML = "<b>Special offer: </b><br />" + offerMsg;
	else
		document.getElementById('offerText').innerHTML = "";*/

	document.getElementById('continueButton').href = '/company/offerRedirect.do?productid=' + offerId;
	document.getElementById('continueButton').onclick = function() {
		shade.style.display = 'none';
		
		if (!loggedIn) {
			displayStopSign(offerId);
			return false;
		}
		
		if (offerMsg == "bn") {
			alert('Attention Barnes & Noble shoppers:\n\nFor a temporary time, the Barnes & Noble purchases you make will not be posted to your EarthMoment profile page. You can still purchase Barnes & Noble products through this site, and CarbonFund.org will still receive their donation, but a temporary glitch is preventing the personal profile from updating automatically.\n\nHowever, we are happy to update your carbon reduction profile manually. Just send an e-mail to info@earthmoment.com requesting that your account be updated. \n\nWe apologize for the inconvenience, and hope to have this technical glitch fixed before Al Gore or Leo come out with sequels to their movies!\n\n--Thank you for shopping EarthMoment');
		}
		openWindow(this.href);
		return false;
	}
	document.getElementById('cancelButton').onclick = function() {
		shade.style.display = 'none';
		return false;
	}

	shade.onclick = function() {
		shade.style.display = 'none';
	}
	infoBox.onclick = function(event) {
		if(!event) event = window.event;
		if (event.stopPropagation) {
			 event.stopPropagation(); 
		} else {
			event.cancelBubble = true;
		}
	}
	infoBox.getElementsByTagName('input')[0].onchange = function(event) {
		if (this.checked) createCookie('noInfoBox', '1', 365);
		else removeCookie('noInfoBox');
	}
	
}

function displayStopSign(offerId)
{
	var stopsign = document.getElementById('stopsign');
	var shade = document.getElementById('shade2');
	
	if (window.innerWidth) {
		stopsign.style.marginTop = (window.pageYOffset + Math.round(window.innerHeight / 2.62) - 150) + 'px';
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		stopsign.style.marginTop = (document.documentElement.scrollTop + Math.round(document.documentElement.clientHeight / 2.62) - 150) + 'px';
	}
	else if (document.body.clientWidth) {
		stopsign.style.marginTop = (document.body.scrollTop + Math.round(document.body.clientHeight / 2.62) - 150) + 'px';		
	}
	
	shade.style.width = document.documentElement.scrollWidth + 'px';
	shade.style.height = document.documentElement.scrollHeight + 'px';
	shade.style.display = 'block';
	
	shade.onclick = function() {
		shade.style.display = 'none';
	}
	
	document.getElementById('cancelButton2').onclick = function() {
		shade.style.display = 'none';
		return false;
	}
	
	stopsign.onclick = function(event) {
		if(!event) event = window.event;
		if (event.stopPropagation) {
			 event.stopPropagation(); 
		} else {
			event.cancelBubble = true;
		}
	}

	document.getElementById('continueButton2').href = '/company/offerRedirect.do?productid=' + offerId;
	document.getElementById('continueButton2').onclick = function() {
		shade.style.display = 'none';
		openWindow(this.href);
		return false;
	}	
}

function displayStopSignStores(offerId)
{
	var stopsign = document.getElementById('stopsign');
	var shade = document.getElementById('shade2');
	
	if (window.innerWidth) {
		stopsign.style.marginTop = (window.pageYOffset + Math.round(window.innerHeight / 2.62) - 150) + 'px';
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		stopsign.style.marginTop = (document.documentElement.scrollTop + Math.round(document.documentElement.clientHeight / 2.62) - 150) + 'px';
	}
	else if (document.body.clientWidth) {
		stopsign.style.marginTop = (document.body.scrollTop + Math.round(document.body.clientHeight / 2.62) - 150) + 'px';		
	}
	
	shade.style.width = document.documentElement.scrollWidth + 'px';
	shade.style.height = document.documentElement.scrollHeight + 'px';
	shade.style.display = 'block';
	
	shade.onclick = function() {
		shade.style.display = 'none';
	}
	
	document.getElementById('cancelButton2').onclick = function() {
		shade.style.display = 'none';
		return false;
	}
	
	stopsign.onclick = function(event) {
		if(!event) event = window.event;
		if (event.stopPropagation) {
			 event.stopPropagation(); 
		} else {
			event.cancelBubble = true;
		}
	}

	document.getElementById('continueButton2').href = '/company/offerRedirect.do?offerId=' + offerId;
	document.getElementById('continueButton2').onclick = function() {
		shade.style.display = 'none';
		openWindow(this.href);
		return false;
	}	
}

function insertOfferMessage(element, offerMsg)
{
	var id = document.getElementById(element);
	if (offerMsg.length > 0) {
		id.innerHTML = '<b>Special offer! <img src="/static/image/campaign_attentionv2.png" alt="Special offer available" title="Special offer available"/> </b><br />' + offerMsg;
	}
	else {
		id.innerHTML = "";
	}
	if (offerMsg == "bn") {
		id.innerHTML = "";
	}
}