var timerID = 0;
var tStart = null;
var Id_No = 0;

var DH = 0;
var an = 0;
var al = 0;
var ai = 0;
var pickedUp = new Array("", false, 0, 0);
if (document.getElementById) {
	ai = 1;
	DH = 1;
} else {
	if (document.all) {
		al = 1;
		DH = 1;
	} else {
		browserVersion = parseInt(navigator.appVersion);
		if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
			an = 1;
			DH = 1;
		}
	}
}

function getReadyToMove(element, evt) {
	pickedUp[0] = element;
	var currentSelection = document.getElementById(pickedUp[0]);
	
	pickedUp[1] = true;
	pickedUp[2] = (0 + evt.clientY - parseInt(currentSelection.style.top));
	pickedUp[3] = (0 + evt.clientX - parseInt(currentSelection.style.left));
}

function checkLoadedObjects(evt) {
	if (pickedUp[1] == true) {
		var currentSelection = document.getElementById(pickedUp[0]);

		currentSelection.style.position = "absolute";
		currentSelection.style.top = (evt.clientY - pickedUp[2]) + "px";
		currentSelection.style.left = (evt.clientX - pickedUp[3]) + "px";
	}
}

function dropLoadedObject(evt) {
	pickedUp = new Array("", false, 0, 0);
}

function UpdateTimer() {
	if (timerID) {
		clearTimeout(timerID);
	}

	if	(!tStart)
		tStart   = new Date();

	var   tDate = new Date();
	var   tDiff = tDate.getTime() - tStart.getTime();

	tDate.setTime(tDiff);

	Id_No++;
	if (document.getElementById('Gold')) {
		if (Id_No == 1) {
			document.getElementById('Gold').style.display='block';
			/*document.getElementById('Gold').style.marginLeft = 'auto';
			document.getElementById('Gold').style.marginRight = 'auto';*/
		}

		if (Id_No < 26) {
			if (navigator.appName.indexOf("Microsoft")!= -1) document.getElementById('Gold').filters.alpha.opacity = (Id_No) * 4;
			if (navigator.appName.indexOf("Netscape")!=-1) document.getElementById('Gold').style.MozOpacity = (Id_No) * 0.04;
  		}
		
		if (Id_No < 201 && Id_No > 175) {
			if (navigator.appName.indexOf("Microsoft")!= -1) document.getElementById('Gold').filters.alpha.opacity = (201 - Id_No) * 4;
			if (navigator.appName.indexOf("Netscape")!=-1) document.getElementById('Gold').style.MozOpacity = (201 - Id_No) * 0.04;
  		}
		
		if (Id_No == 201) document.getElementById('Gold').style.display='none';
	}
	timerID = setTimeout("UpdateTimer()", 150);
}

function StartTimer() {
	tStart = new Date();
	timerID  = setTimeout("UpdateTimer()", 150);
}

function checkform (thisform)
{
	var lReturn = true;

/* 	if (document.getElementById('person-c').value == "") {
		if (lReturn) {
			alert('Please fill out Your Name.');
			document.getElementById('person-c').focus();
			lReturn = false;
		}
	}
 */
	if (document.getElementById('email-c').value == "") {
		if (lReturn) {
			alert('Please fill out Your E-Mail Address.');
			document.getElementById('email-c').focus();
			lReturn = false;
		}
	}

/* 	if (document.getElementById('phone-c').value == "") {
		if (lReturn) {
			alert('Please fill out Your Phone Number.');
			document.getElementById('phone-c').focus();
			lReturn = false;
		}
	}
 */
	return lReturn ;
	
}

function checkcontactform (thisform)
{
	var lReturn = true;

	if (document.getElementById('person').value == "") {
		if (lReturn) {
			alert('Please fill out Your Name.');
			document.getElementById('person').focus();
			lReturn = false;
		}
	}

	if (document.getElementById('email').value == "") {
		if (lReturn) {
			alert('Please fill out Your E-Mail Address.');
			document.getElementById('email').focus();
			lReturn = false;
		}
	}

	if (document.getElementById('subject').value == "") {
		if (lReturn) {
			alert('Please fill out the Subject.');
			document.getElementById('subject').focus();
			lReturn = false;
		}
	}

	if (document.getElementById('message').value == "") {
		if (lReturn) {
			alert('Please fill out the Message Body.');
			document.getElementById('message').focus();
			lReturn = false;
		}
	}

	return lReturn ;
	
}

function SetCalendarView (thisvalue) {
	window.location = "index.php?" + thisvalue;
}

function ShowDetails(evt, legend, OffsetX, OffsetY) {

	var wp = pw();
	dm = fd(legend,0);
	ew = 0;
	eh = 0;
	
	if (dm.offsetWidth) ew = dm.offsetWidth;
	else if (dm.clip.width) ew = dm.clip.width;
	
	if (dm.offsetHeight) eh = dm.offsetHeight;
	else if (dm.clip.height) eh = dm.clip.height;

	lv = mouseX(evt) + OffsetX;
	tv = mouseY(evt) + OffsetY;
	
	if (tv < 1) tv = 5;
	
	if (lv < 2) lv = 2;
	else if (lv + ew > wp) lv = wp - ew - 30;

	if (!an) {
		lv += 'px';
		tv += 'px';
	}
	
	if (document.getElementById('p1')) document.getElementById('p1').style.visibility = 'hidden';
	if (document.getElementById('p2')) document.getElementById('p2').style.visibility = 'hidden';
	if (document.getElementById('p3')) document.getElementById('p3').style.visibility = 'hidden';
	if (document.getElementById('p4')) document.getElementById('p4').style.visibility = 'hidden';
	if (document.getElementById('p5')) document.getElementById('p5').style.visibility = 'hidden';
	if (document.getElementById('p6')) document.getElementById('p6').style.visibility = 'hidden';
	if (document.getElementById('p7')) document.getElementById('p7').style.visibility = 'hidden';
	if (document.getElementById('p8')) document.getElementById('p8').style.visibility = 'hidden';
	if (document.getElementById('p9')) document.getElementById('p9').style.visibility = 'hidden';
	if (document.getElementById('p10')) document.getElementById('p10').style.visibility = 'hidden';

	document.getElementById(legend).style.left = lv;
	document.getElementById(legend).style.top = tv;
	document.getElementById(legend).style.visibility = 'visible';
	document.getElementById(legend).style.zIndex = 1;
}

function fd(oi, wS) {
	if (ai) return wS ? document.getElementById(oi).style:document.getElementById(oi);
	if (al) return wS ? document.all[oi].style: document.all[oi];
	if (an) return document.layers[oi];
}

function pw() {
	return window.innerWidth != null? window.innerWidth: document.body.clientWidth != null? document.body.clientWidth:null;
}

function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX) return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	else return null;
}

function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY) return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	else return null;
}

function checkregistrationform (thisform)
{
	var lReturn = true;

	if (document.getElementById('child_last').value == "") {
		if (lReturn) {
			alert('Please fill out Child\'s Name.');
			document.getElementById('child_last').focus();
			lReturn = false;
		}
	}

	if (document.getElementById('child_first').value == "") {
		if (lReturn) {
			alert('Please fill out Child\'s Name.');
			document.getElementById('child_first').focus();
			lReturn = false;
		}
	}

	if (document.getElementById('parent_last').value == "") {
		if (lReturn) {
			alert('Please fill out Parent\'s Name.');
			document.getElementById('parent_last').focus();
			lReturn = false;
		}
	}

	if (document.getElementById('parent_first').value == "") {
		if (lReturn) {
			alert('Please fill out Parent\'s Name.');
			document.getElementById('parent_first').focus();
			lReturn = false;
		}
	}
	if (document.getElementById('email').value == "") {
		if (lReturn) {
			alert('Please fill out Your E-Mail Address.');
			document.getElementById('email').focus();
			lReturn = false;
		}
	}

	if (document.getElementById('class1').value == "") {
		if (lReturn) {
			alert('Please choose at lest one class.');
			document.getElementById('class1').focus();
			lReturn = false;
		}
	}

	return lReturn ;
	
}

function ShowMap(mapObject, address, markerText) {
	if (document.getElementById(mapObject)) {
		var mapOptions = {
			zoom: 16,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			mapTypeControl: true,
			mapTypeControlOptions: {
				style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
				position: google.maps.ControlPosition.TOP_RIGHT
			},
			navigationControl: true,
			navigationControlOptions: {
				style: google.maps.NavigationControlStyle.ZOOM_PAN,
				position: google.maps.ControlPosition.TOP_LEFT
			},
			scaleControl: false
		};
		
		var map = new google.maps.Map(document.getElementById(mapObject), mapOptions);
		var geocoder = new google.maps.Geocoder();

		if (geocoder) {
			geocoder.geocode( { 'address': address}, function(results, status) {
				if (status == google.maps.GeocoderStatus.OK) {
					var coord = results[0].geometry.location;
					
					var marker = new google.maps.Marker({
						position: coord, 
						map: map,
						title: address
					});
					
					var infowindow = new google.maps.InfoWindow({
						content: markerText
						});
					google.maps.event.addListener(marker, 'click', function() {
						infowindow.open(map,marker);
					}); 
					map.setCenter(coord);
				}
			});
		}
	}
}

// Script for NiftyPlayer 1.7, by tvst from varal.org
// Released under the MIT License: http://www.opensource.org/licenses/mit-license.php

var FlashHelper =
{
	movieIsLoaded : function (theMovie)
	{
		if (typeof(theMovie) != "undefined") return theMovie.PercentLoaded() == 100;
		else return
		false;
  },

	getMovie : function (movieName)
	{
  	if (navigator.appName.indexOf ("Microsoft") !=-1) return window[movieName];
	  else return document[movieName];
	}
};

function niftyplayer(name)
{
	this.obj = FlashHelper.getMovie(name);

	if (!FlashHelper.movieIsLoaded(this.obj)) return;

	this.play = function () {
		this.obj.TCallLabel('/','play');
	};

	this.stop = function () {
		this.obj.TCallLabel('/','stop');
	};

	this.pause = function () {
		this.obj.TCallLabel('/','pause');
	};

	this.playToggle = function () {
		this.obj.TCallLabel('/','playToggle');
	};

	this.reset = function () {
		this.obj.TCallLabel('/','reset');
	};

	this.load = function (url) {
		this.obj.SetVariable('currentSong', url);
		this.obj.TCallLabel('/','load');
	};

	this.loadAndPlay = function (url) {
		this.load(url);
		this.play();
	};

	this.getState = function () {
		var ps = this.obj.GetVariable('playingState');
		var ls = this.obj.GetVariable('loadingState');

		// returns
		//   'empty' if no file is loaded
		//   'loading' if file is loading
		//   'playing' if user has pressed play AND file has loaded
		//   'stopped' if not empty and file is stopped
		//   'paused' if file is paused
		//   'finished' if file has finished playing
		//   'error' if an error occurred
		if (ps == 'playing')
			if (ls == 'loaded') return ps;
			else return ls;

		if (ps == 'stopped')
			if (ls == 'empty') return ls;
			if (ls == 'error') return ls;
			else return ps;

		return ps;

	};

	this.getPlayingState = function () {
		// returns 'playing', 'paused', 'stopped' or 'finished'
		return this.obj.GetVariable('playingState');
	};

	this.getLoadingState = function () {
		// returns 'empty', 'loading', 'loaded' or 'error'
		return this.obj.GetVariable('loadingState');
	};

	this.registerEvent = function (eventName, action) {
		// eventName is a string with one of the following values: onPlay, onStop, onPause, onError, onSongOver, onBufferingComplete, onBufferingStarted
		// action is a string with the javascript code to run.
		//
		// example: niftyplayer('niftyPlayer1').registerEvent('onPlay', 'alert("playing!")');

		this.obj.SetVariable(eventName, action);
	};

	return this;
}

