window.addEvent('domready', function(){	
	if ($chk($('dateStart'))==true){																		 
		new vlaDatePicker('dateStart', { filePath: 'http://www.getactivestayactive.co.nz/includes/vlaCalendar/', format: 'y/m/d', separator: '-', prefillDate: false, startMonday: true });			
		new vlaDatePicker('dateEnd', { filePath: 'http://www.getactivestayactive.co.nz/includes/vlaCalendar/', format: 'y/m/d', separator: '-', prefillDate: false, startMonday: true });				
	}
	if ($chk($('dob'))==true){
		new vlaDatePicker('dob', { filePath: 'http://www.getactivestayactive.co.nz/includes/vlaCalendar/', format: 'y/m/d', separator: '-', prefillDate: false, defaultView: 'year', startMonday: true });																	 
	}
	
	if ($chk($('outlook'))==true){
		var myText = $('openWeather');
		var myWeather = new Fx.Slide('outlook').hide();	
		myText.addEvent('click',function(e){
			e.stop();
			if(myText.get('html')=='View three day outlook')
				myText.set('html','Close three day outlook');
			else
				myText.set('html','View three day outlook');
			myWeather.toggle();			 
		});
	}
																		 
	var loginForm=$('login_username');
	if ($chk(loginForm)==true){
		loginForm.focus();
	}	
	
	var notify = $('notifyArea');
	if ($chk(notify)==true){
		var myEffects = new Fx.Morph(notify, {duration: 4000});
		
		myEffects.start({
			'background-color': '#E1EFFD',
			'color': '#174D7D'
		});	
	}
	
	var accordion = $('accordion');
	if ($chk(accordion)==true){	
																 
		accordion = new Accordion('h5.clicker', 'div.stretcher',{
			alwaysHide: true,
			opacity: false,
			start: 'all-closed',
			onActive: function(toggler, element){
				toggler.setProperty('id','active');
				var styles = new Fx.Morph(toggler);
				styles.start({
					'background-color': '#B1D5F9',
					'color': '#FFF',
					'padding-left': 20
				});
			},
			
			onBackground: function(toggler, element){
				element.setStyles('border-top: medium none; border-bottom: medium none; overflow: hidden; padding-top: 0px; padding-bottom: 0px; height: 0px;');
				toggler.removeProperty('id');
				var styles = new Fx.Morph(toggler);
				styles.start({
					'padding-left': 5,
					'color': '#000',
					'background-color': '#E1EFFD'
				});
			}
		});
		
		
		var list = $$('h5.clicker');
		list.each(function(element) {
		 
			var fx = new Fx.Morph(element, {duration:200, wait:false});
		 
			element.addEvent('mouseenter', function(){
				if (element.getProperty('id') != 'active'){																							
					fx.start({
						'padding-left': 15,
						'background-color': '#C9E2FB'
					});
				}
			});
		 
			element.addEvent('mouseleave', function(){
				if (element.getProperty('id') != 'active'){	
					fx.start({
						'background-color': '#E1EFFD',
						'padding-left': 5
					});
				}
			});
		 
		});
	
	}
	
	
	
	
	
});

function deleteImages(ID){
	new Request.HTML({
		url: "ajax/deleteImages.php?ID="+ID,
		onRequest: function(){
			$('imgLoader').setStyle('display', 'block');
		},		
		update: $('imageRow'),
		onComplete: function(){	
			$('imgLoader').setStyle('display', 'none');
		}
	}).get();
}

function toggleOngoing(){
	var rowDt=$('eventDates');
	var dtSt = rowDt.getStyle('display')=='block'?'none':'block';
	rowDt.tween('display', dtSt);
}

function checkDelete(TYPE){
	if(confirm('Are you sure you want to delete this '+TYPE+' permanently?\nThis cannot be undone.')==false)
		return false
	else
		return true	
}

function removeGenericImages(ID){ 
	new Request.HTML({
		url: "ajax/deleteGenericImage.php?ID="+ID,
		onRequest: function(){
			$('imgLoader').setStyle('display', 'block');
		},		
		update: $('imageRow'),
		onComplete: function(){	
			$('imgLoader').setStyle('display', 'none');
		}
	}).get();
}

function genericName(id,name,ext){
	//CLEAR ALL SELECTED
	$$('.genimage').each(function(el){
		el.set('html','');
	});

	var imgID = $('genImg_'+id);
	
	imgID.set('html','<img src="/images/selected.gif" width="100" height="100">')
	$('filenameGeneric').value = name;
}