/*  --    General Loading Script    --  */

function frameBuster(){
  if(top != self) top.location.replace(self.location)
}
Event.observe(window,'load',frameBuster);
/*  --  End General Loading Script  --  */


function turnOn(id) {
	document.getElementById(id).style.backgroundImage = "url(/kcssc/images/background-progress-over.gif)";
	document.getElementById(id).style.padding = "0px";	
	document.getElementById(id).style.borderColor = "#000000";
	document.getElementById(id).style.borderWidth = "1px";
	document.getElementById(id).style.borderStyle = "solid";
}

function turnOff(id) {
	document.getElementById(id).style.backgroundImage = "";
	document.getElementById(id).style.borderWidth = "0px";
	document.getElementById(id).style.padding = "1px";	
}

function validateForm(form) {
	form = document[form];
	missed = new Array();
	reg = new RegExp('[aeioAEIO]');
	for (i=0;i<form.length;i++) {
		input = form[i];
		if (input.id == "req" && is_null(input.value)) {
			alertstring = 'Please enter a';
			if (reg.test(input.name.charAt(0)))
				alertstring += 'n';
			alert(alertstring + ' ' + input.name.replace(/_/g," ") + '.');
			input.focus();
			return false;
		} else if (input.type == 'password') {
			var compare = input.compare;
			if (is_short(input.value,6,32)) {
				alert('Your password must be between 6 and 32 characters long.');
				input.value = '';
				input.focus();
				return false;
			} else if (compare !== undefined && input.value !== form[compare].value) {
				alert('Your passwords must match.');
				form['password'].value = '';
				form['password2'].value = '';
				form['password'].focus();
				return false;
			}
		} else if (input.name == 'email' && !is_email(input.value)) {
			alert('Please enter a valid e-mail.');
			input.focus();
			return false;
		}
	}
	return true;
}

function memberGallery(id) {
	window.open('member_gallery.php?id='+id,'_gallery','scrollbars=no,menubar=no,resizable=no,toolbar=no,location=no,status=no,width=800,height=600');
}

function eventImage(id) {
	window.open('event_image.php?id='+id,'_eventImage','scrollbars=no,menubar=no,resizable=no,toolbar=no,location=no,status=no,width=800,height=600');
}

function is_null(value) {
	value = new String(value);
	value = value.replace(/\s/g,"");
	if (value == "" || value == null) {
		return true;
	} else {
		return false;
	}
}

function is_short(value,min,max) {
	if (value.length < min || value.length > max) {
		return true;
	} else {
		return false;
	}
}

function is_email(value) {
	return (value.lastIndexOf(".") > value.indexOf("@"));
}

function clearIf(val) {
	if (val.value == "Search for People, Sports, Events")
		val.value = "";
}

function restoreIf(val) {
	if (val.value == "")
		val.value = "Search for People, Sports, Events";
}

function selectAll() {
	for (i=0;i<document.resultsForm.getElementsByTagName('input').length;i++) {
		document.resultsForm.getElementsByTagName('input')[i].checked = true;
	}
}

function selectNone() {
	for (i=0;i<document.resultsForm.getElementsByTagName('input').length;i++) {
		document.resultsForm.getElementsByTagName('input')[i].checked = false;
	}
}

function selectInverse() {
	for (i=0;i<document.resultsForm.getElementsByTagName('input').length;i++) {
		document.resultsForm.getElementsByTagName('input')[i].checked = !document.resultsForm.getElementsByTagName('input')[i].checked;
	}
}

function confirmDelete() {
	todelete = new Array();
	for (i=0;i<document.resultsForm.getElementsByTagName('input').length;i++) {
		if (document.resultsForm.getElementsByTagName('input')[i].checked == true) {
			todelete[i] = document.resultsForm.getElementsByTagName('input')[i].value;
		}
	}
	if (todelete.length == 1) {
		should = confirm("Are you sure you want to delete this item?");
	} else if (todelete.length > 1) {
		should = confirm("Are you sure you want to delete these items?");
	}
	if (should == true) {
		document.resultsForm.submit();
	}
}

/************************* khadiwala functions ********************************/

function genEmail(u,d,s,how,desc,cls){
	//user
	//domain
	//suffix
	//how - how to generate the email: asLink, withDesc
	//parameters (i.e. ?subject=I loved your website!)
	//description of the link (what goes between the <a></a> tags
	//class - style sheet
	//var parameters = (p != "" ? p : "");
	var parameters = "";
	//if(parameters!="" && parameters.substring(0,1) != "?"){parameters = "?" + parameters;}
	var e = u + "@" + d + "." + s;
	var txt;
	if(how == "asLink"){
		document.write("<a href='mailto:" + e + parameters + "'" + (cls ? " class=\"" + cls + "\"" : "") + ">" + e + "</a>");
	} else if(how == "withDesc"){
		document.write("<a href='mailto:" + e + parameters + "'" + (cls ? " class=\"" + cls + "\"" : "") + ">" + desc + "</a>");
	} else {
		document.write(e);
	}
}

function checkURL(u){
	if(u.value=="") return;
	if(u.value.indexOf("http://") == -1 && u.value.indexOf("https://") == -1) u.value = "http://" + u.value;
}

function getObj(oName){
	var browser = new BrowserDetect();	

  if(document.getElementById){
  	return document.getElementById(oName);
  } else if(document.all){
  	return document.all[oName];
  } else if(browser.isNS4){
  	return document.layers[oName];
  }
}

// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}

//helper functions from http://www.crockford.com/javascript/remedial.html
function isAlien(a) {return isObject(a) && typeof a.constructor != 'function';}
function isArray(a) {return isObject(a) && a.constructor == Array;}
function isBoolean(a) {return typeof a == 'boolean';}
function isFunction(a) {return typeof a == 'function';}
function isNull(a) {return typeof a == 'object' && !a;}
function isNumber(a) {return typeof a == 'number' && isFinite(a);}
function isObject(a) {return (a && typeof a == 'object') || isFunction(a);}
function isString(a) {return typeof a == 'string';}
function isUndefined(a) {return typeof a == 'undefined';} 
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {for (i in o) {v = o[i];if (isUndefined(v) && isFunction(v)) {return false;}}}
    return true;
}


function findSelectValueIndex(selName,val){
	var obj = getObj(selName);
	if(obj == null) return '';
	for(var i=0;i<obj.length;i++)
		if(obj[i].value == val) return i;
	return '';
}

function setSelectIndex(selName,val){
	var obj = getObj(selName);
	if(obj == null) return;
	var idx = findSelectValueIndex(selName,val);
	if(idx == '') return;
	obj.selectedIndex = idx;
}

/* Prototype -- Script.aculo.us  Functions */

function setLoadingOverlay(e,text){
	// Loading overlay class used for overlaying object for feedback to user
  //   that something is currently happening

	//  assumptions: object is positioned relatively
  //							 Prototype & Scriptaculous are loaded
  //							 Location of loading image
  
  var element = $(e);
  
  if(!element) return; 
  
  if($(element.id + '_loadingOverlay')){
  	//overlay already exists - make it visible & return
    $(element.id + '_loadingOverlay').style.display = ''
    new Effect.Appear(element.id + '_loadingOverlay',{to: .7}); 
    return;
  }
  
	var objLoadingOverlay = document.createElement("div");
	objLoadingOverlay.setAttribute('id',element.id + '_loadingOverlay');
  objLoadingOverlay.className = 'loadingOverlay';
  var objLoadingDiv = document.createElement("div");
  objLoadingDiv.innerHTML = text == "" ? "loading" : text;

  var objLoadingImage = document.createElement("img");
  objLoadingImage.setAttribute('src', "/kcssc/images/lightbox/loading.gif");

	objLoadingDiv.appendChild(objLoadingImage);
  objLoadingOverlay.appendChild(objLoadingDiv);
  
	element.appendChild(objLoadingOverlay);

  $(element.id + '_loadingOverlay').style.width = element.offsetWidth;
  $(element.id + '_loadingOverlay').style.height = element.offsetHeight;
  
}

function clearLoadingOverlay(e){
	// Loading overlay class used for overlaying object for feedback to user
  //   that something is currently happening

	//  assumptions: Overlay is loaded
  //							 Prototype & Scriptaculous are loaded
  
  var element = $(e); 
  if(!element) return; 

  if($(element.id + '_loadingOverlay')){
  	//overlay already exists - make it visible & return
    if($(element.id + '_loadingOverlay').style.display == 'none') return;
	  new Effect.Fade(element.id + '_loadingOverlay'); 
  } 
  
}

function getXMLResponseDataNode(response){
	if(response){return response.responseXML.getElementsByTagName("response")[0];}
  return false;
}

function xmlToArray(xml){
	//Constants
  var ELEMENT_NODE = 1;
  var TEXT_NODE = 3;
	var arr = new Array();
	for(var i=0; i < xml.childNodes.length; i++){
  	if(xml.childNodes[i].nodeType == ELEMENT_NODE) arr.push(xmlToObject(xml.childNodes[i]));
  }
  return arr;
}

function xmlToObject(xml){
	//Constants
  var ELEMENT_NODE = 1;
  var TEXT_NODE = 3;
	
  if(xml.nodeType == ELEMENT_NODE){
  	if(xml.attributes){
	  	var obj = new Object();
    	for(var i = 0; i < xml.attributes.length; i++) obj[xml.attributes[i].name] = xml.attributes[i].value;
      return obj; 
    }
  }
}

function getXMLResponseSingleValue(response){
	if(typeof(response) == "undefined") return false;
  var arr = xmlToArray(getXMLResponseDataNode(response));
  return arr[0].value; 
}

function emptySelectBox(element){
	var e = $(element);
  if(e.options) {while(e.options.length > 0){e.options[0] = null;}}
}

function addSelectOption(element,text,value){
	if(element == "") return;
  if($(element) && $(element).options) $(element).options[$(element).options.length] = new Option(text,value);
}

function loadSelectBoxWithXMLArrayObject(element,arr){
  var e = $(element);
 
  if(arr.length > 0){
		emptySelectBox(e);
    addSelectOption(e,'','');
	  for(var i = 0; i < arr.length; i++){addSelectOption(e,arr[i].name,arr[i].id);}
  } 

}

function loadCheckboxArrayWithXMLArrayObject(element,inputName,arr){
  if(!isArray(arr) || inputName == "" || element == "" || typeof($(element)) == 'undefined' || arr.length < 1) return;

  var e = $(element);
  e.innerHTML = "";
    
	var objCheckboxDiv;
	var objCheckboxLabel;  
  var objCheckbox;

  var i = 0;
	arr.each(
  	function(element){
    	objCheckboxDiv = document.createElement("div");
      
      objCheckboxLabel = document.createElement("label");
      objCheckboxLabel.setAttribute('for','checkbox_' + inputName + "_" + ++i);
      objCheckboxLabel.innerHTML = element.name;
      
    	objCheckbox = document.createElement("input");
      objCheckbox.setAttribute('type','checkbox');
      objCheckbox.setAttribute('class','checkbox');
      objCheckbox.setAttribute('value',element.id);
      objCheckbox.setAttribute('id','checkbox_' + inputName + "_" + i);
      objCheckbox.setAttribute('name',inputName + '[]');

      objCheckboxDiv.appendChild(objCheckbox);
      objCheckboxDiv.appendChild(objCheckboxLabel);
      e.appendChild(objCheckboxDiv);
			
      //cause setting the atribute didn't work for IE
      //if(element.checked == 1) objCheckbox.setAttribute('checked',true);
      if(element.checked == 1) $('checkbox_' + inputName + "_" + i).checked = true;

    }
  );

}

function getCheckboxArrayQueryString(inputName){
	if(inputName == "") return "";
  
  var str = "";
  var i = 0;
  
  while($('checkbox_' + inputName + "_" + ++i)){
  	if($('checkbox_' + inputName + "_" + i).checked == true){
    	str += (str == "" ? "" : "&") + inputName + "[]=" + $('checkbox_' + inputName + "_" + i).value;
    } 
  }
  return str;
}

function appendAnchor(element,href,text){
	if(!$(element)) return;
	objAnchor = document.createElement("a");
  objAnchor.setAttribute('href',href);
  objAnchor.innerHTML = text;
  $(element).appendChild(objAnchor);
}

function hideElements(arr,eff, duration){
	var fade;
	if(!isArray(arr) && arr == "") return;
  if(!isArray(arr)) arr = new Array(arr);
  if(typeof(eff) != 'undefined' && eff != "") {
  	if(typeof(duration) == 'undefined' || duration == "") duration = .5;
	  if(eff == 'Fade'){arr.each(function(a){if($(a) && $(a).style.display != 'none') new Effect.Fade($(a), {duration: duration});});}
	  if(eff == 'Blind'){arr.each(function(a){if($(a) && $(a).style.display != 'none') Effect.BlindUp($(a), {duration: duration});});}
  } else {
	  
	  arr.each(function(a){alert(a);$(a).style.display = 'none';});
  }
}

function showElements(arr){
	if(!isArray(arr) && arr == "") return;
  if(!isArray(arr)) arr = new Array(arr);
  arr.each(function(a){$(a).style.display = '';});
}

function hideLoadingPane(){$('loadingPane').style.display = 'none';}

function showLoadingPane(){$('loadingPane').style.display = '';}

/* Tabbed Box */

var tabbedBox_curTab = '';

function tabbedBox_switchTab(newTab){
	if(newTab == tabbedBox_curTab) return;
	
  if($('tabbedBox_' + newTab))
  $('tabbedBox_' + newTab).style.display = '';  
  $('tabbedBoxNav_' + newTab).className = 'current';
  
  if(tabbedBox_curTab != "" && $('tabbedBox_' + tabbedBox_curTab)){
    $('tabbedBox_' + tabbedBox_curTab).style.display = 'none';
    $('tabbedBoxNav_' + tabbedBox_curTab).className = '';
	}
  
  tabbedBox_curTab = newTab;
} 

function showHideObj(obj,effect){
	if($(obj) && $(obj).style){
  	if(typeof(effect) != 'undefined' && effect != ""){

    	//slide
      if(effect == 'slide'){
        if($(obj).style.display == ""){
        	Effect.SlideUp(obj);
        } else Effect.SlideDown(obj, {duration: .5});
      }

    	//blind
      if(effect == 'blind'){
        if($(obj).style.display == ""){
        	Effect.BlindUp(obj);
        } else Effect.BlindDown(obj, {duration: .5});
      }

    } else $(obj).style.display = $(obj).style.display == "" ? "none" : "";
  }
}

function onloadGoToHash(loc){
	if(loc == "") return;
  Event.observe(window, 'load', function (){window.location.hash=loc;}, false);
}

function checkAll(field){
  for (i = 0; i < field.length; i++)
	field[i].checked = true;
}

function uncheckAll(field){
  for (i = 0; i < field.length; i++)
	field[i].checked = false;
}

  
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; domain=192.168.1.4; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function resizeRightColumn(){
	$('body').style.height = 'auto';
	if(Element.getHeight('columnleft') > Element.getHeight('body')) Element.setHeight('body', Element.getHeight('columnleft'));
}

function findPos(obj,topParent) {
	//returns x,y positions of requested obj
  topParent = typeof(topParent) != "undefined" && topParent != "" ? topParent : '';
  obj = $(obj);
  if(!obj) return;
  var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
    obj = obj.offsetParent
		while (true) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
      if(!obj.offsetParent || (topParent != "" && obj.offsetParent.id == topParent)) break;
      obj = obj.offsetParent;
		}
	}
  var browser = new BrowserDetect();	
  curleft += browser.isIE ? 1 : 0;
	return [curleft,curtop];
}

function findPos_new(obj,topParent) {
  return [findPosX(obj,topParent),findPosY(obj,topParent)];
}

function findPosX(obj,topParent){
  var curleft = 0;
  if(obj.offsetParent){
    while(1){
      curleft += obj.offsetLeft;
      if(!obj.offsetParent || (topParent != "" && obj.offsetParent.id == topParent)) break;
      obj = obj.offsetParent;
    }
  } else if(obj.x) curleft += obj.x;
  return curleft;
}

function findPosY(obj,topParent){
  var curtop = 0;
  if(obj.offsetParent){
    while(1){
      curtop += obj.offsetTop;
      if(!obj.offsetParent || (topParent != "" && obj.offsetParent.id == topParent)) break;
      obj = obj.offsetParent;
    }
  } else if(obj.y) curtop += obj.y;
  return curtop;
}

function setPos(obj,x,y){
  obj = $(obj);
  if(obj == "") return;
  obj.style.left = x + 'px';
  obj.style.top = y + 'px';
}

function getDim(e){
	if($(e)){
    return [Element.getWidth(e), Element.getHeight(e)];
  }
  
}

var currentMouseCoordinates = '';

function setCurrentMouseCoordinates(e){
	arr = [Event.pointerX(e),Event.pointerY(e)];
  currentMouseCoordinates = arr;
}
Event.observe(document,'mousemove',function(e){setCurrentMouseCoordinates(e);},false);


function withinCoordinates(x,y,w,h){
	if(currentMouseCoordinates == "") return false
	mouseX = currentMouseCoordinates[0];
  mouseY = currentMouseCoordinates[1];
  //writeToDebugPanel([x,y,x+w,y+h,currentMouseCoordinates].inspect());
  return mouseX >= x && mouseY >= y && mouseX <= (w + x) && mouseY <= (h + y);  
}

function mouseWithinElement(e){
  if(!$(e)) return;
	xy = findPos(e);
  x = xy[0];
  y = xy[1];
	h = Element.getHeight(e);
	w = Element.getWidth(e);
  return withinCoordinates(x,y,w,h);
}

function appendTextNode(element,text){
	$(element).appendChild(Builder.node('p',text));
}

function writeToDebugPanel(text){
	if(!$('debugPanel') || text == '') return;
	appendTextNode('debugPanel',text);
  $('debugPanel').scrollTop = $('debugPanel').scrollHeight;
}

var currentMoreInfoElement = '';
var currentMoreInfoTrigger = '';
var hideMoreInfoTimeout = '';
function showMoreinfo(trigger,element,topParent){
  //show a specific more info element
  if(!$(element)) return;
  if(currentMoreInfoElement == element){
    //reset timeout
    if(hideMoreInfoTimeout != '') clearTimeout(hideMoreInfoTimeout); 
    hideMoreInfoTimeout = setTimeout(function(){hideMoreinfo(trigger,element);},500);
    return;
  }
  
  if(currentMoreInfoElement != "" && currentMoreInfoElement != element) hideMoreinfo(currentMoreInfoTrigger,currentMoreInfoElement,true,true);
    
  currentMoreInfoElement = element;
  
  xy = findPos(trigger,topParent);
  //xy = currentMouseCoordinates
  wh = getDim(trigger);
  Element.setLeft(element, xy[0] + wh[0] + 2);
  par = typeof(topParent) == "undefined" || topParent == null || topParent == 'null' ? document.body : topParent;
  Element.setTop(element, xy[1] + 3);
	
  //set triggerPostion
  triggerPostion = $(element).getAttribute('triggerPostion');
  if(triggerPostion == 'below') Element.setTop(element, xy[1] + wh[1]); 
  if(triggerPostion == 'belowMouse'){
    Element.setTop(element, xy[1] + wh[1] + 3);
    Element.setLeft(element, currentMouseCoordinates[0] + 5);
  } 

  Element.show(element);
  if((xy[0] + wh[0] + 2 + Element.getWidth(element)) > Element.getWidth(par)){
    Element.setLeft(element, Element.getWidth(par) - Element.getWidth(element) - 10);
    Element.setTop(element, xy[1] + wh[1] + 3);
  }

  
  hideMoreInfoTimeout = setTimeout(function(){hideMoreinfo(trigger,element);},500);
}

function hideMoreinfo(trigger,element,hideItNow,override){

  if(override === true || (!mouseWithinElement(trigger) && !mouseWithinElement(element) && hideItNow === true)){
    currentMoreInfoElement = '';
    currentMoreInfoTrigger = ''
    clearTimeout(hideMoreInfoTimeout);
    Element.hide(element);
    return;
  }
  
  //alert([trigger,findPos(trigger), getDim(trigger), currentMouseCoordinates, mouseWithinElement(trigger), element, mouseWithinElement(element)]);
  if(!mouseWithinElement(trigger) && !mouseWithinElement(element) && hideItNow !== true){
    if(hideMoreInfoTimeout != '') clearTimeout(hideMoreInfoTimeout);
    hideMoreInfoTimeout = setTimeout(function(){hideMoreinfo(trigger,element,true);},500);
    return;
  } 

  //Set timeout as moreinfo is still not hidden
  hideMoreInfoTimeout = setTimeout(function(){hideMoreinfo(trigger,element);},500);
  
}

function setMoreinfoTriggers(){
  items = $$('.moreinfo').each(function (element){
    if($(element)){
      trigger = $(element).getAttribute('trigger');
      topParent = $(element).getAttribute('topParent');
      if($(trigger)){
        id = $(element).id;
        if($(trigger).href && $(trigger).href == "") $(trigger).href = "javascript:showMoreinfo('" + trigger + "','" + id + "')";
        Event.observe($(trigger),'mouseover',new Function("showMoreinfo('" + trigger + "','" + id + "','" + topParent + "')"));
        Event.observe($(trigger),'focus',new Function("$('" + trigger + "').blur()"));
      }
    }
  });
   //showMoreinfo('moreinfoTrigger','moreinfoItem')

  items = $$('.tooltip').each(function (element){
    if($(element)){
      trigger = $(element).getAttribute('trigger');
      topParent = $(element).getAttribute('topParent');
      if($(trigger)){
        id = $(element).id;
        if($(trigger).href && $(trigger).href == "") $(trigger).href = "javascript:showMoreinfo('" + trigger + "','" + id + "')";
        Event.observe($(trigger),'mouseover',new Function("showMoreinfo('" + trigger + "','" + id + "','" + topParent + "')"));
        Event.observe($(trigger),'focus',new Function("$('" + trigger + "').blur()"));
      }
    }
  });
   
}
Event.observe(window,'load',setMoreinfoTriggers);

function equalizeHeights(arr){
	if(!isArray(arr) || arr.length < 2) return;
  var objs = new Array();
  var maxHeight = 0;
  arr.each(function(e){if($(e)) objs.push(e);}); //verify obj exists
  if(objs.length < 2) return; //return if less than 2 objs were qualified 
  objs.each(function(o){if(Element.getHeight(o) > maxHeight) maxHeight = Element.getHeight(o);}); //find max height of all objects
  objs.each(function(o){if(Element.getHeight(o) < maxHeight) Element.setHeight(o,maxHeight);});
}

/*function setWindowStatus () {
	window.defaultStatus = ""
	return true
}*/
