/*****************************************************************************************************
Created By: Ferdous Md. Jannatul, Sr. Software Engineer
Created On: 10 December 2005
Last Modified: 13 April 2006
Modified by Terry Ridgers May 16, 2006 to support multiple print areas...
Modified by Terry Ridgers Sep 16, 2009 to support COIN specifics
Modified by Terry Ridgers Sep 30, 2009 added support for testing empty Print Divs
Modified by Steve Lussier Jan 04, 2010 added getPrintHome
******************************************************************************************************/
        //Trims all empty space from Print Div Contents
        function Trim(strDivContents) 
        {
          if (strDivContents != null)
          {
            strDivContents = strDivContents.replace(/^\s+/,"");
            return strDivContents.replace(/\s+$/,"");
          }
          return "";
        }  
        //Generating Pop-up Print Preview page
        function getPrint(print_area,language)
        {    
            //Creating new page
            var boolDivPrintContentIsEmpty=false;
            var strLeftContent = new String("Print_Left_Content");
            var strLeftContentInnerText = new String();
            strLeftContentInnerText = document.getElementById(strLeftContent).innerHTML;
            var strMiddleContent = new String("Print_Middle_Content");
            var strMiddleContentInnerText = new String();
            strMiddleContentInnerText = document.getElementById(strMiddleContent).innerHTML;
            var intMiddleContentStartPosToDelete;
            
            var strRightContent = new String("Print_Right_Content");
            var strRightContentInnerText = new String();                                                      
            strRightContentInnerText = document.getElementById(strRightContent).innerHTML;            
            var intRightContentStartPosToDelete;
            
            var strTomContent = new String("Print_TomContent");
            var strTomContentInnerText = new String();
            var strTomContentInnerTextDisclaimer = new String();
            var intTomContentStartPosToDelete;
            var intTomPosStartDisclaimer;
            var intTomPosEndDisclaimer;
            
            var strFooter = new String("Print_footer");
            var strMainBanner = new String();
            var strEDCSmallLogo = new String()
            var pp = window.open();
            var strprint_area = print_area.split(",");
            var intprint_area_index;
            
            if (language == "fr")
            {
              strMainBanner = '<img src="/imagesCMS/edclogo_f.gif">';
              strEDCSmallLogo = '<img src="/imagesCMS/logoEdc_small_f.gif">';
            }
            else
            {
              strMainBanner ='<img src="/imagesCMS/edclogo_e.gif">';
              strEDCSmallLogo = '<img src="/imagesCMS/logoEdc_small_e.gif">';
            }
    
            //Adding HTML opening tag with <HEAD><!-- PageID 17144 - published by RedDot 7.5 - 7.5.1.75 - 26417 --> … </HEAD> portion 
            pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')
            pp.document.writeln('<link href="/styles/countryinfo.css" rel="stylesheet" type="text/css" /><link rel="stylesheet" type="text/css" href="/styles/main.css" /><link rel="stylesheet" type="text/css" href="/styles/sub.css" /><link rel="stylesheet" type="text/css" href="/styles/default.css" />')
            pp.document.writeln('<base target="_self"></HEAD>')
            //Adding Body Tag
            pp.document.writeln('<body>');
            //Adding form Tag
            pp.document.writeln('<form  method="post">');
            //Creating two buttons Print and Close within a table
            if (language == "fr")
            {
                pp.document.writeln('<TABLE style="width:670px"><tr><td align=right><INPUT ID="PRINT" type="button" value="Copie" onclick="javascript:location.reload(true);window.print();"><INPUT ID="CLOSE" type="button" value="Fin" onclick="window.close();"></td></tr>');
            }
            else
            {
                pp.document.writeln('<TABLE style="width:670px"><tr><td align=right><INPUT ID="PRINT" type="button" value="Print" onclick="javascript:location.reload(true);window.print();"><INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();"></td></tr>');
            }
            //Writing print area of the calling page
            pp.document.writeln('  <tr>');
            pp.document.writeln('    <td align="center">');
              pp.document.writeln(strMainBanner);
            pp.document.writeln('    </td>');
            pp.document.writeln('  </tr>');
    
            pp.document.writeln('</TABLE>');                        
   if ((Trim(strLeftContentInnerText) != "") &&
       (Trim(strMiddleContentInnerText) != "") &&
       (Trim(strRightContentInnerText) != ""))
   {
              pp.document.writeln('<TABLE border="0" cellpadding="0" cellspacing="0">');
              pp.document.writeln('  <tr>');
              pp.document.writeln('    <td style="width:144px" valign="top">');
                
                strLeftContentInnerText = strLeftContentInnerText.replace(/id=inside-left/i,"");
                strLeftContentInnerText = strLeftContentInnerText.replace(/\+ more/i,"");
                strLeftContentInnerText = strLeftContentInnerText.replace(/\+ plus/i,"");
                pp.document.writeln(strLeftContentInnerText);
              pp.document.writeln('    </td>');
              pp.document.writeln('    <td style="width:348px" valign="top"  cellspacing="5">');
                
                intMiddleContentStartPosToDelete = 
                  strMiddleContentInnerText.search(/<div class=COINbox-blue-texture-405px>/i);    
                                                      
                if (intMiddleContentStartPosToDelete >= 0)
                {
                  strMiddleContentInnerText = strMiddleContentInnerText.substring(0,intMiddleContentStartPosToDelete);
                }
                strMiddleContentInnerText = strMiddleContentInnerText.replace(/COINdescription/g,"COINdescriptionPrint");
                strMiddleContentInnerText = strMiddleContentInnerText.replace(/class=COINbox-blue-405px/i,"class=COINbox-blue-405pxPrint");
                strMiddleContentInnerText = strMiddleContentInnerText.replace(/class=COINEDC-position/i,"class=COINEDC-positionPrint");
                strMiddleContentInnerText = strMiddleContentInnerText.replace(/<IMG src="\/ci_position_pos.gif">/i,"");
                pp.document.writeln(strMiddleContentInnerText);
              pp.document.writeln('    </td>');
              pp.document.writeln('    <td style="width:178px" align="left" valign="top">');
                pp.document.writeln('      <link href="/styles/countryinfo.css" rel="stylesheet" type="text/css" />');
                intRightContentStartPosToDelete = 
                  strRightContentInnerText.search(/<DIV class=tittle-brown-detail>/i);
                if (intRightContentStartPosToDelete >= 0)
                {
                  strRightContentInnerText = strRightContentInnerText.substring(0,intRightContentStartPosToDelete);
                }
                strRightContentInnerText = strRightContentInnerText.replace(/class=box-red-178px/g,"");
                   pp.document.writeln(strRightContentInnerText);
              pp.document.writeln('    </td>');
              pp.document.writeln('  </tr>');              
               pp.document.writeln('</TABLE>');
               pp.document.writeln('<TABLE border="0" cellpadding="0" cellspacing="0">');
              pp.document.writeln('  <tr>');
              pp.document.writeln('    <td style="width:670px">');
                strTomContentInnerText = document.getElementById(strTomContent).innerHTML;
                strTomContentInnerTextDisclaimer = document.getElementById(strTomContent).innerHTML;
                intTomContentStartPosToDelete =
                  strTomContentInnerText.search(/<tfoot/i);
                if (intTomContentStartPosToDelete >= 0)
                {
                  strTomContentInnerText = strTomContentInnerText.substr(0,intTomContentStartPosToDelete) + "</table></div></div>";
                }                  
                pp.document.writeln(strTomContentInnerText);
                
                intTomPosStartDisclaimer = 
                  strTomContentInnerTextDisclaimer.search(/<DIV class="header/i);
                intTomPosEndDisclaimer = strTomContentInnerTextDisclaimer.search(/<\/TH><\/TR><\/TFOOT>/i);
                if ((intTomPosStartDisclaimer >= 0) &&
                    (intTomPosEndDisclaimer > intTomPosStartDisclaimer))
                {
                   strTomContentInnerTextDisclaimer = 
                     '<div style="font-size:11px;" >' +
                        strTomContentInnerTextDisclaimer.substring(intTomPosStartDisclaimer,intTomPosEndDisclaimer) +
                     "</div>";
                   strTomContentInnerTextDisclaimer = strTomContentInnerTextDisclaimer.replace(/<IMG src="http:\/\/wwwdev.edc.ca\/imagesCMS\/edc_plus_icon.gif">/i,"");
                   strTomContentInnerTextDisclaimer = strTomContentInnerTextDisclaimer.replace(/<IMG src="http:\/\/wwwqac.edc.ca\/imagesCMS\/edc_plus_icon.gif">/i,"");
                   strTomContentInnerTextDisclaimer = strTomContentInnerTextDisclaimer.replace(/<IMG src="http:\/\/www.edc.ca\/imagesCMS\/edc_plus_icon.gif">/i,""); 
                   pp.document.writeln(strTomContentInnerTextDisclaimer);
                }
                pp.document.writeln('    </td>');
                pp.document.writeln('  </tr>');              
               pp.document.writeln('</TABLE>');
   }
   else
   {
              pp.document.writeln('<TABLE border="0" style="width:670px" cellpadding="0" cellspacing="5">');
              pp.document.writeln('  <tr>');
              pp.document.writeln('    <td style="width:670px" valign="top">');
                pp.document.writeln('     <table cellspacing="5">');
                var strOldContent = new String("Table2");
                var strOldContentInnerText = new String();
                strOldContentInnerText = document.getElementById(strOldContent).innerHTML;
                strOldContentInnerText= strOldContentInnerText.replace(/country_left/g,"COINcountry_leftPrint");
                pp.document.writeln(strOldContentInnerText);
                pp.document.writeln('     </table>');
              pp.document.writeln('    </td>');
              pp.document.writeln('  </tr>');
              pp.document.writeln('  <tr>');
              pp.document.writeln('    <td style="width:670px">');
                strTomContentInnerText = document.getElementById(strTomContent).innerHTML;
                strTomContentInnerTextDisclaimer = document.getElementById(strTomContent).innerHTML;
                intTomContentStartPosToDelete =
                  strTomContentInnerText.search(/<tfoot/i);
                if (intTomContentStartPosToDelete >= 0)
                {
                  strTomContentInnerText = strTomContentInnerText.substr(0,intTomContentStartPosToDelete) + "</table></div></div>";
                }                  
                pp.document.writeln(strTomContentInnerText);
                
                intTomPosStartDisclaimer = 
                  strTomContentInnerTextDisclaimer.search(/<DIV class="header/i);
                intTomPosEndDisclaimer = strTomContentInnerTextDisclaimer.search(/<\/TH><\/TR><\/TFOOT>/i);
                if ((intTomPosStartDisclaimer >= 0) &&
                    (intTomPosEndDisclaimer > intTomPosStartDisclaimer))
                {
                   strTomContentInnerTextDisclaimer = 
                     '<div style="font-size:11px;" >' +
                        strTomContentInnerTextDisclaimer.substring(intTomPosStartDisclaimer,intTomPosEndDisclaimer) +
                     "</div>";
                   pp.document.writeln(strTomContentInnerTextDisclaimer);
                }
                pp.document.writeln('    </td>');
                pp.document.writeln('  </tr>');              
               pp.document.writeln('</TABLE>');
      
   }
               pp.document.writeln('<TABLE border="0" cellpadding="0" cellspacing="0">');
              pp.document.writeln('  <tr>');
              pp.document.writeln('    <td>');
                pp.document.writeln(strEDCSmallLogo);
              pp.document.writeln('    </td>');
              pp.document.writeln('  </tr>');              
               pp.document.writeln('</TABLE>');
            
            //Ending Tag of </form>, </body> and </HTML>
            pp.document.writeln('</form></body></HTML>');
        }
         
function getPrintHome(language)
{    

    //Creating new page
    var strMiddleContent = new String("Print_Middle_Content");
    var strMiddleContentInnerText = new String();
    strMiddleContentInnerText = document.getElementById(strMiddleContent).innerHTML;
    var intMiddleContentStartPosToDelete;
    var strRightContent = new String("Print_Right_Content");
    var strRightContentInnerText = new String();                                                      
    strRightContentInnerText = document.getElementById(strRightContent).innerHTML;            
    var intRightContentStartPosToDelete;
    var strTomContent = new String("Print_TomContent");
    var strTomContentInnerText = new String();
    var strTomContentInnerTextDisclaimer = new String();
    var intTomContentStartPosToDelete;
    var intTomPosStartDisclaimer;
    var intTomPosEndDisclaimer;
    var strFooter = new String("Print_footer");
    var strMainBanner = new String();
    var strEDCSmallLogo = new String()
    var pp = window.open();
    var title="";
    if (language == "fr")
    {
        strMainBanner = '<img src="/imagesCMS/edclogo_f.gif">';
        strEDCSmallLogo = '<img src="/imagesCMS/logoEdc_small_f.gif">';
    }
    else
    {
        strMainBanner ='<img src="/imagesCMS/edclogo_e.gif">';
        strEDCSmallLogo = '<img src="/imagesCMS/logoEdc_small_e.gif">';
    }
    
    //Adding HTML opening tag with <HEAD><!-- PageID 17144 - published by RedDot 7.5 - 7.5.1.75 - 26417 --> … </HEAD> portion 
    if (language == "fr")
    {
        title="Prévision d'impression";
    }
    else
    {
        title="Print Preview";
    }
    pp.document.writeln('<HTML><HEAD><title>'+ title +'</title>');
    pp.document.writeln('<link href="/styles/countryinfo.css" rel="stylesheet" type="text/css" /><link rel="stylesheet" type="text/css" href="/styles/main.css" /><link rel="stylesheet" type="text/css" href="/styles/sub.css" /><link rel="stylesheet" type="text/css" href="/styles/default.css" />')
    //pp.document.writeln('<script type="text/javascript" src="/scripts/PERTPopup.js"></script>');
    pp.document.writeln('<base target="_self"></HEAD>');
    //Adding Body Tag
    pp.document.writeln('<body>');
    //Adding form Tag
    pp.document.writeln('<form  method="post">');
    //Creating two buttons Print and Close within a table
    if (language == "fr")
    {
        pp.document.writeln('<TABLE style="width:555px"><tr><td /><td align=right><INPUT ID="PRINT" type="button" value="Imprimer" onclick="javascript:location.reload(true);window.print();"><INPUT ID="CLOSE" type="button" value="Fermer" onclick="window.close();"></td></tr>');
    }
    else
    {
        pp.document.writeln('<TABLE style="width:555px"><tr><td /><td align=right><INPUT ID="PRINT" type="button" value="Print" onclick="javascript:location.reload(true);window.print();"><INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();"></td></tr>');
    }
    //Writing print area of the calling page
    pp.document.writeln('  <tr>');
    pp.document.writeln('    <td align="left">');
    pp.document.writeln(strMainBanner);
    
    pp.document.writeln('    </td>');

    pp.document.writeln('    <td style="width:178px;font-size:11px" align="left" valign="top">');
//    pp.document.writeln('      <link href="/styles/countryinfo.css" rel="stylesheet" type="text/css" />');
    intRightContentStartPosToDelete = strRightContentInnerText.search(/<DIV class=tittle-brown-detail>/i);
    if (intRightContentStartPosToDelete >= 0)
    {
        strRightContentInnerText = strRightContentInnerText.substring(0,intRightContentStartPosToDelete);
    }
    intRightContentStartPosToDelete = strRightContentInnerText.search(/<DIV class="tittle-brown-detail">/i);
    
    if (intRightContentStartPosToDelete >= 0)
    {
        strRightContentInnerText = strRightContentInnerText.substring(0,intRightContentStartPosToDelete);
    }
//    strRightContentInnerText =strRightContentInnerText.replace('<img','<img style="width:50%;height:auto;"');
/*
    strRightContentInnerText =strRightContentInnerText.replace('<A href="/english/mediaroom_14186.htm"><IMG alt="Map" src="/imagesCMS/map_international.gif"></A>','');
    strRightContentInnerText =strRightContentInnerText.replace('<DIV align=center><A href="/french/mediaroom_14186.htm"><IMG alt="Map" src="/imagesCMS/map_international.gif"></A>','');
      strRightContentInnerText =strRightContentInnerText.replace('<LI><A href="/french/mediaroom_14186.htm">Représentants d\'EDC à l\'étranger</A> </LI>','');
      strRightContentInnerText =strRightContentInnerText.replace('<LI><A href="/french/mediaroom_14186.htm">Représentants d\'EDC à l\'étranger</A> </LI>','');
  */
      strRightContentInnerText =strRightContentInnerText.replace('<HR color=#cc0000>','');
      
 
    pp.document.writeln(strRightContentInnerText);
    pp.document.writeln('    </td>');

    pp.document.writeln('  </tr>');
    pp.document.writeln('</TABLE>');                        
    pp.document.writeln('<TABLE  border="0" cellpadding="0" cellspacing="0" style="width:555px">');
    pp.document.writeln('  <tr>');
    pp.document.writeln('    <td style="width:555px;font-size:11px" valign="top"  cellspacing="0">');
    strMiddleContentInnerText =strMiddleContentInnerText.replace('useMap=#pertmap','');

    pp.document.writeln(strMiddleContentInnerText);
    pp.document.writeln('    </td>');
    pp.document.writeln('  </tr>');              
    pp.document.writeln('</TABLE>');
    
    pp.document.writeln('<TABLE border="0" cellpadding="0" cellspacing="0">');
    pp.document.writeln('  <tr>');
    pp.document.writeln('    <td style="width:555px">');
    strTomContentInnerText = document.getElementById(strTomContent).innerHTML;
    strTomContentInnerTextDisclaimer = document.getElementById(strTomContent).innerHTML;
    intTomContentStartPosToDelete =
    strTomContentInnerText.search(/<tfoot/i);
    if (intTomContentStartPosToDelete >= 0)
    {
        strTomContentInnerText = strTomContentInnerText.substr(0,intTomContentStartPosToDelete) + "</table></div></div>";
    }                  
    pp.document.writeln(strTomContentInnerText);
    intTomPosStartDisclaimer = 
    strTomContentInnerTextDisclaimer.search(/<DIV class="header/i);
    intTomPosEndDisclaimer = strTomContentInnerTextDisclaimer.search(/<\/TH><\/TR><\/TFOOT>/i);
    if ((intTomPosStartDisclaimer >= 0) &&
    (intTomPosEndDisclaimer > intTomPosStartDisclaimer))
    {
        strTomContentInnerTextDisclaimer = 
        '<div style="font-size:11px;" >' +
        strTomContentInnerTextDisclaimer.substring(intTomPosStartDisclaimer,intTomPosEndDisclaimer) +
        "</div>";
        strTomContentInnerTextDisclaimer = strTomContentInnerTextDisclaimer.replace(/<IMG src="http:\/\/wwwdev.edc.ca\/imagesCMS\/edc_plus_icon.gif">/i,"");
        strTomContentInnerTextDisclaimer = strTomContentInnerTextDisclaimer.replace(/<IMG src="http:\/\/wwwqac.edc.ca\/imagesCMS\/edc_plus_icon.gif">/i,"");
        strTomContentInnerTextDisclaimer = strTomContentInnerTextDisclaimer.replace(/<IMG src="http:\/\/www.edc.ca\/imagesCMS\/edc_plus_icon.gif">/i,""); 
        pp.document.writeln(strTomContentInnerTextDisclaimer);
    }
    pp.document.writeln('    </td>');
    pp.document.writeln('  </tr>');              
    pp.document.writeln('</TABLE>');
    pp.document.writeln('<TABLE border="0" cellpadding="0" cellspacing="0">');
    pp.document.writeln('  <tr>');
    pp.document.writeln('    <td>');
    pp.document.writeln(strEDCSmallLogo);
    pp.document.writeln('    </td>');
    pp.document.writeln('  </tr>');              
    pp.document.writeln('</TABLE>');
    //Ending Tag of </form>, </body> and </HTML>
    pp.document.writeln('</form></body></HTML>');
    return false;
}