function associate(obj, props) {
	var tobj = {};
	for(var x in props){
		if((typeof tobj[x] == "undefined") || (tobj[x] != props[x])){
			obj[x] = props[x];
		}
	}
	return obj; 
}

function extend(constructor, props) {
	for(var i=1, l=arguments.length; i<l; i++) {
		associate(constructor.prototype, arguments[i]);
	}
	return constructor; 
}

function byId(id){
	return (document.all) ? document.all[id] : document.getElementById(id);                                     
}

function byForms() {
	return (document.all) ? document.all.forms : document.forms;
}

function parseId(item) {
	return item.substring(3, item.length);
}

function byTag(parent, tagname) {
    if (document.all) {
        return document.all[parent].tags(tagname);
    }
    else {
        return parent.getElementsByTagName(tagname);
    }	 
}

function setInitialOpacity(element) {
	element.style.MozOpacity='100%';
}

function getAbsolutePosition(element) {
    var r = { x: element.offsetLeft, y: element.offsetTop };
    if (element.offsetParent) {
      var tmp = getAbsolutePosition(element.offsetParent);
      r.x += tmp.x;
      r.y += tmp.y;
    }
    return r;
}

function trim(s) {
	return rtrim(ltrim(s));
}

function ltrim(s) {
	var l=0;
	while(l < s.length && s[l] == ' ') {
		l++; 
	}
	return s.substring(l, s.length);
}

function rtrim(s) {
	var r=s.length -1;
	while(r > 0 && s[r] == ' ') {	
		r-=1;	
	}
	return s.substring(0, r+1);
}

function disableBubbling(e) {
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

function detectBrowser() {
	var browser=navigator.appName;
	if (browser=="Netscape") {
		return "NS";
	}
	else {
		return "IE";
	}
}

function isEscPressed(e) {
	var kC  = (window.event) ? event.keyCode : e.keyCode; 
	var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE;
	return kC==Esc;          		
}

function isEnterPressed(e) {
	var kC  = (window.event) ? event.keyCode : e.keyCode; 
	return kC==13;          		
}

function isDownKeyPressed(e) {
	var kC  = (window.event) ? event.keyCode : e.keyCode; 
	var downK = (window.event) ? 38 : e.DOM_VK_DOWN;
	return kC==downK;
}

function isUpKeyPressed(e) {
	var kC  = (window.event) ? event.keyCode : e.keyCode; 
	var upK = (window.event) ? 40 : e.DOM_VK_UP;
	return kC==upK;
}

function displaySelectedTag(parentNode) {
	var tabElements = parentNode.getElementsByTagName("li");
	for (var i=0; i<tabElements.length; i++) {
	    if(tabElements[i].className == "selected") {
	       displayElement(tabElements[i]);
	    }
	}
}

function hideElement(element) {
	if (element != null) {
		element.style.visibility = 'hidden';
		element.style.display = 'none';
	}
}

function attachTabListEvents(parentNode) {
	var tabElements = parentNode.getElementsByTagName("li");      
	for (var i=0; i<tabElements.length; i++) {
	    dojo.event.connect(tabElements[i], "onclick", this, "bringToFront");
	}   
}

function displayElement(element) {
	if (element != null) {
		element.style.visibility = "visible";
		element.style.display = "block";   
	}
}

function hideModuleBody(elementId) {
	byId(elementId).style.display = "none";
	byId(elementId).style.visibility = "hidden";
}

function closeErrorDialog() {
    byId("errorDialog").style.visibility = "hidden";
    byId("errorDialog").style.display = "none";
}


function positionElementCentre(ele) {
	var xOff = window.pageXOffset;
	var yOff = window.pageYOffset;
	if (browserCode == "NS") {
    	ele.style.top = yOff+window.innerHeight/2 - 50 + "px";
    	ele.style.left = xOff+(window.innerWidth/2)-150 + "px";
    }
    else if (browserCode == "IE") {
    	ele.style.left = document.body.offsetWidth/2 + "px";
    	ele.style.top = document.body.offsetHeight/2 + "px";
    }
}

function showErrorDialog(errorMessage) {
    byId("errorDialog").style.visibility = "visible";
    byId("errorDialog").style.display = "block";
    document.scrollTop = 0;
	positionElementCentre(byId("errorDialog"));
    byId("errorMessage").innerHTML = errorMessage;	
}

function isPenultimateIndex(index, size) {
	return (index == size-1) ? true : false;
}

function attachRowHighlight(evt) {
	var source = isIE ? evt.srcElement : evt.currentTarget;
	if (source != null) {
		source.style.backgroundColor = "#F5F185";
	}
}

function attachRowDeHighlight(evt) {
	var source = isIE ? evt.srcElement : evt.currentTarget;
	if (source != null) {
		source.style.backgroundColor = "";
	}
}

function attachTDHighlight(evt) {
	var source = evt.currentTarget;
	var children = byTag(source, "td");
	if (source != null) {
		for (var i=0; i< children.length; i++) {
			children[i].style.backgroundColor = "#F5F185";
		}		
	}
}

function attachTDDeHighlight(evt) {
	var source = evt.currentTarget;
	var children = byTag(source, "td");
	if (source != null) {
		for (var i=0; i< children.length; i++) {
			children[i].style.backgroundColor = "";
		}		
	}
}

function forEachDo (GenericCollectionObject, executableFunction, includeIndex) {	
	if (GenericCollectionObject != null && GenericCollectionObject.length > 0) {		
		for (var i=0; i<GenericCollectionObject.length; i++) {	
			var insertCollectionParam = includeIndex && (GenericCollectionObject[i].id != "");
			if (insertCollectionParam) {
				var codeToDo = executableFunction + "(" + ((insertCollectionParam) ? "byId(\""+GenericCollectionObject[i].id+"\")" : "");
				if(arguments.length > 3) {	
					if (insertCollectionParam) codeToDo += ", "; 	
					for (var j=3; j < arguments.length; j++) {
						switch (isString(arguments[j])) {
							case true: codeToDo += "\"" + arguments[j] + (!isPenultimateIndex(j, arguments.length) ? "\", " : "\"");
									   break;
						
							case false: codeToDo += arguments[j].toString() + (!isPenultimateIndex(j, arguments.length)) ? ", " : "";
							            break;
						}					
					}
					codeToDo += ");";
					eval(codeToDo);				
				}
				else {
					codeToDo += ");";
					eval(codeToDo);
				}					
			}
		}
	}
}

function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

function printpage() {
window.print();  
}
