﻿// JScript File

var mobile=false;
var lastInput=undefined;
var lastInputIdx=0;

var termsAgree=false;
var isInit=false;
var isRandom=false;
var patWeight;
var patAge=99;
var patAgeRange=1;
var ICPMaint=20;

compVisArr = new Array();
compVisArr.length=13;
var compGLIDLast=0;                
var compFltr=false;
var compFltrAbbr='fltrOFF';



function init(initArg) {


    clAgreeDlg();
    
                
    //Ensure that dependent questions are hidden by blanking questions which have dependent questions
    //Generically, should replace code w/ loop which blanks visible questions
    
    isInit=true;
    evtAge();
    dataEntry(el('ddGCSEYES'));            
    dataEntry(el('ddDays'));
    dataEntry(el('rbICPMonitor'));
    dataEntry(el('txICP'));
    dataEntry(el('rbICPType'));
    dataEntry(el('rbMannitol'));
    dataEntry(el('rbICPType'));
    dataEntry(el('rbSeizure'));
    dataEntry(el('ddBrainOxyMon'));
    isInit=false;
    
    if(initArg==undefined)
        for(var i=0; i<compVisArr.length; i++)
            compVisArr[i]='N';
    
    compSetRows();
    if(initArg=='reset')
        clEvaluate();
    
}


function initMobile() {

    mobile=true;

    //Ensure that dependent questions are hidden by blanking questions which have dependent questions
    //Generically, should replace code w/ loop which blanks visible questions
    
    isInit=true;
    evtAge();

    dataEntry(el('ddGCSEYES'));            
    dataEntry(el('ddDays'));
    dataEntry(el('rbICPMonitor'));
    dataEntry(el('txICP'));
    dataEntry(el('rbICPType'));
    dataEntry(el('rbMannitol'));
    dataEntry(el('rbICPType'));
    dataEntry(el('rbSeizure'));
    dataEntry(el('ddBrainOxyMon'));
    isInit=false;
    
    clStart(1);

}



function el(elId) {
    return document.getElementById(elId);
}


function clAgreeDlg() {

    if(termsAgree)
        return true;
    
    ddFilterHide('hidden');    
    var divTerms = document.getElementById('divTerms');
    var divTermsContent = document.getElementById('divTermsContent');
    
    var pgWidth=pageWidth();
    var pgHeight=pageHeight();
    
    var divWidth=pgWidth*0.6;
    var divHeight=pgHeight*0.8;
    var divLeft=pgWidth*0.2;
    var divTop=pgHeight*0.1;
    
    divTerms.style.width=divWidth+'px';
    divTerms.style.height=divHeight+'px';
    divTerms.style.left=divLeft+'px';
    divTerms.style.top=divTop+'px';
    divTerms.style.visibility='visible';
    
    divTermsContent.style.width=(divWidth*0.98)+'px';
    divTermsContent.style.height=(divHeight*0.75)+'px';
    
    ol('block');
    httpReq2('clPage.aspx','pg=termsonly','divTermsContent',false);
    
    var divTerms=document.getElementById('divTerms');
    var divPopup=document.getElementById('divPopup');
    var divLearn=document.getElementById('divLearn');
    var divReset=document.getElementById('divReset');
    var divX=getPageOffsetLeft(divLearn);
    var divY=getPageOffsetTop(divLearn);
    divReset.style.left=(divX-305)+'px';
    divReset.style.top=(divY+10)+'px';
    divTerms.style.zIndex='999';
    divPopup.style.zIndex='998';
   
  
  
}

function clAgree() {

    termsAgree=true;
    var divTerms = document.getElementById('divTerms');
    divTerms.style.visibility='hidden';
    ol('none');    
    ddFilterHide('visible');
    clEvaluate();

}

function clAgreeMobile(chk) {


    var divStartBtn = document.getElementById('divGetStarted');
    var arr = new Array();
    arr = document.getElementsByTagName('b');
        
    if(chk.checked){
    
        divStartBtn.className='mDiv_button01';
        divStartBtn.setAttribute('onclick','javascript:document.location.href=\'m.clStart.aspx\';');
        for(var i=0; i < arr.length; i++) 
           if(arr[i].className!='rtop' && arr[i].className!='rbottom')
                arr[i].style.backgroundColor='#3399ff';
    } 
    else {
    
        //divStartBtn.className='mDiv_button01_disabled';
        divStartBtn.className='mDiv_button01 disabled';
        divStartBtn.setAttribute('onclick','');
        for(var i=0; i < arr.length; i++) 
           if(arr[i].className!='rtop' && arr[i].className!='rbottom')
                arr[i].style.backgroundColor='#888888';

    }
    

}


function clEvaluate() {


    var compVis='';
    for(var i=0;i<compVisArr.length;i++)
        compVis=compVis+compVisArr[i];

    var clData = inputSQL(document.clForm);    
    httpReq2('clRpt.aspx','mode=panel&cldata='+clData+'&vis='+compVis+'&fltr='+compFltr,'divEval',true);    


}


function compReport()  {

    if(!evtInclusion())
        return 0;
    var clData = inputSQL(document.clForm);    
    var dataWin=window.open('clRpt.aspx'+'?mode=popup&cldata='+clData,'ClickAndLearn','width=800,height=600,left=50,top=50,scrollbars=yes,resizable=yes');
    dataWin.focus();
    return 0;

}


function clReset(frmObj) {

    var el;
    for (var i=0; i<frmObj.elements.length; i++) {
        el = frmObj.elements[i];
        if(el.getAttribute('propName')!=undefined && el.getAttribute('noReset')==undefined)
            switch(el.type) {
	            case 'select-one': case 'text':  el.value='';break;
	            case 'checkbox' :  el.checked=false;break;
            }
    }    
}


/*======================================================================================================
/
/   Compliance Div Events
/
/=======================================================================================================*/


function compHdrClick(elObj) {

    //ToggleNextRow(trObj);
    ToggleNextDiv(elObj);
    //var trIndex = parseInt(right(trObj.id,2),10);
    var indx = parseInt(elObj.id.substr(elObj.id.length-2,2),10);
    compVisArr[indx]=(compVisArr[indx]=='N')?'Y':'N';
    compGLPopupHide();
    
}


function compHdrMouse(trObj, mouseOut) {

    
    var hiliteColor = mouseOut?'#e1e1e1':'#99ff99';
    var classArr = trObj.className.split(' ');
    var classBase = classArr[0];
    var className = mouseOut?classBase:classBase+' divCompHdrHili';
    var compAbbr = trObj.getAttribute('compAbbr');
    
    
    var inp, inpTag, i;
    var inputs = collectionToArray(document.getElementsByTagName("input"));
	inputs = inputs.concat(collectionToArray(document.getElementsByTagName("select")));
	inputs = inputs.concat(collectionToArray(document.getElementsByTagName("table")));  //Add tables since the radio button renditions as an HTML table
	
	trObj.className=className;
    if(compFltr) {
        var tdObj=trObj.childNodes[(document.all)?0:1];
	    compFltrAbbr=compAbbr;
	    objContent(document.getElementById('lblCompFilter'),'Filter: '+objContentGet(tdObj));
	}
	compSetRows(hiliteColor, compAbbr);
	
    
}


function compGLPopup(compGLID, closeX) {

    if(closeX==undefined)  {
        closeX=false;
        if(document.getElementById('divPopup').style.visibility=='visible')
            return 0;
    }
    
    compGLPopupHide();
    compGLIDLast=compGLID;
    //ad-hoc 
    if(compGLID==16)
        compGLID=14;
    httpReq2('clGuideline.aspx','compid='+compGLID+'&closex='+closeX,'divPopup',false);
    
}


function compGLPopin(compGLID, btnObj) {

    btnObj.style.width='100%';
    var divPopIn=document.getElementById('divPopin'+pad(compGLID,2));
    
    
    if(divPopIn.innerHTML.length<100) {  //arbitrary low number
        divPopIn.innerHTML='<img src="images/waiting.gif" />';
        httpReq2('m.clGuideline.aspx','compid='+compGLID,divPopIn.id,false);
    }
    else {
        btnObj.style.width='80px';
        divPopIn.innerHTML='';
    }
        
}

function compGLPopupHide(mouseOut) {

    if(document.getElementById('imPopupX')!=undefined && mouseOut!=undefined)
        return 0;
        
    var divPopup=document.getElementById('divPopup');
    var divMainGuid=document.getElementById('divMainGuid');
    var imgArrowUp=document.getElementById('imgArrowUp');
    var imgArrowDn=document.getElementById('imgArrowDn');
    
    if(divMainGuid!=undefined) {
        divMainGuid.style.visibility='hidden';
        compGLPopupContent(undefined);   
    }    
    divPopup.style.visibility='hidden';
    imgArrowUp.style.visibility='hidden';
    imgArrowDn.style.visibility='hidden';
    ddFilterHide('visible');
    
}

function compGLPopupCorners()  {

    Rounded('div#divMainGuid','a0bcfa','#a0bcfa');
    Rounded('div#divLinks','#a0bcfa','#e4e4e4');
    Rounded('div#divContent','#a0bcfa','#e0e0e0');

}

function compGLPopupContent(linkObj) {

    document.getElementById('link01').style.fontWeight='';
    document.getElementById('link02').style.fontWeight='';
    document.getElementById('link03').style.fontWeight='';
    document.getElementById('link04').style.fontWeight='';
    document.getElementById('link05').style.fontWeight='';
    document.getElementById('divContent01').style.visibility='hidden';
    document.getElementById('divContent01').style.display='none';
    document.getElementById('divContent02').style.visibility='hidden';
    document.getElementById('divContent02').style.display='none';
    document.getElementById('divContent03').style.visibility='hidden';
    document.getElementById('divContent03').style.display='none';
    document.getElementById('divContent04').style.visibility='hidden';
    document.getElementById('divContent04').style.display='none';
    document.getElementById('divContent05').style.visibility='hidden';
    document.getElementById('divContent05').style.display='none';
    
    if(linkObj!=undefined) {
        var idStr = linkObj.id.substr(4,5);
        linkObj.style.fontWeight='bold';
        divObj=document.getElementById('divContent'+idStr).style.visibility='visible';
        divObj=document.getElementById('divContent'+idStr).style.display='';
    }
    
    //with ie, the inline elements which simulate the corners become vertically 
    //separated after the font-weights above get changed
    
}


function compGLPopupPosition(compGLID) {


    var divPopup=document.getElementById('divPopup');
    var divMainGuid=document.getElementById('divMainGuid');
    var lnkDetails=document.getElementById('lblDetLink_'+compGLID);
    var imgArrowUp=document.getElementById('imgArrowUp');
    var imgArrowDn=document.getElementById('imgArrowDn');
    
    
    //We know our popup will be to the left of link
    //Determine if link is in top or bottom half of page
    var pgX=pageWidth();
    var pgY=pageHeight();

    var scrlX=posLeft();
    var scrlY=posTop();
    
    var elX=getPageOffsetLeft(lnkDetails);
    var elY=getPageOffsetTop(lnkDetails);
    
    var fromTop=elY-scrlY;          //element position from top
    var fromBot=(pgY+scrlY)-elY;    //element position from bottom
    
    var popHt=divPopup.offsetHeight;
    var popWd=divPopup.offsetWidth;
        
    var divTop=elY-(popHt/2);  //center popup at link
    divTop=(fromBot>=popHt/2)?divTop:elY+fromBot-popHt;     //Set bottom of screen as floor for popup
    divTop=(fromTop>=popHt/2)?divTop:scrlY;                 //Set top of screen as ceiling for popup
    
    var imgTop;
        
        
    if(fromTop<fromBot) {  //popup will be below link
        imgID='imgArrowUp';
        imgTop=elY;}
    else {                  //popup will be above link
        imgID='imgArrowDn';
        imgTop=elY-213;}   //213 is height of the arrow

    ddFilterHide('hidden');
    
    var imgArrow=document.getElementById(imgID);
    imgArrow.style.top=imgTop+'px';
    imgArrow.style.left=(elX-117)+'px';  //117 is the width of the arrow    
    imgArrow.style.visibility='visible';
    
    divPopup.style.top=divTop+'px';
    divPopup.style.left=(elX-117-popWd)+'px';  //500 is the width of the popup div    
    divPopup.style.visibility='visible';
    divMainGuid.style.visibility='visible';

    
    
}


function compToggleFltr() {

    var lblFltr=document.getElementById('lblCompFltr');
    var lblTxt=(objContentGet(lblFltr)=='Off')?'On':'Off';
    compFltr=(lblTxt=='On')?true:false;
    objContent(lblFltr,lblTxt);
    
    toggleVis('trCompSectionFltr');
    toggleVis('trCompSectionExam');
    toggleVis('trCompSectionBP');
    toggleVis('trCompSectionICP');
    toggleVis('trCompSectionOther');
    
    if(compFltr)
        compHdrMouse(document.getElementById('trCompHdr00'));
    else {
        compFltrAbbr='fltrOFF';
        compSetRows();
    }
    
}


function compSetRows(hiliteColor, compAbbr) {

    
    var inp, compTag;
    var inputs = collectionToArray(document.getElementsByTagName("input"));
    inputs = inputs.concat(collectionToArray(document.getElementsByTagName("select")));
    inputs = inputs.concat(collectionToArray(document.getElementsByTagName("table")));  //Add tables since the radio button renditions as an HTML table
    
    for (i=0; i<inputs.length; i++) {

        inp = inputs[i];
        compTag=inp.getAttribute('complianceTag');
    	    
        if(compTag!=undefined){
                
            var qCompRow=inp.parentNode.parentNode;
            var compHide=qCompRow.getAttribute('comphide');
            var rowHide=(compHide==true || compHide=='true');
            
            if(!compFltr) {
                qCompRow.style.visibility=(!rowHide)?'visible':'hidden';
                qCompRow.style.display=(!rowHide)?'':'none';
                if(hiliteColor!=undefined) 
                    if(compTag.indexOf(compAbbr)>=0)
                        qCompRow.style.backgroundColor=hiliteColor;
            }
            else {
                if(compTag.indexOf(compFltrAbbr)>=0) {
                    qCompRow.style.visibility=(!rowHide)?'visible':'hidden';
                    qCompRow.style.display=(!rowHide)?'':'none';
                }    
                else {
                    qCompRow.style.visibility='hidden';
                    qCompRow.style.display='none';
                }
            }
        }
    }    
}


function compVarVis(datObj, hide)  {

    var varId=datObj.id

    if(mobile) {  //Uses divs
    
        var divIdx=datObj.getAttribute('divIndex');
        var divId='mDiv_input_'+divIdx;
        var divId=document.getElementById(divId);
        if(divId!=undefined)
            divId.setAttribute('comphide',hide);
    
    }
    else {  //Uses table rows
    
        var rowId='tr'+varId.substring(2);
        var rowObj=document.getElementById(rowId);
        if(rowObj!=undefined)
            rowObj.setAttribute('comphide',hide);
   }
   
   if(hide) 
    setCtrVal(datObj,'');
   
}




function compHelp() {

    var helpWin=window.open('clHelp.aspx','ClickAndLearn','width=600,height=500,left=200,top=100,scrollbars=yes,resizable=yes');
    helpWin.focus();
    return 0;

}


function dataEntry(datObj){


    switch(datObj.id){
            
        case 'ddDays':

            var tbiDays=parseInt(datObj.value,10);
            compVarVis(el('rbSeizure'),!(tbiDays>=7));
            if(!(tbiDays>=7))
                compVarVis(el('rbSeizureProph'),!(tbiDays>=7));
            break;
            
        case 'txAge':
            patAge=parseInt(datObj.value,10);
            patAgeRange = patAge>=12 ? 1 : (patAge>=6 ? 2 : (patAge>=1 ? 3 : 4));
            evtAge();
            break;

        case 'ddGCSEYES': case 'ddGCSMOT':
            var GCSE = document.getElementById('ddGCSEYES');
            var GCSM = document.getElementById('ddGCSMOT');
            var GCST = document.getElementById('txGCSTOT');
            var GCSTotal = 1+parseInt(GCSE.value,10)+parseInt(GCSM.value,10);
            if(!isNaN(GCSTotal))
                GCST.value=GCSTotal;

            compVarVis(el('rbPupils'), !(GCSTotal==3));
            //evtInclusion();
            break;
       
       case 'rbPupils':
           
            //evtInclusion();
            break;     
            

        case 'txWeight': case 'ddWeightU': case 'txCals': case 'txMannGm': 
            evtWeight();break;
                    
        case 'txMABP' :
        
            var txCPP = document.getElementById('txCPP');
            var txICP = document.getElementById('txICP');
            txCPP.value = parseInt(datObj.value,10)-parseInt(txICP.value,10);
            break;
                
        case 'rbICPMonitor':
            
            var ICPMon=(rbValue(datObj.id)==1)?true:false;
            compVarVis(el('rbICPType'), !ICPMon);
            
            //These are dependent on other values dependent on ICPType - should be handled recursively
            if(!ICPMon){
                compVarVis(el('txICP'), true);
                compVarVis(el('txCPP'), true);
                compVarVis(el('rbMannitol'), true);
                compVarVis(el('txMannGm'), true);
                compVarVis(el('txMannDose'), true);
                compVarVis(el('rbICPPropofol'), true);
                compVarVis(el('rbICPAntiB'), true);
            }
            break;


        case 'rbICPType':
            
            var ICPType=(rbValue(datObj.id)==1)?true:false;
            compVarVis(el('txICP'), !ICPType);
            compVarVis(el('txCPP'), !ICPType);
            compVarVis(el('rbICPAntiB'), !ICPType);
            
            //These are dependent on other values dependent on ICPType - should be handled recursively
            if(!ICPType) {      
                compVarVis(el('rbMannitol'), !ICPType);
                compVarVis(el('txMannGm'), !ICPType);
                compVarVis(el('txMannDose'), !ICPType);
                compVarVis(el('rbICPPropofol'), !ICPType);
            }                
            break;


        case 'txICP':
            
            var txCPP = el('txCPP');
            var txMABP = el('txMABP');
            var ICPVal=parseInt(datObj.value,10);
            txCPP.value = parseInt(txMABP.value,10)-ICPVal;
            
            compVarVis(el('rbMannitol'),!(ICPVal>ICPMaint));
            compVarVis(el('rbICPPropofol'),!(ICPVal>ICPMaint));
            if(!(ICPVal>ICPMaint)) {
                compVarVis(el('txMannGm'),!(ICPVal>ICPMaint));
                compVarVis(el('txMannDose'), !(ICPVal>ICPMaint));
            }    
            break;


        case 'rbIntubated':
            compVarVis(el('rbIntubAntiB'),!(rbValue(datObj.id)==1));break;

        case 'rbMannitol':
            compVarVis(el('txMannGm'),!(rbValue(datObj.id)==1));
            compVarVis(el('txMannDose'),!(rbValue(datObj.id)==1));break;
            
        case 'rbSeizure':
            compVarVis(el('rbSeizureProph'),!(rbValue(datObj.id)==1));break;
                    
        case 'ddBrainOxyMon':
            compVarVis(el('rbBrainOxyJug'), parseInt(datObj.value,10)!=2);
            compVarVis(el('rbBrainOxyTis'), parseInt(datObj.value,10)!=3);break;
                
        default:
            
        }

    
    if(isInit!=true && !isRandom && !mobile){
      compSetRows();       
      clEvaluate();
    }


}







function evtAge() {


        var qSBPLow = document.getElementById((mobile?'div':'td')+'SBPLow');

        switch(patAgeRange){
            case 1:
                qSBPLow.innerHTML='Systolic blood pressure &#8805;90 mmHg?';ICPMaint=20;break;
            case 2:
                qSBPLow.innerHTML='Systolic blood pressure &#8805;80 mmHg?';ICPMaint=20;break;
            case 3:
                qSBPLow.innerHTML='Systolic blood pressure &#8805;75 mmHg?';ICPMaint=15;break;
            case 4:
                qSBPLow.innerHTML='Systolic blood pressure &#8805;65 mmHg?';ICPMaint=15;break;
            default:
                
        }
    

}


function evtWeight() {

     var wtVal = document.getElementById('txWeight');
     var wtUnit = document.getElementById('ddWeightU');
     var kCals = document.getElementById('txCals');
     var kCalKg = document.getElementById('txKCalKg');
     var manGm = document.getElementById('txMannGm');
     var manGmKg = document.getElementById('txMannDose');
     var wtMult = (wtUnit.value==1)?1:0.45359;
     
     patWeight=parseInt(wtVal.value*wtMult,10);

     if(patWeight>0) {
        kCalKg.value=(parseInt(kCals.value,10)/patWeight).toFixed(1);
        manGmKg.value=(parseInt(manGm.value,10)/patWeight).toFixed(1);
     }
     else {
        kCalKg.value='';
        manGmKg.value='';
     }


}


function evtInclusion(){

    //temp
      //  if(mobile)
        //    return;
            
    var GCSE = document.getElementById('ddGCSEYES');
    var GCSM = document.getElementById('ddGCSMOT');
    var GCST = document.getElementById('txGCSTOT');
    
    if(GCST.value>8 || GCSM.value==6 || GCSE.value>2 || rbValue('rbPupils')==1) {
        //sm('divDialog');
        dlgMsg('msgInclusion');
        return false;
    }
    return true;
    
}

function tbiRandom()  {


    isRandom=true;
    var rowObj;
    var inp, i, rand_no, skipEvt=false, compHide, rowDisplay, inpBlank, blankCount=99;
    var inputs = collectionToArray(document.getElementsByTagName("input"));
	inputs = inputs.concat(collectionToArray(document.getElementsByTagName("select")));
	
    for (h=0; h<=10 && blankCount>0; h++) {
    
        for (i=0; i<inputs.length; i++) {

            inp = inputs[i];
            skipEvt = false;
            blankCount=0;
            
            if(left(inp.id,2)=='rb')
                rowObj=inp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
            else
                rowObj=inp.parentNode.parentNode;
            
            compHide = rowObj.getAttribute('comphide');
            rowHide = (compHide==true || compHide=='true');
            
            
            if(inp.type=='radio')
                inpBlank=(rbValue(document.getElementById(inp.name).id)==undefined)
            else if(inp.type=='select-one' || inp.type=='text')
                inpBlank=(inp.value=='');
                
            if(inpBlank && rowDisplay!='none')
                blankCount++;
            
            
            if(inpBlank && !rowHide) {
            
                switch(inp.type){
                
                    case 'radio':
        	        
	                    rand_no = Math.ceil(2*Math.random())
	                    inp=document.getElementById(inp.name);
                        setCtrVal(inp,rand_no);
                        i++;
	                    break;
        	            
	                case 'select-one':
        	            
        	            
	                    skipEvt=(inp.id=='ddWeightU');
                        //rand_no = 1 + Math.ceil((inp.length-2)*Math.random());
                        rand_no = Math.ceil((inp.length-1)*Math.random());
                        inp.selectedIndex = rand_no;
	                    break;
        	        
	                case 'text': 
        	            
	                    var MaxVal=inp.getAttribute('dataMaxVal');
  	                    if(MaxVal!=undefined) {
  	                        rand_no = Math.ceil(MaxVal*Math.random())
                            inp.value = rand_no;
                        }
                        
                            
                     
                }
            
            
                if(!skipEvt)
                    dataEntry(inp);
            }
            
        }

    }
    
    
    isRandom=false;
    compSetRows();
    clEvaluate();

    
}










function postStateChange(targetID) {


    switch(targetID) {

        case 'divTermsContent':
            Rounded("div#divTermsInner","#aca899","#dcdcdc");
            break;

        case 'divPopup':
            
            compGLPopupContent(document.getElementById('link01')); 
            compGLPopupPosition(compGLIDLast);
            compGLPopupCorners();            
            break;
                       
        
                        
        case 'divEval':
        
            RoundedTop("div.divRptHdr1","#ffffff","#5f9ea0");
            RoundedBottom("div.divRptFtr1","#ffffff","#5f9ea0");
            Rounded("div.divRoundedInner01","#ccccff","#e6e6fa");
            evtInclusion();
            //RoundedTop("div.divCompTop","#efefef","#5F9EA0");
            //RoundedBottom("div.divCompBot","#efefef","#5F9EA0");
            //Rounded("div.divCompliance","#CCCCFF","#E6E6FA");
            break;                


        case 'divDialog' :
            

            sm('divDialog');   
            //switch(contxtEdit) {
            //    default: break;}
            frmValid(document.frmDialog);  //This will hilite controls needing attention before any user entry
            
            break;
    
    
        case 'divDialogSubmit' :
                
                hm('divDialog');
                $('divDialogSubmit').innerHTML='';  //avoid multiple copies of the frmDialog object
                
                switch(contxtEdit) {
                    
                    case 'cntr': 
                        cntrSelect(cntrIDLast,true);break;
                    case 'acct': case 'acctAdd' :
                        srchInputEvt();break;
                    case 'acctCntr': case 'acctCntrAdd': case 'acctCntrDel': case 'noteCntr': case 'noteCntrAdd': case 'noteCntrDel': case 'cntrAddr':
                        cntrSelect(cntrIDLast);break;
                    case 'notePIDAdd':
                        chgMenu('pid',pidLast);break;
                    case 'loginAs' :
                        top.location.href='home.aspx';break;
                    
                    default:           
                        
                }


        default:
            if(targetID.indexOf('divPopin')>=0) {
                //Rounded("div.divBtn01","#e6e6fa","#cccccc","small");
            }
        
        

    }


}


function clStart(inc) {

    

    var nextInputID='mDiv_input_'+pad(lastInputIdx+inc,2);
    var nextInput=document.getElementById(nextInputID);
    var progressBar=document.getElementById('mDiv_navProgressInner');

    if(nextInput!=undefined) {
        
        var compHide=nextInput.getAttribute('comphide');
        var compRead=nextInput.getAttribute('readonly');
        lastInputIdx=lastInputIdx+inc;
        
        if(compHide==true || compHide=='true' || compRead==true || compRead=='true') {
            clStart(inc);    //recurse until we find visible input
            return;  
        }
        
        nextInput.style.display='block';
        document.getElementById('mDiv_inputHdr0').innerText=nextInput.getAttribute('Section');
        if(lastInput!=undefined) lastInput.style.display='none';
        lastInput=nextInput;
        
        //alert(Math.round(100*parseInt(nextInputID.substr(11,2),10)/36));
        var progPct=Math.round(100*parseInt(nextInputID.substr(11,2),10)/36);
        progressBar.style.width=progPct.toString()+'%';
    }
    else if(inc==1)  {
        var clData = inputSQL(document.clForm);    
        //document.location.href='m.clReport.aspx'+'?cldata='+clData;
        document.location.href='clRpt.aspx?mode=mobile&cldata='+clData;
    }
    
    var backButton=document.getElementById('mDiv_NavBack');
    backButton.style.display=(lastInputIdx==1)?'none':'block';
        
   
}


    
var contxtEdit;

function dlgMsg(contxt) {
    httpReq2('dialog.aspx','mode=load'+'&contxt='+contxt,'divDialog');
}

function dlgInput(contxt) {
    httpReq2('dialog.aspx','mode=load'+'&contxt='+contxt,'divDialog');
}


function objEdit(objID, contxt, params) {
    
    
    var reqPage='dialog.aspx';
    //we cannot show dialog here yet since it's content will get wiped out
    //either show temporary div with waiting.gif or rework dialog function 
    document.getElementById('divDialog').innerHTML='<img src="images/waiting.gif" />';
        
    //later we can replace this switch by knowing the last object type selected    
    var parID=0;    
    
    switch(contxt) {
        default:        
    }
    
    
    httpReq2(reqPage,'objid='+objID+'&parid='+parID+'&mode=load'+'&contxt='+contxt+'&params='+params,'divDialog');
    contxtEdit=contxt;
    
}



function objEditSubmit(objID, contxt, params) {
    
        
    var setStr;
    if(frmValid(document.frmDialog))
        setStr=inputSQL(document.frmDialog);
    else
        {alert('Validation errors.'); return 0;}
    


//===========================================================================================================================
//  Set parentID of object where applicable
//

    var parID=0, post=true, pageReq='dialog.aspx';
    var divDlg=document.getElementById('divDialog');
    
    switch(contxtEdit) {
    
        case 'noteCntrAdd':
            parID=cntrIDLast;break;
        case 'notePIDAdd':
            parID=pidLast;break;    
        default: 

    }

    setStr=setStr.replace(/>/g,'&gt;');
    setStr=setStr.replace(/</g,'&lt;');
    setStr=encodeURIComponent(setStr);
    httpReq2(pageReq,'objid='+objID+'&parid='+parID+'&mode=post'+'&contxt='+contxt+'&params='+params+'&set='+setStr,'divDialogSubmit',post);

}



function pad(number, length) {
   
    var str = '' + number;
    while (str.length < length) {
        str = '0' + str;
    }
   
    return str;

}



