
	var Schedule = Class.create();

	Schedule = {
		
		required: ['schedule_prime','schedule_name','schedule_location','schedule_date','schedule_time','schedule_cname','schedule_cemail','schedule_cphone'],
		
		initialize: function() {
			$('schedule_form').show();
			Event.observe('schedule_form','submit',function(event) {
				if(Schedule.validate()) {
					new Ajax.Request('http://www.cswsafety.com/send_schedule.php',{
						method: 'post',
						parameters: Form.serialize('schedule_form',true),
						onCreate: function(transport) {},
						onComplete: function(transport) {
							Schedule.resetInputs();
							Schedule.displaySuccess();
							alert(transport.responseText);
						}
					});
				} else {
					Schedule.displayError();
				}
			});
			$$('.what input[type=checkbox]').each(function(input) {
				Event.observe(input,'click',function(event) {
					if(this.name=='other') {
						$('other_div').toggle();
					} else {
						if(!$('what_'+this.name)) {
							this.next('br').insert({
								after: new Element('input',{
									name: 'schedule[what]['+this.name+']',
									id: 'what_'+this.name,
									size: '7',
									style: 'margin-left:18px;'
								})
							});
							$('what_'+this.name).insert({
								after: new Element('span',{
									id: this.name+'_span'
								})
							});
							$(this.name+'_span').insert({
								top: '&nbsp; '+this.readAttribute('unit')+'<br>'
							});
							Schedule.required.push('what_'+this.name);
						} else {
							Element.remove('what_'+this.name);
							Element.remove(this.name+'_span');
							Schedule.required = Schedule.required.without('what_'+this.name);
						}
					}
				});
			});
		},
		
		validate: function() {
			var result = true;
			$$('input[rel=what]').each(function(what) {
				if(what.checked==1) {
					result = true;
					throw $break;
				} else {
					result = false;
				}
			});
			if(result!=false) {
				this.required.each(function(req) {
					if($(req).value=='') {
						result = false;
						throw $break;
					};
				});
			}
			return result;
		},
		
		resetInputs: function() {
			$('schedule_form').reset();
		},
		
		displayError: function() {
			$('message').update('Please fill in all the required fields.');
			$('message').addClassName('error');
		},
		
		displaySuccess: function() {
			$('message').update('Thank you for scheduling a job, someone will be in contact with you shortly.');
			$('message').addClassName('success');
			$('message').removeClassname('error');
		}
	
	}

	Event.observe(window,'load',function() {
		Schedule.initialize();
	});