<!--

//
// Display rolling stock image and details
//
//    function SetDetails(inKey, inValue)	Set text values prior to display
//    function DisplayDetails(inString)		Display all details passed and rolling stock image
//    function GetParmString(inString, inKey)	Internal use, to extract and store details passed.
//
//	Key details supported are;	"Img"		Set to "N" if no image is avaialble
//    					"Scale"		"009", "HOn30", "O9" or "1n20"
//					"Stock"		"Locomotive", "railcar"[=railbus], "Goods", "Passenger"  *** NEW - NOT YET CODED ***
//					"Num"		Rolling stock item number
//					"Descr"		Free text
//					"Type"		Use "kit", "scratchbuilt", "conversion" or similar text, i.e. "009 kit conversion"
//					"Man"		Manafacturer name or "n/a"
//					"ManID"		Manafacturer ID for this kit or "n/a"
//					"Text"		"Not yet started" or free text
//					"ToDo"		Free text
//					"ImgUpd"
//					"Oper"
//
//
var ParmImg    = "";
var ParmFrom   = "";
var ParmScale  = "";
var ParmStock  = "";
var ParmNum    = "";
var ParmDescr  = "";
var ParmType   = "";
var ParmMan    = "";
var ParmManID  = "";
var ParmText   = "";
var ParmToDo   = "";
var ParmImgUpd = "";
var ParmOper   = "";


//
//  Display details for one model from passed key/value string
//
function DisplayDetails(inString)
   {var ThisNum;
    var ThisCat;
    var ThisImgName;
    var ThisManAndID;
    var ThisAlt;
    var ThisIdentifier;
    var ThisStock;
    var ThisDescription;
    var BGColLeft, BGColRight, BGColTable;
    var Blank12 = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    var ErrorMessage = "";


    //  Validate From parameter string
    if (ParmFrom.length == 0)
    {
        ErrorMessage = "Expected parameter 'From' not found";
    }

    //  Validate Scale parameter string
    if (ParmScale.length == 0)
    {
        ErrorMessage = "Expected parameter 'Scale' not found";
    }
    else
    {
        if      (ParmScale == "009")   {ThisIdentifier = "a";}
        else if (ParmScale == "HOn30") {ThisIdentifier = "l";}
        else if (ParmScale == "O9")    {ThisIdentifier = "f";}
        else if (ParmScale == "1n20")  {ThisIdentifier = "1";}
        else                           {ErrorMessage = "SetDetails('Scale', '" + ParmScale + "')"; ParmScale = "009"; ThisIdentifier = "a";}
    }


    //  Validate stock parameter string
    if (ParmStock.length == 0)
    {
        ErrorMessage = "Expected parameter 'Stock' not found";
    }
    else
    {
        if      (ParmStock == "locomotive") {ThisStock = "m"; ThisDescription = "Locomotive";}
        else if (ParmStock == "railcar")    {ThisStock = "m"; ThisDescription = "Railcar/Railbus"; ParmStock = "motive";}
        else if (ParmStock == "goods")      {ThisStock = "g"; ThisDescription = "Goods~wagon";}
        else if (ParmStock == "passenger")  {ThisStock = "g"; ThisDescription = "Passenger~coach";}
        else                                {ErrorMessage = "SetDetails('Stock', '" + ParmStock + "')"; ParmStock = "goods"; ThisStock = "x"; ThisDescription = "goods wagon";}
        if ((ParmScale == "HOn30" || ParmScale == "1n20") && ThisDescription == "Goods~wagon") {ThisDescription = "Freight~car";}
    }


    //  Build required text strings from passed parameters
    ThisNum = ParmNum;
    if (ThisNum.length==1) {ThisNum = "0" + ThisNum;}
    if (ThisStock == "m") {ThisCat=ParmScale + "-L" + ThisNum;} else {ThisCat=ParmScale + "-0" + ThisNum;}
    ThisImgName = "k" + ThisIdentifier + ThisStock + ThisNum + "xxm.jpg";
    ThisManAndID = ParmMan + ", " + ParmManID;
    ThisAlt = ThisCat + "&nbsp;&nbsp;" + ParmDescr;
    if (!(ParmImgUpd == "")) {ThisAlt = ThisAlt + ". Image updated " + ParmImgUpd;}

    //  Determine display style variations from passed parameters
    if (ParmImg == "N") {ThisImgName = "kagxxxxm.gif";}

    if (ParmText != "Not yet started")
    {
        BGColTable = " BGCOLOR='#FFFFFF'";
        BGColLeft  = " BGCOLOR='#CCCCCC'";
        BGColRight = " BGCOLOR='#D7D7D7'";
    }
    else
    {
        BGColTable = " BGCOLOR='#DDDDDD'";
        BGColLeft  = " BGCOLOR='#EEFFBB'";
        BGColRight = " BGCOLOR='#EEFFBB'";
    }
    if (ParmOper == "Y")
    {
        ImgBorder = " BGCOLOR='#FF0066'";
    }
    else
    {
        ImgBorder = "";
    }

    //  If any parameters not valid then display error message
    if (ErrorMessage.length > 0)
    {
        document.write("<BR><FONT COLOR='red'><B>Invalid call: </B>" + ErrorMessage + "</FONT><BR>");
    }

    //  Start writing html code for table
    document.write("<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2 WIDTH='95%'><TR><TD WIDTH=200 ROWSPAN=5 VALIGN='top'>");

    //  Output image
    document.write("<TABLE BORDER=0 CELLPADDING=2><TR><TD VALIGN='top' " + ImgBorder + ">");
    document.write("<A HREF='jpage993.html?from=" + ParmFrom + ",layout=" + ParmScale + ",type=" + ParmStock + ",imgno=" + ThisNum + ",text=" + ThisDescription + "~" + ThisCat + "'>");
    document.write("<IMG SRC='http://i22.photobucket.com/albums/b343/mbox4uk/" + ThisImgName + "' BORDER=1 WIDTH=200 HEIGHT=133 VSPACE=0 HSPACE=0 ALIGN='left' ALT='" + ThisAlt + "'>");
    document.write("</A>");
    document.write("</TD></TR></TABLE>");
    document.write("</TD>");

    //  Output rolling stock number
    document.write("<TD WIDTH=100 " + BGColLeft + ">Number" + Blank12 + "</TD><TD" + BGColRight + "><B>" + ThisCat + "</B> " + ParmDescr + "</TD></TR>");

    //  Output construction type and, if required, manafacturer details
    document.write("<TR><TD" + BGColLeft + ">Type</TD><TD" + BGColRight + ">" + ParmType);
    if (ParmMan != "n/a")
    {
        document.write("&nbsp;&nbsp;&nbsp;&nbsp;<FONT SIZE='-1'>(" + ThisManAndID + ")</FONT>");
    }
    document.write("</TD></TR>");

    //  Output remaining fields
    document.write("<TR><TD VALIGN='top'" + BGColLeft + ">Description</TD><TD" + BGColRight + ">" + ParmText + "</TD></TR>");
    document.write("<TR><TD VALIGN='top'" + BGColLeft + ">To Do</TD><TD" + BGColRight + ">" + ParmToDo + "</TD></TR>");
    document.write("</TABLE>");

    //  Clear all parameters prior to next call
    ParmImg    = "";
    ParmFrom   = "";
    ParmScale  = "";
    ParmStock  = "";
    ParmNum    = "";
    ParmDescr  = "";
    ParmType   = "";
    ParmMan    = "";
    ParmManID  = "";
    ParmText   = "";
    ParmToDo   = "";
    ParmImgUpd = "";
    ParmOper   = "";
   }



//
//  Set details before display
//
function SetDetails(inKey, inValue)
   {
    if      (inKey == "Img")    {ParmImg    = inValue;}
    else if (inKey == "From")   {ParmFrom   = inValue;}
    else if (inKey == "Scale")  {ParmScale  = inValue;}
    else if (inKey == "Stock")  {ParmStock  = inValue;}
    else if (inKey == "Num")    {ParmNum    = inValue;}
    else if (inKey == "Descr")  {ParmDescr  = inValue;}
    else if (inKey == "Type")   {ParmType   = inValue;}
    else if (inKey == "Man")    {ParmMan    = inValue;}
    else if (inKey == "ManID")  {ParmManID  = inValue;}
    else if (inKey == "Text")   {ParmText   = inValue;}
    else if (inKey == "ToDo")   {ParmToDo   = inValue;}
    else if (inKey == "ImgUpd") {ParmImgUpd = inValue;}
    else if (inKey == "Oper")   {ParmOper   = inValue;}
    else                        {document.write("<BR><FONT COLOR='red'><B>Unexpected parameter value(s): </B> SetDetails(" + inKey + ", " + inValue + ")</FONT><BR>");}
   }



//
//  Get parameter value by keyword from a key/value string, returned as text
//
function GetParmString(inString, inKey)
   {
    //  Get passed parameter
    ParmFull = inString + "|";
    ParmLength = ParmFull.length;

    //  Search parameter for requested keyword
    Return   = "****";
    ThisKey  = "";
    ThisParm = "";
    FlagKey  = 1;
    Index    = 0;

    while (Index < ParmLength)
       {Char = ParmFull.substr(Index,1);
        if     (Char == "|")   {if (ThisKey == inKey)
                                  {Return = ThisParm;
                                   Index = ParmLength;
                                  }
                                else
                                  {ThisKey  = "";
                                   ThisParm = "";
                                   FlagKey  = 1;
                                  }
                               }
        else if (Char == "=")  {FlagKey = 0;}
        else if (FlagKey == 1) {ThisKey += Char;}
        else                   {ThisParm += Char;}
        Index++;
       }

    return(Return);
   }
-->
