var mySlide;
var drop;
var drop2;
var drop3;
var drop4;
var dropFx;
var dropFx2;
var dropFx3;
var dropFx4;

//var cal1;

function init_slider(divname, linkname) {
	mySlide = new Fx.Slide(divname, {onComplete : resetCursor }).hide();
	$(linkname).addEvent('click', function(e){
		e = new Event(e);
		mySlide.toggle();
		e.stop();
	});
}

function resetCursor() {
	if ($('shownotes').innerHTML == 'show') {
		$('notes').focus();
		$('shownotes').innerHTML = 'hide';
	} else {
		$('notes').blur();
		$('shownotes').innerHTML = 'show';
	}
}

function init_items() {
//	var scrolly = new Scroller(window, {area: 100, velocity: .5});
//	$(window).addEvent('mousedown', scrolly.start.bind(scrolly));
//	$(window).addEvent('mouseup', scrolly.stop.bind(scrolly));
	if (!$('absentcart') && !$('tardycart') && !$('itemscart')) {
		return;
	}
	drop = $('absentcart');
	drop2 = $('tardycart');
	drop3 = $('itemscart');
	drop4 = $('studentscart');
	drop5 = $('excusedabsentcart');
	dropFx = drop.effect('background-color', {wait: false}); // wait is needed so that to toggle the effect,
	if (drop2) {
		dropFx2 = drop2.effect('background-color', {wait: false}); // wait is needed so that to toggle the effect,
	}
	dropFx3 = drop3.effect('background-color', {wait: false}); // wait is needed so that to toggle the effect,
	if (drop4) {
		dropFx4 = drop4.effect('background-color', {wait: false}); // wait is needed so that to toggle the effect,
	}
	if (drop5) {
		dropFx5 = drop5.effect('background-color', {wait: false}); // wait is needed so that to toggle the effect,
	}
	$$('.timeselect').each(function(select) {
		select.addEvent('change', function(e) {
				$('time_'+select.getAttribute('studentid')).value =  $('student_hours'+select.getAttribute('studentid')).value;
				if ($('student_hours'+select.getAttribute('studentid')).value == 0) {
					$('attend_'+select.getAttribute('studentid')).value = 'A';
				} else {
					$('attend_'+select.getAttribute('studentid')).value = 'P';
				}
			});
	});
	$$('.item').each(function(item){
		if (item.getParent().getProperty('id') == 'itemscart') {
			$('presentcount').setText(parseInt($('presentcount').getText())+1);
			//$('itemscart').setStyle('height', 36 + $('itemscart').getStyle('height').toInt());
		} else if (item.getParent().getProperty('id') == 'tardycart') {
			$('tardycount').setText(parseInt($('tardycount').getText())+1);
//			$('tardycount').setText(parseInt($('tardycount').getText())+1);
		} else if (item.getParent().getProperty('id') == 'absentcart') {
			$('absentcount').setText(parseInt($('absentcount').getText())+1);
		} else if (item.getParent().getProperty('id') == 'excusedabsentcart') {
			$('excusedabsentcount').setText(parseInt($('excusedabsentcount').getText())+1);
		} else if (item.getParent().getProperty('id') == 'studentscart') {
			$('studentcount').setText(parseInt($('studentcount').getText())+1);
		}
		item.addEvent('mousedown', function(e) {
			e = new Event(e).stop();

			var clone = this.clone()
				.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
				.setStyles({'opacity': 0.7, 'position': 'absolute'})
				.addEvent('emptydrop', function() {
					this.remove();
					drop.removeEvents();
				}).inject(document.body);
	 
			var clone2;
			if (drop2){
				clone2 = this.clone()
					.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
					.setStyles({'opacity': 0.7, 'position': 'absolute'})
					.addEvent('emptydrop', function() {
						this.remove();
						drop2.removeEvents();
					}).inject(document.body);
			}

			var clone3 = this.clone()
				.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
				.setStyles({'opacity': 0.7, 'position': 'absolute'})
				.addEvent('emptydrop', function() {
					this.remove();
					drop3.removeEvents();
				}).inject(document.body);

			var clone4;
			if (drop4) {
				clone4 = this.clone()
					.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
					.setStyles({'opacity': 0.7, 'position': 'absolute'})
					.addEvent('emptydrop', function() {
						this.remove();
						drop4.removeEvents();
					}).inject(document.body);
			}
	
			var clone5;
			if (drop5) {
				clone5 = this.clone()
					.setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
					.setStyles({'opacity': 0.7, 'position': 'absolute'})
					.addEvent('emptydrop', function() {
						this.remove();
						drop5.removeEvents();
					}).inject(document.body);
			}
	 
			drop.addEvents({
				'drop': function() {
					$('attend_'+item.getProperty('name')).value = 'A';
					if ($('time_'+item.getProperty('name'))) {
						$('time_'+item.getProperty('name')).value = '0';
					}
					if (item.getParent().getProperty('id') != 'absentcart') {
						$('absentcount').setText(parseInt($('absentcount').getText())+1);
						if (item.getParent().getProperty('id') == 'itemscart') {
							$('itemscart').setStyle('height', $('itemscart').getStyle('height').toInt() - item.getStyle('height').toInt());
							$('presentcount').setText(parseInt($('presentcount').getText())-1);
						} else if (item.getParent().getProperty('id') == 'tardycart') {
							$('tardycount').setText(parseInt($('tardycount').getText())-1);
						} else if (item.getParent().getProperty('id') == 'excusedabsentcart') {
							$('excusedabsentcount').setText(parseInt($('excusedabsentcount').getText())-1);
						} else if (item.getParent().getProperty('id') == 'studentscart') {
							$('studentcount').setText(parseInt($('studentcount').getText())-1);
						}
					}
					drop.removeEvents();
					clone.remove();
					item.inject(drop);
					dropFx.start('7389AE').chain(dropFx.start.pass('ffffff', dropFx));
				},
				'over': function() {
					dropFx.start('98B5C1');
				},
				'leave': function() {
					dropFx.start('ffffff');
				}
			});
			if (drop2) {
				drop2.addEvents({
					'drop': function() {
						$('attend_'+item.getProperty('name')).value = 'T';
						if (item.getParent().getProperty('id') != 'tardycart') {
							$('tardycount').setText(parseInt($('tardycount').getText())+1);
							if (item.getParent().getProperty('id') == 'itemscart') {
								$('itemscart').setStyle('height', $('itemscart').getStyle('height').toInt() - 35);
								$('presentcount').setText(parseInt($('presentcount').getText())-1);
							} else if (item.getParent().getProperty('id') == 'absentcart') {
								$('absentcount').setText(parseInt($('absentcount').getText())-1);
							} else if (item.getParent().getProperty('id') == 'excusedabsentcart') {
								$('excusedabsentcount').setText(parseInt($('excusedabsentcount').getText())-1);
							} else if (item.getParent().getProperty('id') == 'studentscart') {
								$('studentcount').setText(parseInt($('studentcount').getText())-1);
							}
						}
						drop2.removeEvents();
						clone2.remove();
						item.inject(drop2);
						dropFx2.start('7389AE').chain(dropFx2.start.pass('ffffff', dropFx2));
					},
					'over': function() {
						dropFx2.start('98B5C1');
					},
					'leave': function() {
						dropFx2.start('ffffff');
					}
				});
			}

			drop3.addEvents({
				'drop': function() {
					$('attend_'+item.getProperty('name')).value = 'P';
					if (item.getParent().getProperty('id') != 'itemscart') {
						$('presentcount').setText(parseInt($('presentcount').getText())+1);
						$('itemscart').setStyle('height', $('itemscart').getStyle('height').toInt() + item.getStyle('height').toInt() + 10);
						//$('presentcount').setText(parseInt($('presentcount').getText())-1);
						if (item.getParent().getProperty('id') == 'absentcart') {
							$('absentcount').setText(parseInt($('absentcount').getText())-1);
						}
						if (item.getParent().getProperty('id') == 'excusedabsentcart') {
							$('excusedabsentcount').setText(parseInt($('excusedabsentcount').getText())-1);
						}
						if (item.getParent().getProperty('id') == 'tardycart') {
							$('tardycount').setText(parseInt($('tardycount').getText())-1);
						} else if (item.getParent().getProperty('id') == 'studentscart') {
							$('studentcount').setText(parseInt($('studentcount').getText())-1);
						}
					}
					drop3.removeEvents();
					clone3.remove();
					item.inject(drop3);
					dropFx3.start('7389AE').chain(dropFx3.start.pass('ffffff', dropFx3));
				},
				'over': function() {
					dropFx3.start('98B5C1');
				},
				'leave': function() {
					dropFx3.start('ffffff');
				}
			});

			if (drop4) {
				drop4.addEvents({
					'drop': function() {
						$('attend_'+item.getProperty('name')).value = '';
						if (item.getParent().getProperty('id') != 'studentscart') {
							$('studentcount').setText(parseInt($('studentcount').getText())+1);
							if (item.getParent().getProperty('id') == 'itemscart') {
								$('presentcount').setText(parseInt($('presentcount').getText())-1);
								$('itemscart').setStyle('height', $('itemscart').getStyle('height').toInt() - item.getStyle('height').toInt());
							} else if (item.getParent().getProperty('id') == 'absentcart') {
								$('absentcount').setText(parseInt($('absentcount').getText())-1);
							} else if (item.getParent().getProperty('id') == 'excusedabsentcart') {
								$('excusedabsentcount').setText(parseInt($('excusedabsentcount').getText())-1);
							} else if (item.getParent().getProperty('id') == 'tardycart') {
								$('tardycount').setText(parseInt($('tardycount').getText())-1);
							} else if (item.getParent().getProperty('id') == 'studentscart') {
								$('studentcount').setText(parseInt($('studentcount').getText())-1);
							}
							drop4.removeEvents();
							clone4.remove();
							item.inject(drop4);
							dropFx4.start('7389AE').chain(dropFx4.start.pass('ffffff', dropFx4));
						}
					},
					'over': function() {
						dropFx4.start('98B5C1');
					},
					'leave': function() {
						dropFx4.start('ffffff');
					}
				});
			}

			if (drop5) {
				drop5.addEvents({
					'drop': function() {
						$('attend_'+item.getProperty('name')).value = 'E';
//						if (item.getParent().getProperty('id') != 'itemscart') {
//							$('itemscart').setStyle('height', $('itemscart').getStyle('height').toInt() - 35);
//						} else 
						$('excusedabsentcount').setText(parseInt($('excusedabsentcount').getText())+1);
						if (item.getParent().getProperty('id') == 'itemscart') {
							$('presentcount').setText(parseInt($('presentcount').getText())-1);
							$('itemscart').setStyle('height', $('itemscart').getStyle('height').toInt() - item.getStyle('height').toInt());
						} else if (item.getParent().getProperty('id') == 'absentcart') {
							$('absentcount').setText(parseInt($('absentcount').getText())-1);
						} else if (item.getParent().getProperty('id') == 'excusedabsentcart') {
							$('excusedabsentcount').setText(parseInt($('excusedabsentcount').getText())-1);
						} else if (item.getParent().getProperty('id') == 'tardycart') {
							$('tardycount').setText(parseInt($('tardycount').getText())-1);
						} else if (item.getParent().getProperty('id') == 'studentscart') {
							$('studentcount').setText(parseInt($('studentcount').getText())-1);
						}
						drop5.removeEvents();
						clone5.remove();
						item.inject(drop5);
						dropFx5.start('7389AE').chain(dropFx5.start.pass('ffffff', dropFx5));
					},
					'over': function() {
						dropFx5.start('98B5C1');
					},
					'leave': function() {
						dropFx5.start('ffffff');
					}
				});
			}
	 
			var drag = clone.makeDraggable({
				droppables: [drop]
			}); // this returns the dragged element
			drag.start(e); // start the event manual
			if (drop2) {
				var drag2 = clone2.makeDraggable({
					droppables: [drop2]
				}); // this returns the dragged element
				drag2.start(e); // start the event manual
			}
			var drag3 = clone3.makeDraggable({
				droppables: [drop3]
			}); // this returns the dragged element
			drag3.start(e); // start the event manual
	 		if (drop4) {
				var drag4 = clone4.makeDraggable({
					droppables: [drop4]
				}); // this returns the dragged element
				drag4.start(e); // start the event manual
			}
			if (drop5) {
				var drag5 = clone5.makeDraggable({
					droppables: [drop5]
				}); // this returns the dragged element
				drag5.start(e); // start the event manual
			}
		});
	 
	});
}

function init_calendar() {
	YAHOO.namespace("example.calendar"); 
	YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", { title:"Choose a date", close:true }); 
	function handleSelect(type,args,obj) {
		var dates = args[0]; 
		var date = dates[0];
		var year = date[0], month = date[1], day = date[2];
		
		var txtDate1 = document.getElementById("newdate");
		txtDate1.value = month + "/" + day + "/" + year;
		obj.hide();
	}
	YAHOO.example.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.cal1, true);
	YAHOO.example.calendar.cal1.render(); 
	YAHOO.util.Event.addListener("newdate", "click", YAHOO.example.calendar.cal1.show, YAHOO.example.calendar.cal1, true);
}

function init_movable_cart(cartName, propertyToAlign) {
	var cart = $(cartName+'cart');
	var initialY;
	var initialX;
	var previousPosition = 0;
	if (cart) {
		initialY = cart.getPosition().y;
		initialX = cart.getPosition().x;
		if ($(cartName+'lock'))	{
			cart.setStyle(propertyToAlign, initialX);
			cart.setStyle('top', initialY);
			$(cartName+'lock').addEvent('click', function(e) {
				var regex = new RegExp('unlock');
				if ($(cartName+'lock').src.match(regex)) {
					cart.topFx.start(initialY);
					previousPosition = 0;
					$(cartName+'lock').src = 'http://imagehost.dingo7.com/aspneticons/lock_16x16.gif';
					cart.removeClass(cartName+'cartfixed');
					cart.addClass(cartName+'cart');
					window.addEvent('scroll', function(){} );
				} else {
					$(cartName+'lock').src = 'http://imagehost.dingo7.com/aspneticons/unlock_16x16.gif';
					cart.setStyle(propertyToAlign, '0');
					cart.setStyle('top', '0');
					cart.removeClass(cartName+'cart');
					cart.addClass(cartName+'cartfixed');
					var fixedEle = cart;
					// Create a Fx.Style that animates 'top', store it as a member property of fixedEle for use later
					//fixedEle.setStyle('top', initialY);
					fixedEle.topFx = fixedEle.effect('top', {wait: false,onComplete: function() { } });
					window.addEvent('scroll', function(){
						// Access the previously-stored topFx, start it animating using the window's current scrollTop + 20px
						var cy = cart.getPosition().y;
						var scrollTopAmount = window.getScrollTop();
							if (scrollTopAmount == 0) {
								cart.setStyle(propertyToAlign, '0');
								cart.setStyle('top', '0');
								cart.topFx.start('0');
								previousPosition = 0;
							} else {
								if (scrollTopAmount > initialY && scrollTopAmount > previousPosition) {
									if (previousPosition > scrollTopAmount) {
										cart.topFx.start(previousPosition);
									} else {
										cart.topFx.start(scrollTopAmount);
									}
									previousPosition = cart.getPosition().y;
								} else {
									if (previousPosition > 0) {
										//if ((scrollTopAmount + 30) < initialY) {
										//	cart.topFx.start(initialY);
										//	previousPosition = 0;
										//} else {
											cart.topFx.start(scrollTopAmount);
										//}
										previousPosition = cart.getPosition().y;
									}
								}
							}
					});
				}
			}
			);
		}
	}
}

function removeStudentFromClass(sid,cid) {
	var really = confirm('Are you sure you want to remove this student?');
	if (really)	{
		var myAjax = new Ajax('/ajax.pl', 
							 {method: 'post', 
							  data : 'action=ajaxremovestudentfromclass&class_id='+cid+'&student_id='+sid, 
							  onComplete: function(resp,xml) { 
								if (resp != 'failure') {
									$('studentclasstable').setHTML(resp);
									updatePageMessage(uStudentLabel + ' removed!', true);
								}
							  }});
		myAjax.request();
	}
}

function removeStudentFromClass2(sid,cid) {
	var myAjax = new Ajax('/ajax.pl', 
						 {method: 'post', 
						  data : 'action=ajaxremovestudentfromclass2&class_id='+cid+'&student_id='+sid, 
						  onComplete: function(resp,xml) { 
							if (resp != 'failure') {
								$('studentshowarea').setHTML(resp);
								updatePageMessage(uStudentLabel + ' removed!', true);
							}
						  }});
	myAjax.request();
}

function removeClassFromStudent(sid,cid) {
	var myAjax = new Ajax('/ajax.pl', 
						 {method: 'post', 
						  data : 'action=ajaxremoveclassfromstudent&class_id='+cid+'&student_id='+sid, 
						  onComplete: function(resp,xml) { 
							if (resp != 'failure') {
								$('classshowarea').setHTML(resp);
								updatePageMessage(uClassLabel + ' removed!', true);
							}
						  }});
	myAjax.request();
}

function addStudentToClass() {
	if (!$('new_student_id').selectedIndex) {
		alert('Please select a '+uStudentLabel+'.');
		return false;
	}
	var myAjax = new Ajax('/ajax.pl', 
						 {method: 'post', 
						  data : $('addstudenttoclassform'), 
						  onComplete: function(resp) { 
							if (resp != 'failure') {
								$('studentclasstable').setHTML(resp);
								if ($('option_student_'+$('new_student_id')[$('new_student_id').selectedIndex].value)) {
									$('option_student_'+$('new_student_id')[$('new_student_id').selectedIndex].value).remove();
								}
								updatePageMessage(uStudentLabel + ' added!', true);
								$('new_student_id').selectedIndex = 0;
							}
						  }});
	myAjax.request();
	return false;
}

function addStudentToClass2() {
	if (!$('new_student_id').selectedIndex) {
		alert('Please select a '+uStudentLabel+'.');
		return false;
	}
	var myAjax = new Ajax('/ajax.pl', 
						 {method: 'post', 
						  data : $('addstudenttoclassform'), 
						  onComplete: function(resp) { 
							if (resp != 'failure') {
								$('studentshowarea').setHTML(resp);
								updatePageMessage(uStudentLabel + ' added!', true);
							}
						  }});
	myAjax.request();
	return false;
}

function addClassToStudent() {
	if ($('new_class_id').value == '') {
		alert('Please select a class.');
		return false;
	}
	var myAjax = new Ajax('/ajax.pl', 
						 {method: 'post', 
						  data : $('addclasstostudentform'), 
						  onComplete: function(resp) { 
							if (resp != 'failure') {
								$('classshowarea').setHTML(resp);
								updatePageMessage(uClassLabel + ' added!', true);
								$('new_class_id').selectedIndex = 0;
								if ($('option_class_'+$('new_class_id').value)) {
									$('option_class_'+$('new_class_id').value).remove();
								}
							}
						  }});
	myAjax.request();
	return false;
}


function editClass(id) {
	$('classtr'+id).setStyle('display', 'none');
	$('edittr'+id).setStyle('display', '');
	$('new_description'+id).setStyle('padding', '0px');
}

function editClassCustomField(id) {
	$('customclassfieldtr'+id).setStyle('display', 'none');
	$('editcustomclassfieldtr'+id).setStyle('display', '');
	$('editcustomclassfieldname'+id).setStyle('padding', '0px');
}

function editStudentCustomField(id) {
	$('customstudentfieldtr'+id).setStyle('display', 'none');
	$('editcustomstudentfieldtr'+id).setStyle('display', '');
	$('editcustomstudentfieldname'+id).setStyle('padding', '0px');
}

function revertClassCustomField(id) {
	$('customclassfieldtr'+id).setStyle('display', '');
	$('editcustomclassfieldtr'+id).setStyle('display', 'none');
}

function revertStudentCustomField(id) {
	$('customstudentfieldtr'+id).setStyle('display', '');
	$('editcustomstudentfieldtr'+id).setStyle('display', 'none');
}

function deleteAttendance() {
	var really = confirm('Are you sure you want to delete the attendance for this day?');
	if (really)	{
		$('action').value = 'deleteattendance';
//		var myAjax = new Ajax('/ajax.pl', 
//							 {method: 'post', 
//							  data : 'action=ajaxdeleteattendance&class_id='+$('class').value, 
//							  onComplete: function(resp) { 
//								if (resp != 'failure') {
//									$('studenttable').setHTML(resp);
//								}
//							  }});
//		myAjax.request();
	} else {
		return false;
	}
}

function changeClass() {
	if ($('class').value || ($('newdate') && $('newdate').value)) {
	//	Cookie.set('selected_class', $('class').value);
		var tick = $('ticker').empty().addClass('ajax-loading');
		var pageData = 'action=ajaxgetstudents&class_id='+$('class').value;
		var savedDate;
		if ($('newdate') && $('newdate').value) {
			pageData = pageData + "&newdate="+$('newdate').value;
			savedDate = $('newdate').value;
		} else if ($('formdate') && $('formdate').value) {
			pageData = pageData + "&formdate="+$('formdate').value;
			savedDate = $('formdate').value;
		}
		var myAjax = new Ajax('/ajax.pl', 
							 {method: 'post', 
							  data : pageData, 
							  onComplete: function(resp) { 
								if (resp != 'failure') {
									var ind = 0;
									if (resp.indexOf("!!!") > 0) {
										var dayType = resp.substring(0,resp.indexOf("!!!"));
										if (dayType == 'N') {
											ind = 0;
										} else if (dayType == 'E') {
											ind = 1;
										} else if (dayType == 'L') {
											ind = 2;
										} else if (dayType == 'S') {
											ind = 3;
										}
										resp = resp.substring(resp.indexOf("!!!")+3);
									}
//									$('day_type').selectedIndex = ind;
									$('content').setHTML(resp);
	//								$('studenttable').setHTML(resp);
									init_items();
									init_calendar();
									//init_slider('notesdiv','shownotes');
									if (savedDate) {
										$('newdate').value = savedDate;
										$('formdate').value = savedDate;
									}
									//init_scroll_event();
									//init_scroll_areas();
									//pageTracker._trackPageview("/indexchangeclass");
								}
								tick.removeClass('ajax-loading');
							  }});
		myAjax.request();
	}
}

function changeDate(direction) {
	if (!$('class').value) {
		alert('Please select a class before changing dates!');
		return false;
	}
	var saveDate = $('newdate').value;
	if (saveDate || direction) {
		var tick = $('ticker2').empty().addClass('ajax-loading');
		var directionParam;
		if (direction) {
			directionParam = direction;
		}
		var myAjax = new Ajax('/ajax.pl', 
							 {method: 'post', 
							  data : 'action=ajaxgetdate&newdate='+$('newdate').value+"&class_id="+$('class').value+"&direction="+directionParam+"&formdate="+$('formdate').value, 
							  onComplete: function(resp) { 
								if (resp != 'failure') {
									var ind = 0;
									if (resp.indexOf("!!!") > 0) {
										var dayType = resp.substring(0,resp.indexOf("!!!"));
										if (dayType == 'N') {
											ind = 0;
										} else if (dayType == 'E') {
											ind = 1;
										} else if (dayType == 'L') {
											ind = 2;
										} else if (dayType == 'S') {
											ind = 3;
										}
										resp = resp.substring(resp.indexOf("!!!")+3);
									}
//									$('day_type').selectedIndex = ind;
									$('content').setHTML(resp);
									if ($('no_data') && $('message')) {
										$('message').addClass('nodata').setHTML('This day\'s attendance has not been saved.');
									}
									//init_slider('notesdiv','shownotes');
									init_items();
									init_calendar();
									//init_scroll_event();
									//init_scroll_areas();
									if (!direction) {
										$('newdate').value = saveDate;
									}
									//pageTracker._trackPageview("/indexchangedate");
								}
								tick.removeClass('ajax-loading');
							  }});
		myAjax.request();
	} else {
		alert('Please select a date.');
	}
}

function updatePageMessage(message, useEffects, isError) {
	if ($('message')) {
		if (isError) {
			$('message').addClass('error');
		} else {
			$('message').removeClass('error');
		}
		$('message').innerHTML = message;
		if (useEffects) {
			var drop = $('message');
			dropFx = drop.effect('background-color', {wait: false, duration: 1000});
			dropFx.start('7389AE').chain(dropFx.start.pass('ffffff', dropFx)).chain(function() { $('message').innerHTML = '';});
		}
	} else {
		if (isError) {
			$('page_message').addClass('error');
		} else {
			$('page_message').removeClass('error');
		}
		$('page_message').innerHTML = message;
		if (useEffects) {
			var drop = $('page_message');
			dropFx = drop.effect('background-color', {wait: false, duration: 1000});
			dropFx.start('7389AE').chain(dropFx.start.pass('eeeeee', dropFx)).chain(function() { $('page_message').innerHTML = '';});
		}
	}
}

function fieldFocusEvent(field, origValue, secondaryFieldName, secondaryOrigValue) {
	var secondaryField = $(secondaryFieldName);
	if (field.value == origValue) { field.value=''}
	if (secondaryField && secondaryField.value == secondaryOrigValue) { secondaryField.value = ''; }
}

function fieldBlurEvent(field, origValue, secondaryFieldName, secondaryOrigValue) {
	var secondaryField = $(secondaryFieldName);
	if (field.value == '') {
		field.value = origValue;
		if (secondaryField && field.value == origValue && secondaryField.value == '') {
			secondaryField.value = secondaryOrigValue;
		}
	}
}
