function Spur(teeth, pitch, precision)
{	
    this.partno = '';
    this.geartype = 'spur';
    this.teeth = teeth;
    this.pitch = pitch;
    this.pa = '';
    this.hubstyle = '';
    this.bore = '';
    this.face = '';
    this.hd1 = '';
    this.hp1 = '';
    this.oal = '';
    this.ltb = '';
    this.keytob = '';
    this.ratio = '';
    this.kwy = '';
    this.ss = '';
    this.matepd = '';
    this.cd = '';
    this.pitchtype = '';
    this.hardness = '';
    this.teethinmate = '';
    this.id = '';
    this.material = '';
	this.matl = '';
    this.backlash = '';
    this.hd2 = '';
    this.hp2 = '';
    this.cbnum = '';
    this.cbdiameter1 = '';
    this.cbdepth1 = '';
    this.cbdiameter2 = '';
    this.cbdepth2 = '';
    this.cbpos = '';
    this.keynum = '';
    this.usestdkwy = '';
    this.keywidth = '';
    this.keydepth = '';
    this.keyloc = '';
    this.key1 = 'off';
    this.key2 = 'off';
    this.key3 = 'off';
    this.key4 = 'off';
    this.key5 = 'off';
    this.key6 = 'off';
    this.key7 = 'off';
    this.key8 = 'off';
    this.ssnum = '';
    this.usestdss = '';
    this.sssize = '';
	this.ssloc = '';
    this.ss1 = 'off';
    this.ss2 = 'off';
    this.ss3 = 'off';
    this.ss4 = 'off';
    this.ss5 = 'off';
    this.ss6 = 'off';
    this.ss7 = 'off';
    this.ss8 = 'off';
    this.units = 'inches';
    this.decimalCheck = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
    this.fractionCheck = /^[0-9]+\/{1}[1-9]+[0]*$/;
    this.decFracCheck = /^((\d+(([-]?(\d)+)(?=\/{1}))?((\/)?(?!\.))?(\d)+)|(\d+(\.\d*)?(\d)*)|((\d*\.)?\d+))$/;
    this.stdKwyWfrac = new Array('3/32', '1/8', '3/16', '1/4', '5/16', '3/8', '1/2', '5/8', '3/4', '7/8', '1');
    this.stdKwyDfrac = new Array('3/64', '1/16', '3/32', '1/8', '5/32', '3/16', '1/4', '5/16', '3/8', '7/16', '1/2');
    this.stdKwyWdec = new Array('-', '-', '-', '-', .0625, .0938, .125, .1875, .250, .3125, .375, .500, .625, .750, .875, 1);
    this.stdKwyDdec = new Array('-', '-', '-', '-', .0313, .0469, .0625, .0938, .125, .1563, .1875, .250, .3125, .375, .4375, .500);
    this.stdSSdec = new Array(0, 1, 2, 3, 6, 10, 20, 30, 40, 40, 50, 50, 60, 70, 80, 90);
    this.stdBoreFrac = new Array('7/16', '9/16', '7/8', '1-1/4', '1-3/8', '1-3/4', '2-1/4', '2-3/4', '3-1/4', '3-3/4', '4-1/2');
    this.stdBoreDecL = new Array(.0156, .0625, .125, .1875, .250, .3125, .5, .625, .9375, 1.3125, 1.4375, 1.8125, 2.3125, 2.8125, 3.3125, 3.8125);
    this.stdBoreDecH = new Array(.0625, .125, .1875, .250, .3125, .4375, .5625, .875, 1.25, 1.375, 1.75, 2.25, 2.75, 3.25, 3.75, 4.5);
    this.stdSS = new Array('10-32', '1/4-20', '5/16-18', '3/8-16', '3/8-16', '1/2-13', '1/2-13', '5/8-11', '3/4-10', '7/8-9', '1-8');
    this.decPrecision = precision;
    this.minval = .001;
    this.ultraminval = .0001;
	this.num = 0;
	this.saved = false;
	this.library = new Array('geartype','teeth','pitch','pa','hubstyle','bore','face','hd1','hp1','hd2','hp2','pitchtype',
	'material','backlash','cbnum','cbpos','cbdiameter1','cbdepth1','cbdiameter2','cbdepth2','keynum',
	'keywidth','keydepth','keyloc','key1','key2','key3','key4','key5','key6','key7','key8','matl','od','pd','ssnum','sssize','ssloc',
	'ss1','ss2','ss3','ss4','ss5','ss6','ss7','ss8','units','usestdkwy', 'usestdss');
    
    if (!this.decPrecision) 
    {
        this.decPrecision = 3;
    }
	
    
    //using "self" solves the loss of scope problem when access this object from functions outside the scope of the object
    self = this;    
}

Spur.prototype = {
    pd: function()
    {
        return (parseInt(this.teeth) / parseFloat(this.pitch)).toFixed(this.decPrecision);
    },
    
    od: function()
    {
        return ((parseInt(this.teeth) + 2) / parseFloat(this.pitch)).toFixed(this.decPrecision);
    },
    
    wd: function()
    {
		if(this.pa > 19.99)
		{
			return (2.25/parseFloat(this.pitch)).toFixed(this.decPrecision);
		}
		else
		{
			return (2.157/parseFloat(this.pitch)).toFixed(this.decPrecision);
		}
        /*if (this.pitch > 20) 
        {
            return ((2.2 / parseFloat(this.pitch)) + .002).toFixed(this.decPrecision);
        }
        else 
        {
            return (2.157 / parseFloat(this.pitch)).toFixed(this.decPrecision);
        }*/
    },
    
    addendum: function()
    {
        return (1 / parseFloat(this.pitch)).toFixed(this.decPrecision);
    },
    
    dedendum: function()
    {
		if(this.pa > 19.99)
		{
			return (1.25/parseFloat(this.pitch)).toFixed(this.decPrecision);
		}
		else
		{
			return (1.157/parseFloat(this.pitch)).toFixed(this.decPrecision);
		}
        //return (parseFloat(this.wd()) - parseFloat(this.addendum())).toFixed(this.decPrecision);
    },
    
    rd: function()
    {
        return (parseFloat(this.pd()) - (2 * parseFloat(this.dedendum()))).toFixed(this.decPrecision);
    },
	
	checkPitch: function(id)
	{
		var pitchError = false;
		var pitchErrorReason = '';
		var pitchFocused = false;
		var errorArray = new Array();
		if(this.pitch == 0 || this.pitch == '' || parseFloat(this.pitch) == 0)
		{
			pitchError = true;
			pitchErrorReason = 'The pitch cannot be blank or zero.';
		}
		if(pitchError)
		{
			errorArray = [id,true,pitchErrorReason,this.pitch];
			return errorArray;
		}
		else
		{
			errorArray = [id, false,'',this.pitch];
			return errorArray;
		}
	}, 
    
    checkBore: function(id)
    {
        var boreError = false;
        var boreErrorReason = '';
        var boreFocused = false;
        var errorArray = new Array();
        var maxBore = this.rd() - .002;
        maxBore = maxBore.toFixed(3);
        
        if (parseFloat(this.bore) > parseFloat(maxBore)) 
        {
            boreError = true;
            boreErrorReason = 'The bore must be less than ' + maxBore;
        }
        		
        if (!this.decimalCheck.test(this.bore) && this.bore.length > 0) 
        {
            boreError = true;
            boreErrorReason = 'The bore value must be in this form: # or #.###';
        }
        
        if (parseFloat(this.bore) > maxBore && this.bore.length > 0) 
        {
            boreError = true;
            boreErrorReason = 'The bore diameter cannot be larger than ' + maxBore;
        }
        
        if (this.bore > 0 && (this.bore == '0' || this.bore == '')) 
        {
            boreError = true;
            boreErrorReason = 'In order to have keyways you must have a bore.';
        }
        
        if (this.bore == '0' || this.bore == '' || parseFloat(this.bore) == 0) 
        {
            boreError = true;
            if (maxBore < 0) 
            {
                boreErrorReason = 'Please enter the number of teeth then come back and enter a bore value.';
            }
            else 
            {
                boreErrorReason = 'The bore value cannot be blank, zero or larger than ' + maxBore;
            }
        }
        
        if (this.hubstyle != 'A') 
        {
            if (parseFloat(this.bore) > parseFloat(this.hd1) && this.hd1.length > 0) 
            {
                //boreWarning = true;
                //boreWarningReason = 'The bore will wipe out hub #1 <br />The part can still be built with your value';
            }
            else 
            {
                boreWarning = false;
            }
        }
        
        //returns the form id, if there is an error, the error reason, and the current value
        if (boreError) 
        {
            errorArray = [id, true, boreErrorReason, this.bore];
            return errorArray;
        }
        else 
        {
            errorArray = [id, false, '', this.bore];
            return errorArray;
        }
    },
    
    checkTeeth: function(id)
    {
        var teethError = false;
        var teethErrorReason = '';
        var errorArray = new Array();
        var minTeeth = 8;
                
        if (this.teeth < minTeeth) 
        {
            teethError = true;
            teethErrorReason += 'You need to have more than 8 teeth to build a gear.<br />';            
        }
        if (!this.decimalCheck.test(this.teeth) && this.teeth.length > 0 || this.teeth.indexOf('.') != '-1') 
        {
            teethError = true;
            teethErrorReason += 'The number of teeth must be in this form: ##';
        }
        
        //returns the form id, if there is an error, the error reason, and the current value
        if (teethError) 
        {
            errorArray = [id, true, teethErrorReason, this.teeth];
            return errorArray;
        }
        else 
        {
            errorArray = [id, false, '', this.teeth];
            return errorArray;
        }
    },
    
    checkFace: function(id)
    {
        var minFace = this.minval;
        var faceError = false;
        var faceErrorReason = '';
        var errorArray = new Array();
        
        if (parseFloat(this.face) < minFace) 
        {
            faceError = true;
            faceErrorReason = 'The face width cannot be less than ' + minFace;
        }
        
        if (!this.decimalCheck.test(this.face)) 
        {
            faceError = true;
            faceErrorReason = 'The face width must be in this form: # or #.###';
        }
        
        //returns the form id, if there is an error, the error reason, and the current value
        if (faceError) 
        {
            errorArray = [id, true, faceErrorReason, this.face];
            return errorArray;
        }
        else 
        {
            errorArray = [id, false, '', this.face];
            return errorArray;
        }
    },
    
    checkHubDiameter: function(id)
    {
        if (!id) 
        {
            return 'error';
        }
        //since this function handles more than one hub diameter you must name the hub diameter id with a 1 or 2 at the end 
        var hubError = false;
        var hubNum = id.substr(id.length - 1);
        var hubErrorReason = '';
        var whichHub = 'Hub diameter #1';
        var thisHub = hubNum == '1' ? this.hd1 : this.hd2;
        var minHub = parseFloat(this.bore) + parseFloat(this.minval);
        minHub = parseFloat(minHub.toFixed(3));
        var maxHub = parseFloat(this.rd()) - this.minval;
        maxHub = parseFloat(maxHub.toFixed(3));
        
        if (!this.decimalCheck.test(thisHub) && thisHub.length > 0) 
        {
            hubError = true;
            hubErrorReason = 'The hub diameter must be in this form: # or #.###';
        }
        
        if (parseFloat(thisHub) > maxHub && thisHub.length > 0) 
        {
            hubError = true;
            hubErrorReason += whichHub + ' cannot be larger than ' + maxHub;
        }
        
        if (parseFloat(thisHub) < minHub && thisHub.length > 0) 
        {
            hubError = true;
            hubErrorReason += 'The hub diameter cannot be smaller than than ' + minHub;
        }
        
        if (this.hubstyle == 'B' && thisHub == 0 && hubNum == 1) 
        {
            hubError = true;
            hubErrorReason += 'The hub diameter cannot be blank, zero, larger than ' + maxHub + ' or smaller than ' + minHub;
        }
        
        if (this.hubstyle == 'C' && thisHub == 0) 
        {
            hubError = true;
            hubErrorReason += 'The hub diameter cannot be blank, zero, larger than ' + maxHub + ' or smaller than ' + minHub;
        }
        
        //returns the form id, if there is an error, the error reason, and the current value
        if (hubError) 
        {
            errorArray = [id, true, hubErrorReason, thisHub];
            return errorArray;
        }
        else 
        {
            errorArray = [id, false, '', thisHub];
            return errorArray;
        }
    },
    
    checkHubProjection: function(id)
    {
        if (!id) 
        {
            return 'error';
        }
        var hubProjError = false;
        var hubProjErrorReason = '';
        var hpNum = id.substr(id.length - 1);
        var thisHP = hpNum == 1 ? this.hp1 : this.hp2;
        
        if (this.hubstyle == 'A') 
        {
            this.hp1 = '';
            this.hp2 = '';
            thisHP = '';
        }
        
        if (!this.decimalCheck.test(thisHP) && thisHP.length > 0) 
        {
            hubProjError = true;
            hubProjErrorReason += 'The hub diameter must be in this form: # or #.### <br />';
        }
        
        if (this.hubstyle == 'B' && thisHP == 0 && hpNum == 1) 
        {
            hubProjError = true;
            hubProjErrorReason += 'The hub length cannot be blank or zero. <br />';
            hubProjErrorReason += 'Enter a value or delete the hub diameter.'
        }
        
        if (this.hubstyle == 'C' && thisHP == 0) 
        {
            hubProjError = true;
            hubProjErrorReason = 'The hub length cannot be blank or zero. <br />';
            hubProjErrorReason += 'Enter a value or delete the hub diameter.'
        }
        
        //returns the form id, if there is an error, the error reason, and the current value
        if (hubProjError) 
        {
            errorArray = [id, true, hubProjErrorReason, thisHP];
            return errorArray;
        }
        else 
        {
            errorArray = [id, false, '', thisHP];
            return errorArray;
        }
    },
    
    checkHubStyle: function(id)
    {
        if (this.hd2.length > 0 || this.hp2.length > 0) 
        {
            this.hubstyle = 'C';
        }
        else 
        {
            if (this.hd1.length > 0 || this.hp1.length > 0) 
            {
                this.hubstyle = 'B';
            }
            else 
            {
                this.hubstyle = 'A';
            }
        }
        
        return [id, false, '', this.hubstyle];
    },
    
    checkCounterBoreDiameter: function(id)
    {        
        if (!id) 
        {
            return 'error';
        }
        
        if (typeof id == 'object') 
        {
            id = getElemID(id);
        }
        
        //since this function handles more than one counter bore you must name the counter bores with a 1 or 2 at the end 
        var minCBdiameter = parseFloat(this.bore) + this.minval;
        var cbNumber = id.substr(id.length - 1);
        var usingHub = false;
        var whichHub = '';
        var cbDiamError = false;
        var cbDiamErrorReason = '';
        var cbDiamWarning = false;
        var cbDiamWarningReason = '';
        var thisCBdiameter = cbNumber == '1' ? this.cbdiameter1 : this.cbdiameter2;
        var maxCBdiameter = this.rd();
        minCBdiameter = minCBdiameter.toFixed(4);
        
        if (this.cbnum > 0) 
        {
            if (this.hubstyle == 'A') 
            {
                maxCBdiameter = parseFloat(this.rd()) - parseFloat(this.minval);
                usingHub = false;
            }
            
            if (this.hubstyle == 'B') 
            {
                if (this.cbpos == 'same') 
                {
                    if (cbNumber == '1') 
                    {
                        maxCBdiameter = parseFloat(this.hd1) > 0 ? parseFloat(this.hd1) - parseFloat(this.minval) : parseFloat(this.rd()) - parseFloat(this.minval);
                        whichHub = "hub #1";
                    }
                    else 
                    {
                        maxCBdiameter = parseFloat(this.rd()) - parseFloat(this.minval);
                    }
                }
                else 
                {
                    if (cbNumber == '1') 
                    {
                        maxCBdiameter = parseFloat(this.rd()) - parseFloat(this.minval);
                        whichHub = "hub #1";
                    }
                    else 
                    {
                        maxCBdiameter = parseFloat(this.hd1) > 0 ? parseFloat(this.hd1) - parseFloat(this.minval) : parseFloat(this.rd()) - parseFloat(this.minval);
                        whichHub = "hub #1";
                    }
                }
            }
            
            if (this.hubstyle == 'C') 
            {
                if (this.cbpos == 'same') 
                {
                    if (cbNumber == '1') 
                    {
                        maxCBdiameter = parseFloat(this.hd1) > 0 ? parseFloat(this.hd1) - parseFloat(this.minval) : parseFloat(this.rd()) - parseFloat(this.minval);
                        whichHub = "hub #1";
                    }
                    else 
                    {
                        maxCBdiameter = parseFloat(this.hd2) > 0 ? parseFloat(this.hd2) - parseFloat(this.minval) : parseFloat(this.rd()) - parseFloat(this.minval);
                        whichHub = "hub #2";
                    }
                }
                else 
                {
                    if (cbNumber == '1') 
                    {
                        maxCBdiameter = parseFloat(this.hd2) > 0 ? parseFloat(this.hd2) - parseFloat(this.minval) : parseFloat(this.rd()) - parseFloat(this.minval);
                        whichHub = "hub #2";
                    }
                    else 
                    {
                        maxCBdiameter = parseFloat(this.hd1) > 0 ? parseFloat(this.hd1) - parseFloat(this.minval) : parseFloat(this.rd()) - parseFloat(this.minval);
                        whichHub = "hub #1";
                    }
                }
            }
            
            maxCBdiameter = parseFloat(maxCBdiameter).toFixed(4);
            
            if (parseFloat(thisCBdiameter) > maxCBdiameter) 
            {
                cbDiamError = true;
                cbDiamErrorReason += 'The counter bore diameter cannot be larger than ' + maxCBdiameter + '<br />';
                if (usingHub) 
                {
                    cbDiamWarningReason = 'The counterbore will wipe out ' + whichHub;
                    cbDiamWarning = true;
                }
            }
            
            if (thisCBdiameter == 0 && (cbNumber == 1 || this.cbnum == 2)) 
            {
                cbDiamError = true;
                cbDiamErrorReason += 'The counter bore diameter cannot be blank, zero, larger than ' + maxCBdiameter + ' or smaller than ' + minCBdiameter + '<br />';
            }
            
            if (!this.decimalCheck.test(thisCBdiameter) && thisCBdiameter.length > 0) 
            {
                cbDiamError = true;
                cbDiamErrorReason += 'The counterbore diameter must be in this form: # or #.### <br />';                
            }
            
            //if (parseFloat(thisCBdiameter) < parseFloat(minCBdiameter) && thisCBdiameter.length > 0) 
            if (parseFloat(thisCBdiameter) < parseFloat(minCBdiameter) && thisCBdiameter.length > 0) 
            {
                cbDiamError = true;
                cbDiamErrorReason = 'The counterbore diameter must be larger than ' + minCBdiameter;
            }
        }
        else 
        {
            thisCBdiameter = '';
        }
        
        //returns the form id, if there is an error, the error reason, and the current value
        if (cbDiamError) 
        {
            errorArray = [id, true, cbDiamErrorReason, thisCBdiameter];
            return errorArray;
        }
        else 
        {
            errorArray = [id, false, '', thisCBdiameter];
            return errorArray;
        }
        
        /*if (cbDiamWarning) 
         {
         this.setupWarnings(isFocused, currentObj, cbDiamError, cbDiamWarningReason);
         }
         else
         {
         errorWarningReasons[currentObj.id] = '';
         errorWarnings[currentObj.id] = false;
         }*/
    },
    
    checkCounterBoreDepth: function(id)
    {
        if (!id) 
        {
            return 'error';
        }
        cbdNumber = id.substr(id.length - 1);
        var maxCBdepth = 0;
        var usingHub = false;
        var whichHub = '';
        var cbDepthError = false;
        var cbDepthErrorReason = '';
        var cbDepthWarning = false;
        var cbDepthWarningReason = '';
        var face = this.face > 0 ? parseFloat(this.face) : this.face;
        this.oal = this.face > 0 ? parseFloat(this.face) : this.face;
        var cb1d = this.cbdepth1 > 0 ? parseFloat(this.cbdepth1) : 0;
        var cb2d = this.cbdepth2 > 0 ? parseFloat(this.cbdepth2) : 0;
        var hd1 = this.hd1 > 0 ? parseFloat(this.hd1) : this.hd1;
        var hd2 = this.hd2 > 0 ? parseFloat(this.hd2) : this.hd2;
        var thisCBdepth = cbdNumber == '1' ? this.cbdepth1 : this.cbdepth2;
        var oppCBd = cbdNumber == '1' ? parseFloat(cb2d) + parseFloat(this.ultraminval) : parseFloat(cb1d) + parseFloat(this.ultraminval);
        
        if (this.hubstyle != 'A') 
        {
            if (this.hd1 > 0) 
            {
                if (this.hp2 > 0) 
                {
                    this.oal = parseFloat(this.hp1) + parseFloat(this.hp2) + parseFloat(this.face);
                }
                else 
                {
                    this.oal = parseFloat(this.hp1) + parseFloat(this.face);
                }
            }
        }
        else 
        {
            this.oal = parseFloat(this.face);
        }
        
        if (this.hubstyle == 'A') 
        {
            maxCBdepth = parseFloat(this.oal) - parseFloat(oppCBd) - parseFloat(this.ultraminval);
        }
        
        if (this.hubstyle == 'B') 
        {
            if (this.cbpos == 'opposite') 
            {
                maxCBdepth = this.cbdiameter1 > (parseFloat(this.hd1) - .001) ? face - oppCBd : this.oal - oppCBd;
            }
            else 
            {
                maxCBdepth = this.oal - oppCBd;
            }
        }
        
        if (this.hubstyle == 'C') 
        {
            maxCBdepth = this.oal - oppCBd;
        }
        
        if (this.cbpos == 'opposite') 
        {
            if (parseFloat(this.cbdiameter1) >= parseFloat(this.hd1) && thisCBdepth > (parseFloat(this.face) - parseFloat(this.ultraminval))) 
            {
                cbDepthError = true;
                cbDepthErrorReason += 'The counter bore depth and diameter will not work.<br /> Make the depth less than ' + this.face + '<br /> Or make the diameter less than ' + this.hd1 + '<br />';
            }
        }
        
        maxCBdepth = parseFloat(maxCBdepth).toFixed(4);
        
        if (parseFloat(thisCBdepth) > maxCBdepth) 
        {
            cbDepthError = true;
            cbDepthErrorReason += 'The counter bore depth must be less than ' + maxCBdepth + '<br />';
        }
        
        if (this.cbnum > 0) 
        {
            if (thisCBdepth == 0 && (cbdNumber == 1 || this.cbnum == 2)) 
            {
                cbDepthError = true;
                if (parseFloat(this.cbdiameter1) >= parseFloat(this.hd1) && this.cbpos == 'opposite') 
                {
                    cbDepthErrorReason += 'The counter bore depth cannot be blank, zero or deeper than ' + (parseFloat(this.face) - parseFloat(this.ultraminval)) + '<br />';
                    cbDepthErrorReason += 'Enter a value or delete the counter bore diameter.';
                }
                else 
                {
                    cbDepthErrorReason += 'The counter bore depth cannot be blank, zero or deeper than ' + maxCBdepth + '<br />';
                    cbDepthErrorReason += 'Enter a value or delete the counter bore diameter.';
                }
            }
            
            if (!this.decimalCheck.test(thisCBdepth) && this.cbnum > 0 && thisCBdepth.toString().length > 0 && (cbdNumber == 1 || this.cbnum == 2)) 
            {
                cbDepthError = true;
                cbDepthErrorReason += 'The counter bore depth must be in this form: # or #.### <br />';
            }
        }
        else 
        {
            thisCBdepth = '';
        }
        
        //returns the form id, if there is an error, the error reason, and the current value
        if (cbDepthError) 
        {
            errorArray = [id, true, cbDepthErrorReason, thisCBdepth];
            return errorArray;
        }
        else 
        {
            errorArray = [id, false, '', thisCBdepth];
            return errorArray;
        }
    },
    
    checkCBnum: function(id)
    {
        if (this.cbdiameter2.length > 0 || this.cbdepth2.length > 0) 
        {
            this.cbnum = '2';
        }
        else 
        {
            if (this.cbdiameter1.length > 0 || this.cbdepth1.length > 0) 
            {
                this.cbnum = '1';
            }
            else 
            {
                this.cbnum = '0';
            }
        }
        
        return [id, false, '', this.cbnum];
    },
    
    checkKeyWidth: function(id)
    {
        var keyWidthError = false;
        var keyWidthErrorReason = '';
        
        if (this.keynum == '') 
        {
            this.keynum = 0;
        }
        
        if (this.keynum == 0) 
        {
			//console.log("keywidth"+this.keywidth+"  string="+this.keywidth.toString()+"  len="+this.keywidth.toString().length);
            if (this.keywidth.toString().length > 0) 
            {
                keyWidthError = true;
                keyWidthErrorReason += 'Please click on a keyway location in the diagram to the right. <br />';
            }
        }
        
        if (this.keywidth.toString().length > 0 || this.keynum > 0) 
        {
            if (this.bore == 0 || this.bore == '' || parseFloat(this.bore) == 0) 
            {
                keyWidthError = true;
                keyWidthErrorReason += 'The bore diameter must be greater than ' + this.keywidth + '.<br />';
            }
            
            if (!this.decimalCheck.test(this.keywidth) && this.keywidth.toString().length > 0) 
            {
                keyWidthError = true;
                keyWidthErrorReason += 'The key width must be in this form: # or #.### <br />';
            }
            
            if (parseFloat(this.keywidth) > parseFloat(this.bore)) 
            {
                keyWidthError = true;
                keyWidthErrorReason += 'The keyway cannot be wider than ' + this.bore + '.<br />';
            }
            
            if (this.keywidth == '') 
            {
                keyWidthError = true;
                keyWidthErrorReason += 'The key width cannot be blank <br />';
            }
        }
                        
        if (this.keywidth > 0 && this.keydepth > 0) 
        {
            keyCornerLen = Math.sqrt((Math.pow(parseFloat(this.bore) / 2 + parseFloat(this.keydepth), 2)) + Math.pow(parseFloat(this.keywidth) / 2, 2));
            
            if (keyCornerLen > parseFloat(this.rd()) - this.minval) 
            {
                keyWidthError = true;
                keyWidthErrorReason += 'The keyway is too deep and\/or too wide and will break through the root of a tooth. <br /> Try reducing the key width or depth.<br />';
            }
        }
        
        /*keyway location 
         if (this.keyloc == 'space')
         {
         $('keywayGearDiv').show();
         $('keywayGearPos').src = '/images/keywaysSpace.gif';
         }
         
         if (cgKeyLocObj.value == 'tooth')
         {
         $('keywayGearDiv').show();
         $('keywayGearPos').src = '/images/keywaysTooth.gif';
         cgKeyNumObj.style.backgroundColor = '#FFFF66';
         }
         
         if (cgKeyLocObj.value == 'any')
         {
         $('keywayGearDiv').show();
         $('keywayGearPos').src = '/images/keywaysAny.gif';
         }
         
         if (this.keynum < 1)
         {
         if (this.keynum == 0)
         {
         if (elId)
         {
         removeKeys();
         }
         }
         }
         */
        /* if (keyWidthError) 
         {
         this.setupMessages(isFocused, keyWidthErrorReason, this.bore);
         $('keywayTab').style.backgroundImage = 'url("/images/tabError.gif")';
         }
         */
        //returns the form id, if there is an error, the error reason, and the current value
        if (keyWidthError) 
        {
            errorArray = [id, true, keyWidthErrorReason, this.keywidth];
            return errorArray;
        }
        else 
        {
            errorArray = [id, false, '', this.keywidth];
            return errorArray;
        }
        
        return;
    },
    
    checkKeyDepth: function(id)
    {
        var keyDepthError = false;
        var keyDepthErrorReason = '';
        
        if (this.keynum == '') 
        {
            this.keynum = 0;
        }
        
        if (this.keynum == 0) 
        {
            if (this.keydepth.toString().length > 0) 
            {
                keyDepthError = true;
                keyDepthErrorReason += 'Please click on a keyway location in the diagram to the right. <br />';
            }
        }
        
        if (this.keydepth.toString().length > 0 || this.keynum > 0) 
        {
            if (!this.decimalCheck.test(this.keydepth)) 
            {
                keyDepthError = true;
                keyDepthErrorReason += 'The key depth must be in this form: # or #.### <br />';
            }
            
            if (this.bore == 0 || this.bore == '' || parseFloat(this.bore) == 0) 
            {
                keyDepthError = true;
                keyDepthErrorReason += 'The bore diameter must be greater than ' + this.keywidth + '.<br />';
            }
            
            var keyDepthHubCheck = (Math.pow((parseFloat(this.bore) / 2) + parseFloat(this.keydepth), 2) + Math.pow((parseFloat(this.keywidth.value) / 2), 2)).toFixed(3);
            keyDepthHubCheck = (Math.sqrt(keyDepthHubCheck)).toFixed(3);
            
            if (((parseFloat(this.keydepth.value)) + (parseFloat(this.bore) / 2)) > ((parseFloat(this.rd()) - parseFloat(this.minVal)) / 2) && this.keydepth > 0) 
            {
                keyDepthError = true;
                keyDepthErrorReason = 'The Keyway depth cannot be greater than ' + this.maxKeyDepth.toFixed(3);
            }
            
            if (keyDepthHubCheck > (parseFloat(this.hd1) / 2) && this.hubstyle != 'A' && this.hd1.length > 0) 
            {
                var keyDepthHubCheckVal = Math.sqrt((Math.pow(parseFloat(this.hd1) / 2, 2) - Math.pow((parseFloat(this.keywidth) / 2), 2))) - parseFloat(this.bore) / 2;
                keyDepthHubCheckVal = keyDepthHubCheckVal.toFixed(3);
                keyWarning = true;
                keyDepthWarningReason = 'The keyway will break through hub diameter #1. <br />' + keyDepthHubCheckVal + ' will not break through.<br /> The part can still be built with your value.'
            }
            
            if (keyDepthHubCheck > (parseFloat(this.hd2) / 2) && this.hubstyle == 'C') 
            {
                var keyDepthHubCheckVal = ((parseFloat(this.hd2) / 2) - (parseFloat(this.bore) / 2) - parseFloat(this.ultraminval)).toFixed(4);
                keyWarning = true;
                keyDepthWarningReason = 'The keyway will break through hub diameter #2. <br />' + keyDepthHubCheckVal + ' will not break through.<br /> Still able to be built with your value.'
            }
        }
        
        if (this.keywidth > 0 && this.keydepth > 0) 
        {
			keyCornerLen = 2*(Math.sqrt((Math.pow(parseFloat(this.bore) / 2 + parseFloat(this.keydepth), 2)) + Math.pow(parseFloat(this.keywidth) / 2, 2)));
            
            if (keyCornerLen > parseFloat(this.rd()) - this.minval) 
            {
                keyDepthError = true;
                keyDepthErrorReason += 'The keyway is too deep and\/or too wide and will break through the root of a tooth. <br /> Try reducing the key width or depth.<br />';
            }
        }
        
        //returns the form id, if there is an error, the error reason, and the current value
        if (keyDepthError) 
        {
            errorArray = [id, true, keyDepthErrorReason, this.keydepth];
            return errorArray;
        }
        else 
        {
            errorArray = [id, false, '', this.keydepth];
            return errorArray;
        }
        
        return;
    }
}
