﻿//BeltLookup.js
//Last modified:1/9/09
//Site: www.Intralox.com
//
//var _selecttext=$("#Style option:first").text();
    function ajaxLoadSeries()
    {
          
          var bt = '"belttype'+'":"'+$("#BeltType").val()+'"';
          bt += ',';
          bt += '"selecttext'+'":"'+$("#Series option:first").text()+'"';
          
          $.ajax({
          type: "POST",
          url: "../webservices/EvalFormBeltLookup.asmx/LoadBeltSeries",
          data: '{'+bt+'}',
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(msg) {
            // Replace the div's content with the page method's return.
            //$("#ajaxResponse").text(msg);
            $("#Series").html(msg.d);
            //$("#seldata").html(msg);
          },
          error:function(xhr,status,errorThrown) {
            // Replace the div's content with the page method's return.
            $("#ajaxResponse").text(xhr.Responsetext);
             $("#seldata").text(bt);
          }
        });
       
    }
    
    function getSelectedStyle()
    {
       var string="";        
        $("#Series option:selected").each(
            function ()
            {
             string += '"series'+'":"'+$(this).text()+'"';
             string +=',';   
            }
            );
        $("#Style option:selected").each(
            function ()
            {
             string += '"style'+'":"'+$(this).text()+'"';
             //string +=$(this).text()+" ";   
            }
            );
        //$("#seldata").append(string);
        return string; 
    }
    function getSelectedSeries()
    {
        var string="";        
        $("#Series option:selected").each(
            function ()
            {
             string += '"series'+'":"'+$(this).text()+'"';
             //string +=$(this).text()+" ";
             //string += ",";
             //string += '"selecttext'+'":"'+$("#Series option:first").text()+'"';
            }
            );
        //$("#seldata").append(string);
        return string;
    }
    function ajaxGetStyle(txt)
    {
         
        
        var series = txt;                        
        
        txt +=",";
        txt += '"selecttext'+'":"'+$("#Style option:first").text()+'"';
        $.ajax(
        {
          type: "POST",
          url: "../webservices/EvalFormBeltLookup.asmx/LoadBeltStyle",
          data: '{'+txt+'}',
          
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(msg) {
            // Replace the div's content with the page method's return.
            //$("#ajaxResponse").text(msg);
            $("#Style").html(msg.d);
            //$("#sel1").append(msg);
          },
          error:function(xhr,status,errorThrown) {
            // Replace the div's content with the page method's return.
            $("#ajaxResponse").text(xhr.responseText);
            $("#ajaxResponse").append("************************");
          }   
        });
     
    }
    function ajaxGetMaterial(txt)
    {
        var series = txt;                        
        txt +=",";
        txt += '"selecttext'+'":"'+$("#Material option:first").text()+'"';

       
        $.ajax(
        {
          type: "POST",
          url: "../webservices/EvalFormBeltLookup.asmx/LoadBeltMaterial",
          data: '{'+txt+'}',
          //data: '{}',
          
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(msg) {
            // Replace the div's content with the page method's return.
            //$("#ajaxResponse").text(msg);
            
            $("#Material").html(msg.d);
            //$("#sel1").append(msg);
          },
          error:function(xhr,status,errorThrown) {
            // Replace the div's content with the page method's return.
            $("#ajaxResponse").text(xhr.responseText);
          }   
        });
    }
    
    $(document).ready(function()
    {
      ajaxLoadSeries();
      $("#Style").attr("disabled","true");
      $("#Material").attr("disabled","true");
      //hide loading images
      $("#aj").hide();
      $("#aj2").hide();
      
      $("#Series").change(function ()
      {
      var selectedi = getSelectedSeries();
      
        $("#aj").show();
        $("#Style").removeAttr("disabled");
        ajaxGetStyle(getSelectedSeries());
        $("#Material").attr("disabled","true");
        $("#aj").hide();
       
       // ajaxGetStyle('{series:100}');
      });
      $("#Style").change(function()
      {
        $("#aj2").show();
        $("#Material").removeAttr("disabled");
        //ajaxGetMaterial(getSelectedStyle());
        $("#aj2").hide();
      });
      

         });  
   

