var JFORM;
var CACHE;
var REQ_FIELDS = new Array();
var VALIDATE_FIELD = false;
function FormWizard() {
fs('FormWizard::construct', true);
this.auto = true;
this.req_fields = new Array();
this.invalid_fields = 0;
this.setup = FormWizard__setup;
this.highlight = FormWizard__highlight;
this.unhighlight = FormWizard__unhighlight;
this.submit = FormWizard__submit;
this.setInvalid = FormWizard__setInvalid;
this.setValid = FormWizard__setValid;
this.checkRequired = FormWizard__checkRequired;
};
function FormWizard__setup() {
fs('FormWizard::setup');
var formlist = new Array();
try {
var forms = $J('form');
for(var i = 0; i < forms.length; i++) {
var form_id = $J(forms[i]).attr('id');
if(form_id == null || form_id == 'login') {
log('Skipping', LOG_FORM_LOW);
continue;
}
formlist.push('#'+form_id);
}
$J.PAGE.set('forms', formlist);
$J.PAGE.set('form_count', formlist.length);
log('Adding form field event triggers', LOG_FORM_LOW);
$J('input').focus(function() {
<!-- [if gte IE 5] -->
JFORM.highlight(this);
<!-- [endif] -->
$J.PAGE.set('active_form', this);
});
<!-- [if gte IE 5] -->
$J('input').blur(function() {
JFORM.unhighlight(this);
});
<!-- [endif] -->
$J('option:even').addClass('altShading');
log('Finished setting up form fields', LOG_FORM_LOW);
jQuery.JFORM = JFORM;
} catch(e) {
return fail(e);
}
return true;
};
function FormWizard__unhighlight(field) {
fs('FormWizard::unhighlight =>'+field.id);
try {
$J(field).removeClass('focused');
} catch(e) {
fail(e);
}
};
function FormWizard__highlight(field) {
fs('FormWizard::highlight =>'+field.id);
try {
$J(field).addClass('focused');
} catch(e) {
fail(e);
}
};
function FormWizard__submit(form, btn) {
fs('FormWizard::submit');
if(form == null) {
return failp('form');
}
try {
jQuery.blockUI();
jQuery(form).submitOn();
$J(form).submit();
return true;
} catch(e) {
fail(e);
}
return false;
};
function FormWizard__setInvalid(field) {
fs('FormWizard::setInvalid');
try {
$J(field).addClass('invalid');
} catch(e) {
return fail(e);
}
return true;
};
function FormWizard__setValid(field) {
fs('FormWizard::setValid');
try {
$J(field).removeClass('invalid');
if(JFORM.invalid_fields < 0) {
log('No required fields left to validate');
return true;
}
var found = $J(JFORM.req_fields).find(field.name);
if(found) {
log('Removing '+field.name+' from invalid list.', LOG_FORM);
JFORM.invalid_fields--;
JFORM.checkRequired();
return true;
} else {
log('No match found for '+field+' in required fields');
}
} catch(e) {
return fail(e);
}
return true;
};
function FormWizard__checkRequired() {
fs('FormWizard::checkRequired');
var rcnt = JFORM.invalid_fields;
try {
log('Still have '+rcnt+' required fields to complete', LOG_FORM);
if(rcnt == 0) {
log('All required fields are valid. Enabling button', LOG_FORM);
JFORM.invalid_fields = -1;
var btncnt = $J('#btnNext').length;
log('Found '+btncnt+' buttons to enable', LOG_FORM);
var btns = $J('#btnNext').get();
btns[0].disabled = false;
log('Submit button enabled', LOG_FORM);
}
} catch(e) {
return fail(e);
}
return true;
};
$(document).ready(function() {
fs('document.ready => form', true);
try {
JFORM = new FormWizard();
JFORM.setup();
} catch(e) {
return fail(e);
}
});
