// PORTALS defined:
var PORTAL_MDR = 'mdr';
var PORTAL_HITSP = 'hitsp';
var PORTAL_COMMON_FORMATS = 'ps';
var PORTAL_MUMM = 'mum';
var PORTAL_STATE_ALL_PAYERS = 'apcd';

// define the window location and default portal:
var pageURI = new URI(window.location);
var pageSystem = PORTAL_MDR;

// look to the URI to find the system:
if(pageURI.getData('system') != undefined){
    pageSystem = pageURI.getData('system');
} else if(pageURI.getData('System') != undefined){
    pageSystem = pageURI.getData('System');
}
function IsEmpty(aTextField) {
    var text = (document.getElementById(aTextField).value);
    var retval = null;
    if ((text==null) ||
        (text.length==0)) {
        alert("Search text is empty");
        retval = false;
    }
    else {
        retval = true;
    }

    if (retval) {
        document.getElementById("searchform").submit();
    }
}

document.write('<!-- navigation menu goes here -->');
function checkLocation(Referer)
{
    //if ( getCookieLink().indexOf(Referer) > -1 ) {
    var highlightInd =0;
    if ( Referer.indexOf("DataElement") > -1 ) {
        if (location.search.indexOf("Referer=DataElement") > -1 ||
            (location.search.indexOf("Referer=Data Element") > -1 &&
                location.search.indexOf("Referer=Data Element Concept") == -1 &&
                location.search.indexOf("Referer=Data Element Concepts") == -1)
            ){
            highlightInd = 1;
        }
    }
    else if ( Referer.indexOf("Value") > -1 ) {
        if (location.search.indexOf("Referer=Value") > -1 ||
            location.search.indexOf("Referer=Value Domain") > -1 ||
            location.search.indexOf("Referer=ValueDomain") > -1) {
            highlightInd = 1;
        }
    }
    else if ( Referer.indexOf("Constraint") > -1 ) {
        if (location.search.indexOf("Referer=Constraint") > -1 ) {
            highlightInd = 1;
        }
    }
    else if ( Referer.indexOf("Concepts") > -1 ) {
        if (location.search.indexOf("Referer=Concepts") > -1 ||
            location.search.indexOf("Referer=Data Element Concept") > -1 ||
            location.search.indexOf("Referer=Data Element Concepts") > -1){
            highlightInd = 1;
        }
        else if (Referer.indexOf("Template") > -1 ) {
            if (location.search.indexOf("Referer=Template") > -1 )
                highlightInd = 1;
        }
        else if ( Referer.indexOf("Conceptual") > -1 ) {
            if (location.search.indexOf("Referer=Conceptual") > -1 ||
                location.search.indexOf("Referer=Conceptual Domain") > -1) {
                highlightInd = 1;
            }
        }
    } else if ( Referer.indexOf("PSForm") > -1 ) {
        if (location.search.indexOf("Referer=PSForm") > -1 ) {
            highlightInd = 1;
        }
    }else if ( Referer.indexOf("CommonFormat") > -1 ) {
        if (location.search.indexOf("Referer=CommonFormat") > -1 ) {
            highlightInd = 1;
        }
    }else if ( Referer.indexOf("PSQS") > -1 ) {
        if (location.search.indexOf("Referer=PSQS") > -1 ) {
            highlightInd = 1;
        }
    }else if ( Referer.indexOf("PSTechSummary") > -1 ) {
        if (location.search.indexOf("Referer=PSTechSummary") > -1 ) {
            highlightInd = 1;
        }
    }else {
        if (location.search.indexOf("Referer="+Referer) > -1)
            highlightInd = 1;
    }
    if (highlightInd ==1) {
        return " style='color:navy;background:white;border-style:transparent;border-width:1px 1px 1px 1px;' ";
    }
    return " style='background:#FFF7CC;' ";
}
setAdminCookie("no");
/*
var patientView = location.search.indexOf("ps");
var hitspView = location.search.indexOf("hitsp");
var mumView = location.search.indexOf("mum");
var apcdView = location.search.indexOf("apcd");
*/
var cookieString = document.cookie;
var indexSize = cookieString.indexOf("chgSize",0);
var newWidth = 150;
if (indexSize > -1) {
    endSize = cookieString.indexOf(";", indexSize);
    if (endSize == -1){
        endSize = cookieString.length;
    }
    var newSize = parseInt(cookieString.substring(indexSize+8,endSize), 10);
    newWidth = (newSize/12)*150;
}
//start menu
document.write('<td id="menu_box" " valign="top"  style="width:');
document.write(newWidth +'px !important;">');
document.write('<div id="menu" style="vertical-align:top;padding:0px 0px 0px 0px;width:');
document.write(newWidth + 'px;margin:0">');
document.write('<ul>');

if (pageSystem == PORTAL_HITSP){
    document.cookie="view=hitsp";
    document.write('<li' + checkLocation("DataElement") + '><A HREF="dr.ui.drOrgDataAlph?Search=All&ResponsibleOrganization=32&Referer=DataElement&System=hitsp&ItemDisplaySize=50" title="Data Elements">Data Elements</a></li>');
    document.write('<li' + checkLocation("Value") + '><A HREF="dr.ui.drValueDomain_Page?system=hitsp&Search=All&ResponsibleOrganization=32&ItemDisplaySize=50&Referer=Value&view_src=mdr" title="Value Sets">Value Sets</a></li>');
    document.write('<li' + checkLocation("Constraints") + '><A HREF="dr.ui.drConstraint_Page?system=hitsp&Search=All&ResponsibleOrganization=32&ItemDisplaySize=50&Referer=Constraint&view_src=mdr" title="Constraints">Constraints</a></li>');
    document.write('<li' + checkLocation("Vocabularies") + '><A HREF="dr.ui.drVocabulary_Page?system=hitsp&Referer=Vocabularies&view_src=mdr" title="Vocabularies">Vocabularies</a></li>');
    document.write('<li' + checkLocation("Template") + '><A HREF="dr.ui.drDataElementConcept_Page?system=hitsp&Referer=Template&view_src=mdr&Search=All" title="HITSP Template" >HITSP Templates</a></li>');
    document.write('<li' + checkLocation("DA") + '><A HREF="dr.ui.drDataAgreement_Page?system=hitsp&Referer=DA&view_src=mdr&Search=All" title="HITSP Constructs" >HITSP Constructs</a></li>');
    document.write('<li' + checkLocation("QM") + '><A HREF="dr.ui.drQualityMeasureListing_Page?system=hitsp&Referer=QM" title="HITSP Quality Measures" >HITSP Quality Measures</a></li>');
    document.write('<li' + checkLocation("Concepts") + '><A HREF="dr.ui.drDataElementConcept_Page?system=hitsp&Referer=Concepts&view_src=mdr" title="Functional Groups">Functional Groups</a></li>');
    document.write('<li' + checkLocation("Models") + '><a HREF="models_hitsp_portal.html?system=hitsp&Referer=Models" title="Information Models">Information Models</a></li>');
    document.write('<li' + checkLocation("Advanced") + '><A HREF="dr.ui.drChooseSearchType?system=hitsp&Referer=Advanced" accesskey="4" title="HITSP Advanced Search">HITSP Advanced Search</a></li>');
    document.write('<li' + checkLocation("Help") + '><A HREF="hitsphelp.html?system=hitsp&Referer=Help" accesskey="5" title="HITSP Help">HITSP Help</a></li>');
    document.write('<li' + checkLocation("Guide") + '><A HREF="HITSP_Quickstart_Guide.html?system=hitsp&Referer=Guide" accesskey="5" title="Quick User Guide">Quick User Guide</a></li>');
    document.write('<li' + checkLocation("Files") + '><A HREF="hitsp_files.html?system=hitsp&Referer=Files" accesskey="5" title="HITSP Files">HITSP Reference Files</a></li>');
    document.write('<li' + checkLocation("Technical") + '><A HREF="USHIK_Technical_Summary.html?system=hitsp&Referer=Technical" accesskey="5" title="USHIK Technical Summary">USHIK Technical Summary</a></li>');

    document.write('</div>');
    document.write('<div class="clearing"></div>');
    document.write('<div style="border-style:outset;border-width:1px;background:#FFF7CC; margin-top: 10px;">');
    document.write('<b>&nbsp;Related Links:</b>');
    document.write('</ul>');
    document.write('<ul style="padding:0;list-style-type: disc;list-style-image: none;list-style-position: inside;">');
    document.write('<li style="margin:10px 0px 0px 0px"><A HREF="http://www.hitsp.org/default.aspx?show=library" title="HITSP Library">HITSP Library</a></li>');
    document.write('</br>');
    document.write('</ul>');
//
}
else if (pageSystem == PORTAL_COMMON_FORMATS){
    document.cookie="view=ps"; // PSForm
    document.write('<li' + checkLocation("CommonFormat") + '><A HREF="dr.ui.drOrgDataAlph?system=ps&amp;Search=All&amp;Referer=CommonFormat" title="Data Elements">Data Elements</a></li>');
    document.write('<li' + checkLocation("PSForm") + '><A HREF="dr.ui.drDataElementConcept_Page?system=ps&amp;Search=All&amp;Referer=PSForm&amp;ItemDisplaySize=50" title="Forms">Forms</a></li>');
    document.write('<li' + checkLocation("PSQS") + '><a href="PSO_Quickstart_Guide.html?system=ps&amp;Referer=PSQS" title="Quickstart Guide">Quickstart Guide</a></li>');
    document.write('<li' + checkLocation("PSTechSummary") + '><a href="USHIK_PSO_Technical_Summary.html?system=ps&amp;Referer=PSTechSummary" title="Technical Summary">Technical Summary</a></li>');
    document.write('<li' + checkLocation("PSHelp") + '><a href="pshelp.html?system=ps&amp;Referer=PSHelp" title="Help">Help</a></li>');
    document.write('</ul>');
    document.write('</div>');
    document.write('<div class="clearing"></div>');
    document.write('<div style="border-style:outset;border-width:1px;background:#FFF7CC; width: ' + newWidth + 'px !important; margin-top: 10px;">');
    document.write('<b>&nbsp;Related Links:</b>');
    document.write('</ul>');
    document.write('<ul style="padding:0;list-style-type: disc;list-style-image: none;list-style-position: inside;">');
    //document.write('<li style="margin:10px 0px 0px 0px"><A HREF="http://www.qualityforum.org" title="NQF" >NQF <img src="/images/exit_small.png" alt="External link"/></a></li>');
    document.write('<li style="margin:10px 0px 0px 0px"><a href="exitDisclaimer.jsp?system=ps&url=http://www.qualityforum.org/projects/commonformats.aspx#t=2&s=&p=" title="NQF" >NQF <img src="/images/exit_small.png" alt="External link"/></a></li>');
    document.write('<li style="margin:10px 0px 0px 0px"><A HREF="exitDisclaimer.jsp?system=ps&url=https://www.psoppc.org" title="PSOPPC">PSOPPC <img src="/images/exit_small.png" alt="External link"/></a></li>');
    document.write('<li style="margin:10px 0px 0px 0px"><A HREF="exitDisclaimer.jsp?system=ps&url=https://www.psoppc.org/web/patientsafety/version-1.1_documents" title="Event Descriptions, Sample Reports, and Forms" >Common Formats <img src="/images/exit_small.png" alt="External link"/></a></li>');
    document.write('<li style="margin:10px 0px 0px 0px"><A HREF="exitDisclaimer.jsp?system=ps&url=https://www.psoppc.org/web/patientsafety/version-1.1_techspecs" title="Technical Specificatons" >Technical Specificatons <img src="/images/exit_small.png" alt="External link"/></a></li>');
    document.write('<li style="margin:10px 0px 0px 0px"><A HREF="http://www.pso.ahrq.gov" title="AHRQ PSO">AHRQ PSO</a></li>');
    document.write('</ul>');
    document.write('</div>');
//' + checkLocation("PSOPPC") + '
}
else if(pageSystem == PORTAL_MUMM){
    document.cookie="view=mum";
    document.write('<li' + checkLocation("Measures") + '><A HREF="dr.ui.drDataElementConcept_Page?system=mum&Referer=Measures&view_src=mum&ItemDisplaySize=50" title="Measures">Measures</a></li>');
    document.write('<li' + checkLocation("Derive") + '><A HREF="dr.ui.drDataElementConcept_Page?system=mum&Referer=Derive&view_src=mum&ItemDisplaySize=50" title="Derived Data Elements">Derived Data Elements</a></li>');
    document.write('<li' + checkLocation("DataElement") + '><A HREF="dr.ui.drOrgDataAlph?Search=All&ResponsibleOrganization=&Referer=DataElement&System=mum&ItemDisplaySize=50" title="Data Elements">Data Elements</a></li>');
    document.write('<li' + checkLocation("Value") + '><A HREF="dr.ui.drValueDomain_Page?system=mum&Search=All&ResponsibleOrganization=&ItemDisplaySize=50&Referer=Value&view_src=mum" title="Value Sets">Value Sets</a></li>');
    document.write('<li' + checkLocation("Constraints") + '><A HREF="dr.ui.drConstraint_Page?system=mum&Search=All&ResponsibleOrganization=&ItemDisplaySize=50&Referer=Constraint&view_src=mum" title="Constraints">Constraints</a></li>');
    document.write('</ul>');
    document.write('</div>');
    document.write('&nbsp;<br/>');
    document.write('<div style="border-style:outset;border-width:1px;background:#FFF7CC;">');
    document.write('</ul>');
}
else if(pageSystem == PORTAL_STATE_ALL_PAYERS){
    document.cookie="view=apcd";
    document.write('<li' + checkLocation("DataElement") + '><a href="dr.ui.drOrgDataAlph?System=apcd&amp;Search=All&amp;Referer=DataElement" title="Data Elements">Data Elements</a></li>');
    document.write('<li' + checkLocation("Value") + '><a href="dr.ui.drValueDomain_Page?system=apcd&amp;Search=All&amp;Referer=Value" title="Value Sets">Value Sets</a></li>');
    document.write('<li' + checkLocation("Transactions") + '><a href="dr.ui.drFunctionalGroup_Page?system=apcd&amp;Referer=Transactions&amp;objectClass=Transactions" title="Transactions">Transactions</a></li>');
    document.write('<li' + checkLocation("Data Collection") + '><a href="dr.ui.drFunctionalGroup_Page?system=apcd&amp;Referer=Collections&amp;objectClass=Data%20Collection" title="Collections">Collections</a></li>');
    document.write('<li' + checkLocation("State") + '><a href="dr.ui.drFunctionalGroup_Page?system=apcd&amp;Referer=State&amp;objectClass=State" title="States">States</a></li>');
    document.write('<li' + checkLocation("Region") + '><a href="dr.ui.drFunctionalGroup_Page?system=apcd&amp;Referer=Region&amp;objectClass=Region" title="Region">Regions</a></li>');
    document.write('</ul>');
}
else {                       // generic USHIK
    document.cookie="view=mdr";
    document.write('<li' + checkLocation("DataElement") + '><A HREF="dr.ui.drOrgDataAlph?Search=All&Referer=DataElement&System=mdr&ItemDisplaySize=50" title="Data Elements">Data Elements</a></li>');
    document.write('<li' + checkLocation("DEConcept") + '><a href="dr.ui.drConcept_View?Search=All&amp;Referer=DEConcept&amp;System=mdr" title="Concepts">Data Element Concepts</a></li>');
    document.write('<li' + checkLocation("Value") + '><A HREF="dr.ui.drValueDomain_Page?system=mdr&Search=All&Referer=Value&view_src=mdr&ItemDisplaySize=50" title="Value Domains">Value Domains</a></li>');
    document.write('<li' + checkLocation("Constraints") + '><A HREF="dr.ui.drConstraint_Page?system=mdr&Search=All&Referer=Constraint&view_src=mdr&ItemDisplaySize=50" title="Constraints">Constraints</a></li>');
    document.write('<li' + checkLocation("Concepts") + '><A HREF="dr.ui.drDataElementConcept_Page?system=mdr&Referer=Concepts&view_src=mdr&ItemDisplaySize=50" title="Functional Groups">Functional Groups</a></li>');
    document.write('<li' + checkLocation("Conceptual") + '><A HREF="dr.ui.drIndex?system=mdr&Referer=Conceptual&view_src=mdr" title="Conceptual Domain">Conceptual Domains</a></li>');
    document.write('<li' + checkLocation("Context") + '><A HREF="dr.ui.drIndex?system=mdr&Referer=Context&view_src=mdr" title="Contexts" >Contexts</a></li>');
    document.write('<li' + checkLocation("Vocabularies") + '><A HREF="dr.ui.drIndex?system=mdr&Referer=Vocabularies&view_src=mdr" title="Vocabularies">Vocabularies</a></li>');
    document.write('<li' + checkLocation("Representational") + '><A HREF="dr.ui.drIndex?system=mdr&Referer=Representational Class&view_src=mdr" title="Representational Classes" >Representational Classes</a></li>');
    document.write('<li id="menu_sub">&nbsp;Views</li>');
    document.write('<li' + checkLocation("Models") + '><a HREF="models.html?system=mdr&Referer=Models" title="Information Models">Information Models</a></li>');
    document.write('<li' + checkLocation("Organizations") + '><A HREF="dr.ui.drIndex?system=mdr&Referer=Organizations&view_src=mdr" title="Organizations">Organizations</a></li>');
    document.write('<li' + checkLocation("DA") + '><A HREF="dr.ui.drIndex?system=mdr&Referer=DA&view_src=mdr" title="Data Agreements">Data Agreements</a></li>');
    document.write('<li' + checkLocation("Collections") + '><A HREF="dr.ui.drIndex?system=mdr&Referer=Collections&view_src=mdr" title="Collections">Collections</a></li>');
    document.write('<li' + checkLocation("Initiatives") + '><A HREF="dr.ui.drIndex?system=mdr&Referer=Initiatives&view_src=mdr" title="Initiatives" >Initiatives</a></li>');
    document.write('<li id="menu_sub">&nbsp;User Tools</li>');
    document.write('<li' + checkLocation("Advanced") + '><A HREF="dr.ui.drChooseSearchType?system=mdr&Referer=Advanced" accesskey="4" title="Advanced Search" >Advanced Search</a></li>');
    document.write('<li' + checkLocation("Reports") + '><A HREF="reports.html?Referer=Reports" title="Reports">Reports</a></li>');
    document.write('<li' + checkLocation("Help") + '><A HREF="help.html?Referer=Help" accesskey="5" title="Help">Help</a></li>');
    //document.write('<li' + checkLocation("Login") + '><A HREF="login.html?Referer=Login" title="Login">Login</a></li>');
    document.write('<li' + checkLocation("What") + '><A HREF="whats_new.html?Referer=What" accesskey="2" title="What&#39;s New in USHIK">What&#39;s New in USHIK</a></li>');
    document.write('</ul>');
}
document.write('</div>');
document.write('</td>');
document.write('<!-- end side navigation -->');