// JavaScript Document site.js
window.addEvent('domready', function(){
								 
var theForm = $('cform');//cform
var theMess = $('mess');
var morff = new Fx.Morph(theMess, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
 
//SETUP MIS FORM FUN
var feilds = $$('#cform input','#cform textarea');
	feilds.each(function(item, index){		
		var sw = item.getProperty('type');
		//console.info(sw);
		switch(sw)
		{
		case 'text':
			item.addEvents({
				'focus': function(){
					item.setStyle('background-color', '#FFFFFF');
				},
				'blur': function(){
					item.setStyle('background-color', '#F2F2F2');
				}
			});	
			break;
		case 'submit':			
			break;
		case 'reset':
			break;
		default:
			item.addEvents({
				'focus': function(){
					item.setStyle('background-color', '#FFFFFF');
				},
				'blur': function(){
					item.setStyle('background-color', '#F2F2F2');
				}
			});	
			break;
		}
	});
//FORM EVENT
theForm.addEvent('submit', function(){
		//DATA COLLECT
		var theName = $('name');
		var theEmail = $('email');
		var theComment = $('comment');
		var theRec = $('receiver').getProperty('value');
		var theSub = $('subject').getProperty('value');
		if(theName.getProperty('value') !== '' && theEmail.getProperty('value').test('@') && theComment.getProperty('value') !== '')
		{
			var objVars = 'receiver='+ theRec + '&subject='+ theSub +'&name='+ theName.getProperty('value') +'&email='+ theEmail.getProperty('value') +'&comment='+ theComment.getProperty('value');
			//SETUP REQUEST
			var myRequest = new Request({
				method: 'get', 
				url: 'sendEmail.asp',
				onSuccess: function(txt) {
					if(txt.test('Error')){
					morff.start({
						'color': '#ffffff',
						'background-color': '#FF0000'
						});
					}else{
					theName.setProperty('value', '');
					theEmail.setProperty('value', '');
					theComment.setProperty('value', '');
					morff.start({
						'color': '#ffffff',
						'background-color': '#00CC66'
						});
					}		
					$('mess').set('text', txt);
					
				},
				onFailure: function() {
				$('mess').set('text', 'Oops, your message was not sent.');
				}
			}).send(objVars);
			
			
		}else{
		morff.start({
			'color': '#ffffff',
			'background-color': '#ff0000'
					});
		$('mess').set('text', 'Please correctly fill in all of the information and try again.');	
		}
		return false;
	});
});									 

