


	var Ajax = function(url,data,request,success)
	{
		var req = new Request({
			url: url?url:location.href,
			method:"post",
			evalScripts:true,
			autoCancel:true,
			data:data?data:'ajax=1',
			onRequest: request,
			onSuccess: success
		}).send();
	};

	
	Element.implement({
		
		toggle: function(el){
			if(this.getStyle("display")=="block"){this.setStyle("display","none");}
			else{this.setStyle("display","block");}
			return this;
		}
		
	});
	
	window.addEvent('domready',function(){
		$$('a.check_all').addEvent('click',function(ev){
			$$('input').each(function(el){
				el.checked=!el.checked;
			});
			return false;	
		});
		$$('input.check_all').addEvent('click',function(ev){
			var me = this;
			$$('input').each(function(el){
				el.checked = me.checked;
			});
		});
	});


	var confirm_before_exit = false;	
	var confirmExit = function() {
		if(confirm_before_exit.length) { return confirm_before_exit; }
		if(confirm_before_exit) { return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?"; }
//		return null;
	};
	window.onbeforeunload = confirmExit;


	



	window.addEvent("domready",function(){

	
		$$('a.confirm').each(function(el){
			el.addEvent('click',function(ev){
				var m = el.get('title')?el.get('title'):'Are you sure you want to do this?';
				var c = confirm(m);
				return c;
			});
		});
	
		/*
		$$("input.required","textarea.required").each(function(itm,i){
			itm.addEvent("blur",function(ev){
				var message = '<i class="error"> This is required</i>';
				var label = $$('label[for='+itm.get('id')+']');
				label = label ? label[0] : false;
				if(itm.value.length==0) { 
					if( label && !label.get('html').contains(message) ) { label.set('html',label.get('html')+message); };
					itm.addClass('missing'); 
				} else { 
					if(label) { label.set('html', label.get('html').replace(eval("/"+message.escapeRegExp()+"/"),'') ); };
					itm.removeClass("missing"); 
				}
			});
		});
		*/
	

		$$('a[rel=external]').each(function(e){e.setProperty('target','_blank');});

		Element.implement({
			hilite: function(t,type){
				if(!t) { t = ''; }
				if(!type) { type = 'success'; }
				if(t) { this.set("html","<p>"+t+"</p>").addClass(type).highlight("#ffffff"); }
				return this;
			}
		});

	});


	window.addEvent('domready',function(){

		/* Check numbers (on blur) */
		$$('.numbers_only').each(function(el){
			el.addEvent('blur',function(ev){
				el.set('value',el.get('value').replace(/[^0-9]/g,''));
				if(el.get('maxlength')){
					el.set('value',el.get('value').substring(0,el.get('maxlength')));
				}
			});
		});

		/* Highlight fields on focus AND show guidelines... */
		$$('input','select','textarea').each(function(el){
			if( !el.getParent('li') ) { return; }
			if( el.getParent('li').getChildren('.guidelines').length>0){
				el.addEvent('focus',function(ev){
					el.getParent('li').addClass('showguidelines');
				});
				el.addEvent('blur',function(ev){
					el.getParent('li').removeClass('showguidelines');
				});
			}
			el.addEvent('focus',function(ev){
				el.getParent('li').addClass('highlighted');
			});
			el.addEvent('blur',function(ev){
				el.getParent('li').removeClass('highlighted');
			});
		});

		$$('.buttons button').each(function(el){
			el.addEvent('click',function(ev){
				el.getChildren('img').each(function(img){
					if ( img.getProperty('src').test('processing') ) {
						img.removeClass('hide').setProperty('style','display:inline;');
					} else {
						img.addClass('hide').setProperty('style','display:none;');
					}
				});
			});
		});

		$$('button').each(function(el){
			el.addEvent('mouseover',function(ev){
				el.addClass('over');
			});
			el.addEvent('mouseout',function(ev){
				el.removeClass('over');
			});
		});

	});

	
	var mailto = function(a,b,c,d) { return '<'+'a href'+'="mail'+'to:'+a+'@'+b+'.'+c+'">'+(d?d:(a+'@'+b+'.'+c))+'<'+'/'+'a>'; };

	
