function Validation() {

    //this is the form validation

   


    var self = this;

    //if this is empty than there are no form fields errors

    this.validForm = new Array();
	

    /*
    // Setup an array for the validation of forms	
    // this array helps to determin the differen types of events to assosicate with 
    each validation
    Each array item is an array
    0 :for force typ
    1 : mask
    2 : Regular expresion validate
    */



    this.arValidType = new Array();
    this.arValidType["email"] = new Array();
    this.arValidType["webaddress"] = new Array();
    this.arValidType["text"] = new Array();
    this.arValidType["numeric"] = new Array();
    this.arValidType["date"] = new Array();
    this.arValidType["address"] = new Array();
    this.arValidType["zipcode"] = new Array();
    this.arValidType["phone"] = new Array();
    this.arValidType["postalcode"] = new Array();
    this.arValidType["any"] = new Array();
    this.arValidType["check"] = new Array();
    this.arValidType["select"] = new Array();
    this.arValidType["title"] = new Array();
    this.arValidType["MinLength"] = new Array();
    this.arValidType["MaxChr"] = new Array();

    this.arValidType["required"] = new Array();
    this.arValidType["comparevalues"] = new Array();

    this.arValidType["image"] = new Array();

    this.arValidType["email"][0] = "blur";
    this.arValidType["email"][1] = "blur";
    this.arValidType["email"][2] = "blur";

    this.arValidType["required"][0] = "submit";
    this.arValidType["required"][1] = false;
    this.arValidType["required"][2] = "blur";
    
    this.arValidType["image"][0] = "change";
    this.arValidType["webaddress"][0] = "blur";
    this.arValidType["comparevalues"][0] = "blur";


    this.arValidType["text"][0] = "keydown";
    this.arValidType["numeric"][0] = "keydown";
    this.arValidType["date"][0] = "blur";
    this.arValidType["address"][0] = "keypress";

    this.arValidType["zipcode"][0] = "keydown";
    this.arValidType["zipcode"][1] = "keypress";
    this.arValidType["zipcode"][2] = "blur";

    this.arValidType["phone"][0] = "keydown";
    this.arValidType["phone"][1] = "keypress";

    this.arValidType["any"][0] = "blur";
    this.arValidType["check"][0] = "click";
    this.arValidType["select"][0] = "change";
    this.arValidType["title"][0] = "keypress";

    this.arValidType["MinLength"][0] = "keypress";
    this.arValidType["MaxChr"][0] = "keypress";

    /// Deal with errors

    this.setFormInvalid = function(id,er) {
        var a = self.validForm;
        var td = -1;
		
        	var m = null;

		var c = new Array();

				try{
        	var m = document.getElementById(id).getAttribute("message");
        }
		catch(e)
		{}
		
        for (var i = 0; i < a.length; i++) {
            var r = a[i]["id"];
            if (r.toLowerCase() == id.toLowerCase()) {
                td = i;
            }
        }


        if (td == -1) {
            c["id"] = id;

            if (m != 'undefined') {
                c["message"] = m;
            }
            else { c["message"] = ''; }
            c["errortype"]=er
            a[a.length] = c;
        }


        return;

    }
  this.setFormValid = function(id) 
  	{
        var a = self.validForm;
	
		for(var i=0;i<a.length;i++)
			{
				var r=a[i]["id"];
				if(r.toLowerCase() == id.toLowerCase())
					{
					 a.splice(i, 1);
					}
			}
			
		
		
    }
    /// Show the error		

    this.addEvent = function(sType, sFn, oObj) {
        if (window.addEventListener) {
            oObj.addEventListener(sType, sFn, false);
        }
        else {
            oObj.attachEvent('on' + sType, sFn, false);
        }
        return;
    }
    /*
    <!---
    // this function deals with settiong the cuurent element based on the event that called
    //  the function that this function is in
    ---->
    */

    this.setCurrentElement = function(e) 
        {
            if (window.event) 
            {
                return window.event.srcElement;
            }
            else 
            {
                return e.target;
            }
    }

    /*<!---
    this function deals auto tabbing
    ---->*/

    this.setAutoTab = function(e) {
        var oElm = self.setCurrentElement.apply(this, arguments);
        var oForm = oElm.form;

        if (oElm.type == 'text' && oElm.getAttribute('maxlength') == oElm.value.length) 
        {

            for (var i = 0; i < oForm.elements.length; i++) {
                if (oForm.elements[i].name == oElm.name) {
                    oForm.elements[i + 1].focus();
                }
            }

        }
    }

    this.isNumeric = function(key) 
        {
            if ((key >= 48 && key <= 57) || (key >= 96 && key <= 105)) {
                return true;
        }
        else 
        {
            return false;
        }
    }

    this.isCharacter = function(key) {
        if ((key >= 97 && key <= 122) || (key >= 65 && key <= 90)) {
            return true;
        }
        else {
            return false;
        }
    }

    this.isSystemKey = function(key) {
        if (key <= 9 || key == 16) {
            return true;
        }
        else {
            return false;
        }
    }

    this.isCapsOn = function(e) {
        kc = e.keyCode ? e.keyCode : e.which;
        sk = e.shiftKey ? e.shiftKey : ((kc == 16) ? true : false);
        if (((kc >= 65 && kc <= 90) && !sk) || ((kc >= 97 && kc <= 122) && sk)) {
            return true;
        }
        else {
            return false;
        }
    }
    /*<!--- 
		
		 Adds validation to a form based @FormId
    this section is for preventing error as information is entered into 
    a form fieled.  Because this is preventetive no error resopnses are generated.
		
	 --->*/

    this.addValidation = function(sFormId) {

        var oForm = document.getElementById(sFormId);
        var oElm = oForm.elements;

        for (var i = 0; i < oElm.length; i++) {

            var sForceVal = oElm[i].getAttribute('forcetype');
            var sMaskVal = oElm[i].getAttribute('mask');
            var sMinLength = oElm[i].getAttribute('MinChr');
            var sMaxLength = oElm[i].getAttribute('MaxChr');
            var sValidate = oElm[i].getAttribute('validate');
            var sCompare = (oElm[i].getAttribute('compareValues') != null) ? true : false;
            var bRequired = (oElm[i].getAttribute('required') != null) ? true : false;

            this.addEvent('keyup', self.setAutoTab, oElm[i]);

            if (oElm[i].type == 'text' || oElm[i].type == 'password' || oElm[i].type == 'textarea') {
                /*/// check to see if we should add a key capture to prevent errors */
                if (sForceVal != 'undefined' && sForceVal != null) {
                    this.applyForceKey(sForceVal.toLowerCase(), oElm[i]);
                }
                /*/// check to see if we should add a mask  */
                if (sMaskVal != 'undefined' && sMaskVal != null) {
                    this.applyMask(sMaskVal.toLowerCase(), oElm[i]);
                }
                /*// check to see if we should add validation*/
                if (sValidate != 'undefined' && sValidate != null) {
                    this.applyValidate(sValidate.toLowerCase(), oElm[i]);
                }
                /*// check to see if we should add validation*/
                if (sCompare) {
                    this.applyValidate("comparevalues", oElm[i]);
                }
                /*// check to see if we should watch for the min length or max length*/
                if (sMinLength != 'undefined' && sMinLength != null) {
                    this.applyLength('MinLength', oElm[i]);
                }
                /*// check to see if we should watch for the min length or max length*/
                if (sMaxLength != 'undefined' && sMaxLength != null) {
                   
                    this.applyLength('MaxChr', oElm[i]);

                }
                /* end check for text inputs*/
            }


            if (oElm[i].type == 'file') {
                /*// check to see if we should add validation*/

                if (sValidate != 'undefined' && sValidate != null) {
                    this.applyValidate(sValidate.toLowerCase(), oElm[i]);
                }
            }


            if (bRequired) {
                this.arValidType["required"][1] = true;
              //  this.setFormInvalid(oElm[i].id);
            }




            ///// End form loop	
        }
        //// End the function for addValidation
        if (this.arValidType["required"][1]) {

            this.applyValidate('required', oForm);

        }
    }


    this.applyForceKey = function(sVal, oCurElm) {
        switch (sVal) {
            case "numeric":
                this.addEvent(this.arValidType[sVal][0], self.CheckNumeric, oCurElm);

                break;

            case "text":
                this.addEvent(this.arValidType[sVal][0], self.CheckCharacter, oCurElm);
                break;

            case "zipcode":
                this.addEvent(this.arValidType[sVal][0], self.CheckZipCode, oCurElm);
                break;

            case "phone":
                this.addEvent(this.arValidType[sVal][0], self.CheckZipCode, oCurElm);
                break;

            case "address":
                this.addEvent(this.arValidType[sVal][0], self.CheckAlphaNumb, oCurElm);
                break;

            case "date":
                this.addEvent(this.arValidType[sVal][0], self.CheckNumeric, oCurElm);
                break;

            case "title":
                this.addEvent(this.arValidType[sVal][0], self.CheckTitle, oCurElm);
                break;

            /////////// END SWITCH STATEMENT					 
        }
    }

    this.applyMask = function(s, o) {
        switch (s) {

            case "zipcode":
                this.addEvent(this.arValidType[s][1], self.zipCodeMask, o);
                break;

            case "phone":
                this.addEvent(this.arValidType[s][1], self.phoneMask, o);
                break;

            case "date":
                this.addEvent(this.arValidType[s][1], self.CheckNumeric, o);
                break;
            /////////// END SWITCH STATEMENT					 
        }
    }
    this.applyValidate = function(s, o) {
        switch (s) {
            case "email":
                this.addEvent(this.arValidType[s][2], self.isEmail, o);
                break;
            case "zipcode":
                this.addEvent(this.arValidType[s][2], self.isZip, o);
                break;
            case "date":
                this.addEvent(this.arValidType[s][1], self.CheckNumeric, o);
                break;
            case "webaddress":
                this.addEvent(this.arValidType[s][0], self.isWebAddress, o);
                break;
            case "image":
                this.addEvent(this.arValidType[s][0], self.isImage, o);
                break;
            case "comparevalues":
                this.addEvent(this.arValidType[s][0], self.compareValues, o);
                break;
            case "required":
                this.addEvent(this.arValidType[s][0], function(o) { return self.Required(o); }, o);
                break;
        }
    }

    this.applyLength = function(sVal, oCurElm) {
        switch (sVal) {
            case "MinChr":
                this.addEvent(this.arValidType[sVal][0], self.checkMinLength, oCurElm);
                break;
            case "MaxChr":
                this.addEvent(this.arValidType[sVal][0], self.checkMaxLength, oCurElm);
                
                break;
        }
    }

    /*
    Sets requires that the form is unable to submit until the field is not empty
    this.applyReqired(oForm)
    */

    this.Required = function(e) {

        var o = self.setCurrentElement.apply(this, arguments);

        //  document.getElementById(e);

        var a = true;
        for (var i = 0; i < o.elements.length; i++) {
            var l = o.elements[i];
            var n = l.getAttribute('required')
            var r = (n != null) ? true : false;
            var status = false;
            var v = self.validForm;

            for (var x = 0; x < v.length; x++) {
                if (v[x]["id"] == l.id) {

                    if (v[x]["errortype"] == 2) {
                    
                        status = true;
                        break;
                    }
                }

            }

            if (r) {

                switch (l.type) {
                    case "select":
                        if (l.selectedIndex == 0) { a = false; self.setFormInvalid(l.id, 1); }
                        else { self.setFormValid(l.id) }
                        break;

                    case "checkbox":
                        if (l.checked != "") { a = false; self.setFormInvalid(l.id, 1); }
                        else { self.setFormValid(l.id) }
                        break;

                    case "radio":
                        var valid = false;
                        for (var i = 0; i < l.length; i++) {
                            if (l[i].checked == 'checked') { valid = true; }
                        }
						
                        if (!valid) { a = false; self.setFormInvalid(l.id, 1); }

                        else { self.setFormValid(l.id) }
                        break;

                    default:

                        if (l.value.length == 0) { a = false; self.setFormInvalid(l.id, 1); }

                        else { if (!status) { self.setFormValid(l.id) } }

                }

            }
        }


        if (!a) {
            try {




                var m = "Required Fields must be completed.\n\r"
                if (v.length > 0) {
                    for (var x = 0; x < v.length; x++) {
                        if (v[x]["message"] == null) {
                            v[x]["message"] = " ";
                        }

                        m += v[x]["message"] + "\n\r"

                    }

                    alert(m);
                }

                e.returnValue = false;

                if (e.preventDefault) {
                    e.preventDefault();
                }

                return false;
            }

            catch (e) {

                return false;
            }
        }

        return a;
    }


    /*<!--- 
    * checking char codes and data types 
    * used for keypress functions
    * and to prevent input 
    --->*/

    this.checkMinLength = function() {
        var o = self.setCurrentElement.apply(this, arguments);
        var s = o.value;
        var n = o.getAttribute('MinLength');

        if (parseInt(s.length) < parseInt(n)) s
        {
            self.fireFail("You must enter at least " + parseInt(n) + " charecters in order to proceed", o.id);
            return false;
        }

        return true;
    }


    this.checkMaxLength = function(e) {
        var o = self.setCurrentElement.apply(this, arguments);
        var s = o.value;

        var n = o.getAttribute('MaxChr');


        if (window.event) {

            var key = event.keyCode;
        }
        else if (e.which) {
            var key = e.which;
        }

        if (!(parseInt(s.length) < parseInt(n)) && !(self.isSystemKey(key))) {
           
            o.value = s.slice(0, (parseInt(n)));

            if (e.which) {
                e.preventDefault();
            }

            self.fireFail("You have reached the max number of  charecters(" + parseInt(n) + ") allowed. "+key, o.id);


            return false;
        }

        else {
            return true;
        }
    }


    this.CheckAlphaNumb = function(e) {

        if (window.event) // IE
        {
            var key = event.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {
            var key = e.which;
        }

        if (self.isCapsOn.apply(this, arguments)) {
            alert("The Caps Lock Key is currently on");
        }
        if (self.isSystemKey(key) || self.isNumeric(key) || self.isCharacter(key) || (key == 32) || (key == 46)) {
            return true;
        }

        else {
            if (e.which) {
                e.preventDefault();
            }

            return false;
        }
    }


    this.CheckTitle = function(e) {

        if (window.event) // IE
        {
            var key = event.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {

            var key = e.which;
        }
        //
        if (self.isCapsOn.apply(this, arguments)) {
            alert("The Caps Lock Key is currently on");
            return false;
        }

        if (self.isSystemKey(key) || self.isCharacter(key) || (key == 32) || (key == 109) || (key == 222)) {

            return true;

        }

        else {
            if (e.which) {
                e.preventDefault();
            }

            return false;
        }
    }


    this.CheckCharacter = function(e) {

        if (window.event) // IE
        {
            var key = event.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {

            var key = e.which;
        }
        if (self.isCapsOn.apply(this, arguments)) {
            alert("The Caps Lock Key is currently on");
            return false;
        }
        if ((String.fromCharCode(key) >= "A" && String.fromCharCode(key) <= "Z") || (self.isSystemKey(key))) {
            return true;
        }

        else {
            if (e.which) {
                e.preventDefault();
            }
            return false;
        }
    }
    ///Numbers only
    this.CheckNumeric = function(e) {
        if (window.event) // IE
        {
            var key = event.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {

            var key = e.which;
        }

        if (self.isSystemKey(key) || self.isNumeric(key)) {

            return true;
        }
        else {

            if (e.which) {
                e.preventDefault();
            }
            return false;
        }
    }

    this.CheckZipCode = function(e) {
        if (window.event) // IE
        {
            var key = event.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {

            var key = e.which;
        }

        if ((key == 189 || key == 109) || self.isSystemKey(key) || self.isNumeric(key)) {
            return true;
        }
        else {
            if (e.which) {
                e.preventDefault();
            }
            return false;
        }
    }

    /*///CheckLcase*/
    this.CheckLcase = function() {
        if (event.keyCode >= 65 && event.keyCode <= 90) {
            return true;
        }
        else {
            return false;
        }
    }

    /*///Ucase*/
    this.CheckUcase = function() {
        if (event.keyCode >= 97 && event.keyCode <= 122) {
            return true;
        }
        else {
            return false;
        }
    }

    /*<!--- 
    *this section deals with masking or corecting data input

	 --->*/

    this.dateMask = function(e) {
        if (window.event) // IE
        {
            var key = event.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {

            var key = e.which;
        }

    }



    this.zipCodeMask = function(e) {
        var oElm = self.setCurrentElement.apply(this, arguments);
        if (window.event) // IE
        {
            var key = event.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {

            var key = e.which;
        }

        if (oElm.value.length >= 5 && !self.isSystemKey(key)) {
            var patt = /\D/g;

            var sVal = oElm.value;

            sVal = sVal.replace(patt, '');
            sVal = sVal.split('');

            if (sVal.length >= 5) {
                sVal[4] = sVal[4] + '-';
            }

            oElm.value = sVal.join('');
        }
        return;
    }

    this.phoneMask = function(e) {
        if (window.event) // IE
        {
            var key = event.keyCode;
        }

        else if (e.which) // Netscape/Firefox/Opera
        {
            var key = e.which;
        }
        var oElm = self.setCurrentElement.apply(this, arguments);

        if (oElm.value.length > 0 && !self.isSystemKey(key)) {
            var patt = /\D/g;

            var sVal = oElm.value;

            sVal = sVal.replace(patt, '');
            sVal = sVal.split('');

            if (sVal.length > 10) {
                sVal[9] = sVal[9] + ' ext.';
            }

            if (sVal.length > 5) {
                sVal[5] = sVal[5] + '-';
            }

            if (sVal.length > 1) {
                sVal[0] = '(' + sVal[0];
            }
            if (sVal.length > 2) {
                sVal[2] = sVal[2] + ') ';
            }

            oElm.value = sVal.join('');
        }
        return;
    }

    this.isImage = function() {
        var o = self.setCurrentElement.apply(this, arguments);

        var string = o.value;
        if (string.length == 0) { self.firePass(o.id); }
        var r = "" + o.getAttribute("validlist") + "$";
        var reg = new RegExp(r);
        if (string.search(reg) == -1) {
            self.fireFail("The image you are trying to upload is in an incorrect format.", o.id);
            return false;
        }

        else {
            self.firePass(o.id);
        }

    }

    this.isWebAddress = function() {

        var o = self.setCurrentElement.apply(this, arguments);
        var string = o.value;

        if (o.value == "")
        {
            return true 
        }
        var urlRegxp = /^(http:\/\/|https:\/\/)(www.)?([\w-_]+.([-_\w]{2,3})+)+?((.\w{2,3})(\/))?((\/\w*.(\w){2,4})?(\/)?)(\?{1}[=&\w]*)?$/;
        if (urlRegxp.test(string)) {
            self.firePass(o.id);
            return true
        }
        else {
            self.fireFail("The url you have entered is an incorrect format.(http://example.com)", o.id);
            return false;
        }
    }

    this.isEmail = function() {

        var o = self.setCurrentElement.apply(this, arguments);
        var string = o.value;

        if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {

            self.firePass(o.id);
            return true;
        }
        else {
            self.fireFail("please check your email address", o.id);
            return false;
        }
    }

    this.isZip = function(sVar) {
        /*/ Check for correct zip code*/
        var o = self.setCurrentElement.apply(this, arguments);
        var string = o.value;

        var reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

        if (!reZip.test(string)) {
            self.fireFail('error', o.id);
            return false;
        }
        self.firePass(o.id);
        return true;

    }

    this.isPostalCode = function(sVar) {
        var o = self.setCurrentElement.apply(this, arguments);
        var string = o.value;

        if (string.search(/^\s*[a-ceghj-npr-tvxy]\d[a-ceghj-npr-tv-z](\s)?\d[a-ceghj-npr-tv-z]\d\s*$/i) != -1) {

            self.firePass(o.id);
            return true;
        }
        else {
            return false;
        }

    }

    this.compareValues = function(sVal) {
        var o = self.setCurrentElement.apply(this, arguments);
        var string = o.value;
        var oE = document.getElementById(o.getAttribute("CompareValues"))
        var eV = oE.value

        if (string != eV) {

            self.fireFail('values for ' + o.getAttribute("CompareValues") + " don't match", o.id);
            return false;
        }
        self.firePass(o.id);
        return true;
    }

    /*<!--- 
    *this uses the ext lib in order to provide a custom confirm box
    * @AlertMessage  (required) is the message  to use in the alert box
    * @sFn 	(optional) function to call
    * @sId	(optional) used to place alert as coming out of a particular DOM element
    --->*/
    this.Confirm = function(AlertMessage, sFn) {

        /*/Ext.MessageBox.confirm('Please Confirm',AlertMessage,)*/
        var sId = '';

        if (arguments[2] != 'undefined') {
            sId = arguments[2];
        };

        Ext.MessageBox.show(
								{
								    title: 'Please Confirm',
								    msg: AlertMessage,
								    buttons: Ext.MessageBox.YESNO,
								    animEl: sId,
								    fn: sFn,
								    icon: Ext.MessageBox.WARNING
								})

    }
    /*<!--- 
    *this uses the ext lib in order to provide a custom alter box
    * @AlertMessage  (required) is the message  to use in the alert box
    * @sId	(optional) used to place alert as coming out of a particular DOM element
    --->*/
    this.fireFail = function(m, i) {
        self.setFormInvalid(i,2);
        self.alert(m, i);
        return;

    }
    this.alert = function(AlertMessage) {
        var sId = '';
        if (arguments[1] != 'undefined') {
            sId = arguments[1];
        };
        alert(AlertMessage);
        // alert(AlertMessage);
        /*//Ext.MessageBox.alert('Alert', AlertMessage);
        Ext.MessageBox.show(
        {
        title: 'Alert Message',
        msg: AlertMessage,
        buttons: Ext.MessageBox.OK, 
        animEl: sId,
        width: 200,
        fn: function(){Ext.get(sId).focus();},
        icon: Ext.MessageBox.WARNING})*/
    }

    this.firePass = function(i) {
        this.setFormValid(i);
        this.clearError(i);
    }
    this.clearError = function() {


    }
}

