function showCadChoice(id)
{
    $('cadIdHolder').value = id;
    var idNum = id.substr(3);
    var partno = $('PARTNO' + idNum).innerHTML;
    var cellIDobj = $(id);
    var cellPosX = findPosX(cellIDobj);
    var cellPosY = findPosY(cellIDobj);
    $('opaqBackCG').show();
    $('getCADcell1').show();
    $('getCADcell2').show();
    $('getCADcell3').show();
    $('cadChoice').style.zIndex = 226;
    var gtype = usingCustom ? $('cgGearType').value.toUpperCase() : $('mainGearType').value.toUpperCase();
    var ptype = $('mainPitchType').value.toUpperCase();
    getPage('Tech_Tools/' + folder + '/cadFormats.php?showPage=false&filledCadFormats=false&gtype=' + gtype + '&ptype=' + ptype, 'getLink');
    $('cadChoiceViewOnlineRow').hide();
    /*if (!hasViewpoint) 
     {
     $('cadChoiceViewOnlineRow').hide();
     }
     if (browserName != 'msie')
     {
     $('cadChoiceViewOnlineRow').hide();
     if (browserName == 'firefox' && browserVersion.substr(0, 1) == '3')
     {
     $('cadChoiceViewOnlineRow').hide();
     }
     }*/
    $('cadChoice').show();
    $('cadChoicePart').innerHTML = partno;
    var cadChoiceH = $('cadChoice').offsetHeight;
    $('cadChoice').style.left = parseInt(cellPosX) + 56 + "px";
    $('cadChoice').style.top = parseInt(cellPosY) - cadChoiceH + "px";
    /*
     if(!$('download3Drad').checked && !$('download2Drad').checked)
     {
     rButton = readCookie('radButton');
     if (rButton == '2D')
     {
     $('download2Drad').checked = true;
     }
     else
     {
     $('download3Drad').checked = true;
     }
     }
     */
    /*
     var format3D = readCookie('3Dformat');
     var format2D = readCookie('2Dformat');
     var cadVersion = readCookie('cadVersion');
     changeSelects(format3D, $('cadChoice3Dformats'));
     changeSelects(format2D, $('cadChoice2Dformats'));
     changeSelects(cadVersion, $('cadChoiceVersions'));
     */
    rButton = readCookie('radButton');
    if (rButton == '2D') 
    {
        $('download2Drad').checked = true;
    }
    else 
    {
        $('download3Drad').checked = true;
    }
    changeVersion();
    
}

function fillFormatSelects(whatD, selectObj, selections)
{
    if (whatD == '2D') 
    {
        $2DversionListObj = $('t2Dversions');
        selectObj.options.length = 0;
        for (x = 0; x < selections.length; x++) 
        {
            selectObj.options[x] = new Option(selections[x], selections[x]);
        }
        
        for (x = 0; x < $2Dversions[0].length - 1; x++) 
        {
            $2DversionListObj.options[x] = new Option($2Dversions[0][x], $2Dversions[0][x]);
            cadChoiceVersionsObj.options[x] = new Option($2Dversions[0][x], $2Dversions[0][x]);
        }
    }
    
    if (whatD == '3D') 
    {
        $3DversionListObj = $('t3Dversions');
        selectObj.options.length = 0;
        for (x = 0; x < selections.length; x++) 
        {
            selectObj.options[x] = new Option(selections[x], selections[x]);
        }
        
        for (x = 0; x < $3Dversions[0].length - 1; x++) 
        {
            $3DversionListObj.options[x] = new Option($3Dversions[0][x], $3Dversions[0][x]);
            cadChoiceVersionsObj.options[x] = new Option($2Dversions[0][x], $2Dversions[0][x]);
        }
    }
}

function showCustomCadChoice(id)
{
    var partno = id;
    $('cadIdHolder').value = 'cad0';
    var x = findPosX($('cgBottomCell'));
    var y = findPosY($('cgBottomCell'));
    var gtype = usingCustom ? $('cgGearType').value.toUpperCase() : $('mainGearType').value.toUpperCase();
    getPage('Tech_Tools/' + folder + '/cadFormats.php?showPage=false&filledCadFormats=false&gtype=' + gtype + '&custom=custom', 'getLink');
    $('cadChoiceViewOnlineRow').hide();
    /*
     if (browserName != 'msie')
     {
     $('cadChoiceViewOnlineRow').hide();
     if (browserName == 'firefox' && browserVersion.substr(0, 1) == '3')
     {
     $('cadChoiceViewOnlineRow').hide();
     }
     }
     */
    $('opaqBackCG').show();
    $('getCADcell1').hide();
    $('getCADcell2').hide();
    $('getCADcell3').hide();
    $('cadChoice').style.left = x + "px";
    $('cadChoice').style.top = parseInt(y) - 30 + "px";
    $('cadChoice').style.zIndex = 226;
    $('cadChoicePart').innerHTML = partno;
    $('cadChoice').show();
    $('download3Drad').checked = true;
    changeVersion();
}

function showDownloadProb()
{
    $('ieDownloadDiv').toggle();
}

function cadControl(e)
{
    var elId = getElemID(e);
    var cadID = $('cadIdHolder').value;
    var idNum = cadID.substr(3);
    
    var partno = "";
    if ($('customGearDiv').visible()) 
    {
        usingCustom = true;
        partno = $('cgMainPN' + CGN).innerHTML;
        gear[CGN].partno = partno;
    }
    else 
    {
        usingCustom = false;
        partno = $('PARTNO' + idNum).innerHTML;
    }
    
    var cadChoiceWarn = 'Please address the following: \r\n\r\n';
    var cadChoiceAlert = false;
    
    var cadChoiceRadio = new findRadioBtn(formInfo.view2D3D);
    var cadChoiceRadioVal = cadChoiceRadio.buttonValue;
    if (!cadChoiceRadioVal) 
    {
        alert('Please select "2D" or "3D"');
        return;
    }
    cadTimer = setInterval("setCadTimer()", 1000);
    switch (cadChoiceRadioVal)
    {
        case "view2Drad":
            $('drawingRadio').checked = true;
            viewIt('view2Drad');//getCadLink(cadID,"view");
            break;
        case "view3Drad":
            $('modelRadio').checked = true;
            viewIt(e);//(cadID,"view");
            break;
        case "download2Drad":
            $('drawingRadio').checked = true;
            if (cadChoiceVersionsObj.value == '--') 
            {
                cadChoiceWarn += 'select your software version. \r\n';
                cadChoiceAlert = true;
            }
            if (cadChoice2DformatsObj.value == '--') 
            {
                cadChoiceWarn += 'select a 2D format \r\n';
                cadChoiceAlert = true;
            }
            if (cadChoiceAlert) 
            {
                alert(cadChoiceWarn);
                return;
            }
            getCadLink(cadID, "download");
            $('cadChoiceMeterDiv').show();
            
            break;
        case "download3Drad":
            $('modelRadio').checked = true;
            if (cadChoiceVersionsObj.value == '--') 
            {
                cadChoiceWarn += 'select your software version. \r\n';
                cadChoiceAlert = true;
            }
            if (cadChoice3DformatsObj.value == '--') 
            {
                cadChoiceWarn += 'select a 3D format \r\n';
                cadChoiceAlert = true;
            }
            if (cadChoiceAlert) 
            {
                alert(cadChoiceWarn);
                return;
            }
            getCadLink(cadID, "download");
            $('cadChoiceMeterDiv').show();
            break;
    }
}

function setCadTimer(setZero)
{
    var args = arguments.callee;
    
    if (!setZero) 
    {
        if (!args.secs) 
        {
            args.secs = 0;
        }
        if (!args.uid) 
        {
            args.uid = 0;
        }
        
        if (args.uid == 0) 
        {
            document.getElementById('cadElapsedTimeMin').innerHTML = '00';
            document.getElementById('cadElapsedTimeSec').innerHTML = '00';
        }
        else 
        {
            min = args.uid / 60;
            min = Math.floor(min);
            document.getElementById('cadElapsedTimeMin').innerHTML = pad(min);
            document.getElementById('cadElapsedTimeSec').innerHTML = pad(args.secs);
            if (args.secs == 59) 
            {
                args.secs = -1;
            }
        }
        args.uid++;
        args.secs++;
    }
    else 
    {
        document.getElementById('cadElapsedTimeMin').innerHTML = '00';
        document.getElementById('cadElapsedTimeSec').innerHTML = '00';
        args.uid = 0;
		args.secs = 0;
    }
}

function pad(num)
{
    return (num < 10 ? '0' : '') + num;
}

function getCadLink(id, getLinkForWhat)
{
    solidworksIsRunning = true;
    if (solidworksIsRunning) 
    {
        ///disable the buttons until getLink and getDownload are completed to stop multiple charges from SW
        downloadBtn1.disabled = true;
        view2Dbtn1.disabled = true;
        view3Dbtn1.disabled = true;
        cadChoiceGetObj.disabled = true;
        for (d = 0; d < 25; d++) 
        {
            if ($('CAD' + d)) 
            {
                cadCell = $('CAD' + d)
                cadCell.onclick = function()
                {
                    doNothing();
                }
                cadCell.setAttribute(attrClass, 'cadLinkD');
            }
        }
        
        ///put the id into the cadIdHolder so it may be used by other functions that don't have access to the cad link
        $('cadIdHolder').value = id;
        
        var cadBox = $('cadIframeBox');
        var idNum = id.substr(3);
        var cadId = $('cadSid').value;
        var gtype = usingCustom ? $('cgGearType').value.toUpperCase() : $('mainGearType').value.toUpperCase();
        var pitchType = $('mainPitchType').value.toUpperCase();
        var partno = usingCustom ? $('cgMainPN' + CGN).innerHTML : $('PARTNO' + idNum).innerHTML;
        var cleanGearType = gtype.replace(/[^a-zA-Z0-9]\s*/g, "").toLowerCase();
        
        
        
        var dp = $('PITCH' + idNum).innerHTML;
        var pa = $('PA' + idNum).innerHTML;
        var $xmlString = '';
        var od = '';
        if ($('OD' + idNum)) 
        {
            od = $('OD' + idNum).innerHTML;
        }
        
        var teeth = '';
        if ($('TEETH' + idNum)) 
        {
            teeth = $('TEETH' + idNum).innerHTML;
        }
        
        var style = '';
        if ($('STYLE' + idNum)) 
        {
            style = $('STYLE' + idNum).innerHTML;
        }
        
        var bore = '';
        if ($('BORE' + idNum)) 
        {
            bore = $('BORE' + idNum).innerHTML;
        }
        
        var fw = $('FACE' + idNum).innerHTML;
        var mpd = '';
        var starts = '';
        var hand = '';
        var oal = '';
        var rackth = '';
        var pLine = '';
        var ha = '';
        var md = '';
        var matePartno = '';
        var usePinion = '';
        var pinionTeeth = '';
        var ratio = '';
        
        if (gtype == 'RACK') 
        {
            oal = $('OAL' + idNum).innerHTML;
            rackth = $('RACKTH' + idNum).innerHTML;
            pLine = $('PLINE' + idNum).innerHTML;
        }
        
        if (gtype == 'WORM GEAR' || gtype == 'WORM') 
        {
            if (gtype == 'WORM GEAR') 
            {
                mpd = $('MATEPD' + idNum).innerHTML;
            }
            if (gtype == 'WORM') 
            {
                mpd = $('PD' + idNum).innerHTML;
            }
            
            starts = $('STARTS' + idNum).innerHTML;
            hand = $('HAND' + idNum).innerHTML;
        }
        
        if (gtype == 'HELICAL') 
        {
            if (usingCustom) 
            {
                ha = gear[CGN].ha; //$('cgHA').value;
                hand = gear[CGN].hand;//$('cgHand').value;
            }
            else 
            {
                ha = $('HA' + idNum).innerHTML;
                hand = $('HAND' + idNum).innerHTML;
            }
        }
        
        if (gtype == 'BEVEL/MITER') 
        {
            md = $('MD' + idNum).innerHTML;
            matePartno = $('MATEPN' + idNum).innerHTML;
            ratio = $('RATIO' + idNum).innerHTML;
            var pnArray = partno.split(/\B|\b/)
            var newString = getNumberNums(pnArray);
            var pLen = dp.length;
            var pPos = newString.indexOf(dp);
            var teethNum = newString.substr(pPos + pLen);
            
            var matePNarray = matePartno.split(/\B|\b/)
            newString = getNumberNums(matePNarray);
            pLen = dp.length;
            pPos = newString.indexOf(dp);
            var mateTeethNum = newString.substr(pPos + pLen);
            
            if (teethNum < mateTeethNum) 
            {
                usePinion = 'TRUE';
                pinionTeeth = teethNum;
                teeth = mateTeethNum;
            }
            else 
            {
                usePinion = 'FALSE';
                pinionTeeth = mateTeethNum;
                teeth = teethNum;
                if (teethNum == mateTeethNum) 
                {
                    usePinion = 'TRUE';
                }
            }
        }
        
        var partLabel = $('cPartno');
        partLabel.innerHTML = "Part # " + partno;
        var cadIEiframe = browserName == 'msie' ? $('cadIframeForIE') : 0;
        showCadIEiframe = browserName == 'msie' ? cadIEiframe.style.display = '' : 0;
        var download2DFormat = $('fExtension2D').value;
        var download2DVersion = $('t2Dversions').value;
        var download3DFormat = $('fExtension3D').value;
        var download3DVersion = $('t3Dversions').value;
        var downloadMsgHolder = $('downloadMsg');
        var drawingOrModel = new findRadioBtn(formInfo.drawingModel);
        var drawingOrModelVal = drawingOrModel.buttonValue;
        var archiveOnOff = $('zipIt').checked;
        var units = usingCustom ? $('cgUnits').value.toUpperCase() : $('mainUnits').value.toUpperCase();
        var kwyW = '';
        var kwyD = '';
        
        ////////////figure out kwy info in decimal form 
        if ($('KWY' + idNum)) 
        {
            //////strip white spaces and conv to lowercase
            var kwyString = $('KWY' + idNum).innerHTML.replaceWS().toLowerCase();
            kwyW = convertKwy(kwyString, units, 'width');
            kwyD = convertKwy(kwyString, units, 'depth');
        }
        
        ///set this value if the zip checkbox is checked "on" means they want a zip file      
        if (archiveOnOff) 
        {
            archive = 'on';
        }
        else 
        {
            archive = 'off';
        }
        
        hd1 = '1';
        hp1 = '1';
        hd2 = '1';
        hp2 = '1';
        
        if (style != 'A') 
        {
            if ($('HD' + idNum)) 
            {
                hd1 = $('HD' + idNum).innerHTML;
            }
            
            if ($('HP' + idNum)) 
            {
                hp1 = $('HP' + idNum).innerHTML;
            }
            
            if ($('HD' + idNum)) 
            {
                hd2 = $('HD' + idNum).innerHTML;
            }
            
            if ($('HP' + idNum)) 
            {
                hp2 = $('HP' + idNum).innerHTML;
            }
        }
        
        if (hd1 == '--') 
        {
            hd1 = 1;
        }
        if (hp1 == '--') 
        {
            hp1 = 1;
        }
        if (platform == 'linux') 
        {
            platform = 'unix';
        }
        
        os = platform;
        
        //////////change this once you change the model names to match the gear types less the spaces
        gtype2 = get3Dgeartype(gtype);
        
        if (units == 'MM') 
        {
        
            gtype2 += "MM";
        }
        
        ///this is the image used for showing the download wait period
        downloadImg = "<img src =\"/images/meter.gif\" alt=\"\" />";//browserName == 'msie' ? "<img src=\"/images/redMeterIE.gif\"  alt=\"\" />" : "<img src=\"/images/redMeter.gif\"  alt=\"\" />";
        if (getLinkForWhat == 'download') 
        {
            ///Once the download type is determined (model or drawing) change this accordingly
            downloadMsgHolder.innerHTML = "Retrieving the " + drawingOrModelVal + ".<br /> This may take a minute! <br />" + downloadImg;
            downloadMsgHolder.style.display = '';
            interfaceName = drawingOrModelVal == 'drawing' ? 'SWGenerateConfigDownload2D' : 'SWGenerateConfigDownload3D';
            vOrD = 'download';
            
            if (drawingOrModelVal == 'drawing' || download2DradObj.checked == true) 
            {
                downloadVersion = cadChoiceVersionsObj.value;
                downloadFormat = download2DFormat;
            }
            else 
            {
                downloadVersion = cadChoiceVersionsObj.value.replaceWith('+', '');
                downloadFormat = download3DFormat;
            }
            downloadVersion = downloadVersion.replaceWith('+', '');
            
            //get and set download controls
            if (usingCustom) 
            {
                view2Dbtn1.disabled = true;
                var $xmlString = 'Tech_Tools/' + folder + '/3Dlinks2.php?cellId=' + id + '&id=' + cadId + '&partno=' + gear[CGN].partno + '&model=' + gtype2;
                $xmlString += '&pitch=' + gear[CGN].pitch + '&pa=' + gear[CGN].pa + '&teeth=' + gear[CGN].teeth + '&style=' + gear[CGN].hubstyle;
                $xmlString += '&bore=' + gear[CGN].bore + '&fw=' + gear[CGN].face + '&hd1=' + gear[CGN].hd1 + '&hp1=' + gear[CGN].hp1;
                $xmlString += '&hd2=' + gear[CGN].hd2 + '&hp2=' + gear[CGN].hp2 + '&mpd=&starts=';
                $xmlString += '&os=' + os + '&vOrD=' + vOrD + '&dFormat2D=tif';
                $xmlString += '&dFormat3D=' + downloadFormat + '&dVersion2D=' + downloadVersion;
                $xmlString += '&dVersion3D=' + downloadVersion + '&dOrM=model';
                $xmlString += '&archive=' + archive + '&iName=' + interfaceName + '&pType=' + gear[CGN].pitchtype + '&units=' + gear[CGN].units;
                $xmlString += '&bName=' + browserName + '&hand=' + hand + '&kwyW=' + gear[CGN].keywidth;
                $xmlString += '&kwyD=' + gear[CGN].keydepth + '&oal=&rackth=&pLine=&ha=' + ha;
                $xmlString += '&usePinion=&pinionTeeth=&md=';
                $xmlString += '&matepn=&ratio=&od=' + gear[CGN].od() + '&filledCadFormats=' + filledCadFormats;
                $xmlString += '&CBnum=' + gear[CGN].cbnum + '&CB1pos=' + gear[CGN].cbpos;
                $xmlString += '&CB1diam=' + gear[CGN].cbdiameter1 + '&CB1depth=' + gear[CGN].cbdepth1;
                $xmlString += '&CB2diam=' + gear[CGN].cbdiameter2 + '&CB2depth=' + gear[CGN].cbdepth2;
                $xmlString += '&keyNum=' + gear[CGN].keynum + '&keyW=' + gear[CGN].keywidth + '&keyD=' + gear[CGN].keydepth;
                $xmlString += '&keyL=' + gear[CGN].keyloc + '&custom=true&backlash=' + gear[CGN].backlash + '&cleanGtype=' + cleanGearType;
                
                
                
                $xmlString += '&key1a=' + gear[CGN]['key1'] + '&key2a=' + gear[CGN]['key2'] + '&key3a=' + gear[CGN]['key3'] + '&key4a=' + gear[CGN].key4 + '&key5a=' + gear[CGN]['key5'];
                $xmlString += '&key6a=' + gear[CGN]['key6'] + '&key7a=' + gear[CGN]['key7'] + '&key8a=' + gear[CGN]['key8'];
                $xmlString += '&ss1=' + gear[CGN]['ss1'] + '&ss2=' + gear[CGN]['ss2'] + '&ss3=' + gear[CGN]['ss3'] + '&ss4=' + gear[CGN]['ss4'] + '&ss5=' + gear[CGN]['ss5'] + '&ss6=' + gear[CGN]['ss6'];
                $xmlString += '&ss7=' + gear[CGN]['ss7'] + '&ss8=' + gear[CGN]['ss8'];
                $xmlString += '&ssSize=' + gear[CGN].sssize;
                $xmlString += '&ssLoc=' + gear[CGN].ssloc;
            }
            else 
            {
                view2Dbtn1.disabled = false;
                $xmlString = 'Tech_Tools/' + folder + '/3Dlinks2.php?cellId=' + id + '&id=' + cadId + '&partno=' + partno + '&model=' + gtype2 + '&pitch=' + dp + '&pa=' + pa + '&teeth=' + teeth + '&style=' + style;
                $xmlString += '&bore=' + bore + '&fw=' + fw + '&hd1=' + hd1 + '&hp1=' + hp1 + '&hd2=' + hd2 + '&hp2=' + hp2 + '&mpd=' + mpd + '&starts=' + starts;
                $xmlString += '&os=' + os + '&vOrD=' + vOrD + '&dFormat2D=' + downloadFormat + '&dFormat3D=' + downloadFormat + '&dVersion2D=' + downloadVersion;
                $xmlString += '&dVersion3D=' + downloadVersion + '&dOrM=' + drawingOrModelVal + '&archive=' + archive + '&iName=' + interfaceName + '&pType=' + pitchType + '&units=' + units;
                $xmlString += '&bName=' + browserName + '&hand=' + hand + '&kwyW=' + kwyW + '&kwyD=' + kwyD + '&oal=' + oal + '&rackth=' + rackth + '&pLine=' + pLine + '&ha=' + ha;
                $xmlString += '&usePinion=' + usePinion + '&pinionTeeth=' + pinionTeeth + '&md=' + md + '&matepn=' + matePartno + '&ratio=' + ratio + '&od=' + od + '&filledCadFormats=' + filledCadFormats;
                $xmlString += '&cleanGtype=' + cleanGearType;
            }
            getPage($xmlString, 'getDownload');
        }
        else 
        {
            vOrD = 'view';
            $('downloadControls').style.display = 'none';
            $('cadView').style.display = 'none';
            
            //show cad info and put an iframe behind it for IE -- set initial page to progress.php
            var cadIbox = $('cadIframe');
            cadIbox.src = '/Tech_Tools/' + folder + '/progress.php?progId=' + cadId + '&partno=' + partno;
            cadBox.style.display = '';
            interfaceName = drawingOrModelVal == 'drawing' ? 'SWGenerateConfigDownload2D' : 'SWGenerateConfigView3D';
            
            if (interfaceName == 'SWGenerateConfigDownload2D') 
            {
                vOrD = 'download';
            }
            ///set position of cad output        		
            var cadBoxH = cadBox.offsetHeight;
            if ($('customGearDiv').visible()) 
            {
                var cgdX = findPosX($('customGearDiv'));
                var cgdY = findPosY($('customGearDiv'));
                cadBox.style.left = parseInt(cgdX) + 220 + 'px';
                cadBox.style.top = parseInt(cgdY) + 28 + 'px';
            }
            else 
            {
                ///position cad output just above the cad link
                var cellBox = $(id);
                var cellPosX = findPosX(cellBox);
                var cellPosY = findPosY(cellBox);
                var cellBoxH = cellBox.offsetHeight;
                cadBox.style.left = parseInt(cellPosX) + 'px';
                cadBox.style.top = parseInt(cellPosY) - parseInt(cadBoxH) + 'px';
            }
            
            if (usingCustom) 
            {
                var $xmlString = 'Tech_Tools/' + folder + '/3Dlinks2.php?cellId=' + id + '&id=' + cadId + '&partno=' + $('cgMainPN' + CGN).innerHTML + '&model=' + gtype2;
                $xmlString += '&pitch=' + gear[CGN].pitch + '&pa=' + gear[CGN].pa + '&teeth=' + gear[CGN].teeth + '&style=' + gear[CGN].hubstyle;
                $xmlString += '&bore=' + gear[CGN].bore + '&fw=' + gear[CGN].face + '&hd1=' + gear[CGN].hd1 + '&hp1=' + gear[CGN].hp1;
                $xmlString += '&hd2=' + gear[CGN].hd2 + '&hp2=' + gear[CGN].hp2 + '&mpd=&starts=';
                $xmlString += '&os=' + os + '&vOrD=view&dOrM=model';
                $xmlString += '&archive=off&iName=SWGenerateConfigView3D&specialView=2D&pType=' + gear[CGN].pitchtype + '&units=' + gear[CGN].units;
                $xmlString += '&bName=' + browserName + '&hand=' + hand;
                $xmlString += '&oal=&rackth=&pLine=&ha=' + ha;
                $xmlString += '&usePinion=&pinionTeeth=&md=';
                $xmlString += '&matepn=&ratio=&od=' + gear[CGN].od() + '&filledCadFormats=true';
                $xmlString += '&CBnum=' + gear[CGN].cbnum + '&CB1pos=' + gear[CGN].cbpos;
                $xmlString += '&CB1diam=' + gear[CGN].cbdiameter1 + '&CB1depth=' + gear[CGN].cbdepth1;
                $xmlString += '&CB2diam=' + gear[CGN].cbdiameter2 + '&CB2depth=' + gear[CGN].cbdepth2;
                $xmlString += '&keyNum=' + gear[CGN].keynum + '&keyW=' + gear[CGN].keywidth + '&keyD=' + gear[CGN].keydepth;
                $xmlString += '&keyL=' + gear[CGN].keyloc + '&backlash=' + gear[CGN].backlash + '&cleanGtype=' + cleanGearType;
                /*var ci4 = 1;
                 
                 for(ci=0;ci<numberOfKeys.length;ci++)
                 {
                 if(numberOfKeys[ci] > -1)
                 {
                 $xmlString += '&key'+ci+'P='+numberOfKeys[ci];
                 
                 }
                 else
                 {
                 $xmlString += '&key'+ci+'P=1';
                 }
                 ci4++;
                 }*/
                $xmlString += '&key1a=' + gear[CGN]['key1'] + '&key2a=' + gear[CGN]['key2'] + '&key3a=' + gear[CGN]['key3'] + '&key4a=' + gear[CGN].key4 + '&key5a=' + gear[CGN]['key5'];
                $xmlString += '&key6a=' + gear[CGN]['key6'] + '&key7a=' + gear[CGN]['key7'] + '&key8a=' + gear[CGN]['key8'];
                $xmlString += '&ss1=' + gear[CGN]['ss1'] + '&ss2=' + gear[CGN]['ss2'] + '&ss3=' + gear[CGN]['ss3'] + '&ss4=' + gear[CGN]['ss4'] + '&ss5=' + gear[CGN]['ss5'] + '&ss6=' + gear[CGN]['ss6'];
                $xmlString += '&ss7=' + gear[CGN]['ss7'] + '&ss8=' + gear[CGN]['ss8'];
                $xmlString += '&ssSize=' + gear[CGN].sssize;
                $xmlString += '&ssLoc=' + gear[CGN].ssloc;
            }
            else 
            {
                $xmlString = 'Tech_Tools/' + folder + '/3Dlinks2.php?cellId=' + id + '&id=' + cadId + '&partno=' + partno;
                $xmlString += '&model=' + gtype2 + '&pitch=' + dp + '&pa=' + pa + '&teeth=' + teeth + '&style=' + style;
                $xmlString += '&bore=' + bore + '&fw=' + fw + '&hd1=' + hd1 + '&hp1=' + hp1 + '&hd2=' + hd2 + '&hp2=' + hp2;
                $xmlString += '&mpd=' + mpd + '&starts=' + starts;
                $xmlString += '&os=' + os + '&vOrD=' + vOrD + '&dOrM=' + drawingOrModelVal + '&iName=' + interfaceName;
                $xmlString += '&dFormat2D=tif&specialView=2D&pType=' + pitchType + '&units=' + units;
                $xmlString += '&bName=' + browserName + '&hand=' + hand + '&kwyW=' + kwyW + '&kwyD=' + kwyD + '&oal=' + oal;
                $xmlString += '&rackth=' + rackth + '&pLine=' + pLine + '&ha=' + ha;
                $xmlString += '&usePinion=' + usePinion + '&pinionTeeth=' + pinionTeeth + '&md=' + md;
                $xmlString += '&matepn=' + matePartno + '&ratio=' + ratio + '&od=' + od + '&filledCadFormats=' + filledCadFormats;
                $xmlString += '&cleanGtype=' + cleanGearType;
            }
            
            getPage($xmlString, 'getLink')
        }
    }
}

function getNumberNums(pnArray)
{
    var pnCount = pnArray.length;
    var newStr = '';
    for (x = 0; x < pnCount; x++) 
    {
        if (isNaN(pnArray[x]) === false) 
        {
            newStr += pnArray[x];
        }
        
        if (pnArray[x] == '-') 
        {
            break;
        }
    }
    
    return newStr;
}

function tickRadio(e)
{
    var elId = getElemID(e);
    //$(elId).checked = true;
    
    
    
    switch (elId)
    
    {
    
        case 'cadChoice2Dformats':
            
            download2DradObj.checked = true;
            
            break;
            
        case 'cadChoice3Dformats':
            
            download3DradObj.checked = true;
            
            break;
            
    }
}

function changeControls(e)
{
    var elId = getElemID(e);
    
    if (elId == 'view2Drad') 
    {
        $('drawingRadio').checked = true;
    }
    
    if (elId == 'view3Drad') 
    {
        $('modelRadio').checked = true;
    }
    var drawingOrModel = new findRadioBtn(formInfo.drawingModel);
    var drawingOrModelVal = drawingOrModel.buttonValue;
    
    if (drawingOrModelVal == 'drawing') 
    {
        showHideElement('t2Dformats', 't3Dformats');
        showHideElement('t2Dversions', 't3Dversions');
    }
    
    if (drawingOrModelVal == 'model') 
    {
        showHideElement('t3Dformats', 't2Dformats');
        showHideElement('t3Dversions', 't2Dversions');
    }
}

function changeVersion(e)
{
    var elId = getElemID(e);
    var radButton = '';
    
    switch (elId)
    {
        case "download2Drad":
            elId = 'cadChoice2Dformats';
            break;
        case "download3Drad":
            elId = 'cadChoice3Dformats';
            break;
        case "view2Drad":
            elId = 't2Dformats';
            break;
        case "view3Drad":
            elId = 't3Dformats';
            break;
        case "error":
            if ($('download3Drad').checked) 
            {
                elId = 'cadChoice3Dformats';
            }
            if ($('download2Drad').checked) 
            {
                elId = 'cadChoice2Dformats';
            }
            break;
    }
    
    if (elId == 't2Dformats' || elId == 'cadChoice2Dformats') 
    {
        //createCookie('radButton','2D',60);
        $2DcurrFormatId = $(elId);
        $2DcurrFormatId = $2DcurrFormatId.selectedIndex;
        $2DversionObj = $('t2Dversions');
        $2DversionObj.options.length = 0;
        cadChoiceVersionsObj.options.length = 0;
        
        for (x = 0; x < $2Dversions[$2DcurrFormatId].length - 1; x++) 
        {
            $2DversionObj.options[x] = new Option($2Dversions[$2DcurrFormatId][x], $2Dversions[$2DcurrFormatId][x]);
            cadChoiceVersionsObj.options[x] = new Option($2Dversions[$2DcurrFormatId][x], $2Dversions[$2DcurrFormatId][x]);
        }
        
        if ($2DversionObj.options.length == '0') 
        {
            $2DversionObj.disabled = true;
            cadChoiceVersionsObj.disabled = true;
        }
        else 
        {
            $2DversionObj.disabled = false;
            cadChoiceVersionsObj.disabled = false;
            if ($2DversionObj.options.length == 2) 
            {
                $('cadChoiceVersions').options[1].selected = true;
            }
        }
        
        //set the hidden element to the format extension format to be used for downloads
        $('fExtension2D').value = $2DformatExtensions[$2DcurrFormatId - 1];
    }
    
    if (elId == 't3Dformats' || elId == 'cadChoice3Dformats') 
    {
        $3DcurrFormatId = $(elId);
        $3DcurrFormatId = $3DcurrFormatId.selectedIndex;
        $3DversionObj = $('t3Dversions');
        $3DversionObj.options.length = 0;
        cadChoiceVersionsObj.options.length = 0;
        
        for (x = 0; x < $3Dversions[$3DcurrFormatId].length - 1; x++) 
        {
            $3DversionObj.options[x] = new Option($3Dversions[$3DcurrFormatId][x], $3Dversions[$3DcurrFormatId][x]);
            cadChoiceVersionsObj.options[x] = new Option($3Dversions[$3DcurrFormatId][x], $3Dversions[$3DcurrFormatId][x]);
        }
        
        if ($3DversionObj.options.length == '0') 
        {
            $3DversionObj.disabled = true;
            cadChoiceVersionsObj.disabled = true;
        }
        else 
        {
            $3DversionObj.disabled = false;
            cadChoiceVersionsObj.disabled = false;
            if ($3DversionObj.options.length == 2) 
            {
                $('cadChoiceVersions').options[1].selected = true;
            }
            else 
            {
                changeSelects(readCookie('cadVersion'), $('cadChoiceVersion'));
            }
        }
        //set the hidden element to the format extension format to be used for downloads
        $('fExtension3D').value = $3DformatExtensions[$3DcurrFormatId - 1];
    }
    if ($('download3Drad').checked) 
    {
        radButton = '3D';
    }
    if ($('download2Drad').checked) 
    {
        radButton = '2D';
    }
    createCookie('radButton', radButton, 60);
    createCookie('3Dformat', $('cadChoice3Dformats').value, 60);
    createCookie('2Dformat', $('cadChoice2Dformats').value, 60);
    //alert('creating cookie for cadversion '+$('cadChoiceVersions').value);
    //createCookie('cadVersion',$('cadChoiceVersions').value, 60);

    //$('cadChoiceVersions').value = '--';
}

function recordVersion(e)
{
    var elId = getElemID(e);
    var version = $('cadChoiceVersions').value;
    var rButton = '';
    /*
     if(elId == 'download2Drad')
     {
     rButton = '2D';
     }
     else
     {
     rButton = '3D';
     }
     */
    //alert('changing version cookie: '+version);
    createCookie('cadVersion', version, 60);
    //createCookie('radButton',rButton,60);
    /*
    
     
    
     
    
     
    
     var versionName = '';
    
     
    
     
    
     
    
     if($('download2Drad').checked)
    
     
    
     
    
     
    
     {
    
     
    
     
    
     
    
     versionName = 'version2D';
    
     
    
     
    
     
    
     }
    
     
    
     
    
     
    
     if($('download2Drad').checked)
    
     
    
     
    
     
    
     {
    
     
    
     
    
     
    
     versionName = 'version3D';
    
     
    
     
    
     
    
     }
    
     
    
     
    
     
    
     if(versionName.length  > 1)
    
     
    
     
    
     
    
     {
    
     
    
     
    
     
    
     
    
     
    
     
    
     
    
     }
    
     
    
     
    
     
    
     */
    
}

function controlButtons()
{
    downloadBtn1.disabled = false;
    cadChoiceGetObj.disabled = false;
    
    if (currentCADview == '3D') 
    {
        view2Dbtn1.disabled = false;
    }
    else 
    {
        view3Dbtn1.disabled = false;
    }
    
    d = 0;
    for (d = 0; d < 25; d++) 
    {
        cadCell = $('CAD' + d);
        if (cadCell) 
        {
            cadCell.onclick = function()
            {
                if (hasCad.indexOf($('mainGearType').value.toLowerCase()) > -1) 
                {
                    showCadChoice(this.id);
                }
            }
            cadCell.setAttribute(attrClass, 'cadLink');
        }
    }
    
    if (usingCustom) 
    {
        view2Dbtn1.disabled = true;
        drawingRadio.disabled = true;
    }
    else 
    {
        drawingRadio.disabled = false;
    }
    
    return;
}

function downloadIt()
{
    var drawingOrModel = new findRadioBtn(formInfo.drawingModel);
    var drawingOrModelVal = drawingOrModel.buttonValue.toLowerCase();
    var cadWarn = 'Please check the following:\n\n';
    var $3DcVersions = $('t3Dversions');
    var $2DcVersions = $('t2Dversions');
    
    var getDL = 'yes';
    
    if (drawingOrModelVal == 'model') 
    {
        if ($3DcadFormats.value == '--') 
        {
            cadWarn += 'Please select a drawing format then select a version if one is available. \n';
            getDL = 'no';
        }
        else 
        {
            if ($3DcVersions.value == '--') 
            {
                cadWarn += 'Please a version compatible with your software.';
                getDL = 'no';
            }
        }
    }
    else 
    {
        if ($2DcadFormats.value == '--') 
        {
            cadWarn += 'Please select a drawing format. \n';
            getDL = 'no';
        }
        else 
        {
            if ($2DcVersions.value == '--') 
            {
                cadWarn += 'Please a version compatible with your software.';
                getDL = 'no';
            }
        }
    }
    
    var id = $('cadIdHolder').value;
    if (getDL == 'yes') 
    {
        getCadLink(id, 'download');
    }
    else 
    {
        alert(cadWarn);
    }
}

function viewIt(e)
{
    var elId = getElemID(e) == 'error' ? e : getElemID(e);
    
    if (elId == 'cadChoiceGet') 
    {
        var cadChoiceRadio = new findRadioBtn(formInfo.view2D3D);
        var cadChoiceRadioVal = cadChoiceRadio.buttonValue;
        elId = cadChoiceRadioVal;
    }
    
    var id = $('cadIdHolder').value;
    if (elId == 'view2Dbtn' || elId == 'view2Drad') 
    {
        $('drawingRadio').checked = 'true';
        currentCADview = '2D';
        view2Dbtn1.disabled = 'true';
        view3Dbtn1.disabled = 'false';
        getCadLink(id, 'view');
    }
    else 
    {
        $('modelRadio').checked = 'true';
        currentCADview = '3D';
        view2Dbtn1.disabled = 'false';
        view3Dbtn1.disabled = 'true';
        getCadLink(id, 'view');
    }
}

function get3Dgeartype(gtypeVal)
{
    gtypeVal = gtypeVal.toUpperCase();
    switch (gtypeVal)
    {
        case "SPUR":
            gtype2 = usingCustom ? 'customSpur' : 'spurGears';
            break;
        case "WORM GEAR":
            gtype2 = usingCustom ? 'customWormGear' : 'wormGears';
            break;
        case "HELICAL":
            gtype2 = usingCustom ? 'customHelical' : 'helicals';
            break;
        case "WORM":
            gtype2 = usingCustom ? 'customWorm' : 'worms';
            break;
        case "RACK":
            gtype2 = usingCustom ? 'customRack' : 'rack';
            break;
        case "CHANGE":
            gtype2 = usingCustom ? 'customChange' : 'changeGears';
            break;
        case "SPIRAL MITER":
            gtype2 = usingCustom ? 'customSpiralMiter' : 'spiralMiter';
            break;
        case "BEVEL/MITER":
            gtype2 = usingCustom ? 'customBevel' : 'bevelGears';
            break;
        case "INTERNAL":
            gtype2 = usingCustom ? 'customInternal' : 'internalGears';
            break;
        case "PINION WIRE":
            gtype2 = usingCustom ? 'customPinionWire' : 'pinionWire';
            break;
        case "STEM PINION":
            gtype2 = usingCustom ? 'customStemPinion' : 'stemPinion';
            break;
    }
    
    return gtype2;
}

function closeCad()
{
    var cadId = $('cadSid').value;
    var cadIbox = $('cadIframe');
    cadIbox.src = '/Tech_Tools/' + folder + '/progress.php?progId=' + cadId;
    $('cadIframeBox').style.display = 'none';
    $('cadIframeForIE').style.display = 'none';
    $('modelRadio').checked = true;
    var mGtype = $('mainGearType').value;
    if (mGtype == 'SPUR' || mGtype == 'WORM GEAR') 
    {
        d = 0;
        for (d = 0; d < 25; d++) 
        {
            cadCell = $('CAD' + d)
            cadCell.onclick = function()
            {
                showCadChoice(this.id);
            }
            cadCell.setAttribute(attrClass, 'cadLink');
        }
    }
    changeControls();
}

function cadLinkD(id)
{
    //handle the CAD link for items that don't handle CAD
    var cadLinkD = $('cadLinkDisabled');
    var gtype = usingCustom ? $('cgGearType').value.toLowerCase() : $('mainGearType').value.toLowerCase();
    if (gtype == 'spur' || gtype == 'worm gear' || gtype == 'worm' || gtype == 'rack' || gtype == 'helical' || gtype == 'change' || gtype == 'bevel/miter') 
    {
        if (platform == 'windows' && browserName != 'opera') 
        {
            cadLinkD.innerHTML = 'You need the Viewpoint Media Player from www.viewpoint.com <br /> in order to view CAD files.';
        }
        else 
        {
            cadLinkD.innerHTML = 'The CAD viewer, Viewpoint Media Player from www.viewpoint.com, is required <br /> but not currently available for your operating system and/or browser.';
        }
    }
    else 
    {
        cadLinkDinfo = 'Cad for these parts will be available soon.<br />2D and 3D CAD is available for spurs gears, <br />helical gears, ';
        cadLinkDinfo += 'bevel gears, worms, worm gears,<br />and change gears. <br />Contact us if you need one right away.';
        cadLinkD.innerHTML = cadLinkDinfo;
    }
    
    if (cadLinkD.style.display == 'none') 
    {
        cadLinkD.style.display = '';
        cadLinkD.style.top = parseInt(yMousePos) - 40 + 'px';
        cadLinkD.style.left = parseInt(xMousePos) + 20 + 'px';
    }
    else 
    {
        cadLinkD.style.display = 'none';
    }
}

