
function showMap(url)
{
	var mapWin = window.open(url, 'mapWin', 'width=350,height=350,status=no,scrollbars=no,resizable=no,toolbar=no,menubar=no');
}

function openWindow(url)
{
	var extWin = window.open(url, 'extWin', 'dialogWidth=575px;dialogHeight=570px;scrollbars=yes,resizable=yes;help=no;unadorned=yes');
}

function selectItem(formName, item, action)
{		
	alert('Not Implemented');
}

function hideSlideshow()
{

	var slideshow = document.getElementById('slideshowbox');
	if(slideshow)
	{
		slideshow.style.display == 'none' ? slideshow.style.display = '': slideshow.style.display = 'none';
	}
}

function selectItem2(formName, item, action)
{		
	var form = document.forms[formName];
	form.itemId.value = item;
	form.action = action;
	form.submit();
}




/*
 * Returns the element with the supplied id
 */
function getElement(id)
{
	var elem;
	if (document.all) 
	{
    	elem = document.all(id); 
    } 
    else if (document.getElementById) 
    {
        elem = document.getElementById(id);
    }
    return elem
}

/*
 * Appends the supplied function to the end 
 * of the documents onload event 
 */ 
function addLoadEvent(func) 
{
	var oldonload = window.onload;
	var initfunction;
	if (typeof oldonload != 'function') 
  	{
    	initfunction = func;
  	} 
  	else 
  	{
    	initfunction = function() 
    	{
	      	if (oldonload) 
	      	{
	        	oldonload();
	      	}
	      	func();
    	}
  	}
	var browserName=navigator.appName; // Get the Browser Name
	if(browserName=="Microsoft Internet Explorer") // For IE
	{
		window.onload=initfunction; // Call init function in IE
	}
	else
	{
		if (document.addEventListener) // For Firefox
		{
			document.addEventListener("DOMContentLoaded", initfunction, false); // Call init function in Firefox
		}
	} 
}

/*
 * Attaches the event listener for the event to the object
 */
function addEventHandler(obj, evType, fn)
{
  	if (obj.addEventListener)
	{
    	obj.addEventListener(evType, fn, false);
    	//return true;
  	}
  	else if (obj.attachEvent)
  	{
  		var r = obj.attachEvent("on" + evType, fn);
    	return r;
  	}
  	else
  	{
    	return false;
  	}
}
				
function fireEvent(element, event)
{
	if(element.fireEvent)//IE
	{
		return element.fireEvent('on'+event,evt);
	}
	else if(document.createEvent)//Gecko based browsers
	{
		var evt = document.createEvent('HTMLEvents');
		if(evt.initEvent)
		{
			evt.initEvent(event, true, true);
		}
		if(element.dispatchEvent)
		{
			return element.dispatchEvent(evt);
		} 
	}
	/*
    if (document.createEventObject)
    {
        // dispatch for IE
        var evt = document.createEventObject();
        return element.fireEvent('on'+event,evt)
    }
    else
    {
        // dispatch for firefox + others
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true ); // event type,bubbling,cancelable
        return !element.dispatchEvent(evt);
    }
    */
}

/*
 * Returns true if the object is null
 */ 
function isNull(object)
{
	return (typeof object == 'undefined' || object == null);
}

/*
 * Returns the attribute "class" attached to the object
 */
function getClassAttribute(object) 
{
	if(window.addEventListener) // Mozilla, Netscape, Firefox
	{	
		var node = object.getAttributeNode("class");
		if(node && node.value)
		{
			return node.value;
		}
   	}
   	else //IE
   	{
        return object.getAttribute("className");
   	}  	
}

/* 
 * Removes repeated elements from the array 
 */
 function getUniqueArray(array)
 {
    var a = [],i;
    array.sort();
    for(i = 0; i < array.length; i++)
    {
        if(array[i] !== array[i+1] && array[i] !== '')
        {
        	//	alert('unique:' + array[i]);	
        	a[a.length] = array[i];
    	}
    }
	return a;
}

/*
 * Debug code - Writes out contents of supplied array
 * to an alert box
 */
function writeArray(array)
{
	var msg = "";
	for(var i = 0; i < array.length ; i++)
	{
		msg += array[i] + "\n";
	}
	alert(msg);
}

/*
 * Debug code - attach to window.onerror to get some kind 
 * of helpful message in IE
 */
function showError(err, file, line) 
{
	alert('The following error occured: ' + err + '\n' +
	'In file: ' + file + '\n' +
	'At line: ' + line);
	return true;
}

function checkAll(chkBoxName, checkBox)
{
	var checkBoxes = document.getElementsByName(chkBoxName);
	for(var i=0;i<checkBoxes.length;i++)
	{
		checkBoxes[i].checked = checkBox.checked;
	}
}

function isChecked(chkBoxName)
{
	var checkBoxes = document.getElementsByName(chkBoxName);
	var count = 0;
	if(checkBoxes)
	{
		for(var i=0;i<checkBoxes.length;i++)
		{
			if(checkBoxes[i].checked)
			{
				count++;
			}
		}
	}
	return count > 0;
}

function showDiv(prefix, divId, hideOther)
{
	var divs = document.getElementsByTagName('div'); 
	
	
	for(var i = 0; i < divs.length; i++)
	{
		if(divs[i].id == prefix + divId)
		{
			divs[i].style.display = 'block';
		}
		else
		{
			if(hideOther);
			{
				var prefixPosition = divs[i].id.indexOf(prefix);
				if(prefixPosition == 0)
				{
					divs[i].style.display = 'none';
				}
			}
		}
	}
}
function swapNodes2(item1,item2) 
{
	// We need a clone of the node we want to swap
	var itemtmp = item1.cloneNode(1);

	// We also need the parentNodes of the items we are going to swap.
	var parent = item1.parentNode;
	var parent2 = item2.parentNode; 

	// First replace the second node with the copy of the first node
	// which returns a the new node
	item2 = parent2.replaceChild(itemtmp,item2);

	//Then we need to replace the first node with the new second node
	parent.replaceChild(item2,item1);

	// And finally replace the first item with it's copy so that we
	// still use the old nodes but in the new order. This is the reason
	// we don't need to update our Behaviours since we still have
	// the same nodes.
	parent2.replaceChild(item1,itemtmp);

	// Free up some memory, we don't want unused nodes in our document.
	itemtmp = null;
}
	
function swapNodes(item1,item2) 
{
	var browserName = navigator.appName;
	if (browserName == "Microsoft Internet Explorer") 
	{
		// ie
		item1.swapNode(item2);
	}
	else
	{
		// We need a clone of the node we want to swap
		var itemtmp = item1.cloneNode(1);
	
		// We also need the parentNode of the items we are going to swap.
		var parent = item1.parentNode;
		
		//parent = parent.parentNode;
		alert('parent:' + parent );
		// First replace the second node with the copy of the first node
		// which returns a the new node
		item2 = parent.replaceChild(itemtmp, item2);
	
		//Then we need to replace the first node with the new second node
		parent.replaceChild(item2, item1);
	
		// And finally replace the first item with it's copy so that we
		// still use the old nodes but in the new order. This is the reason
		// we don't need to update our Behaviours since we still have 	
		// the same nodes.
		parent.replaceChild(item1, itemtmp);
		
		// Free up some memory, we don't want unused nodes in our document.
		itemtmp = null;
	}
}

function getParent(obj, tagType)
{
	if(tagType)
	{
		// if it's not the tag we are expecting.. try the parent
		while ( obj )
		{
			if ( obj.tagName == tagType )
			{
				break;
			}
			obj = obj.parentNode;
		}
	}
	return obj;
}
// IE Dropdown fix
sfHover = function() 
{    
	var dropdown =  document.getElementById("dropDown");
	if(dropdown)
	{
		var sfEls = dropdown.getElementsByTagName("LI");     
		for (var i=0; i < sfEls.length; i++) 
		{        
			sfEls[i].onmouseover=function() 
			{             
				this.className+=" sfhover";         
			}         
			sfEls[i].onmouseout=function() 
			{             
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");         
			}     
		} 
	}
} 
if (window.attachEvent) window.attachEvent("onload", sfHover); 

function relpaceClass(object, newAttribute)
{
	if(window.addEventListener) // Mozilla, Netscape, Firefox
	{	
		var node = object.getAttributeNode("class");
		if(node)
		{
			node.value = newAttribute;
		}
		else
		{
			node = object.setAttribute("class", newAttribute);
		}
	}
   	else //IE
   	{
        object.setAttribute("className", newAttribute, 1); 
   	} 
}

function addClass(object, newAttribute)
{
	if(window.addEventListener) // Mozilla, Netscape, Firefox
	{	
		var node = object.getAttributeNode("class");
		if(node && node.value)
		{
			var existing =  node.value.indexOf(newAttribute) > -1;
			if(!existing)
			{
				node.value += " " + newAttribute;
			}
		}
		else
		{
			node = object.setAttribute("class", newAttribute);
		}
	}
   	else //IE
   	{
        object.setAttribute("className", newAttribute, 1); 
   	} 
}