
var s3mlsgn = 
{
	email : '',
	ie5 : (document.all && document.getElementById), 
	ns6 : (!document.all && document.getElementById), 
	opac : 0,  
	
	dosignup : function()
	{
		if (document.s3mlst && document.s3mlst.s3mlstemail)
		{
			if (!s3mlsgn.validemail(document.s3mlst.s3mlstemail.value))
			{
				s3mlsgn.highlight('i-ml-er');
			}
			else
			{
				s3mlsgn.s3mlreq(document.s3mlst.s3mlstemail.value);
			}
		}
	}, 
	
	swaptext : function(text, e)
	{
		if (e=='FOCUS')
		{
			if (document.s3mlst.s3mlstemail.value==text)
			{
				document.s3mlst.s3mlstemail.value = '';
			}
		}
		if (e=='BLUR')
		{
			if (document.s3mlst.s3mlstemail.value=='')
			{
				document.s3mlst.s3mlstemail.value = text;
			}
		}
	}, 
	
	validemail : function(arg)
	{
		var emailRegEx = /^((?:(?:(?:[a-zA-Z0-9][\.\-\+_]?)*)[a-zA-Z0-9])+)\@((?:(?:(?:[a-zA-Z0-9][\.\-_]?){0,62})[a-zA-Z0-9])+)\.([a-zA-Z0-9]{2,6})$/;
		return emailRegEx.test(arg);
	}, 
	
	s3mlreq : function(email)
	{
		s3mlsgn.email = email;
		s3mlsgn.disablebtn();
		s3mlsgn.highlight('i-ml');
		s3mlsgn.output('Registering email...');
		var s3mlrequest = new ajaxObject('/s3/ajax/request/mailinglist.php', s3mlsgn.s3mlprocess);
		s3mlrequest.update('s3mlstemail='+email, 'POST');
	}, 
	
	s3mlprocess : function(responseText, responseStatus)
	{
		s3mlsgn.enablebtn();
		
		if (responseStatus==200)
		{
			var output = JSON.parse(responseText);
			switch(output.result)
			{
				case 'good':
				
				s3mlsgn.highlight('i-ml');
				s3mlsgn.output(output.message);
				window.setTimeout("s3mlsgn.output('Join Our Mailing List');", 3000);
				
				break;
				
				case 'invalid':
				
				s3mlsgn.highlight('i-ml-er');
				s3mlsgn.output(output.message);
				window.setTimeout("s3mlsgn.output('"+s3mlsgn.email+"');", 3000);
				
				case 'error':
				
				s3mlsgn.highlight('i-ml-er');
				s3mlsgn.output(output.message);
				
				break;
			}	
		}
		else
		{
			s3mlsgn.highlight('i-ml-er');
			s3mlsgn.cleanup(output.message);	
		}
	}, 
	
	fadeopacity : function(fromOpacity, toOpacity, time, fps)
	{
		var steps = Math.ceil(fps * (time / 1000));
		var delta = (toOpacity - fromOpacity) / steps;
		
		s3mlsgn.fadestep(0, steps, fromOpacity, delta, (time / steps));
	},
	
	fadestep : function(stepNum, steps, fromOpacity, delta, timePerStep)
	{
		s3mlsgn.setopacity(document.getElementById(s3mlsgn.outputobjid), 
		Math.round(parseInt(fromOpacity) + (delta * stepNum)));
	
		if (stepNum < steps)
		{
			setTimeout("s3mlsgn.fadestep(" + (stepNum+1) + ", " + steps + ", " + 
			fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
		}
		else
		{
			s3mlsgn.cleanup();
		}
	}, 
	
	setopacity : function(el, opacityAsInt)
	{
		var opacityAsDecimal = opacityAsInt;
    
		if (opacityAsInt > 100)
		{
			opacityAsInt = opacityAsDecimal = 100;
		} 
		else if (opacityAsInt < 0)
		{
			opacityAsInt = opacityAsDecimal = 0;
		} 
		
		opacityAsDecimal /= 100;
		if (opacityAsInt < 1)
		{
			opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
		}
	
	    el.style.opacity = (opacityAsDecimal);
		el.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
	}, 
	
	disablebtn : function()
	{
		document.getElementById('btn-mlist').onclick = null;	
	},
	
	enablebtn : function()
	{
		document.getElementById('btn-mlist').onclick = function() {
			s3mlsgn.dosignup();
		};	
	},  
	
	highlight : function(cl)
	{
		document.s3mlst.s3mlstemail.className = cl;	
	}, 
	
	output : function(text)
	{
		document.s3mlst.s3mlstemail.value = text;	
	}
}