var SurveyForm = new Class({
	
	holderDiv: null,
	
	initialize: function(holderDiv) {
		this.holderDiv = holderDiv;
		$('aBook').addEvent('click', function(e) {
			e.stop();
			this.sendRequest();
		}.bind(this));
		
		new OverText('txtName', { positionOptions: {offset: { x: 0,y: 3}}});
		new OverText('txtPostcode', { positionOptions: {offset: { x: 0,y: 3}}});
		new OverText('txtContactNumber', { positionOptions: {offset: { x: 0,y: 3}}});
		new OverText('txtEmail', { positionOptions: {offset: { x: 0,y: 3}}});
		new OverText('search_term', { positionOptions: {offset: { x: 10,y: 7}}});
		
	},
	
	sendRequest: function() {
		var name = $("txtName").get("value");
		var interest = $("ddInterested").get("value");
		var pcode = $("txtPostcode").get("value");
		var email = $("txtEmail").get("value");
		var tel = $("txtContactNumber").get("value");
		
		var t = this;
		
		
		var myJSONRequest = new Request.JSON({
				url: "process-survey-request.php", 
				method: 'get',
				noCache: true,
				data: 'pcode=' + pcode + '&name=' + name + '&interest=' + interest + "&tel=" + tel + "&email=" + email,
				onRequest: function() {
				
					//t.holderDiv.spin();
					t.clearErrors();
					
				
				},
				onSuccess: function(json) {
					
					if (json.errors.length == 0) {
						//show Success
						t.showSuccess();
						pageTracker._trackPageview('/conversion_page.html');
					} else {
						json.errors.each (function(item, index) {
							$('survey-' + item).addClass('survey-error');
						});
						
					}
					
				
				},
				onComplete: function() {
					//t.holderDiv.unspin();					
				}
		}).send();
		
	},
	
	showSuccess: function() {
		$('survey-form-question').setStyle('display', 'none')
		$('survey-form-complete').setStyle('display', 'block')		
	},
	
	clearErrors: function() {
		this.holderDiv.getElements('.survey-control').each(function (item) {
			item.removeClass('survey-error');
		});
		
	}
	
	

});




