﻿/*
http://www.JSON.org/json2.js
2008-03-24

Public Domain.

NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.

See http://www.JSON.org/js.html
    
modified by Rick Strahl to support MS AJAX style
date formats
*/

if (!this.JSON2) {

    // Create a JSON object only if one does not already exist. We create the
    // object in a closure to avoid global variables.

    JSON2 = function() {

        function f(n) {    // Format integers to have at least two digits.
            return n < 10 ? '0' + n : n;
        }

        //*** RAS - removed date .toJSON for MS Ajax - string double encodes otherwise

        //        Date.prototype.toJSON = function () {

        //// Eventually, this method will be based on the date.toISOString method.
        //              
        //              // RAS MODIFIED: Return MS AJAX Style dates
        //              var xx = '"\/Date(' + this.getTime() + ')\/"';                                    
        //              return xx;
        ////            return this.getUTCFullYear()   + '-' +
        ////                 f(this.getUTCMonth() + 1) + '-' +
        ////                 f(this.getUTCDate())      + 'T' +
        ////                 f(this.getUTCHours())     + ':' +
        ////                 f(this.getUTCMinutes())   + ':' +
        ////                 f(this.getUTCSeconds())   + 'Z';
        //        };


        var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g,
            gap,
            indent,
            meta = {    // table of character substitutions
                '\b': '\\b',
                '\t': '\\t',
                '\n': '\\n',
                '\f': '\\f',
                '\r': '\\r',
                '"': '\\"',
                '\\': '\\\\'
            },
            rep;


        function quote(string) {

            // If the string contains no control characters, no quote characters, and no
            // backslash characters, then we can safely slap some quotes around it.
            // Otherwise we must also replace the offending characters with safe escape
            // sequences.

            return escapeable.test(string) ?
                '"' + string.replace(escapeable, function(a) {
                    var c = meta[a];
                    if (typeof c === 'string') {
                        return c;
                    }
                    c = a.charCodeAt();
                    return '\\u00' + Math.floor(c / 16).toString(16) +
                                               (c % 16).toString(16);
                }) + '"' :
                '"' + string + '"';
        }


        function str(key, holder) {

            // Produce a string from holder[key].

            var i,          // The loop counter.
                k,          // The member key.
                v,          // The member value.
                length,
                mind = gap,
                partial,
                value = holder[key];

            // If the value has a toJSON method, call it to obtain a replacement value.

            if (value && typeof value === 'object' &&
                    typeof value.toJSON === 'function') {
                value = value.toJSON(key);
            }

            // If we were called with a replacer function, then call the replacer to
            // obtain a replacement value.

            if (typeof rep === 'function') {
                value = rep.call(holder, key, value);
            }

            // What happens next depends on the value's type.

            switch (typeof value) {

                case 'string':
                    return quote(value);

                case 'number':

                    // JSON numbers must be finite. Encode non-finite numbers as null.

                    return isFinite(value) ? String(value) : 'null';

                case 'boolean':
                case 'null':

                    // If the value is a boolean or null, convert it to a string. Note:
                    // typeof null does not produce 'null'. The case is included here in
                    // the remote chance that this gets fixed someday.

                    return String(value);

                    // If the type is 'object', we might be dealing with an object or an array or
                    // null.

                case 'object':

                    // Due to a specification blunder in ECMAScript, typeof null is 'object',
                    // so watch out for that case.

                    if (!value) {
                        return 'null';
                    }

                    // *** RAS - MS AJAX style date encoding
                    if (value.toUTCString) {
                        var xx = '"\\/Date(' + value.getTime() + ')\\/"';
                        return xx;
                    }

                    // Make an array to hold the partial results of stringifying this object value.

                    gap += indent;
                    partial = [];

                    // If the object has a dontEnum length property, we'll treat it as an array.

                    if (typeof value.length === 'number' &&
                        !(value.propertyIsEnumerable('length'))) {

                        // The object is an array. Stringify every element. Use null as a placeholder
                        // for non-JSON values.

                        length = value.length;
                        for (i = 0; i < length; i += 1) {
                            partial[i] = str(i, value) || 'null';
                        }

                        // Join all of the elements together, separated with commas, and wrap them in
                        // brackets.

                        v = partial.length === 0 ? '[]' :
                        gap ? '[\n' + gap + partial.join(',\n' + gap) +
                                  '\n' + mind + ']' :
                              '[' + partial.join(',') + ']';
                        gap = mind;
                        return v;
                    }

                    // If the replacer is an array, use it to select the members to be stringified.

                    if (typeof rep === 'object') {
                        length = rep.length;
                        for (i = 0; i < length; i += 1) {
                            k = rep[i];
                            if (typeof k === 'string') {
                                v = str(k, value, rep);
                                if (v) {
                                    partial.push(quote(k) + (gap ? ': ' : ':') + v);
                                }
                            }
                        }
                    } else {

                        // Otherwise, iterate through all of the keys in the object.

                        for (k in value) {
                            v = str(k, value, rep);
                            if (v) {
                                partial.push(quote(k) + (gap ? ': ' : ':') + v);
                            }
                        }
                    }

                    // Join all of the member texts together, separated with commas,
                    // and wrap them in braces.

                    v = partial.length === 0 ? '{}' :
                    gap ? '{\n' + gap + partial.join(',\n' + gap) +
                              '\n' + mind + '}' :
                          '{' + partial.join(',') + '}';
                    gap = mind;
                    return v;
            }
        }


        // Return the JSON object containing the stringify, parse, and quote methods.

        return {
            stringify: function(value, replacer, space) {

                // The stringify method takes a value and an optional replacer, and an optional
                // space parameter, and returns a JSON text. The replacer can be a function
                // that can replace values, or an array of strings that will select the keys.
                // A default replacer method can be provided. Use of the space parameter can
                // produce text that is more easily readable.

                var i;
                gap = '';
                indent = '';
                if (space) {

                    // If the space parameter is a number, make an indent string containing that
                    // many spaces.

                    if (typeof space === 'number') {
                        for (i = 0; i < space; i += 1) {
                            indent += ' ';
                        }

                        // If the space parameter is a string, it will be used as the indent string.

                    } else if (typeof space === 'string') {
                        indent = space;
                    }
                }

                // If there is no replacer parameter, use the default replacer.

                if (!replacer) {
                    rep = function(key, value) {
                        if (!Object.hasOwnProperty.call(this, key)) {
                            return undefined;
                        }
                        return value;
                    };

                    // The replacer can be a function or an array. Otherwise, throw an error.

                } else if (typeof replacer === 'function' ||
                        (typeof replacer === 'object' &&
                         typeof replacer.length === 'number')) {
                    rep = replacer;
                } else {
                    throw new Error('JSON.stringify');
                }

                // Make a fake root object containing our value under the key of ''.
                // Return the result of stringifying the value.

                return str('', { '': value });
            },


            parse: function(text, reviver) {

                // The parse method takes a text and an optional reviver function, and returns
                // a JavaScript value if the text is a valid JSON text.
                var j;

                function walk(holder, key) {

                    // The walk method is used to recursively walk the resulting structure so
                    // that modifications can be made.

                    var k, v, value = holder[key];
                    if (value && typeof value === 'object') {
                        for (k in value) {
                            if (Object.hasOwnProperty.call(value, k)) {
                                v = walk(value, k);
                                if (v !== undefined) {
                                    value[k] = v;
                                } else {
                                    delete value[k];
                                }
                            }
                        }
                    }
                    return reviver.call(holder, key, value);
                }


                // Parsing happens in three stages. In the first stage, we run the text against
                // regular expressions that look for non-JSON patterns. We are especially
                // concerned with '()' and 'new' because they can cause invocation, and '='
                // because it can cause mutation. But just to be safe, we want to reject all
                // unexpected forms.

                // We split the first stage into 4 regexp operations in order to work around
                // crippling inefficiencies in IE's and Safari's regexp engines. First we
                // replace all backslash pairs with '@' (a non-JSON character). Second, we
                // replace all simple value tokens with ']' characters. Third, we delete all
                // open brackets that follow a colon or comma or that begin the text. Finally,
                // we look to see that the remaining characters are only whitespace or ']' or
                // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.

                if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

                    // In the second stage we use the eval function to compile the text into a
                    // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
                    // in JavaScript: it can begin a block or an object literal. We wrap the text
                    // in parens to eliminate the ambiguity.


                    // *** RAS Update:  Fix up Dates: ISO and MS AJAX format support        
                    var regEx = /(\"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}.*?\")|(\"\\*\/Date\(.*?\)\\*\/")/g;
                    text = text.replace(regEx, this.regExDate);
                    // *** End RAS Update

                    j = eval('(' + text + ')');

                    // In the optional third stage, we recursively walk the new structure, passing
                    // each name/value pair to a reviver function for possible transformation.

                    return typeof reviver === 'function' ?
                        walk({ '': j }, '') : j;
                }

                // If the text is not JSON parseable, then a  is thrown.
                throw new SyntaxError('JSON.parse');
            },
            // *** RAS Update: RegEx handler for dates ISO and MS AJAX style
            regExDate: function(str, p1, p2, offset, s) {
                str = str.substring(1).replace('"', '');
                var date = str;

                // MS Ajax date: /Date(19834141)/
                if (/\/Date(.*)\//.test(str)) {
                    str = str.match(/Date\((.*?)\)/)[1];
                    date = "new Date(" + parseInt(str) + ")";
                }
                else { // ISO Date 2007-12-31T23:59:59Z                                     
                    var matches = str.split(/[-,:,T,Z]/);
                    matches[1] = (parseInt(matches[1], 0) - 1).toString();
                    date = "new Date(Date.UTC(" + matches.join(",") + "))";
                }
                return date;
            },

            quote: quote
        };
    } ();
}

(function($) { $.fn.autogrow = function(options) { this.filter('textarea').each(function() { var $this = $(this), minHeight = $this.height(), lineHeight = $this.css('lineHeight'); var shadow = $('<div></div>').css({ position: 'absolute', top: -10000, left: -10000, width: $(this).width() - parseInt($this.css('paddingLeft')) - parseInt($this.css('paddingRight')), fontSize: $this.css('fontSize'), fontFamily: $this.css('fontFamily'), lineHeight: $this.css('lineHeight'), resize: 'none' }).appendTo(document.body); var update = function() { var times = function(string, number) { for (var i = 0, r = ''; i < number; i++) r += string; return r; }; var val = this.value.replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&').replace(/\n$/, '<br/> ').replace(/\n/g, '<br/>').replace(/ {2,}/g, function(space) { return times(' ', space.length - 1) + ' ' }); shadow.html(val); $(this).css('height', Math.max(shadow.height() + 20, minHeight)); }; $(this).change(update).keyup(update).keydown(update); update.apply(this); }); return this; } })(jQuery);
eval(function(p, a, c, k, e, d) { e = function(c) { return (c < a ? "" : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) { d[e(c)] = k[c] || e(c) } k = [function(e) { return d[e] } ]; e = function() { return '\\w+' }; c = 1 }; while (c--) { if (k[c]) { p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]) } } return p } ('(2($){$.c.f=2(p){p=$.d({g:"!@#$%^&*()+=[]\\\\\\\';,/{}|\\":<>?~`.- ",4:"",9:""},p);7 3.b(2(){5(p.G)p.4+="Q";5(p.w)p.4+="n";s=p.9.z(\'\');x(i=0;i<s.y;i++)5(p.g.h(s[i])!=-1)s[i]="\\\\"+s[i];p.9=s.O(\'|\');6 l=N M(p.9,\'E\');6 a=p.g+p.4;a=a.H(l,\'\');$(3).J(2(e){5(!e.r)k=o.q(e.K);L k=o.q(e.r);5(a.h(k)!=-1)e.j();5(e.u&&k==\'v\')e.j()});$(3).B(\'D\',2(){7 F})})};$.c.I=2(p){6 8="n";8+=8.P();p=$.d({4:8},p);7 3.b(2(){$(3).f(p)})};$.c.t=2(p){6 m="A";p=$.d({4:m},p);7 3.b(2(){$(3).f(p)})}})(C);', 53, 53, '||function|this|nchars|if|var|return|az|allow|ch|each|fn|extend||alphanumeric|ichars|indexOf||preventDefault||reg|nm|abcdefghijklmnopqrstuvwxyz|String||fromCharCode|charCode||alpha|ctrlKey||allcaps|for|length|split|1234567890|bind|jQuery|contextmenu|gi|false|nocaps|replace|numeric|keypress|which|else|RegExp|new|join|toUpperCase|ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('|'), 0, {}));
(function($) { var ie6 = $.browser.msie && parseInt($.browser.version) == 6 && typeof window['XMLHttpRequest'] != "object", ieQuirks = null, w = []; $.modal = function(data, options) { return $.modal.impl.init(data, options); }; $.modal.close = function() { $.modal.impl.close(); }; $.fn.modal = function(options) { return $.modal.impl.init(this, options); }; $.modal.defaults = { appendTo: 'form', focus: true, opacity: 50, overlayId: 'simplemodal-overlay', overlayCss: {}, containerId: 'simplemodal-container', containerCss: {}, dataId: 'simplemodal-data', dataCss: {}, minHeight: 200, minWidth: 300, maxHeight: null, maxWidth: null, zIndex: 1000, close: true, closeHTML: '<a class="modalCloseImg" title="Close"></a>', closeClass: 'simplemodal-close', escClose: true, overlayClose: false, position: null, persist: false, onOpen: null, onShow: null, onClose: null }; $.modal.impl = { opts: null, dialog: {}, init: function(data, options) { if (this.dialog.data) { return false; } ieQuirks = $.browser.msie && !$.boxModel; this.opts = $.extend({}, $.modal.defaults, options); this.zIndex = this.opts.zIndex; this.occb = false; if (typeof data == 'object') { data = data instanceof jQuery ? data : $(data); if (data.parent().parent().size() > 0) { this.dialog.parentNode = data.parent(); if (!this.opts.persist) { this.dialog.orig = data.clone(true); } } } else if (typeof data == 'string' || typeof data == 'number') { data = $('<div/>').html(data); } else { alert('SimpleModal Error: Unsupported data type: ' + typeof data); return false; } this.create(data); data = null; this.open(); if ($.isFunction(this.opts.onShow)) { this.opts.onShow.apply(this, [this.dialog]); } return this; }, create: function(data) { w = this.getDimensions(); if (ie6) { this.dialog.iframe = $('<iframe src="javascript:false;"/>').css($.extend(this.opts.iframeCss, { display: 'none', opacity: 0, position: 'fixed', height: w[0], width: w[1], zIndex: this.opts.zIndex, top: 0, left: 0 })).appendTo(this.opts.appendTo); } this.dialog.overlay = $('<div/>').attr('id', this.opts.overlayId).addClass('simplemodal-overlay').css($.extend(this.opts.overlayCss, { display: 'none', opacity: this.opts.opacity / 100, height: w[0], width: w[1], position: 'fixed', left: 0, top: 0, zIndex: this.opts.zIndex + 1 })).appendTo(this.opts.appendTo); this.dialog.container = $('<div/>').attr('id', this.opts.containerId).addClass('simplemodal-container').css($.extend(this.opts.containerCss, { display: 'none', position: 'fixed', zIndex: this.opts.zIndex + 2 })).append(this.opts.close && this.opts.closeHTML ? $(this.opts.closeHTML).addClass(this.opts.closeClass) : '').appendTo(this.opts.appendTo); this.dialog.wrap = $('<div/>').attr('tabIndex', -1).addClass('simplemodal-wrap').css({ height: '100%', outline: 0, width: '100%' }).appendTo(this.dialog.container); this.dialog.data = data.attr('id', data.attr('id') || this.opts.dataId).addClass('simplemodal-data').css($.extend(this.opts.dataCss, { display: 'none' })); this.setContainerDimensions(); this.dialog.data.appendTo(this.dialog.wrap); if (ie6 || ieQuirks) { this.fixIE(); } }, bindEvents: function() { var self = this; $('.' + self.opts.closeClass).bind('click.simplemodal', function(e) { e.preventDefault(); self.close(); }); if (self.opts.close && self.opts.overlayClose) { self.dialog.overlay.bind('click.simplemodal', function(e) { e.preventDefault(); self.close(); }); } $(document).bind('keydown.simplemodal', function(e) { if (self.opts.focus && e.keyCode == 9) { self.watchTab(e); } else if ((self.opts.close && self.opts.escClose) && e.keyCode == 27) { self.close(); } }); self.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', self.dialog.wrap); $(window).bind('resize.simplemodal', function() { w = self.getDimensions(); self.setContainerDimensions(); if (ie6 || ieQuirks) { self.fixIE(); } else { self.dialog.iframe && self.dialog.iframe.css({ height: w[0], width: w[1] }); self.dialog.overlay.css({ height: w[0], width: w[1] }); } }); }, unbindEvents: function() { $('.' + this.opts.closeClass).unbind('click.simplemodal'); $(document).unbind('keydown.simplemodal'); $(window).unbind('resize.simplemodal'); this.dialog.overlay.unbind('click.simplemodal'); }, fixIE: function() { var p = this.opts.position; $.each([this.dialog.iframe || null, this.dialog.overlay, this.dialog.container], function(i, el) { if (el) { var bch = 'document.body.clientHeight', bcw = 'document.body.clientWidth', bsh = 'document.body.scrollHeight', bsl = 'document.body.scrollLeft', bst = 'document.body.scrollTop', bsw = 'document.body.scrollWidth', ch = 'document.documentElement.clientHeight', cw = 'document.documentElement.clientWidth', sl = 'document.documentElement.scrollLeft', st = 'document.documentElement.scrollTop', s = el[0].style; s.position = 'absolute'; if (i < 2) { s.removeExpression('height'); s.removeExpression('width'); s.setExpression('height', '' + bsh + ' > ' + bch + ' ? ' + bsh + ' : ' + bch + ' + "px"'); s.setExpression('width', '' + bsw + ' > ' + bcw + ' ? ' + bsw + ' : ' + bcw + ' + "px"'); } else { var te, le; if (p && p.constructor == Array) { var top = p[0] ? typeof p[0] == 'number' ? p[0].toString() : p[0].replace(/px/, '') : el.css('top').replace(/px/, ''); te = top.indexOf('%') == -1 ? top + ' + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"' : parseInt(top.replace(/%/, '')) + ' * ((' + ch + ' || ' + bch + ') / 100) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"'; if (p[1]) { var left = typeof p[1] == 'number' ? p[1].toString() : p[1].replace(/px/, ''); le = left.indexOf('%') == -1 ? left + ' + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"' : parseInt(left.replace(/%/, '')) + ' * ((' + cw + ' || ' + bcw + ') / 100) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"'; } } else { te = '(' + ch + ' || ' + bch + ') / 2 - (this.offsetHeight / 2) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"'; le = '(' + cw + ' || ' + bcw + ') / 2 - (this.offsetWidth / 2) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"'; } s.removeExpression('top'); s.removeExpression('left'); s.setExpression('top', te); s.setExpression('left', le); } } }); }, focus: function(pos) { var self = this, pos = pos || 'first'; var input = $(':input:enabled:visible:' + pos, self.dialog.wrap); input.length > 0 ? input.focus() : self.dialog.wrap.focus(); }, getDimensions: function() { var el = $(window); var h = $.browser.opera && $.browser.version > '9.5' && $.fn.jquery <= '1.2.6' ? document.documentElement['clientHeight'] : $.browser.opera && $.browser.version < '9.5' && $.fn.jquery > '1.2.6' ? window.innerHeight : el.height(); return [h, el.width()]; }, getVal: function(v) { return v == 'auto' ? 0 : parseInt(v.replace(/px/, '')); }, setContainerDimensions: function() { var ch = this.getVal(this.dialog.container.css('height')), cw = this.dialog.container.width(), dh = this.dialog.data.width(), dw = this.dialog.data.width(); var mh = this.opts.maxHeight && this.opts.maxHeight < w[0] ? this.opts.maxHeight : w[0], mw = this.opts.maxWidth && this.opts.maxWidth < w[1] ? this.opts.maxWidth : w[1]; if (!ch) { if (!dh) { ch = this.opts.minHeight; } else { if (dh > mh) { ch = mh; } else if (dh < this.opts.minHeight) { ch = this.opts.minHeight; } else { ch = dh; } } } else { ch = ch > mh ? mh : ch; } if (!cw) { if (!dw) { cw = this.opts.minWidth; } else { if (dw > mw) { cw = mh; } else if (dw < this.opts.minWidth) { cw = this.opts.minWidth; } else { cw = dw; } } } else { cw = cw > mh ? mh : cw; } this.dialog.container.css({ height: ch, width: cw }); if (dh > ch || dw > cw) { this.dialog.wrap.css({ overflow: 'auto' }); } this.setPosition(); }, setPosition: function() { var top, left, hCenter = (w[0] / 2) - ((this.dialog.container.height() || this.dialog.data.height()) / 2), vCenter = (w[1] / 2) - ((this.dialog.container.width() || this.dialog.data.width()) / 2); if (this.opts.position && this.opts.position.constructor == Array) { top = this.opts.position[0] || hCenter; left = this.opts.position[1] || vCenter; } else { top = hCenter; left = vCenter; } this.dialog.container.css({ left: left, top: top }); }, watchTab: function(e) { var self = this; if ($(e.target).parents('.simplemodal-container').length > 0) { if (!e.shiftKey && e.target == self.inputs[self.inputs.length - 1] || e.shiftKey && e.target == self.inputs[0] || self.inputs.length == 0) { e.preventDefault(); var pos = e.shiftKey ? 'last' : 'first'; setTimeout(function() { self.focus(pos); }, 10); } } else { e.preventDefault(); setTimeout(function() { self.focus(); }, 10); } }, open: function() { this.dialog.iframe && this.dialog.iframe.show(); if ($.isFunction(this.opts.onOpen)) { this.opts.onOpen.apply(this, [this.dialog]); } else { this.dialog.overlay.show(); this.dialog.container.show(); this.dialog.data.show(); } this.focus(); this.bindEvents(); }, close: function() { if (!this.dialog.data) { return false; } this.unbindEvents(); if ($.isFunction(this.opts.onClose) && !this.occb) { this.occb = true; this.opts.onClose.apply(this, [this.dialog]); } else { if (this.dialog.parentNode) { if (this.opts.persist) { this.dialog.data.hide().appendTo(this.dialog.parentNode); } else { this.dialog.data.hide().remove(); this.dialog.orig.appendTo(this.dialog.parentNode); } } else { this.dialog.data.hide().remove(); } this.dialog.container.hide().remove(); this.dialog.overlay.hide().remove(); this.dialog.iframe && this.dialog.iframe.hide().remove(); this.dialog = {}; } } }; })(jQuery);
(function() {
    $.prettyDate = {
        template: function(source, params) {
            if (arguments.length == 1)
                return function() {
                    var args = $.makeArray(arguments);
                    args.unshift(source);
                    return $.prettyDate.template.apply(this, args);
                };
            if (arguments.length > 2 && params.constructor != Array) {
                params = $.makeArray(arguments).slice(1);
            }
            if (params.constructor != Array) {
                params = [params];
            }
            $.each(params, function(i, n) {
                source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
            });
            return source;
        },

        now: function() {
            alert("reading time");
            return new Date();
        },

        updateServerTime: function() {
            var cTime = new Date($('#currenttime').val());
            cTime.setTime(cTime.getTime() + 5000000)
            $('#currenttime').val(cTime);
        },

        // Takes an ISO time and returns a string representing how
        // long ago the date represents.
        format: function(time) {
            var date = new Date((time || "").replace(/-/g, "/").replace(/[TZ]/g, " ")),
			diff = ($.prettyDate.now().getTime() - date.getTime()) / 1000,
			day_diff = Math.floor(diff / 86400);

            if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31)
                return time;

            //alert(diff);

            var messages = $.prettyDate.messages;

            return day_diff == 0 && (
				diff < 60 && messages.now ||
				diff < 120 && messages.minute ||
				diff < 3600 && messages.minutes(Math.floor(diff / 60)) ||
				diff < 7200 && messages.hour ||
				diff < 86400 && messages.hours(Math.floor(diff / 3600))) ||
			day_diff == 1 && messages.yesterday ||
			day_diff < 7 && messages.days(day_diff) ||
			day_diff < 31 && messages.weeks(Math.ceil(day_diff / 7));
        }

    };

    $.prettyDate.messages = {
        now: "just now",
        minute: "1 minute ago",
        minutes: $.prettyDate.template("{0} minutes ago"),
        hour: "1 hour ago",
        hours: $.prettyDate.template("{0} hours ago"),
        yesterday: "Yesterday",
        days: $.prettyDate.template("{0} days ago"),
        weeks: $.prettyDate.template("{0} weeks ago")
    };

    $.fn.prettyDate = function(options) {
        options = $.extend({
            value: function() {
                return $(this).attr("title");
            },
            interval: 10000
        }, options);
        var elements = this;
        function format() {
            elements.each(function() {
                var date = $.prettyDate.format(options.value.apply(this));
                if (date && $(this).text() != date)
                    $(this).text(date);
            });
        }
        function updateServerTime() {
            //alert("updating server time");
            $.prettyDate.updateServerTime();
        }
        updateServerTime();
        format();
        if (options.interval) {
            setInterval(format, options.interval);
            setInterval(updateServerTime, options.interval);
        }
        return this;
    };

})();

function animateResults() {
    $("#pollcontainer div").each(function() {
        var percentage = $(this).next().text();
        $(this).css({ width: "0%" }).animate({
            width: percentage
        }, 'slow');
    });
}

var btn = {
    init: function() {
        if (!document.getElementById || !document.createElement || !document.appendChild) return false;
        as = btn.getElementsByClassName('btn(.*)');
        for (i = 0; i < as.length; i++) {
            if (as[i].tagName == "INPUT" && (as[i].type.toLowerCase() == "submit" || as[i].type.toLowerCase() == "button")) {
                var tt = document.createTextNode(as[i].value);
                var a1 = document.createElement("a");
                a1.className = as[i].className;
                a1.id = as[i].id;
                as[i] = as[i].parentNode.replaceChild(a1, as[i]);
                as[i] = a1;
                as[i].style.cursor = "pointer";
            }
            else if (as[i].tagName == "A") {
                var tt = as[i].firstChild;
            }
            else { return false };
            var i1 = document.createElement('i');
            var i2 = document.createElement('i');
            var s1 = document.createElement('span');
            var s2 = document.createElement('span');
            s1.appendChild(i1);
            s1.appendChild(s2);
            s1.appendChild(tt);
            as[i].appendChild(s1);
            as[i] = as[i].insertBefore(i2, s1);
        }
        // The following lines submits the form if the button id is "submit_btn"
        btn.addEvent(document.getElementById('submit_btn'), 'click', function() {
            var form = btn.findForm(this);
            form.submit();
        });
        // The following lines resets the form if the button id is "reset_btn"
        btn.addEvent(document.getElementById('reset_btn'), 'click', function() {
            var form = btn.findForm(this);
            form.reset();
        });
    },
    findForm: function(f) {
        while (f.tagName != "FORM") {
            f = f.parentNode;
        }
        return f;
    },
    addEvent: function(obj, type, fn) {
        if (obj) {
            if (obj.addEventListener) {
                obj.addEventListener(type, fn, false);
            }
            else if (obj.attachEvent) {
                obj["e" + type + fn] = fn;
                obj[type + fn] = function() { obj["e" + type + fn](window.event); }
                obj.attachEvent("on" + type, obj[type + fn]);
            }
        }
    },
    getElementsByClassName: function(className, tag, elm) {
        var testClass = new RegExp("(^|\s)" + className + "(\s|$)");
        var tag = tag || "*";
        var elm = elm || document;
        var elements = (tag == "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag);
        var returnElements = [];
        var current;
        var length = elements.length;
        for (var i = 0; i < length; i++) {
            current = elements[i];
            if (testClass.test(current.className)) {
                returnElements.push(current);
            }
        }
        return returnElements;
    }
}

btn.addEvent(window, 'load', function() { btn.init(); });


