PageRenderTime 91ms CodeModel.GetById 16ms app.highlight 67ms RepoModel.GetById 1ms app.codeStats 0ms

/aspnet_client/system_web/2_0_50727/CrystalReportWebFormViewer3/js/prompts_param.js

http://github.com/khaneh/Orders
JavaScript | 1103 lines | 892 code | 125 blank | 86 comment | 431 complexity | b7cddc04b169463fdb361a95c64e6963 MD5 | raw file
   1
   2//////////////////////////////
   3// FOR DEBUGGING ONLY
   4var debug = false;
   5function dumpFormFields(formName)
   6{
   7    theForm = document.forms[formName];
   8    for ( idx = 0; idx < theForm.elements.length; ++idx )
   9        alert ( theForm.elements[idx].name + " - " + theForm.elements[idx].value );
  10}
  11
  12//////////////////////////////
  13// GLOBAL VAR
  14var needURLEncode = false;  // only need to do url encode in java
  15var promptPrefix = "promptex-";
  16var CR_NULL = "_crNULL_";
  17var CR_USE_VALUE = "_crUseValue_";
  18
  19var _bver    = parseInt(navigator.appVersion);
  20var Nav4     = ((navigator.appName == "Netscape") && _bver==4);
  21var Nav4plus = ((navigator.appName == "Netscape") && _bver >= 4);
  22var IE4plus  = ((navigator.userAgent.indexOf("MSIE") != -1) && _bver>4);
  23
  24if (Nav4plus)
  25    var userLanguage = (navigator.language.substr(0, 2));
  26else
  27    var userLanguage = (navigator.browserLanguage.substr(0, 2));
  28
  29///////////////////////////////
  30// substitue range string
  31function ConstructRangeDisplayString(rangeStr, param0, param1)
  32{
  33        var newString = rangeStr.replace("{0}", param0);
  34        newString = newString.replace("{1}", param1);
  35        return newString;
  36}
  37
  38///////////////////////////////
  39// Display string for range value in ListBox
  40function GetRangeValueDisplayText(rangeStr, param0, param1, paramType)
  41{
  42        if (paramType == "dt" || paramType == "d" || paramType == "t")
  43        {
  44                if (param0.length != 0)
  45                {
  46                        param0 = NeutralDT2D(param0);
  47                }
  48
  49                if (param1.length != 0)
  50                {
  51                        param1 = NeutralDT2D(param1);
  52                }
  53        }
  54
  55        return ConstructRangeDisplayString(rangeStr, param0, param1);
  56}
  57
  58///////////////////////////////
  59// properly encode prompt values
  60function encodePrompt (prompt)
  61{
  62    if (needURLEncode)
  63    {
  64        return encodeURIComponent(prompt);
  65    }
  66    else
  67    {
  68        return prompt;
  69    }
  70}
  71
  72function clickSetNullCheckBox(inForm, paramName, suffix)
  73{
  74    var nullCtrl = inForm[paramName + "NULL"];
  75    var textCtrl = inForm[paramName + suffix];
  76    var hiddenCtrl = inForm[paramName + suffix + "Hidden"];
  77    var hourCtrl = inForm[paramName + suffix + "Hour"];
  78    var minuteCtrl = inForm[paramName + suffix + "Minute"];
  79    var secondCtrl = inForm[paramName + suffix + "Second"];
  80    var ampmCtrl = inForm[paramName + suffix + "AMPM"];
  81    if (nullCtrl.checked)
  82    {
  83        if (textCtrl != null) textCtrl.disabled = true;
  84        if (hourCtrl != null) hourCtrl.disabled = true;
  85        if (minuteCtrl != null) minuteCtrl.disabled = true;
  86        if (secondCtrl != null) secondCtrl.disabled = true;
  87        if (ampmCtrl != null) ampmCtrl.disabled = true;
  88    }
  89    else
  90    {
  91        if (textCtrl != null) textCtrl.disabled = false;
  92        if (hourCtrl != null) hourCtrl.disabled = false;
  93        if (minuteCtrl != null) minuteCtrl.disabled = false;
  94        if (secondCtrl != null) secondCtrl.disabled = false;
  95        if (ampmCtrl != null) ampmCtrl.disabled = false;
  96        
  97    }
  98}
  99
 100function ClearListBoxAndSetNULL(theList)
 101{
 102    // delete everything in the listbox, add _crNULL_ as an item
 103    promptEntry = new Option(L_NoValue, CR_NULL,false,false);
 104    for ( var idx = 0; idx < theList.options.length; )
 105    {
 106        theList.options[0] = null;
 107        idx++;
 108    }
 109
 110    theList.options[0] = promptEntry;
 111    return;
 112}
 113
 114////////////////////////////////
 115// add number, currency, string from dropdown/textbox to list box
 116// where multiple prompt values are supported
 117function DateTimePromptValueHelper(type, hiddenCtrl, hourCtrl, minuteCtrl, secondCtrl, ampmCtrl)
 118{
 119    var promptValue = "";
 120
 121    var year;
 122    var month;
 123    var day;
 124    if ((type == "dt") || (type == "d"))
 125    {
 126        var d = hiddenCtrl.value;
 127        if (d.length == 0)
 128        {
 129          alert(L_NoDateEntered);
 130          return "";
 131        }
 132        var leftIndex = d.indexOf("(");
 133        var rightIndex = d.indexOf(")");
 134        d = d.substr(leftIndex + 1, rightIndex - leftIndex - 1);
 135        var dArray = d.split(",");
 136        year = dArray[0];
 137        month = dArray[1];
 138        day = dArray[2];
 139    }
 140
 141    if (type == "dt")
 142    {
 143        promptValue = "DateTime(";
 144        promptValue += year;
 145        promptValue += ",";
 146        promptValue += month;
 147        promptValue += ",";
 148        promptValue += day;
 149        promptValue += ",";
 150
 151        var hour = 0;
 152        if (ampmCtrl != undefined)
 153        {
 154            var i = 0;
 155            if (ampmCtrl.selectedIndex == 1)
 156                i = 1;
 157            hour = hourCtrl.selectedIndex + 1 + i * 12;
 158            if (hour == 12) hour = 0;
 159            else if (hour == 24) hour = 12;
 160        }
 161        else
 162        {
 163            hour = hourCtrl.selectedIndex;
 164        }
 165            
 166        promptValue += hour;
 167        promptValue += ",";
 168        promptValue += minuteCtrl.selectedIndex;
 169        promptValue += ",";
 170        promptValue += secondCtrl.selectedIndex;
 171
 172        promptValue += ")";
 173    }
 174    else if (type == "d")
 175    {
 176        promptValue = "Date(";
 177        promptValue += year;
 178        promptValue += ",";
 179        promptValue += month;
 180        promptValue += ",";
 181        promptValue += day;
 182        promptValue += ")";
 183        
 184    }
 185    else if (type == "t")
 186    {
 187        promptValue = "Time(" 
 188
 189        var hour = 0;
 190        if (ampmCtrl != undefined)
 191        {
 192            var i = 0;
 193            if (ampmCtrl.selectedIndex == 1)
 194                i = 1;
 195            hour = hourCtrl.selectedIndex + 1 + i * 12;
 196            if (hour == 12) hour = 0;
 197            else if (hour == 24) hour = 12;
 198        }
 199        else
 200        {
 201            hour = hourCtrl.selectedIndex;
 202        }
 203       
 204            
 205        promptValue += hour;
 206        promptValue += ",";
 207        promptValue += minuteCtrl.selectedIndex;
 208        promptValue += ",";
 209        promptValue += secondCtrl.selectedIndex;
 210        promptValue += ")";
 211    }
 212
 213    return promptValue;
 214}
 215
 216
 217function DateTimeDisplayStringHelper(type, hiddenCtrl, hourCtrl, minuteCtrl, secondCtrl, ampmCtrl)
 218{
 219    var neutralstring = DateTimePromptValueHelper(type, hiddenCtrl, hourCtrl, minuteCtrl, secondCtrl, ampmCtrl);
 220    return NeutralDT2D(neutralstring);
 221}
 222
 223
 224function addPromptDiscreteValueHelper(inForm, type, paramName, suffix)
 225{
 226    theList = inForm[paramName + "ListBox"];
 227
 228    // if there is a NULL checkbox and it is set
 229    if ( inForm[paramName + "NULL"] != null && inForm[paramName + "NULL"].checked )
 230    {
 231        // delete everything in the listbox, add _crNULL_ as an item
 232        ClearListBoxAndSetNULL(theList);
 233        return;
 234    }
 235
 236    // if the listbox already has a NULL value in it, don't do anything, unless user removes NULl value from the listbox
 237    if (theList.options.length > 0 && theList.options[0].value == CR_NULL)
 238    {
 239        alert(L_NoValueAlready);
 240        return;
 241    }
 242
 243    // if defaultdropdownlist selected item is _crNULL_, put it into multiple listbox
 244    var dropDownListName = "";
 245    if (suffix == "DiscreteValue")
 246        dropDownListName = paramName + "SelectValue";
 247    else
 248        dropDownListName = paramName + "SelectLowerBound";
 249    var dropDownListCtrl = inForm[dropDownListName];
 250    if (dropDownListCtrl != null)
 251    {
 252        if (dropDownListCtrl.options[dropDownListCtrl.selectedIndex].value  == CR_NULL)
 253        {
 254            // delete everything in the listbox, add _crNULL_ as an item
 255            ClearListBoxAndSetNULL(theList);
 256            return;
 257        }
 258    }
 259    
 260    var textCtrl = inForm[paramName + suffix];
 261    var hiddenCtrl = inForm[paramName + suffix + "Hidden"];
 262    var hourCtrl = inForm[paramName + suffix + "Hour"];
 263    var minuteCtrl = inForm[paramName + suffix + "Minute"];
 264    var secondCtrl = inForm[paramName + suffix + "Second"];
 265    var ampmCtrl = inForm[paramName + suffix + "AMPM"];
 266
 267    var obj;
 268    var editables = true;
 269
 270    if (textCtrl == undefined && hourCtrl == undefined)
 271    {
 272        //select box not a textbox, hour, minute, and second, ampm dropdown are not there either
 273        editables = false;
 274        obj = dropDownListCtrl;
 275        obj = obj.options[obj.selectedIndex];
 276    }
 277    else
 278    {
 279        if (type == "t")
 280            obj = hourCtrl;
 281        else
 282            obj = textCtrl;
 283    }
 284
 285    if (editables && (type == "dt" || type == "d" || type == "t"))
 286    {   
 287        promptValue = DateTimePromptValueHelper(type, hiddenCtrl, hourCtrl, minuteCtrl, secondCtrl, ampmCtrl);
 288        if (promptValue.length == 0) return false;
 289        
 290        displayString = DateTimeDisplayStringHelper(type, hiddenCtrl, hourCtrl, minuteCtrl, secondCtrl, ampmCtrl);   
 291    }
 292    else
 293    {
 294        promptValue =  encodePrompt(obj.value);
 295        displayString = ( obj.text ) ? obj.text : obj.value;
 296    }
 297
 298    if ( ! checkSingleValue (promptValue, type ) )
 299    {
 300        return false;
 301    }
 302
 303    promptEntry = new Option(displayString,promptValue,false,false);
 304    theList.options[theList.length] = promptEntry;
 305}
 306
 307function addPromptDiscreteValue ( inForm, type , paramName)
 308{
 309    addPromptDiscreteValueHelper(inForm, type, paramName, "DiscreteValue");
 310}
 311
 312////////////////////////////////////
 313// adds Range prompt to listbox where multiple values are supported
 314function addPromptDiscreteRangeValue ( inForm, type , paramName )
 315{
 316    lowerOption = inForm[paramName + "SelectLowerOptions"];
 317
 318    // exactly
 319    if (lowerOption.selectedIndex == 1)
 320    {
 321        // add discrete
 322        addPromptDiscreteValueHelper(inForm, type, paramName, "LowerBound");
 323    }
 324    else
 325    {
 326       // add range
 327       addPromptRangeValue(inForm, type, paramName);
 328    }
 329}
 330
 331////////////////////////////////////
 332// adds Range prompt to listbox where multiple values are supported
 333function addPromptRangeValue ( inForm, type , paramName )
 334{
 335
 336    theList = inForm[paramName + "ListBox"];
 337
 338    // if there is a NULL checkbox and it is set
 339    if ( inForm[paramName + "NULL"] != null && inForm[paramName + "NULL"].checked )
 340    {
 341        // delete everything in the listbox, add _crNULL_ as an item
 342        ClearListBoxAndSetNULL(theList);
 343        return;
 344    }
 345
 346    // if the listbox already has a NULL value in it, don't do anything, unless user removed NULl value from the listbox
 347    if (theList.options.length > 0 && theList.options[0].value == CR_NULL)
 348    {
 349        alert(L_NoValueAlready);
 350        return;
 351    }
 352
 353    // if both defaultdropdownlists selected item is _crNULL_, put it into multiple listbox
 354    // if one of them is _crNULL_, it is not a valid option, do nothing
 355    var lowerDropDownListName = paramName + "SelectLowerBound";
 356    var upperDropDownListName = paramName + "SelectUpperBound";
 357    var lowerDropDownListCtrl = inForm[lowerDropDownListName];
 358    var upperDropDownListCtrl = inForm[upperDropDownListName];
 359    if (lowerDropDownListCtrl != null && upperDropDownListCtrl != null)
 360    {
 361        if (lowerDropDownListCtrl.options[lowerDropDownListCtrl.selectedIndex].value  == CR_NULL
 362            && upperDropDownListCtrl.options[upperDropDownListCtrl.selectedIndex].value  == CR_NULL)
 363        {
 364            // delete everything in the listbox, add _crNULL_ as an item
 365            ClearListBoxAndSetNULL(theList);
 366            return;
 367        }
 368        else if (lowerDropDownListCtrl.options[lowerDropDownListCtrl.selectedIndex].value  == CR_NULL
 369            || upperDropDownListCtrl.options[upperDropDownListCtrl.selectedIndex].value  == CR_NULL)
 370        {
 371           alert(L_BadValue);
 372           return;
 373        }
 374    }
 375
 376    lowerOption = inForm[paramName + "SelectLowerOptions"];
 377    upperOption = inForm[paramName + "SelectUpperOptions"];
 378
 379    lowerBound = inForm[paramName + "LowerBound"];
 380    upperBound = inForm[paramName + "UpperBound"];
 381
 382    lowerBoundHidden = inForm[paramName + "LowerBoundHidden"];
 383    upperBoundHidden = inForm[paramName + "UpperBoundHidden"];
 384
 385    var lhourCtrl = inForm[paramName+"LowerBound" + "Hour"];
 386    var lminuteCtrl = inForm[paramName + "LowerBound" + "Minute"];
 387    var lsecondCtrl = inForm[paramName + "LowerBound" + "Second"];
 388    var lampmCtrl = inForm[paramName + "LowerBound" + "AMPM"];
 389
 390    var uhourCtrl = inForm[paramName+"UpperBound" + "Hour"];
 391    var uminuteCtrl = inForm[paramName + "UpperBound" + "Minute"];
 392    var usecondCtrl = inForm[paramName + "UpperBound" + "Second"];
 393    var uampmCtrl = inForm[paramName + "UpperBound" + "AMPM"];
 394
 395    var editable = true;
 396
 397    //handle select box, not text box case
 398    if ( lowerBound == undefined && lhourCtrl == undefined)//either upper or lower, doesn't matter
 399    {
 400        editable = false;
 401        
 402        lowerBound = inForm[paramName + "SelectLowerBound"];
 403        upperBound = inForm[paramName + "SelectUpperBound"];
 404        lowerBound = lowerBound.options[lowerBound.selectedIndex];
 405        upperBound = upperBound.options[upperBound.selectedIndex];
 406    }
 407
 408    lowerUnBounded = (inForm[paramName+"SelectLowerOptions"].selectedIndex == (inForm[paramName + "SelectLowerOptions"].options.length - 1));
 409    upperUnBounded = (inForm[paramName+"SelectUpperOptions"].selectedIndex == (inForm[paramName + "SelectUpperOptions"].options.length - 1));
 410
 411
 412    lvalue = uvalue = "";
 413
 414    if ( ! lowerUnBounded )
 415    {
 416        if ((type == "dt" || type == "d" || type == "t") && (editable))
 417        {   
 418            lvalue = DateTimePromptValueHelper(type, lowerBoundHidden, lhourCtrl, lminuteCtrl, lsecondCtrl, lampmCtrl);
 419            if (lvalue.length == 0) return false;
 420        }
 421        else
 422            lvalue = lowerBound.value;
 423
 424        if ( ! checkSingleValue ( lvalue, type ) ) {
 425            if ( lowerBound.focus && lowerBound.type.toLowerCase () != "hidden")
 426                lowerBound.focus ();
 427            return false;
 428        }
 429    }
 430    if ( ! upperUnBounded )
 431    {
 432        if ((type == "dt" || type == "d" || type == "t") && (editable))
 433        {   
 434            uvalue = DateTimePromptValueHelper(type, upperBoundHidden, uhourCtrl, uminuteCtrl, usecondCtrl, uampmCtrl);
 435            if (uvalue.length == 0) return false;
 436        }
 437        else
 438            uvalue = upperBound.value;
 439
 440        if ( ! checkSingleValue ( uvalue, type ) ) {
 441            if ( upperBound.focus && upperBound.type.toLowerCase () != "hidden")
 442                upperBound.focus ();
 443            return false;
 444        }
 445    }
 446
 447    var ldisplay = "";
 448    var udisplay = "";
 449    if ((type == "dt" || type == "d" || type == "t") && (editable))
 450    {
 451        if (!lowerUnBounded)
 452            ldisplay = DateTimeDisplayStringHelper(type, lowerBoundHidden, lhourCtrl, lminuteCtrl, lsecondCtrl, lampmCtrl);
 453        if (!upperUnBounded)
 454            udisplay = DateTimeDisplayStringHelper(type, upperBoundHidden, uhourCtrl, uminuteCtrl, usecondCtrl, uampmCtrl);
 455    }
 456    else
 457    {
 458        ldisplay = lvalue;
 459        udisplay = uvalue;
 460    }
 461
 462    lowerChecked = (inForm[paramName+"SelectLowerOptions"].selectedIndex == 0);
 463    upperChecked = (inForm[paramName+"SelectUpperOptions"].selectedIndex == 0);
 464   
 465    value = lowerUnBounded ? "{" : lowerChecked ? "[" : "(";
 466    if ( ! lowerUnBounded ) //unbounded is empty string not quoted empty string (e.g not "_crEMPTY_")
 467        value += encodePrompt(lvalue);
 468    value += "_crRANGE_"
 469    if ( ! upperUnBounded )
 470        value += encodePrompt(uvalue);
 471    value += upperUnBounded ? "}" : upperChecked ? "]" : ")";
 472    if ( debug ) alert (value);
 473
 474    if ( !lowerUnBounded && !upperUnBounded && !checkRangeValue(lvalue, uvalue, type))
 475    {
 476                return false;
 477    }
 478
 479    var display = "";
 480    if (lowerChecked && upperUnBounded)
 481    {
 482                display = ConstructRangeDisplayString(L_FROM, ldisplay, "");
 483    }
 484    else if (lowerUnBounded && upperChecked)
 485    {
 486                display = ConstructRangeDisplayString(L_TO, udisplay, "");
 487    }
 488    else if (!lowerChecked && upperUnBounded)
 489    {
 490                display = ConstructRangeDisplayString(L_AFTER, ldisplay, "");
 491    }
 492    else if (lowerUnBounded && !upperChecked)
 493    {
 494                display = ConstructRangeDisplayString(L_BEFORE, udisplay, "");
 495    }
 496    else if (lowerChecked  && upperChecked)
 497    {
 498                display = ConstructRangeDisplayString(L_FROM_TO, ldisplay, udisplay);
 499    }
 500    else if (lowerChecked && !upperUnBounded && !upperChecked)
 501    {
 502                display = ConstructRangeDisplayString(L_FROM_BEFORE, ldisplay, udisplay);
 503    }
 504    else if (!lowerChecked && !lowerUnBounded && upperChecked)
 505    {
 506                display = ConstructRangeDisplayString(L_AFTER_TO, ldisplay, udisplay);
 507    }
 508    else if (!lowerChecked && !lowerUnBounded && !upperChecked && !upperUnBounded)
 509    {
 510                display = ConstructRangeDisplayString(L_AFTER_BEFORE, ldisplay, udisplay);
 511    }
 512   
 513    if ((!lowerUnBounded) || (!upperUnBounded))
 514    {
 515        promptEntry = new Option(display,value,false,false);
 516        theList.options[theList.length] = promptEntry;
 517    }
 518    else
 519    {
 520        alert(L_BadBound);
 521    }
 522
 523}
 524
 525////////////////////////////////////
 526// disable check boxes based on user selection on the range parameters
 527function disableBoundCheck(lowOrUpBound, inform, paramName) {
 528    if (lowOrUpBound == 0) {
 529        if (inform[paramName + "NoLowerBoundCheck"].checked) {
 530            inform[paramName + "NoUpperBoundCheck"].disabled = true;
 531            inform[paramName + "LowerCheck"].disabled = true;
 532            inform[paramName + "LowerBound"].disabled = true;
 533        }
 534        else {
 535            inform[paramName + "NoUpperBoundCheck"].disabled = false;
 536            inform[paramName + "LowerCheck"].disabled = false;
 537            inform[paramName + "LowerBound"].disabled = false;
 538        }
 539    } else if (lowOrUpBound == 1) {
 540        if (inform[paramName + "NoUpperBoundCheck"].checked) {
 541            inform[paramName + "NoLowerBoundCheck"].disabled = true;
 542            inform[paramName + "UpperCheck"].disabled = true;
 543            inform[paramName + "UpperBound"].disabled = true;
 544        } else {
 545            inform[paramName + "NoLowerBoundCheck"].disabled = false;
 546            inform[paramName + "UpperCheck"].disabled = false;
 547            inform[paramName + "UpperBound"].disabled = false;
 548        }
 549    }
 550}
 551
 552////////////////////////////////////
 553// puts "select" value into text box for an editable prompt which also has defaults
 554function setSelectedValue (inForm, selectCtrlName, textCtrlName, type, namePlusFix)
 555{
 556    var textCtrl = inForm[textCtrlName];
 557    var selectCtrl = inForm[selectCtrlName];
 558    var hiddenCtrl = inForm[namePlusFix+"Hidden"];
 559    var hourCtrl = inForm[namePlusFix+"Hour"];
 560    var minuteCtrl = inForm[namePlusFix+"Minute"];
 561    var secondCtrl = inForm[namePlusFix+"Second"];
 562    var ampmCtrl = inForm[namePlusFix+"AMPM"];
 563
 564    // if no editable input fields are there, return, do nothing;
 565    if (textCtrl == null && hourCtrl == null)
 566        return;
 567
 568    // if selectedItem is UseValue,do nothing, and return
 569    if (selectCtrl.options[selectCtrl.selectedIndex].value == CR_USE_VALUE)
 570    {
 571       return;
 572    }
 573
 574    if (selectCtrl.options[selectCtrl.selectedIndex].value == CR_NULL)
 575    {
 576       if (textCtrl != null) textCtrl.disabled = true;
 577       if (hourCtrl != null) hourCtrl.disabled = true;
 578       if (minuteCtrl != null) minuteCtrl.disabled = true;
 579       if (secondCtrl != null) secondCtrl.disabled = true;
 580       if (ampmCtrl != null) ampmCtrl.disabled = true;
 581       return;
 582    }
 583    else
 584    {
 585       if (textCtrl != null) textCtrl.disabled = false;
 586       if (hourCtrl != null) hourCtrl.disabled = false;
 587       if (minuteCtrl != null) minuteCtrl.disabled = false;
 588       if (secondCtrl != null) secondCtrl.disabled = false;
 589       if (ampmCtrl != null) ampmCtrl.disabled = false;
 590    }
 591
 592    var year, month, day;
 593    var hour, minute, second;
 594    if (type == "dt" || type == "d" || type == "t")
 595    {
 596        var sDateTime = selectCtrl.options[selectCtrl.selectedIndex].value;
 597        if (sDateTime.length == 0)
 598            return;
 599
 600        var leftIndex = sDateTime.indexOf("(");
 601        sDateTime = sDateTime.substr(leftIndex+1, sDateTime.length - leftIndex);
 602        var rightIndex = sDateTime.indexOf(")");
 603        sDateTime = sDateTime.substr(0, rightIndex);
 604        var a = sDateTime.split(",");
 605
 606        if (type == "dt")
 607        {
 608            year = a[0];
 609            month = a[1];
 610            day = a[2];
 611
 612            hour = parseInt(a[3]);
 613            minute = parseInt(a[4]);
 614            second = parseInt(a[5]);
 615        }
 616        else if (type == "d")
 617        {
 618            year = a[0];
 619            month = a[1];
 620            day = a[2];
 621        }
 622        else if (type == "t")
 623        {   
 624            hour = parseInt(a[0]);
 625            minute = parseInt(a[1]);
 626            second = parseInt(a[2]);
 627        }
 628    }
 629
 630    selectedOption = selectCtrl.options[selectCtrl.selectedIndex];
 631    if (type == "dt")
 632    {
 633        var dt = new Date(year, month - 1, day, hour, minute, second);
 634        textCtrl.value = GLDT(dt, true, false);
 635        hiddenCtrl.value = "Date(";
 636        hiddenCtrl.value += year;
 637        hiddenCtrl.value += ",";
 638        hiddenCtrl.value += month;
 639        hiddenCtrl.value += ",";
 640        hiddenCtrl.value += day;
 641        hiddenCtrl.value += ")";
 642
 643        if (ampmCtrl != undefined)
 644        {
 645            if (hour == 0 || hour == 12)
 646                hourCtrl.selectedIndex = 11;
 647            else if (hour > 12)
 648                hourCtrl.selectedIndex = hour - 12 - 1;
 649            else
 650                hourCtrl.selectedIndex = hour - 1;
 651        }
 652        else
 653            hourCtrl.selectedIndex = hour;
 654        minuteCtrl.selectedIndex = minute;
 655        secondCtrl.selectedIndex = second;
 656        if (ampmCtrl != null)
 657        { 
 658            if ( hour >= 12)
 659                ampmCtrl.selectedIndex = 1;
 660            else
 661                ampmCtrl.selectedIndex = 0;
 662        }
 663    }
 664    else if (type == "d")
 665    {
 666        var dt = new Date(year, month - 1, day, 0, 0, 0);
 667        textCtrl.value = GLDT(dt, true, false);
 668        hiddenCtrl.value = "Date(";
 669        hiddenCtrl.value += year;
 670        hiddenCtrl.value += ",";
 671        hiddenCtrl.value += month;
 672        hiddenCtrl.value += ",";
 673        hiddenCtrl.value += day;
 674        hiddenCtrl.value += ")";
 675    }
 676    else if (type == "t")
 677    {
 678        if (ampmCtrl != null)
 679        {
 680            if (hour == 0 || hour == 12)
 681                hourCtrl.selectedIndex = 11;
 682            else if (hour > 12)
 683                hourCtrl.selectedIndex = hour - 12 - 1;
 684            else
 685                hourCtrl.selectedIndex = hour - 1;
 686        }
 687        else
 688            hourCtrl.selectedIndex = hour;
 689        minuteCtrl.selectedIndex = minute;
 690        secondCtrl.selectedIndex = second;
 691        if (ampmCtrl != null)
 692        { 
 693            if ( hour >= 12)
 694                ampmCtrl.selectedIndex = 1;
 695            else
 696                ampmCtrl.selectedIndex = 0;
 697        }
 698    }
 699    else
 700    {
 701        textCtrl.value = selectedOption.value;
 702    }
 703
 704    if (selectCtrl.options[0].value == CR_USE_VALUE)
 705    {
 706        // always show USE_VALUE as selectedItem for the dropdownlist
 707        selectCtrl.selectedIndex = 0;
 708    }
 709}
 710
 711///////////////////////////////////
 712// remove value from listbox where multiple value prompts are supported
 713function removeFromListBox ( inForm, paramName )
 714{
 715    lbox = inForm[paramName + "ListBox"];
 716    for ( var idx = 0; idx < lbox.options.length; )
 717    {
 718        if ( lbox.options[idx].selected )
 719            lbox.options[idx] = null;
 720        else
 721            idx++;
 722    }
 723}
 724
 725/////////////////////////////////////
 726// sets prompt value into the hidden form field in proper format so that it can be submitted
 727function setPromptSingleValue (inform, type, paramName)
 728{
 729    //alert("SetPromptSingleValue");
 730    hiddenField = inform[promptPrefix + paramName];
 731    value = "";
 732    if ( inform[paramName + "NULL"] != null && inform[paramName + "NULL"].checked )
 733    {
 734        value = CR_NULL; //NULL is a literal for, uhmm.. a NULL
 735        hiddenField.value = value;
 736        return true;
 737    }
 738
 739    // if defaultdropdownlist selected item is _crNULL_, put it into multiple listbox
 740    var dropDownListName = paramName + "SelectValue";
 741    var dropDownListCtrl = inform[dropDownListName];
 742    if (dropDownListCtrl != null)
 743    {
 744        if (dropDownListCtrl.options[dropDownListCtrl.selectedIndex].value  == CR_NULL)
 745        {
 746            hiddenField.value = CR_NULL;
 747            return true;
 748        }
 749    }
 750
 751        
 752    discreteVal = inform[paramName + "DiscreteValue"];
 753    if (discreteVal != undefined || inform[paramName + "DiscreteValueHour"] != undefined)
 754    { // editable
 755          
 756        if ( type == "dt" || type == "d" || type == "t")
 757        {
 758           var hiddenCtrl = inform[paramName+"DiscreteValueHidden"];
 759           var hourCtrl = inform[paramName+"DiscreteValueHour"];
 760           var minuteCtrl = inform[paramName + "DiscreteValueMinute"];
 761           var secondCtrl = inform[paramName + "DiscreteValueSecond"];
 762           var ampmCtrl = inform[paramName + "DiscreteValueAMPM"];
 763           value = DateTimePromptValueHelper(type, hiddenCtrl, hourCtrl, minuteCtrl, secondCtrl, ampmCtrl);
 764           if (value.length == 0) return false;
 765        }
 766        else
 767           value = discreteVal.value;
 768    }
 769    else
 770    {
 771        // not editable
 772        discreteVal = inform[paramName+"SelectValue"];
 773        value = discreteVal.options[discreteVal.selectedIndex].value;
 774        //alert(value);
 775    }
 776    if ( ! checkSingleValue ( value, type ) ) {
 777        if (discreteVal.focus && discreteVal.type.toLowerCase ())
 778           discreteVal.focus ();
 779        return false;
 780    }
 781    else
 782        value = encodePrompt(value);
 783
 784    hiddenField.value = value;
 785    return true;
 786}
 787
 788/////////////////////////////////////
 789// sets prompt value for a range into the hidden form field in proper format so that it can be submitted
 790function setPromptRangeValue (inform, type, paramName)
 791{
 792
 793    hiddenField = inform[promptPrefix + paramName];
 794
 795    if ( inform[paramName + "NULL"] != null && inform[paramName + "NULL"].checked )
 796    {
 797        value = CR_NULL; //NULL is a literal for, uhmm.. a NULL
 798        hiddenField.value = value;
 799        return true;
 800    }
 801
 802        // if both defaultdropdownlists selected item is _crNULL_, put it into hiddenfield
 803    // if one of them is _crNULL_, it is not a valid option, do nothing
 804    var lowerDropDownListName = paramName + "SelectLowerBound";
 805    var upperDropDownListName = paramName + "SelectUpperBound";
 806    var lowerDropDownListCtrl = inform[lowerDropDownListName];
 807    var upperDropDownListCtrl = inform[upperDropDownListName];
 808    if (lowerDropDownListCtrl != null && upperDropDownListCtrl != null)
 809    {
 810        if (lowerDropDownListCtrl.options[lowerDropDownListCtrl.selectedIndex].value  == CR_NULL
 811            && upperDropDownListCtrl.options[upperDropDownListCtrl.selectedIndex].value  == CR_NULL)
 812        {
 813            hiddenField.value = "_crNULL_";
 814            return true;
 815        }
 816        else if (lowerDropDownListCtrl.options[lowerDropDownListCtrl.selectedIndex].value  == CR_NULL
 817            || upperDropDownListCtrl.options[upperDropDownListCtrl.selectedIndex].value  == CR_NULL)
 818        {
 819            alert(L_BadValue);
 820            return false;
 821        }
 822    }
 823
 824    lowerOptions = inform[paramName + "SelectLowerOptions"];
 825    upperOptions = inform[paramName + "SelectUpperOptions"];
 826
 827    lowerBound = inform[paramName + "LowerBound"];
 828    upperBound = inform[paramName + "UpperBound"];
 829
 830    lowerBoundHidden = inform[paramName + "LowerBoundHidden"];
 831    upperBoundHidden = inform[paramName + "UpperBoundHidden"];
 832
 833    lowerBoundDropdown = inform[paramName + "SelectLowerBound"];
 834    upperBoundDropdown = inform[paramName + "SelectUpperBound"];
 835
 836    var editables = true;
 837
 838    //handle select box, not text box case
 839    if (lowerBound == undefined && inform[paramName + "LowerBound" + "Hour"] == undefined)
 840    {
 841        editables = false;
 842        lowerBound = lowerBoundDropdown;
 843        upperBound = upperBoundDropdown;
 844        lowerBound = lowerBound.options[lowerBound.selectedIndex];
 845        upperBound = upperBound.options[upperBound.selectedIndex];
 846    }
 847
 848    lowerUnBounded = (lowerOptions.selectedIndex == (lowerOptions.length - 1));
 849    upperUnBounded = (upperOptions.selectedIndex == (upperOptions.length - 1));
 850
 851    lowerChecked = (lowerOptions.selectedIndex == 0);
 852    upperChecked = (upperOptions.selectedIndex == 0);
 853
 854    uvalue = lvalue = "";
 855
 856    if ( ! lowerUnBounded )
 857    {
 858        if ( (type == "dt" || type == "d" || type == "t") && (editables))
 859        {
 860            var lhourCtrl = inform[paramName+"LowerBound" + "Hour"];
 861            var lminuteCtrl = inform[paramName + "LowerBound" + "Minute"];
 862            var lsecondCtrl = inform[paramName + "LowerBound" + "Second"];
 863            var lampmCtrl = inform[paramName + "LowerBound" + "AMPM"];
 864            lvalue = DateTimePromptValueHelper(type, lowerBoundHidden, lhourCtrl, lminuteCtrl, lsecondCtrl, lampmCtrl);
 865            if (lvalue.length == 0) return false;
 866        }
 867        else
 868            lvalue = lowerBound.value;
 869
 870        if ( ! checkSingleValue ( lvalue, type ) ) {
 871            if (lowerBound != undefined && lowerBound.focus)
 872                lowerBound.focus();
 873            return false;
 874        }
 875    }
 876    if ( ! upperUnBounded )
 877    {
 878        if (( type == "dt" || type == "d" || type == "t") &&  (editables))
 879        {
 880            var uhourCtrl = inform[paramName+"UpperBound" + "Hour"];
 881            var uminuteCtrl = inform[paramName + "UpperBound" + "Minute"];
 882            var usecondCtrl = inform[paramName + "UpperBound" + "Second"];
 883            var uampmCtrl = inform[paramName + "UpperBound" + "AMPM"];
 884            uvalue = DateTimePromptValueHelper(type, upperBoundHidden, uhourCtrl, uminuteCtrl, usecondCtrl, uampmCtrl);
 885            if (uvalue.length == 0) return false;
 886        }
 887        else
 888            uvalue = upperBound.value;
 889
 890        if ( ! checkSingleValue ( uvalue, type ) ) {
 891            if (upperBound != undefined && upperBound.focus)
 892                upperBound.focus();
 893            return false;
 894        }
 895    }
 896    
 897    value = lowerUnBounded ? "{" : lowerChecked ? "[" : "(";
 898    if ( ! lowerUnBounded )
 899        value += encodePrompt(lvalue);
 900    value += "_crRANGE_"
 901    if ( ! upperUnBounded )
 902        value += encodePrompt(uvalue);
 903    value += upperUnBounded ? "}" : upperChecked ? "]" : ")";
 904    if ( debug )
 905        alert (value);
 906
 907    if (lowerUnBounded && upperUnBounded)
 908    {
 909        alert(L_BadBound);
 910        return false;
 911    }
 912
 913    if (!lowerUnBounded && !upperUnBounded && !checkRangeValue(lvalue, uvalue, type))
 914    {
 915            return false;
 916    }
 917
 918    hiddenField.value = value;
 919    return true;
 920}
 921
 922/////////////////////////////////////
 923// sets prompt value into the hidden form field in proper format so that it can be submitted
 924function setPromptMultipleValue (inform, type, paramName)
 925{
 926    hiddenField = inform[promptPrefix + paramName];
 927    values = inform[paramName + "ListBox"].options;
 928
 929    if ( values.length == 0 )
 930    {
 931        value = "_crEMPTY_";     //if value is empty, set to empty string
 932    }
 933    else
 934    {
 935        value = "";
 936        for ( idx = 0; idx < values.length; ++idx )
 937        {
 938            // first value could be empty string, then chcking value.length != 0 could miss one empty string
 939            if ( idx != 0 )
 940                value += "_crMULT_"
 941            value += values[idx].value;
 942        }
 943    }
 944    
 945    if ( debug )
 946        alert (value);
 947    
 948    hiddenField.value = value;
 949    //NOTE: we'll always return true as the validation is done before values are added to select box
 950    return true;
 951}
 952
 953///////////////////////////////////////
 954// check and alert user about any errors based on type of prompt
 955var regNumber    = /^(\+|-)?((\d+(\.|,| |\u00A0)?\d*)+|(\d*(\.|,| |\u00A0)?\d+)+)$/
 956var regCurrency  = regNumber;
 957var regDate  = /^(D|d)(A|a)(T|t)(E|e) *\( *\d{4} *, *(0?[1-9]|1[0-2]) *, *((0?[1-9]|[1-2]\d)|3(0|1)) *\)$/
 958var regDateTime  = /^(D|d)(A|a)(T|t)(E|e)(T|t)(I|i)(M|m)(E|e) *\( *\d{4} *, *(0?[1-9]|1[0-2]) *, *((0?[1-9]|[1-2]\d)|3(0|1)) *, *([0-1]?\d|2[0-3]) *, *[0-5]?\d *, *[0-5]?\d *\)$/
 959var regTime  = /^(T|t)(I|i)(M|m)(E|e) *\( *([0-1]?\d|2[0-3]) *, *[0-5]?\d *, *[0-5]?\d *\)$/
 960
 961function checkSingleValue ( value, type )
 962{
 963    if ( type == 'n' && ! regNumber.test ( value ) )
 964    {
 965        alert ( L_BadNumber );
 966        return false;
 967    }
 968    else if ( type == 'c' && ! regCurrency.test ( value ) )
 969    {
 970        alert ( L_BadCurrency );
 971        return false;
 972    }
 973    /*else if ( type == 'd' && ! regDate.test ( value ) )
 974    {
 975        alert ( L_BadDate );
 976        return false;
 977    }
 978    else if ( type == "dt" && ! regDateTime.test ( value ) )
 979    {
 980        alert ( L_BadDateTime );
 981        return false;
 982    }
 983    else if ( type == 't' && ! regTime.test ( value ) )
 984    {
 985        alert ( L_BadTime );
 986        return false;
 987    }*/
 988
 989    //by default let it go...
 990    return true;
 991}
 992
 993function checkRangeValue (fvalue, tvalue, type)
 994{
 995    // determine if the start is smaller than the end
 996    if ((type == "n") || (type == "c"))
 997    {
 998       // Is a number, or currency
 999        if (eval (DelocalizeNum (fvalue)) > eval (DelocalizeNum (tvalue)))
1000        {
1001            alert(L_RangeError);
1002            return false;
1003        }
1004    }
1005    else if (type == "d"){
1006        //Is a Date
1007        if (eval("new " + fvalue) > eval("new " + tvalue)){
1008            alert(L_RangeError);
1009            return false;
1010        }         
1011    }else if (type == "t"){
1012        //Is a Time
1013        var comp1 = eval("new Date(0,0,0," + fvalue.substring(fvalue.indexOf('(') + 1, fvalue.indexOf(')') + 1));
1014        var comp2 = eval("new Date(0,0,0," + tvalue.substring(tvalue.indexOf('(') + 1, tvalue.indexOf(')') + 1));
1015        if (comp1 > comp2){
1016            alert(L_RangeError);
1017            return false;
1018        }         
1019    }else if (type == "dt"){
1020        //Is a DateTime
1021        var comp1 = eval("new Date" + fvalue.substring(8, fvalue.length));
1022        var comp2 = eval("new Date" + tvalue.substring(8, tvalue.length));
1023        if (comp1 > comp2){
1024            alert(L_RangeError);
1025            return false;
1026        }         
1027    }
1028    else if (type == "text")
1029    {
1030         // is a string
1031         if (fvalue.toLowerCase() > tvalue.toLowerCase())
1032         {
1033            alert(L_RangeError);
1034            return false;
1035         }
1036    }
1037    // otherwise, let it go
1038
1039        return true;
1040}
1041
1042function DelocalizeNum(value)
1043{
1044        // trim spaces first
1045        var numStr = value.replace(/\s/g, "");
1046                
1047        // get rid of grouping first    
1048        var tempStr = "";
1049        var index = numStr.indexOf(groupSep);
1050        
1051        while (index != -1)
1052        {
1053                tempStr += numStr.substr(0, index);
1054                numStr = numStr.substr(index + groupSep.length, numStr.length - index - groupSep.length);
1055                index = numStr.indexOf(groupSep);
1056        }
1057        
1058        tempStr += numStr;
1059
1060        index = tempStr.indexOf(decimalSep);
1061        var neutralStr = "";
1062        if (index != -1)
1063        {       
1064                neutralStr += tempStr.substr(0, index);
1065                neutralStr += ".";
1066                neutralStr += tempStr.substr(index + decimalSep.length, tempStr.length - index - decimalSep.length);
1067        }
1068        else
1069        {
1070                neutralStr = tempStr;
1071        }
1072
1073        return neutralStr;
1074}
1075
1076// Disable enter key checking for multibyte languages since the enter key is used for committing characters
1077var isEnabledLanguage = (! ((userLanguage == "ja") || (userLanguage == "ko") || (userLanguage == "zh")) )
1078
1079var isNav = (navigator.appName == "Netscape");
1080if (isEnabledLanguage)
1081{
1082    if(isNav) {
1083        document.captureEvents(Event.KEYUP);
1084    }
1085    document.onkeyup = checkValue;
1086}
1087
1088function checkValue(evt) {
1089  var buttonVal = "";
1090  if (isNav) {
1091    if (evt.which == 13 && (evt.target.type == "text" || evt.target.type == "password")) {
1092        buttonVal = evt.target.value;
1093    }
1094  } else {
1095    if (window.event.keyCode == 13 && (window.event.srcElement.type == "text" || window.event.srcElement.type == "password")) {
1096        buttonVal = window.event.srcElement.value;
1097    }
1098  }
1099
1100  if (buttonVal != "") {
1101    submitParameterValues ();
1102  }
1103}