﻿
// sends input data to webserver, returns list of valid parts.
function ListEscapements()
{
    var pl = new SOAPClientParameters();
    var isGravityFeed = rbGravity.checked; // evaluates to true or false
    var isStrokeLengthAdj;
    var isShockpads;     
        
    
    if (cbLC.checked)
    {
        // if LC escapements checked, get stroke adjustment and shockpad status
        isStrokeLengthAdj = cbStrokeAdj.checked; 
        isShockpads = cbShockPads.checked; 
    }
    else
    {
        // without LC, these options don't exist, so they're always false.
        // They are hidden on the page but I think they could still be checked and throw everything off.
        isStrokeLengthAdj = false;
        isShockpads = false;
    }
        
    // these are the same regardless of feed type
	valDistL = spnUCDistL.ActualValue/spnUCDistL.ConvFact;	
	valWeightW = spnUCWeightW.ActualValue/spnUCWeightW.ConvFact;
	valNumPartsN = parseInt(spnUCNumberN.ActualValue); // won't be a conversion factor for this
	valPressureP = spnUCPressureP.ActualValue/spnUCPressureP.ConvFact;
	valOffsetR = spnUCOffsetR.ActualValue/spnUCOffsetR.ConvFact;    
	isMetric = rbMetric.checked;
	

    // these are feed-type dependent:
	if (isGravityFeed) // if gravity is checked
	{   // if gravity, get gravity-only fields:
		valDistHp = spnUCDistHp.ActualValue/spnUCDistHp.ConvFact;
		valDistHs = spnUCDistHs.ActualValue/spnUCDistHs.ConvFact;
		valAngleA = spnUCAngleA.ActualValue/spnUCAngleA.ConvFact;
		// set conveyor-only variables to 0
		valFrictionF = 0;
		valVelocityV = 0;             
	}
	else
	{   // if conveyor, get conveyor-only fields:        
		valFrictionF = spnUCFrictionF.ActualValue/spnUCFrictionF.ConvFact;
		valVelocityV = spnUCVelocityV.ActualValue/spnUCVelocityV.ConvFact;
		// set gravity-only variables to 0
		valAngleA = 0;
		valDistHp = 0;
		valDistHs = 0;           
	}       
	
	var language = element("UserLanguageStorage").value;
	
    // add parameters to send to WebService
    pl.add("isGravity", isGravityFeed) ; 
    pl.add("inDistL", valDistL) ;
    pl.add("inWeightW", valWeightW) ;
    pl.add("inNumPartsN", valNumPartsN) ;
    pl.add("inPressureP", valPressureP) ;
    pl.add("inOffsetR", valOffsetR) ;    
    pl.add("inDistHp", valDistHp) ;
    pl.add("inDistHs", valDistHs) ;
    pl.add("inAngleA", valAngleA) ;
    pl.add("inFrictionF", valFrictionF) ;
    pl.add("inConveyorV", valVelocityV) ;    
    pl.add("isStrokeLengthAdjust", isStrokeLengthAdj) ;
    pl.add("isShockpads", isShockpads) ;
    pl.add("isMetric", isMetric);
    pl.add("bShowFailed", cbShowFailed.checked);
    pl.add("inLanguage", language);
       
     /*
       // start test:
       var pl2 = new SOAPClientParameters();
       var pl3 = new SOAPClientParameters();
       pl2.add("test1", 5);
       pl3.add("test1", 6);
       pl3.add("test2", 7);
       SOAPClient.invoke("EscapementService.asmx", "OL1OneParameter", pl2, true, test_callback) ;
       SOAPClient.invoke("EscapementService.asmx", "OL1TwoParameters", pl3, true, test_callback) ;
       // : end test
     */
      
    needCalc = false ;
    busy = true ;
    // get data from WebService and display it on webpage
    SOAPClient.invoke("EscapementService.asmx", "ListEscapements", pl, true, list_callback) ;
}


    function test_callback(rtVal)
    {
        alert("value: " + rtVal);
        return;
    }
    
    
// populate list:
function list_callback(valids)
{
    var option;
    var storeSelected;
    
    var colNum;
    
    if (lbPartList.id == "lbPartList")
    {
        colNum = "";
    }
    else
    {
        colNum = "C2";
    }
    
    busy = false ;

    if (needCalc)
    {
        StartCalc() ;
        return ;
    }

    if (valids)
    {
    
        divPartList.style.display = "inline";
        divPartList.visible = "visible";
        divResultColumn.style.display = "inline"; // make sure the results column is visible.
        divResultColumn.visible = "visible";
        
        storeSelected = selectedOptions;
        lbPartList.style.display = "inline";
        lbPartList.visible = "visible";
        
        lbPartList.style.position = "relative";
        // lbPartList.style.zIndex = -50;
        
        
        // populate with valids list.
        clearListBoxAll();
        arLength = valids.length;
						
    	for (i = 0; i < arLength; i++)
	    {
	        option=new Option(valids[i], valids[i], false);
		    option.innerHTML = valids[i].substr(0, 50); // limit length of string to prevent wacky overflow problems
		    
		    if (option.value.match("160")== "160" && cb160.checked)
		    {
		        var og160 = element("og160"+ colNum);
		        if (og160 == null)
		        {
		            og160 = document.createElement("optgroup") ;
                    og160.label = element("lbl160").innerHTML + "..."; //"160 Double Rod...";
                    og160.id = "og160"+ colNum;    
                    lbPartList.appendChild(og160) ;
                }
		        og160.appendChild(option);
            }
        }
        
        for (i = 0; i < arLength; i++)
	    {
	        option=new Option(valids[i], valids[i], false);
		    option.innerHTML = valids[i].substr(0, 50); // limit length of string to prevent wacky overflow problems
		    
		    if (option.value.match("LC")== "LC" && cbLC.checked)
		    {		        
		        
		        var ogLC = element("ogLC" + colNum);		        
		        
		        if (ogLC == null)
		        {
		            ogLC = document.createElement("optgroup") ;
                    ogLC.label = element("lblLC").innerHTML + "..."; // "LC Single Rod...";
                    ogLC.id = "ogLC" + colNum;    
                    lbPartList.appendChild(ogLC) ;
                }
    		    ogLC.appendChild(option);    		    
            }		    
        }
        
        
        
        var j;        
    
        var divResultsMsg = element("divResultsMsg");
        divResultsMsg.innerHTML = "";
        try
        {
            divResultsMsg = element("divResultsMsgC2");
            divResultsMsg.innerHTML = "";
        }
        catch(err)
        {}
        
        // if any parts were selected before, we should select them now.
        selectedOptions = storeSelected;
        reselect();
        sizingCalc();
    }
    else
    {
        // alert("No response from ListEscapements.") ;
        alert(element("hidErrNoResponse").value);
    }

    // divForm.style.height = "800px";    
    return;
}
 
 
