// jQuery Form Validators v0.3.4
// License: http://validator.codeplex.com/license
var validate; (function(b){function i(){f(this)?b(this).highlight():b(this).unhighlight()}function f(c){var a=b(c),e=a.find("input:radio, input:checkbox").size();if(a.attr("disabled")||e>0&&e==a.find("input:radio:disabled, input:checkbox:disabled").size())return"";if((a.val()==""||a.val()==null||a.val()==a.attr("infotext"))&&a.find("input:radio:checked, input:checkbox:checked").size()==0)return a.attr("require")?"require":"";if(a.attr("regular")&&a.attr("validExpress")&&!RegExp(a.attr("validExpress"),"m").test(a.val()))return"regular"; if(a.attr("regular")&&a.attr("invalidExpress")&&RegExp(a.attr("invalidExpress"),"m").test(a.val()))return"regular";if(a.attr("compare")&&b("#"+a.attr("compareTo")).val()!=a.val())return"compare";if(a.attr("custom")&&!(new Function(a.attr("customFn"))).call(c))return"custom";if(a.attr("invalid")&&a.val()==a.attr("invalidVal"))return"invalid";if(validators!=undefined)for(var d in validators)if(a.attr(d)&&validators[d].call(a.val()))return d}function g(){var c=b(this),a=c.offset().top+c.height()+4,e= c.offset().left+Math.max(c.width()-260,0);c.parents().each(function(){if(b(this).css("position")!="static"&&(!b.browser.mozilla||b(this).css("display")!="table")){var d=b(this).offset();a-=d.top;e-=d.left;return false}});c.parent().children(".alertbox").remove();c.parent().append("<div class='alertbox' style='top:"+a+"px; left:"+e+"px;'><div>"+c.attr(f(this))+"</div></div>")}function h(){b(this).parent().children(".alertbox").remove()}validate=function(c){var a=true;b("*[validate="+c+"]").each(function(e, d){if(f(d)){b(d).highlight();a&&b(d).focus();a=false}else b(d).unhighlight()});return a};b.fn.highlight=function(){this.addClass("highlight").focus(g).blur(h).change(i);return this};b.fn.unhighlight=function(){this.removeClass("highlight").unbind("focus",g).unbind("blur",h).parent().children(".alertbox").remove();return this}})(jQuery);
var validators = { email: function () { return !RegExp("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?.)+[a-zA-z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?", "m").test(this) } };

// Date Format 1.2.3
// (c) 2007-2009 Steven Levithan <stevenlevithan.com>, MIT license
// http://blog.stevenlevithan.com/archives/date-time-format
var dateFormat = function () { var k = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g, l = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, s = /[^-+\dA-Z]/g, d = function (a, c) { a = String(a); for (c = c || 2; a.length < c; ) a = "0" + a; return a }; return function (a, c, h) { var f = dateFormat; if (arguments.length == 1 && Object.prototype.toString.call(a) == "[object String]" && !/\d/.test(a)) { c = a; a = undefined } a = a ? new Date(a) : new Date; if (isNaN(a)) throw SyntaxError("invalid date"); c = String(f.masks[c] || c || f.masks["default"]); if (c.slice(0, 4) == "UTC:") { c = c.slice(4); h = true } var b = h ? "getUTC" : "get", g = a[b + "Date"](), n = a[b + "Day"](), i = a[b + "Month"](), o = a[b + "FullYear"](), e = a[b + "Hours"](), p = a[b + "Minutes"](), q = a[b + "Seconds"](); b = a[b + "Milliseconds"](); var m = h ? 0 : a.getTimezoneOffset(), r = { d: g, dd: d(g), ddd: f.i18n.dayNames[n], dddd: f.i18n.dayNames[n + 7], m: i + 1, mm: d(i + 1), mmm: f.i18n.monthNames[i], mmmm: f.i18n.monthNames[i + 12], yy: String(o).slice(2), yyyy: o, h: e % 12 || 12, hh: d(e % 12 || 12), H: e, HH: d(e), M: p, MM: d(p), s: q, ss: d(q), l: d(b, 3), L: d(b > 99 ? Math.round(b / 10) : b), t: e < 12 ? "a" : "p", tt: e < 12 ? "am" : "pm", T: e < 12 ? "A" : "P", TT: e < 12 ? "AM" : "PM", Z: h ? "UTC" : (String(a).match(l) || [""]).pop().replace(s, ""), o: (m > 0 ? "-" : "+") + d(Math.floor(Math.abs(m) / 60) * 100 + Math.abs(m) % 60, 4), S: ["th", "st", "nd", "rd"][g % 10 > 3 ? 0 : (g % 100 - g % 10 != 10) * g % 10] }; return c.replace(k, function (j) { return j in r ? r[j] : j.slice(1, j.length - 1) }) } } (); dateFormat.masks = { "default": "ddd mmm dd yyyy HH:MM:ss", shortDate: "m/d/yy", mediumDate: "mmm d, yyyy", longDate: "mmmm d, yyyy", fullDate: "dddd, mmmm d, yyyy", shortTime: "h:MM TT", mediumTime: "h:MM:ss TT", longTime: "h:MM:ss TT Z", isoDate: "yyyy-mm-dd", isoTime: "HH:MM:ss", isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" }; dateFormat.i18n = { dayNames: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], monthNames: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] }; Date.prototype.format = function (k, l) { return dateFormat(this, k, l) };

//http://www.JSON.org/json2.js
//2010-08-25
if(!this.JSON)this.JSON={}; (function(){function l(b){return b<10?"0"+b:b}function o(b){p.lastIndex=0;return p.test(b)?'"'+b.replace(p,function(f){var c=r[f];return typeof c==="string"?c:"\\u"+("0000"+f.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+b+'"'}function m(b,f){var c,d,g,j,i=h,e,a=f[b];if(a&&typeof a==="object"&&typeof a.toJSON==="function")a=a.toJSON(b);if(typeof k==="function")a=k.call(f,b,a);switch(typeof a){case "string":return o(a);case "number":return isFinite(a)?String(a):"null";case "boolean":case "null":return String(a); case "object":if(!a)return"null";h+=n;e=[];if(Object.prototype.toString.apply(a)==="[object Array]"){j=a.length;for(c=0;c<j;c+=1)e[c]=m(c,a)||"null";g=e.length===0?"[]":h?"[\n"+h+e.join(",\n"+h)+"\n"+i+"]":"["+e.join(",")+"]";h=i;return g}if(k&&typeof k==="object"){j=k.length;for(c=0;c<j;c+=1){d=k[c];if(typeof d==="string")if(g=m(d,a))e.push(o(d)+(h?": ":":")+g)}}else for(d in a)if(Object.hasOwnProperty.call(a,d))if(g=m(d,a))e.push(o(d)+(h?": ":":")+g);g=e.length===0?"{}":h?"{\n"+h+e.join(",\n"+h)+ "\n"+i+"}":"{"+e.join(",")+"}";h=i;return g}}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+l(this.getUTCMonth()+1)+"-"+l(this.getUTCDate())+"T"+l(this.getUTCHours())+":"+l(this.getUTCMinutes())+":"+l(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()}}var q=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, p=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,h,n,r={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},k;if(typeof JSON.stringify!=="function")JSON.stringify=function(b,f,c){var d;n=h="";if(typeof c==="number")for(d=0;d<c;d+=1)n+=" ";else if(typeof c==="string")n=c;if((k=f)&&typeof f!=="function"&&(typeof f!=="object"||typeof f.length!=="number"))throw Error("JSON.stringify");return m("", {"":b})};if(typeof JSON.parse!=="function")JSON.parse=function(b,f){function c(g,j){var i,e,a=g[j];if(a&&typeof a==="object")for(i in a)if(Object.hasOwnProperty.call(a,i)){e=c(a,i);if(e!==undefined)a[i]=e;else delete a[i]}return f.call(g,j,a)}var d;b=String(b);q.lastIndex=0;if(q.test(b))b=b.replace(q,function(g){return"\\u"+("0000"+g.charCodeAt(0).toString(16)).slice(-4)});if(/^[\],:{}\s]*$/.test(b.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){d=eval("("+b+")");return typeof f==="function"?c({"":d},""):d}throw new SyntaxError("JSON.parse");}})();

/* misc */
function addOption(select, text, value, selected) {
    var option = document.createElement("option");
    option.text = text;
    option.value = value;
    option.selected = selected;
    try { select.add(option, null); }
    catch (e) { select.add(option); }
};

function clearOptions(select) {
    select.selectedIndex = -1;
    for (var i = select.options.length - 1; i >= 0; i--)
        select.remove(i);
};

/* slider plugin */
(function ($) {
    $.fn.Scroller = function (options) {
        var defaults = { speed: 1, center: true };
        var options = $.extend(defaults, options);

        //Init
        window.scrollerBegin = function (elem) {
            if (elem == undefined) elem = window.scrollerElement;
            $(elem).css({ marginLeft: 0 }).animate({ marginLeft: -$(elem).attr("totalWidth") }, ($(elem).width() * 10) / parseInt(options["speed"]), "linear", function () { window.scrollerBegin(this); });
        }

        this.each(function () {
            var scroller = this;
            var max = 60;
            window.scrollerElement = this;
            $(this).attr("totalwidth", 0);
            $(this).children().each(function () {
                $(this).bind("load", function () {
                    if (options.center)
                        $(this).css("margin-top", (max - $(this).height()) / 2);
                    var width = parseInt($(scroller).attr("totalwidth")) + 2 + parseInt($(this).outerWidth(true));
                    $(scroller).attr("totalwidth", width).width(width * 2);
                    $(this).siblings().filter(":last").after($(this).clone());
                    $(this).css({ backgroundColor: "#f00" });
                });
                //web-kit doesn't fire "load" event for cached images
                $(this).attr("src", $(this).attr("src"));
            });
            setTimeout("window.scrollerBegin();", 200);
        });
    };
})(jQuery);

$.fn.slider = function (options) {
    var opts = $.extend({}, $.fn.slider.defaults, options);
    return this.each(function () {
        var $this = $(this);
        var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
        $(o.leftControl).css({display:"none"}).bind("click", function (e) { $.fn.slider.move($this, 1, o); });
        $(o.rightControl).bind("click", function (e) { $.fn.slider.move($this, -1, o); });
    });
};
$.fn.slider.move = function ($wrapper, dir, o) {
    if (o.scrolling) return;

    x = $(o.scroller).css("marginLeft") == "auto" ? 0 : parseInt($(o.scroller).css("marginLeft"));

    if (x + (dir * o.increment) < -o.max || x + (dir * o.increment) > 0)
        return;

    if (dir < 0)
        x -= o.increment;
    else
        x += o.increment;
    o.scrolling = true;
    $.fn.slider.check(o, x);
    $(o.scroller).animate({ marginLeft: x }, o.duration, null, function (e) {
        o.scrolling = false;
    });
}

$.fn.slider.check = function (o, x) {
    if (x == 0) {
        $(o.leftControl).fadeOut(o.duration);
    }
    else
        $(o.leftControl).fadeIn(o.duration);
    if (x == -o.max)
        $(o.rightControl).fadeOut(o.duration);
    else
        $(o.rightControl).fadeIn(o.duration);
}

$.fn.slider.defaults = {
    increment: 10,
    max: 100,
    duration: 200,
    scroller: '#inner',
    leftControl: '#leftControl',
    rightControl: '#rightControl'
};
