﻿//===============================================================================================
//  Name:			topic.js
//  Description:	java scripts for topic.aspx page 
//===============================================================================================
//  History: 
//-----------------------------------------------------------------------------------------------    
//  Date            By               Reason
//  12/01/2007      Angela Deng      Initial Version   
//  03/10/2008      Angela Deng      Add printRatingTable, openWin
//  03/17/2008      Angela Deng      Remove checkAllDomain and checkAllRating
//  03/27/2008      Angela Deng      Add disableAnchor
//  04/02/2008      Angela Deng      Add addHoverText and disableHover
//  05/19/2008      Angela Deng      Add printInterventionList
//  05/24/2008      Angela Deng      Add displayIcons()
//  05/29/2008      Angela Deng      Add displayPrintListHoverIcon(); displayPrintRatingHoverIcon();
//  07/10/2008      Angela Deng      Add scrollToView()
//  07/25/2008      Angela Deng      Add toggleDisplayPanel()
//  07/25/2008      Angela Deng      Add displayPanel()
//  09/24/2008      Angela Deng      Add checkFilter()
//  11/05//2008     Angela Deng      Add displayRatingKey()
//  11/05/2008      Angela Deng      Modify checkAll()
//===============================================================================================
function displayRatingKey() 
{   
   // debugger;
    var ratingHeight = document.getElementById("PrintableRatingTable").offsetHeight;
    var panel = document.getElementById("PrintableRatingKey");
    if (ratingHeight > 16 )
    {
        if (panel)
        {
           panel.style.display = "block";
           clearFilter();
         }  
       
    } 
    else
    {
        if (panel)
            panel.style.display = "none";
    }    
}

function checkAll(checked)
{ 
     //debugger;
     for (var j= 0; j< document.getElementsByTagName("table").length; j++)
    {
        var item = document.getElementsByTagName("table")[j];
        if (  item.id == "tbCharItem" )
        {
            var cbtable = item;
            var cbbody = cbtable.getElementsByTagName("tbody")[0];
            for (var row = 0; row < cbbody.getElementsByTagName("tr").length; row++)
            {
                var cbrow = cbbody.getElementsByTagName("tr")[row];
                for (var i = 0; i < cbrow.getElementsByTagName("td").length; i++) 
                {
                    var cdrow = cbrow.getElementsByTagName("td")[i];
                    for ( var k = 0; k < cdrow.childNodes.length; k++)
                    {
                        if (  cdrow.childNodes[k].type == "checkbox")
                             cdrow.childNodes[k].checked = checked;
                    }
                }
            }
        }
    }
}


function checkFilter(oSrc, args) 
{
 //  debugger;
    var exp = "(<\/?)(a(bbr|cronym|ddress|pplet|rea)?|b(ase(font)?|do|ig|lockquote|ody|r|utton)?|c(aption|enter|ite|(o(de|l(group)?)))|d(d|el|fn|i(r|v)|l|t)|em|f(ieldset|o(nt|rm)|rame(set)?)|h([1-6]|ead|r|tml)|i(frame|mg|n(put|s)|sindex)?|kbd|l(abel|egend|i(nk)?)|m(ap|e(nu|ta))|no(frames|script)|o(bject|l|pt(group|ion))|p(aram|re)?|q|s(amp|cript|elect|mall|pan|t(r(ike|ong)|yle)|u(b|p))|t(able|body|d|extarea|foot|h|itle|r|t)|u(l)?|var)(\s(.+?))*>"
    var rx = new RegExp(exp,"i");  
    args.IsValid = !( rx.test(args.Value) ); 
    if (!args.IsValid)
        alert("Invalid input.");
    
}

 
function scrollToView(clientID)
{
   //debugger;
   //alert("Here in scrollToView and clientID = " + clientID);
    var e = document.getElementById(clientID)
    if (e != null)
    { 
        e.scrollIntoView(true);
    }
    //alert("Leaving scrollToView and clientID = " + clientID);
}

function displayPrintListHoverIcon()
{
    //debugger;
    var listHeight = document.getElementById("PrintableList").offsetHeight;
     //   alert("list height is " + listHeight);
    var btn = document.getElementById("btnPrintList");
    if (listHeight > 16 )
    {
        if ( btn != null)
            btn.src = "/ncee/wwc/Images/icons/print_down.gif";
      
    }      
    
}

function displayPrintRatingHoverIcon()
{
    //debugger;
    var ratingHeight = document.getElementById("PrintableRatingTable").offsetHeight;
    var btn = document.getElementById("btnPrint");
    if (ratingHeight > 0 )
    {
        if ( btn != null)
            btn.src = "/ncee/wwc/Images/icons/print_my_summary_down.gif";
      
    }      
   
}

function displayIcons()
{
 // debugger;
    displayPrintListIcon(true);
    displayPrintRatingIcon();
    displayRatingKey();
 //   displayCreateSumIcon()
}

function displayPrintListIcon(isScrollToView)
{
//debugger;
    var listHeight = document.getElementById("PrintableList").offsetHeight;
   //alert("list height is " + listHeight);
    var btn = document.getElementById("btnPrintList");
    if (listHeight > 16 )
    {
        if ( btn != null)
        {
            btn.src = "/ncee/wwc/Images/icons/print.gif";
         }   
      
    }      
    else
    {
        if ( btn != null)
            btn.src = "/ncee/wwc/Images/icons/print_deact.gif";
    }
    
    if (isScrollToView)
       scrollToView("PrintableList");
}

function displayPrintRatingIcon()
{
  //  debugger;
    var ratingHeight = document.getElementById("PrintableRatingTable").offsetHeight
    var btn = document.getElementById("btnPrint");
    if (ratingHeight > 0)
    {
        if ( btn != null)
            btn.src = "/ncee/wwc/Images/icons/print_my_summary.gif";
      
    }      
    else
    {
        if ( btn != null)
            btn.src = "/ncee/wwc/Images/icons/print_my_summary_deact.gif"
    }
}
function printFWWReport(rid, id, print) {
  //  debugger;
    var intervListResultSum = document.getElementById(rid)
    var intervListContentTmp = document.getElementById(id)
    if (intervListContentTmp != null)
        if (intervListContentTmp.offsetHeight > 0) {
        var intervListContent = document.getElementById(id).cloneNode(true);
        var today = new Date();
        var month = today.getMonth() + 1;
        var day = today.getDate();
        var year = today.getFullYear();

        var intervListWindow = window.open('', '', 'left=0,top=0,width=600,height=500,menubar=1,toolbar=1,resizable=1,,scrollbars=1,status=1');

        intervListWindow.document.write('<html><head><title>What Works Clearinghouse: Find What Works</title>');
        intervListWindow.document.write('<link rel="stylesheet" href="/ncee/wwc/css/mainstyle.css">');
        intervListWindow.document.write('<link rel="stylesheet" href="/ncee/wwc/css/topicstyle.css">');
        intervListWindow.document.write('<link rel="stylesheet" href="/ncee/wwc/css/fostyle.css">');
        intervListWindow.document.write('<link rel="stylesheet" href="/ncee/wwc/css/mprstyles.css">');
        intervListWindow.document.write('</head><body><div class="MainContent">');
        intervListWindow.document.write('<div class="printdate">Printed on ' + month + "/" + day + "/" + year + '</div>');
        intervListWindow.document.write('<img src="/ncee/wwc/Images/fww/headertopFWW.gif">');
        intervListWindow.document.write('<br />&nbsp;<br /><div class="WWCmcontent ">');

        disableAnchor(intervListContent);
        disableHover(intervListContent);
        
        intervListWindow.document.write(intervListResultSum.innerHTML);
        intervListWindow.document.write(intervListContent.innerHTML);


        intervListWindow.document.write('</div><div class="dontPrintMe"> <input type="button"  ID="btnPrint" class="fandsButtons" OnClick="javascript:window.print();" value="Print"   /> <input type="button"  ID="btnClose"  class="fandsButtons" OnClick="javascript:window.close();" value="Close Window" /> </div></div></body></html>');
        intervListWindow.document.close();

        intervListWindow.focus();
       if (print == 1) intervListWindow.print();
        // intervListWindow.close(); 

    }
}
function printIntervList(id)
{
//debugger;
 var intervListContentTmp = document.getElementById(id)
 if (intervListContentTmp != null )
    if (intervListContentTmp.offsetHeight > 0)
    {
         var intervListContent = document.getElementById(id).cloneNode(true);
         var today = new Date();
         var month = today.getMonth() + 1;
         var day = today.getDate();
         var year = today.getFullYear();
 
         var intervListWindow = window.open('','','left=0,top=0,width=600,height=500,menubar=1,toolbar=1,resizable=1');
         
         intervListWindow.document.write('<html><head><title>What Works Clearinghouse: Intervention List</title>');
         intervListWindow.document.write('<link rel="stylesheet" href="/ncee/wwc/css/mainstyle.css">');
         intervListWindow.document.write('<link rel="stylesheet" href="/ncee/wwc/css/topicstyle.css">');
         intervListWindow.document.write('</head><body><div class="MainContent">');
         intervListWindow.document.write('<div class="printdate">Printed on ' + month + "/" + day + "/" + year + '</div>');
         intervListWindow.document.write('<img src="/ncee/wwc/Images/headerfooter/headertop.gif">');
         intervListWindow.document.write('<br /><div class="WWCmcontent ">');
                  
         disableAnchor(intervListContent);
         disableHover(intervListContent);
         
         intervListWindow.document.write(intervListContent.innerHTML);
         
         
         intervListWindow.document.write('</div></div></body></html>');
         intervListWindow.document.close();
         
         intervListWindow.focus();
         intervListWindow.print();
          intervListWindow.close(); 
        
     }
}

function printRatingTable(id)
{
 var ratingTableContentTmp = document.getElementById(id)
 if (ratingTableContentTmp != null )
    if (ratingTableContentTmp.offsetHeight > 0)
    {
         var ratingTableContent = document.getElementById(id).cloneNode(true);
         var today = new Date();
         var month = today.getMonth() + 1;
         var day = today.getDate();
         var year = today.getFullYear();
 
         var ratingTableWindow = window.open('','','left=0,top=0,width=600,height=500,toolbar=0,scrollbars=1,status=0');
         
         ratingTableWindow.document.write('<html><head><title>What Works Clearinghouse: Summary of Research Findings</title>');
         ratingTableWindow.document.write('<link rel="stylesheet" href="/ncee/wwc/css/mainstyle.css">');
         ratingTableWindow.document.write('<link rel="stylesheet" href="/ncee/wwc/css/topicstyle.css">');
         ratingTableWindow.document.write('</head><body style=".ratingtablebox a {display: none;}" ><div class="MainContent">');
         ratingTableWindow.document.write('<div class="printdate">Printed on ' + month + "/" + day + "/" + year + '</div>');
         ratingTableWindow.document.write('<img src="/ncee/wwc/Images/headerfooter/headertop.gif"');
         ratingTableWindow.document.write('<br />');
                  
         disableAnchor(ratingTableContent);
         disableHover(ratingTableContent);
         
         ratingTableWindow.document.write(ratingTableContent.innerHTML);
         
         var ratingKeyContent = document.getElementById('PrintableRatingKey');
         ratingTableWindow.document.write(ratingKeyContent.innerHTML);
         
         ratingTableWindow.document.write('</div></body></html>');
         ratingTableWindow.document.close();
         
         ratingTableWindow.focus();
         ratingTableWindow.print();
         ratingTableWindow.close(); 
        
     }
}

function openWin(theURL,theWidth,theHeight)
{
    aWindow=window.open(theURL,"popupwin","width="+((theWidth!=null)?theWidth:350)+",height="+((theHeight!=null)?theHeight:300)+",scrollbars=yes,resizable=yes,screenX=10,screenY=10,left=10,top=10, location=1");
    aWindow.focus();
}

function disableAnchor(obj)
{
   //debugger;
    for ( var i = 0; i < obj.getElementsByTagName("a").length; i++)
      obj.getElementsByTagName("a")[i].removeAttribute('href');
}

function disableHover(obj)
{
    //debugger;
    for ( var i = 0; i < obj.getElementsByTagName("span").length; i++)
    {
      obj.getElementsByTagName("span")[i].removeAttribute('onmouseover');
      obj.getElementsByTagName("span")[i].removeAttribute('onmouseout');
    }
}

function displayHoverText(exp)
{
   //debugger;
   switch (exp)
   {
    case 1: 
        overlib("Name of the educational program, product, practice or policy reviewed.", CAPTION, "Intervention");
        break;
    case 2: 
        overlib("Difference between the percentile rank of the average student in the intervention group and the percentile rank of the average student in the comparison group. Can take on values between -50 and +50, with positive numbers denoting results favorable to the intervention group.", CAPTION, "Improvement Index");
        break;
    case 3: 
        overlib("Considers four factors: the quality of the research design, the statistical significance of the findings, the size of the difference between participants in the intervention and the comparison conditions, and the consistency in findings across studies.  See the &quotEvidence Rating Key&quot for an explanation of each rating.", CAPTION, "Evidence Rating");
        break;
    case 4: 
        overlib("Developed to convey how much evidence was used to determine the intervention rating, focusing on the number and sizes of studies. This scheme has two categories: small and medium to large.", CAPTION, "Extent of Evidence");
        break;
   }
}

 
