function insertAtCursor(oCtrl,sVal){if(document.selection){oCtrl.focus();sel=document.selection.createRange();sel.text=sVal;}else if (oCtrl.selectionStart || oCtrl.selectionStart == '0'){var startPos = oCtrl.selectionStart;var endPos = oCtrl.selectionEnd;oCtrl.value = oCtrl.value.substring(0, startPos) + sVal + oCtrl.value.substring(endPos, oCtrl.value.length);}else{oCtrl.value += sVal;}}
function addLoadEvent(func){var oldonload = window.onload;if (typeof window.onload != 'function'){window.onload = func;}else{window.onload = function(){oldonload();func();}}}

// Matt Kruse's hasClass, with slight modification Determine if an object or class string contains a given class.
function hasClass (obj, className) {if(typeof obj === 'undefined' || obj===null || !RegExp){return false;}var re=new RegExp("(^|\\s)" + className + "(\\s|$)");if(typeof(obj)==="string"){return re.test(obj);}else if(typeof(obj)==="object" && obj.className){return re.test(obj.className);}return false;}

// The following three functions are used for adding dynamic table barring/striping/greenbar and mouseover highlighting
// On the page where you want the barring add a call to addLoadEvent(stripeTables);
// If you want the rows to be hilighted onmouseover add a call to addLoadEvent(highlightRows);
// and ensure your table has thead and tbody tags defined, finally your style sheet needs - 
//	tr.odd	{background:[yourcolourgoeshere];}
//	tr.highlight	{background:[yourcolourgoeshere];}
function addClass(element,value){if(!element.className){element.className=value;}else{newClassName=element.className;newClassName+=" ";newClassName+=value;element.className=newClassName;}}
function removeClassName(oElm, strClassName){var oClassToRemove = new RegExp((strClassName + "\s?"), "i");oElm.className = oElm.className.replace(oClassToRemove, "").replace(/^\s?|\s?$/g, "");}
function stripeTables(){var tables=document.getElementsByTagName("table");for(var m=0;m<tables.length;m++){if(tables[m].className.indexOf("barme") != -1){var tbodies=tables[m].getElementsByTagName("tbody");for(var i=0;i<tbodies.length;i++){var odd=true;var rows=tbodies[i].getElementsByTagName("tr");for(var j=0;j<rows.length;j++){if(odd==false){odd=true;}else{addClass(rows[j],"odd");odd=false;}}}}}}
function highlightRows(){if(!document.getElementsByTagName)return false;var tables=document.getElementsByTagName("table");for(var m=0;m<tables.length;m++){if(tables[m].className.indexOf("barme") != -1){var tbodies=tables[m].getElementsByTagName("tbody");for(var j=0;j<tbodies.length;j++){var rows=tbodies[j].getElementsByTagName("tr");for(var i=0;i<rows.length;i++){rows[i].oldClassName=rows[i].className;rows[i].onmouseover=function(){if(this.className.indexOf("selected") == -1){addClass(this,"highlight");}};rows[i].onmouseout=function(){if(this.className.indexOf("selected")==-1){this.className=this.oldClassName;}}}}}}}

// Check which DOM is available and assign obj and style properties to element
function getObj(name){if(document.getElementById){this.obj=document.getElementById(name);this.style=document.getElementById(name).style;}else if(document.all){this.obj=document.all[name];this.style=document.all[name].style;}else if(document.layers){this.obj=document.layers[name];this.style=document.layers[name];}}
// used by the menu to handle image rollovers
function GetOverImage(id,image){var element = new getObj(id);element.style.backgroundImage = "url("+image+")";}

function pad(number, length){var str=""+number;while(str.length<length){str='0'+str;}return str;} 
function setCaretToEnd(el){if(el.createTextRange){var v=el.value,r=el.createTextRange();r.moveStart('character',v.length);r.select();}}

function clearDDLOptions(el,keepFirstOpt) {
	el.options.length=(keepFirstOpt===false)?0:1;
}

function addToDDLOptionList(el, OptionValue, OptionText) {
	// Add option to the bottom of the list
	el[el.length] = new Option(OptionText, OptionValue);
}

function truncate(strIn,iMax){
	if(strIn){
		if(strIn.length>iMax){
			if(strIn.charAt(iMax) !== " "){
				 var t = iMax;
				 while(strIn.charAt(t) !== " "){t--;}
				 strIn=strIn.substring(0, t);
			}else{
				strIn=strIn.substring(0, iMax);
			}
			strIn=trim(strIn)+"...";
		}
	}
	return strIn;
}

function setAccordionWidgitStatus(sCookieKeyName,el,sOpt){
	var bOn=hasClass(el,"selected"),
		sCookieName="AccordionWidgitStatus",
		sOpenLst=GetCookie(sCookieName,sCookieKeyName);
	//alert('On: '+bOn+'\nAccordionWidgitStatus: '+sOpenLst);
	if(bOn===false){
		// Open; add the opt to the list
		if(sOpenLst.length>0){sOpenLst+="|";}
		sOpenLst+=sOpt;
	}else{
		// Close; remove the opt from the list
		//listFind(list,value,delimiter,ignoreCase)
		var idx=listFind(sOpenLst,sOpt,"|",true),arItems=sOpenLst.split("|");
		if(idx >0){
			idx=idx-1;
			arItems.splice(idx,1);
			sOpenLst=arItems.join("|");
			//alert("Removed: "+sOpt+"\nOpen list: "+sOpenLst);
		}
		//alert(idx);
	}
	//SetCookie2(cookie_name,key_name,value,expires)
	SetCookie2(sCookieName,sCookieKeyName,sOpenLst)
}

// Show More Show Less
// Requires config variable mlConfig e.g. var mlConfig={showMore:"aMore",suppInfo:"supplementalInfo"};
function mlShowHide(a,idx){
	//alert("In show hide element: "+a+" idx: "+idx);
	var elMore=document.getElementById(mlConfig.showMore+idx),elSuppInfo=document.getElementById(mlConfig.suppInfo+idx),more="none",less="inline";
	if(!elMore || !elSuppInfo){return true;}

	if(a===mlConfig.suppInfo){more="inline";less="none";}

	elMore.style.display=more;
	elSuppInfo.style.display=less;
	return true;
}
		    

