// Centrifuge 2.4 Template
//Applet Implementation Specific Functions

bEngineLoaded = false;
oEngineRef = null;
jsRetVal="";
dStartTime = new Date();

//BEG UPGRADE ISSUE CUSTOM FOR BULLARD...
//See other sections below
bDirty = false;
//END UPGRADE ISSUE CUSTOM FOR BULLARD...

aFirstRunURLStack = new Array();
aFirstRunFlags = new Array();
function CheckFirstRun(sPath, bSet){
     bFirstRun = false;
     bGotIt = false;
     sPath = GetCurrentStateID() + sPath;

     //Check the Stack for this URL...
     len = aFirstRunURLStack.length;
     for(i=0; i<len; i++){
         if (aFirstRunURLStack[i] == sPath){
             bGotIt = true;
             break;
         }
     }

     //If doesn't exist then bFirstRun = true and add both to end of stack.
     if (!bGotIt){
         bFirstRun = true;
         if( bSet ) {
             aFirstRunURLStack[aFirstRunURLStack.length] = sPath;
             aFirstRunFlags[aFirstRunFlags.length] = false;
         }
     }else{//set bFirstRun to value of the corresponding flag.
         bFirstRun = aFirstRunFlags[i];
         if (bSet){
             aFirstRunFlags[i] = false;
         }
     }

     return bFirstRun;
}

function refresh(frames)
{
    for( var i=0; i<frames.length; i++ )
    {
        if( frames[i].frames.length > 0 )
            refresh(frames[i].frames);
        else
        {
            if( frames[i].oEngineLocation )
                frames[i].location.reload();
        }
    }
}

function ReloadContent(){
	bEngineLoaded = true;
    refresh(top.frames);
}

function SetEngineRef(){
    oEngineRef = document.EngineApplet.engine;
}

function Finish(){
    //alert(document.EngineApplet);
    if( !document.EngineApplet || !document.EngineApplet.bStartComplete )
    {
        setTimeout("Finish()", 100);
        return;
    }
	SetEngineRef();
	oEngineRef.FinishInitForApplet();
	ReloadContent();
}

function setDebugText(sTo){
	document.testform.debugtext.value = sTo;
}

var aStateIDStack = new Array();
var aURLStack = new Array();
var aFrameStack = new Array();

function SwitchModel(sSwitchID, sURL, oFrameLoc){
    sSelfLocation = oFrameLoc.sSelfLocation;
	sNewStateID = "" + LookupSwitch(sSwitchID);
	if (sNewStateID != ""){
        addDynamicProperty("CurrentSwitchID", sSwitchID);
    	SetActiveModel(sNewStateID, false);
    	//Get the last page for this StateID
//alert("sURL=" + sURL);
    	if (sURL == ""){
		    if (aStateIDStack.length > 1){
		        iPosition = -1;
		        bGotPosition = false;
		        for (i=aStateIDStack.length-1; i >= 0; i--){
		            if (aStateIDStack[i]==sNewStateID && aFrameStack[i]==sSelfLocation){
	                    iPosition = i;
	                    bGotPosition = true;
	                    break;
		            }
		        }
		        if (bGotPosition){
		            SetActiveModel(sNewStateID, false);
		            sURL = aURLStack[iPosition];
//alert("sURL=" + sURL);
		        }
		    }
    	}
        if( oFrameLoc != null ){
	        oFrameLoc.location.replace(sURL);
	    }
	}
    return false;  // workaround for IE5.0
}

function RegisterPage(oSelfLocation, sSelfURL){
//alert("sSelfURL=" + sSelfURL);
    for (i=aFrameStack.length-1; i >= 0; i--){
        if (aFrameStack[i]==oSelfLocation){
//alert("=");
            if (aStateIDStack[i] == oEngineRef.GetCurrentStateID()
            && aURLStack[i] == sSelfURL){
                return;
            }else{
                break;
            }
        }
    }

    aStateIDStack[aStateIDStack.length] = "" + oEngineRef.GetCurrentStateID();
//alert(aStateIDStack[aStateIDStack.length-1]);
    aURLStack[aURLStack.length] = sSelfURL;
//alert(aURLStack[aURLStack.length-1]);
    aFrameStack[aFrameStack.length] = oSelfLocation.sSelfLocation;
//alert(aFrameStack[aFrameStack.length-1]);
}

function GoBack(oSelfLocation){
    if (aStateIDStack.length > 1){
//alert(GetCurrentStateID());
        iPosition = -1;
        bGotPosition = false;
        for (i=aFrameStack.length-1; i >= 0; i--){
            if (aFrameStack[i]==oSelfLocation){
                if (iPosition > -1){
                    iPosition = i;
                    bGotPosition = true;
                    break;
                }else{
                    iPosition = i;
                }
            }
        }
        if (bGotPosition){
            sStateID = aStateIDStack[iPosition];
//alert(sStateID);
            SetActiveModel(sStateID, false);
//alert(GetCurrentStateID());
//alert(aFrameStack[iPosition]);
//alert(aURLStack[iPosition]);
//alert(aFrameStack.length);
            oSelfLocation.location.replace(aURLStack[iPosition]);
            if (iPosition == 0){
                iPosition = 1;
            }
            aStateIDStack.length = iPosition - 1;
            aFrameStack.length = iPosition - 1;
            aURLStack.length = iPosition - 1;
        }
    }
}

// function GetActiveLayer(sSelfURL){
//     sActive = '';
//     for (i=0; i<aURLs.length; i++){
//         //alert("aURLs[" + i + "]=" + aURLs[i]);
//         //alert("sSelfURL=" + sSelfURL);
//         if (aURLs[i] == sSelfURL){
//             //alert("EQUAL");
//             sActive = aLayers[i];
//             //alert("sActive=" + sActive);
//             break;
//         }
//     }
//     //alert("sActive=" + sActive);
//     return sActive;
// }

aURLs = new Array();
//aLayers = new Array();
function HandleSubmit(oSourceFrame, sSourceControl){
    dStartTime = new Date();
    oSourceFrame.status = 'Working ...';
	oEngineRef.HandleSubmit(sSourceControl);
	if (GetDeferLevel(sSourceControl) < 5){
    	aTargetFrames = new Array(oSourceFrame.aRefreshFrames.length);
    	for (i=0; i<aTargetFrames.length; i++){
    	    aTargetFrames[i] = oSourceFrame.aRefreshFrames[i];
        }
        bGotIt = false;
    	for(i=0; i<aTargetFrames.length; i++){
            oCurrTarget = aTargetFrames[i];
            sURL = oCurrTarget.sSelfURL;
            //alert("sURL=" + sURL);
//            sLayer = oCurrTarget.sActiveLayer;
            //alert("sLayer=" + sLayer);
            for (i=0; i<aURLs.length; i++){
                //alert("aURLs[" + i + "]=" + aURLs[i]);
                //alert("sSelfURL=" + sURL);
                if (aURLs[i] == sURL){
                    //alert("EQUAL");
                    bGotIt = true;
                    //alert("sActive=" + sActive);
                    break;
                }
            }
            //alert("sActive=" + sActive);
            if(bGotIt){
                aURLs[i] = sURL;
//                aLayers[i] = sLayer;
            }else{
                aURLs[aURLs.length] = sURL;
//                aLayers[aLayers.length] = sLayer;
            }
//             oSourceFrame.status = '';
            oEngineRef.ClearControls(oCurrTarget.sSelfLocation);
    	    oCurrTarget.document.location.reload();
    	}
        oEngineRef.ClearControls(oSourceFrame.sSelfLocation);
        oSourceFrame.document.location.reload();
  	}
    oSourceFrame.status = '';
}

function GetPageControlValuesJS(sControlID){
	sRetVal = '';
//alert("sControlID.type=" + sControlID.type);
    if (sControlID.type == 'text' || sControlID.type == 'textarea'){
		sRetVal = sControlID.value;
	}else{
//alert("sControlID.length=" + sControlID.length);
    	if (sControlID[1]){
        	for (j=0; j<sControlID.length; j++){
//alert("sControlID.options=" + sControlID.options);
        	    if (sControlID.options){
        			if (sControlID.options[j].selected){
        				if (sRetVal != ''){
        					sRetVal += '|';
        				}
        				sRetVal += sControlID.options[j].value;
        			}
        		}else{
        			if (sControlID[j].checked){
        				if (sRetVal != ''){
        					sRetVal += '|';
        				}
        				sRetVal += sControlID[j].value;
        			}
        		}
        	}
        }else{
			if (sControlID.checked){
				sRetVal = sControlID.value;
			}
    	}
	}
//alert("sRetVal=" + sRetVal);
	jsRetVal = sRetVal;
    return sRetVal;
}

function getXML(){
    return toXML();
}

function getINI(){
    return toINI();
}

function GetCurrentSwitchID(){
    return getDynamicProperty("CurrentSwitchID");
}

function getDocumentBase(){
    return document.EngineApplet.getDocumentBase();
}

function CreateConflictAdvice(attrName)
{
    //if( isInConflict(attrName) )
    if( hasConflictAdvice(attrName) )
    {
        // here, output the conflict icon
        return '<img src="Conflict.gif" height="15" width="15" />';
    }
    return "";
}

function CreateDropDown(attrName, propName, size, showPendingText, pendingText,
                        showBad, showGood, deferred, indexes, showPlusMinus)
{
    if( showPlusMinus == null ) showPlusMinus = true;
    html = "";
    groupNum = GetGroupNumFromAttrName(attrName);
    controlID = "_" + attrName.replace(/ /g, "_") + "_" + propName + "_" + groupNum;
    enums = indexes.split(",");

    // drop-downs are special - if not auto-selected or show pending,
    // make sure the first enumeration is selected
    if( !hasSelection(attrName) &&
        !isAutoSelectable(attrName) &&
        !showPendingText )
    {
        selectIndexes(enums[0], false);
        refreshScreen = true;
    }

    html += '<select class="DropList" name="' + controlID + '" size="' + size;
//BEG UPGRADE ISSUE CUSTOM FOR BULLARD...
bDirty = false;
//    html += '" onchange="';
    html += '" onchange="oEngineLocation.bDirty=true;';
//END UPGRADE ISSUE CUSTOM FOR BULLARD...
    html += "oEngineLocation.addDynamicProperty(sReloadCmd, makeFocusCmd('" + controlID + "'));";
    if( showPendingText )
        html += "oEngineLocation.ClearSelection('" + attrName + "." + propName + "');oEngineLocation.ProcessDirtyStates();";
    html += 'oEngineLocation.selectIndexes(oEngineLocation.GetPageControlValuesJS(this.form.' +
            controlID + '), ' + !deferred + ');';
    if( !deferred )
        html += 'location.reload();';
    html += '">';
    if( showPendingText )
    {
        html += "<option class='GoodNotSelected'";
        html += ' value="-1">+ ' + pendingText;
        html += "</option>";
    }
    for( i=0; i<enums.length; i++ )
    {
        enumeration = getEnumeration(parseInt(enums[i]), propName);
        propValue = enumeration.get(propName);
        advice = enumeration.get("_SelectionAdvice");
        index = enumeration.get("_Index");
        selected = true;
        adviceIndicator = "";
        if( advice == GOOD_NOT_SELECTED ||
            advice == BAD_NOT_SELECTED )
        { // not selected or auto-selected
            selected = false;
        }
        if( advice == GOOD_SELECTED ||
            advice == GOOD_AUTO_SELECTED ||
            advice == GOOD_NOT_SELECTED )
        { // good selection
            if( showGood || selected )
            {
                adviceIndicator = "+ ";
            }
        }
        else if( showBad || selected )
        { // bad selection
            adviceIndicator = "- ";
        }
        if( adviceIndicator != "" )
        { // do display
            var classType = "";
            switch( parseInt(advice + "") )
            {
                case IGOOD_SELECTED: classType = "GoodSelected"; break;
                case IGOOD_NOT_SELECTED: classType = "GoodNotSelected"; break;
                case IGOOD_AUTO_SELECTED: classType = "AutoSelected"; break;
                case IBAD_SELECTED: classType = "BadSelected"; break;
                case IBAD_NOT_SELECTED: classType = "BadNotSelected"; break;
            }
            html += "<option class='" + classType + "'";
            if( selected )
                html += ' selected';
            if( showPlusMinus )
                html += ' value="' + index + '">' + adviceIndicator + propValue;
            else
                html += ' value="' + index + '">' + propValue;
            html += "</option>";
        }
    }
    html += "</select>";
    return html;
}

function CreateRadioButton(attrName, propName, showPendingText, pendingText,
                           showBad, showGood, deferred, indexes)
{
    html = "";
    groupNum = GetGroupNumFromAttrName(attrName);
    controlID = "_" + attrName.replace(/ /g, "_") + "_" + propName + "_" + groupNum;
    enums = indexes.split(",");

    html += '<table cellpadding="0" cellspacing="0">';
    if( showPendingText )
    {
        html += '<tr><td>+</td><td><input type="radio" name="' + controlID + '" ';
        html += ' onclick="';
        html += "oEngineLocation.addDynamicProperty(sReloadCmd, makeFocusCmd('" + controlID + "'));";
        html += "oEngineLocation.ClearSelection('" + attrName + "." + propName + "');oEngineLocation.ProcessDirtyStates();";
        if( !deferred )
            html += 'location.reload();';
        html += '" ';
        if( !hasSelection(attrName) && !hasAutoSelection(attrName) )
            html += " checked ";
        html += ' value="-1" /></td><td>' + pendingText;
        html += "</td></tr>";
    }
    for( i=0; i<enums.length; i++ )
    {
        enumeration = getEnumeration(parseInt(enums[i]), propName);
        propValue = enumeration.get(propName);
        advice = enumeration.get("_SelectionAdvice");
        index = enumeration.get("_Index");
        selected = true;
        adviceIndicator = "";
        if( advice == GOOD_NOT_SELECTED || advice == BAD_NOT_SELECTED )
            selected = false;
        if( advice == GOOD_SELECTED ||
            advice == GOOD_AUTO_SELECTED ||
            advice == GOOD_NOT_SELECTED )
        { // good selection
            if( showGood || selected )
            {
                adviceIndicator = "+ ";
            }
        }
        else if( showBad || selected )
        { // bad selection
            adviceIndicator = "- ";
        }
        if( adviceIndicator != "" )
        { // do display
            html += '<tr><td>' + adviceIndicator + '</td><td><input type="radio" name="' +
                    controlID + '" ';
            html += ' value="' + index + '" ';
            if( selected )
                html += ' checked';
//BEG UPGRADE ISSUE CUSTOM FOR BULLARD...
bDirty = false;
//            html += ' onclick="';
            html += ' onclick="oEngineLocation.bDirty=true;';
//END UPGRADE ISSUE CUSTOM FOR BULLARD...
            if( showPendingText )
                html += "oEngineLocation.ClearSelection('" + attrName +
                        "." + propName + "');oEngineLocation.ProcessDirtyStates();";
            html += 'oEngineLocation.selectIndexes(oEngineLocation.GetPageControlValuesJS(this.form.' +
                    controlID + '), ' + !deferred + ');';
            if( !deferred )
                html += 'location.reload();';
            html += '" /></td>';
            var classType = "";
            switch( parseInt(advice + "") )
            {
                case IGOOD_SELECTED: classType = "GoodSelected"; break;
                case IGOOD_NOT_SELECTED: classType = "GoodNotSelected"; break;
                case IGOOD_AUTO_SELECTED: classType = "AutoSelected"; break;
                case IBAD_SELECTED: classType = "BadSelected"; break;
                case IBAD_NOT_SELECTED: classType = "BadNotSelected"; break;
            }
            html += '<td class="' + classType + '">' + propValue;
            html += '</td></tr>';
        }
    }
    html += "</table>";
//    alert(html);
    return html;
}

function CreateCheckBox(attrName, propName, showBad, showGood, deferred, indexes)
{
    html = "";
    groupNum = GetGroupNumFromAttrName(attrName);
    controlID = "_" + attrName.replace(/ /g, "_") + "_" + propName + "_" + groupNum;
    enums = indexes.split(",");

    html += '<table cellpadding="0" cellspacing="0">';
    for( i=0; i<enums.length; i++ )
    {
        enumeration = getEnumeration(parseInt(enums[i]), propName);
        propValue = enumeration.get(propName);
        advice = enumeration.get("_SelectionAdvice");
        index = enumeration.get("_Index");
        selected = true;
        adviceIndicator = "";
        if( advice == GOOD_NOT_SELECTED || advice == BAD_NOT_SELECTED )
            selected = false;
        if( advice == GOOD_SELECTED ||
            advice == GOOD_AUTO_SELECTED ||
            advice == GOOD_NOT_SELECTED )
        { // good selection
            if( showGood || selected )
            {
                adviceIndicator = "+ ";
            }
        }
        else if( showBad || selected )
        { // bad selection
            adviceIndicator = "- ";
        }
        if( adviceIndicator != "" )
        { // do display
            html += '<tr><td>' + adviceIndicator + '</td><td><input type="checkbox" name="' +
                    controlID + '" ';
            html += ' value="' + index + '" ';
            if( selected )
                html += ' checked';
//BEG UPGRADE ISSUE CUSTOM FOR BULLARD...
bDirty = false;
//            html += ' onclick="';
            html += ' onclick="oEngineLocation.bDirty=true;';
//END UPGRADE ISSUE CUSTOM FOR BULLARD...
            html += "oEngineLocation.addDynamicProperty(sReloadCmd, makeFocusCmd('" + controlID + "'));";
            html += "oEngineLocation.ClearSelection('" + attrName + "." + propName + "');";
            html += 'oEngineLocation.selectIndexes(oEngineLocation.GetPageControlValuesJS(this.form.' +
                    controlID + ').replace(/[\|]/g, ' + "','" + '), ' + !deferred + ');';
            if( !deferred )
                html += 'location.reload();';
            html += '" /></td>';
            var classType = "";
            switch( parseInt(advice + "") )
            {
                case IGOOD_SELECTED: classType = "GoodSelected"; break;
                case IGOOD_NOT_SELECTED: classType = "GoodNotSelected"; break;
                case IGOOD_AUTO_SELECTED: classType = "AutoSelected"; break;
                case IBAD_SELECTED: classType = "BadSelected"; break;
                case IBAD_NOT_SELECTED: classType = "BadNotSelected"; break;
            }
            html += '<td class="' + classType + '">' + propValue;
            html += '</td></tr>';
        }
    }
    html += "</table>";
    return html;
}

function CreateControl(attrName, propName, type, size, showPendingText, pendingText,
                       showBad, showGood, deferred, indexes)
{
    switch( type )
    {
        // Note: Control types are now 1-based, not 0-based as previous
        case 1: return CreateDropDown(attrName, propName, size, showPendingText, pendingText,
                                      showBad, showGood, deferred, indexes);
        case 2: return CreateCheckBox(attrName, propName, showBad, showGood, deferred, indexes);
        case 3: return CreateRadioButton(attrName, propName, showPendingText, pendingText,
                                         showBad, showGood, deferred, indexes);
    }
}

// following function is specific to Bullard
function CreateControlNoAdvice(attrName, propName, type, size, showPendingText, pendingText,
                       showBad, showGood, deferred, indexes)
{
    switch( type )
    {
        // Note: Control types are now 1-based, not 0-based as previous
        case 100048: return CreateDropDown(attrName, propName, size, showPendingText, pendingText,
                                      showBad, showGood, deferred, indexes, false);
        case 2: return CreateCheckBox(attrName, propName, showBad, showGood, deferred, indexes);
        case 3: return CreateRadioButton(attrName, propName, showPendingText, pendingText,
                                         showBad, showGood, deferred, indexes);
    }
}

function CreateTextBoxControl(attrName, propName, numCols, showRecommendation, deferred, advice)
{
    if( advice == null ) advice = "GoodSelected";
    html = "";
    groupNum = GetGroupNumFromAttrName(attrName);
    controlID = "_" + attrName.replace(/ /g, "_") + "_" + propName + "_" + groupNum;

    html += '<input type="text" class="' + advice + '" ';
    html += 'name="' + controlID + '" ';
//BEG UPGRADE ISSUE CUSTOM FOR BULLARD...
bDirty = false;
//    html += 'onChange="oEngineLocation.selectEnumeration(' + "'" +
    html += 'onChange="oEngineLocation.bDirty=true;oEngineLocation.selectEnumeration(' + "'" +
//END UPGRADE ISSUE CUSTOM FOR BULLARD...
                      attrName + "', '" + propName + "', " +
                      'oEngineLocation.GetPageControlValuesJS(this), ' +
                      !deferred + ');';
    html += "oEngineLocation.addDynamicProperty(sReloadCmd, makeFocusCmd('" + controlID + "'));";
    if( !deferred )
        html += "location.reload();";
    html += '" size="' + numCols + '" ';
//BEG UPGRADE ISSUE CUSTOM FOR BULLARD...
	// Bullard fix only - get maxlength property
    selectEnumeration("Text Box Max Lengths", "Name", attrName, false);
    numCols = GetIntProperty(GetGroupNumFromAttrName("Text Box Max Lengths"), "", "Quantity", "0", "SDIR");
    if( numCols > 0 )
	{
        html += 'maxlength="' + numCols + '" ';
	}
//END UPGRADE ISSUE CUSTOM FOR BULLARD...
    // output the input value
    html += ' value="';
    html += GetProperty(GetGroupNumFromAttrName(attrName), "", propName,
                        "", showRecommendation?"ISRD":"ISDR");
    html += '" />';
    return html;
}

function CreateTextControl(attrName, propName, numCols, numRows, showRecommendation, deferred)
{
    var advice = "GoodSelected";
    if( hasAutoSelection(attrName) )
        advice = "AutoSelected";
    else if( isInConflict(attrName) )
        advice = "BadSelected";
    if( numRows == 1 )
    {
        return CreateTextBoxControl(attrName, propName, numCols,
                                    showRecommendation, deferred, advice);
    }
    html = "";
    groupNum = GetGroupNumFromAttrName(attrName);
    controlID = "_" + attrName.replace(/ /g, "_") + "_" + propName + "_" + groupNum;

    html += '<textarea class="' + advice + '" ';
    html += 'name="' + controlID + '" ';
//BEG UPGRADE ISSUE CUSTOM FOR BULLARD...
bDirty = false;
//    html += 'onChange="oEngineLocation.selectEnumeration(' + "'" +
    html += 'onChange="oEngineLocation.bDirty=true;oEngineLocation.selectEnumeration(' + "'" +
//END UPGRADE ISSUE CUSTOM FOR BULLARD...
                      attrName + "', '" + propName + "', " +
                      'oEngineLocation.GetPageControlValuesJS(this), ' +
                      !deferred + ');';
    html += "oEngineLocation.addDynamicProperty(sReloadCmd, makeFocusCmd('" + controlID + "'));";
    if( !deferred )
        html += "location.reload();";
    html += '" rows="' + numRows + '" cols="' + numCols + '" ';
    html += ">";
    // output the input value
    html += GetProperty(GetGroupNumFromAttrName(attrName), "", propName,
                        "", showRecommendation?"ISRD":"ISDR");
    html += '</textarea>';
    return html;
}

// following function is specific to Bullard and the Leather Front model
function CreateCustomTextControl(attrName, propName, numCols, numRows, showRecommendation, deferred)
{
    if( numRows == 1 )
    {
        var advice = "GoodSelected";
        if( hasAutoSelection(attrName) )
            advice = "AutoSelected";
        else if( isInConflict(attrName) )
            advice = "BadSelected";
        html = "";
        groupNum = GetGroupNumFromAttrName(attrName);
        controlID = "_" + attrName.replace(/ /g, "_") + "_" + propName + "_" + groupNum;

        html += '<input type="text" class="' + advice + '" ';
        html += 'name="' + controlID + '" ';
        bDirty = false;
        html += 'onChange="oEngineLocation.bDirty=true;oEngineLocation.selectEnumeration(' + "'" +
                          attrName + "', '" + propName + "', " +
                          'oEngineLocation.GetPageControlValuesJS(this), ' +
                          !deferred + ');';
        html += "oEngineLocation.addDynamicProperty(sReloadCmd, makeFocusCmd('" + controlID + "'));";
        if( !deferred )
            html += "location.reload();";
        html += '" size="' + numCols + '" ';
        selectEnumeration("Text Box Max Lengths", "Name", attrName, false);
        numCols = GetIntProperty(GetGroupNumFromAttrName("Text Box Max Lengths"), "", "Quantity", "0", "SDIR");
        if( numCols > 0 )
        {
            html += 'maxlength="' + numCols + '" ';
        }
        // output the input value
        html += ' value="';
        textEntered = "" + GetProperty(GetGroupNumFromAttrName(attrName), "", propName,
                            "", showRecommendation?"ISRD":"ISDR");
        html += textEntered;
        // determine if we should disable the control
        // first, get current length of text entered.  If > 0, do nothing
        if( textEntered.length == 0 ) {
            // nothing entered, determine max length.  If == 0 , add disabled flag
            maxLength = getCalculation(attrName + " Limit Message");
            if( maxLength != null && maxLength.indexOf(">0<") > -1 )
            {
                html += '" style="background-color:Gray" disabled="true';
            }
        }

        html += '" />';
        return html;
    }
    else
    {
        return CreateTextControl(attrName, propName, numCols, numRows, showRecommendation, deferred)
    }
}

function CreateYesNoControl(attrName, propName, noEnum, yesEnum, deferred)
{
    html = "";
    groupNum = GetGroupNumFromAttrName(attrName);
    controlID = "_" + attrName.replace(/ /g, "_") + "_" + propName + "_" + groupNum;
    enums = getEnumerations(attrName, propName);

    selected = false;
    for( i=0; i<enums.size(); i++ )
    {
        enumeration = enums.elementAt(i);
        propValue = enumeration.get(propName);
        advice = enumeration.get("_SelectionAdvice");
        index = enumeration.get("_Index");
        if( propValue + "" == yesEnum )
        {
            // yes enum found
            selected = !(advice == GOOD_NOT_SELECTED || advice == BAD_NOT_SELECTED);
            yesAdvice = advice;
            //yesIndex = index;
            yesIndex = index;
        }
        else if( propValue + "" == noEnum )
        {
             // no enum found
            //noIndex = index;
            noIndex = index;
            noAdvice = advice;
        }
    }
    if( selected )
    {
        nextIndex = noIndex;
        advice = yesAdvice;
    }
    else
    {
        nextIndex = yesIndex;
        advice = noAdvice;
    }
    var classType = "";
    switch( parseInt(advice + "") )
    {
        case IGOOD_SELECTED: classType = "GoodSelected"; break;
        case IGOOD_NOT_SELECTED: classType = "GoodNotSelected"; break;
        case IGOOD_AUTO_SELECTED: classType = "AutoSelected"; break;
        case IBAD_SELECTED: classType = "BadSelected"; break;
        case IBAD_NOT_SELECTED: classType = "BadNotSelected"; break;
    }
    html += '<input type="checkbox" name="' + controlID + '" ';
//BEG UPGRADE ISSUE CUSTOM FOR BULLARD...
bDirty = false;
//    html += 'onclick="oEngineLocation.selectIndexes(' + nextIndex + ', ' + !deferred + ');';
    html += 'onclick="oEngineLocation.bDirty=true;oEngineLocation.selectIndexes(' + nextIndex + ', ' + !deferred + ');';
//END UPGRADE ISSUE CUSTOM FOR BULLARD...
    html += "oEngineLocation.addDynamicProperty(sReloadCmd, makeFocusCmd('" + controlID + "'));";
    if( !deferred )
        html += "location.reload();";
    html += '" ';
    if( selected )
        html += 'checked="true" ';
    html += ' class="' + classType + '" />';
    return html;
}

function CreateAttrResult(attrName, propName, showBad, showGood, showSelectedOnly, delimiter, indexes, format, decimalPlaces)
{
    html = "";
    enums = indexes.split(",");

    for( i=0; i<enums.length; i++ )
    {
        enumeration = getEnumeration(parseInt(enums[i]), propName);
        propValue = enumeration.get(propName);
        advice = enumeration.get("_SelectionAdvice");

        if( (showSelectedOnly && (advice == GOOD_SELECTED || advice == GOOD_AUTO_SELECTED || advice == BAD_SELECTED)) ||
            (!showSelectedOnly && showGood && (advice == GOOD_SELECTED || advice == GOOD_NOT_SELECTED || advice == GOOD_AUTO_SELECTED)) ||
            (!showSelectedOnly && showBad && (advice == BAD_SELECTED || advice == BAD_NOT_SELECTED)) )
            html += ((html.length > 0 ) ? delimiter : "") + FormatNumber(propValue, format, parseInt(decimalPlaces));
    }

    if( html.length == 0 && !showSelectedOnly )  // did not find any selections or recommendations
    {
        html = FormatNumber(GetProperty(GetGroupNumFromAttrName(attrName), "", propName, "", "IDRS"), format, decimalPlaces);  // get input
    }

    return html;
}



