/*
Stylish Select 0.3 - jQuery plugin to replace a select drop down box with a stylable unordered list
http://scottdarby.com/

Copyright (c) 2009 Scott Darby

Requires: jQuery 1.3

Licensed under the GPL license:
http://www.gnu.org/licenses/gpl.html
*/
(function(a){a("html").addClass("js");Array.prototype.indexOf=function(c,d){for(var b=(d||0);b<this.length;b++){if(this[b]==c){return b}}};a.fn.extend({getSetSSValue:function(b){if(b){a(this).val(b).change();return this}else{return selText=a(this).find(":selected").text()}},resetSS:function(){$this=a(this);$this.next().remove();$this.unbind().sSelect()}});a.fn.sSelect=function(b){return this.each(function(){var j={defaultText:"Please select",animationSpeed:0,ddMaxHeight:""};var m=a.extend(j,b),e=a(this),k=a('<div class="selectedTxt"></div>'),s=a('<div class="newListSelected" tabindex="0"></div>'),A=a('<ul class="newList"></ul>'),u=-1,d=-1,n=[],x=false,h="",w=false;s.insertAfter(e);k.prependTo(s);A.appendTo(s);e.hide();if(e.children("optgroup").length==0){e.children().each(function(B){var C=a(this).text();n.push(C.charAt(0).toLowerCase());if(a(this).attr("selected")==true){m.defaultText=C;d=B}h+="<li>"+C+"</li>"});A.html(h);h="";var y=A.children()}else{e.children("optgroup").each(function(D){var B=a(this).attr("label"),E=a('<li class="newListOptionTitle">'+B+"</li>");E.appendTo(A);var C=a("<ul></ul>");C.appendTo(E);a(this).children().each(function(){++u;var F=a(this).text();n.push(F.charAt(0).toLowerCase());if(a(this).attr("selected")==true){m.defaultText=F;d=u}h+="<li>"+F+"</li>"});C.html(h);h=""});var y=A.find("ul li")}var p=A.height()+3,o=s.height()+3,z=y.length;if(d!=-1){i(d,true)}else{k.text(m.defaultText)}function q(){var C=s.offset().top,B=jQuery(window).height(),D=jQuery(window).scrollTop();if(p>parseInt(m.ddMaxHeight)){p=parseInt(m.ddMaxHeight)}C=C-D;if(C+p>=B){A.css({top:"-"+p+"px",height:p});e.onTop=true}else{A.css({top:o+"px",height:p});e.onTop=false}}q();a(window).resize(function(){q()});a(window).scroll(function(){q()});function t(){s.css("position","relative")}function c(){s.css("position","static")}k.click(function(){if(A.is(":visible")){A.hide();c();return false}s.focus();A.slideDown(m.animationSpeed);t();A.scrollTop(e.liOffsetTop)});y.hover(function(C){var B=a(C.target);B.addClass("newListHover")},function(C){var B=a(C.target);B.removeClass("newListHover")});y.click(function(C){var B=a(C.target);d=y.index(B);w=true;i(d);A.hide();s.css("position","static")});function i(D,F){var B=s.offset().top,G=y.eq(D).offset().top,C=A.scrollTop();if(e.onTop==true){e.liOffsetTop=(((G-B)-o)+C)+parseInt(m.ddMaxHeight)}else{e.liOffsetTop=((G-B)-o)+C}A.scrollTop(e.liOffsetTop);y.removeClass("hiLite").eq(D).addClass("hiLite");var E=y.eq(D).text();if(F==true){e.val(E);k.text(E);return false}e.val(E).change();k.text(E)}e.change(function(B){$targetInput=a(B.target);if(w==true){w=false;return false}$currentOpt=$targetInput.find(":selected");d=$targetInput.find("option").index($currentOpt);i(d,true)});function r(B){B.onkeydown=function(E){if(E==null){var D=event.keyCode}else{var D=E.which}w=true;switch(D){case 40:case 39:v();return false;break;case 38:case 37:l();return false;break;case 33:case 36:g();return false;break;case 34:case 35:f();return false;break;case 13:case 27:A.hide();c();return false;break}keyPressed=String.fromCharCode(D).toLowerCase();var C=n.indexOf(keyPressed);if(typeof C!="undefined"){++d;d=n.indexOf(keyPressed,d);if(d==-1||d==null||x!=keyPressed){d=n.indexOf(keyPressed)}i(d);x=keyPressed;return false}}}function v(){if(d<(z-1)){++d;i(d)}}function l(){if(d>0){--d;i(d)}}function g(){d=0;i(d)}function f(){d=z-1;i(d)}s.click(function(){r(this)});s.focus(function(){a(this).addClass("newListSelFocus");r(this)});s.blur(function(){a(this).removeClass("newListSelFocus");A.hide();c()});k.hover(function(C){var B=a(C.target);B.parent().addClass("newListSelHover")},function(C){var B=a(C.target);B.parent().removeClass("newListSelHover")});A.css("left","0").hide()})}})(jQuery);



/*
 * jQuery Form Plugin
 * version: 2.33 (22-SEP-2009)
 * @requires jQuery v1.2.6 or later
 *
 * Examples and documentation at: http://malsup.com/jquery/form/
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
;(function($) {

/*
	Usage Note:
	-----------
	Do not use both ajaxSubmit and ajaxForm on the same form.  These
	functions are intended to be exclusive.  Use ajaxSubmit if you want
	to bind your own submit handler to the form.  For example,

	$(document).ready(function() {
		$('#myForm').bind('submit', function() {
			$(this).ajaxSubmit({
				target: '#output'
			});
			return false; // <-- important!
		});
	});

	Use ajaxForm when you want the plugin to manage all the event binding
	for you.  For example,

	$(document).ready(function() {
		$('#myForm').ajaxForm({
			target: '#output'
		});
	});

	When using ajaxForm, the ajaxSubmit function will be invoked for you
	at the appropriate time.
*/

/**
 * ajaxSubmit() provides a mechanism for immediately submitting
 * an HTML form using AJAX.
 */
$.fn.ajaxSubmit = function(options) {
	// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
	if (!this.length) {
		log('ajaxSubmit: skipping submit process - no element selected');
		return this;
	}

	if (typeof options == 'function')
		options = { success: options };

	var url = $.trim(this.attr('action'));
	if (url) {
		// clean url (don't include hash vaue)
		url = (url.match(/^([^#]+)/)||[])[1];
   	}
   	url = url || window.location.href || '';

	options = $.extend({
		url:  url,
		type: this.attr('method') || 'GET'
	}, options || {});

	// hook for manipulating the form data before it is extracted;
	// convenient for use with rich editors like tinyMCE or FCKEditor
	var veto = {};
	this.trigger('form-pre-serialize', [this, options, veto]);
	if (veto.veto) {
		log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
		return this;
	}

	// provide opportunity to alter form data before it is serialized
	if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
		log('ajaxSubmit: submit aborted via beforeSerialize callback');
		return this;
	}

	var a = this.formToArray(options.semantic);
	if (options.data) {
		options.extraData = options.data;
		for (var n in options.data) {
		  if(options.data[n] instanceof Array) {
			for (var k in options.data[n])
			  a.push( { name: n, value: options.data[n][k] } );
		  }
		  else
			 a.push( { name: n, value: options.data[n] } );
		}
	}

	// give pre-submit callback an opportunity to abort the submit
	if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
		log('ajaxSubmit: submit aborted via beforeSubmit callback');
		return this;
	}

	// fire vetoable 'validate' event
	this.trigger('form-submit-validate', [a, this, options, veto]);
	if (veto.veto) {
		log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
		return this;
	}

	var q = $.param(a);

	if (options.type.toUpperCase() == 'GET') {
		options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
		options.data = null;  // data is null for 'get'
	}
	else
		options.data = q; // data is the query string for 'post'

	var $form = this, callbacks = [];
	if (options.resetForm) callbacks.push(function() { $form.resetForm(); });
	if (options.clearForm) callbacks.push(function() { $form.clearForm(); });

	// perform a load on the target only if dataType is not provided
	if (!options.dataType && options.target) {
		var oldSuccess = options.success || function(){};
		callbacks.push(function(data) {
			$(options.target).html(data).each(oldSuccess, arguments);
		});
	}
	else if (options.success)
		callbacks.push(options.success);

	options.success = function(data, status) {
		for (var i=0, max=callbacks.length; i < max; i++)
			callbacks[i].apply(options, [data, status, $form]);
	};

	// are there files to upload?
	var files = $('input:file', this).fieldValue();
	var found = false;
	for (var j=0; j < files.length; j++)
		if (files[j])
			found = true;

	var multipart = false;
//	var mp = 'multipart/form-data';
//	multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);

	// options.iframe allows user to force iframe mode
   if (options.iframe || found || multipart) {
	   // hack to fix Safari hang (thanks to Tim Molendijk for this)
	   // see:  http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
	   if (options.closeKeepAlive)
		   $.get(options.closeKeepAlive, fileUpload);
	   else
		   fileUpload();
	   }
   else
	   $.ajax(options);

	// fire 'notify' event
	this.trigger('form-submit-notify', [this, options]);
	return this;


	// private function for handling file uploads (hat tip to YAHOO!)
	function fileUpload() {
		var form = $form[0];

		if ($(':input[name=submit]', form).length) {
			alert('Error: Form elements must not be named "submit".');
			return;
		}

		var opts = $.extend({}, $.ajaxSettings, options);
		var s = $.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts);

		var id = 'jqFormIO' + (new Date().getTime());
		var $io = $('<iframe id="' + id + '" name="' + id + '" src="about:blank" />');
		var io = $io[0];

		$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });

		var xhr = { // mock object
			aborted: 0,
			responseText: null,
			responseXML: null,
			status: 0,
			statusText: 'n/a',
			getAllResponseHeaders: function() {},
			getResponseHeader: function() {},
			setRequestHeader: function() {},
			abort: function() {
				this.aborted = 1;
				$io.attr('src','about:blank'); // abort op in progress
			}
		};

		var g = opts.global;
		// trigger ajax global events so that activity/block indicators work like normal
		if (g && ! $.active++) $.event.trigger("ajaxStart");
		if (g) $.event.trigger("ajaxSend", [xhr, opts]);

		if (s.beforeSend && s.beforeSend(xhr, s) === false) {
			s.global && $.active--;
			return;
		}
		if (xhr.aborted)
			return;

		var cbInvoked = 0;
		var timedOut = 0;

		// add submitting element to data if we know it
		var sub = form.clk;
		if (sub) {
			var n = sub.name;
			if (n && !sub.disabled) {
				options.extraData = options.extraData || {};
				options.extraData[n] = sub.value;
				if (sub.type == "image") {
					options.extraData[name+'.x'] = form.clk_x;
					options.extraData[name+'.y'] = form.clk_y;
				}
			}
		}

		// take a breath so that pending repaints get some cpu time before the upload starts
		setTimeout(function() {
			// make sure form attrs are set
			var t = $form.attr('target'), a = $form.attr('action');

			// update form attrs in IE friendly way
			form.setAttribute('target',id);
			if (form.getAttribute('method') != 'POST')
				form.setAttribute('method', 'POST');
			if (form.getAttribute('action') != opts.url)
				form.setAttribute('action', opts.url);

			// ie borks in some cases when setting encoding
			if (! options.skipEncodingOverride) {
				$form.attr({
					encoding: 'multipart/form-data',
					enctype:  'multipart/form-data'
				});
			}

			// support timout
			if (opts.timeout)
				setTimeout(function() { timedOut = true; cb(); }, opts.timeout);

			// add "extra" data to form if provided in options
			var extraInputs = [];
			try {
				if (options.extraData)
					for (var n in options.extraData)
						extraInputs.push(
							$('<input type="hidden" name="'+n+'" value="'+options.extraData[n]+'" />')
								.appendTo(form)[0]);

				// add iframe to doc and submit the form
				$io.appendTo('body');
				io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
				form.submit();
			}
			finally {
				// reset attrs and remove "extra" input elements
				form.setAttribute('action',a);
				t ? form.setAttribute('target', t) : $form.removeAttr('target');
				$(extraInputs).remove();
			}
		}, 10);

		var domCheckCount = 50;

		function cb() {
			if (cbInvoked++) return;

			io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);

			var ok = true;
			try {
				if (timedOut) throw 'timeout';
				// extract the server response from the iframe
				var data, doc;

				doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
				
				var isXml = opts.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
				log('isXml='+isXml);
				if (!isXml && (doc.body == null || doc.body.innerHTML == '')) {
				 	if (--domCheckCount) {
						// in some browsers (Opera) the iframe DOM is not always traversable when
						// the onload callback fires, so we loop a bit to accommodate
						cbInvoked = 0;
						setTimeout(cb, 100);
						return;
					}
					log('Could not access iframe DOM after 50 tries.');
					return;
				}

				xhr.responseText = doc.body ? doc.body.innerHTML : null;
				xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
				xhr.getResponseHeader = function(header){
					var headers = {'content-type': opts.dataType};
					return headers[header];
				};

				if (opts.dataType == 'json' || opts.dataType == 'script') {
					// see if user embedded response in textarea
					var ta = doc.getElementsByTagName('textarea')[0];
					if (ta)
						xhr.responseText = ta.value;
					else {
						// account for browsers injecting pre around json response
						var pre = doc.getElementsByTagName('pre')[0];
						if (pre)
							xhr.responseText = pre.innerHTML;
					}			  
				}
				else if (opts.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
					xhr.responseXML = toXml(xhr.responseText);
				}
				data = $.httpData(xhr, opts.dataType);
			}
			catch(e){
				ok = false;
				$.handleError(opts, xhr, 'error', e);
			}

			// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
			if (ok) {
				opts.success(data, 'success');
				if (g) $.event.trigger("ajaxSuccess", [xhr, opts]);
			}
			if (g) $.event.trigger("ajaxComplete", [xhr, opts]);
			if (g && ! --$.active) $.event.trigger("ajaxStop");
			if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error');

			// clean up
			setTimeout(function() {
				$io.remove();
				xhr.responseXML = null;
			}, 100);
		};

		function toXml(s, doc) {
			if (window.ActiveXObject) {
				doc = new ActiveXObject('Microsoft.XMLDOM');
				doc.async = 'false';
				doc.loadXML(s);
			}
			else
				doc = (new DOMParser()).parseFromString(s, 'text/xml');
			return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
		};
	};
};

/**
 * ajaxForm() provides a mechanism for fully automating form submission.
 *
 * The advantages of using this method instead of ajaxSubmit() are:
 *
 * 1: This method will include coordinates for <input type="image" /> elements (if the element
 *	is used to submit the form).
 * 2. This method will include the submit element's name/value data (for the element that was
 *	used to submit the form).
 * 3. This method binds the submit() method to the form for you.
 *
 * The options argument for ajaxForm works exactly as it does for ajaxSubmit.  ajaxForm merely
 * passes the options argument along after properly binding events for submit elements and
 * the form itself.
 */
$.fn.ajaxForm = function(options) {
	return this.ajaxFormUnbind().bind('submit.form-plugin', function() {
		$(this).ajaxSubmit(options);
		return false;
	}).bind('click.form-plugin', function(e) {
		var $el = $(e.target);
		if (!($el.is(":submit,input:image"))) {
			return;
		}
		var form = this;
		form.clk = e.target;
		if (e.target.type == 'image') {
			if (e.offsetX != undefined) {
				form.clk_x = e.offsetX;
				form.clk_y = e.offsetY;
			} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
				var offset = $el.offset();
				form.clk_x = e.pageX - offset.left;
				form.clk_y = e.pageY - offset.top;
			} else {
				form.clk_x = e.pageX - e.target.offsetLeft;
				form.clk_y = e.pageY - e.target.offsetTop;
			}
		}
		// clear form vars
		setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 10);
	});
};

// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
$.fn.ajaxFormUnbind = function() {
	return this.unbind('submit.form-plugin click.form-plugin');
};

/**
 * formToArray() gathers form element data into an array of objects that can
 * be passed to any of the following ajax functions: $.get, $.post, or load.
 * Each object in the array has both a 'name' and 'value' property.  An example of
 * an array for a simple login form might be:
 *
 * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
 *
 * It is this array that is passed to pre-submit callback functions provided to the
 * ajaxSubmit() and ajaxForm() methods.
 */
$.fn.formToArray = function(semantic) {
	var a = [];
	if (this.length == 0) return a;

	var form = this[0];
	var els = semantic ? form.getElementsByTagName('*') : form.elements;
	if (!els) return a;
	for(var i=0, max=els.length; i < max; i++) {
		var el = els[i];
		var n = el.name;
		if (!n) continue;

		if (semantic && form.clk && el.type == "image") {
			// handle image inputs on the fly when semantic == true
			if(!el.disabled && form.clk == el) {
				a.push({name: n, value: $(el).val()});
				a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
			}
			continue;
		}

		var v = $.fieldValue(el, true);
		if (v && v.constructor == Array) {
			for(var j=0, jmax=v.length; j < jmax; j++)
				a.push({name: n, value: v[j]});
		}
		else if (v !== null && typeof v != 'undefined')
			a.push({name: n, value: v});
	}

	if (!semantic && form.clk) {
		// input type=='image' are not found in elements array! handle it here
		var $input = $(form.clk), input = $input[0], n = input.name;
		if (n && !input.disabled && input.type == 'image') {
			a.push({name: n, value: $input.val()});
			a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
		}
	}
	return a;
};

/**
 * Serializes form data into a 'submittable' string. This method will return a string
 * in the format: name1=value1&amp;name2=value2
 */
$.fn.formSerialize = function(semantic) {
	//hand off to jQuery.param for proper encoding
	return $.param(this.formToArray(semantic));
};

/**
 * Serializes all field elements in the jQuery object into a query string.
 * This method will return a string in the format: name1=value1&amp;name2=value2
 */
$.fn.fieldSerialize = function(successful) {
	var a = [];
	this.each(function() {
		var n = this.name;
		if (!n) return;
		var v = $.fieldValue(this, successful);
		if (v && v.constructor == Array) {
			for (var i=0,max=v.length; i < max; i++)
				a.push({name: n, value: v[i]});
		}
		else if (v !== null && typeof v != 'undefined')
			a.push({name: this.name, value: v});
	});
	//hand off to jQuery.param for proper encoding
	return $.param(a);
};

/**
 * Returns the value(s) of the element in the matched set.  For example, consider the following form:
 *
 *  <form><fieldset>
 *	  <input name="A" type="text" />
 *	  <input name="A" type="text" />
 *	  <input name="B" type="checkbox" value="B1" />
 *	  <input name="B" type="checkbox" value="B2"/>
 *	  <input name="C" type="radio" value="C1" />
 *	  <input name="C" type="radio" value="C2" />
 *  </fieldset></form>
 *
 *  var v = $(':text').fieldValue();
 *  // if no values are entered into the text inputs
 *  v == ['','']
 *  // if values entered into the text inputs are 'foo' and 'bar'
 *  v == ['foo','bar']
 *
 *  var v = $(':checkbox').fieldValue();
 *  // if neither checkbox is checked
 *  v === undefined
 *  // if both checkboxes are checked
 *  v == ['B1', 'B2']
 *
 *  var v = $(':radio').fieldValue();
 *  // if neither radio is checked
 *  v === undefined
 *  // if first radio is checked
 *  v == ['C1']
 *
 * The successful argument controls whether or not the field element must be 'successful'
 * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
 * The default value of the successful argument is true.  If this value is false the value(s)
 * for each element is returned.
 *
 * Note: This method *always* returns an array.  If no valid value can be determined the
 *	   array will be empty, otherwise it will contain one or more values.
 */
$.fn.fieldValue = function(successful) {
	for (var val=[], i=0, max=this.length; i < max; i++) {
		var el = this[i];
		var v = $.fieldValue(el, successful);
		if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length))
			continue;
		v.constructor == Array ? $.merge(val, v) : val.push(v);
	}
	return val;
};

/**
 * Returns the value of the field element.
 */
$.fieldValue = function(el, successful) {
	var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
	if (typeof successful == 'undefined') successful = true;

	if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
		(t == 'checkbox' || t == 'radio') && !el.checked ||
		(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
		tag == 'select' && el.selectedIndex == -1))
			return null;

	if (tag == 'select') {
		var index = el.selectedIndex;
		if (index < 0) return null;
		var a = [], ops = el.options;
		var one = (t == 'select-one');
		var max = (one ? index+1 : ops.length);
		for(var i=(one ? index : 0); i < max; i++) {
			var op = ops[i];
			if (op.selected) {
				var v = op.value;
				if (!v) // extra pain for IE...
					v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
				if (one) return v;
				a.push(v);
			}
		}
		return a;
	}
	return el.value;
};

/**
 * Clears the form data.  Takes the following actions on the form's input fields:
 *  - input text fields will have their 'value' property set to the empty string
 *  - select elements will have their 'selectedIndex' property set to -1
 *  - checkbox and radio inputs will have their 'checked' property set to false
 *  - inputs of type submit, button, reset, and hidden will *not* be effected
 *  - button elements will *not* be effected
 */
$.fn.clearForm = function() {
	return this.each(function() {
		$('input,select,textarea', this).clearFields();
	});
};

/**
 * Clears the selected form elements.
 */
$.fn.clearFields = $.fn.clearInputs = function() {
	return this.each(function() {
		var t = this.type, tag = this.tagName.toLowerCase();
		if (t == 'text' || t == 'password' || tag == 'textarea')
			this.value = '';
		else if (t == 'checkbox' || t == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};

/**
 * Resets the form data.  Causes all form elements to be reset to their original value.
 */
$.fn.resetForm = function() {
	return this.each(function() {
		// guard against an input with the name of 'reset'
		// note that IE reports the reset function as an 'object'
		if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
			this.reset();
	});
};

/**
 * Enables or disables any matching elements.
 */
$.fn.enable = function(b) {
	if (b == undefined) b = true;
	return this.each(function() {
		this.disabled = !b;
	});
};

/**
 * Checks/unchecks any matching checkboxes or radio buttons and
 * selects/deselects and matching option elements.
 */
$.fn.selected = function(select) {
	if (select == undefined) select = true;
	return this.each(function() {
		var t = this.type;
		if (t == 'checkbox' || t == 'radio')
			this.checked = select;
		else if (this.tagName.toLowerCase() == 'option') {
			var $sel = $(this).parent('select');
			if (select && $sel[0] && $sel[0].type == 'select-one') {
				// deselect all other options
				$sel.find('option').selected(false);
			}
			this.selected = select;
		}
	});
};

// helper fn for console logging
// set $.fn.ajaxSubmit.debug to true to enable debug logging
function log() {
	if ($.fn.ajaxSubmit.debug && window.console && window.console.log)
		window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments,''));
};

})(jQuery);


/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);



/*-------------------------------------------------------------------- 
 * jQuery plugin: customInput()
 * by Maggie Wachs and Scott Jehl, http://www.filamentgroup.com
 * Copyright (c) 2009 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 * Article: http://www.filamentgroup.com/lab/accessible_custom_designed_checkbox_radio_button_inputs_styled_css_jquery/  
 * Usage example below (see comment "Run the script...").
--------------------------------------------------------------------*/


jQuery.fn.customInput = function(){
	$(this).each(function(i){	
		if($(this).is('[type=checkbox],[type=radio]')){
			var input = $(this);
			
			// get the associated label using the input's id
			var label = $('label[for='+input.attr('id')+']');
			
			//get type, for classname suffix 
			var inputType = (input.is('[type=checkbox]')) ? 'checkbox' : 'radio';
			
			// wrap the input + label in a div 
			//$('<div class="custom-'+ inputType +'"></div>').insertBefore(input).append(input, label);
			label.wrap('<div class="custom-'+ inputType +'"></div>');
			// find all inputs in this set using the shared name attribute
			var allInputs = $('input[name='+input.attr('name')+']');
			
			// necessary for browsers that don't support the :hover pseudo class on labels
			label.hover(
				function(){ 
					$(this).addClass('hover'); 
					if(inputType == 'checkbox' && input.is(':checked')){ 
						$(this).addClass('checkedHover'); 
					} 
				},
				function(){ $(this).removeClass('hover checkedHover'); }
			);
			
			//bind custom event, trigger it, bind click,focus,blur events					
			input.bind('updateState', function(){	
				if (input.is(':checked')) {
					if (input.is(':radio')) {				
						allInputs.each(function(){
							$('label[for='+$(this).attr('id')+']').removeClass('checked');
						});		
					};
					label.addClass('checked');
				}
				else { label.removeClass('checked checkedHover checkedFocus'); }
										
			})
			.trigger('updateState')
			.click(function(){ 
				$(this).trigger('updateState'); 
			})
			.focus(function(){ 
				label.addClass('focus'); 
				if(inputType == 'checkbox' && input.is(':checked')){ 
					$(this).addClass('checkedFocus'); 
				} 
			})
			.blur(function(){ label.removeClass('focus checkedFocus'); });
		}
	});
};

	



/*
 * jQuery.validity v1.0.2
 * http://validity.thatscaptaintoyou.com/
 * http://code.google.com/p/validity/
 * 
 * Copyright (c) 2009 Wyatt Allen
 * Dual licensed under the MIT and GPL licenses.
 *
 * Date: 2009-10-12 (Monday, 12 October 2009)
 * Revision: 127
 */

 (function($){var
 defaults={outputMode:"label",scrollTo:false,modalErrorsClickable:true,defaultFieldName:"This field",elementSupport:":text, :password, textarea, select, :radio, :checkbox",argToString:function(val){return val.getDate?(val.getMonth()+1)+"/"+val.getDate()+"/"+val.getFullYear():val;}};$.validity={settings:$.extend(defaults,{}),patterns:{integer:/^\d+$/,date:/^([01]?\d)\/([012]?\d|30|31)\/\d{1,4}$/,email:/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,usd:/^\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})?|\d{1,3}(\.\d{0,2})?|\.\d{1,2}?)$/,url:/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i,number:/^[+-]?(\d+(\.\d*)?|\.\d+)([Ee]\d+)?$/,zip:/^\d{5}(-\d{4})?$/,phone:/^[2-9]\d{2}-\d{3}-\d{4}$/,guid:/^(\{?([0-9a-fA-F]){8}-(([0-9a-fA-F]){4}-){3}([0-9a-fA-F]){12}\}?)$/,time12:/^[01]?\d:[0-5]\d?\s?[aApP]\.?[mM]\.?$/,time24:/^(20|21|22|23|[01]\d|\d)(([:][0-5]\d){1,2})$/,nonHtml:/^[^<>]*$/},messages:{require:"#{field} is required.",match:"#{field} is in an invalid format.",integer:"#{field} must be a positive, whole number.",date:"#{field} must be formatted as a date.",email:"#{field} must be formatted as an email.",usd:"#{field} must be formatted as a US Dollar amount.",url:"#{field} must be formatted as a URL.",number:"#{field} must be formatted as a number.",zip:"#{field} must be formatted as a zipcode ##### or #####-####.",phone:"#{field} must be formatted as a phone number ###-###-####.",guid:"#{field} must be formatted as a guid like {3F2504E0-4F89-11D3-9A0C-0305E82C3301}.",time24:"#{field} must be formatted as a 24 hour time: 23:00.",time12:"#{field} must be formatted as a 12 hour time: 12:00 AM/PM",lessThan:"#{field} must be less than #{max}.",lessThanOrEqualTo:"#{field} must be less than or equal to #{max}.",greaterThan:"#{field} must be greater than #{min}.",greaterThanOrEqualTo:"#{field} must be greater than or equal to #{min}.",range:"#{field} must be between #{min} and #{max}.",tooLong:"#{field} cannot be longer than #{max} characters.",tooShort:"#{field} cannot be shorter than #{min} characters.",equal:"Values don't match.",distinct:"A value was repeated.",sum:"Values don't add to #{sum}.",sumMax:"The sum of the values must be less than #{max}.",sumMin:"The sum of the values must be greater than #{min}.",nonHtml:"#{field} cannot contain HTML characters.",generic:"Invalid."},outputs:{},setup:function(options){this.settings=$.extend(this.settings,options);},report:null,isValidating:function(){return!!this.report;},start:function(){if(this.outputs[this.settings.outputMode]&&this.outputs[this.settings.outputMode].start){this.outputs[this.settings.outputMode].start();}
 this.report={errors:0,valid:true};},end:function(){var results=this.report||{errors:0,valid:true};this.report=null;if(this.outputs[this.settings.outputMode]&&this.outputs[this.settings.outputMode].end){this.outputs[this.settings.outputMode].end(results);}
 return results;},clear:function(){this.start();this.end();}};$.fn.extend({validity:function(arg){return this.each(function(){if(this.tagName.toLowerCase()=="form"){var f=null;if(typeof(arg)=="string"){f=function(){$(arg).require();};}
 else if($.isFunction(arg)){f=arg;}
 if(arg){$(this).bind("submit",function(){$.validity.start();f();return $.validity.end().valid;});}}});},require:function(msg){return validate(this,function(obj){return obj.value.length;},msg||$.validity.messages.require);},match:function(rule,msg){if(!msg){msg=$.validity.messages.match;if(typeof(rule)==="string"&&$.validity.messages[rule]){msg=$.validity.messages[rule];}}
 if(typeof(rule)=="string"){rule=$.validity.patterns[rule];}
 return validate(this,$.isFunction(rule)?function(obj){return!obj.value.length||rule(obj.value);}:function(obj){if(rule.global){rule.lastIndex=0;}
 return!obj.value.length||rule.test(obj.value);},msg);},range:function(min,max,msg){return validate(this,min.getTime&&max.getTime?function(obj){var d=new Date(obj.value);return d>=new Date(min)&&d<=new Date(max);}:function(obj){var f=parseFloat(obj.value);return f>=min&&f<=max;},msg||format($.validity.messages.range,{min:$.validity.settings.argToString(min),max:$.validity.settings.argToString(max)}));},greaterThan:function(min,msg){return validate(this,min.getTime?function(obj){return new Date(obj.value)>min;}:function(obj){return parseFloat(obj.value)>min;},msg||format($.validity.messages.greaterThan,{min:$.validity.settings.argToString(min)}));},greaterThanOrEqualTo:function(min,msg){return validate(this,min.getTime?function(obj){return new Date(obj.value)>=min;}:function(obj){return parseFloat(obj.value)>=min;},msg||format($.validity.messages.greaterThanOrEqualTo,{min:$.validity.settings.argToString(min)}));},lessThan:function(max,msg){return validate(this,max.getTime?function(obj){return new Date(obj.value)<max;}:function(obj){return parseFloat(obj.value)<max;},msg||format($.validity.messages.lessThan,{max:$.validity.settings.argToString(max)}));},lessThanOrEqualTo:function(max,msg){return validate(this,max.getTime?function(obj){return new Date(obj.value)<=max;}:function(obj){return parseFloat(obj.value)<=max;},msg||format($.validity.messages.lessThanOrEqualTo,{max:$.validity.settings.argToString(max)}));},maxLength:function(max,msg){return validate(this,function(obj){return obj.value.length<=max;},msg||format($.validity.messages.tooLong,{max:max}));},minLength:function(min,msg){return validate(this,function(obj){return obj.value.length>=min;},msg||format($.validity.messages.tooShort,{min:min}));},equal:function(arg0,arg1){var
 $reduction=(this.reduction||this).filter($.validity.settings.elementSupport),transform=function(val){return val;},msg=$.validity.messages.equal;if($reduction.length){if($.isFunction(arg0)){transform=arg0;if(typeof(arg1)=="string"){msg=arg1;}}
 else if(typeof(arg0)=="string"){msg=arg0;}
 var
 map=$.map($reduction,function(obj){return transform(obj.value);}),first=map[0],valid=true;for(var i in map){if(map[i]!=first){valid=false;}}
 if(!valid){raiseAggregateError($reduction,msg);this.reduction=$([]);}}
 return this;},distinct:function(arg0,arg1){var
 $reduction=(this.reduction||this).filter($.validity.settings.elementSupport),transform=function(val){return val;},msg=$.validity.messages.distinct,subMap=[],valid=true;if($reduction.length){if($.isFunction(arg0)){transform=arg0;if(typeof(arg1)=="string"){msg=arg1;}}
 else if(typeof(arg0)=="string"){msg=arg0;}
 var map=$.map($reduction,function(obj){return transform(obj.value);});for(var i1=0;i1<map.length;i1++){if(map[i1].length){for(var i2=0;i2<subMap.length;i2++){if(subMap[i2]==map[i1]){valid=false;}}
 subMap.push(map[i1]);}}
 if(!valid){raiseAggregateError($reduction,msg);this.reduction=$([]);}}
 return this;},sum:function(sum,msg){var $reduction=(this.reduction||this).filter($.validity.settings.elementSupport);if($reduction.length&&sum!=numericSum($reduction)){raiseAggregateError($reduction,msg||format($.validity.messages.sum,{sum:sum}));this.reduction=$([]);}
 return this;},sumMax:function(max,msg){var $reduction=(this.reduction||this).filter($.validity.settings.elementSupport);if($reduction.length&&max<numericSum($reduction)){raiseAggregateError($reduction,msg||format($.validity.messages.sumMax,{max:max}));this.reduction=$([]);}
 return this;},sumMin:function(min,msg){var $reduction=(this.reduction||this).filter($.validity.settings.elementSupport);if($reduction.length&&min<numericSum($reduction)){raiseAggregateError($reduction,msg||format($.validity.messages.sumMin,{min:min}));this.reduction=$([]);}
 return this;},nonHtml:function(msg){return validate(this,function(obj){return $.validity.patterns.nonHtml.test(obj.value);},msg||$.validity.messages.nonHtml);},assert:function(expression,msg){var $reduction=this.reduction||this;if($reduction.length){if($.isFunction(expression)){return validate(this,expression,msg||$.validity.messages.generic);}
 else if(!expression){raiseAggregateError($reduction,msg||$.validity.messages.generic);this.reduction=$([]);}}
 return this;}});function validate($obj,regimen,message){var
 $reduction=($obj.reduction||$obj).filter($.validity.settings.elementSupport),elements=[];$reduction.each(function(){if(regimen(this)){elements.push(this);}
 else{raiseError(this,format(message,{field:infer(this)}));}});$obj.reduction=$(elements);return $obj;}
 function addToReport(){if($.validity.isValidating()){$.validity.report.errors++;$.validity.report.valid=false;}}
 function raiseError(obj,msg){addToReport();if($.validity.outputs[$.validity.settings.outputMode]&&$.validity.outputs[$.validity.settings.outputMode].raise){$.validity.outputs[$.validity.settings.outputMode].raise($(obj),msg);}}
 function raiseAggregateError($obj,msg){addToReport();if($.validity.outputs[$.validity.settings.outputMode]&&$.validity.outputs[$.validity.settings.outputMode].raiseAggregate){$.validity.outputs[$.validity.settings.outputMode].raiseAggregate($obj,msg);}}
 function numericSum(obj){var accumulator=0;obj.each(function(){var n=parseFloat(this.value);accumulator+=isNaN(n)?0:n;});return accumulator;}
 function format(str,obj){for(var p in obj){str=str.replace("#{"+p+"}",obj[p]);}
 return capitalize(str);}
 function infer(field){var
 $f=$(field),ret=$.validity.settings.defaultFieldName;if($f.attr("title").length){ret=$f.attr("title");}
 else if(/^([A-Z0-9][a-z]*)+$/.test(field.id)){ret=field.id.replace(/([A-Z0-9])[a-z]*/g," $&");}
 else if(/^[a-z0-9_]*$/.test(field.id)){var arr=field.id.split("_");for(var i=0;i<arr.length;i++){arr[i]=capitalize(arr[i]);}
 ret=arr.join(" ");}
 return ret;}
 function capitalize(sz){return sz.substring?sz.substring(0,1).toUpperCase()+sz.substring(1,sz.length):sz;}})(jQuery);(function($){function getIdentifier($obj){return $obj.attr('id').length?$obj.attr('id'):$obj.attr('name');}
 $.validity.outputs.label={start:function(){$("label.error").remove();},end:function(results){if(!results.valid&&$.validity.settings.scrollTo){location.hash=$("label.error:eq(0)").attr('for');}},raise:function($obj,msg){var
 labelSelector="label.error[for='"+getIdentifier($obj)+"']";if($(labelSelector).length){$(labelSelector).text(msg);}
 else{$("<label/>").attr("for",getIdentifier($obj)).addClass("error").text(msg).click(function(){if($obj.length){$obj[0].select();}}).insertAfter($obj);}},raiseAggregate:function($obj,msg){if($obj.length){this.raise($($obj.get($obj.length-1)),msg);}}};})(jQuery);(function($){var
 errorClass="validity-modal-msg",container="body";$.validity.outputs.modal={start:function(){$("."+errorClass).remove();},end:function(results){if(!results.valid&&$.validity.settings.scrollTo){location.hash=$("."+errorClass+":eq(0)").attr('id');}},raise:function($obj,msg){if($obj.length){var
 off=$obj.offset(),obj=$obj.get(0),errorStyle={left:parseInt(off.left+$obj.width()+4,10)+"px",top:parseInt(off.top-10,10)+"px"};$("<div/>").addClass(errorClass).css(errorStyle).text(msg).click($.validity.settings.modalErrorsClickable?function(){$(this).remove();}:null).appendTo(container);}},raiseAggregate:function($obj,msg){if($obj.length){this.raise($($obj.get($obj.length-1)),msg);}}};})(jQuery);(function($){var
 container=".validity-summary-container",erroneous="validity-erroneous",errors="."+erroneous,wrapper="<li/>",buffer=[];$.validity.outputs.summary={start:function(){$(errors).removeClass(erroneous);buffer=[];},end:function(results){$(container).hide().find("ul").html('');if(buffer.length){for(var i=0;i<buffer.length;i++){$(wrapper).text(buffer[i]).appendTo(container+" ul");}
 $(container).show(1,function(){$(this).effect("pulsate",{times:2},1000);});if($.validity.settings.scrollTo){location.hash=$(errors+":eq(0)").attr("id");}}},raise:function($obj,msg){buffer.push(msg);$obj.addClass(erroneous);},raiseAggregate:function($obj,msg){this.raise($obj,msg);}};})(jQuery);

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */
 
 
 
 
 // Delay Plugin for jQuery
 // - http://www.evanbot.com
 // - copyright 2008 Evan Byrne
 /*
  * Jonathan Howard
  * jQuery Pause
  * version 0.2
  * Requires: jQuery 1.0 (tested with svn as of 7/20/2006)
  * Feel free to do whatever you'd like with this, just please give credit where
  * credit is do.
  * pause() will hold everything in the queue for a given number of milliseconds,
  * or 1000 milliseconds if none is given.
  */
 // Wait Plugin for jQuery
 // http://www.inet411.com
 // based on the Delay and Pause Plugin
  (function($) {
     $.fn.wait = function(option, options) {
         milli = 1000; 
         if (option && (typeof option == 'function' || isNaN(option)) ) { 
             options = option;
         } else if (option) { 
             milli = option;
         }
         // set defaults
         var defaults = {
             msec: milli,
             onEnd: options
         },
         settings = $.extend({},defaults, options);

         if(typeof settings.onEnd == 'function') {
             this.each(function() {
                 setTimeout(settings.onEnd, settings.msec);
             });
             return this;
         } else {
             return this.queue('fx',
             function() {
                 var self = this;
                 setTimeout(function() { $.dequeue(self); },settings.msec);
             });
         }

     }
 })(jQuery);
 
 
 
 
 /*
  * TextLimit - jQuery plugin for counting and limiting characters for input and textarea fields
  * 
  * pass '-1' as speed if you don't want the char-deletion effect. (don't just put 0)
  * Example: jQuery("Textarea").textlimit('span.counter',256)
  *
  * $Version: 2009.07.25 +r2
  * Copyright (c) 2009 Yair Even-Or
  * vsync.design@gmail.com
 */
 (function(jQuery) {
 	jQuery.fn.textlimit=function(counter_el, thelimit, speed) {
 		var charDelSpeed = speed || 15;
 		var toggleCharDel = speed != -1;
 		var toggleTrim = true;
 		var that = this[0];
 		var isCtrl = false; 
 		updateCounter();

 		function updateCounter(){
 			if(typeof that == "object")
 				jQuery(counter_el).text("("+(thelimit - that.value.length)+")");
 		};

 		this.keydown (function(e){ 
 			if(e.which == 17) isCtrl = true;
 			var ctrl_a = (e.which == 65 && isCtrl == true) ? true : false; // detect and allow CTRL + A selects all.
 			var ctrl_v = (e.which == 86 && isCtrl == true) ? true : false; // detect and allow CTRL + V paste.
 			// 8 is 'backspace' and 46 is 'delete'
 			if( this.value.length >= thelimit && e.which != '8' && e.which != '46' && ctrl_a == false && ctrl_v == false)
 				e.preventDefault();
 		})
 		.keyup (function(e){
 			updateCounter();
 			if(e.which == 17)
 				isCtrl=false;

 			if( this.value.length >= thelimit && toggleTrim ){
 				if(toggleCharDel){
 					// first, trim the text a bit so the char trimming won't take forever
 					// Also check if there are more than 10 extra chars, then trim. just in case.
 					if ( (this.value.length - thelimit) > 10 )
 						that.value = that.value.substr(0,thelimit+100);
 					var init = setInterval
 						( 
 							function(){ 
 								if( that.value.length <= thelimit ){
 									init = clearInterval(init); updateCounter() 
 								}
 								else{
 									// deleting extra chars (one by one)
 									that.value = that.value.substring(0,that.value.length-1); jQuery(counter_el).text('Hola! '+(thelimit - that.value.length));
 								}
 							} ,charDelSpeed 
 						);
 				}
 				else this.value = that.value.substr(0,thelimit);
 			}
 		});

 	};
 })(jQuery);
 
 
 /*
  * 	 styleSelect - apply style to a select box
  *   (http://www.8stream.com)
  *
  * 	 Copyright (c) 2009 Siim Sindonen, 8STREAM <siim@8stream.com>
  *   Dual licensed under the MIT and GPL licenses:
  *   http://www.opensource.org/licenses/mit-license.php
  *   http://www.gnu.org/licenses/gpl.html
  * 
  *   Requires jQuery version: >= 1.3.2
  * 	 $Version: 1.2.3 | 22.09.2009
  */

 (function($){

 	$.fn.styleSelect = function(options){

 		var tabindex = 1;

 		var opts = $.extend({}, $.fn.styleSelect.defaults , options);

 		//set tabindex		
 		$('input,select,textarea,button').each(function() {

 			var input = $(this);

 			if (!input.attr('tabindex')){

 				input.attr('tabindex', tabindex);
 				tabindex++;

 			} 
 		});

 		return this.each(function(){

 			mainSelect = $(this);
 			var mainId = mainSelect.attr('name');

 			var styledTabIndex = mainSelect.attr('tabindex');

 			var date = new Date;
 			var selectId = 'selectbox_'+mainId+date.getTime();

 			//Hidde select box
 			mainSelect.hide();

 			//Main container 
 			var mainContainer = $('<div tabindex="'+styledTabIndex+'"></div>').css({position : 'relative'})
 					.addClass(opts.styleClass)
 					.attr('id', selectId)
 					.insertBefore(mainSelect);

 			//Options container
 			var subContainer = $('<ul></ul>').css({'position' : 'absolute', 'z-index' : '100'-styledTabIndex, 'top' : opts.optionsTop, 'left' : opts.optionsLeft})
 					.appendTo($(mainContainer))
 					.hide();

 			//Generate options list
 			var optionsList = "";

 			mainSelect.find('option').each(function(){

 				optionsList += '<li id="'+$(this).val()+'"';
 				if($(this).attr('class')) optionsList += ' class="'+$(this).attr('class')+'" ';
 				optionsList += '>';
 				optionsList += '<span style="display: block;"';
 				if ($(this).attr('selected')) optionsList += ' class="selected" ';
 				optionsList += '>';
 				optionsList += $(this).text();
 				optionsList += '</span>';
 				optionsList += '</li>';

 			});

 				subContainer.append(optionsList);

 				checkSelected(opts.styleClass,opts.optionsWidth);

 			//Show otions
 			$('#'+selectId).click(function(){
 				$(this).find('ul').slideToggle(opts.speed);
 			});

 			//On click
 			$('#'+selectId+' li').click(function(){

 				doSelection($(this));

 			});

 			//Keyboard support
 			$('#'+selectId).keydown(function(event){

 				var active = $(this).find('.selected').parent();

 				if (event.keyCode == 40 || event.keyCode == 39 ){ doSelection(active.next()); }
 				if (event.keyCode == 37 || event.keyCode == 38 ){ doSelection(active.prev()); }

 				if (event.keyCode == 13 || event.keyCode == 0){ $(this).find('ul').slideToggle(opts.speed); }
 				if (event.keyCode == 9){ $(this).find('ul').hide(opts.speed); }

 			});

 			//Do selection
 			var doSelection = function(item){

 				item.siblings().find("span").removeClass('selected');
 				item.find("span").addClass('selected');

 				var selectedItem = item.attr('id');

 				var realSelector = $('select[name="'+mainId+'"]');
 				realSelector.siblings().selected = false;
 				realSelector.find('option[value="'+selectedItem+'"]').attr('selected','selected');
 				realSelector.trigger(opts.selectTrigger);

 				checkSelected(opts.styleClass,opts.optionsWidth);

 			}

 			$('#'+selectId).click(function(e) {
 				e.stopPropagation();
 			});

 			$(document).click(function() {
 				$('#'+selectId+' ul').hide();
 			});

 			});	
 		}

 		//Selected items check
 		function checkSelected(mainClass,mainWidth){

 				$('.'+mainClass).each(function(){

 					var elementList = $(this).find('ul');

 					$(this).find('span').each(function(){

 						var spanClass = $(this).attr("class");
 						if (spanClass == "passiveSelect" || spanClass == "activeSelect") $(this).remove();

 					});

 					var selectedName = $(this).find('.selected');

 					$('<span></span>').text(selectedName.text())
 							.attr('id', selectedName.parent().attr('id'))
 							.addClass('passiveSelect')
 							.appendTo($(this));

 					if (mainWidth === 0){
 						$(this).css({'width' :  elementList.width()});
 					}

 				});

 				$('.'+mainClass+' span').each(function(){
 					if ($(this).attr('id')){
 						$(this).removeClass();
 						$(this).addClass('activeSelect');
 					}
 				});
 		}	

 		$.fn.styleSelect.defaults = {

 			optionsTop: '26px',
 			optionsLeft: '0px',
 			optionsWidth: 0,
 			styleClass: 'selectMenu',
 			speed: 0,
 			selectTrigger: 'change'

 		};

 })(jQuery);
  
  
  
 /*
  * clearingInput: a jQuery plugin
  *
  * clearingInput is a simple jQuery plugin that provides example/label text
  * inside text inputs that automatically clears when the input is focused.
  * Common uses are for a hint/example, or as a label when space is limited.
  *
  * For usage and examples, visit:
  * http://github.com/alexrabarts/jquery-clearinginput
  *
  * Licensed under the MIT:
  * http://www.opensource.org/licenses/mit-license.php
  *
  * Copyright (c) 2008 Stateless Systems (http://statelesssystems.com)
  *
  * @author   Alex Rabarts (alexrabarts -at- gmail -dawt- com)
  * @requires jQuery v1.2 or later
  * @version  0.1.2
  */

 (function ($) {
   $.extend($.fn, {
     clearingInput: function (options) {
       var defaults = {blurClass: 'blur'};

       options = $.extend(defaults, options);

       return this.each(function () {
         var input = $(this).addClass(options.blurClass);
         var form  = input.parents('form:first');
         var label, text;

         text = options.text || textFromLabel() || input.val();

         if (text) {
           input.val(text);

           input.blur(function () {
             if (input.val() === '') {
               input.addClass(options.blurClass).val(text);
             }
           }).focus(function () {
             if (input.val() === text) {
               input.val('');
             }
             input.removeClass(options.blurClass);
           });

           form.submit(function() {
             if (input.hasClass(options.blurClass)) {
               input.val('');
             }
           });

           input.blur();
         }

         function textFromLabel() {
           label = form.find('label[for=' + input.attr('id') + ']');
           // Position label off screen and use it for the input text
           return label ? label.css({position: 'absolute', left: '-9999px'}).text() : '';
         }
       });
     }
   });
 })(jQuery);
 
 
 /* check */
 
 ;(function($){$.fn.simpleImageCheck=function(o){var n=this;if(n.length<1){return n;}
 o=(o)?o:{};o=auditOptions(o);n.each(function(){var i=$(this);if(i.is(':checkbox')){setup(i,o);}});return n;};var setup=function(n,o){var c=n.is(':checked');var src=o.image;if(c){src=o.imageChecked;}
 var id=n.attr('id');if(typeof(id)==='undefined'){id=n.attr('id','imageCheckInput_'+$.fn.simpleImageCheck.uid++).attr('id');}
 var t=$('label[for="'+id+'"]').text();var im=n.before("<img src='"+src+"' id='ic_"+id+"' alt='"+t+"' title='"+t+"' class='imageCheck"+((c)?' checked':'')+"' role='checkbox' aria-checked='"+((c)?'true':'false')+"' aria-controls='"+id+"' />").parent().find('img#ic_'+id);n.click(function(e,triggered){if(triggered===true){return;}
 handleClick(n,im,o,true);}).keypress(function(e){var k=(e.which)?e.which:((e.keyCode)?e.keyCode:0);if(k==13||k==32){e.preventDefault();$(this).click();}}).hide();im.css({cursor:'pointer'}).click(function(e){e.preventDefault();handleClick(n,im,o,false);}).keypress(function(e){var k=(e.which)?e.which:((e.keyCode)?e.keyCode:0);if(k==13||k==32){e.preventDefault();$(this).click();}}).hover(function(){$(this).addClass('imageCheckHover');},function(){$(this).removeClass('imageCheckHover');});}
 var handleClick=function(n,im,o,inputClick){if(im.hasClass('checked')===n.is(':checked')&&!inputClick){n.trigger('click',[true]).change();}
 var c=n.is(':checked');im.toggleClass('checked').attr({'aria-checked':''+((c)?'true':'false'),'src':''+((c)?o.imageChecked:o.image)});setTimeout(function(){o.afterCheck(c);},25);}
 var auditOptions=function(o){if(!$.isFunction(o.afterCheck)){o.afterCheck=function(){};}
 if(typeof(o.image)!='string'){o.image='';}
 if(typeof(o.imageChecked)!='string'){o.imageChecked='';}
 return o;}
 $.fn.simpleImageCheck.uid=0;})(jQuery);
 
 
 
 /*
  * SimpleModal 1.3.3 - jQuery Plugin
  * http://www.ericmmartin.com/projects/simplemodal/
  * Copyright (c) 2009 Eric Martin (http://twitter.com/EricMMartin)
  * Dual licensed under the MIT and GPL licenses
  * Revision: $Id: jquery.simplemodal.js 228 2009-10-30 13:34:27Z emartin24 $
  */
 ;(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:'body',focus:true,opacity:50,overlayId:'simplemodal-overlay',overlayCss:{},containerId:'simplemodal-container',containerCss:{},dataId:'simplemodal-data',dataCss:{},minHeight:200,minWidth:300,maxHeight:null,maxWidth:null,autoResize:false,autoPosition:true,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={o:null,d:{},init:function(data,options){var s=this;if(s.d.data){return false;}ieQuirks=$.browser.msie&&!$.boxModel;s.o=$.extend({},$.modal.defaults,options);s.zIndex=s.o.zIndex;s.occb=false;if(typeof data=='object'){data=data instanceof jQuery?data:$(data);if(data.parent().parent().size()>0){s.d.parentNode=data.parent();if(!s.o.persist){s.d.orig=data.clone(true);}}}else if(typeof data=='string'||typeof data=='number'){data=$('<div></div>').html(data);}else{alert('SimpleModal Error: Unsupported data type: '+typeof data);return s;}s.create(data);data=null;s.open();if($.isFunction(s.o.onShow)){s.o.onShow.apply(s,[s.d]);}return s;},create:function(data){var s=this;w=s.getDimensions();if(ie6){s.d.iframe=$('<iframe src="javascript:false;"></iframe>').css($.extend(s.o.iframeCss,{display:'none',opacity:0,position:'fixed',height:w[0],width:w[1],zIndex:s.o.zIndex,top:0,left:0})).appendTo(s.o.appendTo);}s.d.overlay=$('<div></div>').attr('id',s.o.overlayId).addClass('simplemodal-overlay').css($.extend(s.o.overlayCss,{display:'none',opacity:s.o.opacity/100,height:w[0],width:w[1],position:'fixed',left:0,top:0,zIndex:s.o.zIndex+1})).appendTo(s.o.appendTo);s.d.container=$('<div></div>').attr('id',s.o.containerId).addClass('simplemodal-container').css($.extend(s.o.containerCss,{display:'none',position:'fixed',zIndex:s.o.zIndex+2})).append(s.o.close&&s.o.closeHTML?$(s.o.closeHTML).addClass(s.o.closeClass):'').appendTo(s.o.appendTo);s.d.wrap=$('<div></div>').attr('tabIndex',-1).addClass('simplemodal-wrap').css({height:'100%',outline:0,width:'100%'}).appendTo(s.d.container);s.d.data=data.attr('id',data.attr('id')||s.o.dataId).addClass('simplemodal-data').css($.extend(s.o.dataCss,{display:'none'})).appendTo('body');data=null;s.setContainerDimensions();s.d.data.appendTo(s.d.wrap);if(ie6||ieQuirks){s.fixIE();}},bindEvents:function(){var s=this;$('.'+s.o.closeClass).bind('click.simplemodal',function(e){e.preventDefault();s.close();});if(s.o.close&&s.o.overlayClose){s.d.overlay.bind('click.simplemodal',function(e){e.preventDefault();s.close();});}$(document).bind('keydown.simplemodal',function(e){if(s.o.focus&&e.keyCode==9){s.watchTab(e);}else if((s.o.close&&s.o.escClose)&&e.keyCode==27){e.preventDefault();s.close();}});$(window).bind('resize.simplemodal',function(){w=s.getDimensions();s.setContainerDimensions(true);if(ie6||ieQuirks){s.fixIE();}else{s.d.iframe&&s.d.iframe.css({height:w[0],width:w[1]});s.d.overlay.css({height:w[0],width:w[1]});}});},unbindEvents:function(){$('.'+this.o.closeClass).unbind('click.simplemodal');$(document).unbind('keydown.simplemodal');$(window).unbind('resize.simplemodal');this.d.overlay.unbind('click.simplemodal');},fixIE:function(){var s=this,p=s.o.position;$.each([s.d.iframe||null,s.d.overlay,s.d.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 s=this,p=pos||'first';var input=$(':input:enabled:visible:'+p,s.d.wrap);input.length>0?input.focus():s.d.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:v.indexOf('%')>0?v:parseInt(v.replace(/px/,''));},setContainerDimensions:function(resize){var s=this;if(!resize||(resize&&s.o.autoResize)){var ch=s.getVal(s.d.container.css('height')),cw=s.getVal(s.d.container.css('width')),dh=s.d.data.outerHeight(true),dw=s.d.data.outerWidth(true);var mh=s.o.maxHeight&&s.o.maxHeight<w[0]?s.o.maxHeight:w[0],mw=s.o.maxWidth&&s.o.maxWidth<w[1]?s.o.maxWidth:w[1];if(!ch){if(!dh){ch=s.o.minHeight;}else{if(dh>mh){ch=mh;}else if(dh<s.o.minHeight){ch=s.o.minHeight;}else{ch=dh;}}}else{ch=ch>mh?mh:ch;}if(!cw){if(!dw){cw=s.o.minWidth;}else{if(dw>mw){cw=mw;}else if(dw<s.o.minWidth){cw=s.o.minWidth;}else{cw=dw;}}}else{cw=cw>mw?mw:cw;}s.d.container.css({height:ch,width:cw});if(dh>ch||dw>cw){s.d.wrap.css({overflow:'auto'});}}if(s.o.autoPosition){s.setPosition();}},setPosition:function(){var s=this,top,left,hc=(w[0]/2)-(s.d.container.outerHeight(true)/2),vc=(w[1]/2)-(s.d.container.outerWidth(true)/2);if(s.o.position&&Object.prototype.toString.call(s.o.position)==="[object Array]"){top=s.o.position[0]||hc;left=s.o.position[1]||vc;}else{top=hc;left=vc;}s.d.container.css({left:left,top:top});},watchTab:function(e){var s=this;if($(e.target).parents('.simplemodal-container').length>0){s.inputs=$(':input:enabled:visible:first, :input:enabled:visible:last',s.d.data[0]);if((!e.shiftKey&&e.target==s.inputs[s.inputs.length-1])||(e.shiftKey&&e.target==s.inputs[0])||s.inputs.length==0){e.preventDefault();var pos=e.shiftKey?'last':'first';setTimeout(function(){s.focus(pos);},10);}}else{e.preventDefault();setTimeout(function(){s.focus();},10);}},open:function(){var s=this;s.d.iframe&&s.d.iframe.show();if($.isFunction(s.o.onOpen)){s.o.onOpen.apply(s,[s.d]);}else{s.d.overlay.show();s.d.container.show();s.d.data.show();}s.focus();s.bindEvents();},close:function(){var s=this;if(!s.d.data){return false;}s.unbindEvents();if($.isFunction(s.o.onClose)&&!s.occb){s.occb=true;s.o.onClose.apply(s,[s.d]);}else{if(s.d.parentNode){if(s.o.persist){s.d.data.hide().appendTo(s.d.parentNode);}else{s.d.data.hide().remove();s.d.orig.appendTo(s.d.parentNode);}}else{s.d.data.hide().remove();}s.d.container.hide().remove();s.d.overlay.hide().remove();s.d.iframe&&s.d.iframe.hide().remove();s.d={};}}};})(jQuery);
 
 
/* misc */


function beforeForm() { 
	$('.asubmit').attr("disabled","disabled");
	$('#ajaxload').show();
	return true;
}

function processJson(data) { 
	if (data) {
		if (eval(data.bad)) {
			$('.asubmit').attr("disabled","");
      $('#ajaxload').hide();
		} else {
			var fheight = $("#form_container").height();
			var theight = (fheight - 90)
			$("#form_container").fadeOut("slow", function(){
        $('#ajaxload').hide();
				$("#form_notices").after('<div class="thanks" style="height: '+ theight +'px"><p><!-- strong>Vous venez de faire un heureux!</strong --> Votre compliment a bien été envoyé <!-- à YY -->et <strong>sera visible sur le site dès son approbation</strong>. <!-- YY rayonnera de joie, soyez-en certain! --></p><p>Vous désirez rendre <strong>une autre personne heureuse</strong>? Envoyez d\'autres compliments et <strong>augmentez vos chances</strong> de devenir testeur exclusif pour DIM!</p><p><a href="#new" id="sendnew">Envoyer un autre compliment</a></p></div>');
				$("#sendnew").click(function(){
					$(".thanks").hide();
					$('#add_compliment').resetForm();
					$("#ctrack").text("(180)");
					$("#form_container").fadeIn("slow");
					$('.asubmit').attr("disabled","");
					return false;
				})
			});
		}
	} else {
		$('#form_notices').text("Ajax error : no data received. ").fadeIn("slow");
	}
} 
 
 
 
function testProcessJson(data) { 
	if (data) {
		if (eval(data.bad)) {
			$('.asubmit').attr("disabled","");
      $("#terror").text("Adresse email incorrecte").fadeIn();
      $('#ajaxload').hide();
			return false;
		} else {
      $('.asubmit').attr("disabled","");
      $('#ajaxload').hide();
      $("#tester_container").html('<div id="poptop"><p class="done">Merci, votre participation a bien été enregistrée.</p><p>Nous vous contacterons personnellement si vous faites partie des heureux élus. <strong>N\'oubliez pas d\'augmenter vos chances</strong> de sélection en envoyant des compliments. Si vous n\'avez pas été retenu, pas de panique, vous pourrez <strong>participer de nouveau dès le mois prochain</strong>.</p><p><a href="#" class="after-close">Fermer</a></p></div><div id="popbottom"></div>');
      if (eval(data.compliment)) {
        $(".after-close").click(function(){
          var measure = ($(document).height() - 100);
          $.modal.close();
          $.scrollTo("#add_compliment", {duration: measure, axis:"y", easing: "easeOutQuad", offset: -18});
          return false;
        });
      } else {
        $(".after-close").click(function(){
          $.modal.close();
          return false;
        });
      }
			return false;
		};
	} else {
		$('#form_notices').text("Ajax error : no data received. ").fadeIn("slow");
	}

}


/*	compliment generator, inspired by the version at http://betes.free.fr/generateur.htm
		(c) blah blah blah 2009 - Colin O'Brien/Things etc	*/

function mixItUp(){
	$('#generator select').each(function() {
		many = $(this).children("option").size();
		saying = Math.random();
    saying = Math.floor(many*saying);
		$(this).val(saying);
	});
}

function doCompliment(){
	var compliment = "";
	var chain = [];
	$('#generator select > option:selected').each(function(i) {
			var current = $(this).text();
			chain[i] = current;
	});
	var compliment = chain[0] + ' ' + chain[1] + ' ' + chain[2] + ', ' + chain[3] +  ' ' + chain[4] +  ' ' + chain[5] + ', '  + chain[6] + ' ' + chain[7] + ' ' + chain[8] + ' ' + chain[9] + '.';
	text_area = document.getElementById('id_body_temp');
	text_area.value = '';
	text_area.value = compliment;
}


/* valign */

(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('margin-top', mh);
	});
};
})(jQuery);


(function ($) {
    $.fn.dvAlign = function(container) {
        return this.each(function(i){
	   if(container == null) {
	      container = 'div';
	   }
	   var paddingPx = 10; //change this value as you need (It is the extra height for the parent element)
	   $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
	   var el = $(this).children(container + ":first");
	   var elh = $(el).height(); //new element height
	   var ph = $(this).height(); //parent height
	   if(elh > ph) { //if new element height is larger apply this to parent
	       $(this).height(elh + paddingPx);
	       ph = elh + paddingPx;
	   }
	   var nh = (ph - elh) / 2; //new margin to apply
	   $(el).css('margin-top', nh);
        });
     };
})(jQuery);


