var relloc = '/';

// Validate a given email address ------------------------------------------------------

validateEmail = function(email) {
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(email.match(emailRegEx)){
		return true;
	} else {
		return false;
	}
}

// Floating DIV functions

centerPopup = function(divid) {

	var eltDims = $(divid).getDimensions();
	var browserDims = $(document.body).getDimensions(); 

	//var y  = (browserDims.height - eltDims.height) / 2;
	var y = 20;
	var x = (browserDims.width - eltDims.width) / 2;

	var styles = { position : 'absolute',
	top      : y + 'px',
	left     : x + 'px' };

	$(divid).setStyle(styles);
	$(divid).scrollTo();

}

unfadeBackground = function() {
	new Effect.Opacity($('container'), { 
		from: 0.3, 
		to: 1.0, 
		duration: 0.5 
	});
} 

fadeBackground = function() {
	new Effect.Opacity($('container'), { 
		from: 1.0, 
		to: 0.3, 
		duration: 0.5 
	});
}

triggerPopup = function(divid) {
	fadeBackground();
	centerPopup(divid);
	new Effect.Appear($(divid));
	return false;
}

closePopup = function(divid) {
	new Effect.Fade($(divid));
	unfadeBackground();
}

userSurveyPopup = function() {
	new Ajax.Updater($('popup-container-content'), relloc + '_ajax/ajax_user_survey_form.php', {
		evalScripts: true,
		onComplete: function() {
			triggerPopup('popup-container');
		}
	});
	return false;
}

submit_survey = function() {
	$('survey_submit_btn').disabled = true;
	new Ajax.Request(relloc + '_ajax/ajax_user_survey_form_submit.php', {
		parameters: $('user_survey').serialize(),
		onSuccess:function() {
			alert('Thank you for completing our survey!');
			$('survey_submit_btn').disabled = false;
			closePopup('popup-container');
		},
		onFailure:function() {
			alert('Sorry, there has been a problem submitting your survey. Please try again.');
			$('survey_submit_btn').disabled = false;
		}
	});
}


