// JavaScript Document
//Define the Ajax Gateway URL
var ajax_url = 'Tech/Gateway.inc.php'

/*************************************************************
* The womOn() function will set the window.onload function to
* be womGo() which will run all of your window.onload
* functions.
*************************************************************/
function womOn(){
  window.onload = womGo;
}
/*************************************************************
* The womGo() function loops through the woms array and
* runs each function in the array.
*************************************************************/
function womGo(){
  for(var i = 0;i < woms.length;i++)
    eval(woms[i]);
}
/*************************************************************
* The womAdd() function will add another function to the woms
* array to be run when the page loads.
*************************************************************/
function womAdd(func){
  woms[woms.length] = func;
}
/*************************************************************
* The woms array holds all of the functions you wish to run
* when the page loads.
*************************************************************/
var woms = new Array();


//Login Controller to assign Input Methods
function LoginController () {
	this.clearLogout()
	this.attachAction ()
}
	LoginController.prototype.clearLogout = function () {
		
	}
	LoginController.prototype.attachAction = function () {
		document.LoginForm.User_Email.onclick = function () {
			if (this.value == 'Email') {
				this.value = ''
			}
		}
		document.LoginForm.User_Email.onblur = function () {
			if (this.value == '') {
				this.value = 'Email'
			}
		}
		
		//onfocus need method 
		document.LoginForm.User_Pass.onfocus = function () {
		if (this.value == 'Password') {
				this.value = ''
				this.setAttribute('type', 'Password')
			}
		}
		document.LoginForm.User_Pass.onclick = function () {
			if (this.value == 'Password') {
				this.value = ''
				this.setAttribute('type', 'Password')
			}
		}
		document.LoginForm.User_Pass.onblur = function () {
			if (this.value == '') {
				this.setAttribute('type', 'Text')
				this.value = 'Password'
			}
		}
	}
//Login Form Validity Check Upon Submition
function ValidateLogin (that) {
var Validity = true
var Error = ''
if (that.User_Email.value == 'Email' || that.User_Pass.value == 'Password') {
	Validity = false
	document.getElementById('UserControl').innerHTML += '<br /><br />Please fill in the missing fields'
}
return Validity
}

//Calendar Popup Control Functions
function setMultipleValues(y,m,d) {	
	document.forms[0].StartYear.value = y;
	document.forms[0].StartMonth.selectedIndex = m;
	for (var i=0; i<document.forms[0].StartDay.options.length; i++) {
		if (document.forms[0].StartDay.options[i].value==d) {
			document.forms[0].StartDay.selectedIndex=i;
		}
	}			 
}
function setMultipleValues2(y,m,d) {	
	document.forms[0].FinishYear.value = y;
	document.forms[0].FinishMonth.selectedIndex = m;
	for (var i=0; i<document.forms[0].FinishDay.options.length; i++) {
		if (document.forms[0].FinishDay.options[i].value==d) {
			document.forms[0].FinishDay.selectedIndex=i;
		}
	}			 
}
function getDateString(y_obj,m_obj,d_obj) {
	var y = y_obj.options[y_obj.selectedIndex].value;
	var m = m_obj.options[m_obj.selectedIndex].value;
	var d = d_obj.options[d_obj.selectedIndex].value;
	if (y=="" || m=="") { return null; }
	if (d=="") { d=1; }
	return str= y+'-'+m+'-'+d;
}

//Event Balloon Popup Controler
function EventInfoController (that, SignUp, E, Event_Desc, Event_Title, Event_Start_Time, Event_Finish_Time, Event_Venue) {
	this.EventInfo = document.createElement('Div')
	this.EventInfo.className = 'Event_Info'
	document.getElementsByTagName('Body')[0].appendChild(this.EventInfo)		
	this.EventInfo.style.cssText = 'left: ' + (mouseX + 10) + 'px; top: ' + (mouseY - 25) + 'px;'	
	this.EventInfoTop = document.createElement('Div')
	this.EventInfoTop.className = 'EventInfoTop'
	this.EventInfoTop.innerHTML += '<img src="Media/SiteImages/Remove.jpg" border="0px" class="CloseEvent" onclick="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);" title="Close" alt="Close Event Popup">'
	this.EventInfo.appendChild(this.EventInfoTop)
	this.EventInfoCenter = document.createElement('Div') 
	this.EventInfoCenter.className = 'EventInfoCenter'
	this.EventInfo.appendChild(this.EventInfoCenter)
	if (SignUp != '') {
		this.EventInfoCenter.innerHTML += SignUp + '<br />'
	}
	if (E != '') {
		this.EventInfoCenter.innerHTML += E + '<br />'
	}
	this.EventInfoCenter.innerHTML += '<b>' + Event_Title + '</b><br />'
	this.EventInfoCenter.innerHTML += '<span class="Event_Time">' + Event_Start_Time + ' - ' + Event_Finish_Time + '<br />'
	this.EventInfoCenter.innerHTML += Event_Venue + '</span><br /><br />'
	this.EventInfoCenter.innerHTML += Event_Desc
	this.EventInfoBottom = document.createElement('Img')
	this.EventInfoBottom.setAttribute('src', 'Media/Layout/Bubble_Bottom.png')
	this.EventInfoBottom.setAttribute('width', '274px')
	this.EventInfoBottom.setAttribute('height', '15px')
	this.EventInfo.appendChild(this.EventInfoBottom)	
}

//Toggle Recurring Event Open / Closed
function ToggleRepeat (that) {
	var div = document.getElementById('RecurringEvent')
	//check that the start date has been inputted
	if (document.forms[0].StartMonth.value != "Month" && document.forms[0].StartDay.value != "" && document.forms[0].StartYear.value != "" ) {
		document.getElementById('RecurringOutput').innerHTML = ''
		if (div.style.display == 'none') {
			/*
			//below was being used to return the text day of the starting day
			//so it could be checked off in the multipe days for recurring events
			//working, but will impliment later
			//ajax call to return the day selected to check in the recurring checkboxes
			var action 		= '?Action=RequestDateToDay'
			var month       = '&Month=' + document.forms[0].StartMonth.options[document.forms[0].StartMonth.selectedIndex].value
			var day       	= '&Day=' + document.forms[0].StartDay.options[document.forms[0].StartDay.selectedIndex].value
			var year        = '&Year=' + document.forms[0].StartYear.options[document.forms[0].StartYear.selectedIndex].value
			var Response	= '&Response=PopulateRecurringDays'
			var get_vars 	= action + month + day + year + Response
			//var post_vars	= month + day + year + Response
			var post_vars = "";
			makePOSTRequest(ajax_url + get_vars, post_vars)
			*/
			div.style.display = ''
		} else {
			div.style.display = 'none'
			document.forms[0].RepeatEvery.selectedIndex = 0
			document.forms[0].FinishMonth.selectedIndex = 0
			document.forms[0].FinishDay.selectedIndex = 0
			document.forms[0].FinishYear.selectedIndex = 0
		}
	} else {
		that.checked = false
		document.getElementById('RecurringOutput').innerHTML = 'You must enter the event start date first'
	}
}	
	//CallBack function for the ajax call above
	function PopulateRecurringDays (day) {
		document.getElementById(day).checked = true
	}

//PinPoint Mouse Location
//Used to determine event information popup placement on the calendar
var mouseX = ''
var mouseY = ''

function MouseController () {
	if (window.Event) {
			document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = this.getCursorXY;
}
	MouseController.prototype.getCursorXY = function (e) {
		mouseX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		mouseY = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	}

function ShowLgImage (that) {
	var img = document.getElementById('LgImage')
	var src = that.src.split('/')
	var lgimage = src[src.length - 1].split('-')
	var tmp = lgimage[1].split('.')
		lgimage = lgimage[0] + '-large.' + tmp[1]
		img.setAttribute('src', 'Media/GalleryImages/' + src[src.length - 3] + '/' + src[src.length - 2] + '/' + lgimage)
		img.setAttribute('width', '520px')
		img.setAttribute('height', '320px')
}

//Remove a DOM Object with a fade out / shrink
function FadeRemove (ObjId) {
	IntervalId = 0
	Opacity = 70
	IntervalId = setInterval('Fade(\'' + ObjId + '\')', 125) 
}
	function Fade (ObjId) {
		this.Obj = document.getElementById(ObjId)
		/*
		if (navigator.appName.indexOf("Netscape")!=-1 &&parseInt(navigator.appVersion) >= 5) {
			this.Obj.style.MozOpacity = Opacity / 100
		} else if (navigator.appName.indexOf("Microsoft")!= -1 &&parseInt(navigator.appVersion) >= 4) {
			this.Obj.filters.alpha.opacity = Opacity
		}
		*/
		this.Obj.style.opacity = Opacity / 100
		Opacity = Opacity - 10
		if (Opacity == 0) {
			clearInterval(IntervalId)
			RemoveObj(ObjId)
		}
	}
	
	function RemoveObj (ObjId) {
		IntervalId = 0
		IntervalId = setInterval('HideObject(\'' + ObjId + '\')', 50) 
	}
		function HideObject (ObjId) {
			this.Obj = document.getElementById(ObjId)
			this.Obj.style.height = (this.Obj.offsetHeight - 30) + 'px'
			if (parseInt(this.Obj.offsetHeight) < 30) {
				clearInterval(IntervalId)
				this.Obj.parentNode.removeChild(this.Obj)
			}
		}