<!--
/**
I do not know the author of some of these scripts. I did not strip any
names or credit intentionally. 
If you own it and want credit, please let me know russellsimpkins@hotmail.com.

Feel free to use this script and add it to your toolbox.
**/

var showit;

/**
 * Application specific function used to set visible/hidden based on cookie
 **/
function initialHide(target) {
    var showit = getCookie(target);
    var remember = getCookie(target);
    if (remember == undefined || remember == null) return;
    if (showit == undefined || showit == null) return;
    if (showit == 0) {
        hide(target,'hidden');
    }
}
/**
 * Application specific code to show one while hiding another. I suppose
 * I could have called this toggle.
 **/
function showhide(target,force) {
    date = new Date();
    date.setUTCFullYear( date.getUTCFullYear() + 3 );

    if (force != null && force == true) {
        showit=1;
        setCookie(target,1,date);
        show(target);
        return;
    }
    if (showit==null) {
        showit = getCookie(target);
    }
    if (showit == undefined || showit == null) {
        showit=0;
        hide(target);
        setCookie(target,showit,date);
    } else {
        if (showit == 1) {
            showit=0;
            setCookie(target,showit,date);
            hide(target);
        } else {
            showit=1;
            setCookie(target,showit,date);
            show(target);
        }
    }
}
/**
 * A simple function to make what was once hidden, visible
 **/
function show(target,showclass){
    o = getAnObject(target);
    if (showclass != undefined && showclass!=null) {
        o.className = showclass;
    } else {
        // default 
        o.className = 'visible';
    }
}
/**
 * A simple function to make what was once visible, hidden
 **/
function hide(target,hideclass){
    o = getAnObject(target);
    if (hideclass != undefined && hideclass!=null) {
        o.className = hideclass;
    } else {
        o.className = 'hidden';
    }
}
/**
 * Checks to see if a given variable is empty, just like in php
 * author: russellsimpkins@hotmail.com
 **/
function empty(value) {
    if( value == null ||
        value == "" ||
        value == 0 ||
        trim(value) == ""
        ) {
        return true;
    }
    return false;
}
/**
 * Helper function to check valid dates
 * It intellignetly tries to determine one of the date separators and
 * author: russellsimpkins@hotmail.com
 **/
function valiDate( tdate, sep ) {
    if (sep == null || sep == "") sep = "/";
    document.write("<br>sep: " + sep);
    if ( tdate.indexOf(sep) > 0 ) {
        parts = tdate.split(sep);
        if ( parts.length != 3 ) return false;
        if ( parts[0].length == 4 ) {
            // test using YYYY/MM/DD format
            return checkDate( parts[1],parts[2],parts[0] );
        } else {
            // test using MM/DD/YYYY
            return checkDate( parts[0], parts[1], parts[2] );
        }
    }
    return false;
}
/**
 * Validates a given date
 * author: russellsimpkins@hotmail.com
 **/
function checkDate( month, day, year ) {
    months = new Array(32,29,32,31,32,31,32,32,31,32,31,32);
    // set the low year
    lowyear = 1880;
    if (--month < 0) return false;
    if ( year <= lowyear ) return false;
    // leap year test
    if ( (year%4) == 0 ) months[1]=30;
    if ( month < 12 && day > 0  && day < months[month] ) {
        return true;
    } else {
        return false;
    }
}
/**
 * Validate zipcodes basic structure is correct.
 * author: russellsimpkins@hotmail.com
 **/
function validZip( zipcode ) {
    tester = new String( zipcode );
    if ( tester.indexOf( "-" )) {
        tester = tester.replace(new RegExp("-","g"),"");
        if ( isNaN( tester ) ) return false;
        if ( tester.length == 9 ) return true;
    }
    if ( isNaN( tester ) ) return false;
    if ( tester.length == 5 ) return true;
    return false;
}
/**
 * Validate zipcodes basic structure is correct.
 * author: russellsimpkins@hotmail.com
 **/
function validPhone( phonenum ) {
    tester = new String( phonenum );
    if ( tester == null ) return false;
    tester = tester.replace(new RegExp("\\.","g"),"");
    tester = tester.replace(new RegExp("-","g"),"");
    tester = tester.replace(new RegExp("x","g"),"");
    //alert(tester + isNaN( tester ));
    if ( isNaN( tester ) ) return false;
    if ( tester.length < 10 ) {
        return false;
    }
    return true;
}
/**
 * Email validator
 * author: unknown
 **/
function checkEmail(src) {
     var regex = new RegExp("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$");
     return regex.test(src);
}
/**
 * Quick and dirty trim string function. It is recursive.
 * author: russellsimpkins@hotmail.com
 **/
function trim( str ) {
    if ( str.charAt(0) == " ")
        return trim( str.substr(1) );
    if ( str.charAt( str.length - 1 ) == " ")
        return trim( str.substr(0, str.length - 2) );
    return str;
}
/**
 * Cross-browser script to style object. Make sure id and name are set
 * DOES NOT ALWAYS WORK WELL WITH LAYERS
 * found at apple developer site... author unknown
 **/
function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if (document.all && document.all(objectId)) {
        // MSIE 4 DOM
        return document.all(objectId).style;
    } else if(document.getElementById && document.getElementById(objectId)) {
        // W3C DOM
        return document.getElementById(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
        // NN 4 DOM.. note: this won't find nested layers
        return document.layers[objectId];
    } else {
        return false;
    }
}
/**
 * Cross-browser script to an object. Make sure id and name are set.
 * DOES NOT ALWAYS WORK WELL WITH LAYERS
 * found at apple developer site... author unknown
 **/
function getAnObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if (document.getElementById && document.getElementById(objectId)) {
        // W3C DOM
        return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
        // MSIE 4 DOM
        return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
        // NN 4 DOM.. note: this won't find nested layers
        return document.layers[objectId];
    } else {
        return false;
    }
} // getAnObject

/**
 * Simple script to flip images. You should
 * author: unknown
 **/
function imgFlip(target,changeto) {
    if (menuItem==changeto) return;
    found = getAnObject( target );
    found.src = eval(changeto + ".src");
}

/**
 * Simple script to open a popup window
 * author: russellsimpkins@hotmail.com
 **/
function openPop(theURL,winName,features) {
    if (theURL==null) theURL="/";
    if (winName==null) winName="default";
    if (features==null) features="width=400;height=400";
  window.open(theURL,winName,features);
}

/**
 * Simple script to change address set in a drop-down menu
 * I expect your menu to be selected and to have uri/url as options
 * i.e. <option value="http://somewhere.com">Go somewhere now</option>
 * usage <select onchange="jumpmenu(this)">
 * author: russellsimpkins@hotmail.com
 **/
function jumpmenu(menu) {
    window.location.href = menu.options[menu.selectedIndex].value;
}

/**
 * One way to always get a form.
 * author: russellsimpkins@hotmail.com
 **/
function getForm( id ) {
    var allforms = document.forms;
    var index = 0;
    for ( index = 0; index < allforms.length; ++index) {
        if ( allforms[index].id == id ) {
            return allforms[index];
        }
    }
    return null;
}
/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 * found on the web... author unknown
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 * found on the web... author unknown
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + '=' + escape(value) +
        ((expires) ? '; expires=' + expires.toGMTString() : '') +
        ((path) ? '; path=' + path : '') +
        ((domain) ? '; domain=' + domain : '') +
        ((secure) ? '; secure' : '');
}
/**
 * This function deletes a cookie by destroying the value
 * and setting the expires date to yesterday.
 * found on the web... author unknown
 */
function deleteCookie ( cookie, path, domain ) {
  var cookie_date = new Date ( );
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie += '=; expires=' + 
  cookie_date.toGMTString() + 
  ((path) ? '; path=' + path : '') +
  ((domain) ? '; domain=' + domain : '');
}

/**
 * Selects all items in a select box.
 * author: unknown
 **/
function selectAll(selectObj) {
      if (selectObj == null) return false;
    if (selectObj.options.length == 0) return false;
    for (var i = 0; i < selectObj.length; i++) {
        selectObj.options[i].selected = true;
    }
    return;
}
/**
 * un-selects all items in a multi-select box
 * author: unknown
 **/
function unSelectAll(selectObj) {
    if (selectObj == null) return false;
    for (var i = 0; i < selectObj.length; i++) {
        selectObj.options[i].selected = false;
    }
    return true;
}
/**
 * Do nothing function
 * author: unknown
 **/
function doNothing() {
}
/**
 * The next set of functions are helper functions for multi-select boxes.
 **/
var MOVE_FIRST = 1;
var MOVE_LAST = 2;
var MOVE_UP = 3;
var MOVE_DOWN = 4;
/**
 * Helper function to simplify script in html
 * author: unknown
 **/
function move(selectObj, direction) {
    if (selectObj == null) return false;
    switch (direction) {
        case MOVE_FIRST:
            moveFIRST(selectObj);
            break;
        case MOVE_LAST:
            moveLAST(selectObj);
            break;
        case MOVE_UP:
            moveUP(selectObj);
            break;
        case MOVE_DOWN:
            moveDOWN(selectObj);
            break;
    }
}
/**
 * Helper function to selected
 * author: unknown
 **/
function moveUP(selectObj) {
    if ((selectObj == null) || (selectObj.selectedIndex < 0)) return false;
    var topIndex = 0;
    var arr = new Array(selectObj.options.length);
    for (var i = 0; i < selectObj.options.length; i++) {
        if (selectObj.options[i].selected) {
            if (i == topIndex) {
                topIndex++;
                arr[i] = true;
            } else {
                var option = new Option(); // save the previous option
                option.value = selectObj.options[i - 1].value;
                option.text = selectObj.options[i - 1].text;

                selectObj.options[i - 1].value = selectObj.options[i].value;
                selectObj.options[i - 1].text = selectObj.options[i].text;
                selectObj.options[i].value = option.value;
                selectObj.options[i].text = option.text;
                arr[i - 1] = true;
            }
        } else {
            arr[i] = false;
        }
    }
    // highlight moved options
    for (var i = 0; i < arr.length; i++) {
        selectObj.options[i].selected = arr[i];
    }
    return true;
}
/**
 * Helper function to selected
 * author: unknown
 **/
function moveDOWN(selectObj) {
    if ((selectObj == null) || (selectObj.selectedIndex < 0)) return false;
    var bottomIndex = selectObj.options.length - 1;
    var arr = new Array(selectObj.options.length);
    for (var i = selectObj.options.length - 1; i >= 0; i--) {
        if (selectObj.options[i].selected) {
            if (i == bottomIndex) {
                bottomIndex--;
                arr[i] = true;
            } else {
                var option = new Option();
                option.value = selectObj.options[i + 1].value;
                option.text = selectObj.options[i + 1].text;
                selectObj.options[i + 1].value = selectObj.options[i].value;
                selectObj.options[i + 1].text = selectObj.options[i].text;
                selectObj.options[i].value = option.value;
                selectObj.options[i].text = option.text;
                arr[i + 1] = true; // save value for highlight later
            }
        } else {
            arr[i] = false;
        }
    }
    // highlight moved options
    for (var i = 0; i < arr.length; i++) {
        selectObj.options[i].selected = arr[i];
    }
    return true;
}
/**
 * Helper function to selected
 * author: unknown
 **/
function moveLAST(selectObj) {

    if ((selectObj == null) || (selectObj.selectedIndex < 0)) return false;
    var bottomIndex = selectObj.options.length - 1;
    var arr = new Array(selectObj.options.length);
    index = selectObj.selectedIndex;
    end = bottomIndex;
    foption = selectObj.options[index];

    for ( i = 0; i < end; ++i) {
        if (selectObj.options[i].selected) {
            var option = new Option();
            option.value = selectObj.options[i + 1].value;
            option.text = selectObj.options[i + 1].text;
            selectObj.options[i + 1].value = selectObj.options[i].value;
            selectObj.options[i + 1].text = selectObj.options[i].text;
            selectObj.options[i + 1].selected = true;
            selectObj.options[i].value = option.value;
            selectObj.options[i].text = option.text;
            selectObj.options[i].selected = false;
        }
    }

    return true;
}
/**
 * Helper function to selected
 * author: unknown
 **/
function moveFIRST(selectObj) {
    if ((selectObj == null) || (selectObj.selectedIndex < 0)) return false;
    var bottomIndex = selectObj.options.length - 1;
    var arr = new Array(selectObj.options.length);
    index = selectObj.selectedIndex;
    end = 0;
    foption = selectObj.options[index];
    for ( i = bottomIndex; i > end ; --i) {
        if (selectObj.options[i].selected) {
            var option = new Option();
            option.value = selectObj.options[i - 1].value;
            option.text = selectObj.options[i - 1].text;
            selectObj.options[i - 1].value = selectObj.options[i].value;
            selectObj.options[i - 1].text = selectObj.options[i].text;
            selectObj.options[i - 1].selected = true;
            selectObj.options[i].value = option.value;
            selectObj.options[i].text = option.text;
            selectObj.options[i].selected = false;
        }
    }
    return true;
}
/**
 * A nice little funtion to fix character codes above 126
 **/
function fixString(stringtofix) {
    var newstring = new String();
    for (i=0;i < stringtofix.length; i++) {
    if(stringtofix.charCodeAt(i) > 126){
            newstring += "&#" + stringtofix.charCodeAt(i) + ";";
        } else {
            newstring += stringtofix.charAt(i);
        }
    }
    return newstring;
}
/**
 * A nice little function to find an element by name or id and value.
 * Useful when you want to select a checkbox that has the same name but
 * different values. It will go through all elements of all forms until
 * it finds a match, then set checked=true
 *
 *@param item - the name or id of the element you should set both name and
 *				and id for all elements to be cross browser compliant.
 *@param value - the value that uniquely identifies the element.
 *@author - russellsimpkins@hotmail.com
 **/
function check(item,value) {
    forms = document.forms;
    for (outer=0;outer<forms.length;++outer) {
    form=forms[outer];
        elements = form.elements;
        for (i=0;i<elements.length;++i) {
            element = elements[i];
            if (element.name!=undefined && element.name==item && element.value==value) {
                element.checked=true;
                return;
            }
            if (element.id!=undefined && element.id==item && element.value==value) {
                element.checked=true;
                return;
            }
        }
    }
}
/**
 * This function cleans up a number by removing all
 * non numbers
 */
function clean_no (cc_no) { 
    // Remove non-numeric characters from cc_no
    return cc_no.replace(new RegExp("[^0-9]+"), ""); 
} 

/**
 * This function tells you which credit card you have based on the
 * credit card number
 */
function identify (cc_no) { 
     cc_no = clean_no (cc_no); 
    // Get card type based on prefix and length of card number 
    var regex = new RegExp("^4(.{12}|.{15})$");
    if (regex.test(cc_no))
        return 'Visa';
    regex = new RegExp("^5[1-5].{14}$");
    if (regex.test(cc_no))
        return 'Mastercard';
    regex = new RegExp("^3[47].{13}$");
    if (regex.test(cc_no))
        return 'American Express';
    regex = new RegExp("^3(0[0-5].{11}|[68].{12})$");
    if (regex.test(cc_no))
        return 'Diners Club/Carte Blanche';
    regex = new RegExp("^6011.{12}$");
    if (regex.test(cc_no))
        return 'Discover Card';
    regex = new RegExp("^(3.{15}|(2131|1800).{11})$");
    if (regex.test(cc_no))
        return 'JCB';
    regex = new RegExp("^2(014|149).{11})$");
    if (regex.test(cc_no))
        return 'enRoute';
    return 'unknown'; 
}
/**
 * This function give you a string in reverse
 */
function strrev( str ) {
    if (str == undefined || str == null || str == "") 
        return str;
    var newStr = new String();
    for (index = str.length-1;index>=0; --index) {
        newStr+=str.substr(index,1);
    }
    
    return newStr;
}
/**
 * This function validates a credit card number
 */
function validate (cc_no) { 
    // Reverse and clean the number 
    cc_no = strrev ( clean_no(cc_no) ); 
     
    // VALIDATION ALGORITHM 
    // Loop through the number one digit at a time 
    // Double the value of every second digit (starting from the right) 
    // Concatenate the new values with the unaffected digits 
    digits = "";
    sum=new Number();
    for (index = 0; index < cc_no.length; ++index) {
        digits += (index % 2) ? cc_no.charAt(index) * 2 : cc_no.charAt(index); 
    }
    // Add all of the single digits together 
    for (index = 0; index < digits.length; ++index) {
        sum += Number(digits.charAt(index)); 
    }
    
    // Valid card numbers will be transformed into a multiple of 10 
    return (sum % 10) ? false : true; 
} 
/**
 * utility method to validate and identify a credit card number
 */
function check (cc_no) { 
    valid = validate(cc_no); 
    type  = identify(cc_no);
    ret = new Array();
    ret[0] = valid;
    ret[1] = type;
    ret['valid'] = valid;
    ret['type'] = type;
    return ret;
}
/**
 * Simple function to open pop-up windows.
 **/
function openWin(url,name,height,width,details) {
    if (name == null) {
        name='preview';
    }
	if (height==null || height=="") height=600;
	if (width==null || width=="") width=600;
	if (details == null || details=="") details='scrollbars=yes,resizable=yes,menubar=yes,location=yes,status=yes,toolbar=yes,height=' + height +',width=' + width;
    x = window.open(url,name,details);
	x.focus();
    return;
}
/** 
 * Use this to close your pop-up and refresh the calling
 * page. Doesn't work so well if the parent page was from a post.
 **/
function closeme() {
    window.close();
    window.opener.focus();
    window.opener.location.href=window.opener.location.href;
    return false;
}
function resetform(name) {
	myform = getAnObject(name);
    myform.reset();
}
function submitform(name) {
	myform = getAnObject(name);
    myform.submit();
}
// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4,
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection

// 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, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV
// (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_nav6, is_nav6up, is_gecko, is_ie3,
//     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,
//     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
// (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_winme, is_win2k
//     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
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when new versions of browsers are released, so
// in conditional code forks, use is_ie5up ("IE 5.0 or greater")
// is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5
// to check version in code which you want to work on future
// versions.

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    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));
    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_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

    // 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_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_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1);

    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));

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3) is_js = 1.1;
    else if (is_opera5up) is_js = 1.3;
    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_hotjava3up) is_js = 1.4;
    else if (is_nav6 || is_gecko) 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_nav6up) is_js = 1.5;
    // NOTE: ie5up on mac is 1.4
    else if (is_ie5up) is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else is_js = 0.0;

    // *** 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));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // 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);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) is_js = 1.4;
    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));

//-->

function calc(form) {
    var gender = getAnObject("gender");
    gender = gender.value;
    age = getAnObject("age");
    if (!empty(age.value)) {
        age = age.value;
    } else {
        alert("Please enter your age.");
        age.focus();
        return;
    }
    height = getAnObject("height");
    if (!empty(height.value)) {
        height = height.value;
    } else {
        alert("Please enter your height.");
        height.focus();
        return;
    }
    weight = getAnObject("weight");
    if (!empty(weight.value)) {
        weight = weight.value;
    } else {
        alert("Please enter your weight.");
        weight.focus();
        return;
    }
    lweight = getAnObject("lweight");
    if (!empty(lweight.value)) {
        lweight = lweight.value;
    } else {
        alert("Please enter your last weight.");
        lweight.focus();
        return;
    }
    dweight = getAnObject("dweight");
    if (!empty(dweight.value)) {
        dweight = dweight.value;
    } else {
        alert("Please enter your desired weight.");
        dweight.focus();
        return;
    }
    dcalorie = getAnObject("dcalorie");
    if (!empty(dcalorie.value)) {
        dcalorie = dcalorie.value;
    } else {
        alert("Please enter estimated daily intake of calories.");
        dcalorie.focus();
        return;
    }
    res = lweight-weight;
    // some sane value - never give a recommendation lower than this.
    sanity=2000;
    if (res<1) {
        rec = (dcalorie - 200);
        rec = new Number(rec);
        if (rec<sanity) {
            rec = sanity;
            text = "You're doing good. Don't reduce your calorie intake to anything less than " + rec + " calories per day.";
        } else {
            text = "You should reduce your intake of calories to " + rec + " calories per day.";
        }
    } else if (res == 2) {
        rec = (dcalorie - 100);
        rec = new Number(rec);
        if (rec<sanity) {
            rec = sanity;
        }
        if (rec<sanity) {
            rec = sanity;
            text = "You're doing good. Don't reduce your calorie intake to anything less than " + rec+ " calories per day.";
        } else {
            text = "You should reduce your intake of calories to " + rec+ " calories per day.";
        }
    } else {
        text = "You're doing good. Keep your intake of calories at " + dcalorie+ " calories per day.";
    }
    what = getAnObject("bgCalcInside");
    what.innerHTML="<p class='bgResults'><strong>" + text + "</strong><br /><img src='img/spacer.gif' height='200' width='1' alt='' border='1' /></p>";
}
function testit() {
    new Ajax.Request('getdata.php',
  {
    method:'post', parameters: {company: 'example', limit: 12},
    onSuccess: function(transport,json) {
      var response = transport.responseText || "no response text";
      alert("Success! \n\n" + response);
      alert(json ? Object.inspect(transport.responseText) : "no JSON object");
    },
    onFailure: function(){ alert('Something went wrong...') }
  });
}
function submit(formname) {
    var theform = getAnObject(formname);
    if (theform) {
        theform.submit();
    }
}
function setSubmit(action,formname,id) {
    var theform = getAnObject(formname);
    var act = getAnObject('act');
    if (act) {
        act.value=action;
    }
    var tid = getAnObject('target_id');
    if (tid) {
        tid.value=id;
    }
    if (theform) {
        theform.submit();
    }
}

// this function will switch out the doctor's url. we expect there is an anchor
// named 'info' and that there are a number of static pages built named
// doctorinfo_n.html where n is the doctor id specified in the select option
// values.
function changeDoctor(selectname) {
    aselect = getAnObject(selectname);
    if (aselect) {
        // build up the filename
        what = getAnObject('info');
        if (what) {
            what.target = "doctorinfo_" + aselect.options[aselect.selectedIndex].value + ".html";
        }
    }
}

function validateCCinfo(formname) {
    theform = getAnObject(formname);
    if (theform) {
        // check what's required.
        //  zip, email, phone, cardNumber, cvc, expmonth, expyear, submitToMe
        fistName = getAnObject('firstName');
        if (fistName==false || empty(fistName.value)) {
            alert("Please enter your first name.");
            fistName.focus();
            return;
        }
        lastName = getAnObject('lastName');
        if (lastName==false || empty(lastName.value)) {
            alert("Please enter your last name.");
            lastName.focus();
            return;
        }
        address1 = getAnObject('address1');
        if (address1==false || empty(address1.value)) {
            alert("Please enter your address.");
            address1.focus();
            return;
        }
        
        city = getAnObject('city');
        if (city==false || empty(city.value)) {
            alert("Please enter your city.");
            city.focus();
            return;
        }
        zip = getAnObject('zip');
        if (zip==false || empty(zip.value)) {
            alert("Please enter your zipcode.");
            zip.focus();
            return;
        }
        email = getAnObject('email');
        if (email==false || empty(email.value)) {
            alert("Please enter your email address.");
            email.focus();
            return;
        }
        phone = getAnObject('phone');
        if (phone==false || empty(phone.value)) {
            alert("Please enter your phone number.");
            phone.focus();
            return;
        }
        
        cardNumber = getAnObject('cardNumber');
        if (cardNumber==false || empty(cardNumber.value)) {
            alert("Please enter your credit card number.");
            cardNumber.focus();
            return;
        } else {
            if (!validate(cardNumber.value)) {
                alert('That card number does not appear to be valid.');
                cardNumber.value="";
                cardNumber.focus();
                return;
            }
        }
        cvc = getAnObject('cvc');
        if (cvc==false || empty(cvc.value)) {
            alert("Please enter your card verification code.");
            cvc.focus();
            return;
        }
        expmonth = getAnObject('expmonth');
        if (expmonth==false || empty(expmonth.value)) {
            alert("Please enter your card expiration month.");
            expmonth.focus();
            return;
        }
        expyear = getAnObject('expyear');
        if (expyear==false || empty(expyear.value)) {
            alert("Please enter your card expiration year.");
            expyear.focus();
            return;
        }
        submitToMe = getAnObject('submitToMe');
        if (submitToMe==false || submitToMe.checked==false) {
            alert("You must agree to our terms before I can place your order.");
            submitToMe.focus();
            return;
        }
        theform.action.value='consultant-pay.php';
        theform.submit();
    }
    else {
        return;
    }
}