//
// JavaScript Browser Sniffer
// Eric Krok, Andy King, Michel Plungjan Jan. 31, 2002
// see http://webreference.com/tools/browser/javascript.html for more information
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
// please send any improvements to aking@internet.com and we'll
// roll the best ones in
//
// adapted from Netscape's Ultimate client-side JavaScript client sniffer
// and andy king's sniffer
// Revised May 7 99 to add is.nav5up and is.ie5up (see below). (see below).
// Revised June 11 99 to add additional props, checks
// Revised June 23 99 added screen props - gecko m6 doesn't support yet - abk
//                    converted to var is_ from is object to work everywhere
// 990624 - added cookie forms links frames checks - abk
// 001031 - ie4 mod 5.0 -> 5. (ie5.5 mididentified - abk)
//          is_ie4 mod tp work with ie6+ - abk
// 001120 - ns6 released, document.layers false, put back in
//        - is_nav6 test added - abk
// 001121 - ns6+ added, used document.getElementById, better test, dom-compl
// 010117 - actual version for ie3-5.5 by Michel Plungjan
// 010118 - actual version for ns6 by Michel Plungjan
// 010217 - netscape 6/mz 6 ie5.5 onload defer bug docs - abk
// 011107 - added is_ie6 and is_ie6up variables - dmr
// 020128 - added link to netscape's sniffer, on which this is based - abk
//          updated sniffer for aol4-6, ie5mac = js1.4, TVNavigator, AOLTV,
//          hotjava
// 020131 - cleaned up links, added more links to example object detection
// 020131 - a couple small problems with Opera detection. First, when Opera
//          is set to be compatible with other browsers it will contain their
//          information in the userAgent strings. Thus, to be sure we have 
//          Opera we should check for it before checking for the other bigs.
//          (And make sure the others are !opera.) Also corrected a minor
//          bug in the is_opera6up assignment.
// 020214 - Added link for Opera/JS compatibility; added improvements for 
//          windows xp/2000 id in opera and aol 7 id (thanks to Les
//          Hill, Les.Hill@getronics.com, for the suggestion).
// 020531 - Added N6/7 and moz identifiers. 
// 020605 - Added mozilla guessing, Netscape 7 identification, and cleaner
//          identification for Netscape 6. (this comment added after code 
//          changes)
// 020725 - Added is_gecko. -- dmr
// 021205 - Added is_Flash and is_FlashVersion, based on Doc JavaScript code. 
//          Added Opera 7 variables. -- dmr
// 021209 - Added aol8. -- dmr
// 030110 - Added is_safari, added 1.5 js designation for Opera 7. --dmr
// 030128 - Added is_konq, per user suggestion (thanks to Sam Vilain).
//          Removed duplicate Opera checks left over after last revision. - dmr
// 031124 - Added is_fb and version. We report this right after the is_moz
//          report. - dmr
// 040325 - Added is_fx and version. We report this right after the is_moz
//          report. - dmr
// 040421 - Added Debian check to is_moz. Thanks to Patrice Bridoux for
//          reporting this.
// 040517 - Added is_fb/is_fx to plugins based flash detection. Thanks to 
//          Martin Bischoff for pointing out this omission.
//
// Everything you always wanted to know about your JavaScript client
// but were afraid to ask. Creates "is_" variables indicating:
// (1) browser vendor:
//     is_nav, is_ie, is_opera
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav5, is_nav5up, 
//     is_nav6, is_nav6up, is_ie3, is_ie4, is_ie4up, is_ie5up, is_ie6...
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//        is_sun, is_sun4, is_sun5, is_suni86
//        is_irix, is_irix5, is_irix6
//        is_hpux, is_hpux9, is_hpux10
//        is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//        is_linux, is_sco, is_unixware, is_mpras, is_reliant
//        is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms
//
// based in part on 
// http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
// The Ultimate JavaScript Client Sniffer
// and Andy King's object detection sniffer
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when Nav5 and IE5 (or later) are released, so
// in conditional code forks, use is_nav4up ("Nav4 or greater")
// and is_ie4up ("IE4 or greater") instead of is_nav4 or is_ie4
// to check version in code which you want to work on future
// versions. For DOM tests scripters commonly used the 
// is_getElementById test, but make sure you test your code as
// filter non-compliant browsers (Opera 5-6 for example) as some 
// browsers return true for this test, and don't fully support
// the W3C's DOM1.
//

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();

    // *** BROWSER VERSION ***
    var is_minor = parseFloat(appVer);
    var is_major = parseInt(is_minor);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1); // new 020128- abk
    var is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1); // new 021205- dmr
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);
    var is_opera6up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5); // new020128
    var is_opera7up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6); // new021205 -- dmr

    // Note: On IE, start of appVersion return 3 or 4
    // which supposedly is the version of Netscape it is compatible with.
    // So we look for the real version further on in the string

    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
       is_major = parseInt(is_minor);
    }

    // ditto Konqueror
    var is_konq = false;
    var kqPos   = agt.indexOf('konqueror');
    if (kqPos !=-1) {                 
       is_konq  = true;
       is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
       is_major = parseInt(is_minor);
    }                                 

    var is_getElementById   = (document.getElementById) ? "true" : "false"; // 001121-abk
    var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false"; // 001127-abk
    var is_documentElement = (document.documentElement) ? "true" : "false"; // 001121-abk

    var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
    var is_khtml  = (is_safari || is_konq);

    var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
    var is_gver  = 0;
    if (is_gecko) is_gver=navigator.productSub;

    var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                    (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                    (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                    (is_gecko) && 
                    ((navigator.vendor=="")||(navigator.vendor=="Mozilla")||(navigator.vendor=="Debian")));
    var is_fb = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                 (is_gecko) && (navigator.vendor=="Firebird"));
    var is_fx = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                 (is_gecko) && (navigator.vendor=="Firefox"));
    if ((is_moz)||(is_fb)||(is_fx)) {  // 032504 - dmr
       var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
       if(!(is_moz_ver)) {
           is_moz_ver = agt.indexOf('rv:');
           is_moz_ver = agt.substring(is_moz_ver+3);
           is_paren   = is_moz_ver.indexOf(')');
           is_moz_ver = is_moz_ver.substring(0,is_paren);
       }
       is_minor = is_moz_ver;
       is_major = parseInt(is_moz_ver);
    }
	var is_fb_ver = is_moz_ver;
	var is_fx_ver = is_moz_ver;

    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
                && (!is_khtml) && (!(is_moz)) && (!is_fb) && (!is_fx));

    // Netscape6 is mozilla/5 + Netscape6/6.0!!!
    // Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
    // Changed this to use navigator.vendor/vendorSub - dmr 060502   
    // var nav6Pos = agt.indexOf('netscape6');
    // if (nav6Pos !=-1) {
    if ((navigator.vendor)&&
        ((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
        (is_nav)) {
       is_major = parseInt(navigator.vendorSub);
       // here we need is_minor as a valid float for testing. We'll
       // revert to the actual content before printing the result. 
       is_minor = parseFloat(navigator.vendorSub);
    }

    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && is_minor >= 4);  // changed to is_minor for
                                                // consistency - dmr, 011001
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );

    var is_nav6   = (is_nav && is_major==6);    // new 010118 mhp
    var is_nav6up = (is_nav && is_minor >= 6) // new 010118 mhp

    var is_nav5   = (is_nav && is_major == 5 && !is_nav6); // checked for ns6
    var is_nav5up = (is_nav && is_minor >= 5);

    var is_nav7   = (is_nav && is_major == 7);
    var is_nav7up = (is_nav && is_minor >= 7);

    var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
    var is_ie3  = (is_ie && (is_major < 4));

    var is_ie4   = (is_ie && is_major == 4);
    var is_ie4up = (is_ie && is_minor >= 4);
    var is_ie5   = (is_ie && is_major == 5);
    var is_ie5up = (is_ie && is_minor >= 5);
    
    var is_ie5_5  = (is_ie && (agt.indexOf("msie 5.5") !=-1)); // 020128 new - abk
    var is_ie5_5up =(is_ie && is_minor >= 5.5);                // 020128 new - abk
	
    var is_ie6   = (is_ie && is_major == 6);
    var is_ie6up = (is_ie && is_minor >= 6);

	// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);
    var is_aol7  = ((agt.indexOf("aol 7")!=-1) || (agt.indexOf("aol7")!=-1));
    var is_aol8  = ((agt.indexOf("aol 8")!=-1) || (agt.indexOf("aol8")!=-1));

    var is_webtv = (agt.indexOf("webtv") != -1);
    
    // new 020128 - abk
    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));
    // end new
	
    // *** JAVASCRIPT VERSION CHECK ***
    // Useful to workaround Nav3 bug in which Nav3
    // loads <SCRIPT LANGUAGE="JavaScript1.2">.
    // updated 020131 by dragle
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3) is_js = 1.1;
    else if ((is_opera5)||(is_opera6)) is_js = 1.3; // 020214 - dmr
    else if (is_opera7up) is_js = 1.5; // 031010 - dmr
    else if (is_khtml) is_js = 1.5;   // 030110 - dmr
    else if (is_opera) is_js = 1.1;
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
    else if (is_nav5 && !(is_nav6)) is_js = 1.4;
    else if (is_hotjava3up) is_js = 1.4; // new 020128 - abk
    else if (is_nav6up) is_js = 1.5;

    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.

    else if (is_nav && (is_major > 5)) is_js = 1.4;
    else if (is_ie && (is_major > 5)) is_js = 1.3;
    else if (is_moz) is_js = 1.5;
    else if (is_fb||is_fx) is_js = 1.5; // 032504 - dmr
    
    // what about ie6 and ie6up for js version? abk
    
    // HACK: no idea for other browsers; always check for JS version 
    // with > or >=
    else is_js = 0.0;
    // HACK FOR IE5 MAC = js vers = 1.4 (if put inside if/else jumps out at 1.3)
    if ((agt.indexOf("mac")!=-1) && is_ie5up) is_js = 1.4; // 020128 - abk
    
    // Done with is_minor testing; revert to real for N6/7
    if (is_nav6up) {
       is_minor = navigator.vendorSub;
    }

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) ||
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
               (agt.indexOf("windows 16-bit")!=-1) );

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));
	
	var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));    // new 020128 - abk
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1) || (agt.indexOf("windows 2000")!=-1)); // 020214 - dmr
    var is_winxp = ((agt.indexOf("windows nt 5.1")!=-1) || (agt.indexOf("windows xp")!=-1)); // 020214 - dmr

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 ||
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) ||
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||
                    (agt.indexOf("ibm-webexplorer")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    if (is_mac) { is_win = !is_mac; } // dmr - 06/20/2002
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) ||
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) ||
                                (agt.indexOf("powerpc")!=-1)));

    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);
    var is_aix2  = (agt.indexOf("aix 2") !=-1);
    var is_aix3  = (agt.indexOf("aix 3") !=-1);
    var is_aix4  = (agt.indexOf("aix 4") !=-1);
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1);
    var is_mpras    = (agt.indexOf("ncr")!=-1);
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux ||
                 is_sco ||is_unixware || is_mpras || is_reliant ||
                 is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));
	// additional checks, abk
	var is_anchors = (document.anchors) ? "true":"false";
	var is_regexp = (window.RegExp) ? "true":"false";
	var is_option = (window.Option) ? "true":"false";
	var is_all = (document.all) ? "true":"false";
	// cookies - 990624 - abk
	document.cookie = "cookies=true";
	var is_cookie = (document.cookie) ? "true" : "false";
	var is_images = (document.images) ? "true":"false";
	var is_layers = (document.layers) ? "true":"false"; // gecko m7 bug?
	// new doc obj tests 990624-abk
	var is_forms = (document.forms) ? "true" : "false";
	var is_links = (document.links) ? "true" : "false";
	var is_frames = (window.frames) ? "true" : "false";
	var is_screen = (window.screen) ? "true" : "false";

	// java
	var is_java = (navigator.javaEnabled());

	// Flash checking code adapted from Doc JavaScript information; 
	// see http://webref.com/js/column84/2.html
   var is_Flash        = false;
   var is_FlashVersion = 0;

   if ((is_nav||is_opera||is_moz||is_fb||is_fx)||
       (is_mac&&is_ie5up)) {
      var plugin = (navigator.mimeTypes && 
                    navigator.mimeTypes["application/x-shockwave-flash"] &&
                    navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) ?
                    navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
      if (plugin) {
         is_Flash = true;
         is_FlashVersion = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1));
      }
   }

   if (is_win&&is_ie4up)
   {
      document.write(
         '<scr' + 'ipt language=VBScript>' + '\n' +
         'Dim hasPlayer, playerversion' + '\n' +
         'hasPlayer = false' + '\n' +
         'playerversion = 10' + '\n' +
         'Do While playerversion > 0' + '\n' +
            'On Error Resume Next' + '\n' +
            'hasPlayer = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & playerversion)))' + '\n' +
            'If hasPlayer = true Then Exit Do' + '\n' +
            'playerversion = playerversion - 1' + '\n' +
         'Loop' + '\n' +
         'is_FlashVersion = playerversion' + '\n' +
         'is_Flash = hasPlayer' + '\n' +
         '<\/sc' + 'ript>'
      );
   }

// A utility function that returns true if a string contains only 
// whitespace characters.
function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

// This is the function that performs form verification. It will be invoked
// from the onSubmit() event handler. The handler should return whatever
// value this function returns.
function verifyForm(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";

    // Loop through the elements of the form, looking for all 
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // then verify that they are numbers and that they are in the right range.
    // Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];
        if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value)) {
                empty_fields += "\n\t * " + e.name;
                continue;
            }

            // Now check for fields that are supposed to be numeric.
            if (e.numeric || (e.min != null) || (e.max != null)) { 
                var v = parseFloat(e.value);
                if (isNaN(v) || 
                    ((e.min != null) && (v < e.min)) || 
                    ((e.max != null) && (v > e.max))) {
                    errors += "- The field " + e.name + " must be a number";
                    if (e.min != null) 
                        errors += " that is greater than " + e.min;
                    if (e.max != null && e.min != null) 
                        errors += " and less than " + e.max;
                    else if (e.max != null)
                        errors += " that is less than " + e.max;
                    errors += ".\n";
                }
            }
        }
    }

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "___________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    if (empty_fields) {
        msg += "- The following required field(s) are empty:" 
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    msg += errors;
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "___________________________________________________\n\n"
    alert(msg);
    return false;
}

   
// Popup Window Opener
function openPopUp(URL, w, h, rs, sb, hk, mb, sc, st, tb) {
		// Set some default params
		var valid = "0,1";
		if (isNaN(w)) {w = 450;}
		if (isNaN(h)) {h = 450;}
		// resizeable
		if (valid.indexOf(rs) == "-1") {rs = 1;}
		// statusbar
		if (valid.indexOf(sb) == "-1") {sb = 1;}
		// hotkeys
		if (valid.indexOf(hk) == "-1") {hk = 0;}
		// menubar
		if (valid.indexOf(mb) == "-1") {mb = 0;}
		// scrollbars
		if (valid.indexOf(sc) == "-1") {sc = 1;}
		// statusbar
		if (valid.indexOf(st) == "-1") {st = 1;}
		// toolbar
		if (valid.indexOf(tb) == "-1") {tb = 0;}
		
		new_window = window.open(URL, "tool_popup", "height=" + h + ",width=" + w + ", resizable=" + rs + ", statusbar=" + sb + ", hotkeys=" + hk + ",menubar=" + mb + ",scrollbars=" + sc + ",status=" + st + ",toolbar=" + tb);
		new_window.resizeTo(w,h);
	   	new_window.focus();}
		
// Resize an already loaded window
function resizeWindow(w,h) {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			 top.outerWidth=w;
			 top.outerHeight=h;
		}
			else top.resizeTo(w,h);
		}
	}



// Limit length of text or textarea fields
function limitLength(field, max){
	    if (field.value.length > max){
	        alert('Text too long. Must be ' + max + ' characters or less');
			field.value = field.value.substr(0,max);
			field.focus();
	        return false;
	    }
	    return true;
	}

// Auto advance
function autoTab(input,len,e) {
		var isNN = (navigator.appName.indexOf("Netscape")!=-1);
		var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		if(input.value.length >= len && !containsElement(filter,keyCode)) {
			input.value = input.value.slice(0, len);
			input.form[(getIndex(input)+1) % input.form.length].focus();
			}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
				else
				index++;
				return found;
		}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
				else i++;
				return index;
			}
		return true;
	}
	
// Show/Hide div
function hideShow(thisDiv) {
	if(!document.getElementById) {
		return;
	}
		obj = document.getElementById(thisDiv);
		obj.style.display = (obj.style.display == "none" ) ? "block" : "none";
	}

// Validates fields to be all numeric
function validateNumeric(field) {
	var valid = "0123456789"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		alert("Invalid entry!  Only numbers are accepted!");
		field.value = "";
		field.focus();
		field.select();
	   }
	}

// Validates field to be all alpha
function validateAlpha(field) {
	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		alert("Invalid entry!  Only letters are accepted!");
		field.value = "";
		field.focus();
		field.select();
	   }
	}

// Validates field to be all alphanumeric
function validateAlphaNumeric(field) {
	var valid = "1243567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		alert("Invalid entry!  Only letters and numbers are accepted!");
		field.value = "";
		field.focus();
		field.select();
	   }
	}

	
function move(AllItems, FaveItems) {
	var arrAllItems = new Array();
	var arrFaveItems = new Array();
	var arrLookup = new Array();
	var i;
	for (i = 0; i < FaveItems.options.length; i++) {
		arrLookup[FaveItems.options[i].text] = FaveItems.options[i].value;
		arrFaveItems[i] = FaveItems.options[i].text;
	}
	var fLength = 0;
	var tLength = arrFaveItems.length;
	for(i = 0; i < AllItems.options.length; i++) {
		arrLookup[AllItems.options[i].text] = AllItems.options[i].value;
		if (AllItems.options[i].selected && AllItems.options[i].value != "") {
			arrFaveItems[tLength] = AllItems.options[i].text;
			tLength++;
		} else {
		arrAllItems[fLength] = AllItems.options[i].text;
		fLength++;
	   }
	}
	
	arrAllItems.sort();
	arrFaveItems.sort();
	AllItems.length = 0;
	FaveItems.length = 0;
	var c;
	for(c = 0; c < arrAllItems.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrAllItems[c]];
		no.text = arrAllItems[c];
		AllItems[c] = no;
	}
	
	for(c = 0; c < arrFaveItems.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrFaveItems[c]];
		no.text = arrFaveItems[c];
		FaveItems[c] = no;
	   }
	}

function selectAll(FormName, SelectBox){
	  temp = "document." + FormName + "." + SelectBox;
	  Source = eval(temp);
	
	  for(x=0; x<(Source.length); x++){
	    Source.options[x].selected = "true";
	    }
	}

// Validate email address
function validateEmail(field) {
		if ((field.value.length == 0) || (/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/.test(field.value))){
			return (true);
			}
		alert("Invalid E-mail Address!\nPlease re-enter using user@domain.com format.");
		field.value = "";
		field.focus();
		field.select();
		}

// Validate Phone Number
function validatePhone(field) {
		if ((field.value.length == 0) || (/^\(\d{3}\)\s?\d{3}-\d{4}$/.test(field.value))){
			return (true);
			}
		alert("Invalid phone number!\nPlease re-enter using (111)555-1212 format.");
		field.value = "";
		field.focus();
		field.select();
		}

// Validate US Zip
function validateZipOrPC(field) {
		if ((field.value.length == 0) || (/^((\d{5}-\d{4})|(\d{5})|([AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d))$/.test(field.value))){
			return (true);
			}
		alert("Invalid ZIP or Postal Code.");
		field.value = "";
		field.focus();
		field.select();
		}

// Validate dates
function validateDate(field) {
		if ((field.value.length == 0) || (/^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/.test(field.value))){
			return (true);
			}
		alert("Invalid date format!\nPlease enter a valid date\nusing mm/dd/yyyy format.");
		field.value = "";
		field.focus();
		field.select();
		}

// Validate Money Format
function validateMoney(field) {
		if ((field.value.length == 0) || (/^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/.test(field.value))){
			return (true);
			}
		alert("Invalid money format!\nPlease re-enter using $123.45 format.");
		field.value = "";
		field.focus();
		field.select();
		}

// Credit card validation
function validateCC() {
	var cardNumber = document.customer.paymentCardNumber.value;
	var cardType = document.customer.paymentCardType.value;
	  
	var isValid = false;
	var ccCheckRegExp = /[^\d ]/;
	isValid = !ccCheckRegExp.test(cardNumber);

  if (isValid) {
	var cardNumbersOnly = cardNumber.replace(/ /g,"");
	var cardNumberLength = cardNumbersOnly.length;
	var lengthIsValid = false;
	var prefixIsValid = false;
	var prefixRegExp;

    switch(cardType) {
      case "mastercard":
        lengthIsValid = (cardNumberLength == 16);
        prefixRegExp = /^5[1-5]/;
        break;
      case "visa":
        lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
        prefixRegExp = /^4/;
        break;
      case "amex":
        lengthIsValid = (cardNumberLength == 15);
        prefixRegExp = /^3(4|7)/;
        break;
      case "discover":
        lengthIsValid = (cardNumberLength == 16);
        prefixRegExp = /^6011/;
        break;
      default:
        prefixRegExp = /^$/;
        alert("Card type not found");
    }
    prefixIsValid = prefixRegExp.test(cardNumbersOnly);
    isValid = prefixIsValid && lengthIsValid;
  }

  if (isValid) {
    var numberProduct;
    var numberProductDigitIndex;
    var checkSumTotal = 0;

    for (digitCounter = cardNumberLength - 1; 
      digitCounter >= 0; 
      digitCounter--) {
      checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
      digitCounter--;
      numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
      for (var productDigitCounter = 0;
        productDigitCounter < numberProduct.length; 
        productDigitCounter++) {
        checkSumTotal += 
          parseInt(numberProduct.charAt(productDigitCounter));
      }
    }
    isValid = (checkSumTotal % 10 == 0);
  } else {
  	alert("Please provide a valid credit card number.");
  }
  return isValid;
}

// Keeps form from being submitted twice
function LockButtons(whichform) {
		ua = new String(navigator.userAgent);
		if (ua.match(/IE/g)) {
			for (i=1; i<whichform.elements.length; i++) {
				if (whichform.elements[i].type == 'submit') {
					whichform.elements[i].disabled = true;
				}
			}
		}
		whichform.submit();
	}

// Ensures string is greater than min and less than max in length
function lengthRange(field,min,max) {
	if (((field.value.length >= min) && (field.value.length <= max)) || (field.value.length == 0)) { 
			return true;
		} else {
			alert('Value must be between ' + min + ' and ' + max + ' characters long.'); 
			field.value = "";
			field.focus();
			field.select();
		}
	}

// Ensures string is greater than min and less than max in value
function valueRange(field,min,max) {
	if (((field.value >= min) && (field.value <= max)) || (field.value.length == 0)) { 
			return true;
		} else {
			alert('Value must be between ' + min + ' and ' + max + '.');
			field.value = "";
			field.focus();
			field.select();
		}
	}

// compares the values of two form fields
function compare2(firstfield,secondfield) {
	if (firstfield.value != secondfield.value) {
			alert('The values for ' + firstfield.name + ' and ' + secondfield.name + ' must match.');
			secondfield.value = "";
			secondfield.focus();
			secondfield.select();
		}
	}

// trims the left of a field
function LTrim(field) {
	   var whitespace = new String(" \t\n\r");
	   var s = new String(field);
	   if (whitespace.indexOf(s.charAt(0)) != -1) {
	      var j=0, i = s.length;
	      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
	         j++;
	      s = s.substring(j, i);
	   }
	   return s;
	}
	
// trims the right of a field
function RTrim(field) {
	   var whitespace = new String(" \t\n\r");
	   var s = new String(field);
	   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
	      var i = s.length - 1;
		  while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
	         i--;
	      s = s.substring(0, i+1);
	   }
	   return s;
	}
	
// trims whitespace off both ends of a field using ltrim() and rtrim() above.
function trimField(field) {
		origStr = field.value;
		newStr = RTrim(LTrim(field.value));
	if (origStr != newStr) {
		field.value = newStr;
		}
		return newStr;
	}

function noenter() {
  return !(window.event && window.event.keyCode == 13); }
  

// Countdown script  v1.1
// documentation: http://www.dithered.com/javascript/countdown/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
function Countdown(name) {
   this.name = name;
   this.updateFrequency = 1000;
   this.images = null;
   this.endDate = new Date();
   this.format = (document.getElementById && document.getElementById(this.name)) ? document.getElementById(this.name).innerHTML : '';
}

Countdown.prototype.setEndDate = function(year, month, day, hour, minute, second, milliseconds) {
   this.endDate = new Date(year, month - 1, day, ( (hour) ? hour : 0), ( (minute) ? minute : 0), ( (second) ? second : 0), ( (milliseconds) ? milliseconds : 0));
};

Countdown.prototype.start = function() {
   this.update();
   setInterval(this.name + '.update()', (this.updateFrequency ? this.updateFrequency : 1000) );
};

Countdown.prototype.update = function() {
   // calculate the time until countdown end date
   var now = new Date();
   var difference = this.endDate - now;
   // decompose difference into days, hours, minutes and seconds parts
   var days    = parseInt(difference / 86400000) + '';
   var hours   = parseInt((difference % 86400000) / 3600000) + '';
   var minutes = parseInt((difference % 3600000) / 60000) + '';
   var seconds = parseInt((difference % 60000) / 1000) + '';
   var milliseconds = parseInt(difference % 1000) + '';
   // negative values should be set to 0
   if (isNaN(days) || days.charAt(0) == '-') days = '0';
   if (isNaN(hours) || hours.charAt(0) == '-') hours = '0';
   if (isNaN(minutes) || minutes.charAt(0) == '-') minutes = '0';
   if (isNaN(seconds) || seconds.charAt(0) == '-') seconds = '0';
   if (isNaN(milliseconds) || milliseconds.charAt(0) == '-') milliseconds = '0';
   // display changes differently for images and text countdowns
if (this.format != '') {
      if (document.getElementById && document.getElementById(this.name)) {
         var html = this.format;
         html = html.replace(/~d~/, days);
         html = html.replace(/~h~/, hours);
         html = html.replace(/~m~/, minutes);
			 if (seconds < 10) {
			 	html = html.replace(/~s~/, '0' + seconds);
			 } else {
		        html = html.replace(/~s~/, seconds);
			 }
         html = html.replace(/~ms~/, milliseconds);
         document.getElementById(this.name).innerHTML = html;
      }
   }
};

/* This processes a form cancellation */
function cancelOrder() {
		if (confirm('This will cancel all tickets in your current order.')) {
			location.href='/?event=cancelOrder';
		}
	}

/* This makes sure there is a numeric value in at least one of the seat selection form fields. */
function checkSelectSeatsForm() {
	    var check = false;
		var selectedZone = 0
		var FieldName = new String;
		var splitFormName = new Array(3);
		
		// Find the zone that that is selected
		if ( isNaN(document.select_seats.zone.length) ) 
		{
			selectedZone = document.select_seats.zone.value
		}
		else
		{
			for (var j = 0 ; j < document.select_seats.zone.length ; j++ )
				if (document.select_seats.zone[j].checked)
					selectedZone = document.select_seats.zone[j].value;
		}

		// Text boxes are formated with seatselection_1_1516_35.0000 where the _1_ is the zone
		//
		for (var i = 0; i < document.select_seats.elements.length ; i++) 
		{
			// We are looking for text fields so we will only test text elements
			if (document.select_seats.elements[i].type == 'text')
			{
				// Create a string object our of the name so that we can use the split mehtod
				FieldName = new String(document.select_seats.elements[i].name);
				
				// use the split method on the name to sepparate the "seatselection" and the zone value form the name
				splitFormName = FieldName.split('_', 3);

				// compate the first to elements of the arroy with the name seatselection and the zone if they match then count it
				// check the seatselection and the zone if they match count the value of the field
				
				if (splitFormName[0] == 'seatselection' && splitFormName[1] == selectedZone)
				{
					
					if ( (document.select_seats.elements[i].value * 1) > 0 ) 
						check = true;
					
				} // splitFormName[0] == 'seatselection' && splitFormName[1] == selectedZone
			} // end if element is text
	    } // end for loop 
		
		// Message to the user that they need to select a some seats
		if( !check )
			alert('You must select at least one seat!');
		
		// Return the value of check
		return check;
		
	}
// end function checkSelectSeatsForm()

/* This is for filling the "shipping information" section of the customer registration form */
var Ecom_BillTo_Postal_Name_First = "";
var Ecom_BillTo_Postal_Name_Last = "";
//var Ecom_BillTo_Online_Email = "";
var Ecom_BillTo_Postal_Company = "";
var billTitle = "";
var Ecom_BillTo_Postal_Street_Line1 = "";
var Ecom_BillTo_Postal_Street_Line2 = "";
var Ecom_BillTo_Postal_City = "";
var Ecom_BillTo_Postal_StateProv = "";
//var billStateIndex = 0;
var Ecom_BillTo_Postal_PostalCode = "";
var Ecom_BillTo_Postal_CountryCode = "";
var Ecom_BillTo_Telecom_Phone_Number = "";
//var billWorkPhone = "";
//var billFax = "";
var useBilling = 0;

function InitSaveVariables(form) {
	Ecom_BillTo_Postal_Name_First = form.Ecom_BillTo_Postal_Name_First.value;
	Ecom_BillTo_Postal_Name_Last = form.Ecom_BillTo_Postal_Name_Last.value;
	//billEmail = form.Ecom_BillTo_Online_Email.value;
	Ecom_BillTo_Postal_Company = form.Ecom_BillTo_Postal_Company.value;
	billTitle = form.billTitle.value;
	Ecom_BillTo_Postal_Street_Line1 = form.Ecom_BillTo_Postal_Street_Line1.value;
	Ecom_BillTo_Postal_Street_Line2 = form.Ecom_BillTo_Postal_Street_Line2.value;
	Ecom_BillTo_Postal_City = form.Ecom_BillTo_Postal_City.value;
	Ecom_BillTo_Postal_StateProv = form.Ecom_BillTo_Postal_StateProv.value;
	Ecom_BillTo_Postal_PostalCode = form.Ecom_BillTo_Postal_PostalCode.value;
	Ecom_BillTo_Postal_CountryCode = form.Ecom_BillTo_Postal_CountryCode.value;
	Ecom_BillTo_Telecom_Phone_Number = form.Ecom_BillTo_Telecom_Phone_Number.value;
	//billStateIndex = form.Ecom_BillTo_Postal_StateProv.selectedIndex;
	//Ecom_BillTo_Postal_StateProv = form.Ecom_BillTo_Postal_StateProv[billStateIndex].value;
	Ecom_BillTo_Telecom_Phone_Number = form.Ecom_BillTo_Telecom_Phone_Number.value;
	//billWorkPhone = form.billWorkPhone.value;
	//billFax = form.billFax.value;
	}

function shipToBillPerson(form) {
	if (form.useBilling.checked) {
	InitSaveVariables(form);
	form.Ecom_ShipTo_Postal_Name_First.value = form.Ecom_BillTo_Postal_Name_First.value;
	form.Ecom_ShipTo_Postal_Name_Last.value = form.Ecom_BillTo_Postal_Name_Last.value;
	//form.Ecom_ShipTo_Online_Email.value = form.Ecom_BillTo_Online_Email.value;
	form.Ecom_ShipTo_Postal_Company.value = form.Ecom_BillTo_Postal_Company.value;
	form.shipTitle.value = form.billTitle.value;
	form.Ecom_ShipTo_Postal_Street_Line1.value = form.Ecom_BillTo_Postal_Street_Line1.value;
	form.Ecom_ShipTo_Postal_Street_Line2.value = form.Ecom_BillTo_Postal_Street_Line2.value;
	form.Ecom_ShipTo_Postal_City.value = form.Ecom_BillTo_Postal_City.value;
	form.Ecom_ShipTo_Postal_StateProv.value = form.Ecom_BillTo_Postal_StateProv.value;
	form.Ecom_ShipTo_Postal_PostalCode.value = form.Ecom_BillTo_Postal_PostalCode.value;
	form.Ecom_ShipTo_Postal_CountryCode.value = form.Ecom_BillTo_Postal_CountryCode.value;
	form.Ecom_ShipTo_Telecom_Phone_Number.value = form.Ecom_BillTo_Telecom_Phone_Number.value;
	//form.shipWorkPhone.value = form.billWorkPhone.value;
	//form.shipFax.value = form.billFax.value;
	//form.Ecom_ShipTo_Postal_StateProv.selectedIndex = form.Ecom_BillTo_Postal_StateProv.selectedIndex;
	form.useBilling.checked = form.useBilling.checked;
	}
	else {
	form.Ecom_BillTo_Postal_Name_First.value = Ecom_BillTo_Postal_Name_First;
	form.Ecom_BillTo_Postal_Name_Last.value = Ecom_BillTo_Postal_Name_Last;
	//form.Ecom_BillTo_Online_Email.value = Ecom_BillTo_Online_Email;
	form.Ecom_BillTo_Postal_Company.value = Ecom_BillTo_Postal_Company;
	form.billTitle.value = billTitle;
	form.Ecom_BillTo_Postal_Street_Line1.value = Ecom_BillTo_Postal_Street_Line1;
	form.Ecom_BillTo_Postal_Street_Line2.value = Ecom_BillTo_Postal_Street_Line2;
	form.Ecom_BillTo_Postal_City.value = Ecom_BillTo_Postal_City;
	form.Ecom_BillTo_Postal_StateProv.value = Ecom_BillTo_Postal_StateProv;
	form.Ecom_BillTo_Postal_PostalCode.value = Ecom_BillTo_Postal_PostalCode;
	form.Ecom_BillTo_Postal_CountryCode.value = Ecom_BillTo_Postal_CountryCode;
	form.Ecom_BillTo_Telecom_Phone_Number.value = Ecom_BillTo_Telecom_Phone_Number;
	//form.shipWorkPhone.value = billWorkPhone;
	//form.Ecom_BillTo_Postal_StateProv.selectedIndex = billStateIndex;
	form.useBilling.checked = useBilling;
	   }
	}

/***********************************************
* Switch Content script- ? Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
var enablepersist="on" //Enable saving state of content structure? (on/off)
	if (document.getElementById){
	document.write('<style type="text/css">')
	document.write('.switchcontent{display:none;}')
	document.write('</style>')
	}
function getElementbyClass(classname){
	ccollect=new Array()
	var inc=0
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (i=0; i<alltags.length; i++){
		if (alltags[i].className==classname)
		ccollect[inc++]=alltags[i]
		}
	}
function contractcontent(omit){
	var inc=0
	while (ccollect[inc]){
		if (ccollect[inc].id!=omit)
		ccollect[inc].style.display="none"
		inc++
		}
	}
function expandcontent(cid){
	if (typeof ccollect!="undefined"){
		contractcontent(cid)
		document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
		selectedItem=cid+"|"+document.getElementById(cid).style.display
		}
	}
function revivecontent(){
	selectedItem=getselectedItem()
	selectedComponents=selectedItem.split("|")
	contractcontent(selectedComponents[0])
	document.getElementById(selectedComponents[0]).style.display=selectedComponents[1]
	}
function get_cookie(Name) { 
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) { 
		offset += search.length
		end = document.cookie.indexOf(";", offset);
		if (end == -1) end = document.cookie.length;
		returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
return returnvalue;
}
function getselectedItem(){
	if (get_cookie(window.location.pathname) != ""){
	selectedItem=get_cookie(window.location.pathname)
	return selectedItem
	}
	else
	return ""
	}
function saveswitchstate(){
	if (typeof selectedItem!="undefined")
	document.cookie=window.location.pathname+"="+selectedItem
	}
function do_onload(){
	getElementbyClass("switchcontent")
	if (enablepersist=="on" && getselectedItem()!="")
	revivecontent()
	}
if (window.addEventListener)
window.addEventListener("load", do_onload, false)

else if (window.attachEvent)
window.attachEvent("onload", do_onload)

else if (document.getElementById)
window.onload=do_onload;

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate;
	
/* Checkbox functions
//
//
*/

// HISTORY
// ------------------------------------------------------------------
// February 29, 2004: Fixed bug caused by LAST update, when control
//    checkbox is the first on checked. I hate when that happens.
// January 28, 2004: Fixed bug that occurred when checkbox was CHECKED
//    by default.
// December 16, 2002: Created
/* 
Original coding done by David Rogers - http://www.MrDaveR.com/

DESCRIPTION: This library lets you quickly and easily make multiple checkboxes
behave as a group by limiting the total number of boxes that can be checked
and/or have a master control checkbox. 

COMPATABILITY: Should work on all Javascript-compliant browsers.

USAGE:
// Create a new CheckBoxGroup object
var myOptions = new CheckBoxGroup();

// Tell the object which checkboxes exist in your group. You may make multiple
// calls to this function, and/or pass multiple arguments. You may specify
// field names exactly, or use a wildcard at the beginning or end of the 
// name.
myOptions.addToGroup("cb1","cb2","optionset*");
myOptions.addToGroup("*checkbox");

// Optionally set a "control" box which will effect all other boxes.
myOptions.setControlBox("masterCheckboxName");

// Specify how your control box will interact with the group. Options are
// either "some" or "all" ("all" is default).
// all: Checking the box will select all the other boxes. Unchecking it will
//      uncheck all the group checkboxes. Selecting all the checkboxes in
//      the group will automatically check the control box.
// some: Checking any checkbox in the group will check the control box. The
//       control box may not be unchecked if any option in the group is 
//       still checked. If no boxes in the group are checked, you may still
//       check the control box.
myOptions.setMasterBehavior("some");

// Optionally set the maximum number of boxes in the group which are allowed
// to be checked. You may pass a second argument which is an alert message to
// be displayed to the user if they exceed this limit.
myOptions.setMaxAllowed(3);
myOptions.setMaxAllowed(3,"You may only select 3 choices!");

// IMPORTANT: After defining the group and behavior, you must insert an action
// into EVERY checkbox's onClick event-handler. Just specify the name of the
// group object that the checkbox belongs to, and pass it 'this' as the argument.
<INPUT TYPE="checkbox" NAME="cb1" onClick="myOptions.check(this)">

// That's it! Your checkboxes will now behave as a group!

*/ 
function CheckBoxGroup() {
	this.controlBox=null;
	this.controlBoxChecked=null;
	this.maxAllowed=null;
	this.maxAllowedMessage=null;
	this.masterBehavior=null;
	this.formRef=null;
	this.checkboxWildcardNames=new Array();
	this.checkboxNames=new Array();
	this.totalBoxes=0;
	this.totalSelected=0;
	// Public methods
	this.setControlBox=CBG_setControlBox;
	this.setMaxAllowed=CBG_setMaxAllowed;
	this.setMasterBehavior=CBG_setMasterBehavior;	// all, some
	this.addToGroup=CBG_addToGroup;
	// Private methods
	this.expandWildcards=CBG_expandWildcards;
	this.addWildcardCheckboxes=CBG_addWildcardCheckboxes;
	this.addArrayCheckboxes=CBG_addArrayCheckboxes;
	this.addSingleCheckbox=CBG_addSingleCheckbox;
	this.check=CBG_check;
	}

// Set the master control checkbox name
function CBG_setControlBox(name) { this.controlBox=name; }

// Set the maximum number of checked boxes in the set, and optionally
// the message to popup when the max is reached.
function CBG_setMaxAllowed(num,msg) {
	this.maxAllowed=num;
	if (msg!=null&&msg!="") { this.maxAllowedMessage=msg; }
	}

// Set the behavior for the checkbox group master checkbox
//	All: all boxes must be checked for the master to be checked
//	Some: one or more of the boxes can be checked for the master to be checked
function CBG_setMasterBehavior(b) { this.masterBehavior = b.toLowerCase(); }

// Add checkbox wildcards to the checkboxes array
function CBG_addToGroup() {
	if (arguments.length>0) {
		for (var i=0;i<arguments.length;i++) {
			this.checkboxWildcardNames[this.checkboxWildcardNames.length]=arguments[i];
			}
		}
	}

// Expand the wildcard checkbox names given in the addToGroup method
function CBG_expandWildcards() {
	if (this.formRef==null) {alert("ERROR: No form element has been passed.  Cannot extract form name!"); return false; }
	for (var i=0; i<this.checkboxWildcardNames.length;i++) {
		var n = this.checkboxWildcardNames[i];
		var el = this.formRef[n];
		if (n.indexOf("*")!=-1) { this.addWildcardCheckboxes(n); }
		else if(CBG_nameIsArray(el)) { this.addArrayCheckboxes(n); }
		else { this.addSingleCheckbox(el); }
		}
	}


// Add checkboxes to the group which match a pattern
function CBG_addWildcardCheckboxes(name) {
	var i=name.indexOf("*");
	if ((i==0) || (i==name.length-1)) {
		searchString= (i)?name.substring(0,name.length-1):name.substring(1,name.length);
		for (var j=0;j<this.formRef.length;j++) {
			currentElement = this.formRef.elements[j];
			currentElementName=currentElement.name;
			var partialName = (i)?currentElementName.substring(0,searchString.length) : currentElementName.substring(currentElementName.length-searchString.length,currentElementName.length);
			if (partialName==searchString) {
				if(CBG_nameIsArray(currentElement)) this.addArrayCheckboxes(currentElement);
				else this.addSingleCheckbox(currentElement);
				}
			}
		}
	}

// Add checkboxes to the group which all have the same name
function CBG_addArrayCheckboxes(name) {
	if((CBG_nameIsArray(this.formRef[name])) && (this.formRef[name].length>0)) {
		for (var i=0; i<this.formRef[name].length; i++) { this.addSingleCheckbox(this.formRef[name][i]); }
		}
	}

function CBG_addSingleCheckbox(obj) {
	if (obj != this.formRef[this.controlBox]) {
		this.checkboxNames[this.checkboxNames.length]=obj;
		this.totalBoxes++;
		if (obj.checked) {
			this.totalSelected++;
			}
		}
	}

// Runs whenever a checkbox in the group is clicked
function CBG_check(obj) {
	var checked=obj.checked;
	if (this.formRef==null) {
		this.formRef=obj.form;
		this.expandWildcards();
		if (this.controlBox==null || obj.name!=this.controlBox) {
			this.totalSelected += (checked)?-1:1;
			}
		}
	if (this.controlBox!=null&&obj.name==this.controlBox) {
		if (this.masterBehavior=="all") {
			for (i=0;i<this.checkboxNames.length;i++) { this.checkboxNames[i].checked=checked; }
			this.totalSelected=(checked)?this.checkboxNames.length:0;
			}
		else {
			if (!checked) {
				obj.checked = (this.totalSelected>0)?true:false;
				obj.blur();
				}
			}
		}
	else {
		if (this.masterBehavior=="all") {
			if (!checked) {
				this.formRef[this.controlBox].checked=false;
				this.totalSelected--;
				}
			else { this.totalSelected++; }
			if (this.controlBox!=null) {
				this.formRef[this.controlBox].checked=(this.totalSelected==this.totalBoxes)?true:false;
				}
			}
		else {
			if (!obj.checked) { this.totalSelected--; }	
			else { this.totalSelected++; }
			if (this.controlBox!=null) {
				this.formRef[this.controlBox].checked=(this.totalSelected>0)?true:false;
				}
			if (this.maxAllowed!=null) {
				if (this.totalSelected>this.maxAllowed) {
					obj.checked=false;
					this.totalSelected--;
					if (this.maxAllowedMessage!=null) { alert(this.maxAllowedMessage); }
					return false;
					}
				}
			}
		}
	}

function CBG_nameIsArray(obj) {
	return ((typeof obj.type!="string")&&(obj.length>0)&&(obj[0]!=null)&&(obj[0].type=="checkbox"));
	}

/* Type-ahead combobox script */
/* **** ARRAY EXTENSION FOR NON-SUPPORTING BROWSERS **** */
if(typeof Array.prototype.push=='undefined') {
    Array.prototype.push = function () {
        var i=0,
            b=this.length,
            a=arguments;
        for(i;i<a.length;i++) {
            this[b+i]=a[i];
		}
        return this.length
    }
}
/* **** STRING EXTENSION FOR PUNCTUATION **** */
if (typeof(String.fromCharCode) == 'undefined') {
	String.fromCharCode = function () {
		if (arguments.length = 0) {
			return "";
		}
		var charCodeChars = new Array(32),
			returnString = "",
			i;
		charCodeChars[9] = '\t';
		charCodeChars[13] = '\n';
		charCodeChars.push(' ','!','"','#','$','%','',"'",'(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@');
		charCodeChars.push('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_','`');
		charCodeChars.push('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','{','|','}','~');
		for (i=0;arguments.length>i;i++) {
			returnString += charCodeChars[arguments[i]];
		}
		return returnString;
	}
}
String.fromKeyCode = function (keyCode,evtType) {
	if (!evtType || !evtType.length) {
		evtType = "keyDown";
	} else if (evtType.toLowerCase() == "keypress") {
		return String.fromCharCode(keyCode);
	}
	var keyDownChars = new Array(16);
		keyDownChars[8] = '[Bksp]';
		keyDownChars[9] = '[Tab]';
		keyDownChars[12] = '[N5+shift]';
		keyDownChars[13] = '[Enter]';
		keyDownChars.push('[Shift]','[Ctrl]','[Alt]','[Pause]','[CapsLock]');
		for (i=11;i;--i) {
			keyDownChars.push('undefined');
		}
		keyDownChars[27] = '[Esc]';
		keyDownChars.push(' ','[PgUp]','[PgDn]','[End]','[Home]','[Left]','[Up]','[Right]','[Down]');
		for (i=7;i;--i) {
			keyDownChars.push('undefined');
		}
		keyDownChars[45] = '[Ins]';
		keyDownChars[46] = '[Del]';
		keyDownChars.push(['0',')'],['1','!'],['2','@'],['3','#'],['4','$'],['5','%'],['6','^'],['7','&'],['8','*'],['9','(']);
		for (i=7;i;--i) {
			keyDownChars.push('undefined');
		}
		keyDownChars.push('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[WinKey]');
		for (i=4;i;--i) {
			keyDownChars.push('undefined');
		}
		keyDownChars.push('0','1','2','3','4','5','6','7','8','9','*','+','undefined','-','.','/','[F1]','[F2]','[F3]','[F4]','[F5]','[F6]','[F7]','[F8]','[F9]','[F10]','[F11]','[F12]');
		for (i=62;i;--i) {
			keyDownChars.push('undefined');
		}
		keyDownChars[144] = '[NumLock]';
		keyDownChars[145] = '[ScrollLock]';
		keyDownChars.push([';',':'],['=','+'],[',','<'],['-','_'],['.','>'],['/','?'],['`','~']);
		for (i=26;i;--i) {
			keyDownChars.push('undefined')
		}
		keyDownChars.push(['[','{'],['\\','|'],[']','}'],["'",'"']);
	return keyDownChars[keyCode];
}

/* **** COMBOBOX CODE **** */
/**************************************************
Original Version (1.0):
Glenn G. Vergara
http://www21.brinkster.com/gver/
glenngv AT yahoo DOT com
Makati City, Philippines

Object-Based Version:
Eric C. Davis
http://www.10mar2001.com/
eric AT 10mar2001 DOT com
Atlanta, GA, US

(Keep the above intact if you want to use it! Thanks.)

Current Version: 2.5b
Last Update: 1 December 2003

********
Change Log:
New in version 2.5b:
	- Reversed selectItem() loop to prevent default IE6/Win rapid-change behaviour (skipped to second on match of first)
	- Outfitted for DOM2-style event handling; uses detection and falls back to DOM0 events
	- Resets immediately on ALT+TAB to prevent IE6/Win's loss of the reset timer.

New in version 2.4:
	- Added accepting of non-existent option
	- Added punctuation as acceptable input
	- Added setValueByValue() convenience method

New in version 2.2:
	- Many properties made private
	- Getters and setters for nearly all properties

New in version 2.0:
	- Object-oriented properties and methods using prototype
	- Constructor can accept a select element object or a select element object's ID string
	- Invocation reduced to single line of script: varName = new TypeAheadCombo('selectElementID');

New in version 1.4:
	- Allowable character set ranges use dynamic evaluation
	- Display of typed characters in status bar can be disabled

New in version 1.2:
	- Replaced major if/elseif/.../else statement with switch/case
	- Correction of characters typed on the numpad, reassigning to actual character values
********

********
API:
Constructor:
	new TypeAheadCombo(someSelectElement) // as an object or object reference
	new TypeAheadCombo('someSelectElementID') // as a string
	new TypeAheadCombobox('someSelectElementID', true) // to allow an undefined value

Privileged Methods: (these interact with private properties and act as helper functions)
	getTyped()
		- returns the string typed by the user since the last timeout
	setTyped(str)
		- argument "str" - string which will replace the value in the type buffer
	type(str)
		- argument "str" - string which will be appended to the type buffer
	resetTyped()
		- clears what has been typed from the buffer
	getIndex()
		- returns the location of the option currently selected
	setIndex(val)
		- stores the location of the option being selected
	getPrev()
		- returns the location of the option previously selected
	setPrev(val)
		- stores the location of the option previously selected
	setResetTime(val)
		- sets the timeout interval for the reset timers
	getResetTime()
		- returns the timeout interval for the reset timers
	setResetTimer()
		- sets the timeout for the reset of the typed buffer
	clearResetTimer()
		- clears the timeout of the reset of the typed buffer
	validChar(charCode)
		- validates that the charCode passed is acceptable to the typed buffer
	setDisplayStatus(bool)
		- set whether to display the typed buffer in the status bar
	getDisplayStatus()
		- returns the current setting for status bar display of the typed buffer

Public Methods:
	detectKey()
		- detects the keyCode, parses whether it is acceptable, and adds it to the typed buffer if so
	selectItem()
		- finds the first option that matches the typed buffer and selects it
	reset()
		- clears the typed buffer and the status display
	updateIndex()
		- handles the onclick and onblur events
	elementFocus()
		- handles the onfocus event
	elementKeydown()
		- handles the onkeydown event
********

***************************************************/
function TypeAheadCombo (anElement,acceptNewValue) {
	// DEGRADE UNSUPPORTED
	if (document.layers) {
		return;
	}
	// VALIDATION
	if (!anElement) {
		return false;
	}
	if (typeof anElement == "string") { // try for the ID
		anElement = document.getElementById ? document.getElementById(anElement) : document.all ? document.all[anElement] : anElement;
	}
	if (typeof anElement == "string") { // the grab failed: typeof null yields "object"
		return false;
	}
	// ASSOCIATION
	this.element = anElement;
	this.id = this.element.id + 'Combo';
	this.element.combo = this;
	// ELEMENT EVENT HANDLERS
	if (this.element.addEventListener) {
		// first try DOM2 methods
		this.element.addEventListener("keydown", this.elementKeydown, false);
		this.element.addEventListener("focus", this.elementFocus, false);
		this.element.addEventListener("click", this.updateIndex, false);
		this.element.addEventListener("blur", this.updateIndex, false);
	} else {
		// now try DOM0 methods
		this.element.onkeydown = this.elementKeydown;
		this.element.onfocus = this.elementFocus;
		this.element.onclick = this.updateIndex;
		this.element.onblur = this.updateIndex;
	}
	this.element.reset = this.reset;
	// PRIVATE PROPERTIES
	var self = this,	// corrects privatization bug
		typed = "",
		index = prev = 0,
		displayStatus = true,
		selector, resetter, nullStarter, acceptNew,
		resetTime = 1600,
		numberRangeStart = 48,
		numberRangeEnd = 57,
		charRangeStart = 65,
		charRangeEnd = 90,
		punctRangeStart = 146,
		punctRangeEnd = 223;
	if (this.element.options[0].text.length == 0 && (this.element.options[0].value.length == 0 || this.element.options[0].value == 0)) {
		nullStarter = true;
	} else {
		nullStarter = false;
	}
	if (typeof acceptNewValue != 'undefined' && acceptNewValue) {
		acceptNew = true;
		resetTime = 2400;
	} else {
		acceptNew = false;
	}
	// PRIVATE METHODS
	var getResetTime = function () {
		return resetTime;
	}
	var charInRanges = function (charCode) {
		if ((charCode >= numberRangeStart && charCode <= numberRangeEnd) || (charCode >= charRangeStart && charCode <= charRangeEnd) || (charCode >= punctRangeStart && charCode <= punctRangeEnd)) {
			return true;
		} else {
			return false;
		}
	}
	// PRIVILEDGED METHODS
	this.hasNullStarter = function () {
		return nullStarter;
	}
	this.getAcceptsNew = function () {
		return acceptNew;
	}
	this.getTyped = function () {
		return typed;
	}
	this.setTyped = function (str) {
		typed = str;
		return true;
	}
	this.resetTyped = function () {
		typed = "";
		return true;
	}
	this.type = function (str) {
		typed += str;
		return true;
	}
	this.getIndex = function () {
		return index;
	}
	this.setIndex = function (val) {
		if (!isNaN(val)) {
			index = val;
		}
	}
	this.getPrev = function () {
		return (prev ? prev : 0);
	}
	this.setPrev = function (val) {
		if (!isNaN(val)) {
			prev = val;
		}
	}
	this.setResetTime = function (val) {
		if (!isNaN(val)) {
			resetTime = val;
		}
	}
	this.setResetTimer = function () {
		resetter = setTimeout("document.forms['"+this.element.form.name+"'].elements['"+this.element.name+"'].reset();", getResetTime());
	}
	this.clearResetTimer = function () {
		clearTimeout(resetter);
	}
	this.delayedSelect = function () {
		selector = setTimeout("document.forms['"+this.element.form.name+"'].elements['"+this.element.name+"'].combo.selectItem();", 10);
	}
	this.cancelDelay = function () {
		clearTimeout(selector);
	}
	this.validChar = function (evt, charCode) {
		if ((evt.ctrlKey) || (evt.altKey)) {
			return false;
		} else if ((evt.shiftKey) && charInRanges(charCode)) {
			return true;
		} else if (evt.shiftKey) {
			return false;
		} else {
			return charInRanges(charCode);
		}
	}
	this.setDisplayStatus = function (bool) {
		if (bool == true || bool == false) {
			displayStatus = bool;
		}
	}
	this.getDisplayStatus = function () {
		return displayStatus;
	}
	this.cancel = function (evt) {
		if (evt) {
			evt.preventDefault();
		} else {
			window.event.returnValue = false;
		}
		return false;
	}
}

/*
PUBLIC METHODS
*/

TypeAheadCombo.prototype.detectKey = function (evt){
	this.clearResetTimer();
	this.cancelDelay();
	var combo_letter = "";
	var combo_code = (evt) ? evt.keyCode : window.event ? window.event.keyCode : evt.which;
	var event = (evt) ? evt : window.event;
	if (combo_code <= 105 && combo_code >= 96) { // make up for numPad typing
		combo_code = combo_code - 48;
	}
	switch (combo_code) {
		case 27:	//ESC key
			this.reset();
			this.setIndex(this.getPrev());
			// Put a little delay to override NS6/Mozilla's built-in behavior of ESC inside select element
			setTimeout("document.forms['"+this.element.form.name+"'].elements['"+this.element.name+"'].selectedIndex = document.forms['"+this.element.form.name+"'].elements['"+this.element.name+"'].index",0);
			return false;
			break;
		case 13:	//ENTER key
		case 9:		//TAB key
			this.reset();
			if (this.element.onchange) {
				// set timer to prevent stack overflow in IE.
				setTimeout("document.forms['" + this.element.form.name + "'].elements['" + this.element.name + "'].onchange()", 1);
			}
			return true;
			break;
		case 8:		//BACKSPACE key
			this.setTyped(this.getTyped().substring(0,this.getTyped().length-1));
			if (this.getAcceptsNew() && this.getIndex() == 0) {
				this.makeNewValue();
			}
			if (this.getTyped() == "") {
				this.reset();
				this.setIndex(this.getPrev());
				this.element.selectedIndex = this.getIndex();
				if (evt) {
					evt.preventDefault();
				} else {
					window.event.returnValue = false;
				}
				return false;
			} else {
				this.setResetTimer();
			}
			break;
		case 33:	//PAGEUP key
		case 34:	//PAGEDOWN key
		case 35:	//END key
		case 36:	//HOME key
		case 38:	//UP arrow
		case 40:	//DOWN arrow
			this.reset();
			return true;
			break;
		case 37:	//LEFT arrow	(translates to %)
		case 39:	//RIGHT arrow	(translates to ')
			this.reset();
			return false;
			break;
		case 32:	//SPACE key	(not in accepted ranges)
			combo_letter = " ";
			this.setResetTimer();
			break;
		default:
			if (this.validChar(event, combo_code)) {
				combo_letter = String.fromKeyCode(combo_code);
				if (combo_letter.length > 1) {
					if (event.shiftKey) {
						combo_letter = combo_letter[1];
					} else {
						combo_letter = combo_letter[0];
					}
				}
				this.setResetTimer();
			} else {
				return true;
			}
			break;
	}
	this.type(combo_letter);
	if (this.getDisplayStatus()) {
		window.status = this.getTyped();
	}
	if (document.all) {
		return this.selectItem();
	} else {
		return this.delayedSelect();
	}
}

TypeAheadCombo.prototype.selectItem = function (){
	var i = this.element.options.length,
		match = false;
	do {
		if (this.element.options[--i].text.toUpperCase().indexOf(this.getTyped().toUpperCase()) == 0){
			this.element.selectedIndex = i;
			this.setIndex(i);	//remember selected index
			match = true;
		}
	} while (i > 0);
	if (match) {
		return false; // always return false;
	}
	if (this.getAcceptsNew()) {
		this.makeNewValue();
	} else {
		this.element.selectedIndex = this.getIndex();	//re-select previously selected option even if there's no match
	}
	return false;  //always return false
}

TypeAheadCombo.prototype.makeNewValue = function () {
	this.removeNewValue();
	var tmpText = this.getTyped(),tmpStart = tmpEnd = "",tmpArr,i;
	if (this.hasNullStarter()) {
		newOption = this.element.options[0];
	} else if (tmpText.length > 0) {
		newOption = document.createElement("option");
		this.element.insertBefore(newOption, this.element.firstChild);
		this.newOption = newOption;
	} else {
		this.newOption = null;
		return;
	}
	tmpArr = tmpText.split(" ");
	i = tmpArr.length;
	if (tmpText.indexOf(" ") >= 0) {
		do {
			tmpStart = tmpArr[--i].substring(0,1);
			tmpEnd = tmpArr[i].substring(1,tmpArr[i].length);
			tmpArr[i] = tmpStart.toUpperCase() + tmpEnd.toLowerCase();
		} while (i);
		tmpText = tmpArr.join(" ");
	} else {
		tmpStart = tmpText.substring(0,1);
		tmpEnd = tmpText.substring(1,tmpText.length);
		tmpText = tmpStart.toUpperCase() + tmpEnd.toLowerCase();
	}
	newOption.value = tmpText;
	newOption.text = tmpText;
	this.element.selectedIndex = 0;
	this.setIndex(0);
}

TypeAheadCombo.prototype.removeNewValue = function () {
	if (this.hasNullStarter()) {
		this.element.options[0].text = '';
		this.element.options[0].value = '';
	} else if (this.newOption) {
		this.element.remove(this.newOption);
	}
}

TypeAheadCombo.prototype.setValueByValue = function (aValue) {
	var i = this.element.options.length;
	do {
		if (this.element.options[--i].value == aValue) {
			this.element.selectedIndex = i;
			break;
		}
	} while (i);
}

TypeAheadCombo.prototype.reset = function () {
	theCombo = this;
	if (this.combo) {
		theCombo = this.combo;
	}
	theCombo.element.selectedIndex = theCombo.getIndex();
	theCombo.resetTyped();
	if (theCombo.getDisplayStatus()) {
		window.status = window.defaultStatus ? window.defaultStatus : '';
	}
}

TypeAheadCombo.prototype.updateIndex = function (evt){
	var theCombo, theEl;
	if (evt && window.addEventListener) {
		// ready for handler with DOM2 event properties
		var e = new DOM2Event(evt, window.event, this);
		theEl = e.target;
	} else {
		theEl = this;
	}
	theCombo = theEl.combo;
	theCombo.setIndex(theEl.selectedIndex);
	theCombo.setPrev(theCombo.getIndex());
}

TypeAheadCombo.prototype.elementFocus = function (evt) {
	var theCombo;
	if (evt && window.addEventListener) {
		// ready for handler with DOM2 event properties
		var e = new DOM2Event(evt, window.event, this);
		theCombo = e.target.combo;
	} else {
		theCombo = this.combo;
	}
	theCombo.setIndex(theCombo.element.selectedIndex);
}

TypeAheadCombo.prototype.elementKeydown = function (evt) {
	var theCombo;
	if (evt && window.addEventListener) {
		// ready for handler with DOM2 event properties
		if (DOM2Event) {
			var e = new DOM2Event(evt, window.event, this);
		}
		theCombo = e.target.combo;
	} else {
		theCombo = this.combo;
	}
	if (!theCombo.detectKey(e)) {
		return theCombo.cancel(e);
	}
}
