window.addEvent('domready',function() {

//Newsletter Submit
		$('searchsubmit').addEvent( 'click', function(evt){
			new Event(evt).stop();
			$('searchform').send({
				onSuccess: function(successData){
					alert(successData);
					$('s').value = 'email address';
				},
				onFailure: function(errorData){
					alert(errorData);
				}
			});
		} );

//Contact submit
		$('contactsubmit').addEvent( 'click', function(evt){
			new Event(evt).stop();
			//validate form
			strVal = $('contact_name').value;
			nMin = 2;
			nMax = 50;
			if(strVal.length < nMin || strVal.length > nMax){
				alert('Please enter name between ' + nMin + ' to ' + nMax + ' characters');
				$('contact_name').focus();
				return false;
			}
			nMinAddress = 10;
			nMaxAddress = 100;
			strVal = $('contact_address').value;
			if(strVal.length < nMinAddress || strVal.length > nMaxAddress){
				alert('Please enter address between ' + nMinAddress + ' to ' + nMaxAddress + ' characters');
				$('contact_address').focus();
				return false;
			}
			strVal = $('contact_city').value;
			if(strVal.length < nMin || strVal.length > nMax){
				alert('Please enter city between ' + nMin + ' to ' + nMax + ' characters');
				$('contact_city').focus();
				return false;
			}
			
			nMinSt = 2;
			nMaxSt = 5;
			strVal = $('contact_st').value;
			if(strVal.length < nMinSt || strVal.length > nMaxSt){
				alert('Please enter St between ' + nMinSt + ' to ' + nMaxSt + ' characters');
				$('contact_st').focus();
				return false;
			}
			nMinZip = 5;
			nMaxZip = 10;
			strVal = $('contact_zip').value;
			if(strVal.length < nMinZip || strVal.length > nMaxZip){
				alert('Please enter zip between ' + nMinZip + ' to ' + nMaxZip + ' characters');
				$('contact_zip').focus();
				return false;
			}
			
			//
			$('contactform').send({
				onSuccess: function(successData){
					alert(successData);
					$('resetcontact').click();
				},
				onFailure: function(errorData){
					alert(errorData);
				}
			});
		} );
		
		//Date picker
		$$('input.DatePicker').each( function(el){
			new DatePicker(el);
				el.addEvents({
				'keyup': function(e) {
					e.stopPropagation();
					if ( (e.keyCode == 46 || e.keyCode == 8)){
						el.value = '';
					}
				}
			});
		});

//
});
/*
window.addEvent('load', function() {
//initialize datepicker
new DatePicker($('contact_preferred_appointment_date'), { pickerClass: 'datepicker_vista' });
//class='date demo_vista'

});
*/
