	var ns4 = document.layers;
	var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) 
		||(navigator.userAgent.indexOf("Opera/5")!=-1);
	var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) 
		||(navigator.userAgent.indexOf("Opera/6")!=-1);
	var agt=navigator.userAgent.toLowerCase();
	var mac = (agt.indexOf("mac")!=-1);
	var ie = (agt.indexOf("msie") != -1); 
	var mac_ie = mac && ie;

function addElement(tag_name,txt,container,class_item,element)
{	
	txt=htmlspecialchars_decode(txt,'ENT_QUOTES');
	
	var newdiv = document.createElement(tag_name);
	if(class_item!=null) newdiv.className=class_item;
	if(txt)	newdiv.innerHTML =txt;
	if(!element)
		{
			var ni = document.getElementById(container);
			ni.appendChild(newdiv);
		}else{
			element.appendChild(newdiv);
		}
}

function addElementBefore(tag_name,txt,container,class_item,element,before)
{	
	txt=htmlspecialchars_decode(txt,'ENT_QUOTES');
	
	var newdiv = document.createElement(tag_name);
	if(class_item!=null) newdiv.className=class_item;
	if(txt)	newdiv.innerHTML =txt;
	if(!element)
		{
			var ni = document.getElementById(container);
			ni.insertBefore(newdiv,before);
		}else{
			element.insertBefore(newdiv,before);
		}
}

function removeElement(container,divNum) {
  var olddiv = container.childNodes[noChilds()-1];
  container.removeChild(olddiv);
}

function noChilds()
{
    var parent = document.getElementById('container');
    var childCount = parent.getElementsByTagName('DIV').length;
	return childCount;
}

function newLine()
{
	var parent = document.getElementById('container');
	var newP = document.createElement('br');
	parent.appendChild(newP);
}

function removeAllChildNodes(node) {
	if (node && node.hasChildNodes && node.removeChild) {
		while (node.hasChildNodes()) {
			node.removeChild(node.firstChild);
			}
		}
}


function htmlspecialchars_decode(string, quote_style) {

   string = string.toString();
  
   string = string.replace(/&amp;/g, '&');
   string = string.replace(/&lt;/g, '<');
   string = string.replace(/&gt;/g, '>');
  
   if (quote_style == 'ENT_QUOTES') {
       string = string.replace(/&quot;/g, '"');
       string = string.replace(/&#039;/g, '\'');
   } else if (quote_style != 'ENT_NOQUOTES') {
       string = string.replace(/&quot;/g, '"');
   }
  
   return string;
}

var notWhitespace = /\S/;
function cleanWhitespace(node) {
  for (var x = 0; x < node.childNodes.length; x++) {
    var childNode = node.childNodes[x];
    if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
// that is, if it's a whitespace text node
      node.removeChild(node.childNodes[x])
      x--
    }
    if (childNode.nodeType == 1) {
// elements can have text child nodes of their own
      cleanWhitespace(childNode)
    }
  }
}

function getElementHeight(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function findPosition(obj) {
	var curleft = curtop = 0;
	
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function getFlashMovieObject(movieName){
	if (window.document[movieName]){
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
	if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName];
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{
		return document.getElementById(movieName);
	}
}


/* <![CDATA[ */

/* Javascript word wrap,
   Em Tonkin Aug 2006 */

function dowrap(mystring, mycutchars){
	// Here we do the actual word wrap
	// Set the NUMBER OF CHARS TO WORD WRAP HERE
	var howmanychars=40; // hard limit for wordwrap
	var margin=7; // look within this many chars of the word wrap
	if(mycutchars == undefined){
		var spacerchar="<br/>"; // you could also just make this " "; - cut by putting a space in
	} else {
		spacerchar=mycutchars;
	}
	var myreturnstring;
	var mycutlocation=howmanychars;
	var usecutchar=true;
	if(mystring.length>howmanychars){
		// try to cut about howmanychars off the beginning. Then call this function with the rest
		 
		// If we're going to be clever, let's see if we can find a preferred cutting character within n chars of the spacerchar
		// preferred cutting chars: "/" and "-"
		//if(mystring.charAt(howmanychars) == '/' || mystring.charAt(howmanychars) == '-'){

		// Find a / or a - within n chars, or just cut it straight.
		for(var count=howmanychars-margin;count<howmanychars;count++){
			if(mystring.charAt(count) == '/' || mystring.charAt(count)== '-'){
				mycutlocation= count;
				usecutchar=true;
			}
			if(mystring.charAt(count)==' ' || mystring.charAt(count)== ','){
				mycutlocation= count;
				usecutchar=false;
			}
		}
		if(usecutchar){	
			myreturnstring= mystring.substr(0, mycutlocation+1)+ spacerchar;
		} else {
			myreturnstring= mystring.substr(0, mycutlocation+1);

		}
		myreturnstring= myreturnstring + dowrap(mystring.substr(mycutlocation+1,mystring.length), spacerchar);

		
		
	} else {
		myreturnstring=mystring;
	}

	return myreturnstring;
}

function wordwrap(mytype,mystring, mycutchars){
	// mytype should be the tagname of the element you want to word wrap... (eg'span')
	// mystring should be the substring at the beginning of each id (eg urlspan)
	// search through for the element tagname we gave (mytype)
	if (document.getElementsByTagName)  // if we can't get elements by tagname, give up
		{
			var objAnchors = document.getElementsByTagName(mytype);
			for (var iCounter=0; iCounter<objAnchors.length; iCounter++) {
				var myid;
				myid=objAnchors[iCounter].id;
				if(myid.substr(0, mystring.length)==mystring){
					/* If that node isn't just a span or something, it might have child nodes */
					var mycontent = objAnchors[iCounter].innerHTML; // get current content 
					var mynewcontent=dowrap(mycontent, mycutchars); // Get new wrapped content
					objAnchors[iCounter].innerHTML=mynewcontent;	// Replace the original with the wrapped version
				}
			}
		}
	}
/* ]]> */


