//-------------------------------------------------------------------------------
function urlEncode( str ) {   
	return encodeURIComponent( str ).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A');   
} //urlEncode

//-------------------------------------------------------------------------------
function urlDecode( str ) {   
	return decodeURIComponent( str.replace( /%E9/g, 'e' ) );   
} //urlDecode

//-------------------------------------------------------------------------------
var setCookie = function( name, value, expireDays ) {
	var expire=new Date();
	expire.setDate( expire.getDate() + expireDays );
	document.cookie = name + "=" + encodeURIComponent( value ) + ( ( expireDays == 0 ) ? "" : ";expires=" + expire.toUTCString() );	
}//setCookie

//-------------------------------------------------------------------------------
var getCookie = function( name ) {
	if( document.cookie.length > 0 ) {
		start = document.cookie.indexOf( name + "=" );
		if( start != -1 ) {
			start = start + name.length + 1;
			end   = document.cookie.indexOf( ";", start );
			if( end == -1 ) {
				end = document.cookie.length;
			}
			return decodeURIComponent( document.cookie.substring( start, end ) );
		}
	}
	return "";
}//getCookie
	
//-------------------------------------------------------------------------------
var pluralize = function( count, word ) {
	return ( count + ' ' + ( count == 1 ? word : word + 's' ) );	
}//pluralize
	
//-------------------------------------------------------------------------------
var durationLength = function( numSeconds, showSeconds, shortFormat ) {
	var result = '';
	var total  = 0;
	
	if( shortFormat == null ) {
		shortFormat = true;
	}
	
	//hours
	var value = Math.floor( numSeconds / (60*60) ); 
	if( value > 0 ) {
		result = value;
		
		if( shortFormat ) {
			result += ' hr'; 	
		}
		else {
			result += ( value == 1 ? ' hour' : ' hours' );
		}
		
		total  = value * 60*60;
	}
	
	//minutes
	value = Math.floor( ( numSeconds - total ) / 60 ); 
	if( value > 0 || result.length > 0 ) {
		if( result.length > 0 ) {
			result += ' ';
		}
		result += value;
		
		if( shortFormat ) {
			result += ' min'; 	
		}
		else {
			result += ( value == 1 ? ' minute' : ' minutes' );
		}

		total  += value * 60;
	}
	
	//seconds
	if( showSeconds != null && showSeconds ) {
		value = numSeconds - total; 
		if( value > 0 ) {
			if( result.length > 0 ) {
				result += ' ';
			}
			result += value;
			
			if( shortFormat ) {
				result += ' sec'; 	
			}
			else {
				result += ( value == 1 ? ' second' : ' seconds' );
			}			
		}	
	}
	
	return result;	
}//durationLength
