// JavaScript Document

function fixAction(string, formname)	{
	eval("document." + formname + ".action.value='" + string + "';"); 
	eval("showLoading();");
	eval("document." + formname + ".submit();"); 
	return false;
}
			
function showLoading()	{
	if (document.getElementById('form-loading'))
		document.getElementById('form-loading').style.display = "block";
}
			
function switchPlusMinus(id)	{
	return false;
	
	var getCurImg;
	var myImg;
	
	getCurImg = document.getElementById(id).src;
	myImg = getCurImg.split("/");
	
	//if it is plus, change to minus
	if (myImg[myImg.length-1] == "plus.gif")	{
		document.getElementById(id).src =  "http://" + location.hostname + "/images/minus.gif";
	}
	//if it is minus, change to plus
	else	{
		document.getElementById(id).src = "http://" + location.hostname + "/images/plus.gif";
	}
	
	return false;
}

function switchContent(id, oldcontent, newcontent)	{
	
	currentContent = document.getElementById(id);
	
	if (currentContent.innerHTML == oldcontent)	{
		currentContent.innerHTML = newcontent;
	}
	else	{
		currentContent.innerHTML = oldcontent;
	}
	
	return false;
}

//Slightly overly-complicated hide/show reply discussion stuff for blog discussion php_page_component
//***This function could be greatly optimized if some slight changes are made in way posts are displayed, or more time is spent clarifying show/hide parameters
function switchReply(test_value, a_toggle, reply_box, new_comment_box)	{
	var sdiv,i, toggle;
	
	
	//first, switch the status of what we clicked on
	toggleHide(reply_box);
	
	//If we clicked 'Reply'
	if (document.getElementById(reply_box).style.display == "block")	{
		document.getElementById(a_toggle).innerHTML = "&times;&nbsp;Close";
		hideThis(new_comment_box);	
		
		sdiv=document.getElementsByTagName('*');
		for(i in sdiv){
			if(/discussion_reply_/.test(sdiv[i].id)) {				
				var myObject = document.getElementById(sdiv[i].id);
				
				if (myObject.tagName == "A"  && sdiv[i].id != a_toggle)	{
					myObject.innerHTML = "&raquo;&nbsp;Reply";
				}
				//else
				//	alert(myObject.tagName + " 1 " +  sdiv[i].id);
					
				if (myObject.tagName == "DIV"  && sdiv[i].id != reply_box)	{
					hideThis(sdiv[i].id);
				}	
				//else
				//	alert(myObject.tagName + " YYY " +  sdiv[i].id);
			}
		}//end for
	
		
		
	}//end if
	//else, we clicked 'Close'
	else	{
		document.getElementById(a_toggle).innerHTML = "&raquo;&nbsp;Reply";
		hideThis(reply_box);
		
		showThis(new_comment_box);
	}
	
		
}



function doSearch()	{
	//First, show loading graphic
	var resultDiv = document.getElementById('search_results');
	resultDiv.innerHTML = '<img src="images/loading3.gif">';
	
	var searchFor = new Array("search_people", "search_networks", "search_conferences");
	var searchTerm = document.getElementById('search_term');
	
	for (var i=0; i<searchFor.length; i++){
 		if (document.getElementById(searchFor[i]).checked == true)	{
			ajax_do('loadSearch.php?p=' + searchFor[i] + '&s=' + searchTerm.value);
		}
	}

}

function showLoading(element_id)	{
	if (document.getElementById(element_id))
		document.getElementById(element_id).style.display = "block";
}

function makeDate()	{
	document.agendaForm.date.value = (document.agendaForm.date.value + " " + document.agendaForm.myTime.value);	

}


function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}
//Sample usages

//disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv"


<!-- Dynamic Version by: Nannette Thacker -->
<!-- http://www.shiningstar.net -->
<!-- Original by :  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->
<!-- Use one function for multiple text areas on a page -->
<!-- Limit the number of characters per textarea -->
<!-- Begin
function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
	cntfield.value = maxlimit - field.value.length + " characters remaining";
}
//  End -->
function textCounter2(field,cntfield,maxlimit) {
	if (document.layers) {netscapecorrector=1;maxlimit+=1}
	if (document.all) {netscapecorrector=0}

	words = field.value.replace(/\s/g,' ');
	words=words.split(" ");
	
	if (words.length-1>=maxlimit) 	{ // if too long...trim it!
		var characterLimit = 0;
		for (i=0;i<maxlimit;i++) {
			characterLimit += parseInt(words[i].length) + 1;
		}
		//alert(characterLimit);
		field.value = field.value.substring(0, characterLimit);
	}
	// otherwise, update 'characters left' counter
	else	{
		cntfield.value = "Using " + words.length + " of " + maxlimit + " words";	
	}
	
}

// CREDITS:
// Word Counter
// by Urs Dudli and Peter Gehrig 
// Copyright (c) 2001 Peter Gehrig and Urs Dudli. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http://www.24fun.com & http://www.designerwiz.com
// info@24fun.com
// 3/5/2001

// IMPORTANT: 
// If you add this script to a script-library or script-archive 
// you have to add a link to http://www.24fun.com on the webpage 
// where the scrips will be running.

// CONFIGURATION:
// Go to www.24fun.com, open category 'utility' and download 
// the full-version of this script as ZIP-file containing
// step-by-step instructions and copy-and-paste installation for non-programmers.

// What's the maximum length of your textfield (number of words)

var maximalwords=5

// Do not edit the script below

	
function countwords(formName, inputName) {
	var words=""
	var content=""
	var corrector=0
	var text=document.formName.inputName.value;
	words=text.split(" ")
	if (words[words.length-1]=="") {corrector=1;}
	document.formName.inputName.value=(words.length)-corrector
	if (words.length-1>=maximalwords) {
		for (i=0;i<maximalwords-netscapecorrector;i++) {
			content+=words[i]+" "
			document.formName.inputName.value=content
		}
	}
	var timer=setTimeout("countwords()",100)
}
window.onload=countwords

/* EXTRA FUNCTIONS FOR HIDING */


function hideThis(objname)	{
	document.getElementById(objname).style.display = "none";
}
function showThis(objname)	{
	document.getElementById(objname).style.display = "block";
}
function toggleHide(objname)	{
	if (document.getElementById(objname).style.display == "none")
		showThis(objname);
	else
		hideThis(objname);
}

function toggleVisibility(objname)	{
	if (document.getElementById(objname).style.visibility == "hidden")
		document.getElementById(objname).style.visibility = "visible";
	else
		document.getElementById(objname).style.visibility = "hidden";
}



function uncheckAll(theform, elementName)	{
	
	var elementLength = theform.elementName.length;
	
	for (var i=0; i < theform.elementLength; i++) {
		alert(theform.elementName[i]);
		theform.elementName[i].checked = false;
	}//end for
	
}

function insertText(fromDiv, toDiv)	{
	
	var orgContent = document.getElementById(toDiv).innerHTML;
	document.getElementById(toDiv).innerHTML = document.getElementById(fromDiv).innerHTML;
	
	document.getElementById(fromDiv).innerHTML = orgContent;
	
}


function disableEndDate(elementName,prefix)	{
	
	var x1=document.getElementsByName(prefix + "month");
	var x2=document.getElementsByName(prefix + "year");
	
	if (document.getElementById(elementName).checked)	{
		x1[0].style.display = "none";
		x2[0].style.display = "none";	
	}
	else	{
		x1[0].style.display = "inline";
		x2[0].style.display = "inline";	
	}
	
}//end function disableEndDate




/********************


 Advanced search stuff


***********************/


function flipDirection(elementId, elementImage)	{
	
	if (document.getElementById(elementId) && document.getElementById(elementImage))	{
		
		var el = document.getElementById(elementId);
		var elimg = document.getElementById(elementImage)
		
		if (el.value == "ASC")	{
			el.value = "DESC";
			elimg.src = "images/sortdown.gif";
		}
		else	{
			el.value = "ASC";
			elimg.src = "images/sortup.gif";
		}
	}
		


}//end function flipDireciton



//setup up global timeout variable so we can kill it every time this function is called.   We dont want old data being processed if new query is coming in
var adv_search_timer;
function do_adv_search(search_page)	{
	
	//lets wait 0.5 seconds before doing the query, just to make sure user isn't doing some fast typeing (this seems to be only something that happens on FF.  Other browsers all accurately respresent onKeyUp, FF stalls
	if (!adv_search_timer)
		var adv_search_timer;
	
	clearTimeout(adv_search_timer);
	
	document.getElementById('loading_gif').style.display='block';
	adv_search_timer = setTimeout("document.frm_adv_" + search_page + "_search.submit();", 500);
}



//remove selected (current) item, and then set new item as current  (
function switchCurrent(currentClass, newCurrentID)	{
	

	var el = getElementsByClassName(currentClass);
	for (i=0; i < el.length; i++)	{
		el[i].className = 'none';
		
	}//end while
	
	document.getElementById(newCurrentID).className = 'adv_search_month_current';
			
		
}

function searchVenues_onClick()	{
	
	/*var getString = document.step3.searchVenues.value;
	getString = getString.toString();
	document.step3.newLocation[0].checked=true; 
	
	ajax_do('loadPage.php?p=searchVenue&id=searchResults&f='+getString);
	alert(getString);
	return false;	*/
}

function filterList(theform)
{
	var filterLabel = "filters[";
										
	$$("li.inviteList").each( function (el,j) {
		el.show();
	});
	
	var args = new Hash();
	
	for (var i=0; i < theform.elements.length; i++) {
		if ( theform.elements[i].name.indexOf("filters[") == 0 )
		{
			if ( theform.elements[i].checked ) 
			{
				var arg = theform.elements[i].name.substr( filterLabel.length, theform.elements[i].name.length - filterLabel.length - "][]".length );
				if ( args.get(arg) === undefined )
					args.set(arg,theform.elements[i].value);
				else
					args.set(arg,args.get(arg)+","+theform.elements[i].value);
			}
		}
	}
	
	args.keys().each( function (arg) {
		$$(".hidden_" + arg ).each( function (el) {
			
			var hide = true;
			el.value.split(",").each( function (val) {
				if ( args.get(arg).split(",").indexOf( val ) >= 0 )
				{
					hide = false;
					throw $break;
				}
			});

			if ( hide )
			{
				el.ancestors()[0].hide();
			}
		});		
	});
}


