home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 February / PCWorld_2003-02_cd.bin / Software / Topware / mbsa / mbsasetup.msi / Cabs.w22.cab / dropdown.js < prev    next >
Text File  |  2002-02-28  |  15KB  |  621 lines

  1.  
  2. var comboBoxArray = new Array();
  3. var IPcomboBoxArray = new Array();
  4.  
  5. function CreateComboBoxObject(strDropDownListID, strComboBoxName)
  6. {
  7.     this.Mycmb = document.all[strDropDownListID];
  8.     this.SetDefaultText                = SetDefaultText;
  9.     this.Mycmb.selectedIndex        = -1;
  10.     this.UseStateFunctions            = false;
  11.     this.Clear                        = Clear;
  12.     this.GetSelectedText            = GetSelectedText;
  13.     this.AlignTextBoxOverDropDown    = AlignTextBoxOverDropDown;
  14.     this.cbo_OnChange                = cbo_OnChange;
  15.     this.txt_OnBlur                    = txt_OnBlur; 
  16.     this.setDefaultIndex            = setDefaultIndex;
  17.     this.txt_OnKeyUp                = txt_OnKeyUp;
  18.     this.focus                        = focus;
  19.     //do lookup or not
  20.     this.LookupValues                = true;
  21.     this.SetAccessKey                = SetAccessKey;
  22.     //case sensitivity
  23.     this.LookupCaseInSensitive    = true;
  24.     //store the previous text for the lookup
  25.     this.MytxtPreviousValue            = "";
  26.     //generate the text box on the fly
  27.     
  28.     var strMytxtID = "txtMytxt" + strDropDownListID;
  29.  
  30.     var strMytxt = "<INPUT type='text' id=" + strMytxtID + " name=" + strMytxtID + " onblur='" + strComboBoxName + ".txt_OnBlur()' " + 
  31.                        " onkeyup='" + strComboBoxName + ".txt_OnKeyUp()' " +
  32.                        " style='display: none; position: absolute' value='' >";
  33.  
  34.     this.Mycmb.insertAdjacentHTML("afterEnd", strMytxt);
  35.     //assign obj to new textbox
  36.     this.Mytxt = document.all[strMytxtID];
  37.  
  38.     var strMyHiddentxtID = strDropDownListID + "_value";
  39.     
  40.     var strMyHiddentxt = "<INPUT type='hidden' " + " id=" + strMyHiddentxtID + " name=" + strMyHiddentxtID + " >";
  41.  
  42.     this.Mycmb.insertAdjacentHTML("afterEnd", strMyHiddentxt);
  43.     this.MyHiddentxt = document.all[strMyHiddentxtID];
  44.  
  45.     this.AdjustingSize = false;
  46.     this.AlignTextBoxOverDropDown();
  47.  
  48.     comboBoxArray[comboBoxArray.length] = this;
  49. }
  50.  
  51. function SetAccessKey(Key)
  52. {
  53.     this.Mytxt.accessKey = Key;
  54. }
  55.  
  56. function CreateIPComboBoxObject(strDropDownListID, strComboBoxName)
  57. {
  58.     this.MyIPcmb = document.all[strDropDownListID];
  59.     this.MyIPcmb.selectedIndex        = -1;
  60.     this.UseStateFunctions        = false;
  61.     this.AlignIPCombo    = AlignIPCombo;
  62.     this.cboIP_OnChange                = cboIP_OnChange;
  63.     this.cboIPRange_OnChange                = cboIPRange_OnChange;
  64.     this.UseStateFunctions = false;
  65.     this.AdjustingSize = false;
  66.     this.IPAddressArrowUp = IPAddressArrowUp;
  67.     this.IPAddressArrowDown = IPAddressArrowDown;
  68.     this.IPRangeAddressArrowUp = IPRangeAddressArrowUp;
  69.     this.IPRangeAddressArrowDown = IPRangeAddressArrowDown;
  70.     this.AlignIPCombo();
  71.  
  72.     IPcomboBoxArray[IPcomboBoxArray.length] = this;
  73. }
  74.  
  75. function AlignIPCombos()
  76. {
  77.     var iIndex;
  78.     for (iIndex=0; iIndex < comboBoxArray.length; iIndex++)
  79.     {
  80.         IPcomboBoxArray[iIndex].AlignIPCombo();
  81.     }
  82. }
  83.  
  84. function AlignIPCombo()
  85. {    
  86.     if (!this.AdjustingSize)
  87.     {
  88.         this.AdjustingSize = true;
  89.         this.MyIPcmb.style.position="static";
  90.  
  91.         this.MyIPcmb.style.position    ="absolute";
  92.         this.MyIPcmb.style.posLeft    = GetAbsoluteXPosition(document.getElementById("IP1"))
  93.         this.MyIPcmb.style.posTop    = GetAbsoluteYPosition(document.getElementById("IP1"));
  94.         
  95.         if(document.all["IP1"].clientWidth >29)
  96.         {    
  97.             if(document.all["IP5"] != null && document.all["IP5"] != 'undefined')
  98.             {//must be an IP Range
  99.                 this.MyIPcmb.style.width = "405px";
  100.             }
  101.             else
  102.             {//single IP
  103.                 this.MyIPcmb.style.width = "190px";
  104.             }
  105.             var strClipRectangle = "rect(0 " + 
  106.                             (this.MyIPcmb.offsetWidth) + " " +
  107.                             this.MyIPcmb.offsetHeight + " " +
  108.                         (this.MyIPcmb.offsetWidth - 20) + ")";
  109.         }
  110.         else
  111.         {
  112.         var strClipRectangle = "rect(0 " + 
  113.                             (this.MyIPcmb.offsetWidth) + " " +
  114.                             this.MyIPcmb.offsetHeight + " " +
  115.                             (this.MyIPcmb.offsetWidth - 18 ) + ")";
  116.         }
  117.         this.MyIPcmb.style.clip = strClipRectangle;
  118.         this.AdjustingSize = false;
  119.     }
  120. }
  121.  
  122. function AlignTextBoxesOverDropDowns()
  123. {
  124.     var iIndex;
  125.     for (iIndex=0; iIndex < comboBoxArray.length; iIndex++)
  126.     {
  127.         comboBoxArray[iIndex].AlignTextBoxOverDropDown();
  128.     }
  129. }
  130.  
  131. //sets the default option
  132. function SetDefaultText(Text)
  133. {
  134.  
  135.     this.Mycmb.selectedIndex = -1;
  136.     this.Mytxt.value = Text;
  137. }
  138.  
  139.  
  140. //Move the textbox over the Combo
  141. function AlignTextBoxOverDropDown()
  142. {    
  143.     if (!this.AdjustingSize)
  144.     {
  145.         this.AdjustingSize = true;
  146.         this.Mytxt.style.display="none";
  147.         this.Mycmb.style.position="static";
  148.  
  149.         this.Mytxt.style.posLeft    = GetAbsoluteXPosition(this.Mycmb);
  150.         this.Mytxt.style.posTop        = GetAbsoluteYPosition(this.Mycmb) + 1;
  151.         this.Mytxt.style.posWidth    = this.Mycmb.offsetWidth - 16;  // 16 THIS IS THE WIDTH OF THE DROP DOWN ARROW
  152.         this.Mytxt.style.posHeight    = this.Mycmb.offsetHeight;
  153.  
  154.         this.Mycmb.style.position    ="absolute";
  155.         this.Mycmb.style.posLeft    = this.Mytxt.style.posLeft;
  156.         this.Mycmb.style.posTop    = this.Mytxt.style.posTop;
  157.         
  158.         this.ComboWidth = this.Mycmb.offsetWidth;
  159.         var strClipRectangle = "rect(0 " + 
  160.                             (this.Mycmb.offsetWidth) + " " +
  161.                             this.Mycmb.offsetHeight + " " +
  162.                             (this.Mytxt.style.posWidth -5 ) + ")";
  163.  
  164.         this.Mycmb.style.clip = strClipRectangle;
  165.         this.Mytxt.style.display="";
  166.         this.AdjustingSize = false;
  167.     }
  168.  
  169. }
  170.  
  171. function Clear()
  172. {
  173.     this.Mytxt.value = "";
  174.     this.Mycmb.selectedIndex = -1;
  175. }
  176.  
  177. function GetAbsoluteXPosition(element)
  178. {
  179.     var pos = 0;
  180.     while (element != null)
  181.     {
  182.         pos += element.offsetLeft;
  183.         element = element.offsetParent;
  184.     }
  185.  
  186.     return pos;
  187. }
  188.  
  189. function GetAbsoluteYPosition(element)
  190. {
  191.     var pos = 0;
  192.  
  193.     while (element != null )
  194.     {
  195.         pos += element.offsetTop;
  196.         element = element.offsetParent;
  197.     }
  198.  
  199.     return pos;
  200. }
  201.  
  202. function GetSelectedText()
  203. {
  204.     return this.Mytxt.value;
  205. }
  206.  
  207. function cboIP_OnChange()
  208. {
  209.     var tmpIndex = this.MyIPcmb.selectedIndex;
  210.     var tempOption = this.MyIPcmb.options[tmpIndex];
  211.     
  212.     var IPArr = tempOption.text.split(".")
  213.     document.all["IP1"].value = IPArr["0"];
  214.     document.all["IP2"].value = IPArr["1"];
  215.     document.all["IP3"].value = IPArr["2"];
  216.     document.all["IP4"].value = IPArr["3"];
  217.     
  218.     this.MyIPcmb.selectedIndex=-1;
  219.     if(this.UseStateFunctions) 
  220.     {
  221.         SetState("IP");
  222.     }
  223. }
  224.  
  225. function cboIPRange_OnChange()
  226. {
  227.     var tmpIndex = this.MyIPcmb.selectedIndex;
  228.     var tempOption = this.MyIPcmb.options[tmpIndex];
  229.  
  230.     var IPArr = tempOption.text.split("to")
  231.     var IP1 = IPArr["0"].split(".");
  232.     var IP2 = IPArr["1"].split(".");
  233.     
  234.     document.all["IP1"].value = IP1["0"];
  235.     document.all["IP2"].value = IP1["1"];
  236.     document.all["IP3"].value = IP1["2"];
  237.     document.all["IP4"].value = IP1["3"].substring(0,IP1["3"].length-1);
  238.     document.all["IP5"].value = IP2["0"].substring(1,IP2["0"].length);
  239.     document.all["IP6"].value = IP2["1"];
  240.     document.all["IP7"].value = IP2["2"];
  241.     document.all["IP8"].value = IP2["3"];
  242.     
  243.     if(this.UseStateFunctions) 
  244.     {
  245.         SetState("IP");
  246.     }
  247.     this.MyIPcmb.selectedIndex=-1;
  248. }
  249.  
  250. function cbo_OnChange()
  251. {
  252.     var tmpIndex = this.Mycmb.selectedIndex;
  253.     var tempOption = this.Mycmb.options[tmpIndex];
  254.     this.Mytxt.value  = tempOption.text;
  255.     
  256.     this.Mytxt.focus();
  257.     this.Mytxt.select();
  258.     
  259.     if(this.UseStateFunctions) 
  260.     {
  261.         SetState("CPU");
  262.     }
  263.     this.Mycmb.selectedIndex=-1;
  264. }
  265.  
  266. function txt_OnKeyUp()
  267. {        
  268.     if (this.LookupValues)
  269.     {
  270.         if (event.keyCode < 32)  
  271.         {
  272.             return;
  273.         }
  274.         else if (event.keyCode == 46)  
  275.         {
  276.             return;
  277.         }
  278.         else if (event.keyCode == 38)//up arrow  
  279.         {
  280.             var len = this.Mycmb.options.length;
  281.             if(len > 0)
  282.             {
  283.                 var tempString;
  284.                 var curText        = this.Mytxt.value;
  285.                 var FoundIndex = -1;
  286.                 for (var iIndex=0; iIndex<len; iIndex++)
  287.                 {
  288.                     tempString = this.Mycmb.options(iIndex).text;
  289.                     
  290.                     tempString = tempString.toUpperCase();
  291.                     curText = curText.toUpperCase();
  292.                     if (tempString == curText)
  293.                     {
  294.                         FoundIndex = iIndex;
  295.                     }
  296.                 }
  297.                 if(FoundIndex == -1)
  298.                 {
  299.                     //do nothing
  300.                 }
  301.                 else
  302.                 {
  303.                     if(FoundIndex > 0)
  304.                     {
  305.                         this.Mytxt.value = this.Mycmb.options(FoundIndex -1).text;
  306.                         var tmpRange = this.Mytxt.createTextRange();
  307.                         tmpRange.moveStart("character", this.Mytxt.length);
  308.                         tmpRange.select();
  309.                         SetState("CPU");
  310.                     }
  311.                 }
  312.             }            
  313.             return;
  314.         }
  315.         else if (event.keyCode == 40)//Down arrow  
  316.         {
  317.             var len = this.Mycmb.options.length;
  318.             if(len > 0)
  319.             {
  320.                 var tempString;
  321.                 var curText        = this.Mytxt.value;
  322.                 var FoundIndex = -1;
  323.             
  324.                 for (var iIndex=0; iIndex<len; iIndex++)
  325.                 {
  326.                     
  327.                     tempString = this.Mycmb.options(iIndex).text;    
  328.                     tempString = tempString.toUpperCase();
  329.                     curText = curText.toUpperCase();
  330.                     if (tempString == curText)
  331.                     {
  332.                         FoundIndex = iIndex;
  333.                     }
  334.                 }
  335.                 if(FoundIndex == -1)
  336.                 {
  337.                     this.Mytxt.value = this.Mycmb.options(0).text;
  338.                     var tmpRange = this.Mytxt.createTextRange();
  339.                     tmpRange.moveStart("character", this.Mytxt.length);
  340.                     tmpRange.select();
  341.                     SetState("CPU");
  342.                 }
  343.                 else
  344.                 {    
  345.                     if(FoundIndex < this.Mycmb.options.length - 1)
  346.                     {
  347.                         this.Mytxt.value = this.Mycmb.options(FoundIndex + 1).text;
  348.                         var tmpRange = this.Mytxt.createTextRange();
  349.                         tmpRange.moveStart("character", this.Mytxt.length);
  350.                         tmpRange.select();
  351.                         SetState("CPU");
  352.                     }
  353.                 }
  354.             }
  355.             return;
  356.         }
  357.         if(this.UseStateFunctions) 
  358.         {
  359.             SetState("CPU");
  360.         }
  361.         var curText        = this.Mytxt.value;
  362.         var prevText    = this.MytxtPreviousValue;
  363.         var iIndex;
  364.  
  365.         if ((curText == "")    || (curText == prevText))
  366.         {
  367.             this.MytxtPreviousValue = curText;
  368.             return;
  369.         }
  370.  
  371.         var len = this.Mycmb.options.length;
  372.         var tempString;
  373.         
  374.         for (iIndex=0; iIndex<len; iIndex++)
  375.         {
  376.             tempString = this.Mycmb.options(iIndex).text;
  377.  
  378.             if (this.LookupCaseInSensitive)
  379.             {
  380.                 tempString = tempString.toUpperCase();
  381.                 curText = curText.toUpperCase();
  382.             }
  383.  
  384.             if (tempString.indexOf(curText) == 0)
  385.             {
  386.                 var helperString = this.Mycmb.options(iIndex).text;
  387.  
  388.                 this.Mytxt.value = this.Mytxt.value + helperString.substr(curText.length);
  389.                 this.Mycmb.selectedIndex = iIndex;
  390.                 this.MytxtPreviousValue = this.Mytxt.value;
  391.  
  392.                 var tmpRange = this.Mytxt.createTextRange();
  393.                 tmpRange.moveStart("character", curText.length);
  394.                 tmpRange.select();
  395.                 return;
  396.             }
  397.         }
  398.     }
  399. }
  400.  
  401. function txt_OnBlur()
  402. {
  403.     var myDropDownList    = this.Mycmb;
  404.     var myEditCell        = this.Mytxt;
  405.     var myHiddenCell    = this.MyHiddentxt;
  406.     var iIndex;
  407.     
  408.     myHiddenCell.value = myEditCell.value;
  409.     myDropDownList.selectedIndex = -1;
  410.  
  411.     if (myEditCell.value == "")
  412.     {
  413.         return;
  414.     }
  415.  
  416.     var len = myDropDownList.options.length;
  417.     for (iIndex=0; iIndex<len; iIndex++)
  418.     {
  419.         var str1 = myDropDownList.options(iIndex).text;
  420.         var str2 = myEditCell.value;
  421.  
  422.         if (this.LookupCaseInSensitive)
  423.         {
  424.             str1 = str1.toUpperCase();
  425.             str2 = str2.toUpperCase();
  426.         }
  427.         
  428.         if (str1 == str2)
  429.         {
  430.             myDropDownList.selectedIndex = iIndex;
  431.             myHiddenCell.value = myDropDownList.options(iIndex).value;
  432.             return;
  433.         }
  434.     }
  435.  
  436.     if (this._bOnlyAllowedEntries)
  437.     {
  438.         myDropDownList.focus();    
  439.  
  440.         alert("'" + myEditCell.value + "' is not allowed");
  441.         this.Mycmb.selectedIndex = -1;
  442.         this.Mytxt.select();
  443.         
  444.         return;
  445.     }
  446. }
  447.  
  448. function focus()
  449. {
  450.     this.Mycmb.focus();
  451. }
  452.  
  453. function setDefaultIndex(iIndex)
  454. {
  455.     var len = this.Mycmb.options.length;
  456.     if ((iIndex >=0) && (iIndex < len))
  457.     {
  458.         this.Mycmb.selectedIndex = iIndex;
  459.         this.Mytxt.value = this.Mycmb.options(iIndex).text;
  460.         this.MyHiddentxt.value = this.Mycmb.options(iIndex).value;
  461.         return;
  462.     }
  463.  
  464.     this.Mytxt.value = "";
  465. }
  466.  
  467. function IPAddressArrowUp(curText)
  468. {
  469.     var len = this.MyIPcmb.options.length;
  470.     if(len > 0)
  471.     {
  472.         var tempString;
  473.         var FoundIndex = -1;
  474.         var NewValue = "";
  475.         for (var iIndex=0; iIndex<len; iIndex++)
  476.         {
  477.             tempString = this.MyIPcmb.options(iIndex).text;
  478.             if (tempString.toString() == curText.toString())
  479.             {
  480.                 FoundIndex = iIndex;
  481.             }
  482.         }
  483.         if(FoundIndex == -1)
  484.         {
  485.             //do nothing
  486.             NewValue = curText;
  487.         }
  488.         else
  489.         {
  490.             if(FoundIndex > 0)
  491.             {
  492.                 NewValue = this.MyIPcmb.options(FoundIndex -1).text;
  493.             }
  494.         }
  495.         return NewValue;
  496.     }
  497.     else
  498.         return "";
  499. }
  500. function IPAddressArrowDown(curText)
  501. {
  502.     var len = this.MyIPcmb.options.length;
  503.     if(len > 0)
  504.     {
  505.         var tempString;
  506.         var NewValue = "";
  507.         var FoundIndex = -1;
  508.         for (var iIndex=0; iIndex<len; iIndex++)
  509.         {
  510.             tempString = this.MyIPcmb.options(iIndex).text;
  511.  
  512.             if (tempString.toString() == curText.toString())
  513.             {
  514.                 FoundIndex = iIndex;
  515.             }
  516.         }
  517.         if(FoundIndex == -1)
  518.         {
  519.             NewValue = this.MyIPcmb.options(0).text;
  520.         }
  521.         else
  522.         {
  523.             if(FoundIndex < this.MyIPcmb.options.length - 1)
  524.             {
  525.                 NewValue = this.MyIPcmb.options(FoundIndex + 1).text;
  526.             }
  527.         }
  528.  
  529.         return NewValue;
  530.     }
  531.     else
  532.         return "";
  533. }
  534.  
  535. function IPRangeAddressArrowUp(curText)
  536. {
  537.     var len = this.MyIPcmb.options.length;
  538.     
  539.     if(len > 0)
  540.     {
  541.         var curIPArr = curText.split("to");
  542.         var curIP1 = curIPArr["0"].substring(0,curIPArr["0"].length -1);
  543.         var curIP2 = curIPArr["1"].substring(1,curIPArr["1"].length -1);
  544.     
  545.         var tempString;
  546.         var FoundIndex = -1;
  547.         var NewValue = "";
  548.         for (var iIndex=0; iIndex<len; iIndex++)
  549.         {
  550.             tempString = this.MyIPcmb.options(iIndex).text;
  551.             
  552.             var IPArr = tempString.split("to");
  553.             var IP1 = IPArr["0"].substring(0,IPArr["0"].length -1);
  554.             var IP2 = IPArr["1"].substring(1,IPArr["1"].length -1);
  555.             if (curIP1.toString() == IP1.toString() && curIP2.toString() == IP2.toString())
  556.             {
  557.                 FoundIndex = iIndex;
  558.             }
  559.         }
  560.         if(FoundIndex == -1)
  561.         {
  562.             //do nothing
  563.             NewValue = curText;
  564.         }
  565.         else
  566.         {
  567.             if(FoundIndex > 0)
  568.             {
  569.                 NewValue = this.MyIPcmb.options(FoundIndex -1).text;
  570.             }
  571.         }
  572.         return NewValue;
  573.     }
  574.     else
  575.         return "";
  576. }
  577.  
  578. function IPRangeAddressArrowDown(curText)
  579. {
  580.     var len = this.MyIPcmb.options.length;
  581.     
  582.     if(len > 0)
  583.     {
  584.         var curIPArr = curText.split("to");
  585.         var curIP1 = curIPArr["0"].substring(0,curIPArr["0"].length -1);
  586.         var curIP2 = curIPArr["1"].substring(1,curIPArr["1"].length -1);
  587.     
  588.         var tempString;
  589.         var FoundIndex = -1;
  590.         var NewValue = "";
  591.         for (var iIndex=0; iIndex<len; iIndex++)
  592.         {
  593.             tempString = this.MyIPcmb.options(iIndex).text;
  594.             
  595.             var IPArr = tempString.split("to");
  596.             var IP1 = IPArr["0"].substring(0,IPArr["0"].length -1);
  597.             var IP2 = IPArr["1"].substring(1,IPArr["1"].length -1);
  598.             if (curIP1.toString() == IP1.toString() && curIP2.toString() == IP2.toString())
  599.             {
  600.                 FoundIndex = iIndex;
  601.             }
  602.         }
  603.         if(FoundIndex == -1)
  604.         {
  605.             //do nothing
  606.             NewValue = curText;
  607.         }
  608.         else
  609.         {
  610.             if(FoundIndex < this.MyIPcmb.options.length - 1)
  611.             {
  612.                 NewValue = this.MyIPcmb.options(FoundIndex + 1).text;
  613.             }
  614.         }
  615.         return NewValue;
  616.     }
  617.     else
  618.         return "";
  619.     
  620. }
  621.