﻿var lc_count = 0;
var temp_count = 0;

function UpdateLogin() {

    uid = lc[0];
    ckay = lc[1];
    
    obj = GS.CP30.WebServices.Suggest.UpdateLogin(uid, ckay, OnUpdateLoginComplete);
}

function OnUpdateLoginComplete() {
    
    if(lc_count++ > 120)
    {
        window.location = "/pub/logout.aspx";
    }
    else setTimeout('UpdateLogin()', 30000);
}

function RedirectHome(clientid) {

    if(clientid > 0)
        document.location = "/default.aspx?id=" + clientid;
    else document.location = "/default.aspx";
}

function openSeverityDefinitions() {
    
    var loc = window.location;
    
    if(loc.toString().indexOf('&t=c') > -1)
        type = "c";
    else type = "p";
    
    window.open("/Forms/Common/" + type + "_severitydefs.aspx", "","height=550,width=650,resizable=yes,scrollbars=1,toolbar=no,location=no,menubar=no");
}

function openOBDefs() {

    window.open("/Forms/Common/obdefs.aspx", "","height=550,width=650,resizable=yes,scrollbars=1,toolbar=no,location=no,menubar=no");
}

function openPregDefs() {

    window.open("/Forms/Common/pregdefs.aspx", "","height=550,width=650,resizable=yes,scrollbars=1,toolbar=no,location=no,menubar=no");
}

function ShowModals(sender) {

    if(sender.id == "cp30nav_lnkFeedback")
    {
        document.getElementById("feedbackwrapper").style.display = "block";
        
        setTimeout('document.getElementById(\"cp30nav_txtName\").focus()', 200);
    }
    else if(sender.id == "cp30nav_lnkMyReports")
    {
        document.getElementById("recentreportswrapper").style.display = "block";
        
        var zz = setTimeout('ScaleRecentReps()', 100);
    }   
}

function HideModals() {

    if(document.getElementById("feedbackwrapper"))
    {
        document.getElementById("cp30nav_txtName").value = "";
        document.getElementById("cp30nav_txtEmail").value = "";
        document.getElementById("cp30nav_txtFeedback").value = "";
    }
    document.getElementById("feedbackwrapper").style.display = "none";
    document.getElementById("recentreportswrapper").style.display = "none";
}

function LoadFormulary() {

    document.getElementById('formloadingimg').style.visibility = "visible";
    document.getElementById('formdatawrapper').innerHTML = "";
}


function ScaleRecentReps() {

    var myWidth = 0, myHeight = 0;
   
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    }
    

    if(document.getElementById("cp30nav_pnlRecentReports"))
    {
        var offset = document.getElementById('recentrepoffset').offsetTop;

        if((offset + 60 > myHeight) && (myHeight > 125))
        {
            document.getElementById("cp30nav_pnlRecentReports").style.height = myHeight - 80 + "px";
            document.getElementById('cp30nav_pnlRecentReports').style.top = "30px";
        }
        else if((offset > 0) && (myHeight > 125))
        {
           document.getElementById("cp30nav_pnlRecentReports").style.height = offset + 35 + "px";
        }
    }  
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function GetHSHTML(aprid) {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptAddPair("aprid", aprid);
        ntptEventTag("ev=openhs");
    }
    
    if(document.getElementById('imagearea'))
    {
        if(document.getElementById('imagearea').style.display == 'none')
            obj = GS.CP30.WebServices.Suggest.GetHSHTML(aprid, OnGetHSHTMLComplete);    
    }
    else obj = GS.CP30.WebServices.Suggest.GetHSHTML(aprid, OnGetHSHTMLComplete);
}

function OnGetHSHTMLComplete(result) {


    document.getElementById("productdetailwrapper").style.display = "block";
    document.getElementById('proddetail').innerHTML = result;  
 
    document.getElementById("btnOpenProdDetails").click(); 
    
    var myWidth = 0, myHeight = 0;
   
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    }
    
    var offset = document.getElementById('proddetailoffset').offsetTop;   
    
    if((offset + 60 > myHeight) && (myHeight > 125))
    {
        document.getElementById("pnlProdDetails").style.height = myHeight - 80 + "px";
    }
    else if((offset > 0) && (myHeight > 125))
    {
       document.getElementById("pnlProdDetails").style.height = offset + 35 + "px";
    }   
    
    document.getElementById("btnOpenProdDetails").click(); 
    
    CamerasToThumbs();
}

function getHeight(div) {

    var x = document.getElementById(div);
    
    alert(x.style.height);
    alert(x.offsetTop);
    alert(x.scrollTop);
}


function LoadProductDetails(cpnum, aprid) {

    if(document.getElementById('imagearea').style.display == 'none')
        window.location = "/Forms/Monograph/monograph.aspx?sec=monsup&cpnum=" + cpnum + "&aprid=" + aprid;
}

function LoadImage(aid, type, modal) {

    if(document.getElementById('dropColors'))
    {
        //document.getElementById('cp30nav_txtSearch').focus();
        
        if(ie6 || ie5)
        {
            document.getElementById('dropColors').style.visibility = "hidden";
            document.getElementById('dropShapes').style.visibility = "hidden";
        }    
    }    
    
    var imagediv;

    if(modal == 1)
    {
        imagediv = document.getElementById("imageareamodal");
    }
    else imagediv = document.getElementById("imagearea");

    var src = "/Forms/Common/imageserve.ashx?n=" + aid + "&t=" + type;
    
    var width = 450;
    var height = 314;
    
    imagediv.innerHTML = "<img id='largeimage' src='" + src + "' alt='Drug Photo Image' width='" + width + "' height='" + height + "' />";
    
    var myWidth = 0, myHeight = 0;
   
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    }
    
    if(modal == 1)
    {
        imagediv.style.left = parseInt(myWidth/2 - 225) + "px";
        imagediv.style.top = parseInt(myHeight/2 - 300) + "px";  
    }
    else
    {        
        imagediv.style.left = parseInt(myWidth/2 - 225) + "px";
        imagediv.style.top = parseInt(myHeight/2 - 157) + "px";      
    }   
    
    imagediv.style.display = "block";
    imagediv.style.position = "absolute";
    
   // document.form1.style.opacity = .4;
}

function ShowLargeImage(aid, type, product)
{
    document.getElementById("imgLargeImage").src = "/Forms/Common/imageserve.ashx?n=" + aid + "&t=" + type;
}

function CamerasToThumbsPrint() {

    CamerasToThumbs();
    
    if(typeof isRA == 'undefined')
    {
        self.print();
    }
}

function CamerasToThumbs()
{
    var id;
    var type;
    var oImgs = document.getElementsByTagName("img");
        
    for(i=0; i<oImgs.length; i++)
    {
        if(oImgs[i].className == 'thumbnail')
        {
            type = oImgs[i].id.substring(0,1);
            id = oImgs[i].id.substring(1,oImgs[i].id.length);
            
            oImgs[i].src = "/Forms/Common/imageserve.ashx?n=" + id + "&w=30&h=21&t=" + type;
            oImgs[i].style.borderTop = "solid 2px #a09d9d";
            oImgs[i].style.borderLeft = "solid 2px #a09d9d";
            oImgs[i].style.borderRight = "solid 2px black";
            oImgs[i].style.borderBottom = "solid 2px black";
            //oImgs[i].className = "thumbnailborder";           
        }
    }
}

function CamerasToMediumsPrint() {

    CamerasToMediums();
    
    if(typeof isRA == 'undefined')
    {
        self.print();
    }
}

function CamerasToMediums() {

    var id;
    var type;
    var oImgs = document.getElementsByTagName("img");
        
    for(i=0; i<oImgs.length; i++)
    {
        if(oImgs[i].className == 'medimage')
        {
            type = oImgs[i].id.substring(0,1);
            id = oImgs[i].id.substring(2,oImgs[i].id.length);
            
            oImgs[i].src = "/Forms/Common/imageserve.ashx?n=" + id + "&w=240&h=168&t=" + type;
            oImgs[i].style.borderTop = "solid 2px #a09d9d";
            oImgs[i].style.borderLeft = "solid 2px #a09d9d";
            oImgs[i].style.borderRight = "solid 2px black";
            oImgs[i].style.borderBottom = "solid 2px black";
            
            if(ie)
            {
                oImgs[i].className = 'medimage_ie';
            }
        }
    }
}

function ClearImage() {

    if(document.getElementById("imagearea"))
    {
        document.getElementById("imagearea").style.display = "none";
        document.getElementById("imagearea").innerHTML =  "";
    }
    
    if(document.getElementById("imageareamodal"))
    {   
        document.getElementById("imageareamodal").style.display = "none";
        document.getElementById("imageareamodal").innerHTML =  "";
    }
    
    if(document.getElementById('dropColors'))
    {
        //document.getElementById('cp30nav_txtSearch').focus();
        
        if(ie6 || ie5)
        {
            document.getElementById('dropColors').style.visibility = "visible";
            document.getElementById('dropShapes').style.visibility = "visible";
        }    
    }

}

function btnDrugIdentifier_Click() {

    document.location = "/Forms/AdvSearch/msearch.aspx?s=d";
}

String.prototype.trim = function() { var _ret = this.replace(/^\s+|\s+$/g, ''); return _ret.replace(/^(\&nbsp\;)+|(\&nbsp\;)+$/g, ''); }

function CheckInput(sender) {

    var searchstring = sender.value;

    searchstring = searchstring.replace('%', '');
    
    if(searchstring.trim() == "")
    {
        alert("Please enter search criteria");
        sender.value = "";
        sender.focus();
        return false;
    }
    else
    {      
        if(searchstring.length > 50)
            searchstring = searchstring.substring(0, 50);
            
        document.location = "/Forms/search.aspx?s=" + searchstring;
    }
}


function ScrollToSection(div, section) {
    
    var ivsolbreak = 0;
    if(document.getElementById('ivtablebreak') && section.indexOf('iv_jumpto_so') > -1)
       ivsolbreak = document.getElementById('ivtablebreak').offsetTop;
    
    if(document.getElementById("indexes"))
        CloseIndexes();
        
    var contentdiv = document.getElementById(div);
    var sectionlink = document.getElementById(section);

    contentdiv.scrollTop = sectionlink.offsetTop - 3 + ivsolbreak;
}


function ScrollToSection_Rel(div, section) {                    // For relatively positioned divs, must sniff browser for scrollTo to land properly

    var contentdiv = document.getElementById(div);
    var sectionlink = document.getElementById(section);
    
    if(document.getElementById("indexes"))
        CloseIndexes();
        
    
    if(moz)
    {
        contentdiv.scrollTop = sectionlink.offsetTop - 300;
    }
    else contentdiv.scrollTop = sectionlink.offsetTop - 3;
    
}

function ScrollToScrollTop(div, scrolltop) {

    document.getElementById(div).scrollTop = scrolltop;
}

function doAlert(msg) {

    alert(msg);
}

function CloseFeedback() {

    return false;
}

function createTitle(indexpos)
{
    var title;
    var stripHTML = /<(?:.|\s)*?>/g;
    var refnum = "ref" + indexpos;
    
    title = indexarray[indexpos];
    title = chars_from_hex(title);
    title = title.replace(stripHTML, "");

    document.getElementById(refnum).title = title;
}

function removeTitle(refnum)
{
    document.getElementById(refnum).title = "";
}

//function OpenReferenceMono(indexpos, refnum)
//{
//    // Unica event tagging
//    if(document.getElementById('unica'))
//    {
//        ntptAddPair("refnum", refnum);
//        ntptEventTag("ev=openref");
//    }
//    
//    OpenWindow=window.open("", "newwin", "height=350, width=450,toolbar=no,scrollbars=scroll,menubar=no");
//    OpenWindow.document.write("<html>");
//    OpenWindow.document.write("<head>");
//    OpenWindow.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
//    OpenWindow.document.write("<title>Reference</title>");
//    OpenWindow.document.write("</head>");
//    OpenWindow.document.write("<body>");
//    OpenWindow.document.write("<h1>Reference</h1>");
//    OpenWindow.document.write("<b>" + refnum + "</b>&nbsp;-&nbsp;" + chars_from_hex(indexarray[indexpos]) );
//    OpenWindow.document.write("<br />");
//    OpenWindow.document.write("</body>");
//    OpenWindow.document.write("</html>");
//    OpenWindow.document.close();
//    self.name="main"
//}

/*
function OpenReferenceMono(indexpos, refnum)
{
    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptAddPair("refnum", refnum);
        ntptEventTag("ev=openref");
    }   
  
    
    OpenWindow=window.open("", "newwin", "height=350, width=450,toolbar=no,scrollbars=scroll,menubar=no");
    OpenWindow.document.write("<html>");
    OpenWindow.document.write("<head>");
    OpenWindow.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
    OpenWindow.document.write("<title>Reference</title>");
    OpenWindow.document.write("</head>");
    OpenWindow.document.write("<body>");
    OpenWindow.document.write("<h1>Reference</h1>");
    OpenWindow.document.write("<b>" + refnum + "</b>&nbsp;-&nbsp;" + chars_from_hex(indexarray[indexpos]) );
    
    if (pubmedarray != null)
    {
        if (pubmedarray[indexpos].length > 1)
            {
                var pubMedID = document.getElementById('cp30nav_hdnPubMedID').value;
                if (pubMedID.length > 0)
                {
                    pubMedID = "?holding=" + pubMedID;
                }        
                OpenWindow.document.write("<br /><br /><div align=\"center\" >" + '<h4>View this reference at:</h4> <a href="http://www.ncbi.nlm.nih.gov/pubmed/' + pubmedarray[indexpos] + pubMedID + '" title="View this reference at PubMed"  target="_blank"  ><img style=\"border: none;\" src="/Images/linkingOut_PubMed.gif" alt="View this reference at PubMed" /></a></div>');
            }
    }
 
     OpenWindow.document.write("<br />");
  
   
    OpenWindow.document.write("</body>");
    OpenWindow.document.write("</html>");
    OpenWindow.document.close();
    self.name="main"
}
*/
function OpenRefMonoModal(indexpos, refnum)
{

   // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptAddPair("refnum", refnum);
        ntptEventTag("ev=openref");
    }
    
    document.getElementById("refmodal").style.display = "block";
    document.getElementById("btnrefopenmodal").click();
    document.getElementById("refdef").innerHTML = "<b>" + refnum + "</b>&nbsp;-&nbsp;" + chars_from_hex(indexarray[indexpos]);
    
    if (pubmedarray != null)
    {
        if (pubmedarray[indexpos].length > 1)
        {
            var pubMedID = document.getElementById('cp30nav_hdnPubMedID').value;
            if (pubMedID.length > 0) 
            {
                pubMedID = "?holding=" + pubMedID;
            }    
        
            var str;
            str =  "<span style=\"font-size:9px; font-weight:bold;\">View this reference at:<br /><br /></span>" 
            + '<a href="http://www.ncbi.nlm.nih.gov/pubmed/' + pubmedarray[indexpos] + pubMedID + '" title="View this reference at PubMed"  target="_blank"   ><img style="border: none;" src="/Images/linkingOut_PubMed.gif" alt="PubMed" /></a>';


            var mdc;
            var mdcuser = document.getElementById("mdcuser").value;

            if(mdcuser == "user")
            {          
                mdc =  '&nbsp;&nbsp;<a href=\"javascript:OpenRefMDC('+ pubmedarray[indexpos] + pubMedID +');" title="View this reference at MDConsult"    ><img style="border: none;" src="/Images/linkingOut_MDConsult.gif" alt="MDConsult" /></a>';                 
            } 
            else
            {
                mdc = '';
            }
    
            document.getElementById("pubmedref").innerHTML = str + mdc;
    
        }
    }
}

function OpenRefMDC(pid)
{
    window.open('/Forms/Resources/refmdconsult.aspx?pid='+ pid, 'MDConsult', 'height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes');
}


function closeRefMonoModal()
{
    document.getElementById("refmodal").style.display = "none";
}

/*
function OpenReferenceInte(title, refnum)
{
    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptAddPair("refnum", refnum);
        ntptEventTag("ev=openref");
    }
    
    OpenWindow=window.open("", "newwin", "height=350, width=450,toolbar=no,scrollbars=scroll,menubar=no");
    OpenWindow.document.write("<html>");
    OpenWindow.document.write("<head>");
    OpenWindow.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
    OpenWindow.document.write("<title>Reference</title>");
    OpenWindow.document.write("</head>");
    OpenWindow.document.write("<body>");
    OpenWindow.document.write("<h1>Reference</h1>");
    OpenWindow.document.write("<b>" + refnum + "</b>&nbsp;-&nbsp;" + chars_from_hex(title));
    
    if (pubmedarray != null)
    {
        if (pubmedarray[indexpos].length > 1)
        {
            OpenWindow.document.write("<br /><br /><div align=\"center\" >" + '<h4>View this reference at:</h4> <a href="http://www.ncbi.nlm.nih.gov/pubmed/' + pubmedarray[indexpos] + '" title="View this reference at PubMed"  target="_blank"  ><img style=\"border: none;\" src="/Images/linkingOut_PubMed.gif" alt="View this reference at PubMed" /></a></div>');
        }
    }
 
    OpenWindow.document.write("<br />");
    OpenWindow.document.write("<br />");
    OpenWindow.document.write("</body>");
    OpenWindow.document.write("</html>");
    OpenWindow.document.close();
    self.name="main"
}

function OpenReferenceInteModal(title, refnum)
{
    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptAddPair("refnum", refnum);
        ntptEventTag("ev=openref");
    }
    
    document.getElementById("refmodal").style.display = "block";
    document.getElementById("btnrefopenmodal").click();
    document.getElementById("refdef").innerHTML = "<b>" + refnum + "</b>&nbsp;-&nbsp;" + chars_from_hex(title);
       
}
*/

/*
 * JavaScript ASCII Converter
 *
 * do whatever you want with this.
 *
 * useage: have a form with text inputs named "chars", "dec", "hex", "bin" and
 * "delimiter". on suitable events call from_char(), from_dec(), from_hex() or
 * from_bin() with the form as the only argument.
 *
 * TPO 2001/2004
 */

var charArray = new Array(
	' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-',    //32-45
	'.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';',    //46-59
	'<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',    //60-73
	'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',    //74-87
	'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e',   //88-101
	'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',    //102-115
	't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', '', '€', '',    //116-129
	'‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '', 'Ž', '',    //130-143
	'', '‘', '’', '“', '”', '•', '–', '—', '˜', '™', 'š', '›', 'œ', '',    //144-157
	'ž', 'Ÿ', ' ', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«',    //158-171
	'¬', '­', '®', '¯', '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹',    //172-185
	'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç',    //186-199
	'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ',    //200-213
	'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã',    //214-227
	'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', '½', 'î', 'ï', 'ð', 'ñ',    //228-241
	'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ');   //242-255

var hex_digits = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
		'A', 'B', 'C', 'D', 'E', 'F');

function byteToHex(n)
{
	return hex_digits[(n >> 4) & 0xf] + hex_digits[n & 0xf];
}

function charToByte(c)
{
	var i;
	for(i=0; i < charArray.length; i++) {
		if(c == charArray[i]) return i+32;
	}
	return 0;
}

function byteToChar(n)
{
	if(n < 32 || n > 255) return " ";
	return charArray[n-32];
}

function chars_from_hex(index)
{
	var hex_str = index
	var char_str = "";
	var num_str = "";
	var i;
	for(i=0; i < hex_str.length; i+=2)
		char_str += byteToChar(parseInt(hex_str.substring(i, i+2), 16));
	return char_str;
}

function hex_from_chars(index)
{
	var char_str = index
	var hex_str = "";
	var i, n;
	for(i=0; i < char_str.length; i++) {
		n = charToByte(char_str.charAt(i));
		if(n != 0) 
			hex_str += byteToHex(n);
	}
	return hex_str;
}         

function OpenIVRefs(div) {

    var elem = document.getElementById(div);
    document.getElementById('ivrefmodalplh').innerHTML = elem.innerHTML;
    document.getElementById('ivrefmodalwrapper').style.display = "block";
    
    document.getElementById('btnOpenIVRefModal').click();
}

function OpenIVModal(resultIDs, t) {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=openIVModal");
    }
    
    var header = document.getElementById("ivm_header");
    var title = document.getElementById("ivm_resulttitle");
    var img = document.getElementById("ivm_headerimg");
    var resultheader = document.getElementById('ivm_resultheader');
    
    switch(t)
    {
        case 'c':
            header.style.backgroundColor = "#eafbd1";
            header.style.color = "#036733";
            header.style.borderColor = "#83d08c";
            img.src = "/Images/c.gif";
            resultheader.style.color = "#006830";
            title.style.color = "#006830";            
            title.innerHTML = "Compatible";
            break;
        case 'i':
            header.style.backgroundColor = "#fce5df";
            header.style.color = "#90110a";
            header.style.borderColor = "#920f07";
            img.src = "/Images/i.gif";
            resultheader.style.color = "#90110a";
            title.style.color = "#920f07";
            title.innerHTML = "Incompatible";
            break;
        case 'u':
            header.style.backgroundColor = "#fefed4";
            header.style.color = "#9b6501";
            header.style.borderColor = "#b0892a";
            img.src = "/Images/u.gif";
            resultheader.style.color = "#9b6501";
            title.style.color = "#b0892a";            
            title.innerHTML = "Uncertain";
            break;
    }
    
    obj = GS.CP30.WebServices.Suggest.GetIVDetailsByResultIDs(resultIDs, OnGetIVModalDetails); 
}

var IVResultHeaders = new Array();
var IVResultDescs = new Array();
var IVRefs = new Array();
var IV_CS = new Array();
var IV_M = new Array();
var IV_SC = new Array();
var IV_C = new Array();
var IV_D = new Array();
var IV_N = new Array();
var IVCurrentIndex = 0;

function SetupNewIVDetails()
{
    IVResultHeaders = new Array();
    IVResultDescs = new Array();
    IVRefs = new Array();
    IV_CS = new Array();
    IV_M = new Array();
    IV_SC = new Array();
    IV_C = new Array();
    IV_D = new Array();
    IV_N = new Array();
    IVCurrentIndex = 0;
    
    document.getElementById('ivm_resultheader').innerHTML = "";
    document.getElementById('ivm_resultdesc').innerHTML = "";
    document.getElementById('ivm_ref').innerHTML = "";
    document.getElementById('ivm_secdetails').innerHTML = "";
}

function UpdateIVPaging()
{
    var total = IVResultHeaders.length;
    var pagingArea = document.getElementById('ivm_paging');
    pagingArea.innerHTML = (IVCurrentIndex + 1) + " of " + total;
    
    if(IVCurrentIndex > 0)
    {
        pagingArea.innerHTML = "<a class='ivm_paginglink' href=\"JavaScript:LoadIVResult(" + (IVCurrentIndex - 1) + ");\" title='Previous'><img src='/Images/left.gif' alt='' style='border: none;' /></a>" + pagingArea.innerHTML;
    }
    
    if(IVCurrentIndex < total - 1)
    {
        pagingArea.innerHTML += "<a class='ivm_paginglink' href=\"JavaScript:LoadIVResult(" + (IVCurrentIndex + 1) + ");\" title='Next'><img src='/Images/right.gif' alt='' style='border: none;' /></a>";
    }
}

function OnGetIVModalDetails(result)
{
    try
    {
        SetupNewIVDetails();
        eval(result);
        LoadIVResult(0);
        UpdateIVPaging();
        
        if(IV_CS.length == 0)
        {
            document.getElementById("ivm_premlinks").style.display = "none";        
        }
        
        document.getElementById("ivmodalwrapper").style.display = "block";    
        document.getElementById("btnOpenIVModal").click();
    }
    catch(err)
    {
        alert("Error retrieving details.");
    }
}

function LoadIVResult(index)
{
    IVCurrentIndex = index;
    UpdateIVPaging();
    document.getElementById('ivm_resultheader').innerHTML = IVResultHeaders[index];
    document.getElementById('ivm_resultdesc').innerHTML = IVResultDescs[index];
    document.getElementById('ivm_ref').innerHTML = IVRefs[index];    
    
    if(IV_CS.length > 0)
    {
        var elem = document.getElementById('ivmlink_cs');
    }
    else
    {
        var elem = document.getElementById('ivmlink_n');
    }
    IVM_SecLink_Click(elem);
}

function IVM_SecLink_Click(sender)
{
    if(IV_CS.length > 0)
    {
        document.getElementById('ivmlink_cs').style.color = "#4a69a2";
        document.getElementById('ivmlink_m').style.color = "#4a69a2";
        document.getElementById('ivmlink_sc').style.color = "#4a69a2";
        document.getElementById('ivmlink_c').style.color = "#4a69a2";
        document.getElementById('ivmlink_d').style.color = "#4a69a2";    
    }

    document.getElementById('ivmlink_n').style.color = "#4a69a2";
    
    sender.style.color = "#986700";
    
    var sec = document.getElementById('ivm_secdetails');
    var text;
    
    switch(sender.title)
    {
        case "Chemical Stability":
        
            text = IV_CS[IVCurrentIndex];
            
            if(text.length == 0) sec.innerHTML = "Not Available.";
            else sec.innerHTML = text
            break;
        case "Method":
        
            text = IV_M[IVCurrentIndex];
            
            if(text.length == 0) sec.innerHTML = "Not Available.";
            else sec.innerHTML = text
            break;
        case "Storage Conditions":
        
            text = IV_SC[IVCurrentIndex];
            
            if(text.length == 0) sec.innerHTML = "Not Available.";
            else sec.innerHTML = text
            break;
        case "Container":
        
            text = IV_C[IVCurrentIndex];
            
            if(text.length == 0) sec.innerHTML = "Not Available.";
            else sec.innerHTML = text
            break;
        case "Duration":
        
            text = IV_D[IVCurrentIndex];
            
            if(text.length == 0) sec.innerHTML = "Not Available.";
            else sec.innerHTML = text
            break;
            
        case "Notations":
        
            text = IV_N[IVCurrentIndex];
            
            if(text.length == 0) sec.innerHTML = "Not Available.";
            else sec.innerHTML = text
            break;
    }
}

function PrintIVStudyDetails() { 

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=printivmodal");
    }
    
    OpenWindow=window.open("", "newwin", "height=550, width=650,scrollbars=1,resizable=1");
    OpenWindow.document.write("<html>");
    OpenWindow.document.write("<head>");
    OpenWindow.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
    OpenWindow.document.write("<link href=\"/StyleSheets/Print.css?r=4\" rel=\"stylesheet\" type=\"text/css\" />");
    OpenWindow.document.write("<style type=\"text/css\" media=\"print\">#printbutton, #releasebreak { display: none; }</style>");
    
    OpenWindow.document.write("<title>IV Compatibility Study Details</title>");
    OpenWindow.document.write("</head>");
    OpenWindow.document.write("<body style=\"text-align: left;\" ");
    
    if(typeof isRA == 'undefined')
    {
        OpenWindow.document.write("onload=\"setTimeout('self.print()', 20)\">");
    }
    else
    {
        OpenWindow.document.write(">");
    }
    
    OpenWindow.document.write("<img id=\"printbutton\" onclick=\"window.print();\" title=\"Print\" src=\"/Images/print.gif\" alt=\"Print\" />");


    OpenWindow.document.write("<h2>IV Compatibility Study Details</h2>");  
      
    for(i=0; i < IVResultHeaders.length; i++)
    {
        OpenWindow.document.write("<h3>" + IVResultHeaders[i] + "</h3>");
        OpenWindow.document.write("<h4>" + IVResultDescs[i] + "</h4>");
        OpenWindow.document.write("<p>" + IVRefs[i] + "</p>");
        
        if(IV_CS.length > 0)
        {
            if(IV_CS[i].length > 0)
            {
                OpenWindow.document.write("<p><b>Chemical Stability:</b> " + IV_CS[i] + "</p>");
            }
            else
            {
                OpenWindow.document.write("<p><b>Chemical Stability:</b> Not Available.</p>");
            }

            if(IV_M[i].length > 0)
            {
                OpenWindow.document.write("<p><b>Method:</b> " + IV_M[i] + "</p>");
            }
            else
            {
                OpenWindow.document.write("<p><b>Method:</b> Not Available.</p>");
            }
            
            if(IV_SC[i].length > 0)
            {
                OpenWindow.document.write("<p><b>Storage Conditions:</b> " + IV_SC[i] + "</p>");
            }
            else
            {
                OpenWindow.document.write("<p><b>Storage Conditions:</b>  Not Available.</p>");
            }
            
            if(IV_C[i].length > 0)
            {
                OpenWindow.document.write("<p><b>Container:</b> " + IV_C[i] + "</p>");
            }
            else
            {
                OpenWindow.document.write("<p><b>Container:</b> Not Available.</p>");
            }
            
            if(IV_D[i].length > 0)
            {
                OpenWindow.document.write("<p><b>Duration:</b> " + IV_D[i] + "</p>");
            }
            else
            {
                OpenWindow.document.write("<p><b>Duration:</b> Not Available.</p>");
            } 
        }
        
        if(IV_N[i].length > 0)
        {
            OpenWindow.document.write("<p><b>Notations:</b> " + IV_N[i] + "</p>");
        }
        else
        {
            OpenWindow.document.write("<p><b>Notations:</b> Not Available.</p>");   
        }
        
        
        OpenWindow.document.write("<hr />");
    }  

    OpenWindow.document.write("<div style='text-align: center'>Copyright ©2010 Gold Standard</div>");

    OpenWindow.document.write("</body>");
    OpenWindow.document.write("</html>");
    OpenWindow.document.close();
    self.name="main"
    
}

function OpenDorlands() {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=gotodorlands");
    }
    
    window.open("http://www.dorlands.com/", "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenToxed() {
    
    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=gototoxed");
    }
    
    window.open("/Forms/Resources/opentoxed.aspx", "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenFirstCONSULT() {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=gotofirstconsult");
    }
    
    window.open("http://www.firstconsult.com", "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenMDConsult(url, unicaeventname) {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=" + unicaeventname);
    }
    
    window.open(url, "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenMosbys(url, unicaeventname) {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=" + unicaeventname);
    }
    
    window.open(url, "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenPL(qs) {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=gotopl");
    }
    
    var url = "http://www.pharmacistsletter.com";
    
    if(url.length > 0) url+= qs;
        
    window.open(url, "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenPrL(qs) {

    // Unica event tagging
    if (document.getElementById('unica')) {
        ntptEventTag("ev=gotoprl");
    }

    var url = "http://www.prescribersletter.com";

    if (url.length > 0) url += qs;

    window.open(url, "", "height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenNMDB(qs) {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=gotonmdb");
    }
    
    var url = "http://www.naturaldatabase.com";
    
    if(url.length > 0) url+= qs;    
    
    window.open(url, "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenPier(url) {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=gotopier");
    }
    
    if(document.getElementById("pierindexes"))
        ClosePierIndexes();
        
    if(url == '-1')
        url = 'http://piergsm.acponline.org/index.html?ref=gsm';
        
    window.open(url, "", "height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenMedGuide(filename) {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptAddPair("name", filename);
        ntptEventTag();
    }
    
    window.open("/MedGuides/" + filename, "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenFC(accountno) {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=gotoformchecker");
    }
    
    window.open("https://hub.medkeeper.com/Publisher/servlet/AuthenticatePage?uid=" + accountno, "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenQRG() {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptAddPair("name", "QRG");
        ntptEventTag();
    }
    
    window.open("/QRG/QRG.pdf", "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

function OpenOF() {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=gotoonformulary");
    }
    
    window.open("http://on-formulary-ip.com/", "","height=590,width=790,resizable=yes,scrollbars=1,toolbar=yes,location=yes,menubar=yes");
}

// Used to trap enter key on scriptaculous dropdown.  
// Waits 100ms before submitting for server verification to allow suggest name to populate textbox.
function fnTrapKD(rep, event) {
 
 if (document.all){

  if (event.keyCode == 13){

   event.returnValue=false;

   event.cancel = true;

   if( rep == "iv")
     window.setTimeout('AddToReport("iv")', 100);
   else if( rep == "adv")
     window.setTimeout('AddToReport("adv")', 100);
   else if( rep == "inte")
     window.setTimeout('AddToReport("inte")', 100);
   else if( rep == "dc")
     window.setTimeout('AddToReport("dc")', 100);
   else if( rep == "dci")
   {
        window.setTimeout('AddToReport_Index("dci")', 100);
   }
   else if( rep == "advsrch" )
     window.setTimeout('Search()', 100);
     
   
  }

 }

 else if (document.getElementById){

  if (event.which == 13){

   event.returnValue=false;

   event.cancel = true;
   
   if( rep == "iv")
     window.setTimeout('AddToReport("iv")', 100);
   else if( rep == "adv")
     window.setTimeout('AddToReport("adv")', 100);
   else if( rep == "inte")
     window.setTimeout('AddToReport("inte")', 100);
   else if( rep == "dc")
     window.setTimeout('AddToReport("dc")', 100);
   else if( rep == "dci")
   {
     window.setTimeout('AddToReport_Index("dci")', 100);   
   }
   else if( rep == "advsrch" )
     window.setTimeout('Search()', 100);


  }

 }

 else if(document.layers){

  if(event.which == 13){

   event.returnValue=false;

   event.cancel = true;
   
   if( rep == "iv")
     window.setTimeout('AddToReport("iv")', 100);
   else if( rep == "adv")
     window.setTimeout('AddToReport("adv")', 100);
   else if( rep == "inte")
     window.setTimeout('AddToReport("inte")', 100);
   else if( rep == "dc")
     window.setTimeout('AddToReport("dc")', 100);
   else if( rep == "dci")
   {
       window.setTimeout('AddToReport_Index("dci")', 100); 
   }
   else if( rep == "advsrch" )
     window.setTimeout('Search()', 100);

  }
 }
}

function btnDefault_Click() {}

function openHelp(){

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        //ntptAddPair("ind", index);
        ntptEventTag("ev=helpmenow");
    }
    
    var w = 480, h = 340;

    if (document.all) {
        /* the following is only available after onLoad */
        w = document.body.clientWidth;
        h = document.body.clientHeight;
    }
    else if (document.layers) {
        w = window.innerWidth;
        h = window.innerHeight;
    }
    var popW = 780, popH = 580;
    var leftPos = (w-popW)/2, topPos = (h-popH)/2;
    window.open('/forms/common/helpmenow.aspx?url=' + escape(location.href), 'helpmenow','menubar=0,statusbar=0,resizable=0,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}

function openAdmin() {

    var w = 480, h = 340;

    if (document.all) {
        /* the following is only available after onLoad */
        w = document.body.clientWidth;
        h = document.body.clientHeight;
    }
    else if (document.layers) {
        w = window.innerWidth;
        h = window.innerHeight;
    }
    var popW = 780, popH = 580;
    var leftPos = (w - popW) / 2, topPos = (h - popH) / 2;
    window.open('/forms/mycp/login.aspx', 'myCP', 'menubar=0,statusbar=0,resizable=0,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);

}

function getClassNames (element) {
   var classNames = element.className.split(/\s+/g);
   return classNames;
}

function setClass (element, className) {
   var classNames = getClassNames(element);
   var alreadySet = false;
   for (var i = 0; i < classNames.length; i++) {
     if (classNames[i] == className) {
       alreadySet = true;
       break;
     }
   }
   if (!alreadySet) {
     element.className =
/\S/.test(element.className) ? element.className + ' ' + className :
className;
   }
}

function unsetClass (element, className) {
   var pattern = new RegExp('(^|\\s+)' + className + '(\\s+|$)');
   element.className = element.className.replace(pattern, '$1$2');
} 

function ToggleDNA(type) {

    var area = document.getElementById('drugnamesarea');
    
    if(area.style.display == "block")
    {
        CloseDNA();
    }
    else
    {
        OpenDNA(type);
    }
}

function OpenDNA(type) {

    // Unica event tagging
    if(document.getElementById('unica'))
    {
        ntptEventTag("ev=opendrugnames-" + type);
    }

    if(document.getElementById('indexes'))
    {
        CloseIndexes();
    }
    
    document.getElementById('drugnamesarea').style.display = 'block';
    var title = document.getElementById('dna_title');
    var content = document.getElementById('dna_content');
    
    if(type=='u')
    {
        title.innerHTML = "US Drug Names";
        content.innerHTML = document.getElementById('dna_uc').innerHTML;
    }
    else
    {
        title.innerHTML = "Global Drug Names";
        content.innerHTML = document.getElementById('dna_gc').innerHTML;
    }
    
    if(document.getElementById('dropFormularies'))
    {
        document.getElementById('dropFormularies').style.visibility = "hidden";
    }
    
    if(document.getElementById('dropFC'))
    {
        document.getElementById('dropFC').style.visibility = "hidden";
    }
    
}

function CloseDNA() {

    if(document.getElementById('dropFormularies'))
    {
        document.getElementById('dropFormularies').style.visibility = "visible";
    }
    if(document.getElementById('dropFC'))
    {
        document.getElementById('dropFC').style.visibility = "visible";
    }
    
    document.getElementById('drugnamesarea').style.display = 'none';
}