﻿	// Script requires Prototype 1.5.1
	// See http://www.prototypejs.org
	//
	// This file is part of the debt test, and should be syndicated across all partners.
	var FSAForm = {
		loaded: false,
		load: function() {
			if((typeof Prototype=='undefined') || 
			   (typeof Element == 'undefined') || 
			   (typeof Element.Methods=='undefined') ||
			   parseFloat(Prototype.Version.split(".")[0] + "." +
						  Prototype.Version.split(".")[1]) < 1.5) {
				this.loaded = false;
				alert("FSA tools require the Prototype JavaScript framework 1.5.0 or later. See http://www.prototypejs.org for more information.\n\nThis form has been disabled - please contact this website's administrator.");
				return false;
			}
			else
			{
				this.loaded = true;
				return true;
			}
		},
		enable: function(id) {
			if (this.loaded) {
				$A($(id).getElementsByTagName('*')).each(function(n) { 
					if (n.nodeName.toUpperCase() == "INPUT")
						Form.Element.enable(n);
					if (n.nodeName.toUpperCase() == "DIV")
						Element.removeClassName(n,"disabled");
					return;
				});
			}
		},
		disable: function(id) {
			if (this.loaded) {
				$A($(id).getElementsByTagName('*')).each(function(n) { 
					if (n.nodeName.toUpperCase() == "INPUT")
					{
						Form.Element.disable(n);
						n.checked = false;
					}
					if (n.nodeName.toUpperCase() == "DIV")
						Element.addClassName(n,"disabled");
					return;
				});
			}
		},
		changeLabel: function(id,label) {
			if (this.loaded) {
				$(id).innerHTML = label;
			}
		},
		checkid: "",			// set this id to validate radio/checkboxes under this
		checkerrors: 0,			
		checkform: null, 
		check: function(_fm) {
			if (this.loaded) {
				this.checkform = $(_fm);
				if (this.checkid != "") {
					var f = this.checkform.getElements();
					for (var i = 0; i < f.length; i++)
					{
						if (f[i].disabled == false && f[i].type == "radio")
						{	
							if ($A(this.checkform[f[i].name]).all(function(n) { return !n.checked; } ))
								this.checkerrors++;
						}
						if (f[i].disabled == false && f[i].type == "text")
						{	
							var e = $(f[i]);
							
							var relAttribute = String(e.getAttribute('rel'));
							var re = /\W/ig; // default
							if (relAttribute.toLowerCase().match('number'))
							{	
							    re = /\D/g;
                                var val = $F(this.checkform[f[i].name])
                                if (val <0) {this.checkerrors++;}
                            }
							var val = $F(this.checkform[f[i].name])
							if ((re.test(val) && val.length > 0) || val.length == 0)
								this.checkerrors++;
						}
					}

					if (this.checkerrors > 0) {
						alert("Please check your answers. You have either missed a question or not given a number as your answer. ");
						this.checkerrors = 0;
						return false;
					}
					else
						return true;
				}
				else
					return true;
			}
			else
				return false;
		}
	}
	FSAForm.load();