function fadeItAll(callBack) {
	var theFader;	
	if ($('faderDiv') != null) {
		theFader = $('faderDiv');
	} else {
		theFader = document.createElement('div');
		document.body.appendChild(theFader);
	}
	
	theFader.setAttribute('id', 'faderDiv');
	theFader = $('faderDiv');
	
	lockScrollers();
	
	//Scriptaculous Size getter
	var theFaderSize = document.viewport.getDimensions();
	theFader.style.width 		= theFaderSize.width + 'px';
	theFader.style.height 		= theFaderSize.height + 'px';
	
	var theSrollOffsets = document.viewport.getScrollOffsets();
	theFader.style.top			= theSrollOffsets.top + 'px';
	theFader.style.left			= theSrollOffsets.left + 'px';
	
	theFader.style.position 	= 'absolute';
	theFader.style.zIndex 		= '850';
	theFader.style.background 	= '#000';
	theFader.style.display 		= 'none';
	//theFader.onclick			= unfadeItAll;
	
	Effect.Appear(theFader, { duration: .3, from: 0, to: .75, afterFinish: callBack } );
}

function unfadeItAll() {
	if ($('faderDiv') != null) {
		Effect.Fade($('faderDiv'), { duration: 0.3, from: 0.75,  to: 0.0, afterFinish: function() { unlockScrollers(); } } );
	}
}

function lockScrollers() {
}

function unlockScrollers() {
}

function showPopup(type, target, queryString) {
	fadeItAll();
	var thePopupBox;	
	if ($('thePopupBox') != null) {
		thePopupBox = $('thePopupBox');
	} else {
		thePopupBox = document.createElement('div');
		document.body.appendChild(thePopupBox);
	}
	
	thePopupBox.setAttribute('id', 'thePopupBox');
	thePopupBox = $('thePopupBox');
	
	//Scriptaculous Size getter
	if (type == "quote") {
		var boxWidth = 500;
		var boxHeight = 520;
		thePopupBox.addClassName('popupQuote');
	} else if (type == "login" || type == "newsletter") {
		var boxWidth = 500;
		var boxHeight = 180;
		thePopupBox.addClassName('popupLogin');
	} else {
		var boxWidth = 400;
		var boxHeight = 500;
	}
	
	thePopupBox.style.display 		= 'none';
	
	thePopupBox.style.width 	= String(boxWidth) + 'px';
	thePopupBox.style.height 	= String(boxHeight) + 'px';
	
	var theSrollOffsets		= document.viewport.getScrollOffsets();
	var theWindowSize 		= document.viewport.getDimensions();
	thePopupBox.style.top	= (theWindowSize.height / 2 - boxHeight / 2 + theSrollOffsets.top) + 'px';
	thePopupBox.style.left	= (theWindowSize.width / 2 - boxWidth / 2 + theSrollOffsets.left) + 'px';
	
	thePopupBox.style.position 	= 'absolute';
	thePopupBox.style.zIndex 		= '950';
	thePopupBox.innerHTML 			= '<center><img src="images/ajax-bar-green.gif" style="margin: ' + String(parseInt((boxHeight - 15) * .5)) + 'px auto auto auto;" /></center>';
	
	Effect.Appear(thePopupBox, { duration: .3, from: 0, to: 1.0, afterFinish: function() {
			new Ajax.Request(target, {
				method: 'post',
				parameters: queryString,
				onSuccess: function(transport) {
					thePopupBox.innerHTML = transport.responseText;
				}
			});
		} 
	});
}

function closePopupBox() {
	new Effect.Puff($('thePopupBox'), { duration: .5, afterFinish: function() {
			unfadeItAll();
		}
	});
}

function checkPopupEmailForm() {
	var isValid = true;
	
	if ($F('popupEmail_name') == '') {
		$('popupEmail_name').addClassName('errorHere');
		isValid = false;
	} else
		$('popupEmail_name').removeClassName('errorHere');
	
	if ($F('popupEmail_email') == '') {
		$('popupEmail_email').addClassName('errorHere');
		isValid = false;
	} else
		$('popupEmail_email').removeClassName('errorHere');
	
	if ($F('popupEmail_subject') == '') {
		$('popupEmail_subject').addClassName('errorHere');
		isValid = false;
	} else
		$('popupEmail_subject').removeClassName('errorHere');
		
	if ($F('popupEmail_body') == '') {
		$('popupEmail_body').addClassName('errorHere');
		isValid = false;
	} else
		$('popupEmail_body').removeClassName('errorHere');
	
	return isValid;
}

function showNewsletterResults(response) {
	$('newsletterFormContainer').innerHTML = response;

	$('newsletterFormLoaderGraphic').style.display = 'none';
	$('newsletterFormContainer').style.display = 'block';
}

function submitNewsletterForm() {
	//http://app.onmarketer.com/ListBuilder.ashx
	var queryString = $('newsletterForm').serialize();
	
	new Effect.Fade($('newsletterFormContainer'), { duration: .3, from: 1.0, to: 0.0, afterFinish: function() {
			$('newsletterFormLoaderGraphic').style.display = 'block';
			new Ajax.Request('http://app.onmarketer.com/ListBuilder.ashx', {
				method: 'post', 
				parameters: queryString,
				onSuccess: function(transport) {
					showNewsletterResults(transport.responseText);
				}
			});
		}
	});
}

function showEmailResults(responseHurf) {
	$('emailFormContainer').innerHTML = responseHurf;

	$('emailFormLoaderGraphic').style.display = 'none';
	$('emailFormContainer').style.display = 'block';
}

function sendPopupEmail() {
	var queryString = $('emailForm').serialize();
	
	new Effect.Fade($('emailFormContainer'), { duration: .3, from: 1.0, to: 0.0, afterFinish: function() {
			$('emailFormLoaderGraphic').style.display = 'block';
			new Ajax.Request('staticfiles/popups/quote.php', {
				method: 'post', 
				parameters: queryString,
				onSuccess: function(transport) {
					showEmailResults(transport.responseText);
				},
				onFailure: function(transport) {
				},
				onComplete: function(transport) {
					showEmailResults(transport.responseText);
				}
			});
		}
	});
}