
function maxArray( arr ) {
		 // this function calculates the maximum value in the associative array
		 var max = 0;
		 for(var i in arr){
  		     if (arr[i] > max)
  		     		 		 max = arr[i];
  		 }
  		 return max;
}

function minArray( arr ) {
		 // this function calculates the minimum value in the associative array
		 var min;
		 var count = 0;
		 for(var i in arr){
		 		 // initialize minimum value with first value of associative array
		 		 if (count==0)
		 		 		 min = arr[i];
		 		 if (arr[i] < min)
  		     		 		 min = arr[i];
  		     		 count++;
  		 }
  		 return min;
}

function drawTagCloud(map, maxStyle) {
		 // this function draws the tag cloud using the associative javascript array generated by the Notes view
		 // calculate the maximum entries in the cloud. if not found, no tags are found
		 var maxEntries = maxArray(map);
		 if (maxEntries==0) {
		 		 document.write('No tags found');
		 }
		 
		 //		 calculate the minimum entries in the cloud
		 var minEntries = minArray(map);
		 
		 // calculate the range
		 var range = maxEntries - minEntries;
		 if (range <= 0)
		 		 range = 1; 
		 
		 // loop through the tag map to draw each tag.
		 for(var tag in map){
  		 		 drawTag(tag, map[tag], minEntries, maxEntries, maxStyle,range);
  		 }
}

function drawTag(tag, count, min, max, maxStyle,range) {
  sizeTag = Math.round((((maxStyle-1)/(range))*count) +(1*max-maxStyle*min)/(range));
  document.write('<a href="archive?openview&type=Category&key='+tag+'" class="tag' + sizeTag + '">' + tag + '</a> ');
}
function RandomPhoto() {
document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="150" HEIGHT="150" id="RandomPicture" ALIGN="">');
document.write('<PARAM NAME=movie VALUE="http://www.ubsuccessful.com/blogsphere.nsf/RandomPicture.swf">');
document.write('<PARAM NAME=loop VALUE=false>');
document.write('<PARAM NAME=quality VALUE=high>');
document.write('<PARAM NAME=wmode VALUE=transparent> ');
document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF> ');
document.write('<EMBED src="http://www.ubsuccessful.com/blogsphere.nsf/RandomPicture.swf" loop=false quality=high wmode=transparent bgcolor=#FFFFFF  WIDTH="150" HEIGHT="150" NAME="RandomPicture" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
document.write('</EMBED></OBJECT>');
}
function RunBlogSearch()
{
var form = document.BlogSearch;
var query = form.SearchQuery.value;

	if( query == '' ){
		alert('Sorry, you must enter a search term.');
		form.SearchQuery.focus();
	}
	else{
	window.location.href = form.SearchPath.value + '/SearchResults?OpenNavigator&Query='+query;
	}
}
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+"; 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) {
	createPollCookie(name,"",-1);
}
