/*

	2009 City of Waterloo
	
	General helper methods

*/

// Returns trimmed version of a given string
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

// Contains method for arrays
if ( !Array.prototype.contains ) {

    Array.prototype.contains = function(obj){

		var len = this.length;

		for (var i = 0; i < len; i++){
		
			if( this[i] == obj )
				return true;
		
		}

		return false;

	};

}

// ToString method for arrays
if ( !Array.prototype.ToString ) {

    Array.prototype.ToString = function(){

		var temp = "";

		for (var i = 0; i < this.length; i++){
			
			temp += this[i];
			
			if ( i != ( this.length - 1 ) )
				temp += ",";
				
		}

		return temp;

	};

}

// Used for entering and leaving search textbox so the user doesn't have to clear the 'Search' text
function Search_Enter(searchTextbox) {

	if ( searchTextbox.value.toLowerCase() == 'search' )
		searchTextbox.value = '';

}

function Search_Leave(searchTextbox) {

	var url = document.location.href;
	
	if( searchTextbox.value.trim() == '' )
	searchTextbox.value = 'Search';		

}

/*

	Hides inputs - This is used for Internet Explorer 6, as they show through the drop-down menu	
	
*/
function HideInputs() {
	
	var ver = navigator.appVersion;
	var isIE6 = ver.indexOf("MSIE 6.0") != -1;
	
	if ( isIE6 ) {
		
		var elements = document.getElementsByTagName("select");
		
		for (var i = 0; i < elements.length; i++) {
			elements[i].style.visibility = 'hidden';
		}		
		
	}

}

/*

	Shows inputs
	
*/
function ShowInputs() {

	var ver = navigator.appVersion;
	var isIE6 = ver.indexOf("MSIE 6.0") != -1;
	
	if ( isIE6 ) 
	{
		
		var elements = document.getElementsByTagName("select");
		
		for (var i = 0; i < elements.length; i++) 
		{
			elements[i].style.visibility = 'visible';
		}		
		
	}
	
}

		// election results pop up window //
		function openResultsWin()
		{
			dimx=1024;
			dimy=720;
			x=screen.width;
			y=screen.height;
			if(x<dimx)
			{
				dimx=x*0.90; dimy=0.90*x*dimy/dimx;
			} 
			px=(x-dimx)/2;py=(y-dimy)/2;
			var oNewWin = window.open('http://www.waterloo.ca/election2010/results.html', 'electionResultsWin', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width='+dimx+', height='+dimy+', top='+py+', left='+px);
			oNewWin.focus();
			if(!oNewWin)
			{
				alert('The election results window failed to open.  Please disable all pop-up blockers and try again.');
			}
			void(0);
		}
