// JavaScript Document

	function _append_zero(n){
		if (n>0 && n<10){
			return '0' + n;	
		}
		return n;
	}
	
	function _external_internal_links()
	{
		// links;
		
		$$("a").each(function(n) {
			if ((n.protocol=='http:' || n.protocol=='https:') && window.location.host!=n.hostname){
				n.target = '_blank';
				/*n.observe('click', function (e){
					//window.open(n.href);
					alert(n.hostname + ' ? ' + window.location.host);
					e.stop();
				});
				//e.stop();*/
				
			}	
		});
	}
	
	// auto height
	function _autoHeight(){
		$$('textarea.autoHeight').each(function (e){
			var txt = $(e);
			var ht = txt.rows-1;
	
			e.onkeydown = function (el){
				/*alert(txt.rows);	
				txt.height != txt.dummy.getHeight() + txt.line_height*/
				var c = 0;
				var r = 2;				
				var t = txt.value;
				for(var i=0; i<t.length; i++) {
					if (t.substr(i,1) == '\n') {
						c = 0;
						r++;
					}
					else {
						c++;
						if(c >= txt.cols) { c=0; r++;}
					}
				}
				if (r>ht){
					txt.rows = r;				
				}
			}
		});
	}
	
	function _formSubmission()
	{
		$$("form").each(function(n) {
			
			// check for no magic;
			
			if (n.hasClassName('noMagic')==false){
				n.observe('submit', function(e){
					// process form;
					var valid = true;
					
					if (_required_fields = n.select('.required')){
						_required_fields.each(function(r)						   
						{
							if (r_object = $(r.readAttribute('for'))){
								
								if (r_object.getValue()=='' && r_object.disabled==false){
									valid = false;
									r.up('li').addClassName('error');
								}
							}
						});
						
					}
					
					if (valid){
					
						_process_indicator_html = '<dl class="clearfix submit_spin_icon warn inform"><dt class="title"><b>un</b> <span>momento</span></dt>';
						_process_indicator_html += '<dd class="story"><p>processing.</p></dd><dd class="tag">please, be patient &ndash; it does <em>tend</em> to take awhile.</dd></dl>';
								
						_process_object = document.createElement('div');
						Element.extend(_process_object);
						_process_object.update(_process_indicator_html);
						_process_object.id = 'form_processing';
				
						n.select('fieldset').invoke('hide'); // hide forms;
						_process_object.addClassName('form_processing');
						n.insert(_process_object);
						
					} else {
						e.stop();
					}
				});
			}
		});
	}
	
	
	function _apply_general_actions()
	{	
		_autoHeight(); // done
		_external_internal_links(); // done
		_formSubmission(); // done
	}
	
	_apply_action('_apply_general_actions');
	
	
	
	



