//Frank Walsh
//Key-Stone Automotive Corporation
//Year, Make, Model Search Javascript Consuming Module
//8-11-2004
//Requires webservice.htc - Microsoft WebService Behavior Module
//Requires jsinit.js - Variable Definition File
//Design Example named ymmsearch.html


/************REQUIRED HTML FIELDS AND FORMS****************/
/*                                                        */
/* HTML FORM : OrderForm                                  */
/*             HTML LISTBOX : QAChoice                    */
/*             HTML HIDDEN INPUT FIELD : accum            */
/*             HTML HIDDEN INPUT FIELD : accumText        */
/*             HTML HIDDEN INPUT FIELD : state            */
/*             HTML HIDDEN INPUT FIELD : RtnCode          */
/*             HTML HIDDEN INPUT FIELD : RtnText          */
/*             HTML HIDDEN INPUT FIELD : category         */
/*             HTML HIDDEN INPUT FIELD : YrMkMd           */
/*                                                        */
/* HTML DIV FIELD : PartsInfoCell                         */
/*                                                        */
/**********************************************************/

/**********************************************************************************/
/*              Javascript WebService Init Consumption Function                   */
/* The below function prepares the web-service for use by examining the           */
/* ecatexample.html file you will find the line:                                  */
/*       <DIV ID="myWebService" style="behavior:url(webservice.htc)"></DIV>       */
/* this line assigns the Microsoft WebService Behavior component to the alias     */
/* myWebService. You then access the useService function of the Webservice        */
/* Behavior passing it two parameters, the first is the location of the service   */
/* the second is the alias you wish to use for this webservice in your Javascript */
/*                                                                                */
/* In the below init() function, we initialize two WebService Defs. one for the   */
/* CatalogService, and another for the OrderService                               */
/*                                                                                */
/*  Input:                                                                        */
/*          This Function Requires NO INPUT                                       */
/*  Output:                                                                       */
/*          This Function has NO OUTPUT                                           */
/*                                                                                */
/**********************************************************************************/

function init()
{
		serverName = document.OrderForm.serverName.value;

		//myWebService.useService("http://order.ekeystone.com/WSElectroniccatalog/ElectronicCatalog.asmx?WSDL","CatalogService"); //Map the WebService to the Javascript Name "CatalogService"
	  myWebService.useService("http://"+serverName+"/JSCatalogProxy/CatalogProxy.asmx?WSDL","CatalogService"); //Map the WebService to the Javascript Name "CatalogService"

  //myWebService.useService("http://order.ekeystone.com/WSElectronicOrder/ElectronicOrder.asmx?WSDL","OrderService"); //Map the WebService to the Javascript Name "OrderService"
  //myWebService.useService("http://"+serverName+"/WSElectronicOrder/ElectronicOrder.asmx?WSDL","OrderService"); //Map the WebService to the Javascript Name "OrderService"

}

/**********************************************************************************/
/*            Javascript WebService GetPartsInfo Consumption Function             */
/* The below function is called directly from an OnClick or OnChange call in a    */
/* HTML document. The structure of the internal call is as follows: You make a    */
/* call to your defined behavior name, which in this case is myWebService.        */
/* We then reference the alias we defined the web service as in this case:        */
/* CatalogService. The webservice behavior contains member function callService   */
/* The callService function takes these params in the below listed order:         */
/*        callService Params:                                                     */
/*                   Javascript Function to call on Result,                       */
/*                   WebMethod to call in the selected WebService,                */
/*                   Parameter 1 to pass to the selected WebService,              */
/*                   Parameter 2 to pass to the selected WebService,              */
/*                   Parameter 3,                                                 */
/*                   This structure of variable passing continutes until          */
/*                   you run out of parameters to pass                            */
/*                                                                                */
/*  getPartsInfo Function Inputs:                                                 */
/*  Input:                                                                        */
/*    SearchKey      : The SearchKey to be used for our search                    */
/*    SearchStyle    : The SearchStyle to be used for our search - 1[Char]        */
/*               Search Styles Available:                                         */
/*                        1 = Part Number                                         */
/*                        2 = QAKeyCode - Returned from GetQA                     */
/*                        3 = Keyword or Part Number                              */
/*    MaxRows        : Max Rows to Return in Response - 3 Digit Number            */
/*    MyPrice        : Return My Purchase Price - Y or N                          */
/*  Output:                                                                       */
/*       This function has no output, but calls the PartsInfoResult Function if   */
/*       it successfully connects and transmits data to the webservice            */
/*                                                                                */
/**********************************************************************************/

function getPartsInfo(SearchKey,SearchStyle,MaxRows,MyPrice)
{
 myWebService.CatalogService.callService(PartsInfoResult, "GetPartsInfo",GetPartInfoKey,CustNumber,SearchKey,SearchStyle,MaxRows,MyPrice);
}

/**********************************************************************************/
/*                Javascript WebService GetQA Consumption Function                */
/* The below function is called from either an HTML onChange() or onClick() ref-  */
/* erence, or a reference in an XML Stylesheet definition [XSL File].             */
/* The callService function takes these params in the below listed order:         */
/*        callService Params:                                                     */
/*                   Javascript Function to call on Result,                       */
/*                   WebMethod to call in the selected WebService,                */
/*                   Parameter 1 to pass to the selected WebService,              */
/*                   Parameter 2 to pass to the selected WebService,              */
/*                   Parameter 3,                                                 */
/*                   This structure of variable passing continutes until          */
/*                   you run out of parameters to pass                            */
/*                                                                                */
/*  getQA Function Inputs:                                                        */
/*  Input:                                                                        */
/*       This function takes the Accum variable as input which represents the     */
/*       selected choice value just made when presented a question.               */
/*  Output:                                                                       */
/*       This function has no output, but calls the GetQAResult Function if       */
/*       it successfully connects and transmits data to the webservice            */
/*                                                                                */
/**********************************************************************************/

function getQA(Accum)
{
 if(Accum!="NEWSEARCH" && Accum!="SELECTONE") //If we didn't just choose the New Search Option or the "Select One" default choice
        {
                   var theLength; //Init a variable to hold the length of the list box
                   var SearchLevel = document.OrderForm.SearchLevel.value; //Grab the current search level from the hidden HTML field
                   if(SearchLevel == "Year") //If the search level is currently year
                                  {
                                            var theList = document.OrderForm.QAYear; //Set a variable equal to the QAYear Listbox
                                            theLength = document.OrderForm.QAYear.options.length; //Define a variable equal to the number of choices in the QAChoice Listbox
                                            document.OrderForm.accum.value = "____";  //Set the accum equal to three underscores
                                            document.OrderForm.QAYear.disabled = false; //Make sure the year listbox is not disabled
                                            document.OrderForm.QAMake.disabled = true; //Disable the make listbox
                                            document.OrderForm.QAModel.disabled = true; //Disable the model listbox
                                            document.OrderForm.PartBox.disabled = true; //Disable the part listbox
                                            //document.OrderForm.PartType[0].disabled = true; //Disable the part type selections
                                            //document.OrderForm.PartType[1].disabled = true; //Disable the part type selections
                                            //document.OrderForm.PartType[2].disabled = true; //Disable the part type selections
                                            //document.OrderForm.PartType[3].disabled = true; //Disable the part type selections

                                  }
                   else if(SearchLevel == "Make") //If the search level is currently Make
                                  {
                                       var theList = document.OrderForm.QAYear; //Set a variable equal to the QAYear Listbox
                                       theLength = document.OrderForm.QAYear.options.length; //Define a variable equal to the number of choices in the QAChoice Listbox
                                       document.OrderForm.accum.value = document.OrderForm.RtnCode.value + Accum; //Set the Hidden Input field Accum equal to the RtnCode Hidden Input field plus the just selected option
                        	       document.OrderForm.QAYear.disabled = true;       //Disable the year listbox
                        	       document.OrderForm.QAMake.disabled = false;      //Enable the make listbox
                        	       document.OrderForm.QAModel.disabled = true;      //Disable the model listbox
                        	       document.OrderForm.PartBox.disabled = true;     //Disable the part listbox
                                       //document.OrderForm.PartType[0].disabled = true; //Disable the part type selections
                                       //document.OrderForm.PartType[1].disabled = true; //Disable the part type selections
                                       //document.OrderForm.PartType[2].disabled = true; //Disable the part type selections
                                       //document.OrderForm.PartType[3].disabled = true; //Disable the part type selections
                        	       document.OrderForm.YrMkMd.value += Accum.substr(0,4); //Append the first four characters of accum to the YrMkMd hidden HTML field
                                  }
                   else if(SearchLevel == "Model") //If the search level is currently Model
                                  {
                                            var theList = document.OrderForm.QAMake;  //Set a variable equal to the QAMake Listbox
                                            theLength = document.OrderForm.QAMake.options.length; //Define a variable equal to the number of choices in the QAChoice Listbox
                                            document.OrderForm.accum.value = document.OrderForm.RtnCode.value + Accum; //Set the Hidden Input field Accum equal to the RtnCode Hidden Input field plus the just selected option
                        	            document.OrderForm.QAYear.disabled = true;  //Disable the Year Listbox
                        	            document.OrderForm.QAMake.disabled = true;  //Disable the Make Listbox
                        	            document.OrderForm.QAModel.disabled = false; //Enable the QAModel Listbox
                        	            document.OrderForm.PartBox.disabled = true;  //Disable the Part Listbox
                                            //document.OrderForm.PartType[0].disabled = true; //Disable the part type selections
                                            //document.OrderForm.PartType[1].disabled = true; //Disable the part type selections
                                            //document.OrderForm.PartType[2].disabled = true; //Disable the part type selections
                                            //document.OrderForm.PartType[3].disabled = true; //Disable the part type selections
                        	            document.OrderForm.YrMkMd.value += Accum.substr(0,3); //Append the first three characters of the accum to the YrMkMd hidden HTML Field
                                  }
                   else if(SearchLevel == "Part" || SearchLevel == "InsidePart") //If we are on the Part Selection level or inside the part selection box
                                  {
                                  	   if(document.OrderForm.QAModel.disabled == false) //If the QAModel is not yet disabled, that means we just finished selecting a model
                                  	           {
                                                      var theList = document.OrderForm.QAModel; //Define a variable equal to the QAModel Listbox
                                                      theLength = document.OrderForm.QAModel.options.length; //Define a variable equal to the QAModel Listbox Length
                                                      document.OrderForm.accum.value = document.OrderForm.category.value; //Set the accum field equal to the selected part category value
                                  	              document.OrderForm.accumText.value = ""; //Set the accumText field equal to nothing
                                                      document.OrderForm.YrMkMd.value += Accum.substr(0,4); //Append the first four characters of the selected model to the YrMkMd hidden html field
                                                      var NewPartSearch = true; //define a flag that says this is a new part search
                                                   }
                                           else //If the QAModel box was disabled that means we came from a selection in the PartList box or Category Change
                                                   {
                                                      var IsLastQuestion = ""; //Define the variable IsLastQuestion equal to nothing

                                                      if (Accum.indexOf("Y") > 0) //see if the character Y is in the Accum
                                                                {
                                                                            Accum.replace("Y", ""); //If it is replace it with nothing
                                                                            IsLastQuestion = "YES"; //Mark this as the last question
                                                                }
                                                      else if (Accum.indexOf("N") > 0) //see if the character N is in the accum
                                                                {
                                                                            Accum.replace("N",""); //If it is replace it with nothing
                                                                }
                                                      if (Accum.ToUpperCase == "NO DATA") //If the user just selected a NO DATA choice
                                                                {
                                                                            ResetPage(); //Reset the page
                                                                            return;
                                                                }
                                                      if(SearchLevel != "Part")
                                                           if (document.OrderForm.QuestionText.value == "Generic Description") //If the Question just answered was on the Generic Description Level
                                                                if (IsLastQuestion == "YES") //If it was the last question
                                                                        {
                                                                            document.OrderForm.accum.value = document.OrderForm.RtnCode.value + Accum.substr(0,4) + trim(document.OrderForm.YrMkMd.value); //Formulate the new Accum Value
                                                                        }
                                                                else //If this was not the last question
                                                                        {
                                                                            document.OrderForm.accum.value = document.OrderForm.RtnCode.value + Accum.substr(0,4) + trim(document.OrderForm.YrMkMd.value) + "0000"; //Formulate the new Accum Value
                                                                        }
                                                           else //If the question was not on the Generic Description Level
                                                                {
                                                                document.OrderForm.accum.value = trim(document.OrderForm.RtnCode.value) + trim(Accum); //Formulate the new accum value
                                                                }
                                                      else
                                                          {
                                                            document.OrderForm.accum.value = document.OrderForm.category.value;
                                                          }
                                                      var theList = document.OrderForm.PartBox; //Set a variable equal to the Part listbox
                                                      theLength = document.OrderForm.PartBox.options.length; //Set a variable equal to the length of the Part Listbox
                                                   }

                                           document.OrderForm.QAYear.disabled = true; //Disable the QAYear Listbox
                                  	   document.OrderForm.QAMake.disabled = true; //Disable the QAMake Listbox
                                  	   document.OrderForm.QAModel.disabled = true; //Disable the QAModel Listbox
                                  	   document.OrderForm.PartBox.disabled = false; //Disable the Part Listbox
                                           //document.OrderForm.PartType[0].disabled = false; //Disable the part type selections
                                          // document.OrderForm.PartType[1].disabled = false; //Disable the part type selections
                                          // document.OrderForm.PartType[2].disabled = false; //Disable the part type selections
                                          // document.OrderForm.PartType[3].disabled = false; //Disable the part type selections
                                  }

                   var AccumText = ""; //Set the AccumText Variable equal to ""

                   if(SearchLevel == "Make" || SearchLevel == "Model" || SearchLevel == "Part" || SearchLevel == "InsidePart") //If we are on any of the Search Level's excluding Year
                                  { //This code finds the assocated text for a selected value and then is later saved into AccumText
                                            for(var i = 0; i < theLength; i++) //While we still have options to itterate through
                                                    {

                                                    if(Accum.match(theList.options[i].value)) //If we find a match between our curren option value and the selected value
                                                                {
                                                                        var spacetest = theList.options[i].text.substring(theList.options[i].text.length-1,theList.options[i].text.length) //Take the last character in the option text we selected
                                                                        if(spacetest == " ") //If it is a space
                                                                                     AccumText = theList.options[i].text.substring(0,theList.options[i].text.length-1); //Delete the space
                                                                        else
                                                                                     AccumText = theList.options[i].text; //Otherwise select the entire option text
                                                                        break; //Exit the Loop
                                                                }

                                                    }

                                  }

                                                            document.OrderForm.accumText.value = document.OrderForm.RtnText.value + AccumText; //Add the AccumText we just set to the Hidden Input Field accumText
                                                            document.OrderForm.accumText.value = document.OrderForm.accumText.value.replace("&","&amp;"); //Replace any amersands with valid XML ampersand representation

                  if(AccumText.toUpperCase() == "SELECT ALL") //If the option we selected was the Select ALL Option
                              getPartsInfo(document.OrderForm.accum.value,'2','50','N'); //Get Part Info for all the options

                  else if(document.OrderForm.state.value == "YES") //If the option we just selected was the last choice we will have to make
                                 {
                                           getPartsInfo(document.OrderForm.accum.value,'2','50','N'); //Get Part Info for the options
                                 }
                  else if(SearchLevel == "Part") //If we just hit the Part Level Selection
                              {
                                document.OrderForm.RetainYMM.value = document.OrderForm.category.value + "[]" + document.OrderForm.state.value + "[]" + document.OrderForm.accum.value + "[]" + document.OrderForm.accumText.value + "[]" + document.OrderForm.RtnCode.value + "[]" + document.OrderForm.RtnText.value + "[]" + document.OrderForm.YrMkMd.value + "[]" + document.OrderForm.SearchLevel.value + "[]" + document.OrderForm.QuestionText.value;
                                document.OrderForm.SearchLevel.value = "InsidePart"; //Set the SearchLevel to where we will now be, Inside the part level
                              	myWebService.CatalogService.callService(getQAResult, "GetQAYMM",GetQAKey,document.OrderForm.accum.value,document.OrderForm.accumText.value,document.OrderForm.YrMkMd.value); //Call the GetQAYMM webservice instead of the GetQA
                              }
                  else
                              {
                              myWebService.CatalogService.callService(getQAResult, "GetQA",GetQAKey,document.OrderForm.accum.value,document.OrderForm.accumText.value); //Otherwise get the list of new Choices to be selected from
                              }

        }
 else if ( Accum == "SELECTONE" ) //If the user selected the default Select One choice somehow
      return;
 else //Otherwise We selected a New Search So..
     ResetPage(); //Call the ResetPage Function
 }

/**********************************************************************************/
/*        Electronic Catalog PartsInfoResult Consumption Function                 */
/* The below function is called internally by the GetPartsInfo function upon a    */
/* result. When a result is recieved this function takes that result and places   */
/* the RAW XML in a variable to be later parsed by our XML Style Sheet.           */
/*                                                                                */
/*  Input:                                                                        */
/*          This Function Requires NO USER INPUT but recieves XML when called by  */
/*          getPartsInfo.                                                         */
/*  Output:                                                                       */
/*          This Function has NO OUTPUT but on a ready state calls the PartsD-    */
/*          ata exchange functioin which prepares to apply the required styles-   */
/*          heet.                                                                 */
/*                                                                                */
/**********************************************************************************/

function PartsInfoResult(pResult)
{
       if(pResult.error) //If Part Information Lookup returned a Webservice Error
          alert("Unsuccessful call. Error is " + pResult.errorDetail.string);    // Display the Error Message

       pXMLData = new ActiveXObject('MSXML2.FreeThreadedDOMDocument'); //Create a new ActiveXObject
       pXMLData.onreadystatechange = PartsDataChange; //Assign the PartsDataChange function to be called on XML Ready State
       pXMLData.validateOnParse = true; //Validate the Data when it is parsed
       pXMLData.async = true;
       pXMLData.loadXML(pResult.raw.xml); //Load the result XML into the pXMLData ActiveXObject
}

/**********************************************************************************/
/*        Electronic Catalog GetQAResult Consumption Function                     */
/* The below function is called internally by the GetQA function upon a result.   */
/* When a result is recieved this function takes that result and places the       */
/* contents in a listbox named QAChoice.                                          */
/*                                                                                */
/*  Input:                                                                        */
/*          This Function Requires NO USER INPUT but recieves XML when called by  */
/*          getQA.                                                                */
/*  Output:                                                                       */
/*          This Function has NO OUTPUT but prepares the listbox with the next    */
/*          set of choices the user must select from.                             */
/*                                                                                */
/**********************************************************************************/

function getQAResult(qResult)
{
       if(typeof(qResult.value) != "undefined")
       {
                document.OrderForm.QuestionText.value = qResult.value.QuestionText; //Set the QuestionText Hidden HTML Field
                var SearchLevel = document.OrderForm.SearchLevel.value; //Get the Current SearchLevel from the hidden HTML field
                var QAChoice; //Define a QAChoice Variable
                if(SearchLevel == "Year")  //If the search level we made our selection on was Year
                        {
                               QAChoice = document.OrderForm.QAYear; //Set a variable equal to the Year Listbox
                               document.OrderForm.SearchLevel.value = "Make"; //Set the new search level to make
                        }
                else if(SearchLevel == "Make") //If the search level we made our selection on was Make
                        {
                                QAChoice = document.OrderForm.QAMake; //Set a variable equal to the Make Listbox
                                document.OrderForm.SearchLevel.value = "Model"; //Set the new search level to model
                        }
                else if(SearchLevel == "Model") //If the search level we made our selectioin on was Model
                        {
                	        QAChoice = document.OrderForm.QAModel; //Set a variable equal to the Model Listbox
                	        document.OrderForm.SearchLevel.value = "Part"; //Set the new search level to model
                        }
                else //We are inside the Part Listbox
                        {
                	        QAChoice = document.OrderForm.PartBox; //Set a variable equal to the Part Listbox
                        }


                var num_options = qResult.value.OptionText.length;  //Set a variable equal to the number of choices the webservice returned
                if(SearchLevel == "Part" || SearchLevel == "InsidePart") //If we are on or inside the Part List box, we woln't want the default Select One Option to appear
                        {
                                var QALength = 0; //Set the QALength to 0 so it clears from position 0
                        }
                else
                        {
                                var QALength = 1; //Set it to 1 so it doesn't clear the Select One choice
                        }
                document.OrderForm.state.value = qResult.value.IsLastQuestion;  //Set the Hidden Input Field state equal to the qResult IsLastQuestion Variable
                while(QAChoice.options[QALength] != null) //While things exist on the list
                        {
                                QAChoice.options[QALength] = null; //Delete them
                        }
                if(qResult.value.IsLastQuestion == "DONE") //If we are on the last set of choices
                        {
                                //var optText = "New Search";  //Create Option Text - New Search
                              var optText = "";  //Create Option Text - New Search
             	                var optCode = "NEWSEARCH";   //Create Option Code - NEWSEARCH
             	                QAChoice.options[0] = new Option(optText,optCode); //Place the Option in the option list
                                if(qResult.value.OptionText[0] != "")
                                        getPartsInfo(qResult.value.AnswerCode,'2','50','N'); //Get Part Info since we were on the last set of choices
                        }
                else //Otherwise if we were not on the last set of choices
                        {
                        	for(i = 0; i<num_options;i++) //Itterate through the array of options we were returned by the webservice
                                                {
             	                                             var optText = qResult.value.OptionText[i]; //Create Option Text for the current option
             	                                             var optCode = qResult.value.OptionCode[i]; //Create Option Code for the curren option
             	                                             QAChoice.options[QALength] = new Option(optText,optCode); //Add the option to the listbox
             	                                             QALength++; //add one to the QALength variable
                                                }

                                document.OrderForm.RtnCode.value = qResult.value.AnswerCode; //Set the Hidden Input Field RtnCode equal to the Webservice AnswerCode Return
                                document.OrderForm.RtnText.value = qResult.value.AnswerText; //Set the Hidden Input Field RtnText equal to the Webservice AnswerText Return
                        }
       }
else
       {
                while(document.OrderForm.PartBox.options[0] != null)
                {
                	document.OrderForm.PartBox.options[0] = null;
                }
                //var optText = "New Search";
                var optText = "No Results are available for this Category.";
       	        var optCode = "NEWSEARCH";
       	        document.OrderForm.PartBox.options[0] = new Option(optText,optCode);
       }
}


/**********************************************************************************/
/*        Electronic Catalog PartsDataChange Consumption Function                 */
/* As the returned XML data is recieved from the webservice, this function        */
/* monitors the process and takes action when the data is totally recieved.       */
/*                                                                                */
/*                                                                                */
/*  Input:                                                                        */
/*          This Function Requires NO USER INPUT but recieves XML when called by  */
/*          PartInfoResult.                                                       */
/*  Output:                                                                       */
/*          This Function has NO OUTPUT but on data ready state calls the Parts-  */
/*          InfoDisplay function which applies the desired stylesheet and places  */
/*          the returned data in an available dynamic HTML Field.                 */
/*                                                                                */
/**********************************************************************************/

function PartsDataChange()
{
     if (pXMLData.readyState == 4)
        {
                if (pXMLData.parseError.errorCode != 0)
                                alert("Error");
                else
                    {
                       PartsInfoDisplay();
                    }
        }

}

/**********************************************************************************/
/*           Electronic Catalog PartsInfoDisplay Consumption Function             */
/*        This function takes the returned XML and applies a XML StyleSheet then  */
/*        places the returned information in an HTML DIV Field.                   */
/*                                                                                */
/*  Input:                                                                        */
/*          This Function Requires NO USER INPUT but recieves XML when called by  */
/*          PartsDataChange.                                                      */
/*  Output:                                                                       */
/*          This Function has NO OUTPUT but applies the desired stylesheet        */
/*          and places the data in an available dynamic HTML Field.               */
/*                                                                                */
/**********************************************************************************/

function PartsInfoDisplay()
{

	alert("To see the results of your search click OK and they will appear below the search form.")
     // create a new parser object instance and load stylesheet
     var pXMLStyle = new ActiveXObject('MSXML2.FreeThreadedDOMDocument');
     pXMLStyle.async = false;
     pXMLStyle.load('/xsl/style-partinfo.xsl');
     if (pXMLStyle.parseError.errorCode != 0)
        {
       return;
        }

     // create a new XSLTemplate object and set stylesheet
     var pTemplate = new ActiveXObject('MSXML2.XSLTemplate');
     pTemplate.stylesheet = pXMLStyle;

     // create a processor and specify the XML parser to use
     var pProc = pTemplate.createProcessor();

		 	 // ADD PARAMETER - KIM
		  pProc.addParameter("mUP",document.OrderForm.mUP.value);
		  pProc.addParameter("category",document.OrderForm.category.value);
		  pProc.addParameter("YrMkMd",document.OrderForm.YrMkMd.value);
			// loop therought the select boxes to get the values
			var make = ""
			var model= "";
			var myear = "";

			ksmake = document.OrderForm.QAMake.options[document.OrderForm.QAMake.selectedIndex].text;
			ksmodel = document.OrderForm.QAModel.options[document.OrderForm.QAModel.selectedIndex].text;
		 	ksyear = document.OrderForm.QAYear.options[document.OrderForm.QAYear.selectedIndex].text;

			makeID = document.OrderForm.QAMake.options[document.OrderForm.QAMake.selectedIndex].value;
			modelID = document.OrderForm.QAModel.options[document.OrderForm.QAModel.selectedIndex].value;
		 	yearID = document.OrderForm.QAYear.options[document.OrderForm.QAYear.selectedIndex].value;

			makeINDEX = document.OrderForm.QAMake.selectedIndex;
			modelINDEX = document.OrderForm.QAModel.selectedIndex;
		 	yearINDEX = document.OrderForm.QAYear.selectedIndex;

		  pProc.addParameter("makeINDEX", makeINDEX);
		  pProc.addParameter("modelINDEX",modelINDEX);
		  pProc.addParameter("yearINDEX", yearINDEX);

		  pProc.addParameter("yearID", yearID);
		  pProc.addParameter("modelID",modelID);
		  pProc.addParameter("makeID", makeID);
		  pProc.addParameter("ksyear", ksyear);
		  pProc.addParameter("ksmodel",ksmodel);
		  pProc.addParameter("ksmake", ksmake);
		  pProc.addParameter("QuestionText",document.OrderForm.QuestionText.value);
		  pProc.addParameter("state",document.OrderForm.state.value);
		  pProc.addParameter("accum",document.OrderForm.accum.value);
		  pProc.addParameter("accumText",document.OrderForm.accumText.value);
		  pProc.addParameter("RtnCode",document.OrderForm.RtnCode.value);
		  pProc.addParameter("SearchLevel",document.OrderForm.SearchLevel.value);
		  pProc.addParameter("RetainYMM",document.OrderForm.RetainYMM.value);

     pProc.input = pXMLData;


     // perform transformation and display results in the page
     if (pProc.transform() == true)
       PartsInfoCell.innerHTML = pProc.output;
     else
       alert("FAILURE");
}

/**********************************************************************************/
/*                        Electronic Catalog ResetPage Function                   */
/* This function is used to reset the page variables and choices on a NewSearch   */
/* or category change.                                                            */
/*  Input:                                                                        */
/*        NONE                                                                    */
/*  Output:                                                                       */
/*        NONE                                                                    */
/*                                                                                */
/**********************************************************************************/

function ResetPage(retained_search)
{
if (retained_search == "true")
   {
   getQA('');
   return;
   }

//   for (var i=0; i < document.OrderForm.PartType.length; i++) //Go through the radio buttons
//   {
//   if (document.OrderForm.PartType[i].checked) //If we found one that was checked
//      {
//      document.OrderForm.category.value = document.OrderForm.PartType[i].value; //Set the Hidden Input Field Category equal to its value
//      }
//   }

 document.OrderForm.category.value = "001" //Set the Hidden Input Field Category equal to its value

document.OrderForm.state.value = "";      //Reset all our Hidden Input Field Variables
document.OrderForm.accum.value = "";
document.OrderForm.SearchLevel.value = "Year";   //Set the Search Level to Year
document.OrderForm.accumText.value ="";
document.OrderForm.RtnText.value = "";
document.OrderForm.RtnCode.value = "";
document.OrderForm.YrMkMd.value = "";
PartsInfoCell.innerHTML = "";          //Reset or Dynamic Field that holds Part Info
document.OrderForm.QAMake.options[0].selected = true;
document.OrderForm.QAModel.options[0].selected = true;

var counter = document.OrderForm.QAYear.options.length;

for(var i = 1; i<counter; i++)
   document.OrderForm.QAYear.options[i]=null;

document.OrderForm.QAYear.options[0].selected = true

counter = document.OrderForm.QAMake.options.length;

for(var i = 1; i<counter; i++)
   document.OrderForm.QAMake.options[i]=null;

counter = document.OrderForm.QAModel.options.length;

for(var i = 1; i<counter; i++)
   document.OrderForm.QAModel.options[i]=null;

while(document.OrderForm.PartBox.options[0] != null) //While things exist on the list
              {
                      document.OrderForm.PartBox.options[0] = null; //Delete them
              }
getQA(document.OrderForm.accum.value); //Get the Base level choices for the selected part category
}

/**********************************************************************************/
/*               Electronic Catalog Order Confirmation Function                   */
/* This function called to confirm the placement of an order via an Alert Box.    */
/* If yes is pressed, it places the order. This function is called internally in  */
/* the XSL Stylesheet style-partinfo.xsl                                          */
/* or category change.                                                            */
/*  Input:                                                                        */
/*        PartID  : Part ID to be Ordered.                                        */
/*  Output:                                                                       */
/*        NONE                                                                    */
/*                                                                                */
/**********************************************************************************/

function OrderConfirmation(PartID)
{
   if (confirm("Order Part Number: "+PartID+"\r\nQuantity : 1?"))  //If statement dependent on confirmation dialog box
      PlaceOrder(PartID,"1","test","test"); //Place the order
}

/**********************************************************************************/
/*              Javascript WebService PlaceOrder Consumption Function             */
/* The below function is called directly from an OnClick or OnChange call in a    */
/* HTML document. The structure of the internal call is as follows: You make a    */
/* call to your defined behavior name, which in this case is myWebService.        */
/* We then reference the alias we defined the web service as in this case:        */
/* OrderService. The webservice behavior contains the member function callService */
/* The callService function takes these params in the below listed order:         */
/*        callService Params:                                                     */
/*                   Javascript Function to call on Result,                       */
/*                   WebMethod to call in the selected WebService,                */
/*                   Parameter 1 to pass to the selected WebService,              */
/*                   Parameter 2 to pass to the selected WebService,              */
/*                   Parameter 3,                                                 */
/*                   This structure of variable passing continutes until          */
/*                   you run out of parameters to pass                            */
/*                                                                                */
/*  PlaceOrder Function Inputs:                                                   */
/*  Input:                                                                        */
/*       FullPartNo     : The Part Number to be ordered                           */
/*       Quant          : The Quantity of the part to order                       */
/*       PONumber       : The associated Purchase Order Number                    */
/*       AdditionalInfo : A string with additional order info                     */
/*  Output:                                                                       */
/*       This function has no output, but calls the OrderResult Function if it    */
/*       successfully connects and transmits data to the webservice               */
/*                                                                                */
/**********************************************************************************/

function PlaceOrder(FullPartNo,Quant,PONumber,AdditionalInfo)
{
     myWebService.OrderService.callService(OrderResult, "PlaceOrder",PlaceOrderKey,CustNumber,FullPartNo,Quant,PONumber,AdditionalInfo); //Take Our OrderService we previously mapped and call the Place Order Function sending its result to the OrderResult Function, also send the inputs listed.
}

/**********************************************************************************/
/*              Javascript WebService OrderResult Consumption Function            */
/* The below function is called by the PlaceOrder javascript function above when  */
/* valid data is returned from the webmethod. The purpose of this function is to  */
/* confirm the placement of an order. This function confirms an order was placed  */
/* by displaying an Alert Box or by displaying an error if the order was not      */
/* successful.                                                                    */
/*                                                                                */
/*  Input:                                                                        */
/*          This Function Requires a return from the PlaceOrder Webmethod Call    */
/*          located in the PlaceOrder Javascript Function.                        */
/*  Output:                                                                       */
/*          NONE                                                                  */
/*                                                                                */
/**********************************************************************************/

function OrderResult(oResult)
{

if(oResult.value == "OK")    //If the PlaceOrder Result reports a success
  alert("ORDER SUCCESSFULLY PLACED"); //Alert the user to the success of the order
else
  alert(oResult.value); //Otherwise display the resulting error
}

/**********************************************************************************/
/*              Javascript WebService Trim Consumption Function                   */
/*                                                                                */
/*  This function very simply trims a string so it doesn't have any leading or    */
/*  tailing invalid characters.                                                   */
/*                                                                                */
/*  Input:                                                                        */
/*         String                                                                 */
/*  Output:                                                                       */
/*         Trimmed String                                                         */
/*                                                                                */
/**********************************************************************************/

function trim(sInString)
{
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

/**********************************************************************************/
/*           Javascript WebService categoryChange Consumption Function            */
/*                                                                                */
/*  This function is called when a user selects a new part category. It finds the */
/*  new category selection and resets the PartBox Search.                         */
/*                                                                                */
/*  Input:                                                                        */
/*        NONE                                                                    */
/*  Output:                                                                       */
/*         Visual Page Modification                                               */
/*                                                                                */
/**********************************************************************************/

function categoryChange()
{
	msgCat();
// for (var i=0; i < document.OrderForm.PartType.length; i++) //Go through the radio buttons
//   {
//   if (document.OrderForm.PartType[i].checked) //If we found one that was checked
//      {
//      document.OrderForm.category.value = document.OrderForm.PartType[i].value; //Set the Hidden Input Field Category equal to its value
//      }
//   }
 document.OrderForm.category.value ="001";
   document.OrderForm.state.value = "";      //Reset all our Hidden Input Field Variables
   document.OrderForm.accum.value = "";
   document.OrderForm.SearchLevel.value = "Part"; //Set the search level to part
   document.OrderForm.QAModel.disabled = true; //Set the QAModel Listbox enable property so the program thinks this is the first time we are entering it
   document.OrderForm.accumText.value ="";
   document.OrderForm.RtnText.value = "";
   document.OrderForm.RtnCode.value = "";
   PartsInfoCell.innerHTML = "";          //Reset or Dynamic Field that holds Part Info
   var Accum = "";
   getQA(Accum); //Get the Base level choices for the selected part category
}

/**********************************************************************************/
/*           Javascript WebService DisplayImage Consumption Function              */
/*                                                                                */
/*  This function is called when a user wants to look at a image for a part. It   */
/*  creates a new window of the image size and displays it to the user. It is     */
/*  called in the XSL Style Sheet.                                                */
/*                                                                                */
/*  Input:                                                                        */
/*        VenCode   : The Vendor Code for the Part                                */
/*        ImageName : The Name of the Part Image                                  *
/*  Output:                                                                       */
/*         Visual Page Modification                                               */
/*                                                                                */
/**********************************************************************************/

var image_1 = new Image()

function DisplayImage(VenCode,ImageName)
{

    //Define a new image
   if(ImageName != '') //If the Image name is not nothing
        image_1.src = "http://www.ekeystonemax.com/images/00/partimages/"+VenCode+"/"+ImageName; //Load the image
   else
        image_1.src = "http://www.ekeystonemax.com/images/00/00000/unavailableimage.gif"; //Load the image for parts that don't have an image

   image_1.onload = ImageLoaded;
}

function ImageLoaded()
{
      var picURL=image_1.src; //Load the source string into picURL
      newWindow=null;
      newWindow=window.open('','newWin','toolbar=no,alwaysRaised=true,width='+image_1.width+',height='+image_1.height); //Open a new browser window and set its properties
      newWindow.document.write('<html><head><title>Part Image<\/title><\/head><body background="'+picURL+'"><\/body><\/html>'); //Write HTML to the new window
      newWindow.resizeBy(image_1.width-newWindow.document.body.clientWidth,image_1.height-newWindow.document.body.clientHeight)
      newWindow.focus() //Give the new window focus
}


function msgCat( )
{

alert("We are processing your search.\nTo see all the product categories for your vehicle click OK.\nTo Drill Down from that category click on the item category\nPlease wait for search box to change.");
}  // msgCat

