function setupPrintPrivew(pTitle) {
    //
    //  This function is used to setup the print preview css.
    //  The main 'screen.css' used in the 2nd header template need to be removed first.
    //  After that, call the changeStyel() to use the css with title="prrintpreview" as the 
    //  main css.  This css with printpreview title must be declared as an "alternate stylesheet".
    //  Example: 
    //   <link rel="alternate stylesheet" href="flang_print_preview.css" type="text/css" media='screen' title='printpreview' />
    //

    //  alert('in setupPrintPreviw() - ptitle:'+pTitle);
    //  alert('in setupPrintPrivew():'+window.location.href);

    if (window.location.href.search('print=y') > -1) {
         // this is a print or print preview version -  apply the print preview css

         document.title=pTitle;
        
        // remove the screen.css to prevent any side effect

     // var style = document.getElementById("screen");
      //style.parentNode.removeChild(style);
      //delete style;
      changeStyle('printpreview');

    }
    if (window.location.href.search('print=nref') > -1) {
         // this is a print or print preview version -  apply the print preview css

         document.title=pTitle;

        // remove the screen.css to prevent any side effect

      //var style = document.getElementById("screen");
      //style.parentNode.removeChild(style);
      //delete style;
      changeStyle('printpreview1');

    }
} 

function printpopup(){
    var tfeature="toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,left=25,top=25";
    var myWidth;
    var myHeight;
    var myPopupWindow;

    if( typeof( window.innerWidth ) == 'number' ) { 
     //Non-IE 
  myWidth = Math.round(window.innerWidth * 0.8);
  myHeight = Math.round(window.innerHeight * 0.8); 

     } else if( document.documentElement && 
  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
     //IE 6+ in 'standards compliant mode' 
  myWidth = Math.round(document.documentElement.clientWidth * 0.8); 
  myHeight = Math.round(document.documentElement.clientHeight * 0.8); 
     }
     else {
  myWidth=900;
        myHeight=500;
     }

    tfeature = tfeature + ',width='+myWidth+',height='+myHeight;
    
    var newURL = "";

    newURL = AddUrlParameter(window.location.href, 'print', 'y', true);

    //   alert('newURL:'+newURL);

    myPopupWindow =window.open(newURL, 'PrintWin', tfeature);
    myPopupWindow.focus();
}


function getAllSheets() {
        if( !window.ScriptEngine && navigator.__ice_version ) { return document.styleSheets; }
        if( document.getElementsByTagName ) { var Lt = document.getElementsByTagName('LINK'), St = document.getElementsByTagName('STYLE');
        } else if( document.styleSheets && document.all ) { var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
        } else { return []; } for( var xIndex = 0, os = []; Lt[xIndex]; xIndex++ ) {
                var rel = Lt[xIndex].rel ? Lt[xIndex].rel : Lt[xIndex].getAttribute ? Lt[xIndex].getAttribute('rel') : '';
                if( typeof( rel ) == 'string' && rel.toLowerCase().indexOf('style') + 1 ) { os[os.length] = Lt[xIndex]; }
        } for( var xIndex = 0; St[xIndex]; xIndex++ ) { os[os.length] = St[xIndex]; } return os;
}

function changeStyle() {
  window.userHasChosen = window.MWJss;
  for( var xIndex = 0, ss = getAllSheets(); ss[xIndex]; xIndex++ ) {
    if( ss[xIndex].title ) { ss[xIndex].disabled = true; }
    for( var yIndex = 0; yIndex < arguments.length; yIndex++ ) {
      if( ss[xIndex].title == arguments[yIndex] ) { ss[xIndex].disabled = false; }
    }
  }
}

     
function AddUrlParameter(sourceUrl, parameterName, parameterValue, replaceDuplicates) 
{ 
    if ((sourceUrl == null) || (sourceUrl.length == 0)) sourceUrl = document.location.href; 

    var removeNameTag = sourceUrl.split("#");
    var urlParts = removeNameTag[0].split("?"); 
    var newQueryString = ""; 

    if (urlParts.length > 1) 
    { 
        var parameters = urlParts[1].split("&"); 
        for (var i=0; (i < parameters.length); i++) 
        { 
                var parameterParts = parameters[i].split("="); 
                if (!(replaceDuplicates && parameterParts[0] == parameterName)) 
                { 
                        if (newQueryString == "") 
                                newQueryString = "?"; 
                        else 
                                newQueryString += "&"; 
                        newQueryString += parameterParts[0] + "=" + parameterParts[1]; 
                } 
        } 
    } 
    if (newQueryString == "") 
        newQueryString = "?"; 
    else 
        newQueryString += "&"; 
    newQueryString += parameterName + "=" + parameterValue; 
 
    return urlParts[0] + newQueryString; 
}  


