var isIE6 = navigator.userAgent.indexOf("MSIE 6.0") != -1;

function tmo_onload() {
	generateGenericIdLinks();
	generatePopouts();
}

//addEvent(window,'load',new Function('tmo_onload()'));

/* Global Functions */
function generateGenericIdLinks(startAtElement) {
	var allA = (startAtElement != null) ? getAllElements(startAtElement, 'a') : getAllElements(document, 'a');
	if (allA != null) {
		for (var i=0; i<allA.length; i++) {
			var nextA = allA[i];
			for (linkType in fadeContentWidths) {
				if (nextA.className.indexOf(linkType + "-link") != -1) {
					var qs = nextA.href.substring(nextA.href.indexOf("?")+1);
					if (qs.indexOf("cat=") != -1) {
						qs = "&" + qs.substring(qs.indexOf("cat="));
					} else if (qs.indexOf("id=") != -1) {
						qs = qs.substring(qs.indexOf("id=") + 3);
					} else {
						qs = '';
					}
					if (qs != '') {
						nextA.genericid = qs;
						nextA.linktype = linkType;
						nextA.onclick = function() {
							setGenericId(this.genericid);
							showFade(this.linktype);
							return false;
						}
					}
					continue;
				}
			}
		}
	}
}

function getAllElements(parentEl, elType) {
	if (document.getElementsByTagName) {
		return parentEl.getElementsByTagName(elType);
	} else if (document.all) {
		return parentEl.all[elType];
	}
	return null;
}
function getSingleElement(elId) {
	if (document.getElementById) {
		return document.getElementById(elId);
	} else if (document.all) {
		return document.all(elId);
	}
	return null;
}

function generatePopouts() {
	var allDiv = getAllElements(document, 'div');
	if (allDiv != null) {
		var done = false;
		for (var i=0; i<allDiv.length; i++) {
			var div = allDiv[i];
			if (div.className.indexOf("expandable-group") != -1) {
				var allHeader = getAllElements(div, 'h3');
				var allBlocks = getAllElements(div, 'div');

				if (allHeader != null && allBlocks != null) {
					for (var h=0; h<allHeader.length; h++) {
						var header = allHeader[h];
						header.onclick = function() {
							var sib = getSingleElement(this.blockid);
							var disp = sib.style.display;
							sib.style.display = (disp == 'block') ? 'none' : 'block';
							if (disp == 'none') {
								if (this.textContent != null) {
									this.textContent = this.textContent.replace("+", "-");
								} else {
									this.innerText = this.innerText.replace("+", "-");
								}
							} else {
								if (this.textContent != null) {
									this.textContent = this.textContent.replace("-", "+");
								} else {
									this.innerText = this.innerText.replace("-", "+");
								}
							}
						}
						header.blockid = 'BlockId' + i + '_' + h;

						header.style.cursor = 'pointer';
						if (header.textContent != null) {
							header.textContent = "+ " + header.textContent;
						} else {
							header.innerText = "+ " + header.innerText;
						}

						var block = allBlocks[h];
						block.id = 'BlockId' + i + '_' + h;
						block.style.display = 'none';
					}
				}
			}
		}
	}
}

/**
 * these three method are for feedback textarea 
 */ 
function isMaxlength(obj){ 
 var mlen=parseInt(obj.getAttribute("maxlength")); 
 if (obj.getAttribute && obj.value.length>mlen){  
  obj.value=obj.value.substring(0,mlen-1) 
 }
}
 
function imposeMaxLength(obj){  
 var mlen=parseInt(obj.getAttribute("maxlength"));  
 return (obj.value.length <= mlen);
}

function cleartextarea(id){
id.value="";
id.style.color="black";
}
 