$(document).ready(function(){
	$('#imgEmailExclusives').click(	function() { showEmailExclusives(); } );
	$('#txtEmailExclusives').click( function() { $('#txtEmailExclusives').select(); } );
});
function showEmailExclusives() {
	$('#imgEmailExclusives').attr('src','/sitebase/wrap/theme0/images/btn.emailexclusives.on.jpg');
	$('#imgEmailExclusives').attr('class','');
	$('#imgSpecialOffers').attr('src','/sitebase/wrap/theme0/images/btn.specialoffers.off.jpg');
	$('#imgSpecialOffers').attr('class','clickable');
	$('#imgEmailExclusives').unbind('click');
	$('#imgSpecialOffers').click(	function() { showSpecialOffers(); } );
	$('#divEmailExclusives').show('fast');
	$('#divHomeSpecials').hide('fast');
}
function showSpecialOffers() {
	$('#imgEmailExclusives').attr('src','/sitebase/wrap/theme0/images/btn.emailexclusives.off.jpg');
	$('#imgEmailExclusives').attr('class','clickable');
	$('#imgSpecialOffers').attr('src','/sitebase/wrap/theme0/images/btn.specialoffers.on.jpg');
	$('#imgSpecialOffers').attr('class','');
	$('#imgEmailExclusives').click(	function() { showEmailExclusives(); } );
	$('#imgSpecialOffers').unbind('click');
	$('#divEmailExclusives').hide('fast');
	$('#divHomeSpecials').show('fast');
}

function checkValidEmailAddress() {
	var sEmail = $('#txtEmailExclusives').val();
	var boolSubmit = true;
	var msg = 'Please correct the following problem(s):\n\n';
	
	if (sEmail == '') {
		boolSubmit = false;
		msg = msg + '* Please enter a value for \'Email\'.\n';
	} else {
		var reIllegalEmail = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
		var reValidEmail = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if (reIllegalEmail.test(sEmail) || !reValidEmail.test(sEmail)) {
			boolSubmit = false;
			msg = msg + '* Please enter a valid Email Address.\n';
		}
	}

	if (boolSubmit) {
		return boolSubmit;
	} else {
		alert(msg);
		return boolSubmit;
	}
}
function sendEmail() {
	if (checkValidEmailAddress()) {
	
		$.post('email-signup.aspx',
			{ txtEmailExclusives: $('#txtEmailExclusives').val(),
			  from: 'index'
			 },
			function(xml) {
				var bSuccess = $(xml).find('success').text();
				var sMessage = $(xml).find('message').text();
				if (bSuccess) {
					$('#divEmailExclusives1').hide('fast');
					$('#divEmailExclusives2').show('fast');
					
				}
				else {
					var sAlert = "There was an error adding your email address.";
					if (sMessage.length > 0) sAlert += "/r/n" + sMessage;
					alert(sAlert);
				}
			}
		); 
	
	}
}
