Event.observe(window, 'load', signupMagic, false);
Event.observe(window, 'load', buttonOvers, false);

function signupMagic() {
	
	/*
	
	Global email subscription boxes require two distinct actions:
	1) the text field needs to empty when clicked
	2) the button needs a rollover state
	
	____________________________________________*/

	// get inputs within signup fieldset
	var inputs = $A($$('div.signup fieldset input'));
	var field = inputs[0];
	
	// CLEAR INPUT TEXT ON FOCUS, RESTORE ON BLUR
	
	// get default invitation text
	var invitation = field.value;
	
	// add focus and blur events
	Event.observe(field, 'focus', function(){ if(this.value == invitation) { this.value = '';} }, false);
	//Event.observe(field, 'blur', function(){ this.value = invitation; }, false);
	
}

function hoverState(thing) {

	/*
	mouseover-creating utility
	____________________________________________*/
	
	// get default button image
	var src = thing.src;
	var dirs = src.split('/');
	var img = dirs.pop(); 

	// add -over to filename and reconstruct filepath
	var over = dirs.join('/') + '/' + img.replace(/([.][^.]*$)/, '-over$1');

	// add mouseover and mouseout events
	Event.observe(thing, 'mouseover', function(){ this.src = over; }, false);
	Event.observe(thing, 'mouseout', function(){ this.src = src; }, false);
}

function buttonOvers() {

	/*
	adds rollovers to any input button with 
	a src attribute
	____________________________________________*/

	$A($$('input[src]')).each(
		function(button) { hoverState(button); }
	);
	$A($$('div.buttons div.button img')).each(
		function(button) { hoverState(button); }
	);
		
}

function validateEmail(sender, args)
{
    if(args.Value.trim().length > 0)
    {
        var ex = /^([a-zA-Z0-9_.+-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
        var re = new RegExp(ex );
         
        if(re.exec(args.Value))
        {
            args.IsValid = true;
        }
        else
        {
            sender.errormessage= "* invalid email";
            sender.innerHTML= sender.errormessage;
            args.IsValid = false;
        }        
    }
    else
    {
        sender.errormessage= "* required";
        sender.innerHTML= sender.errormessage;
        args.IsValid = false;
    }
}
