home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 October / CHIP1002.ISO / exe / COMPUGUI.exe / whform.js < prev    next >
Encoding:
Text File  |  2002-04-23  |  5.1 KB  |  215 lines

  1. var gfunLookUp;
  2. var gbInputEnable;
  3. var gfunInit;
  4. var gstrFormName= "";
  5. var gbWithButton = false;
  6. var gsTitle="";
  7. var gsOverImage = "";
  8. var gsOutImage = "";
  9. var gsClickImage = "";
  10. var gsText = "";
  11. var gsBgColor = "#c0c0c0";
  12. var gsBgImage = "";
  13. var gbInImage = 0;
  14. var gbInputEnable = 0;
  15.  
  16. var goTitleFont=null;
  17. var goInputFont=null;
  18. var goNormalFont=null;
  19. var goHoverFont=null;
  20. var gnType=-1;
  21. var gbWhForm=false;
  22.  
  23. function setBackground(sBgImage)
  24. {
  25.     if (sBgImage != null && sBgImage.length > 0)
  26.         gsBgImage = sBgImage;
  27.  
  28.     if  (gsBgImage  && gsBgImage .length > 0)
  29.     {
  30.         document.body.background = gsBgImage ;
  31.     }
  32. }
  33.  
  34. function setBackgroundcolor(sBgColor)
  35. {
  36.     if (sBgColor != null && sBgColor.length > 0)
  37.         gsBgColor = sBgColor;
  38.  
  39.     if (gsBgColor&& gsBgColor.length > 0)
  40.     {
  41.         document.body.bgColor = gsBgColor;
  42.     }
  43. }
  44.  
  45. function setBtnType(sType)
  46. {
  47.     if (sType == "image")
  48.     {
  49.         gnType = 0;
  50.     }
  51.     else if (sType == "text")
  52.     {
  53.         gnType = 1;
  54.     }
  55. }
  56.  
  57. function setGoImage1(sImage1)
  58. {
  59.     gsOutImage = sImage1;
  60.     if (gsOutImage && gsOutImage.length > 0)
  61.         gbWithButton = true;
  62. }
  63.  
  64. function setGoImage2(sImage2)
  65. {
  66.     gsOverImage = sImage2;
  67.     if (gsOverImage && gsOverImage.length > 0)
  68.         gbWithButton = true;
  69. }
  70.  
  71. function setGoImage3(sImage3)
  72. {
  73.     gsClickImage = sImage3;
  74.     if (gsClickImage && gsClickImage.length > 0)
  75.         gbWithButton = true;
  76. }
  77.  
  78. function setGoText(sText)
  79. {
  80.     gsText = sText;
  81.     if (gsText.length > 0)
  82.         gbWithButton = true;
  83. }
  84.  
  85. function setFont(sType, sFontName, sFontSize, sFontColor, sFontStyle, sFontWeight, sFontDecoration)
  86. {
  87.     var vFont = new whFont(sFontName, sFontSize, sFontColor, sFontStyle, sFontWeight, sFontDecoration);
  88.     if (sType == "Title")
  89.     {
  90.         goTitleFont = vFont;
  91.         var vFont1 = new whFont(sFontName, sFontSize, "black", sFontStyle, sFontWeight, sFontDecoration);
  92.         goInputFont=vFont1;        
  93.     }
  94.     else if (sType == "Normal")
  95.         goNormalFont = vFont;
  96.     else if (sType == "Hover")
  97.         goHoverFont = vFont;
  98. }
  99.  
  100. function writeFormStyle()
  101. {
  102.     var sStyle = "<style type='text/css'>";
  103.     sStyle += "p.title {" + getFontStyle(goTitleFont) + "margin-top:0;margin-bottom:0}\n";
  104.     sStyle += ".inputfield {" + getFontStyle(goInputFont) +"width:100%; }\n";
  105.     sStyle+="A:link {"+getFontStyle(goNormalFont)+"}\n";
  106.     sStyle+="A:visited {"+getFontStyle(goNormalFont)+"}\n";
  107.     sStyle +="A:hover {"+getFontStyle(goHoverFont)+"}\n";
  108.     sStyle+=".clsFormBackground{\n";
  109.     if (gsBgImage)
  110.         sStyle+="border-top:"+gsBgColor+" 1px solid;}\n";
  111.     else
  112.         sStyle+="border-top:black 1px solid;}\n";
  113.  
  114.     sStyle += "</style>";
  115.     document.write(sStyle);
  116. }
  117.  
  118. function lookupKeyDown()
  119. {
  120.     if (gbInputEnable)
  121.     {
  122.         if (gbIE4)
  123.         {
  124.             if (event.keyCode == 13)    //Enter key
  125.                 gfunLookUp(true);
  126.             else
  127.                 gfunLookUp(false);
  128.         }            
  129.         else
  130.             gfunLookUp(false);
  131.     }
  132. }
  133.  
  134. function init()
  135. {
  136.     if (gfunInit)
  137.         gfunInit();
  138.     if (!window.Array)  return;
  139.         document.onkeyup = lookupKeyDown;
  140. }
  141.  
  142. function inputSubmit()
  143. {
  144.     if ((gbInputEnable && !gbIE4)|| gbInImage)
  145.         gfunLookUp(true);
  146. }
  147.  
  148. function inputEnable(bEnable)
  149. {
  150.     gbInputEnable = bEnable;
  151. }
  152.  
  153. function inImage(bImage)
  154. {
  155.     gbInImage = bImage;
  156. }
  157.  
  158. function getFormHTML()
  159. {
  160.     var sForm = "";
  161.     sForm += "<table class=\"clsFormBackground\" width=\"100%\" cellspacing=\"0\" cellpadding=\"5\" border=\"0\">";
  162.     sForm += "<form name=\"" + gstrFormName + "\" method=\"POST\" action=\"javascript:inputSubmit()\" style=\"width:100%\">";
  163.     sForm += "<tr>";
  164.     sForm += "<td>";
  165.     sForm += "<p class=title><nobr>" + gsTitle + "</nobr><br><table width=\"100%\"><tr valign=\"middle\"><td width=\"100%\"><input class=\"inputfield\" type=\"text\" name=\"keywordField\" onfocus=\"inputEnable(1);\" onblur=\"inputEnable(0);\"></td>";
  166.     if (gbWithButton && gnType >= 0)
  167.     {
  168.         sForm += "<td><a title=\"submit button\" href=\"javascript:void(0);\" onclick=\"" + gstrFormName + ".submit(); return false;\" onfocus=\"inImage(1);\" onblur=\"inImage(0);\" onmouseup=\"onMouseUp();\" onmousedown=\"onMouseDown();\" onmouseover=\"onMouseOver();\" onmouseout=\"onMouseOut();\">"
  169.         if (gnType == 0)
  170.         {
  171.             if (!gsText)
  172.                 gsText="Go";
  173.             sForm += "<img alt=\""+gsText+"\" id=\"go\" border=\"0\" src=\"" + gsOutImage + "\">";
  174.         }
  175.         else
  176.             sForm += gsText ;
  177.         sForm += "</a></td>";
  178.     }
  179.     sForm += "</tr></table></p></td></tr></form></table>";
  180.     return sForm;
  181. }
  182.  
  183. function onMouseOver()
  184. {
  185.     if (getElement("go") && gsOverImage)
  186.         getElement("go").src = gsOverImage;
  187. }
  188.  
  189. function onMouseDown()
  190. {
  191.     if (getElement("go") && gsClickImage)
  192.         getElement("go").src = gsClickImage;
  193. }
  194.  
  195. function onMouseUp()
  196. {
  197.     if (getElement("go") && gsOutImage)
  198.         getElement("go").src = gsOutImage;
  199. }
  200.  
  201. function onMouseOut()
  202. {
  203.     if (getElement("go") && gsOutImage)
  204.         getElement("go").src = gsOutImage;
  205. }
  206.  
  207. if (window.gbWhUtil&&window.gbWhVer&&window.gbWhProxy&&window.gbWhMsg)
  208. {
  209.     goTitleFont=new whFont("Arial", "9pt", "#000000", "normal", "normal", "none");
  210.     goNormalFont=new whFont("Arial", "9pt", "#000000", "normal", "normal", "none");
  211.     goHoverFont=new whFont("Arial", "9pt", "#000000", "normal", "normal", "underline");
  212.     gbWhForm=true;
  213. }
  214. else
  215.     document.location.reload();