/* Copyright (C) 2007 - 2009, Incode Systems, Inc. and John L. Lawler */ 

var dialogueOffsetX=0;var dialogueOffsetY=0;function DisableInput(s){s.disabled=true;s.className+=" readonly";};function DisableSelectInsertHidden(s){if(s.parentNode.firstChild.type!="hidden"){var i=document.createElement("input");i.type="hidden";i.value=s.value;i.name=s.name;s.parentNode.insertBefore(i,s);};s.name="";DisableInput(s);};function getCellValue(c){if(c.nodeType==3)return c.parentNode.innerHTML;else if(c.nodeName=="SELECT")return ReturnSelectedChildNode(c).innerHTML;else if(c.nodeType==1&&c.value)return c.value;else return null;};function getElementByIdInChildNodes(p,id,depth){var result;if(depth==null)depth=1;if(depth==0)if(p.id&&p.id==id)return p;else return null;else for(var c=0;c<p.childNodes.length;c++){result=getElementByIdInChildNodes(p.childNodes[c],id,(depth-1));if(result)return result;};return null;};function getElementByIdUnderParent(p,id){var result;if(p.id&&p.id==id)return p;else{var kids=p.childNodes;for(var c=0;c<kids.length;c++){result=getElementByIdUnderParent(kids[c],id);if(result)return result;}};return null;};function GetFirstTextElementsValue(elem){if(elem.nodeType==null)return elem;var el=elem;var eC=elem.firstChild;while(eC!=null&&eC.nodeType!=3){el=eC;eC=el.firstChild;};return el.innerHTML;};function getSelectOptionByHTML(sF,search){for(var i=0;i<sF.options.length;i++){if(sF.options[i].innerHTML==search)return sF.options[i];};return null;};function getSelectOptionByValue(sF,search){for(var i=0;i<sF.options.length;i++){if(sF.options[i].value==search)return sF.options[i];};return null;};function getSelectedOptionHTML(sF){return sF.options[sF.selectedIndex].innerHTML;};function setSelectOptionByHTML(sF,search){var opt=getSelectOptionByHTML(sF,search);if(opt)opt.selected=true;};function setSelectOptionByValue(sF,search){var opt=getSelectOptionByValue(sF,search);if(opt)opt.selected=true;};function insertAfter(parent,node,referenceNode){parent.insertBefore(node,referenceNode.nextSibling);};function MakeReadOnlyInput(s){s.readOnly=true;s.className+=" readonly";};function MakeReadWriteInput(s){s.readOnly=false;s.className=s.className.replace(/readonly/g,"");};function MatchSelectsBySelectedValue(src,dest){if(src.options.length==0||src.disabled)return;var tv=src.options[src.selectedIndex].value;var result=SearchGeneralArray(dest.options,tv,function(o){return o.value;});if(result!=-1)dest.selectedIndex=result;};function removeAllChildren(parent){if(parent.firstChild)while(parent.firstChild)parent.removeChild(parent.firstChild);};function removeElements(elArray){var el;for(var i=0;i<elArray.length;i++){el=gEBI(elArray[i]);removeNodeIfExists(el);}};function SetDateInputFormats(ar,action){var el;for(var i=0;i<ar.length;i++){el=gEBI(ar[i]);if(el.value==DateFormatISO||el.value=="")if(action=="set"||(action!="clear"&&el.value=="")){el.value=DateFormatISO;el.style.color="gray";}else if(action=="clear"||(action!="set"&&el.value==DateFormatISO)){el.value="";el.style.color="";}}};function setSelectAndDisable(sF,value){setSelectOptionByValue(sF,value);sF.disabled=true;};function setVariableInURL(url,variable,value){var startIndex=url.indexOf(variable);if(startIndex>-1){var reInMiddle=new RegExp(variable+"=[^&]*&","g");var reAtEnd=new RegExp("&"+variable+"=[^&]*$","g");if(url.search(reInMiddle)>-1)url=url.replace(reInMiddle,"");else if(url.search(reAtEnd)>-1)url=url.replace(reAtEnd,"");};url=url+"&"+variable+"="+encodeURI(value).replace(/&/,"%26");return url;};function CreatePopup(puContainerDiv,title,content,attributes){var puTitleDiv=document.createElement("div");var puContentDiv=document.createElement("div");var puButtonsDiv=document.createElement("div");var buttonOk=document.createElement("button");var windowClass=new Object();windowClass.Container=puContainerDiv;windowClass.visible=true;windowClass.hide=function(){this.Container.style.display="none";this.visible=false;if(hasSelectBug())showAllSelects();};windowClass.show=function(){if(hasSelectBug())hideAllSelects();this.Container.style.display="block";this.visible=true;if(this.focusControl)this.focusControl.focus();};if(attributes==null)attributes={};puContainerDiv.className="MsgPopup "+((attributes.divStyle!=null)?attributes.divStyle:"default")+" "+((attributes.divStyle!=null)?attributes.divStyle:"default")+"Border";puContainerDiv.style.padding="0";puContainerDiv.style.opacity=".90";puTitleDiv.className=((attributes.divStyle!=null)?attributes.divStyle:"default")+"Title";puTitleDiv.style.paddingLeft="3px";puTitleDiv.style.paddingBottom="2px";puTitleDiv.innerHTML=title;puContainerDiv.appendChild(puTitleDiv);puContentDiv.style.padding="5px";puContentDiv.style.overflow="auto";if(attributes.noHr!=true)puContentDiv.innerHTML=content.replace(/\n/g,"<hr>");else puContentDiv.innerHTML=content;puContainerDiv.appendChild(puContentDiv);if(!attributes.controls&&attributes.noControls!=true){attributes.controls=[{type:"button",content:"Ok",focus:true,style:{width:"50px"},onclick:function(){if(attributes.modal)modalBackgroundRemove();windowClass.hide();if(attributes.functionAfterOk)attributes.functionAfterOk();return false;}}];};var newControl;for(var c=0;c<attributes.controls.length;c++){newControl=document.createElement(attributes.controls[c].type);if(attributes.controls[c].type=="button"){newControl.innerHTML=attributes.controls[c].content;if(attributes.controls[c].style&&attributes.controls[c].style.width){newControl.style.width=attributes.controls[c].style.width;};if(attributes.controls[c].onclick)newControl.onclick=attributes.controls[c].onclick;if(attributes.controls[c].focus)windowClass.focusControl=newControl;};puButtonsDiv.appendChild(newControl);};puButtonsDiv.style.textAlign="center";puButtonsDiv.style.paddingBottom="5px";puContainerDiv.appendChild(puButtonsDiv);if(attributes.width!=null)puContainerDiv.style.width=attributes.width+"px";if(attributes.height!=null)puContainerDiv.style.height=attributes.height+"px";if(attributes.left!=null)puContainerDiv.style.left=attributes.left+"px";if(attributes.top!=null)puContainerDiv.style.top=attributes.top+"px";if(attributes.functionBefore)attributes.functionBefore();if(attributes.modal){modalBackgroundAdd();};if(hasSelectBug())hideAllSelects();document.body.appendChild(puContainerDiv);if(puContainerDiv.clientHeight>(getViewportHeight()-100))puContentDiv.style.height=(getViewportHeight()-100)+"px";if(puContainerDiv.clientWidth>(getViewportWidth()-20))puContainerDiv.style.width=(getViewportWidth()-20)+"px";if(attributes.left==null){puContainerDiv.style.left=(getViewportWidth()/2)-(puContainerDiv.clientWidth/2)+dialogueOffsetX+"px";dialogueOffsetX+=10;};if(attributes.top==null){puContainerDiv.style.top=(getViewportHeight()/2)-(puContainerDiv.clientHeight/2)+dialogueOffsetY+"px";dialogueOffsetY+=10;};if((getAbsoluteLeft(puContainerDiv)+puContainerDiv.clientWidth)>getViewportWidth())puContainerDiv.style.left=(getViewportWidth()-puContainerDiv.clientWidth-20)+"px";if((getAbsoluteTop(puContainerDiv)+puContainerDiv.clientHeight)>getViewportHeight())puContainerDiv.style.top=(getViewportHeight()-puContainerDiv.clientHeight-20)+"px";if(windowClass.focusControl)windowClass.focusControl.focus();return windowClass;};function modalBackgroundAdd(){var modalBackground=document.createElement("div");modalBackground.className=modalBackground.id="modalBackground";modalBackground.style.top=modalBackground.style.left="0";var html=document.body.parentNode;modalBackground.style.width=getWidth(html)+html.scrollLeft+"px";modalBackground.style.height=getHeight(html)+html.scrollTop+"px";setOpacity(modalBackground,0);document.body.appendChild(modalBackground);var o,mB;for(i=0;i<=10;i++){o=0.05*i;setTimeout('setOpacity(gEBI("modalBackground"), '+o+');',(25*i));}};function modalBackgroundRemove(){if(document.getElementById("modalBackground")){var o,mB;for(i=0;i<=10;i++){o=0.5-(0.05*i);setTimeout('setOpacity(gEBI("modalBackground"), '+o+');',(25*i));};setTimeout('document.body.removeChild('+'document.getElementById("modalBackground"));',250);return true;}else return false;};function setOpacity(obj,o){if(!checkBrowser("msie"))obj.style.opacity=o;if(checkBrowser("msie")){obj.style.filter="alpha(opacity="+(o*100)+")";}};function CreatePopupAndFocusElementAfterOk(content,title,Field){var puContainerDiv=document.createElement("div");CreatePopup(puContainerDiv,title,content,{divStyle:"warning",functionAfterOk:function(){FocusAndSelect(Field);},functionBefore:function(){Field.scrollIntoView();puContainerDiv.style.left=(getAbsoluteLeft(Field)-getContainerScrollLeft(Field))+'px';puContainerDiv.style.top=(getAbsoluteTop(Field)-getContainerScrollTop(Field))+'px';},left:getAbsoluteLeft(Field)+5,top:getAbsoluteTop(Field)+5,width:300,modal:true});};function CreateValidatePopup(content,Field){CreatePopupAndFocusElementAfterOk(content,"<b>Validation Error</b>",Field);};function CreatePostErrorPopup(content,Field){var puContainerDiv=document.createElement("div");if(Field!=null)CreatePopupAndFocusElementAfterOk(content,"<b>Post Error</b>",Field);else CreatePopup(puContainerDiv,"<b>Post Error</b>",content,{divStyle:"warning"});};function CreateInfoPopup(content,Field,attributes){var puContainerDiv=document.createElement("div");return CreatePopup(puContainerDiv,"<b>Information</b>",content,attributes);};function CreateHelpPopup(content,width,height){var puContainerDiv=document.createElement("div");CreatePopup(puContainerDiv,"<b>Help</b>",content,{width:width,height:height});};function CreateConfirmPopup(content,f){var puContainerDiv=document.createElement("div");CreatePopup(puContainerDiv,"<b>?</b>",content,{width:300,controls:[{type:"button",content:"Ok",onclick:function(){this.ownerDocument.forms[0].submit();}},{type:"button",content:"Cancel",focus:true,onclick:function(){this.parentNode.parentNode.style.display="none";if(hasSelectBug())showAllSelects();return false;}}]});};function getAbsoluteLeft(obj){var objLeft=0;var lastObj=obj;objLeft=lastObj.offsetLeft;while(lastObj.offsetParent!=null&&lastObj.offsetParent.style.position!="absolute"){lastObj=lastObj.offsetParent;objLeft+=lastObj.offsetLeft;};return objLeft;};function getAbsoluteTop(obj){var objTop=0;var lastObj=obj;if(obj.style&&obj.style.display&&obj.style.display=="none"){return obj.style.top.replace(/px/,"");}else{objTop=lastObj.offsetTop;while(lastObj.offsetParent!=null&&lastObj.offsetParent.style.position!="absolute"){lastObj=lastObj.offsetParent;objTop+=lastObj.offsetTop;}};return objTop;};function getWidth(el){if(el.clientWidth!=0)return el.clientWidth;else if(el.offsetWidth!=0)return el.offsetWidth;else if(el.style&&el.style.width)return el.style.width.replace(/px/g,"");else return false;};function getHeight(el){if(el.clientHeight!=0)return el.clientHeight;else if(el.offsetHeight!=0)return el.offsetHeight;else if(el.style&&el.style.height)return el.style.height.replace(/px/g,"");else return false;};function CreateHelpButton(content,parentNode){var newButton=document.createElement("input");newButton.type="image";newButton.alt=newButton.title="Help";newButton.src=GLOBAL_images+"/help-browser.png";(function(){newButton.onclick=function(){CreateHelpPopup(content,600);return false;};})();if(parentNode!=null)parentNode.appendChild(newButton);else document.getElementById("TitleRight").appendChild(newButton);};function getContainerScrollLeft(obj){var objLeft=0;var lastObj=obj;while(lastObj.parentNode!=document.body&&objLeft==0){lastObj=lastObj.parentNode;objLeft=lastObj.scrollLeft;};return objLeft;};function getContainerScrollTop(obj){var objTop=0;var lastObj=obj;while(lastObj.parentNode!=document.body&&objTop==0){lastObj=lastObj.parentNode;objTop=lastObj.scrollTop;};return objTop;};function getWindowWidth(){return screen.availWidth||screen.Width;};function getWindowHeight(){return screen.availHeight||screen.Height;};function setDivHeightByViewport(divId,offset){document.getElementById(divId).style.height=(getViewportHeight()-offset)+"px";};function checkBrowser(str){return navigator.userAgent.toLowerCase().indexOf(str)+1;};function hasSelectBug(){if(checkBrowser("msie 6")||checkBrowser("msie 5"))return true;else return false;};function hideAllSelects(){var selects=document.getElementsByTagName('select');for(var i=0;i<selects.length;i++){selects[i].style.visibility="hidden";}};function showAllSelects(){var selects=document.getElementsByTagName('select');for(var i=0;i<selects.length;i++){selects[i].style.visibility="visible";}};function compatAddEventListener(o,e,f,b){if(o.addEventListener)o.addEventListener(e,f,b);else if(o.attachEvent)o.attachEvent('on'+e,f);else alert("No event listener adding function available!");};function compatPreventDefault(o){if(o.preventDefault)o.preventDefault();return false;};function compatEventElementShouldSubmit(e){var el=(e.target)?e.target:e.srcElement;if(el.type=="submit"||el.type=="button"||el.type=="textarea"||el.getAttribute("submitonenter")=="true")return true;else return false;};function sleep(sleepms){var then,now;then=new Date().getTime();now=then;while((now-then)<sleepms){now=new Date().getTime();}};function trim(sInString){sInString=sInString.replace(/^\s+/g,"");return sInString.replace(/\s+$/g,"");};function isEmpty(s){return trim(s)=="";};function isInteger(s){var i;for(i=0;i<s.length;i++){var c=s.charAt(i);if((c<"0")||(c>"9"))return false;};return true;};function StrPadLeft(orig_str,pad_char,pad_to_len){if(orig_str.length>=pad_to_len)return orig_str;while(orig_str.length<pad_to_len){orig_str=pad_char+orig_str;};return orig_str;};function StrPadRight(orig_str,pad_char,pad_to_len){if(orig_str.length>=pad_to_len)return orig_str;while(orig_str.length<pad_to_len){orig_str=orig_str+pad_char;};return orig_str;};function FormatFloat(n,decimalPlaces){var dPos,dPart;if(isNaN(decimalPlaces))decimalPlaces=0;n=(parseFloat(n.toFixed(decimalPlaces))).toLocaleString();dPos=n.indexOf(DecimalSeparator);if(dPos==-1)dPos=n.length;dPart=StrPadRight(n.substr(dPos+1),"0",decimalPlaces);if(decimalPlaces>0)return n.substr(0,dPos)+DecimalSeparator+dPart;else if(decimalPlaces==0&&dPos!=n.length)return n.substr(0,dPos);else return n;};function onEnter(e,f){if(!e)e=window.event;if(e.keyCode==13){if(f)f();return false;};return true;};function wasKeypressed(e,kC){if(!e)e=window.event;if(e.keyCode==kC)return true;else return false;};function TrimWithEllipses(str,maxLen){if(str.length>maxLen)return str.substr(0,maxLen-3)+'...';else return str;};function escapeQuotes(s){if(s==null)return null;s=s.replace(/\'/g,"\\'");s=s.replace(/\"/g,"\\\"");return s;};function SearchGeneralArray(a,search,indexFunction){if(indexFunction==null)indexFunction=function(a){return a};for(var i=0;i<a.length;i++)if(indexFunction(a[i])==search)return i;return -1;};Array.prototype.DeleteIndex=function(i){var nA=new Array();if(i<0||i>(this.length-1))nA=this;else nA=nA.concat(this.slice(0,-this.length+i),this.slice(i+1));return nA;};Date.prototype.toISOString=function(){return this.getFullYear().toString()+"-"+StrPadLeft((this.getMonth()+1).toString(),"0",2)+"-"+StrPadLeft(this.getDate().toString(),"0",2);};Date.prototype.toUSAString=function(){return StrPadLeft((this.getMonth()+1).toString(),"0",2)+"/"+StrPadLeft(this.getDate().toString(),"0",2)+"/"+this.getFullYear().toString();};function cloneObject(obj){var newObj=(obj instanceof Array)?[]:{};for(i in obj){if(i=='clone')continue;if(obj[i]&&typeof obj[i]=="object")newObj[i]=cloneObject(obj[i]);else newObj[i]=obj[i];};return newObj;};function FocusAndSelect(Field){Field.focus();if(Field.type=="text"||Field.type=="textarea")Field.select();};function getValById(id){return document.getElementById(id).value;};function markBtnPressed(t){gEBI('BtnPressed').value=t.name;};function confirmDelete(b,s){if(confirm('Delete '+s+'?')){markBtnPressed(b);gEBI('Validate').value='0';return true;}else return false;};function removeNodeIfExists(n){if(n)n.parentNode.removeChild(n);};function isArray(obj){if(obj.constructor.toString().indexOf("Array")==-1)return false;else return true;};function GenerateURIQueryStringFromArrayOfIds(a){var ae=new Array();var e;for(var i=0;i<a.length;i++){e=document.getElementById(a[i]);if(e)ae.push(e);};return GenerateURIQueryFromElements(ae);};function GenerateURIQueryFromElements(ae){var r,el,prefix;r="";for(var i=0;i<ae.length;i++){el=ae[i];prefix="&"+el.name+"=";if(el.type=="checkbox")r+=prefix+encodeURI((el.checked)?"on":"");else if(el.type=="select-multiple")r+=GenerateURIQueryFromSelectMultiple(el);else if(el.value!="")r+=prefix+encodeURI(el.value).replace(/&/,"%26");};return r;};function ReturnSelectedChildNode(select){for(var i=0;i<select.options.length;i++){if(select.options[i].selected)return select.options[i];};return null;};function GenerateURIQueryFromSelectMultiple(sm){var r="";for(var i=0;i<sm.options.length;i++){if(sm.options[i].selected)r+="&"+sm.name+"="+encodeURIComponent(sm.options[i].value);};return r;};function gEBI(id){return document.getElementById(id);};function dcE(tagName){return document.createElement(tagName);};function setBPto(v){gEBI("BtnPressed").value=v;};function SetFormInputOnkeypress(id,v){if(gEBI(id)){if(!v)v="SearchBtn";(function(){var p1=gEBI(id);p1.onkeypress=function(e){if(!e)e=window.event;return onEnter(e,function(){setBPto(v);if(gEBI(v))gEBI(v).click();else p1.form.submit();});};})();}};function FormInputOnkeypress(e,t,sb){var v=sb;if(!e)e=window.event;return onEnter(e,function(){setBPto(v);if(gEBI(v))gEBI(v).click();else t.form.submit();});};function setSearchAppDimensions(gParm){var w=getViewportWidth();var h=getViewportHeight();var g;if(gParm&&!isArray(gParm)){g=new Array();g.push(gParm);}else g=gParm;var TableContainer=(g[0]&&g[0].TableContainer)?((g[0].TableContainer.parentNode&&g[0].TableContainer.parentNode.tagName=="DIV"&&g[0].TableContainer.parentNode.id!="AppForm")?g[0].TableContainer.parentNode:g[0].TableContainer):gEBI("searchContainerDiv");var cCD=gEBI("criteriaContainerDiv");var hC=gEBI("HeaderContainer");var dCD=gEBI("DetailContainerDiv");var sB=gEBI("StatusBar");var hFactor=202;hFactor=hFactor+((cCD)?(cCD.parentNode.clientHeight-80):(getHeight(hC)-80));var newHeight;hFactor-=((dCD)?10:0)-((sB)?24:0);if(h>300)newHeight=(h-hFactor);else newHeight=(300-hFactor-17);if(gParm)for(var i=0;i<g.length;i++){if(g[i].MessageContainer&&g[i].TableContainer){var percPos=g[i].TableContainer.style.height.indexOf("%");if(percPos!=-1)g[i].TableContainerHeightPerc=g[i].TableContainer.style.height.substring(0,percPos);var tchFactor=1;if(g[i].TableContainerHeightPerc)tchFactor=g[i].TableContainerHeightPerc/100;g[i].TableContainer.style.height=((newHeight*tchFactor)-20)+"px";}};TableContainer.style.height=(newHeight)+"px";if(dCD)dCD.style.height=newHeight+"px";if(w>400)w=w-130;else w=400-130;gEBI("AppForm").style.width=(w+106)+"px";if(dCD)dCD.style.width=(w+93)+"px";TableContainer.style.width=(w+93)+"px";if(cCD)cCD.style.width=w+"px"
if(gParm)for(var i=0;i<g.length;i++)g[i].resize();};function getViewportWidth(){var w;if(self.innerHeight)w=self.innerWidth;else if(document.documentElement&&document.documentElement.clientHeight)w=document.documentElement.clientWidth;else if(document.body)w=document.body.clientWidth;return w;};function getViewportHeight(){var h;if(self.innerHeight)h=self.innerHeight;else if(document.documentElement&&document.documentElement.clientHeight)h=document.documentElement.clientHeight;else if(document.body)h=document.body.clientHeight;return h;};function BuildTheadLockedOverlay(mainTable){var origHead=mainTable.getElementsByTagName("thead")[0];var gridCont=mainTable.parentNode;var headOverlayDiv=document.createElement("div");headOverlayDiv.style.position="absolute";headOverlayDiv.style.overflow="hidden";if(checkBrowser("msie"))headOverlayDiv.style.marginLeft="2px";var headOverlayTable=mainTable.cloneNode(false);headOverlayTable.cellSpacing=0;headOverlayTable.cellPadding=0;headOverlayTable.border=1;headOverlayDiv.appendChild(headOverlayTable);headOverlayDiv.style.left=getAbsoluteLeft(mainTable)+1+"px";headOverlayDiv.style.top=getAbsoluteTop(mainTable)+1+"px";gridCont.insertBefore(headOverlayDiv,mainTable);(function(){var v1=headOverlayDiv;var v2=gridCont;gridCont.onscroll=function(){v1.scrollLeft=v2.scrollLeft;};})();var ovH=origHead.cloneNode(true);headOverlayTable.appendChild(ovH);headOverlayDiv.style.width=(gridCont.clientWidth)+"px";headOverlayTable.style.width=mainTable.clientWidth+2+"px";var lastRow=origHead.rows.length-1;ovH.style.height=origHead.clientHeight+"px";for(var i=0;i<origHead.rows[lastRow].cells.length;i++){ovH.rows[lastRow].cells[i].onclick=origHead.rows[lastRow].cells[i].onclick;ovH.rows[lastRow].cells[i].style.width=origHead.rows[lastRow].cells[i].clientWidth+"px";};headOverlayDiv.scrollLeft=gridCont.scrollLeft;return headOverlayDiv;};function compatAddCSSRule(name,content){if(!document.styleSheets[0])alert("compatAddCSSRule: there are no styleSheets");if(document.styleSheets[0].insertRule)document.styleSheets[0].insertRule(name+"{"+content+"};",0);else if(document.styleSheets[0].addRule)document.styleSheets[0].addRule(name,content);};


