//v1.3: Anson: backup _4: introducing Combustion writeModelTDs
// // v1.2: Anson: backup _3: introducing more writeModelTDs
// // v1.1: introduce writeTD for each page..
// v1.0: fine until 6-12-11

// called from applet..
function doAlert(s) {
    oTop.bottomPanel.alertAppletBottom(s)
}

function switchImage(docID,imageFile){
        document[docID].src = imageFile;
}
//border paint and tip on mouseover child page icons
//mouse over daemon icons on the page: sID is the model name, sDaemon is the daemon name, only needed when sTip is blank and a Model keyword is there.
function handleMouseOver(sID,sTip, sDaemon){
    //alert(sTip);
       var oEl = document.getElementById(sID);
       oEl.style.backgroundColor = "#cccccc";
       var sTitle = '<nobr>' + sDaemon + '</nobr>';
       if(sTip == ''){
           sTip = '<nobr>Takes you to<br/></nobr>'+sID+' page';
           if(sID.indexOf('Model')!=-1) sTip = '<nobr>Launches the '+sID+' </nobr><br/><nobr>'+sTitle+' </nobr><br/>';
           if(sID.indexOf('Simulator')!=-1) sTip = '<nobr>Launches the '+sID+' </nobr><br/><nobr>'+sTitle+' </nobr><br/>';
           //goTip('Takes you to<br/>'+sID+' page');
           //return;
       }
       goTip(sTip);
}
function handleMouseOut(sID){
       var oEl = document.getElementById(sID);
       oEl.className='borderNoLine';
       oEl.style.backgroundColor = "#eeeeee"
       UnTip('');
}
//border paint on mouseover address images
function handleMouseOverAddress(sID,iLevel){
    //alert(iLevel);
       var sTip = 'Go back to this page';
       var oEl = document.getElementById(sID);
       oEl.className='borderLineAddress';

       if(sID.indexOf('End')!=-1) sTip = 'This is the <br/>current page';
       else if(sID.indexOf('0')!=-1)sTip ='Go to <br/>home page';
       else if(iLevel){
           if(iLevel == 1) sTip = 'Go up '+ iLevel + ' level';
           else sTip = 'Go up '+ iLevel + ' levels';
       }

       goTip(sTip);
}
function handleMouseOutAddress(sID){
       var oEl = document.getElementById(sID);
       oEl.className='borderNoLineAddress';
       UnTip('');
}


// called from every choice table, the model descriptions are created here as template
// for customized model description call writeModelExample (see rias.html first row)
function writeModelTDs(sID, nColSpan,sEx, asPage, asLink, asTip) { //args: id, colspan, spec.example, pages to visit
    if(!asLink)asLink = [0,'','','','','','','','',''];
    if(!asTip)asTip = ['','','','','','','','','',''];
    var s = '<td width = "85%" colspan="' +nColSpan +'" class="tabledata"><p/>';
    //alert(sEx);
    switch(sID){
        case 'PC Model':
            s += '<span class="td_mainheading"> Pure Phase-Transition Fluid: </span>The phase-change (<span class="specialword-orange">PC</span>)'+
                 ' model can be used to determine states of sub-cooled (compressed) liquid, super-heated vapor, and saturated mixture of liquid and vapor phases.  Based on the <span class="tabledata italics"> saturation</span> and <span class="tabledata italics">'+
                 ' super-heated </span> tables, the model is quite accurate.  Sub-cooled liquid is modeled with the'+
                 ' compressed-liquid sub-model, except for species with an asterisk (H2O* as opposed to H2O), which uses compressed liquid table for better accuracy.'+
                 ' </p></p>Working fluids such as H2O, R-12, NH3, R-134a, N2, CO2,'+
                 ' etc., should be treated as PC fluids if there is any possibility of a phase transition. ';
    
          break;
          
        case 'SL Model':
             s += '<span class="td_mainheading"> Pure Solid and Pure Liquid: </span>Constant density '+
            'and constant specific heats (<i class="math">c<sub>p</sub></i> = <i class="math">c<sub>v</sub></i> = c) '+
            'characterize the solid/liquid (<span class="specialword-orange">SL</span>) model. '+
            'Beside a wide selection to choose '+
            'from, a new solid or liquid can be created by assigning custom material '+
            'properties. '+
            '</p></p>Working substances such as steel, iron, copper, aluminum, wood, water, oil, etc., '+
            'which can be assumed to maintain their condensed (solid or liquid) phase '+
            'when a system undergoes other changes, can be analyzed with the SL model.';
          break;
          
        case 'PG Model':
             s += '<span class="td_mainheading"> Pure Perfect  Gas: </span>The perfect gas'+
            ' (<span class="specialword-orange">PG</span>) model is the simplest gas model. It obeys the ideal gas equation of state (<span class="italics">pv=RT</span>); '+
            ' moreover, the <span class="tabledata"> specific heats </span>are assumed'+
            ' constants. Noble gases, He, Ar, Ne, etc., are genuinely perfect gases. Beside a wide selection, new gases can be constructed by assigning custom'+
            ' material properties. A perfect gas can be considered as a simplified ideal gas. </p>';
          break;

        case 'IG Model':
             s += '<span class="td_mainheading"> Pure Ideal Gas: </span>An ideal gas'+
            ' (<span class="specialword-orange">IG</span>) is a gas that obeys the ideal gas equation'+
            ' of state (<span class="italics">pv=RT</span>). Specific heats are temperature dependent. '+
            ' As a result the IG model is more accurate than the PG model when variation in temperature is significant. Choose from an wide'+
            ' selection of gases.';
          break;

        case 'RG Model':
             s += '<span class="td_mainheading"> Pure Real Gas: </span>Based on the generalized <span class="specialword-orange">'+
            ' compressibility chart</span> (<span class="italics">pv=ZRT</span>), the <span class="specialword-orange">real gas</span>'+
            ' (<span class="specialword-orange">RG</span>) model can handle a large number'+
            ' of fluids in their liquid, vapor or gaseous states. But generality'+
            ' comes  at the expense of accuracy.';
        break;

        case 'Pure Gas':
             s += '<span class="td_mainheading"> Pure Gas: </span>A pure gas has a fixed chemical composition across space and time. Oxygen, nitrogen, and air are examples of a pure gas. The PG (perfect gas) model is the simplest gas model which obeyes the ideal gas equation (<span class="italics">pv = RT</span>) and assumes specific heats to be constant. In the IG (ideal gas) model, specific heats are assumed to be function of temperature only. The RG (real gas) model uses generalized compressiblity charts and is useful for gases near the critical or super-critical conditions for which PC-model data are not avaiable. '+
             '';
        break;

        case 'Binary Mixture':
             s += '<span class="td_mainheading"> Binary Mixture: </span>The  mixture of two gases, A and B,  is expressed'+
             ' in terms of the mass or mole fraction of gas-A. Select one of the mixture models. Moist air is a special case of a binary mixture (PG+PG) of dry gas and water vapor.';
        break;

        case 'Two Different Gases':
             s += 'The binary mixture model allows the two gases to be chemically different. You select the two gases from two fluid selectors, A and B. The mass (or mole) fraction of gas-A determines if the working fluid is a pure gas-A (<i class="math">x<sub>A</sub></i> = 1), pure gas-B (<i class="math">x<sub>A</sub></i> = 0), or a mixture (0&lt;<i class="math">x<sub>A</sub></i>&lt;1).';
        break;

        case 'MA Model':
             s += 'The moist air'+
            ' (<span class="specialword-orange">MA</span>) model captures the behavior of a moist gas (not just air) by introducing additional properties such as relative and absolute humidity, dry and wet bulb temperature, etc. The gas mixture is assumed to consist of dry gas and water vapor, with each component treated as a perfect gas. </p>';
          break;

        case 'General Mixture':
             s += '<span class="td_mainheading"> General Mixture: </span>Mixture can contain an unlimited number, <i class="math">n</i>, of species.'+
             ' Composition can be specified through mass, volume, mass fraction, or mole fraction.';
        break;

        case 'n-IG Model':
             s += '<span class="td_mainheading"> General Mixture: </span>The working fluid can be a general mixture of ideal gases (n-IG). Form the mixture just once with up to sixty '+
                 'gases and use it as the working fluid for the entire cycle.';
        break;
        case 'Ideal Gas Equilibrium (IGE) Mixture':
             s += '<span class="td_mainheading"> Ideal Gas Equilibrium (IGE) Mixture: </span>\n'+
             ' An initial (reactants) mixture, (say, 1 kmol of O<sub>2</sub> and 3.76 kmol of N<sub>2</sub>) is specified. Thereafter, any state can be '+
             'calculated (say, for a given temperature and pressure) with the mixture composition itself a variable. Possible  species in the equilibrium '+
             'mixture are user selected (say, O<sub>2</sub>, N<sub>2</sub>, NO, NO<sub>2</sub>, O, N, and O<sub>3</sub>) to keep computational time reasonable.  ';
        break;

        case 'Chemical Equilibrium Model':
             s += '<span class="td_mainheading"> Chemical Equilibrium (IGE) Model: </span>The initial mixture composition (by mass, volume, or mole) '+
                 'and the products species (just the names) are specified. For '+
                 'a given pressure and temperature the daemon calculates the equilibrium '+
                 'composition and the complete products state including the equilibrium flame temperature by minimizing the Gibbs function.';
        break;
                                       
        case 'Chemical Equilibrium Web Model':
             s += '<span class="td_mainheading"> Enhanced Chemical Equilibrium (IGE) Model: </span>Using the power of web service, the data base used is expanded to more than a '+
                 'thousand species from various sources including NASA and NIST. While the stand-alone '+
                 'daemon has about 200 species, this daemon currently loads more than 1500 species. ';
        break;

        case 'Non-Premixed Reactants':
             s += 'Fuel and oxidizer are separated. Set up the reaction as fuel+oxidizer-->products. '+
                 'In the state panel, evaluate the states of fuel, oxidizer and products. The combustion device '+
                 '(device panel) has two inlets, i1 and i2, one for fuel and one for oxidizer, and one exit (e) for '+
                 'the products. Use this daemon not only for energy or entropy analysis of a combustor, but also for '+
                 'balancing a combustion reaction (for given products analysis, excess or deficient air, fuel analysis, etc.).';
        break;

        case 'Premixed Reactants':
             s += '<span class="td_mainheading">Fuel and Oxidizer are Premixed: </span>Reactants (fuel and oxidizer) are premixed. Set up the reaction as reactants-->products. You may have to '+
                 'manually balance the reaction. The products composition is frozen (dictated by the reaction you set up) during '+
                 'the process analysis. In the state panel, evaluate the states of reactants and products. The combustion process '+
                 'executed by the mixture takes it from a unique b (begin) state to a single f (final) state.';
        break;

        case 'Ideal Gas Mixture Model':
            s += '<span class="td_mainheading">IG Mixture Model: Variable Specific Heats: </span>Reactants and products are treated as mixtures of ideal gases. When a liquid or solid component is present (liquid octane or solid carbon, for instance), '+
                'it is assumed to occupy zero volume (having zero partial pressure).'
        break;

        case 'Perfect Gas Mixture Model':
            s += '<span class="td_mainheading">PG Mixture Model: Constant Specific Heats: </span>Reactants and products are treated as mixtures of perfect gases. Assumption of constant specific heats results in exaggerated prediction of adiabatic flame temperature. ';
        break;

        case 'RIA: Steady Flow Combustion':
             s += '<span class="td_mainheading"> Reactor Simulation by RIA: </span> This RIA  simulates a steady state combustion chamber. You can choose fuel, oxidizer, air-fuel ratio, '+
                 'combustion chamber conditions, and probable species in the combustion products using an animation of the '+
                 'combustion chamber. The RIA will produce the equilibrium composition and heat transfer for a given exit '+
                 'temperature. For a given heat transfer, it will calculate composition and temperature at the exit. A '+
                 'parametric study can be conducted, where the RIA will plot the equilibrium flame temperature (and any '+
                 'species concentration) as the air-fuel ratio is changed over any desired range.';
        break;


        case 'RIA: Device Simulators':
             s += '<span class="td_mainheading"> Device Simulation by RIAs: </span> These rich internet applications (RIAs) can be used to explore parametric behavior of simple open-steady devices. Unlike the daemons, the RIAs do not require a thorough thermodynamic background and can be used to to gain practical insight alongside learning the underlying theory.'+
             '';
        break;
        case 'RIA: Process Simulators':
             s += '<span class="td_mainheading"> Process Simulation by RIAs: </span> These rich internet applications (RIAs) can be used to interactively explore a process where a system goes from a beginning state to a final state under some given constrain (say, the temperature remains constant) Unlike the daemons, the RIAs do not require a thorough thermodynamic background and can be used to to gain practical insight alongside learning the underlying theory.'+
             '';
        break;

        case 'RIA: State Simulators':
             s += '<span class="td_mainheading"> State Simulation by RIAs: </span> These rich internet applications (RIAs) can be used to explore an equilbrium state. Unlike the daemons, the RIAs do not require a thorough thermodynamic background and can be used to to gain practical insight alongside learning the underlying theory.'+
             '';
        break;
        case 'RIA-IG Model':
             s += '<span class="td_mainheading"> Gas Turbine Simulation by RIA: </span> This RIA  simulates gas turbine cycles - ideal Brayton cycle, actual cycle, cycle with reheat, regneration, multi-state '+
                 'cycles. Graphically set the input parameters such as the inlet conditions, compression ratio, device efficiencies, etc., '+
                 'and the RIA calculates the thermal efficiency and other cycle parameters. It can also calculate equilibrium composition at '+
                 'any given state point. Parametric study is quite simple - just select a parameter range and the desired result is plotted '+
                 'against the independent variable.';
        break;

//        case 'RIA: Otto Cycle':
//             s += 'Set the compression ratio using the sliding bar and click Calculate. See how easy it is to explore parametric behavior of an Otto cycle. ';
//        break;
//
//        case 'RIA: Diesel Cycle':
//             s += 'Set the compression ratio using the sliding bar and click Calculate. See how easy it is to explore parametric behavior of a Diesel cycle. ';
//        break;

        case 'RIA: Reciprocating Cycles':
             s += '<span class="td_mainheading">RIAs: Reciprocating Cycles: </span>Set the compression ratio using the sliding bar and click Calculate. See how easy it is to explore parametric behavior of a Diesel or Otto cycle. ';
        break;

        case 'PC/PC Model':
             s += '<span class="td_mainheading">Two Different Phase-Change Fluids: </span>Combined cycles using two different phase-change fluids can be analyzed with this model. Two choices for '+
                 'selecting the working fluid model make it necessary to individually specify the working fluid for each state.';
        break;


        case 'PC/IG Model':
             s += '<span class="td_mainheading">One Phase-Change Fluid and One Ideal Gas: </span>Combined cycles using a phase-change (PC) fluid for one cycle and an ideal gas (IG) for another can be analyzed with '+
                 'this daemon. Two choices for selecting the working fluid make it necessary to individually specify the working fluid for each state. ';
        break;


        case 'PC+PC':
            s += 'The system has two uniform sub-systems consisting of two different phase-change fluids, say, H2O and NH3 (or H2O and H2O), which are '+
                'not allowed to mix. Therefore, we will need four states, - bA, bB, fA and fB-states - to describe the non-uniform beginning and final states.';
        break;

        case 'SL+SL':
            s += 'The system has two uniform sub-systems consisting of two blocks of solids, two liquids (different or identical), or a solid and a liquid, which '+
                'do not exchange any mass at any time. The liquid has no possibility of a phase change allowing the use of the SL model. We will need two states, bA '+
                'and bB, to describe the composite beginning-state and two states, fA and fB, to describe the composite final-state.';
        break;

        case 'IG+IG':
            s += 'The system has two uniform sub-systems consisting of two perfect gases, identical or different (PG Models). While the two sub-systems exchange energy, '+
                'they maintain their individual identities since they do not mix. We will need two states, bA and bB, to describe the composite beginning-state and two '+
                'states, fA and fB, to describe the composite final-state. The property mass fraction, <i class="math">x<sub>A</sub></i>, of gas A is set to 0 or 1 to select gas A or gas B as the '+
                'working fluid. Note that two identical gases can be treated under the same framework (<i class="math">x<sub>A</sub></i> will remain fixed as either 1, for gas A, or 0 for gas B).';
        break;

        case 'PC+SL':
            s += 'The system has two uniform sub-systems consisting of a solid (SL Model) and a phase change (PC Model) fluid. We will need two states, bA and bB, '+
                'to describe the composite beginning-state and two states, fA and fB, to describe the composite final-state.';
        break;

        case 'PC+IG':
            s += 'The system has two uniform sub-systems consisting of a phase-change fluid (PC Model) and an ideal gas (IG Model). While the two sub-systems exchange '+
                'energy, they maintain their individual identities as they do not mix. We will need two states, bA and bB, to describe the composite beginning-state and '+
                'two states, fA and fB, to describe the composite final-state.';
        break;
        
        case 'IG+SL':
            s += 'The system has two uniform sub-systems consisting of a solid or a liquid (SL Model) and an ideal gas (IG Model).  While the two sub-systems exchange energy, '+
                'they maintain their individual identities as they do not mix. We will need two states, bA and bB, to describe the composite beginning-state and two states, fA '+
                'and fB, to describe the composite final-state.';
        break;

        case 'Generic, Non-Uniform, Non-Mixing, Closed Process Daemons':
            s += 'The system has two uniform sub-systems, each with the same working fluid (say, H2O and H2O). While the two sub-systems exchange energy, they maintain their '+
                'individual identities as they do not mix. We will need two states, bA and bB, to describe the composite beginning-state and two states, fA and fB, to describe '+
                'the composite final-state.'
        break;

        case 'RG+RG':
            s += 'Same as above except the gases are modeled with the real gas (RG) model.'
        break;

         case 'PG+PG':
            s += 'Same as above except the gases are modeled with the perfect gas (PG) model.'
        break;


        case 'Two Identical Fluids':
            s += 'The system has two separate flows consisting of two identical fluids, say, H2O and H2O, which can not mix. Two inlet and two exit states - i1, i2, e1 and e2-states - are necessary to describe the non-mixing device. The two fluids can be chemically identical.';
        break;

        case 'Two Different Fluids':
            s += 'The system has two separate flows consisting of two phase-change (PC) fluids, say, H2O and NH3, which can not mix. Two inlet and two exit states - i1, i2, e1 and e2-states - are necessary to describe the non-mixing device. The two fluids can be chemically identical.';
        break;

        case 'Two Different Fluids: SL+SL':
            s += 'Same as above except the solid/liquid (SL) model is used for the two flows.';
        break;

        case 'Two Different Fluids: IG+IG':
            s += 'Same as above except the ideal gas (IG) model is used for the two flows.';
        break;

        case 'Two Different Fluids: PC+SL':
            s += 'One of the fluids is modeled with the phase-change (PC) model and the other with the solid/liquid (SL) model.';
        break;

        case 'Two Different Fluids: IG+SL':
            s += 'One of the fluids is modeled with the  ideal gas (IG) model and the other with the solid/liquid (SL) model.';
        break;

        case 'Two Different Fluids: PC+IG':
            s += 'One of the fluids is modeled with the phase-change (PC) model and the other with the ideal gas (IG) model.';
        break;

        case 'HVAC MA Model':
            s += 'HVAC (heating, vantilation, and air-conditioning) systems undergoing psychrometric processes such as simple cooling, simple heating, humidification, de-humidification, etc.';
        break;

        case 'GD Model':
            s += 'Thermodynamics of high speed fluid flow is handled here. The gas is modeled as a perfect gas (PG model). Isentropic flow through converging/diverging nozzles, normal shock waves, and advanced topics such as oblique shocks, expansion waves, etc., can also be analyzed by this daemon.';
        break;

        default:
           s='xxxx';
        }
        //figure out the links for examples
        var sDots = '';
        for (var i=0; i<asLink[0]; i++) sDots += '../';
        var nPages = asPage.length;
        var sPages = ''; var sP = ''; var sTip = '';
        for(var i=0; i<nPages; i++){
            if(nPages>2 && i<(nPages-2)) {sP = ', ';}
            else if(nPages>2 && i==(nPages-2)) {sP = ', and ';}
            else if(nPages>1 && i==(nPages-2)) {sP = ' and ';}
            else sP = '';
            //sPages = sPages + '<span class="pagelink">' + asPage[i] + '</span>' + sP;''
            sTip = asTip[i];
            if(sTip == ''){
                if(asPage[i].indexOf('Tutorial') != -1) sTip = 'Hands-on instructions';
                if(asPage[i].indexOf('Examples') != -1) sTip = 'Manual and TEST solutions';
                if(asPage[i].indexOf('Problems') != -1) sTip = 'Chapter end problems';
                //sTip = asLink[i+1]; // for debugging.
            }
            sPages = sPages + sGetMainPageLink(sDots + asLink[i+1], asPage[i], sTip)   + sP;


        }
        s += '</p><span style="color:red;">Examples:</span> '+ sEx;
        if(nPages>0) s+=  ' For specific examples, visit ' + sPages + ' pages.';
        s += ' </td>';
      
        document.write(s);
        //var oEl = document.getElementById(sID);
        //oEl.style.width = nWidth;

    return;
}


// blank sTip makes standard 'takes you to this page'
// ncolspan -ve signals stacking icons 0 ends the stack, Name of icon is used as id,
function writeDaemonIconTDs(sTip, nColSpan,sDaemon, sName,sImageURL,sLinkURL,nWidth,nMargin) {
    //alert(sTip);
    if(!nWidth)nWidth = 100;
    if(!nMargin)nMargin = 5;
    var sID = sName; var s;
    if(nColSpan<0){
        nColSpan = -nColSpan;
            s =  '<td align="center"  colspan="' + nColSpan + '" >'+
        '<div  id = "' + sID + '" class = "borderNoLine" onmouseover= \'handleMouseOver("' + sID + '","' + sTip + '","' + sDaemon + '")\' '+
        'onmouseout= \'handleMouseOut("'+sID+'")\' onclick = \'goMainHref("' + sLinkURL +'")\'>'+
        '<img src="' + sImageURL + '" border="0"'+
        'alt="Takes You to ' + sName + ' Page" nosave="" height="30"'+
        'width="50"> <div class="simpleheading">' + sName + '</div></div><br/>';
        document.write(s);

    }
    else if (nColSpan == 0){
            s =   '<div  id = "' + sID + '" class = "borderNoLine" onmouseover= \'handleMouseOver("' + sID + '","' + sTip + '","' + sDaemon + '")\' '+
        'onmouseout= \'handleMouseOut("'+sID+'")\' onclick = \'goMainHref("' + sLinkURL +'")\'>'+
        '<img src="' + sImageURL + '" border="0"'+
        'alt="Takes You to ' + sName + ' Page" nosave="" height="30"'+
        'width="50"> <div class="simpleheading">' + sName + '</div></div> </td>';
        document.write(s);
    }
    else{
        s =  '<td align="center"  colspan="' + nColSpan + '" >'+
        '<div  id = "' + sID + '" class = "borderNoLine" onmouseover= \'handleMouseOver("' + sID + '","' + sTip + '","' + sDaemon + '")\' '+
        'onmouseout= \'handleMouseOut("'+sID+'")\' onclick = \'goMainHref("' + sLinkURL +'")\'>'+
        '<img src="' + sImageURL + '" border="0"'+
        'alt="Takes You to ' + sName + ' Page" nosave="" height="30"'+
        'width="50"> <div class="simpleheading">' + sName + '</div></div> </td>';
        document.write(s);
    }

       var oEl = document.getElementById(sID);
       oEl.style.width = nWidth;
       oEl.style.marginRight = nMargin;
       oEl.style.marginLeft = nMargin;
       //alert('margin:'+nMargin);
    return;
}

// blank td; only colspan is used
function writeBlankDaemonIconTDs(sTip, nColSpan,sDaemon, sName,sImageURL,sLinkURL,nWidth,nMargin) {
    //alert(sTip);
    if(!nWidth)nWidth = 100;
    if(!nMargin)nMargin = 5;
    var sID = sName;
    sName = '';
    var      s =  '<td align="center"  colspan="' + nColSpan + '" >&nbsp; </td>';
    document.write(s);

//       var oEl = document.getElementById(sID);
//       oEl.style.width = nWidth;
//       oEl.style.marginRight = nMargin;
//       oEl.style.marginLeft = nMargin;
       //alert('margin:'+nMargin);
    return;
}
//
////for wide rows with many icons combine the two methods above to create 2 TRs (gas mixture, pure gas, etc,)
//function writeModelDaemonIconTR(sRowName,nColspan,sGenericEx,asLinkName,asLink,asLinkTip,nDot,
//                                sDaemonClass, anColspan,asDaemonName, asImageFile, asImageLink, anIconWidth, asIconTip){
//                                //Generic Uniform daemon, 1, PG Model, ../../pg.gif, perfgas, 100, 'hi'
//
//    //first paragraph with name and example
//    writeModelTDs(sRowName,nColspan,sGenericEx,asLinkName,asLink,asLinkTip);
//    document.write('</tr><tr>');
//    //create all the icons
//    var nDaemonIcons = asDaemonName.length;
//    var sImageLink = ''; var sImageFile=''; var sImageFilePrefix = '';
//    //alert ('ndot = '+nDot +' '+nDaemonIcons);
//    for (var i =0; i< nDot; i++) sImageFilePrefix += '../';
//
//    for (var i =0; i< nDaemonIcons; i++){
//        if(asDaemonName[i] == '')   writeBlankDaemonIconTDs("", anColspan[i]);
//        else{
//            sImageFile = sImageFilePrefix+ 'images/icons/'+asImageFile[i];
//            sImageLink = asImageLink[i] + '/' + asImageLink[i] + '.html';
//            //alert('regular: '+ i +'. image filename= ' + sImageFile + ';  link name='+sImageLink);
//            writeDaemonIconTDs(asIconTip[i], anColspan[i], sDaemonClass,asDaemonName[i],sImageFile,sImageLink,anIconWidth[i]);
//        }
//    }
//
//}
// just the example for ria page: the first member the number of .., asTip is of course tooltip.
function writeModelExample(sID, nColSpan,sEx, asPage, asLink, asTip) { //args: id, colspan, spec.example, pages to visit
    if(!asLink)asLink = [0,'','','','','','','','',''];
    if(!asTip)asTip = ['','','','','','','','','',''];
    var s = '';

        //figure out the links for examples
        var sDots = '';
        for (var i=0; i<asLink[0]; i++) sDots += '../';
        var nPages = asPage.length;
        var sPages = ''; var sP = ''; var sTip = '';
        for(var i=0; i<nPages; i++){
            if(nPages>2 && i<(nPages-2)) {sP = ', ';}
            else if(nPages>2 && i==(nPages-2)) {sP = ', and ';}
            else if(nPages>1 && i==(nPages-2)) {sP = ' and ';}
            else sP = '';
            //sPages = sPages + '<span class="pagelink">' + asPage[i] + '</span>' + sP;''
            sTip = asTip[i];
            if(sTip == ''){
                if(asPage[i].indexOf('Tutorial') != -1) sTip = 'Hands-on instructions';
                if(asPage[i].indexOf('Examples') != -1) sTip = 'Manual and TEST solutions';
                if(asPage[i].indexOf('Problems') != -1) sTip = 'Chapter end problems';
                //sTip = asLink[i+1]; // for debugging.
            }
            sPages = sPages + sGetMainPageLink(sDots + asLink[i+1], asPage[i], sTip)   + sP;


        }
        s += '</p><span style="color:red;">Examples:</span> '+ sEx;
        if(nPages>0) s+=  ' For specific examples, visit ' + sPages + ' pages.';
        //s += ' </td>';

        document.write(s);

    return;
}

// called from every choice table, the page icon cells are created here..
function writeIconTDs(sTip, nColSpan, sName,sImageURL,sLinkURL,nWidth,nMargin) {
    //alert(sTip);
    if(!nWidth)nWidth = 100;
    if(!nMargin)nMargin = 5;
    var sID = sName;
    var sDaemon = "";
    var s =  '<td   colspan="' + nColSpan + '" align="center">'+
        '<div id = "' + sID + '" class = "borderNoLine" onmouseover= \'handleMouseOver("' + sID + '","' + sTip + '","' + sDaemon + '")\' '+
        'onmouseout= \'handleMouseOut("'+sID+'")\' onclick = \'goMainHref("' + sLinkURL +'")\'>'+
        '<img src="' + sImageURL + '" border="0"'+
        'alt="Takes You to ' + sName + ' Page" nosave="" height="30"'+
        'width="50"> <div class="simpleheadingblue" >' + sName + '</div></div> </td>';
    document.write(s);
       var oEl = document.getElementById(sID);
       oEl.style.width = nWidth;
    return;
}
//Name of the daemon page
function writeHeader(part1,part2) {
    document.write('<center><span class=part1header>'+part1+" "+
        '</span><span class=part2header>'+part2+'</center>');
}

//draw the blue table header
function writeTableHeader(sTitle, sBackground){
    var s = '<center>';
    s += '<table width="95%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ECE9D8" class="td"><tbody>';
    s += '<tr>';
    s += '<td width="10"><img src="../../../Test/images/headleftcornerT.jpg" alt="" width="10" height="27" border="0" nosave=""></td>';
    s += '<td align="left" nowrap="nowrap" width="100%" bgcolor="#55aaaa"><span class="tableheading"> Click on an icon or the \'next\' button to start. </span></td>';
    s += '<td width="10"><img src="../../../Test/images/headrightcornerT.jpg" alt="" nosave="" border="0"></td>';
    s += '</tr></tbody></table> </center>';
    document.write(s);
}
//hierarchical address images in every page
function writeImageLinks(linkArray) {
    var imgLevel=linkArray[0];
    var i=1;
    //alert(linkArray[i] +' '+linkArray[i+1]);
    writeImageLinkHome(imgLevel, imgLevel+i, linkArray[i]); //special
    while(i<imgLevel){
        writeImageLink(imgLevel, imgLevel-i, linkArray[i+1]);
        i=i+1;
    }
    writeImageLinkEnd(imgLevel, imgLevel-i, linkArray[i+1]); //special
}
	

//homepage link
function writeImageLinkHome(imgLevel, hrefLevel, localFile) {
    // fixed address first
    //alert('imagelinkhomexx');
    var targetString="";
    if(localFile=="index") targetString=' target="_top" ';
    if(localFile=="index") targetString='top';
    var i = 0;   var imgDotStr="";
    while (i < imgLevel) { 
        imgDotStr=imgDotStr +"../"; i=i+1;
    }
    i = 0;  var hrefDotStr="";
    while (i < hrefLevel) { 
        hrefDotStr=hrefDotStr +"../"; i=i+1;
    }

    if(localFile=="index") hrefDotStr=hrefDotStr +"../";
    var homeDotStr=imgDotStr+"../";
    var hrefA=hrefDotStr+localFile+".html";
    var imgAoff=imgDotStr+"images/icons/"+localFile+".jpg";
    var imgAon=imgDotStr+"images/icons/"+localFile+"On.jpg";
    var imageName=localFile; //imageName=localFile;
    //document.write('<td align="center"   bgcolor="008fff"><a  style = "cursor:pointer;" onclick = \'goHrefLocal("' + targetString + '","' + hrefA + '")\' ><img id="imgLevel0"  onmouseover  = \'handleMouseOverAddress("imgLevel0")\' onmouseout  = \'handleMouseOutAddress("imgLevel0")\'  width=100 height=30 src='+imgAoff+' border="1" alt="Takes you to home page."  align=center></a></td>');
    document.write('<td align="center"   bgcolor="008fff"><a  style = "cursor:pointer;" onclick = \'goHrefLocal("' + targetString + '","' + hrefA + '")\' ><img id="imgLevel0"  onmouseover  = \'handleMouseOverAddress("imgLevel0")\' onmouseout  = \'handleMouseOutAddress("imgLevel0")\'  width=100 height=30 src='+imgAoff+' border="1" alt="Takes you to home page."  align=center></a></td>');
}




//Write actual clickable address.
function writeImageLink(imgLevel, hrefLevel, localFile) {
    // fixed address first
    var sID = 'imgLevel'+hrefLevel;
    var targetString="";
    if(localFile=="index") targetString=' target=\"_top\" ';
    var i = 0;   var imgDotStr="";
    while (i < imgLevel) { 
        imgDotStr=imgDotStr +"../"; i=i+1;
    }
    i = 0;  var hrefDotStr="";
    while (i < hrefLevel) { 
        hrefDotStr=hrefDotStr +"../"; i=i+1;
    }

    var homeDotStr=imgDotStr+"../";
    var hrefA=hrefDotStr+localFile+".html";
    var imgAoff=imgDotStr+"images/icons/"+localFile+".jpg";
    var imgAon=imgDotStr+"images/icons/"+localFile+"On.jpg";
    var imageName=localFile; //imageName=localFile;
    //document.write('<td align=center  bgcolor=008fff><a  style = "cursor:pointer;" onclick = \'goHrefLocal("' + targetString + '","' + hrefA + '")\' ><img NOSAVE width=50 height=30 src='+imgAoff+' border=1 alt="Hierarchical clickable ancestor of this page."  align=center></a></td>');
    //document.write('<td align=center  bgcolor=008fff><a  style = "cursor:pointer;" onclick = \'goHrefLocal("' + targetString + '","' + hrefA + '")\' ><img NOSAVE width=50 height=30 src='+imgAoff+' border=1 alt="Hierarchical clickable ancestor of this page."  align=center></a></td>');
    document.write('<td align="center"   bgcolor="008fff"><a  style = "cursor:pointer;" onclick = \'goHrefLocal("' + targetString + '","' + hrefA + '")\' ><img id="'+ sID +'" onmouseover  = \'handleMouseOverAddress("'+ sID +'","'+ hrefLevel +'")\' onmouseout  = \'handleMouseOutAddress("'+ sID +'")\'  width=50 height=30 src='+imgAoff+' border="1" alt="Takes you to parent page."  align=center></a></td>');

}

function writeImageLinkEnd(imgLevel, hrefLevel, localFile) {
    //writeImageLink(imgLevel, hrefLevel, localFile);
    var i = 0;   var imgDotStr="";
    while (i < imgLevel) { 
        imgDotStr=imgDotStr +"../"; i=i+1;
    }
    var imgAoff=imgDotStr+"images/icons/"+localFile+".jpg";
    //document.write('<td align=center  bgcolor=008fff><img NOSAVE width=50 height=30 src='+imgAoff+' border=1 alt="Hierarchical address of this page."  align=center></td>');
    document.write('<td align="center"   bgcolor="008fff"><img id="imgLevelEnd"  onmouseover  = \'handleMouseOverAddress("imgLevelEnd")\' onmouseout  = \'handleMouseOutAddress("imgLevelEnd")\'  width=50 height=30 src='+imgAoff+' border="1"   align=center></td>');
    document.write('</tr></table>');
}

function goHrefLocal(targetString, sPageURL){
//function goHrefLocal(sPageURL){
    //alert('hi'+sPageURL);
    if(targetString=="")  oTop.main.location = sPageURL;
    else  oTop.location = sPageURL;
}
//Address bar: Home.Daemons...etc., start a table; specially treat map, daemos and rias.
function writeAddressPartA(labArray) {
    //write fixed part
    document.write('<center><table border=0 cellspacing=0 cellpadding=0 >'+
        '<tr><td align="right" bgcolor="008fff"  class="addressHeading addressStyle">&nbsp;thermofluids.net&nbsp;>&nbsp;</td>');

//    document.write('<table border=0 cellspacing=0 cellpadding=0 >'+
//        '<tr><td align=center bgcolor=008fff  class="addressHeading addressStyle">&nbsp;thermofluids.net&nbsp;>&nbsp;</td>'+
//        '<td align=center bgcolor=008fff  class="addressHeading addressStyle">Daemons&nbsp;&nbsp;</td>');

    if(labArray[0] == "Daemons"){
        document.write('<td align=center bgcolor=008fff  class="addressHeading addressStyle">Daemons&nbsp;&nbsp;</td>');

    }
    else if(labArray[0] == "RIAs"){
        document.write('<td align=center bgcolor=008fff  class="addressHeading addressStyle">RIAs&nbsp;&nbsp;</td>');
    }
    else if(labArray[0] == "Map"){
        document.write('<td align=center bgcolor=008fff  class="addressHeading addressStyle">Map&nbsp;&nbsp;</td>');
    }
    else{
        document.write('<td align=center bgcolor=008fff  class="addressHeading addressStyle">Daemons&nbsp;&nbsp;</td>');
        var n=labArray.length;
        var i = 0;
        while (i < n) {
            document.write('<td align=center bgcolor=008fff  class="addressHeading addressStyle">');
            document.write("&nbsp;>&nbsp;"+labArray[i]);
            document.write('&nbsp;</td>');
            i=i+1;
        }
    }

    document.write('</tr><tr>');
}

//Write actual clickable address.
function writeAddressPartB(addressArray) {
    // fixed address first
    var imgLevel=addressArray[0];
    var i = 0;  imgDotStr="";
    while (i < imgLevel) { 
        imgDotStr=imgDotStr +"../"; i=i+1;
    }

    homeDotStr=imgDotStr+"../";
    //hrefA="../../../../../"+"index.html";
    hrefA=homeDotStr+"index.html";
    imgAoff=imgDotStr+"images/icons/home.jpg";
    imgAon=imgDotStr+"images/icons/homeOn.jpg";
    document.write('<tr><td align=center><a onmouseover=\'switchImage("A",imgAon)\' onmouseout=\'switchImage("A",imgAoff); return true;\'  href='+
        hrefA+' target="_top"><img NOSAVE width=50 height=30 src='+imgAoff+' name="A" border=1 alt="Takes You to TEST Home Page"  align=center></a></td>');

    i=1;
    hrefLevel=imgLevel-i;
    var j=0; var hrefDotStr="";
    while (j < hrefLevel) {
        hrefDotStr=hrefDotStr +"../"; j=j+1;
    }
    hrefi=hrefDotStr+"solve.html";
    imgAoff=imgDotStr+"images/icons/daemon.gif";
    imgAon=imgDotStr+"images/icons/home.jpg";
    document.write('<td align=center><a onmouseover=\'switchImage("B",imgAon)\' onmouseout=\'switchImage("B",imgAoff); return true;\'  href='+
        hrefi+' target="main"><img NOSAVE width=50 height=30 src='+imgAoff+' name="B" border=1 alt="Takes You to this page"  align=center></a></td>');

    //' <td align=center><a href="../../../solve.html"><img NOSAVE width=50 height=30 '+
    //' src="../../../../images/icons/daemon.gif" alt="Takes You to TEST.Daemons Page" align=center ></a></td>'+

    document.write('<td align=center><a href="../../states.html"><img  NOSAVE width=50 height=30 '+
        'src="../../../../images/icons/states.gif" alt="Takes You to TEST.Daemons.States Page"   align=center></a></td>'+
        '<td align=center><a href="../volume.html"><img  NOSAVE width=50 height=30 '+
        'src="../../../../images/icons/volume.gif" alt="Takes You to TEST.Daemons.States Page" align=center></a></td>'+
        '<td align=center><img NOSAVE  width=50 height=30 src="../../../../images/icons/pg.gif" alt="You are here!"></a></td>'+
        '</tr></table></center>');
}

// write h. address for animation chapters
function writeAddressAnimChapter(sChNo){ 
    var sChName = 'Chapter '+sChNo;
    var i = sChNo-0;
    if (i<10) sChNo = '0'+sChNo;
    var sChImgName = 'ch'+sChNo+'.jpg';
    var s = '<center>';
    s += '<table border="0" cellspacing="0" cellpadding="0" bgcolor="#bbbbff">';
    s += '<tbody><tr>';
    s += '<td bgcolor="#008fff" class="addressHeading addressStyle">&nbsp;thermofluids.net</td>';
    s += '<td bgcolor="#008fff" align=center class="addressHeading addressStyle">&nbsp;>&nbsp;Animations</td>';
    s += '<td bgcolor="#008fff" align=center class="addressHeading addressStyle">&nbsp;>&nbsp;'+sChName+'&nbsp;</td>';
    s += '</tr><tr>';
    s += '<td align="center"><a href="../../../index.html" target="_top"><img src="../../../Test/images/icons/index.jpg" alt="Takes you to TEST home page" nosave="" height="30" width="100" align="Center" border=1></a></td>';
    s += '<td align="center"><a href="../../index.html" target="main"><img  src="../../../Test/images/icons/animation.jpg" alt="Takes you to animations table of content" nosave="" height="30" width="50" align="center" border=1></td>';
    s += '<td align="center"><img border="0" src="../../../Test/images/icons/'+sChImgName+'" alt="Icon for the current page, not a link." nosave="" height="30" width="50" align="Center" border=1></td>';
    s += '</tr></tbody></table> </center>';
    document.write(s);

}


// write h. address for visual tour chapters
function writeAddressClipChapter(sChNo){ 
    var sChName = 'Chapter '+sChNo;
    var i = sChNo-0;
    if (i<10) sChNo = '0'+sChNo;
    var sChImgName = 'ch'+sChNo+'.jpg';
    var s = '<center>';
    s += '<table border="0" cellspacing="0" cellpadding="0" bgcolor="#bbbbff">';
    s += '<tbody><tr>';
    s += '<td bgcolor="#008fff" class="addressHeading addressStyle">&nbsp;thermofluids.net</td>';
    s += '<td bgcolor="#008fff" align=center class="addressHeading addressStyle">&nbsp;>&nbsp;Visual Tour</td>';
    s += '<td bgcolor="#008fff" align=center class="addressHeading addressStyle">&nbsp;>&nbsp;'+sChName+'&nbsp;</td>';
    s += '</tr><tr>';
    s += '<td align="center"><a href="../../../index.html" target="_top"><img src="../../../Test/images/icons/index.jpg" alt="Takes you to TEST home page" nosave="" height="30" width="100" align="Center" border=1></a></td>';
    s += '<td align="center"><a href="../../index.html" target="main"><img  src="../../../Test/images/icons/clip.jpg" alt="Takes you to animations table of content" nosave="" height="30" width="50" align="center" border=1></td>';
    s += '<td align="center"><img border="0" src="../../../Test/images/icons/'+sChImgName+'" alt="Icon for the current page, not a link." nosave="" height="30" width="50" align="Center" border=1></td>';
    s += '</tr></tbody></table> </center>';
    document.write(s);

}
// replace parent.frames[i] with a href page (used by combustion pages for example)
function replaceFrameWith(i,sPage){
    var index = i-0;
    if(actualMedia=="LOCAL"){
        alert("This daemon uses Web Service, which is only available online. Switch to www.thermofluids.net and try again.");
        return;
    }
    parent.frames[index].location.replace(sPage);
}

//write a dynamic nice link as suggested by Robi
//sTip can be '' or 'daemons' or absent
function writeMainPageLink(sLink, sName, sTip){
    if(!sTip || sTip == '') sTip = 'Takes you to this page directly';
    if(sTip == 'daemons') sTip = 'Click to launch the daemon'
    document.write('<span class="linkStyle" onmouseout = \'UnTip()\' onmouseover = \'goTip("' + sTip + '")\'  onclick = \'handleOnclickLink("' + sLink + '")\'>' + sName + '</span>');
    //alert(sLink);
}

//href for the main page. requires index files. tutorial, examples, and problems all  have a menu and ch/Body frames.
function sGetMainPageLink(sLink, sName, sTip){
    if(!sTip || sTip == '') sTip = 'Takes you to this page directly';
    if(sTip == 'daemons') sTip = 'Click to launch the daemon'
    //return '<span class="linkStyle" onmouseout = \'UnTip()\' onmouseover = \'goTip("' + sTip + '")\'  onclick = \'handleOnclickLink("' + sLink + '")\'>' + sName + '</span>';
    return '<span class="linkStyle" onmouseout = \'UnTip()\' onmouseover = \'goTip("' + sTip + '")\'  onclick = \'handleOnclickLink("' + sLink + '")\'>' + sName + '</span>';
}

//main page consists of a menubar and chBody frames.
function handleOnclickLink(sLink){
    //alert(sLink);
    parent.main.location = sLink;
}
