﻿//////////////////////////////////////////////////////////////////////////////////////////////////
// John Warner (warnerj5000@gmail.com)
// PHD, Inc 2007
// Purpose: This javascript file handles the RotRightCol.html file.
//          RotRightCol.html contains the outputs for the rotary sizing.
//          The standard UnitConverter outputs and the listbox. 
//          All DHTML for the right column of rotary.html will be handled 
//          within this javascript file.
//          
//          The javascript to handle flash and the details button... maybe here, maybe another file
//
//////////////////////////////////////////////////////////////////////////////////////////////////
function element(id) // find control regardless of web-browser.
{
    if (document.getElementById != null)
        return document.getElementById(id) ;

    if (document.all != null)  // for old IE
        return document.all[id] ;

    if (document.layers != null)  // for old NS
        return document.layers[id] ;

    return null ;  // give up
}

function rightLoad()
{
    var divDetails = element("divDetails");
    var App2divDetails = element("App2divDetails");
    divDetails.innerHTML = iframeText("ifrResults");
     element("cbMarginal").checked = true;
    //divDetails.style.width = "100px";
   // try
   // {
    App2divDetails.innerHTML   = iframeText("App2ifrResults");
   // }
    //catch(err)
    //{
    //    //alert("err: " + err);
    //}
}


function loadImperial()
{
    var InertiaUOM = element("spnUCInertia").innerText, 
    InertiaUOM = element("hidInLbS2").value;
    
    return;
}


function iframeText(id)
{
    var sText;    

    if(window.frames[id])
    {
        sText = window.frames[id].document.body.innerHTML;
    }
    else
    {
        sText = document.getElementById(id).contentDocument.body.innerHTML;
    }
    
    return sText;
}

function outputUCSetup(colName)
{
    loadImperial();
    
    SetupUC(colName + "imgInertiaMinus", colName + "txtInertia", colName + "imgInertiaPlus",  colName + "spnUCInertia", "inertia", element("hidInLbS2").value, "0", 1, 1, 4, 0, Infinity, true) ;        
    SetupUC( colName + "imgReqTorqueMinus",  colName + "txtReqTorque",  colName + "imgReqTorquePlus",  colName + "spnUCReqTorque", "torque", element("hidInLb").value, "0", 1, 1, 4, 0, Infinity, true) ;        
   
     SetupUC(colName + "imgTotalInertiaMinus", colName + "txtTotalInertia", colName + "imgTotalInertiaPlus",  colName + "spnUCTotalInertia", "inertia", element("hidInLbS2").value, "0", 1, 1, 4, 0, Infinity, true) ;        
    SetupUC( colName + "imgTotalReqTorqueMinus",  colName + "txtTotalReqTorque",  colName + "imgTotalReqTorquePlus",  colName + "spnUCTotalReqTorque", "torque", element("hidInLb").value, "0", 1, 1, 4, 0, Infinity, true) ;        
   
    SetupUC( colName + "imgPeakVelocityMinus",  colName + "txtPeakVelocity",  colName + "imgPeakVelocityPlus",  colName + "spnUCPeakVelocity", "angularvelocity", element("hidDegSec").value, "0", 1, 1, 4, 0, Infinity, true) ;        
    SetupUC( colName + "imgAccelerationMinus",  colName + "txtAcceleration",  colName + "imgAccelerationPlus",  colName + "spnUCAcceleration", "angularacceleration", element("hidDegSec2").value, "0", 1, 1, 4, 0, Infinity, true) ;        
    SetupUC( colName + "imgKineticEnergyMinus",  colName + "txtKineticEnergy", colName +  "imgKineticEnergyPlus", colName +  "spnUCKineticEnergy", "energy", element("hidInLb").value, "0", 1, 1, 4, 0, Infinity, true) ;        
    SetupUC( colName + "imgBacklashMinus", colName +  "txtBacklash", colName +  "imgBacklashPlus", colName +  "spnUCBacklash", "angle", element("hidDegree").value, "0", 1, 1, 4, 0, Infinity, true) ;        
   
    return;
}

function getSelectedIndex(col, startIndex)
{
    var lbPartList = element(col + "lbPartList");
    var selected = 0; // if nothing is selected, set to 0
    var index;
    if (startIndex == undefined)
        index = 0;
    else
        index = startIndex;
        
    for (var i=index; i <= lbPartList.options.length-1; i++) 
    {   
        if (lbPartList.options[i].selected) 
        { 
            selected = i;
            break;
        }
    }    
    return selected;
}

function getSelectedRotName(index, col)
{
      
    var lbPartList = element(col + "lbPartList");; 
    var rotName; 
   
    
    try
    {
         rotName = lbPartList.options[index].innerHTML;    
    }
    catch(e)
    {
        try
        {
            rotName = lbPartList.options[0].innerHTML;  
        }
        catch(e)
        {
            rotName = "";
        }  
    }
    rotName = removeStatus(rotName);    
    return rotName;    
}

function removeStatus(name)
{
    var index = name.indexOf("x");
    if (name.substr(0,4) == "Rx1A")
        name = name.substr(0,5);
    else if (name.substr(0,4) == "Rx3R")
        name = name.substr(0,6);
    else if (name.substr(0,4) == "3Rx1")
        name = name.substr(0,7);
    else if (name.substr(0,4) == "3Rx3")
        name = name.substr(0,7);
    else if (name.substr(0,4) == "4Rx1")
        name = name.substr(0,7);
    else if (name.substr(0,4) == "5Rx1")
        name = name.substr(0,7);    
        
    else
        name = name.substr(0,index);
        
    return name;
}

function FailedClick(col)
{
  var
	cbFail = element(col + "cbFailed"),
	cbMarg = element(col + "cbMarginal");
	
  if (cbFail.checked)
	cbMarg.checked = true ;

  cbMarg.disabled = cbFail.checked ;

  //InputChanged(this.id) ;
  //InputChanged(new DummyEvent(col + "rbMetricInputs")) ; 
  return;
}

function MarginalClick(col)
{
  //InputChanged() ;
  //InputChanged(new DummyEvent(col + "rbMetricInputs")) ; 
}
//*****

function setImgSelected()
{
    // 
    var i = getSelectedIndex();
    var lbPartList = element("lbPartList");
    var selected = lbPartList[i].value;
    var img = element("imgRotSelect");
    
    // alert("selected: " + selected);
    
    if (selected.search("R11") >= 0 || selected.search("R16")>= 0)
    {
        img.src = "images/Rotaries/1-8000rot_H100.gif";
    }
    else if (selected.search("R21")>= 0 || selected.search("R26")>= 0)
    {
        img.src = "images/Rotaries/MultPosRot_H100.gif";
    }
    else if (selected.search("R13R")>= 0 || selected.search("R23R")>= 0)
    {
        img.src = "images/Rotaries/TD2-8000_H100.gif";
    }
    else if (selected.search("RA")>= 0)
    {
        img.src = "images/Rotaries/RArot_H100.gif";
    }
    else if (selected.search("RCC")>= 0)
    {
        img.src = "images/Rotaries/RCCrot_H100.gif";
    }
    else if (selected.search("RF")>= 0)
    {
        img.src = "images/Rotaries/RFrot_H100.gif";
    }
    else if (selected.search("RI")>= 0)
    {
        img.src = "images/Rotaries/RIrot_H100.gif";
    }
    else if (selected.search("RL")>= 0)
    {
        img.src = "images/Rotaries/RLrot_H100.gif";
    }
}