//-----------------------------------------------------------------------------------------------------------
//    NOTEPRIMECOMMON JavaScripts
//-----------------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------------
// npcom_IsBrowserIE
//
// Returns true if the executing browser it a Microsoft Internet Explorer browser.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_IsBrowserIE()
{
	try
	{ return (window.navigator.userAgent.indexOf("MSIE ") > 0); }
	catch(x)
	{ return false; }
}

//-----------------------------------------------------------------------------------------------------------
// npcom_IsBrowserNS
//
// Returns true if the executing browser it a Netscape browser.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_IsBrowserNS()
{
	try
	{ return (window.navigator.userAgent.indexOf("Netscape") > 0); }
	catch(x)
	{ return false; }
}

//-----------------------------------------------------------------------------------------------------------
// npcom_IsBrowserFF
//
// Returns true if the executing browser it a Firefox browser.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_IsBrowserFF()
{
	try
	{ return (window.navigator.userAgent.indexOf("Firefox") > 0); }
	catch(x)
	{ return false; }
}

//-----------------------------------------------------------------------------------------------------------
// npcom_IsBrowserAS
//
// Returns true if the executing browser it a Safari browser.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_IsBrowserAS()
{
	try
	{ return (window.navigator.userAgent.indexOf("Safari") > 0)&&(window.navigator.userAgent.indexOf("Chrome") = 0); }
	catch(x)
	{ return false; }
}

//-----------------------------------------------------------------------------------------------------------
// npcom_IsBrowserOO
//
// Returns true if the executing browser it a Opera browser.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_IsBrowserOO()
{
	try
	{ return (window.navigator.userAgent.indexOf("Opera") > 0); }
	catch(x)
	{ return false; }
}

//-----------------------------------------------------------------------------------------------------------
// npcom_IsBrowserGC
//
// Returns true if the executing browser it a Google browser.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_IsBrowserGC()
{
	try
	{ return (window.navigator.userAgent.indexOf("Chrome") > 0); }
	catch(x)
	{ return false; }
}

//-----------------------------------------------------------------------------------------------------------
// npcom_BrowserDisplay
//
// Returns true if the executing browser it a Google browser.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_BrowserDisplay()
{
	if (npcom_IsBrowserIE())
	{ return "Explorer";}
	else if (npcom_IsBrowserFF())
	{ return "Firefox";}
	else if (npcom_IsBrowserAS())
	{ return "Safari";}
	else if (npcom_IsBrowserNS())
	{ return "Netscape";}
	else if (npcom_IsBrowserOO())
	{ return "Opera";}
	else if (npcom_IsBrowserGC())
	{ return "Chrome";}
	else
	{ return "Unknown";}
}
//-----------------------------------------------------------------------------------------------------------
// npcom_BrowserDisplay
//
// Returns true if the executing browser it a Google browser.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_BrowserDisplayTo(sCtl)
{
    var cCtl = dnn.dom.getById(sCtl);
    if(cCtl!=null) { cCtl.value = npcom_BrowserDisplay(); }
}

//-----------------------------------------------------------------------------------------------------------
// npcom_hasattributes
//
//   Return true is the specified aElement has attributes
//
//-----------------------------------------------------------------------------------------------------------
function npcom_hasattributes(aElement)
{
    try
    {
        if (aElement.hasAttributes)
        { return aElement.hasAttributes(); }
        else
        {
            if (aElement.attributes&&aElement.attributes.length>0)
            { return true; }
            else
            { return false; }    
        }
    }
    catch(x)
    { return false; }
}
//-----------------------------------------------------------------------------------------------------------
// npcom_checkforattributeIE
//
//   Returns the specified sAttr in aElement if it exists otherwise returns null
//
//   Internet Explorer Version (for performance)
//
//-----------------------------------------------------------------------------------------------------------
function npcom_checkforattributeIE(aElement,sAttr)
{
	var resx;
	try
	{
	    for (var z=0; z<aElement.attributes.length; z++)
	    {
	        if (aElement.attributes[z].name==sAttr)
	        {
		        resx = aElement.attributes[z].value;
		        break;
	        }
	    }
	}
	catch(x) {}
	return resx;
}
//-----------------------------------------------------------------------------------------------------------
// npcom_checkforattribute
//
//   Returns the specified sAttr in aElement if it exists otherwise returns null
//
//-----------------------------------------------------------------------------------------------------------
function npcom_checkforattribute(aElement,sAttr)
{
    if (npcom_IsBrowserIE())
    { return npcom_checkforattributeIE(aElement,sAttr); }
    
	var resx;
	try
	{
	    if (npcom_hasattributes(aElement)&&sAttr!=undefined)
	    {
	        if (aElement.hasAttribute)
	        {
	            if (aElement.hasAttribute(sAttr))
	            {
	                resx = aElement.getAttribute(sAttr);
	            }
	        }
	        else
	        {
        	    for (var z=aElement.attributes.length-1; z>=0; z--)
	            {
	                if (aElement.attributes[z].name==sAttr)
	                {
		                resx = aElement.attributes[z].value;
		                break;
	                }
	            }
	        }
	    }
	}
	catch(x){}
	return resx;
}
//-----------------------------------------------------------------------------------------------------------
// npcom_replaceattributeIE
//
//   Replaces the specified sAttr in aElement with sNew if it exists and matches the sOld value.
//
//   Internet Explorer Version (for performance)
//
//-----------------------------------------------------------------------------------------------------------
function npcom_replaceattributeIE(aElement,sAttr,sOld,sNew)
{
    try
    {
	    for (var z=0; z<aElement.attributes.length; z++)
	    {
	        if (aElement.attributes[z].name==sAttr)
	        {
		        if (aElement.attributes[z].value==sOld)
		            aElement.attributes[z].value=sNew;
	            break;
	        }
	    }
	}
	catch(x){}
}
//-----------------------------------------------------------------------------------------------------------
// npcom_replaceattribute
//
//   Replaces the specified sAttr in aElement with sNew if it exists and matches the sOld value.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_replaceattribute(aElement,sAttr,sOld,sNew)
{
    if (npcom_IsBrowserIE())
    { npcom_replaceattributeIE(aElement,sAttr,sOld,sNew); return; }

    var resx = npcom_checkforattribute(aElement,sAttr);
    try
    {
        if(resx.toLowerCase()==sOld.toLowerCase())
        {
            if (aElement.hasAttributes)
            { aElement.setAttribute(sAttr,sNew); }
            else
            {
       	        for (var z=aElement.attributes.length-1; z>=0; z--)
	            {
	                if (aElement.attributes[z].name==sAttr)
	                {
        		        if (aElement.attributes[z].value==sOld)
    	                    aElement.attributes[z].value=sNew;
    		            break;
	    	        }
    	       }
            }
        }
    }
    catch(x) {}       
}
//-----------------------------------------------------------------------------------------------------------
// npcom_getElemementByAttributeIE
//
//
//   Internet Explorer Version (for performance)
//
//-----------------------------------------------------------------------------------------------------------
function npcom_getElementByAttributeIE(aAttribute,aValue,aSpecial,aInElement)
{
    var ElementVerifier;
    var Elements=new Array();
    function SearchElement(aElement)
    { 
        if(aElement==null||aElement==undefined)return
	    if(ElementVerifier(aElement))
	    { 
	        Elements[Elements.length]=aElement;
	        // no child search if found ...
            //if(aElement.id!=undefined){ alert('Found ' + aElement.id + ' [' + aElement.nodeName + ']');npcomxlog=0;}
	        SearchElement(aElement.nextSibling);
	    }
	    else
	    {
            //if(aElement.id!=undefined && (aElement.id=='dnn_ctr451_ContactsEdit_ddlParent' || npcomxlog==1)){ alert(aElement.id + ' [' + aElement.nodeName + ']');npcomxlog=0;}
	        if(aElement.nodeName!='SELECT') SearchElement(aElement.firstChild);
	        SearchElement(aElement.nextSibling);
	    }  
    }
    if(aInElement==undefined)aInElement=document.body;
    if(aSpecial==undefined)aSpecial="!";
    if (aValue=="*")
        str="if(Element."+aAttribute+"!=undefined){return true;}else{return false;}";
    else 
    if (aSpecial=="*")
        str="if(Element."+aAttribute+"!=undefined && Element."+aAttribute+".indexOf('"+aValue+"')>=0){return true;}else{return false;}";
    else
        str="if(Element."+aAttribute+"=='"+aValue+"'){return true;}else{return false}";
    
    ElementVerifier=function(aElement)
                    {
                        Element=aElement;
	                    if(aElement.nodeName=='#text'||aElement.nodeName=='OPTION')return false;
	                    var E=new Function(str);
	                    if(E()){return true;}else{return false};
                    }
    SearchElement(aInElement);
    return Elements;
}
//-----------------------------------------------------------------------------------------------------------
// npcom_getElemementByAttribute
//
//
//-----------------------------------------------------------------------------------------------------------
function npcom_getElementByAttribute(aAttribute,aValue,aSpecial,aInElement)
{
    if (npcom_IsBrowserIE())
    { return npcom_getElementByAttributeIE(aAttribute,aValue,aSpecial,aInElement); }
    
    var ElementVerifier;
    var Elements=new Array();
    if(aInElement==undefined)aInElement=document.body;
    if(aSpecial==undefined)aSpecial="!";
    //if(aValue!="*") alert('GetElementByAttribute: Looking for ' + aAttribute + '=' + aValue + ' In ' + aInElement.nodeName);
    ElementVerifier=function(aElement,aAttribute,aValue,aSpecial)
                    {
                        if(npcom_hasattributes(aElement)==false) {return false;}
                        if(aElement.nodeName=='#text'||aElement.nodeName=='OPTION') {return false;}
                        var attval = npcom_checkforattribute(aElement,aAttribute)
                        if (attval!=undefined)
                        {
                            if (aValue=="*") {return true;}
                            if (aSpecial=="*") 
                            {
                                //alert('ElementVerifier: Element has attribute special check for ' + aValue + ' [' + attval + '] idx=' + attval.indexOf(aValue));
                                if (attval.indexOf(aValue)>=0) {return true;}
                            }
                            if(attval==aValue) {return true;}
                        }    
                        return false;
                    }

    function npcom_SearchElementRecursable(aElement,aAttribute,aValue,aSpecial)
    { 
        if(aElement==null||aElement==undefined)return
        if(ElementVerifier(aElement,aAttribute,aValue,aSpecial))
        { 
            //alert('SearchElementRecursable: Found Element=' + aElement.id);
            Elements[Elements.length]=aElement;
            npcom_SearchElementRecursable(aElement.nextSibling,aAttribute,aValue,aSpecial);
        }
        else
        {
            if(aElement.nodeName!='SELECT') 
            { 
                npcom_SearchElementRecursable(aElement.firstChild,aAttribute,aValue,aSpecial);
            }    
            npcom_SearchElementRecursable(aElement.nextSibling,aAttribute,aValue,aSpecial);
        }  
    }
    npcom_SearchElementRecursable(aInElement,aAttribute,aValue,aSpecial);
    //alert('GetElementByAttribute: SearchElement called!');
    return Elements;
}
//-----------------------------------------------------------------------------------------------------------
// npcom_showbyattribute
//
//
//-----------------------------------------------------------------------------------------------------------
function npcom_showbyattribute(sClient,sShowAttribute)
{
    if(sShowAttribute==undefined)sShowAttribute="OnShow";
    
    var ShowTabElements=npcom_getElementByAttribute(sShowAttribute,sClient,"");
    for (var i=0; i<ShowTabElements.length; i++)
    {
	    ShowTabElements[i].style.display = '';
        dnn.setVar(ShowTabElements[i].id + ':jsvisible', 1);
    }
}	
//-----------------------------------------------------------------------------------------------------------
// npcom_hidebyattribute
//
//
//-----------------------------------------------------------------------------------------------------------
function npcom_hidebyattribute(sClient,sHideAttribute)
{
    if(sHideAttribute==undefined)sHideAttribute="OnHide";
    
    var HideTabElements=npcom_getElementByAttribute(sHideAttribute,sClient,"");
    for (var i=0; i<HideTabElements.length; i++)
    {
	HideTabElements[i].style.display = 'none';
        dnn.setVar(HideTabElements[i].id + ':jsvisible', 0);
    }
}	
//-----------------------------------------------------------------------------------------------------------
// npcom_showbyattributein
//
//
//-----------------------------------------------------------------------------------------------------------
function npcom_showbyattributein(sClient,sShowAttribute,sLookIn)
{
    var xLookIn = dnn.dom.getById(sLookIn);
    if(sShowAttribute==undefined)sShowAttribute="OnShow";
    
    var ShowTabElements=npcom_getElementByAttribute(sShowAttribute,sClient,"",xLookIn);
    for (var i=0; i<ShowTabElements.length; i++)
    {
	ShowTabElements[i].style.display = '';
        dnn.setVar(ShowTabElements[i].id + ':jsvisible', 1);
    }
}	
//-----------------------------------------------------------------------------------------------------------
// npcom_showbyattributein
//
//
//-----------------------------------------------------------------------------------------------------------
function npcom_hidebyattributein(sClient,sHideAttribute,sLookIn)
{
    var xLookIn = dnn.dom.getById(sLookIn);
    if(sHideAttribute==undefined)sHideAttribute="OnHide";
    
    var HideTabElements=npcom_getElementByAttribute(sHideAttribute,sClient,"",xLookIn);
    for (var i=0; i<HideTabElements.length; i++)
    {
	HideTabElements[i].style.display = 'none';
        dnn.setVar(HideTabElements[i].id + ':jsvisible', 0);
    }
}	
//-----------------------------------------------------------------------------------------------------------
// npcom_hideshowbyattribute
//
//
//-----------------------------------------------------------------------------------------------------------
function npcom_hideshowbyattribute(sClient,sShowAttribute,sHideAttribute)
{
    if(sShowAttribute==undefined)sShowAttribute="OnShow";
    if(sHideAttribute==undefined)sHideAttribute="OnHide";
    
    var ShowTabElements=npcom_getElementByAttribute(sShowAttribute,sClient,"");
    for (var i=0; i<ShowTabElements.length; i++)
    {
	    ShowTabElements[i].style.display = '';
        dnn.setVar(ShowTabElements[i].id + ':jsvisible', 1);
    }
    var HideTabElements=npcom_getElementByAttribute(sHideAttribute,sClient,"");
    for (var i=0; i<HideTabElements.length; i++)
    {
	    HideTabElements[i].style.display = 'none';
        dnn.setVar(HideTabElements[i].id + ':jsvisible', 0);
    }
    return false;
}	
//-----------------------------------------------------------------------------------------------------------
// npcom_IsChecked
//
// Returns true if the check box or tick box is checked/ticked.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_IsChecked(aBox)
{
    try
    {
        if (aBox.checked=="checked"||aBox.checked==true)
        { return true; }
        else { return false; }
    }
    catch(x)
    { return false; }
}

//-----------------------------------------------------------------------------------------------------------
// npcom_AddIEHover
//
// Returns true if the check box or tick box is checked/ticked.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_AddIEHover(aElem)
{
    try
    {
	aElem.className+=" iehover";
    }
    catch(x)
    { return false;}
}
//-----------------------------------------------------------------------------------------------------------
// npcom_RemIEHover
//
// Returns true if the check box or tick box is checked/ticked.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_RemIEHover(aElem)
{
    try
    {
	aElem.className=aElem.className.replace(new RegExp(" iehover\\b"), "");
    }
    catch(x)
    { return false;}
}

/**
* This function inserts a text at the current cursor position
* @param string text to insert at current position
* @param DOMElement field in which the value should be inserted
*/
/*
function npcom_insertatcurrentwrapper(sCtl, sText)
{
    var oCtl = dnn.dom.getById(sCtl);
    if (oCtl != null)
    {
        npcom_insertatcurrentposition(sText,oCtl);
    }
}
function npcom_insertatcurrentposition(value, dest)
{
    // for Internet Explorer 
    if (document.selection) 
    {        
        dest.focus();
        var sel = document.selection.createRange();
        sel.text = value;
    }
    // for Mozilla 
    else if (dest.selectionStart || dest.selectionStart == '0')
    {
        var startPos = dest.selectionStart;
        var endPos = dest.selectionEnd;
        dest.value = dest.value.substring(0, startPos) + value
                   + dest.value.substring(endPos, dest.value.length);
    }
    else
    {
        dest.value += value;
    }
}
*/
function npcom_printpreview()
{
    var OLECMDID = 7;
    /* OLECMDID values:
        * 6 - print
        * 7 - print preview
        * 1 - open window
        * 4 - Save As
        */
    var PROMPT = 2; // 2 DONTPROMPTUSER 
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';

    window.onload = "";  
    document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
    WebBrowser1.ExecWB(OLECMDID, PROMPT);
}

function npcom_togglefields(oVis, sCtl1, sCtl2, sCtl3, sCtl4, sCtl5, sCtl6, sCtl7, sCtl8)
{
	//oVis.checked = !oVis.Checked
	var oCtl = dnn.dom.getById(sCtl1);
	if (oCtl != null)
	{
		if (oVis.checked)
		{
			oCtl.style.display = '';
		}
		else
		{
			oCtl.style.display = 'none';
		}
	}	
	
	oCtl = dnn.dom.getById(sCtl2);
	if (oCtl != null)
	{
		if (oVis.checked)
		{
			oCtl.style.display = '';
		}
		else
		{
			oCtl.style.display = 'none';
		}
	}
	oCtl = dnn.dom.getById(sCtl3);
	if (oCtl != null)
	{
		if (oVis.checked)
		{
			oCtl.style.display = '';
		}
		else
		{
			oCtl.style.display = 'none';
		}
	}
	oCtl = dnn.dom.getById(sCtl4);
	if (oCtl != null)
	{
		if (oVis.checked)
		{
			oCtl.style.display = '';
		}
		else
		{
			oCtl.style.display = 'none';
		}
	}
	oCtl = dnn.dom.getById(sCtl5);
	if (oCtl != null)
	{
		if (oVis.checked)
		{
			oCtl.style.display = '';
		}
		else
		{
			oCtl.style.display = 'none';
		}
	}
	oCtl = dnn.dom.getById(sCtl6);
	if (oCtl != null)
	{
		if (oVis.checked)
		{
			oCtl.style.display = '';
		}
		else
		{
			oCtl.style.display = 'none';
		}
	}
	oCtl = dnn.dom.getById(sCtl7);
	if (oCtl != null)
	{
		if (oVis.checked)
		{
			oCtl.style.display = '';
		}
		else
		{
			oCtl.style.display = 'none';
		}
	}
	oCtl = dnn.dom.getById(sCtl8);
	if (oCtl != null)
	{
		if (oVis.checked)
		{
			oCtl.style.display = '';
		}
		else
		{
			oCtl.style.display = 'none';
		}
	}
}

function npcom_toggletablesonstate(sTblShowList)
{
	    var aryTablesShow = sTblShowList.split(';');
	    for (var i=0; i<aryTablesShow.length; i++)
	    {
		if (aryTablesShow[i].length > 0)
		{
	            var sCtl = dnn.dom.getById(aryTablesShow[i]);
	            if (sCtl != null)
	            {
		        if (sCtl.style.display == 'none')
		        {
			    sCtl.style.display = '';
		        }
		        else
		        {
		            sCtl.style.display = 'none';
                	}
	            }	
	        }
    	    }
    	    return false;
}

function npcom_toggletablesoncheck(oVis, sTblShowList)//, sTabPage)
{
	if (oVis != null)
	{
	    var aryTablesShow = sTblShowList.split(';');
	    for (var i=0; i<aryTablesShow.length; i++)
	    {
		if (aryTablesShow[i].length > 0)
		{
	            var sCtl = dnn.dom.getById(aryTablesShow[i]);
	            if (sCtl != null)
	            {
		        if (npcom_IsChecked(oVis))
		        {
	                    //alert('OnCheckToggle IsChecked for ' + oVis.id + ' Checked=' + oVis.checked);
			    sCtl.style.display = '';
		        }
		        else
		        {
	                    //alert('OnCheckToggle IsNotChecked for ' + oVis.id + ' Checked=' + oVis.checked);
		            sCtl.style.display = 'none';
                	}
	            }	
	        }
    	    }
    	    return true;
	}	
	return false;
}
function npcom_handleoncheckcontrol(sClientID, sTblShowList)//, sTabPage)
{
        var oVis = dnn.dom.getById(sClientID);
        return npcom_toggletablesoncheck(oVis, sTblShowList);//, sTabPage);
}
function npcom_verifyoncheckcontrol(aElement)//, sTabPage)
{
        var onchkmaster = npcom_checkforattribute(aElement,"oncheckmaster");
        if (onchkmaster!=undefined) 
        {
            //alert("VerifyOnCheck" + onchkmaster);
            npcom_handleoncheckcontrol(onchkmaster,aElement.id);//, sTabPage);
            return true;
        }
        return false;    
}

function npcom_toggletablesoffcheck(oVis, sTblShowList)
{
	if (oVis != null)
	{
	    var aryTablesShow = sTblShowList.split(';');
	    for (var i=0; i<aryTablesShow.length; i++)
	    {
		if (aryTablesShow[i].length > 0)
		{
	            var sCtl = dnn.dom.getById(aryTablesShow[i]);
	            if (sCtl != null)
	            {
		        if (npcom_IsChecked(oVis))
		        {
	                    //alert('OffCheckToggle IsChecked for ' + oVis.id + ' Checked=' + oVis.checked);
			    sCtl.style.display = 'none';
		        }
		        else
		        {
	                    //alert('OffCheckToggle IsNotChecked for ' + oVis.id + ' Checked=' + oVis.checked);
		            sCtl.style.display = '';
                	}
	            }	
	        }
    	    }
    	    return true;
	}	
	return false;
}
function npcom_handleoffcheckcontrol(sClientID, sTblShowList)
{
        var oVis = dnn.dom.getById(sClientID);
        return npcom_toggletablesoffcheck(oVis, sTblShowList);
}
function npcom_verifyoffcheckcontrol(aElement)
{
        var offchkmaster = npcom_checkforattribute(aElement,"offcheckmaster");
        if (offchkmaster!=undefined) 
        {
            npcom_handleoffcheckcontrol(offchkmaster,aElement.id);
            return true;
        }
        return false;    
}
function npcom_verifyothercontrolvisibility(aElement)
{
        var offchkmaster = npcom_checkforattribute(aElement,"vizmaster");
        if (offchkmaster!=undefined) 
        {
            var xList = dnn.dom.getById(offchkmaster)
            if (xList!=null) 
            {
                /*alert("VizCheck for " + xList.id);*/
                npcom_HandleListVisibilityByAttribute(xList); 
                return true;
            }
        }
        return false;    
}
function npcom_copyselectionto(This, sToCtl, fInFocus)
{
        if (fInFocus==null) { fInFocus=false;}
	var toCtl = dnn.dom.getById(sToCtl);
	if (This!=null&&toCtl!=null)
	{
            var listvalue = This.value;
            var listtext  = This.text;
            toCtl.value = listtext;
            if (fInFocus) { toCtl.focus(); }
        }
}
function npcom_toggletablesnoselection(xList, sTblShowList, sTblHideList)
{
	if (xList != null)
	{
            var listvalue = xList.value;
            //var listvaluestr = parseStr(listvalue);
	    var aryTablesShow = sTblShowList.split(';');
	    for (var i=0; i<aryTablesShow.length; i++)
	    {
		if (aryTablesShow[i].length > 0)
		{
	            var sCtl = dnn.dom.getById(aryTablesShow[i]);
	            if (sCtl != null)
	            {
  	                if (listvalue != null)
  	                {
		            if (listvalue!='0' && listvalue!='')
		            {
			        sCtl.style.display = 'none';
		            }
		            else
		            {
		                sCtl.style.display = '';
                    	    }
                	}
	            }	
	        }
    	    }
	    var aryTablesHide = sTblHideList.split(';');
	    for (var i=0; i<aryTablesHide.length; i++)
	    {
		if (aryTablesHide[i].length > 0)
		{
	            var sCtl = dnn.dom.getById(aryTablesHide[i]);
	            if (sCtl != null)
	            {
  	                if (listvalue != null)
  	                {
		            if (listvalue!='0' && listvalue!='')
		            {
			        sCtl.style.display = '';
		            }
		            else
		            {
		                sCtl.style.display = 'none';
                    	    }
                	}
	            }	
	        }
    	    }
	}	
}
// JScript source code
function npcom_showhidetables(sTblShowList, sTblHideList)
{
        // do hide list first so that if replicated in show list then corrects itself.
        //alert("Hide:" + sTblHideList + " Show:" + sTblShowList)
	var aryTablesHide = sTblHideList.split(';');
	for (var i=0; i<aryTablesHide.length; i++)
	{
		if (aryTablesHide[i].length > 0)
		{
			var hCtl = dnn.dom.getById(aryTablesHide[i]);
			
			if (hCtl != null)
			{
	                //alert("Hiding" + hCtl.id)
			        hCtl.style.display = 'none';
    			        dnn.setVar(hCtl.id + ':jsvisible', 0);
			}	
		}
	}

	var aryTablesShow = sTblShowList.split(';');
	for (var i=0; i<aryTablesShow.length; i++)
	{
		if (aryTablesShow[i].length > 0)
		{
	                var sCtl = dnn.dom.getById(aryTablesShow[i]);
	                if (sCtl != null)
	                {
		               sCtl.style.display = '';
    			       dnn.setVar(sCtl.id + ':jsvisible', 1);
	                }	
	        }
	}
}

// JScript source code
function npcom_shiftfocus(sTo)
{
	var toCtl = dnn.dom.getById(sTo);
	if (toCtl!=null)
	{
            toCtl.focus();
	}
}
function npcom_tickboxfocus(sTickOn, sTickOff)
{
	var onCtl = dnn.dom.getById(sTickOn);
	var offCtl = dnn.dom.getById(sTickOff);
	if (onCtl!=null&&offCtl!=null)
	{
	    var checked = onCtl.checked;
            if (checked==undefined) checked='false';
	    if (checked=='false'||onCtl.style.display=='none') 
	    {
                offCtl.focus();
	    }	
	    else
	    {
                onCtl.focus();
	    }
	}
}
function npcom_tickboxhandle(sTickOn, sTickOff)
{
	var onCtl = dnn.dom.getById(sTickOn);
	var offCtl = dnn.dom.getById(sTickOff);
	if (onCtl!=null&&offCtl!=null)
	{
	    var checked = onCtl.checked;
	    var tbCtl;
            var p,i;  
            if((p=offCtl.id.indexOf("_toff"))>0) 
            {
                i=offCtl.id.substring(0,p);
                //alert("TickBoxStrip: " + i)
                tbCtl = dnn.dom.getById(i);
                if (tbCtl!=null) checked = tbCtl.checked;
            }
            if (checked==undefined) checked='false';
	    // handle case where tickbox is off ... (either on hidden of checked state off)
            //alert("CtlOnState: Tick=" + onCtl.checked + " Disp=" + onCtl.style.display)
	    if (checked=='false'||onCtl.style.display=='none') 
	    {
	        // hide off box
		offCtl.style.display = 'none';
                dnn.setVar(offCtl.id + ':jsvisible', 0);
                // show on box
                onCtl.style.display = '';
                dnn.setVar(onCtl.id + ':jsvisible', 1);
                // set 'control' state
                onCtl.checked='true';
                onCtl.focus();
                if (tbCtl!=null) tbCtl.checked='checked';
	    }	
	    else
	    {
	        // hide on box
		onCtl.style.display = 'none';
                dnn.setVar(onCtl.id + ':jsvisible', 0);
                // show off box
                offCtl.style.display = '';
                dnn.setVar(offCtl.id + ':jsvisible', 1);
                // set 'control' state
                onCtl.checked='false';
                offCtl.focus();
                if (tbCtl!=null) tbCtl.checked=undefined;
	    }
	    //alert("Result tbCtlChecked=" + tbCtl.checked);
	}
}
function npcom_tickboxcontrol(sTickOff)
{
    var tbCtl;
    var p,i;  
    if((p=sTickOff.indexOf("_toff"))>0) 
    {
       i=sTickOff.substring(0,p);
       tbCtl = dnn.dom.getById(i);
    }
    return tbCtl;
}
function npcom_tickboxtsfocus(sTickOn, sTickOff, sTickTS)
{
	var onCtl = dnn.dom.getById(sTickOn);
	var offCtl = dnn.dom.getById(sTickOff);
	var tsCtl = dnn.dom.getById(sTickTS);
	if (onCtl!=null&&offCtl!=null&&tsCtl!=null)
	{
	    var tbCtl = npcom_tickboxcontrol(offCtl.id);
	    var checked;
            if (tbCtl!=null) checked = tbCtl.checked;
            if (checked==undefined) checked='false';
	    if (checked=='notset'||(offCtl.style.display=='none'&&onCtl.style.display=='none'))
	    {
                tsCtl.focus();
                if (tbCtl!=null&&tbCtl.checked==undefined) tbCtl.checked='notset';
	    }	
	    else
	    if (checked=='checked'||(offCtl.style.display=='none'&&tsCtl.style.display=='none'))
	    {
                onCtl.focus();
                if (tbCtl!=null&&tbCtl.checked==undefined) tbCtl.checked='checked';
	    }	
	    else
	    {
                offCtl.focus();
	    }
	}
}
function npcom_tickboxtshandle(sTickOn, sTickOff, sTickTS)
{
	var onCtl = dnn.dom.getById(sTickOn);
	var offCtl = dnn.dom.getById(sTickOff);
	var tsCtl = dnn.dom.getById(sTickTS);
	if (onCtl!=null&&offCtl!=null&&tsCtl!=null)
	{
	    var tbCtl = npcom_tickboxcontrol(offCtl.id);
	    var checked;
            if (tbCtl!=null) checked = tbCtl.checked;
            if (checked==undefined) checked='false';
	    if (checked=='notset'||(offCtl.style.display=='none'&&onCtl.style.display=='none'))
	    {
	        // hide off box
		offCtl.style.display = 'none';
                dnn.setVar(offCtl.id + ':jsvisible', 0);
                // hide TS box
                tsCtl.style.display = 'none';
                dnn.setVar(tsCtl.id + ':jsvisible', 0);
                // show on box
                onCtl.style.display = '';
                dnn.setVar(onCtl.id + ':jsvisible', 1);
                // set 'control' state
                onCtl.focus();
                if (tbCtl!=null) tbCtl.checked='checked';
	    }	
	    else
	    if (checked=='checked'||(offCtl.style.display=='none'&&tsCtl.style.display=='none'))
	    {
	        // hide on box
		onCtl.style.display = 'none';
                dnn.setVar(onCtl.id + ':jsvisible', 0);
	        // hide TS box
		tsCtl.style.display = 'none';
                dnn.setVar(tsCtl.id + ':jsvisible', 0);
                // show off box
                offCtl.style.display = '';
                dnn.setVar(offCtl.id + ':jsvisible', 1);
                // set 'control' state
                offCtl.focus();
                if (tbCtl!=null) tbCtl.checked=undefined;
	    }	
	    else
	    {
	        // hide off box
		offCtl.style.display = 'none';
                dnn.setVar(offCtl.id + ':jsvisible', 0);
                // hide on box
                onCtl.style.display = 'none';
                dnn.setVar(onCtl.id + ':jsvisible', 0);
                // show TS box
                tsCtl.style.display = '';
                dnn.setVar(tsCtl.id + ':jsvisible', 1);
                // set 'control' state
                tsCtl.focus();
                if (tbCtl!=null) tbCtl.checked='notset';
	    }
	    //alert("Result tbCtlChecked=" + tbCtl.checked);
	}
}

function npcom_filtertypes(sClient, cList, cForStr, cForNum, cForBit, cForArr, cForDat, cLS)
{
	var xList = dnn.dom.getById(cList);
	var x4Str = dnn.dom.getById(cForStr);
	var x4Num = dnn.dom.getById(cForNum);
	var x4Arr = dnn.dom.getById(cForArr);
	var x4Bit = dnn.dom.getById(cForBit);
	var x4Dat = dnn.dom.getById(cForDat);
	var x4LS  = dnn.dom.getById(cLS);
	if (xList != null)
	{
	    if (x4Str != null) 
	        x4Str.style.display = 'none';
	    if (x4Dat != null) 
	        x4Dat.style.display = 'none';
	    if (x4Num != null) 
	        x4Num.style.display = 'none';
	    if (x4Bit != null) 
	        x4Bit.style.display = 'none';
	    if (x4Arr != null) 
	        x4Arr.style.display = 'none';
	    if (x4LS != null) 
	        x4LS.style.display = 'none';
	    var listvalue = xList.value;
	    if (listvalue != null)
  	    {
	        var listtype = dnn.getVar(sClient + ":" + listvalue);
	        if (listtype != null)
	        {
    		    if (listtype=='string')
    		    {
        	            if (x4Str != null) 
	                        x4Str.style.display = '';
        	            if (x4LS != null) 
	                        x4LS.style.display = '';
	            }
	            else
    		    if (listtype=='numeric')
    		    {
        	            if (x4Num != null) 
	                       x4Num.style.display = '';
	            }
	            else
    		    if (listtype=='date')
    		    {
        	            if (x4Dat != null) 
	                        x4Dat.style.display = '';
	            }
	            else
    		    if (listtype=='bit')
    		    {
        	            if (x4Bit != null) 
	                        x4Bit.style.display = '';
	            }
	            else
    		    if (listtype=='array')
    		    {
	                    if (x4Arr != null) 
	                        x4Arr.style.display = '';
	            }
  	        }
	    }	
 	}
}

function npcom_filtertypesnew(This, cLookIn, sTypeAttr)
{
    if (sTypeAttr==null || sTypeAttr==undefined) { sTypeAttr = 'ftype'; }
    var xTCtl = dnn.dom.getById(cLookIn);
    var sAttributeType = npcom_findSelectedInputElementAttribute(This,sTypeAttr);
    if (xTCtl==null) { alert('No control matching id ' + cLookIn); }
    var HideTabElements=npcom_getElementByAttribute(sTypeAttr,"*","!",xTCtl);
    for (var i=0; i<HideTabElements.length; i++)
    {
        //alert('Hiding ' + HideTabElements[i].id);
	HideTabElements[i].style.display = 'none';
        dnn.setVar(HideTabElements[i].id + ':jsvisible', 0);
    }
    var ShowTabElements=npcom_getElementByAttribute(sTypeAttr,sAttributeType,"!",xTCtl);
    for (var i=0; i<ShowTabElements.length; i++)
    {
        //alert('Showing ' + ShowTabElements[i].id);
	ShowTabElements[i].style.display = '';
        dnn.setVar(ShowTabElements[i].id + ':jsvisible', 1);
    }
}

function npcom_toggletablesonselectionempty(This, sTblShowList, sTblHideList)
{
    var listvalue = This.value;
    var aryTablesShow = sTblShowList.split(';');
    var noselect = (listvalue=='' || listvalue==undefined || listvalue=='0' || listvalue=='-1');
    //alert('selection empty = ' + noselect);
    for (var i=0; i<aryTablesShow.length; i++)
    {
	if (aryTablesShow[i].length > 0)
	{
            var sCtl = dnn.dom.getById(aryTablesShow[i]);
            if (sCtl != null)
            {
                if (noselect==true)
                {
            	    sCtl.style.display = '';
                    dnn.setVar(sCtl.id + ':jsvisible', 1);
		}
		else
		{
		    sCtl.style.display = 'none';
                    dnn.setVar(sCtl.id + ':jsvisible', 0);
                }
            }
	}	
    }
    var aryTablesHide = sTblHideList.split(';');
    for (var i=0; i<aryTablesHide.length; i++)
    {
	if (aryTablesHide[i].length > 0)
	{
            var sCtl = dnn.dom.getById(aryTablesHide[i]);
            if (sCtl != null)
            {
                if (noselect==true)
                {
            	    sCtl.style.display = 'none';
                    dnn.setVar(sCtl.id + ':jsvisible', 0);
		}
		else
		{
		    sCtl.style.display = '';
                    dnn.setVar(sCtl.id + ':jsvisible', 1);
                }
            }
	}	
    }
}

function npcom_framedtypes(This, cReport, cLookup, cMask, cTemplate, cUseGrid, cSelGrid)
{
	if (This != null)
	{
    	    var x4Rpt = dnn.dom.getById(cReport);
	    var x4Lkp = dnn.dom.getById(cLookup);
	    var x4Msk = dnn.dom.getById(cMask);
	    var x4Tmp = dnn.dom.getById(cTemplate);
	    var x4Grd = dnn.dom.getById(cUseGrid);
	    var x4Sel = dnn.dom.getById(cSelGrid);
	    if (x4Rpt != null) 
	        x4Rpt.style.display = 'none';
	    if (x4Lkp != null) 
	        x4Lkp.style.display = 'none';
	    if (x4Msk != null) 
	        x4Msk.style.display = 'none';
	    if (x4Tmp != null) 
	        x4Tmp.style.display = 'none';
	    if (x4Grd != null) 
	        x4Grd.style.display = 'none';
	    if (x4Sel != null) 
	        x4Sel.style.display = 'none';
	    var listvalue = This.value;
	    //alert ('List Value On Change = ' + listvalue);
	    if (listvalue != null)
  	    {
    	        if (listvalue=='report')
    		{
        	    if (x4Rpt != null) 
	                x4Rpt.style.display = '';
        	    if (x4Msk != null) 
	                x4Msk.style.display = '';
	        }
	        else
    	        if (listvalue=='template')
    		{
        	    if (x4Tmp != null) 
	                x4Tmp.style.display = '';
        	    if (x4Msk != null) 
	                x4Msk.style.display = '';
        	    if (x4Grd != null) 
	                x4Grd.style.display = '';
        	    if (x4Sel != null) 
	                x4Sel.style.display = '';
	        }
	        else
    		if (listvalue=='lookup')
    		{
        	    if (x4Lkp != null) 
	                x4Lkp.style.display = '';
	        }
	    }	
 	}
}

function npcom_XYPos(zxc)
{
    zxcObjLeft = zxc.offsetLeft;
    zxcObjTop = zxc.offsetTop;
    while(zxc.offsetParent!=null)
    {
        zxcObjParent=zxc.offsetParent;
        zxcObjLeft+=zxcObjParent.offsetLeft;
        zxcObjTop+=zxcObjParent.offsetTop;
        zxc=zxcObjParent;
    }
    return [zxcObjLeft,zxcObjTop];
}

function npcom_settextvalue(sCtl, sText)
{
	var oCtl = dnn.dom.getById(sCtl);
	if (oCtl != null)
	{
	    oCtl.value = sText;
	}	
}
function npcom_setimageurl(sCtl, sUrl)
{
	var oIcon = dnn.dom.getById(sCtl);
	if (oIcon != null)
	{
            oIcon.src = sUrl;
        }
}

function npcom_settextvaluetoselected(cCtl, sCtl)
{
	var xCtl = dnn.dom.getById(cCtl);
        var oCtl = dnn.dom.getById(sCtl);
	if (xCtl != null && oCtl != null)
  	{
            var listvalue = oCtl.value;
            //alert(listvalue);
            if (listvalue != null) 
                xCtl.value = listvalue;
            else
                xCtl.value = "";
	}  
}

function npcom_settextvaluetoxpos(cCtl, sCtl)
{
	var xCtl = dnn.dom.getById(cCtl);
	if (xCtl != null || window.event != null)
	{
	    //var cleft = npcom_XPos(xCtl)
	    //var x = window.event.clientX-cleft;
	    var oCtl = dnn.dom.getById(sCtl);
	    if (oCtl != null)
  	    {
  	        var bx = npcom_XYPos(xCtl)[0]
  	        var cx = window.event.x;
  	        if (cx != null) 
	            oCtl.value = parseInt((cx-bx)*100/xCtl.width);
	        else
	            oCtl.value = "0";
	    }	
	}  
}

function npcom_settextvaluetoabsdiff(cCtl1, cCtl2, sCtl, nBothValid)
{
	var xCtl1 = dnn.dom.getById(cCtl1);
	var xCtl2 = dnn.dom.getById(cCtl2);
        var oCtl = dnn.dom.getById(sCtl);
	if (xCtl1 != null && xCtl2 != null && oCtl != null)
	{
            var bx = xCtl1.value;
            var cx = xCtl2.value;
		
            if (nBothValid==1 && ( xCtl1.value=='' || xCtl2.value==''))
            {
                cx = null;
            }
            if (cx != null && bx != null) 
            {
                if (bx-cx>0)
                    oCtl.value = parseInt(bx-cx);
                else
                    oCtl.value = parseInt(cx-bx);	            
	    }
	    else
	        oCtl.value = "";
	}  
}
function npcom_settextvaluetodiff(cCtl1, cCtl2, sCtl, nBothValid)
{
	var xCtl1 = dnn.dom.getById(cCtl1);
	var xCtl2 = dnn.dom.getById(cCtl2);
        var oCtl = dnn.dom.getById(sCtl);
	if (xCtl1 != null && xCtl2 != null && oCtl != null)
	{
            var bx = xCtl1.value;
            var cx = xCtl2.value;
            if (nBothValid==1 && ( xCtl1.value=='' || xCtl2.value==''))
            {
                cx = null;
            }
            else
            {
                if (bx=='') { bx=parseInt(0); }
                if (cx=='') { cx=parseInt(0); }
                //alert('BX=' + bx + ' CX=' + cx);
            }
            if (cx != null && bx != null) 
            {
                oCtl.value = parseInt(bx-cx);
	    }
	    else
	        oCtl.value = "";
	}  
}

function npcom_collecturlfromiconlist(sClient, cList, cIcon)
{
                     //alert(sClient);
	var xList = dnn.dom.getById(cList);
	var xIcon = dnn.dom.getById(cIcon);
	if (xList != null && xIcon != null)
	{
	    var listvalue = xList.value;
	    var listvalueint = parseInt(listvalue);
  	    if (listvalue != null)
  	    {
	        var iconurl = dnn.getVar(sClient + ":" + listvalue);
	        if (iconurl != null)
	        {
  	            xIcon.style.display = '';
  	            xIcon.src = iconurl;
                }
                else
                    xIcon.style.display = 'none';
	    }	
 	}

}

function npcom_handlecountrylist(sClient, cList, cRow, cFlagIcon, cCode, cDial)
{
	var xList = dnn.dom.getById(cList);
	var xFlag = dnn.dom.getById(cFlagIcon);
	var xCode = dnn.dom.getById(cCode);
	var xDial = dnn.dom.getById(cDial);
	var xRow = dnn.dom.getById(cRow);
	if (xList != null && xRow != null)
	{
	    var listvalue = xList.value;
	    if (listvalue != null && listvalue != "" && listvalue != "0")
  	    {
  	        xRow.style.display = '';
	        var iconurl = dnn.getVar(sClient + ":clflag-" + listvalue);
	        if (xFlag != null)
	        {
	          if (iconurl != null)
	          {
  	            xFlag.style.display = '';
  	            xFlag.src = iconurl;
                  }
                  else
                    xFlag.style.display = 'none';
                }    
                var codetxt = dnn.getVar(sClient + ":clcode-" + listvalue);
	        if (xCode != null)
                {
                  if (codetxt != null)
	          {
  	            xCode.style.display = '';
  	            xCode.value = codetxt;
  	            xCode.text = codetxt;
                  }
                  else
                    xCode.style.display = 'none';
                }
                var dialtxt = dnn.getVar(sClient + ":cldial-" + listvalue);
	        if (xDial != null)
                {
                  if (dialtxt != null)
	          {
  	            xDial.style.display = '';
  	            xDial.value = dialtxt;
  	            xDial.text = dialtxt;
                  }
                  else
                    xDial.style.display = 'none';
                }
	    }	
	    else
	    {
                xRow.style.display = 'none';
            }
 	}

}

function npcom_swapImgRestore() { 
  var i,x,a=document.npcom_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function npcom_displayStatusMsg(msgStr) { 
  status=msgStr;
  document.npcom_returnValue = true;
}

function npcom_preloadImages() { 
  var d=document; if(d.images){ if(!d.npcom_p) d.npcom_p=new Array();
    var i,j=d.npcom_p.length,a=npcom_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.npcom_p[j]=new Image; d.npcom_p[j++].src=a[i];}}
}

function npcom_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=npcom_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function npcom_swapImage() 
{ 
    var i,j=0,x,a=npcom_swapImage.arguments; document.npcom_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=npcom_findObj(a[i]))!=null){document.npcom_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function npcom_controlOnCurrentTab(sClient,aElement)
{
  if (aElement==null||aElement==undefined||sClient==null||sClient==undefined) return true;
  var aValue = dnn.getVar(sClient + ":tabselected");
  if(aElement.InTab!=undefined && aElement.InTab.indexOf(aValue)>=0)
  {
    return true;
  }
  else
  {
    return false;
  }
}
function npcom_findSelectedInputElement(aElement)
{
    if(aElement==null||aElement==undefined)return
    var listvalue = aElement.value;
    //alert('Looking in [' + aElement.name + '] for value [' + listvalue + '] with childcount=' + aElement.childNodes.length);
    var resx;
    for (var z=0; z<aElement.childNodes.length; z++)
    {
        var childNode = aElement.childNodes[z];
        //alert('*Child Node Type [' + childNode.nodeName + '] with value [' + childNode.value + ']');
        if (childNode.value==listvalue)
        {
	   resx = childNode;
           //alert('*Found Type [' + childNode.nodeName + '] with value [' + childNode.value + ']');
	   break;
	}   
    }
    return resx;
}
function npcom_findSelectedInputElementAttribute(aElement,sAttr)
{
    if(aElement==null||aElement==undefined)return
    var aSelected = npcom_findSelectedInputElement(aElement);
    var resx;
    if(aSelected==null||aSelected==undefined)return
    //alert('Found Selected Input Element Type [' + aSelected.nodeName + '] Looking for Attribute=' + sAttr + ' where attributelength=' + aSelected.attributes.length);
    for (var z=0; z<aSelected.attributes.length; z++)
    {
        if (aSelected.attributes[z].name==sAttr)
        {
	   resx = aSelected.attributes[z].value;
           //alert('Found Selected Item Attribute[' + resx + ']');
	   break;
	}   
    }
    return resx;
}
function npcom_SetImageOnChange(aElement,sUrlAttr,sImage)
{
    var sAttributeUrl = npcom_findSelectedInputElementAttribute(aElement,sUrlAttr);
    npcom_setimageurlprotected(sImage, sAttributeUrl);
}
function npcom_setimageurlprotected(sCtl, sUrl)
{
    //alert('Update Selected Image [' + sCtl + '] with url=' + sUrl);
    var oIcon = dnn.dom.getById(sCtl);
    if (oIcon != null)
    {
        //alert('Found Selected Image [' + oIcon.id + '] with url=' + sUrl);
        if (sUrl==undefined||sUrl=='') 
        {
            oIcon.style.display = 'none';
        }
        else
        {
            oIcon.src = sUrl;
            oIcon.style.display = '';
        }    
    }
}

function npcom_HandleListTextByAttribute(aElement)
{
    var i = 1;
    for (i=1;i<=5;i++)
    {
        var look = "ctl4txt" + String(i);
        var attr = "txt" + String(i);
        var ctlattribute = npcom_checkforattribute(aElement,look);
        if (ctlattribute==undefined||ctlattribute==null) { /*alert("Does not have attribute");*/ break; }
        npcom_SetTextOnChange(aElement,ctlattribute,attr);
    }
}

function npcom_HandleListVisibilityByAttribute(aElement)
{
    var i = 1;
    for (i=1;i<=5;i++)
    {
        var look = "ctl4viz" + String(i);
        var attr = "viz" + String(i);
        //alert("Looking for " + i + " attrlook=" + look);
        var ctlattribute = npcom_checkforattribute(aElement,look);
        if (ctlattribute==undefined||ctlattribute==null) { /*alert("Does not have attribute");*/break; }
        npcom_SetVisibleOnChange(aElement,ctlattribute,attr);
    }
}

function npcom_SetTextOnChange(aElement,sCtl,sTxtAttr)
{
    var sText = npcom_findSelectedInputElementAttribute(aElement,sTxtAttr);
    //alert('ListText for ' + sCtl + ' Val=' + sText);
    if (sText!=null&&sText!=undefined){ npcom_settextvalue(sCtl,sText); }
}

function npcom_SetVisibleOnChange(aElement,sCtl,sVisAttr)
{
    var oViz = dnn.dom.getById(sCtl);
    if (oViz!=null)
    {
       var sViz = npcom_findSelectedInputElementAttribute(aElement,sVisAttr);
       if (sViz==undefined||sViz=='')
       {
          //alert('ListVisible NoVizAttribute for ' + oViz.id + ' Val=' + sViz);
          oViz.style.display = 'none';
       }
       else
       {
         if (sViz=='0')
         {
           //alert('ListVisible IsNotViz for ' + oViz.id + ' Val=' + sViz);
           oViz.style.display = 'none';
         }
         else
         {
           //alert('ListVisible IsViz for ' + oViz.id + ' Val=' + sViz);
           oViz.style.display = '';
         }    
       }    
    }
}

function npcom_selecttab(sClient,sLookIn,sTab,sTitleText,sTabAttribute)
{
    //alert('SelectTab: Lookin' + sLookIn);
    event.returnValue=false;
    if(sTabAttribute==undefined)sTabAttribute="InTab";
    var cLookIn = dnn.dom.getById(sLookIn);
    //if (cLookIn!=null) { alert('SelectTab: LookInElement=' + cLookIn.nodeName); }
    var AllTabElements=npcom_getElementByAttribute(sTabAttribute,"*","!",cLookIn);
    //alert('SelectTab: TabElements=' + AllTabElements.length);
    for (var i=0; i<AllTabElements.length; i++)
    {
	AllTabElements[i].style.display = 'none';
    }
    var SelectedTabElements=npcom_getElementByAttribute(sTabAttribute,sTab,"*",cLookIn);
    //alert('SelectTab: SelectedElements Array length=' + SelectedTabElements.length);
    for (var i=0; i<SelectedTabElements.length; i++)
    {
        var fSkip = 0;
        if (npcom_verifyoncheckcontrol(SelectedTabElements[i])==true) { /*alert("OnCheckControlTested for " + SelectedTabElements[i].id);*/fSkip=1; }
        if (npcom_verifyoffcheckcontrol(SelectedTabElements[i])==true) { /*alert("OffCheckControlTested for " + SelectedTabElements[i].id);*/fSkip=1; }
        if (npcom_verifyothercontrolvisibility(SelectedTabElements[i])==true) { /*alert("ListCheckControlTested for " + SelectedTabElements[i].id);*/fSkip=1; }
	if (fSkip==0) {/*alert("TabMakingVisible for " + SelectedTabElements[i].id);*/SelectedTabElements[i].style.display = '';}
    }
    
    // updates the client selected state variable ...
    dnn.setVar(sClient + ":tabselected",sTab);
    //alert('SelectTab: Set [' + sClient + ":tabselected" + '] to ' + sTab)

    var AllTabs=npcom_getElementByAttribute("TabOwner",sClient,"!",cLookIn);
    //alert('SelectTab: Items in Owner ' + AllTabs.length);
    for (var i=0; i<AllTabs.length; i++)
    {
        var xtabname = AllTabs[i].getAttribute('TabName');
        //alert('Item=' + AllTabs[i].id + ' in Tab [' + xtabname + ']');
        if (sTab.toLowerCase()!=xtabname.toLowerCase())
        {
            npcom_replaceattribute(AllTabs[i],'class','NPCommonTabLeft_Active','NPCommonTabLeft');
            npcom_replaceattribute(AllTabs[i],'class','NPCommonTabRight_Active','NPCommonTabRight');
            npcom_replaceattribute(AllTabs[i],'class','NPCommonTab_Active','NPCommonTab');
        }
        else
        {
            npcom_replaceattribute(AllTabs[i],'class','NPCommonTabLeft','NPCommonTabLeft_Active');
            npcom_replaceattribute(AllTabs[i],'class','NPCommonTabRight','NPCommonTabRight_Active');
            npcom_replaceattribute(AllTabs[i],'class','NPCommonTab','NPCommonTab_Active');
        }
    }
    var titlebarname = dnn.getVar(sClient + ":tabtitlebar");
    //alert('SelectTab: TitleBar=' + titlebarname + ' set to ' + sTitleText);
    var cTitleBar = dnn.dom.getById(titlebarname);
    if (cTitleBar != null && sTitleText != undefined)
    {
	cTitleBar.value = sTitleText;
    }    
    //return false;
}

function npcom_showhideexception(cIconControl)
{
    var AllExcElements=npcom_getElementByAttribute("exceptionrow","*");
    for (var i=0; i<AllExcElements.length; i++)
    {
	AllExcElements[i].style.display = 'none';
    }
    if (cIconControl != null)
    {
        //alert('Client= Tab=' + cIconControl.id);
        var p,i,x,y;  
        if((p=cIconControl.id.indexOf("excicon"))>0) 
        {
            i=cIconControl.id.substring(0,p);
            x=cIconControl.id.substring(p+7);
            y=i+"excinfo"+x;
	    var hCtl = dnn.dom.getById(y);
	    if (hCtl != null)
	    {
                if (hCtl.id!=dnn.getVar("exceptionviewselected"))
                {
	            hCtl.style.display = '';
    	            dnn.setVar("exceptionviewselected",hCtl.id);
    	        }
    	        else
    	        {
	            hCtl.style.display = 'none';
    	            dnn.setVar("exceptionviewselected","none");
    	        }
	    }	
        }
    }
    return false;
}

function npcom_numericinput(This, AllowDot, AllowMinus)
{
    // on timeout 'minus' validation
    if(arguments.length == 1)
    {
       	var s = This.value;
       	// if "-" exists then it better be the 1st character
       	var i = s.lastIndexOf("-");
       	if(i == -1)
            return;
        if(i != 0)
            This.value = s.substring(0,i)+s.substring(i+1);
        return;
    }
    var code = event.keyCode;
    //alert('code = ' + code);
    switch(code)
    {
        case 8:     // backspace
        case 37:    // left arrow
        case 39:    // right arrow
        case 46:    // delete
        case 9:     // tab
            event.returnValue=true;
            return;
    }
    if(code == 189||code == 109)     // minus sign
    {
      	if(AllowMinus == false)
       	{
            event.returnValue=false;
            return;
        }
        // wait until the element has been updated to see if the minus is in the right spot
        var s = "npcom_numericinput(dnn.dom.getById('"+This.id+"'))";
        setTimeout(s, 250);
        return;
    }
    if(AllowDot && (code==190||code==110))
    {
        if(This.value.indexOf(".") >= 0)
        {
            // don't allow more than one dot
            event.returnValue=false;
            return;
        }
        event.returnValue=true;
        return;
    }
    // allow character of between 0 and 9 (including keypad codes)
    if((code >= 48 && code <= 57)||(code >= 96 && code <= 105))
    {
        event.returnValue=true;
        return;
    }
    event.returnValue=false;
}
function npcom_preventbackspace(This)
{
    var code = event.keyCode;
    //alert('code = ' + code);
    switch(code)
    {
        case 8:     // backspace
            event.returnValue=false;
            return;
    }
    event.returnValue=true;
}
function npcom_preventCR(This)
{
    var code = event.keyCode;
    switch(code)
    {
        case 13:    // cr
            event.keyCode=9; //tab
    }
}

/*

'*******************************************************************************
'Name:          FxnGenDateChange
'
'Returns:       True if the date control is updated, otherwise False.
'
'Parameter:     p_DateCtl As Control        Data in this control is converted.
'
'Description:
'If the control text is X- or X+ where X is a number, sets the date to today
'minus or plus X days.  Also sets it to minus/plus X days if the text is -X,
'--X, ---X, +X, ++X or +++X and X has the same number of digits to the -'s or
'+'s.  Otherwise, depending on the setting in TblApplication, converts the
'control data from ddmm, ddmmyy, mmdd or mmddyy to a date.  When ddmm and mmdd
'are used, the year is set based on the range 90 days forward and 275 days back
'from today.
'
'Last Updated:  Andrew Whittam
'               9/6/08
'*******************************************************************************
Public Function FxnGenDateChange(p_DateCtl As Control) As Boolean
    On Error GoTo Err_FxnGenDateChange
    Dim l_SystemDB As Database, l_RS As Recordset, l_KeyName As String, l_SystemFilePath As String, l_Msg As String
    Dim l_DateConversion As Byte, l_Date As Date, l_Len As Long, l_Dummy As Boolean, l_xx As Integer, l_Frm As Form, l_SetFrm As Boolean

    FxnGenDateChange = False
    
    l_Len = Len(p_DateCtl.Text)
    
    If l_Len > 1 And l_Len < 4 Then
        If Right(p_DateCtl.Text, 1) = "-" Then
            If IsNumeric(Left(p_DateCtl.Text, l_Len - 1)) Then
                l_Date = Date - CLng(Left(p_DateCtl.Text, l_Len - 1))
                FxnGenDateChange = True
            End If
        ElseIf Right(p_DateCtl.Text, 1) = "+" Then
            If IsNumeric(Left(p_DateCtl.Text, l_Len - 1)) Then
                l_Date = Date + CLng(Left(p_DateCtl.Text, l_Len - 1))
                FxnGenDateChange = True
            End If
        End If
    End If
    
    If Not FxnGenDateChange Then
        If l_Len = 2 And Left(p_DateCtl.Text, 1) = "-" Then
            If IsNumeric(Right(p_DateCtl.Text, 1)) Then
                l_Date = Date - CLng(Right(p_DateCtl.Text, 1))
                FxnGenDateChange = True
            End If
        ElseIf l_Len = 2 And Left(p_DateCtl.Text, 1) = "+" Then
            If IsNumeric(Right(p_DateCtl.Text, 1)) Then
                l_Date = Date + CLng(Right(p_DateCtl.Text, 1))
                FxnGenDateChange = True
            End If
        ElseIf l_Len = 4 And Left(p_DateCtl.Text, 2) = "--" Then
            If IsNumeric(Right(p_DateCtl.Text, 2)) Then
                l_Date = Date - CLng(Right(p_DateCtl.Text, 2))
                FxnGenDateChange = True
            End If
        ElseIf l_Len = 4 And Left(p_DateCtl.Text, 2) = "++" Then
            If IsNumeric(Right(p_DateCtl.Text, 2)) Then
                l_Date = Date + CLng(Right(p_DateCtl.Text, 2))
                FxnGenDateChange = True
            End If
        ElseIf l_Len = 6 And Left(p_DateCtl.Text, 3) = "---" Then
            If IsNumeric(Right(p_DateCtl.Text, 3)) Then
                l_Date = Date - CLng(Right(p_DateCtl.Text, 3))
                FxnGenDateChange = True
            End If
        ElseIf l_Len = 6 And Left(p_DateCtl.Text, 3) = "+++" Then
            If IsNumeric(Right(p_DateCtl.Text, 3)) Then
                l_Date = Date + CLng(Right(p_DateCtl.Text, 3))
                FxnGenDateChange = True
            End If
        End If
    End If
    
    If Not FxnGenDateChange Then
        l_KeyName = "Software\2ic Software\" & CStr(FxnGenGetValue("Ap_Application", "TblApplication")) & "\" _
                    & Format$(Int(CCur(FxnGenGetValue("Ap_Version", "TblApplication"))), "General Number")
        l_SystemFilePath = QueryValue(l_KeyName & "\Application", "System File", HKEY_LOCAL_MACHINE)
        On Error Resume Next
        Set l_SystemDB = DBEngine.Workspaces(0).OpenDatabase(l_SystemFilePath, False, False, ";pwd=cpa6164")
        If Err = 3024 Then      'Couldn't find file '....'.
            l_Msg = "A " & CStr(FxnGenGetValue("Ap_Application", "TblApplication")) & " system file is missing.  Please re-install the application."
            MsgBox l_Msg, vbExclamation + vbOKOnly, "Cannot Find System File"
            GoTo Exit_FxnGenDateChange
        ElseIf Err <> 0 Then
            GoTo Err_FxnGenDateChange
        End If
        On Error GoTo Err_FxnGenDateChange
        Set l_RS = l_SystemDB.OpenRecordset("TblApplication")
        With l_RS
            .MoveFirst
            l_DateConversion = CByte(!Ap_DateConversion)
            .Close
        End With
        Set l_SystemDB = Nothing
        Select Case l_DateConversion
            Case 1      'ddmm.
                If l_Len = 4 Then
                    If IsNumeric(p_DateCtl.Text) Then
                        l_Date = DateSerial(Year(Date), Right(p_DateCtl.Text, 2), Left(p_DateCtl.Text, 2))
                        If l_Date - Date > 90 Then          'More than 90 days ahead of today.
                            l_Date = DateSerial(Year(l_Date) - 1, Month(l_Date), Day(l_Date))
                        ElseIf Date - l_Date > 275 Then     'More than 275 days before of today.
                            l_Date = DateSerial(Year(l_Date) + 1, Month(l_Date), Day(l_Date))
                        End If
                        FxnGenDateChange = True
                    End If
                End If
            Case 2      'ddmmyy.
                If l_Len = 6 Then
                    If IsNumeric(p_DateCtl.Text) Then
                        l_Date = DateSerial(Right(p_DateCtl.Text, 2), Mid(p_DateCtl.Text, 3, 2), Left(p_DateCtl.Text, 2))
                        FxnGenDateChange = True
                    End If
                End If
            Case 3      'mmdd.
                If l_Len = 4 Then
                    If IsNumeric(p_DateCtl.Text) Then
                        l_Date = DateSerial(Year(Date), Left(p_DateCtl.Text, 2), Right(p_DateCtl.Text, 2))
                        If l_Date - Date > 90 Then          'More than 90 days ahead of today.
                            l_Date = DateSerial(Year(l_Date) - 1, Month(l_Date), Day(l_Date))
                        ElseIf Date - l_Date > 275 Then     'More than 275 days before of today.
                            l_Date = DateSerial(Year(l_Date) + 1, Month(l_Date), Day(l_Date))
                        End If
                        FxnGenDateChange = True
                    End If
                End If
            Case 4      'mmddyy.
                If l_Len = 6 Then
                    If IsNumeric(p_DateCtl.Text) Then
                        l_Date = DateSerial(Right(p_DateCtl.Text, 2), Left(p_DateCtl.Text, 2), Mid(p_DateCtl.Text, 3, 2))
                        FxnGenDateChange = True
                    End If
                End If
        End Select
    End If
    
    If FxnGenDateChange Then
        p_DateCtl = l_Date
        l_SetFrm = False
        For l_xx = 1 To 5       'Should be enough levels.
            On Error Resume Next
            Select Case l_xx
                Case 1:     If Left$(p_DateCtl.Parent.Name, 3) = "Frm" Then l_SetFrm = True
                Case 2:     If Left$(p_DateCtl.Parent.Parent.Name, 3) = "Frm" Then l_SetFrm = True
                Case 3:     If Left$(p_DateCtl.Parent.Parent.Parent.Name, 3) = "Frm" Then l_SetFrm = True
                Case 4:     If Left$(p_DateCtl.Parent.Parent.Parent.Parent.Name, 3) = "Frm" Then l_SetFrm = True
                Case 5:     If Left$(p_DateCtl.Parent.Parent.Parent.Parent.Parent.Name, 3) = "Frm" Then l_SetFrm = True
            End Select
            If Err <> 0 Then
                If Err = 2452 Then      'The expression you entered has an invalid reference to the Parent property.
                    GoTo Exit_FxnGenDateChange
                Else
                    GoTo Err_FxnGenDateChange
                End If
            End If
            On Error GoTo Err_FxnGenDateChange
            If l_SetFrm Then
                Select Case l_xx
                    Case 1:     Set l_Frm = p_DateCtl.Parent
                    Case 2:     Set l_Frm = p_DateCtl.Parent.Parent
                    Case 3:     Set l_Frm = p_DateCtl.Parent.Parent.Parent
                    Case 4:     Set l_Frm = p_DateCtl.Parent.Parent.Parent.Parent
                    Case 5:     Set l_Frm = p_DateCtl.Parent.Parent.Parent.Parent.Parent
                End Select
                If p_DateCtl.AfterUpdate = "[Event Procedure]" Then CallByName l_Frm, p_DateCtl.Name & "_AfterUpdate", VbMethod
                Exit For
            End If
        Next l_xx
    End If
    
Exit_FxnGenDateChange:
    Exit Function
Err_FxnGenDateChange:
    Call PrcGenErrorBox(k_AccessError, "Utilities.FxnGenDateChange", Error$, Err)
    Resume Exit_FxnGenDateChange
End Function
*/
function npcom_IsNumeric(vTestValue)
{
	// put the TEST value into a string object variable
	var sField = new String(vTestValue);
	// alert('Field[' + sField + ']Len=' + sField.length);
	if(sField.length==0) 
	{ return false; }
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) 
	{ return false; }
	
	// loop through each character of the string
	for(var x=0; x < sField.length; x++) 
	{
	   // if the character is < 0 or > 9, return false (not a number)
	   if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) == '-' && x==0)) 
	   { /* do nothing */ }
	   else 
	   { return false; }
	}
	// made it through the loop - we have a number
	return true;
}

function npcom_dateshortcuts(This, Day, Month, Year, DateConversion, DateFormat, AllowRelative)
{
    var TypedNeedsConvert = false;
    var TypedDay,TypedMonth,TypedYear;
    var TypedValue = This.value;
    if (AllowRelative==null) { AllowRelative=true;}
    if (AllowRelative)
    {
        var DeltaDays = parseInt(0);
        if (DeltaDays==0 && TypedValue.length==6 && TypedValue.lastIndexOf("---")==0)
        { DeltaDays=parseInt(TypedValue.substring(3,6),10); DeltaDays = -DeltaDays;}
        if (DeltaDays==0 && TypedValue.length==4 && TypedValue.lastIndexOf("--")==0)
        { DeltaDays=parseInt(TypedValue.substring(2,4),10); DeltaDays = -DeltaDays; }
        if (DeltaDays==0 && TypedValue.length==2 && TypedValue.lastIndexOf("-")==0)
        { DeltaDays=parseInt(TypedValue.substring(1,2),10); DeltaDays = -DeltaDays;}
        if (DeltaDays==0 && TypedValue.length==6 && TypedValue.lastIndexOf("+++")==0)
        { DeltaDays=parseInt(TypedValue.substring(3,6),10); }
        if (DeltaDays==0 && TypedValue.length==4 && TypedValue.lastIndexOf("++")==0)
        { DeltaDays=parseInt(TypedValue.substring(2,4),10); }
        if (DeltaDays==0 && TypedValue.length==2 && TypedValue.lastIndexOf("+")==0)
        { DeltaDays=parseInt(TypedValue.substring(1,2),10); }
        if (DeltaDays!=0)
        {
            //alert('Delta = ' + DeltaDays + ' where TV = ' + TypedValue + ' From = '+ Day+'/'+Month+'/'+Year);
            var Result = npcom_adddays(Day,Month,Year,DeltaDays).split(",");
            TypedDay = Result[0];
            TypedMonth = Result[1];
            TypedYear = Result[2];
            //alert('Delta = ' + DeltaDays + ' Result = '+ TypedDay+'/'+TypedMonth+'/'+TypedYear);
            TypedNeedsConvert=true;
        }
    }
    
    if (TypedNeedsConvert==false)
    {
      switch(DateConversion)
      {
        case 1:     // ddmm
            if (TypedValue.length==4 && npcom_IsNumeric(TypedValue))
            {
                TypedDay=parseInt(TypedValue.substring(0,2),10);
                TypedMonth=parseInt(TypedValue.substring(2,4),10);
                // correct month
                if (TypedMonth==0) { TypedMonth=1;}
                if (TypedMonth>12) { TypedMonth=12;}
                // correct day
                var LDOM = npcom_lastdayofmonth(TypedMonth,Year);
                if (TypedDay>LDOM) {TypedDay=LDOM;}
                if (TypedDay==0) {TypedDay=1;}
                TypedYear=Year;
                var Result = npcom_deltadays(Day,Month,Year,TypedDay,TypedMonth,Year);
                // now test for 90 days more, then it is last year
                if (Result>90) {TypedYear-=1;}
                if (Result<-275) { TypedYear+=1;} 
                TypedNeedsConvert=true;
            }
            break;
        case 3:     // mmdd
            if (TypedValue.length==4&&npcom_IsNumeric(TypedValue))
            {
                TypedMonth=parseInt(TypedValue.substring(0,2),10);
                TypedDay=parseInt(TypedValue.substring(2,4),10);
                if (TypedMonth==0) { TypedMonth=1;}
                if (TypedMonth>12) { TypedMonth=12;}
                TypedYear=Year;
                var Result = npcom_deltadays(Day,Month,Year,TypedDay,TypedMonth,Year);
                // now test for 90 days more, then it is last year
                if (Result>90) {TypedYear-=1;}
                if (Result<-275) { TypedYear+=1;} 
                TypedNeedsConvert=true;
            }
            break;
        case 2:     // ddmmyy
            if (TypedValue.length==6&&npcom_IsNumeric(TypedValue))
            {
                TypedDay=parseInt(TypedValue.substring(0,2),10);
                TypedMonth=parseInt(TypedValue.substring(2,4),10);
                if (TypedMonth==0) { TypedMonth=1;}
                if (TypedMonth>12) { TypedMonth=12;}
                TypedYear=parseInt(TypedValue.substring(4,6),10);
                TypedNeedsConvert=true;
            }
            break;
        case 4:     // mmddyy
            if (TypedValue.length==6&&npcom_IsNumeric(TypedValue))
            {
                TypedMonth=parseInt(TypedValue.substring(0,2),10);
                TypedDay=parseInt(TypedValue.substring(2,4),10);
                if (TypedMonth==0) { TypedMonth=1;}
                if (TypedMonth>12) { TypedMonth=12;}
                TypedYear=parseInt(TypedValue.substring(4,6),10);
                TypedNeedsConvert=true;
            }
            break;
      }
    }  
    if (TypedNeedsConvert==true)
    {
        var LDOM = npcom_lastdayofmonth(TypedMonth,TypedYear);
        if (LDOM>0)
        {
            //alert('LDOM = ' + LDOM + ' For = '+ TypedDay+'/'+TypedMonth+'/'+TypedYear);
            if (TypedDay>LDOM) {TypedDay=LDOM;}
            if (TypedDay==0) {TypedDay=1;}
        }    
        return npcom_dateupdate(This,TypedDay,TypedMonth,TypedYear,Year,DateFormat);
    }
    event.returnValue=true;
}
function npcom_dateinput(This,Day,Month,Year,DateFormat,AllowRelative)
{
    // on timeout 'minus'/'plus' validation
    if(arguments.length == 1)
    {
       	var s = This.value;
       	// if "-" exists then it better be the 1st character
       	var m1 = s.lastIndexOf("-");
       	var p1 = s.lastIndexOf("+");
       	var m2 = s.lastIndexOf("--");
       	var p2 = s.lastIndexOf("++");
       	var m3 = s.lastIndexOf("---");
       	var p3 = s.lastIndexOf("+++");
       	if(m1<0&&m2<0&&m3<0&&p1<0&&p2<0&&p3<0)
            return;
        if(m3>0)
        { This.value = s.substring(0,m3)+s.substring(m3+3); }
        else if(m2>0&&m3<0)
        { This.value = s.substring(0,m2)+s.substring(m2+2); }
        else if(m1>0&&m3<0&&m2<0)
        { This.value = s.substring(0,m1)+s.substring(m1+1); }
        if(p3>0)
        { This.value = s.substring(0,p3)+s.substring(p3+3); }
        else if(p2>0&&p3<0)
        { This.value = s.substring(0,p2)+s.substring(p2+2); }
        else if(p1>0&&p3<0&&p2<0)
        { This.value = s.substring(0,p1)+s.substring(p1+1); }
        return;
    }
    if (AllowRelative==null) { AllowRelative=true;}

    var code = event.keyCode;
    //alert(code);
    switch(code) // for selected keys we will skip processing ...
    {
        case 8:     // backspace
        case 37:    // left arrow
        case 39:    // right arrow
        case 46:    // delete
        case 9:     // tab
        case 190:   // dot
        case 191:   // fwdslash
        case 220:   // bckslash
        case 111:   // bckslash keypad
        case 110:   // dot keypad
        case 35:    // end
        case 36:    // home
            event.returnValue=true;
            return;
    }
    if(code==186&&event.ctrlKey)
    {
        var TypedDay=Day;
        var TypedMonth=Month;
        var TypedYear=Year;
        npcom_dateupdate(This,TypedDay,TypedMonth,TypedYear,Year,DateFormat);
        event.returnValue=false;
        return;
    }
    if((code==189||code==187||code==109||code==107)&&AllowRelative)  // minus/plus sign (inc keypad)
    {
        // wait until the element has been updated to see if the minus is in the right spot
        var s = "npcom_dateinput(dnn.dom.getById('"+This.id+"'))";
        setTimeout(s, 250);
        return;
    }
    // allow character of between 0 and 9 (including keypad codes)
    if((code >= 48 && code <= 57)||(code >= 96 && code <= 105))
    {
        event.returnValue=true;
        return;
    }
    event.returnValue=false;
}
function npcom_dateupdate(This, TypedDay, TypedMonth, TypedYear, Year, DateFormat)
{
    //alert('update d=' + TypedDay + ' m=' + TypedMonth + ' y=' + TypedYear + ' Form = ' + DateFormat);
    var DateResult = new String(DateFormat);
    var digDay = 2;
    var indDay = DateFormat.indexOf("dd");
    if (indDay<0) { indDay = DateFormat.indexOf("d"); digDay=1; }
    var strDay = String(TypedDay);
    if (TypedDay<10&&digDay>1){ strDay = "0"+TypedDay; }
    DateResult = DateResult.replace('dd',strDay);
    DateResult = DateResult.replace('d',strDay); // if above didn't do it.
    var digMon = 2;
    var indMon = DateFormat.indexOf("mm");
    if (indMon<0) { indMon = DateFormat.indexOf("m"); digMon=1; }
    var strMon = new String(TypedMonth);
    if (TypedMonth<10&&digMon>1){ strMon = "0"+TypedMonth; }
    DateResult = DateResult.replace("mm",strMon);
    DateResult = DateResult.replace("m",strMon); // if above didn't do it.
    var digYear = 4;
    var indYear = DateFormat.indexOf("yyyy");
    if (indYear<0) { indYear = DateFormat.indexOf("yy"); digYear=2; }
    var strYear = new String(TypedYear);
    var strCrYr = new String(Year);
    if (TypedYear<100&&digYear>2){ strMon = strCrYr.substring(0,2)+TypedYear; }
    DateResult = DateResult.replace("yyyy",strYear);
    DateResult = DateResult.replace("yy",strYear); // if above didn't do it.
    //alert('updatestrs d=' + strDay + ' m=' + strMon + ' y=' + strYear);
    //This.Value = DateResult;
    //alert('result=' + DateResult);
    var s = "npcom_settextvalue('"+This.id+"','"+DateResult+"')";
    setTimeout(s, 100);
}
function npcom_setpagefocus(sPage)
{

    var ctltofocus = dnn.getVar(sPage + ":npctltofocus");
    //alert("var =" + ctltofocus);
    if (ctltofocus!=null) { npcom_shiftfocus(ctltofocus); }
}
function npcom_focusbkgd(This,sTo)
{
    dnn.setVar(This.id + ':nporigbkgd', This.style.backgroundColor);  	            
    This.style.backgroundColor=sTo;
    //alert(This.is + ' origbg=' + dnn.getVar(This.id + ':nporigbkgd'));
}
function npcom_revertbkgd(This)
{
    This.style.backgroundColor=dnn.getVar(This.id + ':nporigbkgd');
}
function npcom_focusbord(This,sTo)
{
    dnn.setVar(This.id + ':nporigbord', This.style.borderColor);  	            
    dnn.setVar(This.id + ':nporigbordw', This.style.borderWidth);  	            
    This.style.borderColor=sTo;
    This.style.borderWidth='2px';
}
function npcom_revertbord(This,sTo)
{
    This.style.borderColor=dnn.getVar(This.id + ':nporigbord');
    This.style.borderWidth=dnn.getVar(This.id + ':nporigbordw');
}
function npcom_isleapyear(vYear)
{
    var Year = parseInt(vYear);
    //alert('LpYr Test Year['+vYear+'] Now['+Year+']');
    var divby4 = Year/4;
    var divby4x = Math.floor(Year/4);
    var is4thyear = (divby4==divby4x);
    var divby100 = Year/100;
    var divby100x = Math.floor(Year/100);
    var is100thyear = (divby100==divby100x);
    var divby1000 = Year/1000;
    var divby1000x = Math.floor(Year/1000);
    var is1000thyear = (divby1000==divby1000x);
    return ((is4thyear==true&&is100thyear==false)||(is1000thyear==true)); 
}
function npcom_lastdayofmonth(vMonth,vYear)
{
    var Month = parseInt(vMonth);
    //alert('LDOM Test Month['+vMonth+']['+vYear+'] Now['+Month+']');
    switch(Month)
    {
        case 1: {return 31;}
        case 2: if (npcom_isleapyear(vYear)) {return 29;} else { return 28; }
        case 3: {return 31;}
        case 4: {return 30;}
        case 5: {return 31;}
        case 6: {return 30;}
        case 7: {return 31;}
        case 8: {return 31;}
        case 9: {return 30;}
        case 10: {return 31;}
        case 11: {return 30;}
        case 12: {return 31;}
    }
    return 0;
}
function npcom_adddays(Day,Month,Year,DayDelta)
{
    var limit=1000;
    if (DayDelta!=0)
    {
        if (DayDelta<0)
        {
            while ((++DayDelta)<=0&&(limit--)>0)
            {
                Day-=1;
                if (Day==0)
                {
                    Month -= 1;
                    if (Month==0) { Year-=1; Month=12; }
                    Day = npcom_lastdayofmonth(Month,Year);
                }
            }
        }
        else
        {
            while ((--DayDelta)>=0&&(limit--)>0)
            {
                Day+=1;
                if (Day>npcom_lastdayofmonth(Month,Year))
                {
                    Month += 1;
                    if (Month==13) { Year+=1; Month=1; }
                    Day = 1;
                }
            }
        }
    }
    return Day+','+Month+','+Year;
}
function npcom_deltadays(Day1,Month1,Year1,Day2,Month2,Year2)
{
    var limit=9000;
    var DayDelta=0;
    var Day,Month,Year;
    var Compared = npcom_comparedates(Day1,Month1,Year1,Day2,Month2,Year2);
    if (Compared>0) // Date2 is earlier, start at Date1 and go down to Date2
    {
        Day=Day1;
        Month=Month1;
        Year=Year1;
        while (((limit--)>0)&&!(Day==Day2&&Month==Month2&&Year==Year2))
        {
           Day-=1;
           if (Day==0)
           {
              Month -= 1;
              if (Month==0) { Year-=1; Month=12; }
              Day = npcom_lastdayofmonth(Month,Year);
           }
           DayDelta-=1;
        }
    }
    else if (Compared<0) // Date1 is earlier, start at Date2 and go down to Date1
    {
        Day=Day2;
        Month=Month2;
        Year=Year2;
        while (((limit--)>0)&&!(Day==Day1&&Month==Month1&&Year==Year1))
        {
           Day-=1;
           if (Day==0)
           {
              Month -= 1;
              if (Month==0) { Year-=1; Month=12; }
              Day = npcom_lastdayofmonth(Month,Year);
           }
           DayDelta+=1;
        }
    }
    return DayDelta;
}
function npcom_comparedates(Day1,Month1,Year1,Day2,Month2,Year2)
{
    var result = 0;
    if (Year1<Year2) { result=-1; } // Date 1 < Date 2
    else if (Year1>Year2) { result=1; } // Date 1 > Date 2
    else // Same Year
    {
        if (Month1<Month2) { result=-1; } // Date 1 < Date 2
        else if (Month1>Month2) { result=1;  } // Date 1 > Date 2
        else // Same Month
        {
            if (Day1<Day2) { result=-1; } // Date 1 < Date 2
            else if (Day1>Day2) { result=1; } // Date 1 > Date 2
            else {} // Same Day - leave as 0
        }
    }
//    alert('Compare ' + Day1+'/'+Month1+'/'+Year1 + ' to ' + Day2+'/'+Month2+'/'+Year2 + ' result=' + result)
    return result;
}
//-----------------------------------------------------------------------------------------------------------
// npcom_CollectClientTimeInfo
//
// Fills java variables with client time specific information.
//
//-----------------------------------------------------------------------------------------------------------
function npcom_CollectClientTimeInfo(sClientID,fReload) 
{
    try
    { 
        if (fReload==null || fReload==undefined) { fReload=false; }
        var clntNow = new Date();
        var date1 = new Date(clntNow.getFullYear(), 0, 1, 0, 0, 0, 0);
        var date2 = new Date(clntNow.getFullYear(), 6, 1, 0, 0, 0, 0);
        var temp = date1.toGMTString();
        var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
        var temp = date2.toGMTString();
        var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
        var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
        var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);
        var hoursDiffJanTime = hoursDiffStdTime;
        var hoursDiffJulTime = hoursDiffDaylightTime;

        if (hoursDiffStdTime>hoursDiffDaylightTime>0)
        {
            var tmp = hoursDiffStdTime;
            hoursDiffStdTime = hoursDiffDaylightTime;
            hoursDiffDaylightTime = hoursDiffStdTime;
        }
       
        var sLocalCtl = dnn.getVar(sClientID + ":LocalCtl");
        if (sLocalCtl!=null && sLocalCtl!=undefined && sLocalCtl!='')
        {
            var xLocalCtl = dnn.dom.getById(sLocalCtl);
            if (xLocalCtl!=null) { xLocalCtl.value =  clntNow.toLocaleString(); }
        }
        var sLocalTime = clntNow.getDate() + "," + String(clntNow.getMonth()+1) + "," + clntNow.getFullYear() + "," + clntNow.getHours() + "," + clntNow.getMinutes()
        dnn.setVar(sClientID + ":LocalTime",sLocalTime);
        
        var sLocalUTC = clntNow.getUTCDate() + "," + String(clntNow.getUTCMonth()+1) + "," + clntNow.getUTCFullYear() + "," + clntNow.getUTCHours() + "," + clntNow.getUTCMinutes()
        dnn.setVar(sClientID + ":LocalUTC",sLocalUTC);

        var sTZNCtl = dnn.getVar(sClientID + ":TZNCtl");
        if (sTZNCtl!=null && sTZNCtl!=undefined && sTZNCtl!='')
        {
            var xTZNCtl = dnn.dom.getById(sTZNCtl);
            if (xTZNCtl!=null) 
            { 
                xTZNCtl.value = "Jan: " + String(hoursDiffJanTime) + " Jul: " + String(hoursDiffJulTime);
            }
        }
        dnn.setVar(sClientID + ":LocalTZN","1," + String(hoursDiffJanTime) + ",7," + String(hoursDiffJulTime));

        var sTZOCtl = dnn.getVar(sClientID + ":TZOCtl");
        if (sTZOCtl!=null && sTZOCtl!=undefined && sTZOCtl!='')
        {
            var xTZOCtl = dnn.dom.getById(sTZOCtl);
            if (xTZOCtl!=null) 
            { 
                if (hoursDiffStdTime>=0)
                { xTZOCtl.value = "GMT +" + hoursDiffStdTime; } else { xTZOCtl.value = "GMT " + hoursDiffStdTime; }
            }
        }
        dnn.setVar(sClientID + ":LocalTZO",String(hoursDiffStdTime));

        var sDSUCtl = dnn.getVar(sClientID + ":DSUCtl");
        if (sDSUCtl!=null && sDSUCtl!=undefined && sDSUCtl!='')
        {
            var xDSUCtl = dnn.dom.getById(sDSUCtl);
            if (xDSUCtl!=null) 
            {
                if (hoursDiffDaylightTime == hoursDiffStdTime) 
                { xDSUCtl.value = "No"; } else { xDSUCtl.value = "Yes"; } 
            }
        }
        if (hoursDiffDaylightTime == hoursDiffStdTime) 
        { dnn.setVar(sClientID + ":LocalDSU","No"); } else { dnn.setVar(sClientID + ":LocalDSU","Yes"); } 

        if (fReload==true && dnn.getVar(sClientID + ":AlreadyPB")!="yes")
        {
            dnn.setVar(sClientID + ":AlreadyPB","yes");
            __doPostBack('','');
        }
    }
    catch(x)
    { }
}        
