var formObj = null;
2
3var fObj = new Class({
4 initialize: function(){
5 // BBCheck
6 if( $('bbcheck_submit') ){
7 $('checkResult').innerHTML = "<strong>Please enter your BT telephone number above and click check</strong>";
8 $('bbcheck_submit').addEvent('click', function(e){
9 this.bbcheck();
10 }.bind(this));
11
12 // Run account checking...
13 //this.accountcheck();
14
15 this.disabled = $$('.startDisabled input').concat($$('.startDisabled select'));
16 this.disabled.each( function(obj, n){
17 obj.setProperty('disabled','disabled');
18 });
19 this.hidden = $$('.startHidden');
20 this.hidden.each( function(obj, n){
21 obj.setStyle('display','none');
22 });
23 }
24
25 this.cancel = $$('.cancel');
26 this.cancel.each(function(obj,n){
27 obj.addEvent('click',function(e){
28 if(confirm('Are you sure?'))
29 window.location='.';
30 });
31 }.bind(this));
32
33 // Required fields
34 this.form = $$('form');
35
36 this.form.each(function(obj, n){
37 obj.addEvent('submit', function(e){
38 var required = obj.getElements('.required input').concat(obj.getElements('.required select'));
39 var shownAlert = 0;
40 required.each(function(rob,rn){
41 if(!rob.value && !shownAlert){
42 shownAlert = 1;
43 alert('Please fill in all required fields');
44 e.preventDefault();
45 }
46 });
47 });
48 }.bind(this));
49
50 var ddConf = $$('#ddConfirm .confirm');
51 if(ddConf){
52 $$('#ddConfirm .ddconfchk').addEvent('click',function(e){
53 ddConf.removeProperty('disabled');
54 });
55 }
56 },
57
58 bbcheck: function(){
59 var bbcheck = $$('.bbcheck_tel');
60
61 $('checkResult').innerHTML = "Checking...";
62 //$('checkResult').innerHTML = "Calculating infinity...";
63 $('bbChecking').setStyle('display','block');
64 checkRequest = new Request({
65 method: 'get',
66 url: '/ajax.php?broadband_check=' + $('inBTPhone').getProperty('value') + '&product=' + $('seFormProduct').options[$('seFormProduct').selectedIndex].value + '&' +(Math.random()*100),
67 onComplete: function( response ){
68 $('bbChecking').setStyle('display','none');
69 response = JSON.decode( response );
70 if(response.msg){
71 $('checkResult').innerHTML = response.msg;
72 if( response.canhas ){
73 this.disabled.each( function( obj, n ){
74 obj.removeProperty('disabled');
75 });
76 this.hidden.each( function( obj, n ){
77 obj.setStyle('display', 'block');
78 });
79 }
80 }
81 }.bind(this)
82 }).send();
83 },
84
85 // Check account
86 accountcheck: function(){
87 var acHas = $('account_has');
88
89 $$('.accountCheck').setStyle('display','none');
90 $$('.nonAccount').setStyle('display','none');
91
92 acHas.addEvent('change',function(e){
93 if(acHas.value.contains('Yes')){
94 $$('.nonAccount').setStyle('display','none');
95 $$('.accountCheck').setStyle('display','block');
96 }else{
97 $$('.accountCheck').setStyle('display','none');
98 $$('.nonAccount').setStyle('display','block');
99 }
100 });
101 }
102});
103
104window.addEvent('domready',function(){
105 formObj = new fObj();
106});
107 