Event.observe(window, 'load', function() {
	var webCallAnchor = $('webCallAnchor');
	if (webCallAnchor) {
		webCallAnchor.onclick = function() {
			//Make sure there's no href
			if (this.tagName == 'A') {
				this.href = '#';
			}
			//Create a popup box
			var webcallbox = new MessageBox('webcallbox', 'Web Call Us');
			webcallbox.setWidth(420);
			webcallbox.setAlignment('left');
			webcallbox.setMessage('<form id="webcall_form" action="/webcall/ajax/call"><p><label>Your Name</label><input type="text" class="text" name="caller_name" /></p><p><label>Your Number</label><input type="text" class="text" name="caller_number" /><br /><em>(Area code required. Must be a valid Australian phone number.)</em></p><p><input type="submit" class="button" name="__submit" value="Place Call" /></p></form>');
			webcallbox.show();
			
			attachFormAction('webcall_form', function() {
				var form = $('webcall_form');
				var ajax = new AjaxProcessing(form, form.action);
				ajax.messageOnLoading('Establishing connection');
				ajax.messageOnSuccess('Connection established');
				ajax.messageOnFailure('Connection failed');
				ajax.onSuccess('justcallback', function(result) {
					webcallbox.hideTitleBar();
					webcallbox.setAlignment('center');
					webcallbox.setMessage('<h1>Connection established</h1><p><img src="/img/webcall/connected.jpg" /><br /><em>(Note: If by some chance, you have not received a call from us, please try again later or use the listed alternative contact method to reach us</em></p>');
					webcallbox.addClose();
				});
				ajax.process();
			});
			
			return;
		}
	}
});
