//******
// Add an event listener to an element
/*function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    //alert("Handler could not be attached");
  }
}*/
function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}
//******
// Remove an event listener from an element
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    //alert("Handler could not be removed");
  }
}

//****** Retrieve a reference to an object in the document
//
function getObj(objID)
{
	if (document.getElementById){
		return document.getElementById(objID);
	} else if (document.all){
		return document.all[objID];
	} else if (document.layers){
		return document.layers[objID];
	}
}

//****** Set a div's display attribute to show
//
function showDiv(div)
{
	getObj(div).style.display = '';
}

//****** Set a div's display attribute to none
//
function hideDiv(div)
{
	getObj(div).style.display = 'none';
}

//******
// Generate a random number
function Rndm(max) {
  return 1 + Math.floor(Math.random() * max);
}

//******
// Send a request to a url through the src
// attribute of an image.
function preserveSession(){
    
    var strReq  = '/index.cfm?fuseAction=preserveSession&random=' + Rndm(10000);
    var imgObj  = getObj('psImg');      
    
    if(imgObj){
        imgObj.src = strReq;       
    }   
   
} 

//******
// Open a popup window
function openWindow(url,name,props){
    newwindow = window.open(url,name,props);
}

//******
// Add a Trim function to the string datatype
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

//Random Number to prevent Caching
var randomnumber=Math.floor(Math.random()*100000)

//******
// DivID
// ObjectID
// WIDTH - swf file width
// HEIGHT - swf file height
// URL - swf file path
// align - left, right, middle
// varString - cariable string to attach to swf file path
// bgcolor -  hexidecimal color
// scale -  noBorder or leave blank
// autStrt -  true, false
// wmode -  transparent, opaque 
function flashObj(DivID, ObjectID, URL, varString, WIDTH, HEIGHT, align, bgcolor, scale, autoSrt, wmode, version)
{
  document.getElementById(DivID).innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='" + version + "' width=" + WIDTH + " height=" + HEIGHT + " id=" + ObjectID + " align=" + align + "><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value=" + URL + varString + "?noCache=" + randomnumber + " /><param name='menu' value='false' /><param name='quality' value='high' /><param name='SCALE' value=" + scale + "><param name='autostart' value="+autoSrt+" /> <param name='bgcolor' value="+ bgcolor +" />  <param name='wmode' value="+wmode+" /><embed src=" + URL + varString + "?noCache=" + randomnumber + "' menu='false' quality='high' wmode="+ wmode +" width=" + WIDTH + " name="+ ObjectID +" height=" + HEIGHT + " align=" + align + " allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' scale=" + scale + "/></embed></object>";
}
function flashLasVegasBanner(DivID, ObjectID, URL, varString, WIDTH, HEIGHT, align, bgcolor, scale, autoSrt, wmode, version)
{
  document.getElementById(DivID).innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='" + version + "' width=" + WIDTH + " height=" + HEIGHT + " id=" + ObjectID + " align=" + align + "><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value=" + URL + varString + "?noCache=" + randomnumber + " /><param name='menu' value='false' /><param name='quality' value='high' /><param name='SCALE' value=" + scale + "><param name='autostart' value="+autoSrt+" /> <param name='bgcolor' value="+ bgcolor +" />  <param name='wmode' value="+wmode+" /><embed src=" + URL + varString + "?noCache=" + randomnumber + "' menu='false' quality='high' wmode="+ wmode +" width=" + WIDTH + " name="+ ObjectID +" height=" + HEIGHT + " align=" + align + " allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' scale=" + scale + "/></embed></object>";
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
