// -----------------------------------------------------------------------------------
//
//	SportsMatchMaker.js
//	by SportsMatchMaker.com Rockstar Developers!!!
//
//	STOP LOOKING...THIS CODE IS ENCRYPTED!! Just kidding! Hey, we'll make you a deal.
//  Look but don't touch, ok? Deal!! ;-)
//
//	Well, we did BORROW some code from Spry. :-)
//
// -----------------------------------------------------------------------------------

function SportsMatchMaker(){
	this.sessionTimeout = 29; //set it to 29 to ensure the session exists so we can properly clear from the log
	this.sessionStart = new Date();
	this.timout = -1;
}

SportsMatchMaker.prototype.startSessionTimer = function(){
	if(this.timout != -1){
		clearTimeout(this.timout);
	}
	this.timout = setTimeout(this.handleSessionTimeout, this.sessionTimeout*(60*1000)); //timeout * (60 seconds/min * 1000 milliseconds/second));
}

SportsMatchMaker.prototype.handleSessionTimeout = function(){
	alert("Your session has ended. You need to log in again to continue.");
	
	smm.redirect("/index.cfm?logout");
}

SportsMatchMaker.prototype.redirect = function(location){
	window.location = location;
}

SportsMatchMaker.prototype.getComboSelectedValue = function(combo){
	if(typeof(combo) == "string") combo = this.$(combo);
	
	return combo.options[combo.selectedIndex].value;
}

SportsMatchMaker.prototype.getComboSelectedText = function(combo){
	if(typeof(combo) == "string") combo = this.$(combo);
	
	return combo.options[combo.selectedIndex].text;
}

SportsMatchMaker.prototype.isNumeric = function(value){
	return !isNaN(value);
}

/**
	Returns a(the) dom element(s) passed in
	
	param element A string value of the element you are looking for
	param ... A rest parameter
	
	returns string
**/
SportsMatchMaker.prototype.$ = function(element){
	if (arguments.length > 1){
		for (var i = 0, elements = [], length = arguments.length; i < length; i++)
			elements.push(smm.$(arguments[i]));
		return elements;
	}
	if (typeof element == "string") element = document.getElementById(element);

	return element;
}

/**
	Returns a(the) dom element(s) passed in
	
	param element An element you want to show/hide 
	
	returns string
**/
SportsMatchMaker.prototype.toggleDisplay = function(element){
	if(element == null) return;
	if(typeof element == "string") element = smm.$(element);
	
	var isVisible = element.style.display != "none";
	if(element) element.style.display = (isVisible ? "block" : "none");
	
	return isVisible;
}

/**
	Returns a(the) dom element(s) passed in
	
	param element An element you want to show/hide 
**/
SportsMatchMaker.prototype.show = function(element, displayValue){
	if(element == null) return;
	if(typeof element == "string") element = smm.$(element);
	if(displayValue == null) displayValue = "block";
	
	
	element.style.display = displayValue;
}

/**
	Returns a(the) dom element(s) passed in
	
	param element An element you want to show/hide 
**/
SportsMatchMaker.prototype.hide = function(element){
	if(element == null) return;
	if(typeof element == "string") element = smm.$(element);
	
	element.style.display = "none";
}

var smm = new SportsMatchMaker();
