﻿
/* 
-----------------------------------------------------------------------
    ClinDotNet 
    Javascript Function Library v. 1.0
----------------------------------------------------------------------- 
*/


/* ********************************************************************
    Function: 
        clearRadioButtonGroup()
    Params  : 
        rbgID = the radio button group ID
    Description : 
        This function is used to clear a Radio Button Group and it's 
        called directly from an hyperlinek displayed at runtime by the 
        main engine. To obtain the real name of the object, the function
        must split the provided name and take the last item of the 
        resulting array.
    
*********************************************************************** */
function clearRadioButtonGroup(rbgID){
	var nrb = document.forms[0].elements.length;
	var res = "";
	for(j=0;j<nrb;j++){
	    fname = document.forms[0].elements[j].name;
	    rname = fname.split('$');
	    uname = rname[rname.length-1];
	    if(uname==rbgID) {
	        // document.forms[0].elements[j].checked = false;
	        if(document.forms[0].elements[j].value == "")
	            document.forms[0].elements[j].checked = true;
	    }
	}
}


/* ********************************************************************
    Function: 
        setTodayDate()
    Params  : 
        cName = the shared name of the 3-item datetime object
    Description : 
        This function is used to set the values of CNAME_D/M/Y to
        current date values
    
*********************************************************************** */
function setTodayDate(cName){
    var nrb = document.forms[0].elements.length;
    var today = new Date()
    var month = today.getMonth() + 1
    var day = today.getDate()
    var year = today.getFullYear()
	for(j=0;j<nrb;j++){
	    fname = document.forms[0].elements[j].name;
	    rname = fname.split('$');
	    uname = rname[rname.length-1];
	    if(uname==cName+"_D") document.forms[0].elements[j].value = day;
	    else if(uname==cName+"_M") document.forms[0].elements[j].value = month;
	    else if(uname==cName+"_Y") document.forms[0].elements[j].value = year;
	}    
}


/* ********************************************************************
    Function: 
        setNA()
    Params  : 
        txtID = the textbox name to be nullified
    Description : 
        This function is used to set the values of a textbox to NA (-1)
    
*********************************************************************** */
function setNA(txtID){
    document.getElementById(txtID).value= "-9";
}

/* ********************************************************************
    Function: 
        showDiv()
    Params  : 
        divname = the name of the div to be displayed
    Description : 
        This function is used to make a DIV element visible
    
*********************************************************************** */
function showDiv(divname){
    document.getElementById(divname).style.display='block';
}


/* ********************************************************************
    Function: 
        hideDiv()
    Params  : 
        divname = the name of the div to be hided
    Description : 
        This function is used to make a DIV element hidden
    
*********************************************************************** */
function hideDiv(divname){
    document.getElementById(divname).style.display='none';
}


/* ********************************************************************
    Function: 
        hideDivButMe()
    Params  : 
        divname = the name of the div to be displayed
    Description : 
        This function is used to make a DIV element visible and to hide all
        the other div. The DIV to be hided must have an ID like "JSDIV_something"
    
*********************************************************************** */
function hideDivButMe(divname){
    /* TODO */
}


/* ********************************************************************
    Function: 
        showhide()
    Params  : 
        divname = the name of the div to be displayed or hided
    Description : 
        Used to change the visibility status of a DIV    
*********************************************************************** */
function showhide(divname){
    var display = document.getElementById(divname).style.display;
    document.getElementById(divname).style.display = (display == "block") ? "none" : "block";   
}



/* ********************************************************************
    Function: 
        setValueOfWarningField()
    Params  : 
        thevalue = the value (Warning ID) to be assigned
    Description : 
        Used to set the value of current warning 
*********************************************************************** */
function setValueOfWarningField(thevalue){
    document.getElementById("_WRN_CURRENT").value = thevalue;
}
