//looking at other peoples code is silly!

var charityCall = {
	effectel: {},
	datePickers: {},

	start: function() {

		if ($('adminNewsForm')) {
			charityCall.adminNewsCancelEdit();
		}
		
		$$('.demoTips').each(function(element,index) {
			var content = element.get('title').split(' :: ');
			//element.store('tip:title', content[0]);
			element.store('tip:title', ' ');
			element.store('tip:text', content[1]);
		});
		var demoTips = new Tips($$('.demoTips'), {
			showDelay: 100,
			hideDelay: 0,
			fixed: true,
			offset: {x: 10,y:18}
		});

		$$('input.DatePicker').each( function(el){
			var pickerName = el.get('id');
			charityCall.datePickers[pickerName] = new DatePicker(el);
		});

		var sideblocks = $$('#content .side li');
		sideblocks.each(function(el, i){

			var first = el.getElement('a');
			if (!first) return;
			var overfxs = new Fx.Morph(first, {'duration': 150, 'wait': false, transition: Fx.Transitions.Sine.easeOut});		
			var tocolor = '#2980be';
			var fromcolor = '#707070';		
			el.mouseouted = true;
			el.addEvent('mouseenter', function(e){
				overfxs.start({
					'color': tocolor,
					'margin-left': -10
				});
			});
			el.addEvent('mouseleave', function(e){
				overfxs.start({
					'color': fromcolor,
					'margin-left': 0
				});
			});
		});	
	
		if ($('demobar')){	
			var sideblocks = $$('#demobar li');
			sideblocks.each(function(el, i){
	
				var first = el.getElement('a');
				if (!first) return;
				var overfxs = new Fx.Morph(first, {'duration': 150, 'wait': false, transition: Fx.Transitions.Sine.easeOut});		
				var tocolor = '#2980be';
				var fromcolor = '#707070';		
				el.mouseouted = true;
				el.addEvent('mouseenter', function(e){
					overfxs.start({
						'color': tocolor,
						'margin-left': 10
					});
				});
				el.addEvent('mouseleave', function(e){
					overfxs.start({
						'color': fromcolor,
						'margin-left': 0
					});
				});
	
			});
		}


		if ($('footer')){	
			var sideblocks = $$('#footer li, #postButtonDiv li');
			sideblocks.each(function(el, i){
	
				var first = el.getElement('a');
				if (!first) return;
				var overfxs = new Fx.Morph(first, {'duration': 150, 'wait': false, transition: Fx.Transitions.Sine.easeOut});		
				var tocolor = '#2980be';
				var fromcolor = '#707070';		
				el.mouseouted = true;
				el.addEvent('mouseenter', function(e){
					overfxs.start({
						'color': tocolor
					});
				});
				el.addEvent('mouseleave', function(e){
					overfxs.start({
						'color': fromcolor
					});
				});
	
			});
		}
	
		$$('.icons img').each(function(el, i){
			el.addEvent('mouseover', function(){
				el.set('tween', {duration: 200, transition: Fx.Transitions.Sine.easeOut});
				el.tween('opacity', .5);
			});	
			el.addEvent('mouseout', function(){
				el.set('tween', {duration: 350, transition: Fx.Transitions.Sine.easeOut});
				el.tween('opacity', 1);	
			});
		});
	
		$$('.homelinks a').each(function(el, i){
			var image = el.getElement('img');
			el.addEvent('mouseover', function(){
				image.set('tween', {duration: 200, transition: Fx.Transitions.Sine.easeOut});
				image.tween('opacity', .5);
			});	
			el.addEvent('mouseout', function(){
				image.set('tween', {duration: 350, transition: Fx.Transitions.Sine.easeOut});
				image.tween('opacity', 1);	
			});
		});
		
	
		if ($('returnMessage')) {
			charityCall.effectel.returnMessage = new Fx.Slide($('returnMessage'), {
				duration: 100,
				transisition: Fx.Transitions.Quad.easeOut
			});
			charityCall.effectel.returnMessage.hide();
		}
		if ($('receiptForm')) {
			charityCall.effectel.receiptForm = new Fx.Slide($('receiptForm'), {
				duration: 100,
				transisition: Fx.Transitions.Quad.easeOut
			});
		}
		
		if ($('postButtonHep')) {
			$('postButtonHep').addEvent('click', function(e){
				charityCall.hepSearchPost();
				e.stop();
			});
		}
	
		if ($('adminNewsButtonNew')) {
			$('adminNewsButtonNew').addEvent('click', function(e){
				charityCall.adminNewsPost();
				e.stop();
			});
		}
		
		if ($('adminNewsButtonSave')) {
			$('adminNewsButtonSave').addEvent('click', function(e){
				charityCall.adminNewsPost();
				e.stop();
			});
		}
		
		if ($('postButton')) {
			$('postButton').addEvent('click', function(e){
				charityCall.receiptPost();
				e.stop();
			});
		}

		if ($('postButtonCustom')) {
			$('postButtonCustom').addEvent('click', function(e){
				charityCall.customPost();
				e.stop();
			});
		}

		if ($('postButtonContact')) {
			$('postButtonContact').addEvent('click', function(e){
				charityCall.contactPost();
				e.stop();
			});
		}

		if ($('postButtonHelp')) {
			$('postButtonHelp').addEvent('click', function(e){
				charityCall.helpPost();
				e.stop();
			});
		}

		if ($('postButtonPartnership')) {
			$('postButtonPartnership').addEvent('click', function(e){
				charityCall.partnershipPost();
				e.stop();
			});
		}
		
		if ($('postButtonLogin')) {
			$('postButtonLogin').addEvent('click', function(e){
				charityCall.loginPost();
				e.stop();
			});
		}
		
		if ($('postButtonVideo')) {
			$('postButtonVideo').addEvent('click', function(e){
				charityCall.videoPost();
				e.stop();
			});
		}

		if ($('postReminder')) {
			$('postReminder').addEvent('click', function(e){
				charityCall.reminderPost();
				e.stop();
			});
		}

		if ($('reminderForm')) {
			$('reminderForm').addEvent('submit', function(e){
				charityCall.reminderPost();
				e.stop();
				return false;
			});
		}

		if ($('partnershipForm')) {
			$('partnershipForm').addEvent('submit', function(e){
				charityCall.partnershipPost();
				e.stop();
				return false;
			});
		}

		if ($('contactForm')) {
			$('contactForm').addEvent('submit', function(e){
				charityCall.contactPost();
				e.stop();
				return false;
			});
		}

		if ($('helpForm')) {
			$('helpForm').addEvent('submit', function(e){
				charityCall.helpPost();
				e.stop();
				return false;
			});
		}

		if ($('customForm')) {
			$('customForm').addEvent('submit', function(e){
				charityCall.customPost();
				e.stop();
				return false;
			});
		}

		if ($('receiptForm')) {
			$('receiptForm').addEvent('submit', function(e){
				charityCall.receiptPost();
				e.stop();
				return false;
			});
		}
		
		if ($('loginForm')) {
			$('loginForm').addEvent('submit', function(e){
				charityCall.loginPost();
				e.stop();
				return false;
			});
		}
		
		if ($('videoForm')) {
			$('videoForm').addEvent('submit', function(e){
				charityCall.videoPost();
				e.stop();
				return false;
			});
		}
		
		if ($('changepassForm')) {
			$('changepassForm').addEvent('submit', function(e){
				charityCall.changepassPost();
				e.stop();
				return false;
			});
		}
	},

	errorScroll: function() {
		var myFx = new Fx.Scroll($(document.body), {
		    offset: {
		        'x': 0,
		        'y': 0
		    },
			duration: 200,
			transition: Fx.Transitions.Sine.easeOut
		}).toTop();
	},

	phoneValidate: {
		zChar: new Array(' ', '(', ')', '-', '.'),
		maxphonelength: 13,
		phonevalue1: null,
		phonevalue2: null,
		cursorposition: null,
		
		ParseForNumber1: function(object){
			charityCall.phoneValidate.phonevalue1 = charityCall.phoneValidate.ParseChar(object.value, charityCall.phoneValidate.zChar);
		},

		ParseForNumber2: function (object){
			charityCall.phoneValidate.phonevalue2 = charityCall.phoneValidate.ParseChar(object.value, charityCall.phoneValidate.zChar);
		},
		
		backspacerUP: function (object,e) {
			if(e){
				e = e
			} else {
				e = window.event
			}
			if(e.which){
				var keycode = e.which
			} else {
				var keycode = e.keyCode
			}
			
			charityCall.phoneValidate.ParseForNumber1(object)
			
			if(keycode >= 48){
				charityCall.phoneValidate.ValidatePhone(object)
			}
		},
		
		backspacerDOWN: function (object,e) {
			if(e){
				e = e
			} else {
				e = window.event
			}
			if(e.which){
				var keycode = e.which
			} else {
				var keycode = e.keyCode
			}
			charityCall.phoneValidate.ParseForNumber2(object)
		},
		
		Getcursorposition: function (){
		
			var t1 = charityCall.phoneValidate.phonevalue1;
			var t2 = charityCall.phoneValidate.phonevalue2;
			var bool = false
			for (i=0; i<t1.length; i++) {
				if (t1.substring(i,1) != t2.substring(i,1)) {
					if(!bool) {
						charityCall.phoneValidate.cursorposition=i
						bool=true
					}
				}
			}
		},
		
		ValidatePhone: function (object){
			
			var p = charityCall.phoneValidate.phonevalue1
			
			p = p.replace(/[^\d]*/gi,"")
			
			if (p.length < 3) {
			object.value=p
			} else if(p.length==3){
			pp=p;
			d4=p.indexOf('(')
			d5=p.indexOf(')')
			if(d4==-1){
			pp="("+pp;
			}
			if(d5==-1){
			pp=pp+")";
			}
			object.value = pp;
			} else if(p.length>3 && p.length < 7){
			p ="(" + p;
			l30=p.length;
			p30=p.substring(0,4);
			p30=p30+")"
			
			p31=p.substring(4,l30);
			pp=p30+p31;
			
			object.value = pp;
			
			} else if(p.length >= 7){
			p ="(" + p;
			l30=p.length;
			p30=p.substring(0,4);
			p30=p30+")"
			
			p31=p.substring(4,l30);
			pp=p30+p31;
			
			l40 = pp.length;
			p40 = pp.substring(0,8);
			p40 = p40 + "-"
			
			p41 = pp.substring(8,l40);
			ppp = p40 + p41;
			
			object.value = ppp.substring(0, charityCall.phoneValidate.maxphonelength);
			}
			
			charityCall.phoneValidate.Getcursorposition()
			
			if(charityCall.phoneValidate.cursorposition >= 0){
			if (charityCall.phoneValidate.cursorposition == 0) {
			charityCall.phoneValidate.cursorposition = 2
			} else if (charityCall.phoneValidate.cursorposition <= 2) {
			charityCall.phoneValidate.cursorposition = charityCall.phoneValidate.cursorposition + 1
			} else if (charityCall.phoneValidate.cursorposition <= 5) {
			charityCall.phoneValidate.cursorposition = charityCall.phoneValidate.cursorposition + 2
			} else if (charityCall.phoneValidate.cursorposition == 6) {
			charityCall.phoneValidate.cursorposition = charityCall.phoneValidate.cursorposition + 2
			} else if (charityCall.phoneValidate.cursorposition == 7) {
			charityCall.phoneValidate.cursorposition = charityCall.phoneValidate.cursorposition + 4
			e1=object.value.indexOf(')')
			e2=object.value.indexOf('-')
			if (e1>-1 && e2>-1){
			if (e2-e1 == 4) {
			charityCall.phoneValidate.cursorposition = charityCall.phoneValidate.cursorposition - 1
			}
			}
			} else if (charityCall.phoneValidate.cursorposition < 11) {
			charityCall.phoneValidate.cursorposition = charityCall.phoneValidate.cursorposition + 3
			} else if (charityCall.phoneValidate.cursorposition == 11) {
			charityCall.phoneValidate.cursorposition = charityCall.phoneValidate.cursorposition + 1
			} else if (charityCall.phoneValidate.cursorposition >= 12) {
			charityCall.phoneValidate.cursorposition = charityCall.phoneValidate.cursorposition
			}
			
			try {
				var txtRange = object.createTextRange();
				txtRange.moveStart( "character", charityCall.phoneValidate.cursorposition);
				txtRange.moveEnd( "character", charityCall.phoneValidate.cursorposition - object.value.length);
				txtRange.select();
			} catch (e) {}
			}
		
		},
		
		ParseChar: function (sStr, sChar)
		{
			if (sChar.length == null)
			{
			charityCall.phoneValidate.zChar = new Array(sChar);
			}
			else charityCall.phoneValidate.zChar = sChar;
			
			for (i=0; i<charityCall.phoneValidate.zChar.length; i++)
			{
			sNewStr = "";
			
			var iStart = 0;
			var iEnd = sStr.indexOf(sChar[i]);
			
			while (iEnd != -1)
			{
			sNewStr += sStr.substring(iStart, iEnd);
			iStart = iEnd + 1;
			iEnd = sStr.indexOf(sChar[i], iStart);
			}
			sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);
			
			sStr = sNewStr;
			}
			
			return sNewStr;
		}

	},
	
	adminNewsEdit: function(id) {
		$('admin_news_date').value = $('admin_news_item_' + id).getElement('.adminNewsDate span').get('html');
		$('admin_news_title').value = $('admin_news_item_' + id).getElement('.adminNewsTitle span').get('html');
		$('admin_news_content').value = $('admin_news_item_' + id).getElement('.adminNewsContent span').get('html');
		$('admin_news_id').value = id;
		$('postButtonNew').style.display = 'none';
		$('postButtonSave').style.display = '';
		$('adminNewsEditbar').style.display = '';
	},
	
	adminNewsCancelEdit: function() {
		$('admin_news_date').value = '';
		$('admin_news_title').value = '';
		$('admin_news_content').value = '';
		$('admin_news_id').value = '0';
		$('postButtonNew').style.display = '';
		$('postButtonSave').style.display = 'none';
		$('adminNewsEditbar').style.display = 'none';
	},
	

	adminNewsPost: function() {
		$('adminNewsButtonNew').disabled = true;
		$('adminNewsButtonNew').setAttribute("class", "buttonWait");

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';
		$('returnMessage').empty();
		charityCall.effectel.returnMessage.hide();

		var jsonRequest = JSON.encode({
			date: $('admin_news_date').value,
			title: $('admin_news_title').value,
			content: $('admin_news_content').value,
			news_id: $('admin_news_id').value
		});

		if ($('admin_news_id').value && $('admin_news_id').value != '0') {
			var url = '/panel/news/edit';
			var request = new Request.JSON({
				url: url,
				onComplete: function(response) {

					var content = '';

					if (response && response.status) {
						content = '<div class="messageSuccess"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-ok.png">&nbsp;&nbsp;</td><td class="message">Your news article has successfully been edited.</td></tr></table></div><br /><br />';
						$('admin_news_item_' + $('admin_news_id').value).set('html',response.html);
						$('admin_news_item_' + $('admin_news_id').value).highlight();
						$('postButtonDiv').style.display = '';
						charityCall.adminNewsCancelEdit();
					} else {

						content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">Please enter all of the bellow fields.</td></tr></table></div><br /><br />';
						$('postButtonDiv').style.display = '';	
					}

					$('returnMessage').set('html',content);	
					$('returnMessage').getElement('div').highlight();
					
					$('ajaxLoader').style.display = 'none';
					charityCall.effectel.returnMessage.slideIn();
					charityCall.errorScroll();

				}
			}).get({json: jsonRequest});
			
		} else {
			var url = '/panel/news/new';
			var request = new Request.JSON({
				url: url,
				onComplete: function(response) {
					var content = '';
	
					if (response && response.status) {
						content = '<div class="messageSuccess"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-ok.png">&nbsp;&nbsp;</td><td class="message">Your news article has sucessfully been created.</td></tr></table></div><br /><br />';
						$('admin_news_container').set('html',response.html + $('admin_news_container').get('html'));
						$('admin_news_item_' + response.id).highlight();
						if ($('admin_news_none')) {
							$('admin_news_none').style.display = 'none';
						}
						$('postButtonDiv').style.display = '';
						charityCall.adminNewsCancelEdit();
						
					} else {
	
						content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">Please enter all of the bellow fields.</td></tr></table></div><br /><br />';
						$('postButtonDiv').style.display = '';	
					}
	
					$('returnMessage').set('html',content);	
					$('returnMessage').getElement('div').highlight();
					
					$('ajaxLoader').style.display = 'none';
					charityCall.effectel.returnMessage.slideIn();
					charityCall.errorScroll();
	
				}
			}).get({json: jsonRequest});
		}
	},
	

	adminDeleteNews: function(id) {
		charityCall.adminNewsCancelEdit();
		var jsonRequest = JSON.encode({
			id: id
		});

		var url = '/panel/news/delete';
		var request = new Request.JSON({
			url: url,
			onComplete: function(response) {

				var content = '';

				if (response && response.status) {
					content = '<div class="messageSuccess"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-ok.png">&nbsp;&nbsp;</td><td class="message">Successfully deleted.</td></tr></table></div><br /><br />';
					$('admin_news_item_' + id).destroy();
				} else {
					content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">Failed to delete for some strange reason.</td></tr></table></div><br /><br />';
				}

				$('returnMessage').set('html',content);	
				$('returnMessage').getElement('div').highlight();

				charityCall.effectel.returnMessage.slideIn();
				charityCall.errorScroll();
				charityCall.adminNewsCancelEdit();

			}
		}).get({json: jsonRequest});
	},
	
	loginPost: function() {
		$('postButtonLogin').disabled = true;
		$('postButtonLogin').setAttribute("class", "buttonWait");

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';
		$('returnMessage').empty();
		charityCall.effectel.returnMessage.hide();

		var jsonRequest = JSON.encode({
			username: $('login_user').value,
			password: $('login_pass').value
		});

		var url = '/login/login';
		var request = new Request.JSON({
			url: url,
			onComplete: function(response) {

				var content = '';

				if (response && response.status) {
					location.href = '/panel';
				} else {
					content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">There was an error with your username / password combination.</td></tr></table></div><br /><br />';
					$('postButtonDiv').style.display = '';	
				}

				$('returnMessage').set('html',content);	
				
				$('ajaxLoader').style.display = 'none';
				charityCall.effectel.returnMessage.slideIn();
				charityCall.errorScroll();

			}
		}).get({json: jsonRequest});
	},
	
	changepassPost: function() {
		$('postButtonChangepass').disabled = true;
		$('postButtonChangepass').setAttribute("class", "buttonWait");

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';
		$('returnMessage').empty();
		charityCall.effectel.returnMessage.hide();

		var jsonRequest = JSON.encode({
			old: $('pass_old').value,
			new_pass: $('pass_new').value,
			new_pass: $('pass_confirm').value
		});

		var url = '/login/login';
		var request = new Request.JSON({
			url: url,
			onComplete: function(response) {

				var content = '';

				if (response && response.status) {
					location.href = '/panel';
				} else {
					content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">There was an error with your username / password combination.</td></tr></table></div><br /><br />';
					$('postButtonDiv').style.display = '';	
				}

				$('returnMessage').set('html',content);	
				
				$('ajaxLoader').style.display = 'none';
				charityCall.effectel.returnMessage.slideIn();
				charityCall.errorScroll();

			}
		}).get({json: jsonRequest});
	},
	
	videoPost: function() {
		$('postButtonVideo').disabled = true;
		$('postButtonVideo').setAttribute("class", "buttonWait");

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';
		$('returnMessage').empty();
		charityCall.effectel.returnMessage.hide();

		var jsonRequest = JSON.encode({
			email: $('video_email').value,
			name: $('video_name').value,
			company: $('video_company').value,
			terms: $('video_terms').checked ? '1' : ''
		});

		var url = '/video/login';
		var request = new Request.JSON({
			url: url,
			onComplete: function(response) {

				var content = '';

				if (response && response.status) {
					window.location.href = window.location.href;
				} else {
					content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">Please complete the form below.</td></tr></table></div><br /><br />';
					$('postButtonDiv').style.display = '';	
				}

				$('returnMessage').set('html',content);	
				
				$('ajaxLoader').style.display = 'none';
				charityCall.effectel.returnMessage.slideIn();
				charityCall.errorScroll();

			}
		}).get({json: jsonRequest});
	},

	reminderPost: function() {
		$('postReminder').disabled = true;
		$('postReminder').addClass('buttonWait');

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';

		$('returnMessage').empty();
		charityCall.effectel.returnMessage.hide();

		var jsonRequest = JSON.encode({
			email: $('reminder_email').value,
			interval: $('reminder_interval').value,
			active: $('reminder_active').value
		});

		var url = '/reminder/' + $('reminder_id').value + '/' + $('reminder_session').value + '/update';
		var request = new Request.JSON({
			url: url,
			onComplete: function(response) {

				var content = '';

				if (response && response.status) {
					content = '<div class="messageSuccess"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-ok.png">&nbsp;&nbsp;</td><td class="message">Your reminder has been updated.</td></tr></table></div><br /><br />';
				} else {
					content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">Please enter all of the bellow fields.</td></tr></table></div><br /><br />';
				}
				if (response && response.error) {
					alert(response.error);
				}

				$('postReminder').disabled = false;
				$('postReminder').removeClass('buttonWait');
		
				$('ajaxLoader').style.display = 'none';
				$('postButtonDiv').style.display = '';

				$('returnMessage').set('html',content);	
				
				$('ajaxLoader').style.display = 'none';
				charityCall.effectel.returnMessage.slideIn();
				charityCall.errorScroll();

			}
		}).get({json: jsonRequest});
	},

	receiptPost: function() {
		$('postButton').disabled = true;
		$('postButton').setAttribute("class", "buttonWait");

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';
		$('returnMessage').empty();
		charityCall.effectel.returnMessage.hide();

		var jsonRequest = JSON.encode({
			name: $('receipt_name').value,
			charity: $('receipt_charity').value,
			phone: $('receipt_phone').value,
			email: $('receipt_email').value,
			date: $('receipt_date').value
		});

		var url = '/receipt/send';
		var request = new Request.JSON({
			url: url,
			onComplete: function(response) {

				var content = '';

				if (response && response.status) {
					content = '<div class="messageSuccess"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-ok.png">&nbsp;&nbsp;</td><td class="message">Your request has been completed.</td></tr></table></div><br /><br />';
					charityCall.effectel.receiptForm.slideOut();
					$('postButtonDiv').style.display = 'none';
				} else {
					content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">Please enter all of the bellow fields.</td></tr></table></div><br /><br />';
					$('postButtonDiv').style.display = '';	
				}

				$('returnMessage').set('html',content);	
				
				$('ajaxLoader').style.display = 'none';
				charityCall.effectel.returnMessage.slideIn();
				charityCall.errorScroll();

			}
		}).get({json: jsonRequest});
	},

	customPost: function() {
		$('postButtonCustom').disabled = true;
		$('postButtonCustom').setAttribute("class", "buttonWait");

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';
		$('returnMessage').empty();
		charityCall.effectel.returnMessage.hide();

		var jsonRequest = JSON.encode({
			subject: $('contact_subject').value,
			message: $('contact_message').value,
			email: $('contact_email').value
		});

		var url = '/customorder/send';
		var request = new Request.JSON({
			url: url,
			onComplete: function(response) {

				var content = '';

				if (response && response.status) {
					content = '<div class="messageSuccess"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-ok.png">&nbsp;&nbsp;</td><td class="message">Your request has been completed.</td></tr></table></div><br /><br />';
					charityCall.effectel.receiptForm.slideOut();
					$('postButtonDiv').style.display = 'none';
				} else {

					content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">Please enter all of the bellow fields.</td></tr></table></div><br /><br />';
					$('postButtonDiv').style.display = '';	
				}

				$('returnMessage').set('html',content);	
				
				$('ajaxLoader').style.display = 'none';
				charityCall.effectel.returnMessage.slideIn();
				charityCall.errorScroll();

			}
		}).get({json: jsonRequest});
	},

	contactPost: function() {
		$('postButtonContact').disabled = true;
		$('postButtonContact').setAttribute("class", "buttonWait");

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';
		$('returnMessage').empty();
		charityCall.effectel.returnMessage.hide();

		var jsonRequest = JSON.encode({
			subject: $('contact_subject').value,
			message: $('contact_message').value,
			email: $('contact_email').value
		});

		var url = '/contact/send';
		var request = new Request.JSON({
			url: url,
			onComplete: function(response) {

				var content = '';

				if (response && response.status) {
					content = '<div class="messageSuccess"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-ok.png">&nbsp;&nbsp;</td><td class="message">Your request has been completed.</td></tr></table></div><br /><br />';
					charityCall.effectel.receiptForm.slideOut();
					$('postButtonDiv').style.display = 'none';
				} else {

					content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">Please enter all of the bellow fields.</td></tr></table></div><br /><br />';
					$('postButtonDiv').style.display = '';	
				}

				$('returnMessage').set('html',content);	
				
				$('ajaxLoader').style.display = 'none';
				charityCall.effectel.returnMessage.slideIn();
				charityCall.errorScroll();

			}
		}).get({json: jsonRequest});
	},

	partnershipPost: function() {
		$('postButtonPartnership').disabled = true;
		$('postButtonPartnership').setAttribute("class", "buttonWait");

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';
		$('returnMessage').empty();
		charityCall.effectel.returnMessage.hide();

		var jsonRequest = JSON.encode({
			charity_name: $('partnership_charity_name').value,
			charity_url: $('partnership_url').value,
			charity_address: $('partnership_address').value,
			charity_city: $('partnership_city').value,
			charity_state: $('partnership_state').value,
			charity_zip: $('partnership_zip').value,
			charity_country: $('partnership_country').value,
			charity_phone: $('partnership_phone').value,
			charity_fax: $('partnership_fax').value,
			contact_name_first: $('partnership_name_first').value,
			contact_name_last: $('partnership_name_last').value,
			contact_title: $('partnership_title').value,
			contact_email: $('partnership_email').value,
			contact_phone: $('partnership_phone_contact').value,
			charity_revenue: $('partnership_revenue').value,
			charity_org: $('partnership_org_yes').checked ? 1 : 0
		});

		var url = '/partnership/send';
		var request = new Request.JSON({
			url: url,
			onComplete: function(response) {

				var content = '';

				if (response && response.status) {
					content = '<div class="messageSuccess"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-ok.png">&nbsp;&nbsp;</td><td class="message">Your request has been completed.</td></tr></table></div><br /><br />';
					charityCall.effectel.receiptForm.slideOut();
					$('postButtonDiv').style.display = 'none';
				} else {
					content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">Please enter all of the bellow fields.</td></tr></table></div><br /><br />';
					$('postButtonDiv').style.display = '';	
				}

				$('returnMessage').set('html',content);	
				
				$('ajaxLoader').style.display = 'none';
				charityCall.effectel.returnMessage.slideIn();
				charityCall.errorScroll();

			}
		}).get({json: jsonRequest});
	},

	helpPost: function() {
		$('postButtonHelp').disabled = true;
		$('postButtonHelp').setAttribute("class", "buttonWait");

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';
		$('returnMessage').empty();
		charityCall.effectel.returnMessage.hide();

		var jsonRequest = JSON.encode({
			subject: $('help_subject').value,
			message: $('help_message').value,
			email: $('help_email').value
		});

		var url = '/help/send';
		var request = new Request.JSON({
			url: url,
			onComplete: function(response) {

				var content = '';

				if (response && response.status) {
					content = '<div class="messageSuccess"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-ok.png">&nbsp;&nbsp;</td><td class="message">Your request has been completed.</td></tr></table></div><br /><br />';
					charityCall.effectel.receiptForm.slideOut();
					$('postButtonDiv').style.display = 'none';
				} else {
					content = '<div class="messageError"><table cellpadding="1" cellspacing="0"><tr><td><img src="/images/icon-error.png">&nbsp;&nbsp;</td><td class="message">Please enter all of the bellow fields.</td></tr></table></div><br /><br />';
					$('postButtonDiv').style.display = '';	
				}

				$('returnMessage').set('html',content);	
				
				$('ajaxLoader').style.display = 'none';
				charityCall.effectel.returnMessage.slideIn();
				charityCall.errorScroll();

			}
		}).get({json: jsonRequest});
	},
	hepSearchPost: function() {
		$('postButtonHep').disabled = true;
		$('postButtonHep').setAttribute("class", "buttonWait");

		$('ajaxLoader').style.display = '';
		$('postButtonDiv').style.display = 'none';
		$('hepSearch').submit();
	}
	

}

var DatePicker = new Class({

	/* set and create the date picker text box */
	initialize: function(dp){

		// Options defaults
		this.dayChars = 1; // number of characters in day names abbreviation
		this.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
		this.daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
		this.format = 'mm/dd/yyyy';
		this.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
		this.startDay = 7; // 1 = week starts on Monday, 7 = week starts on Sunday
		this.yearOrder = 'asc';
		this.yearRange = 10;
		this.yearStart = (new Date().getFullYear());


		// Finds the entered date, or uses the current date
		if(dp.value != '') {
			dp.then = new Date(dp.value);
			dp.today = new Date();
		} else {
			dp.then = dp.today = new Date();
		}
		// Set beginning time and today, remember the original
		dp.oldYear = dp.year = dp.then.getFullYear();
		dp.oldMonth = dp.month = dp.then.getMonth();
		dp.oldDay = dp.then.getDate();
		dp.nowYear = dp.today.getFullYear();
		dp.nowMonth = dp.today.getMonth();
		dp.nowDay = dp.today.getDate();

		// Pull the rest of the options from the alt attr
		if(dp.alt) {
			options = JSON.encode(dp.alt);
		} else {
			options = [];
		}
		dp.options = {
			monthNames: (options.monthNames && options.monthNames.length == 12 ? options.monthNames : this.monthNames) || this.monthNames, 
			daysInMonth: (options.daysInMonth && options.daysInMonth.length == 12 ? options.daysInMonth : this.daysInMonth) || this.daysInMonth, 
			dayNames: (options.dayNames && options.dayNames.length == 7 ? options.dayNames : this.dayNames) || this.dayNames,
			startDay : options.startDay || this.startDay,
			dayChars : options.dayChars || this.dayChars, 
			format: options.format || this.format,
			yearStart: options.yearStart || this.yearStart,
			yearRange: options.yearRange || this.yearRange,
			yearOrder: options.yearOrder || this.yearOrder
		};
		dp.setProperties({'readonly':true});
		dp.container = false;
		dp.calendar = false;
		dp.interval = null;
		dp.active = false;
		dp.onclick = dp.onfocus = this.create.pass(dp, this);
	},

	/* create the calendar */
	create: function(dp){
		if (dp.calendar) return false;

		// Hide select boxes while calendar is up
		if(window.ie6){
			$$('select').addClass('dp_hide');
		}
		
		/* create the outer container */
		dp.container = new Element('div', {'class':'dp_container'}).injectBefore(dp);
		
		/* create timers */
		dp.container.onmouseover = dp.onmouseover = function(){
			$clear(dp.interval);
		};
		dp.container.onmouseout = dp.onmouseout = function(){
			dp.interval = setInterval(function(){
				if (!dp.active) this.remove(dp);
			}.bind(this), 500);
		}.bind(this);
		
		/* create the calendar */
		dp.calendar = new Element('div', {'class':'dp_cal'}).injectInside(dp.container);
		
		/* create the date object */
		var date = new Date();
		
		/* create the date object */
		if (dp.month && dp.year) {
			date.setFullYear(dp.year, dp.month, 1);
		} else {
			dp.month = date.getMonth();
			dp.year = date.getFullYear();
			date.setDate(1);
		}
		dp.year % 4 == 0 ? dp.options.daysInMonth[1] = 29 : dp.options.daysInMonth[1] = 28;
		
		/* set the day to first of the month */
		var firstDay = (1-(7+date.getDay()-dp.options.startDay)%7);
		
		
		
		/* create the month select box */
		monthSel = new Element('select', {'id':dp.id + '_monthSelect'});
		for (var m = 0; m < dp.options.monthNames.length; m++){
			monthSel.options[m] = new Option(dp.options.monthNames[m], m);
			if (dp.month == m) monthSel.options[m].selected = true;
		}
		
		/* create the year select box */
		yearSel = new Element('select', {'id':dp.id + '_yearSelect'});
		i = 0;
		dp.options.yearStart ? dp.options.yearStart : dp.options.yearStart = date.getFullYear();
		if (dp.options.yearOrder == 'desc'){
			for (var y = dp.options.yearStart; y > (dp.options.yearStart - dp.options.yearRange - 1); y--){
				yearSel.options[i] = new Option(y, y);
				if (dp.year == y) yearSel.options[i].selected = true;
				i++;
			}
		} else {
			for (var y = dp.options.yearStart; y < (dp.options.yearStart + dp.options.yearRange + 1); y++){
				yearSel.options[i] = new Option(y, y);
				if (dp.year == y) yearSel.options[i].selected = true;
				i++;
			}
		}
		
		/* start creating calendar */
		calTable = new Element('table');
		calTableThead = new Element('thead');
		calSelRow = new Element('tr');
		calSelCell = new Element('th', {'colspan':'7'});
		monthSel.injectInside(calSelCell);
		yearSel.injectInside(calSelCell);
		calSelCell.injectInside(calSelRow);
		calSelRow.injectInside(calTableThead);
		calTableTbody = new Element('tbody');
		
		/* create day names */
		calDayNameRow = new Element('tr');
		for (var i = 0; i < dp.options.dayNames.length; i++) {
			calDayNameCell = new Element('th');
			calDayNameCell.appendText(dp.options.dayNames[(dp.options.startDay+i)%7].substr(0, dp.options.dayChars)); 
			calDayNameCell.injectInside(calDayNameRow);
		}
		calDayNameRow.injectInside(calTableTbody);
		
		/* create the day cells */
		while (firstDay <= dp.options.daysInMonth[dp.month]){
			calDayRow = new Element('tr');
			for (i = 0; i < 7; i++){
				if ((firstDay <= dp.options.daysInMonth[dp.month]) && (firstDay > 0)){
					calDayCell = new Element('td', {'class':dp.id + '_calDay', 'axis':dp.year + '|' + (parseInt(dp.month) + 1) + '|' + firstDay}).appendText(firstDay).injectInside(calDayRow);
				} else {
					calDayCell = new Element('td', {'class':'dp_empty'}).appendText(' ').injectInside(calDayRow);
				}
				// Show the previous day
				if ( (firstDay == dp.oldDay) && (dp.month == dp.oldMonth ) && (dp.year == dp.oldYear) ) {
					calDayCell.addClass('dp_selected');
				}
				// Show today
				if ( (firstDay == dp.nowDay) && (dp.month == dp.nowMonth ) && (dp.year == dp.nowYear) ) {
					calDayCell.addClass('dp_today');
				}
				firstDay++;
			}
			calDayRow.injectInside(calTableTbody);
		}
		
		/* table into the calendar div */
		calTableThead.injectInside(calTable);
		calTableTbody.injectInside(calTable);
		calTable.injectInside(dp.calendar);
		
		/* set the onmouseover events for all calendar days */
		$$('td.' + dp.id + '_calDay').each(function(el){
			el.onmouseover = function(){
				el.addClass('dp_roll');
			}.bind(this);
		}.bind(this));
		
		/* set the onmouseout events for all calendar days */
		$$('td.' + dp.id + '_calDay').each(function(el){
			el.onmouseout = function(){
				el.removeClass('dp_roll');
			}.bind(this);
		}.bind(this));
		
		/* set the onclick events for all calendar days */
		$$('td.' + dp.id + '_calDay').each(function(el){
			el.onclick = function(){
				ds = el.axis.split('|');
				dp.value = this.formatValue(dp, ds[0], ds[1], ds[2]);
				this.remove(dp);
			}.bind(this);
		}.bind(this));
		
		/* set the onchange event for the month & year select boxes */
		monthSel.onfocus = function(){ dp.active = true; };
		monthSel.onchange = function(){
			dp.month = monthSel.value;
			dp.year = yearSel.value;
			this.remove(dp);
			this.create(dp);
		}.bind(this);
		
		yearSel.onfocus = function(){ dp.active = true; };
		yearSel.onchange = function(){
			dp.month = monthSel.value;
			dp.year = yearSel.value;
			this.remove(dp);
			this.create(dp);
		}.bind(this);
	},
	
	/* Format the returning date value according to the selected formation */
	formatValue: function(dp, year, month, day){
		/* setup the date string variable */
		var dateStr = '';
		
		/* check the length of day */
		if (day < 10) day = '0' + day;
		if (month < 10) month = '0' + month;
		
		/* check the format & replace parts // thanks O'Rey */
		dateStr = dp.options.format.replace( /dd/i, day ).replace( /mm/i, month ).replace( /yyyy/i, year );
		dp.month = dp.oldMonth = '' + (month - 1) + '';
		dp.year = dp.oldYear = year;
		dp.oldDay = day;
		
		/* return the date string value */
		return dateStr;
	},
	
	/* Remove the calendar from the page */
	remove: function(dp){
		$clear(dp.interval);
		dp.active = false;
		if (window.opera) dp.container.empty();
		else if (dp.container) dp.container.set('html','');
		dp.calendar = false;
		dp.container = false;
		$$('select.dp_hide').removeClass('dp_hide');
	}
});

window.addEvent('domready', function(){
	charityCall.start();
});