window.addEvent('domready', function(){
$$('[class=tb]').each(function(el){
		$(el).addEvents({
			'focus': function(el){
				$(this.get('id').replace('txt','inp')).setStyle('background','transparent url(images/inptxt1-leftg.png) no-repeat scroll 0 0');
				$(this.get('id').replace('txt','right')).setStyle('background','transparent url(images/inptxt1-rightg.png) no-repeat scroll 100% 0');
			},
			'blur': function(el){
				$(this.get('id').replace('txt','inp')).setStyle('background');
				$(this.get('id').replace('txt','right')).setStyle('background');
			}
		});
				   
});	
$('Commments').addEvents({
	'focus': function(el){
		$('Comments_Holder').setStyle('background','transparent url(images/textarea-bggreen.png) no-repeat scroll 0 0');
	},
		'blur': function(el){
		$('Comments_Holder').setStyle('background');
		}
						 });
});


var errorcount =0;

function checktext(form_field){
	if ($(form_field).value == ''){
	    errorcount += 1;
		$(form_field.replace('txt','inp')).setStyle('background','transparent url(images/inptxt1-leftr.png) no-repeat scroll 0 0');
		$(form_field.replace('txt','right')).setStyle('background','transparent url(images/inptxt1-rightr.png) no-repeat scroll 100% 0');
		 $(form_field).removeEvents('focus');
		  $(form_field).removeEvents('blur');
        $(form_field).removeEvents('keyup');
	    $(form_field).addEvent('keyup',function(){
	        checktext(form_field);
	      });
	  }else{
	    $(form_field.replace('txt','inp')).setStyle('background','transparent url(images/inptxt1-leftg.png) no-repeat scroll 0 0');
		$(form_field.replace('txt','right')).setStyle('background','transparent url(images/inptxt1-rightg.png) no-repeat scroll 100% 0');
		$(form_field).addEvents({
			'focus': function(){
				$(form_field.replace('txt','inp')).setStyle('background','transparent url(images/inptxt1-leftg.png) no-repeat scroll 0 0');
				$(form_field.replace('txt','right')).setStyle('background','transparent url(images/inptxt1-rightg.png) no-repeat scroll 100% 0');
			},
			'blur': function(){
				$(form_field.replace('txt','inp')).setStyle('background','transparent url(images/inptxt1-left.png) no-repeat scroll 0 0');
				$(form_field.replace('txt','right')).setStyle('background','transparent url(images/inptxt1-right.png) no-repeat scroll 100% 0');
			}
		});
		
	}
}


function checkcomment(form_field){
	if ($(form_field).value == ''){
	    errorcount += 1;
		$('Comments_Holder').setStyle('background','transparent url(images/textarea-bgred.png) no-repeat scroll 0 0');
		 $(form_field).removeEvents('focus');
		  $(form_field).removeEvents('blur');
        $(form_field).removeEvents('keyup');
	    $(form_field).addEvent('keyup',function(){
	        checkcomment(form_field);
	      });
	  }else{
	    $('Comments_Holder').setStyle('background','transparent url(images/textarea-bggreen.png) no-repeat scroll 0 0')
		$(form_field).addEvents({
			'focus': function(){
				$$('Comments_Holder').setStyle('background','transparent url(images/textarea-bggreen.png) no-repeat scroll 0 0')
			},
			'blur': function(){
				$('Comments_Holder').setStyle('background','transparent url(images/textarea-bg.gif) no-repeat scroll 0 0');
			}
		});
		
	}
}



function CheckForm(){
	errorcount = 0;
	checktext('first_name_txt');
	checktext('last_name_txt');
	checktext('subject_txt');
	checkcomment('Commments');
	if (errorcount==0){
		$('ContactUs').submit();
	}else{
		var ca1 = new Custom.Alert('', '<b>Errors</b> <br /><br /> <span class="little">You have ' + errorcount + ' errors</span>', {
			content: 'html',
			text: {
				confirmButtonText: '',
				closeButtonText: ''
			},
			opacify:false,
			draggable: false,
			zones: {
				box: 'box1',
				head: 'head1',
				body: 'body1',
				buttonBox: 'buttonBox1'
			},
			buttons: {
				closeButton: 'cancelButton1',
				confirmButton: 'confirmButton1'
			},
			overlay: false
	}
	);
		ca1.create();
	}
		

		
}


