function makePrintFriendlyURL(currentLocation)
{
    //ITWorld newsletters
    if ( currentLocation.indexOf("http://www.itworld.com/nl/") != -1 )
    {        
        return currentLocation + '/pf_index.html';
    }
    
    //Washington post (but not all stories...)
    if ( currentLocation.indexOf("http://www.washingtonpost.com/ac2/wp-dyn/") != -1 )
    {
        return currentLocation + '?language=printer';
    }
    
    //more Washington post
    if ( currentLocation.indexOf("http://www.washingtonpost.com/wp-dyn/articles/") != -1)
    {
        return "http://www.washingtonpost.com/ac2/wp-dyn/" + currentLocation.substring( 46, currentLocation.length - 5) + '?language=printer';
    }
    
    
    //O'Reilly Java articles
    if ( currentLocation.indexOf("onjava.com") != -1 ||
         currentLocation.indexOf("macdevcenter.com") != -1 ||
         currentLocation.indexOf("oreillynet.com") != -1 ||
         currentLocation.indexOf("ondotnet.com") != -1 ||
         currentLocation.indexOf("onlamp.com") != -1 ||
         currentLocation.indexOf("openp2p.com") != -1 || 
         currentLocation.indexOf("osdir.com") != -1 || 
         currentLocation.indexOf("perl.com") != -1 || 
         currentLocation.indexOf("xml.com") != -1 ||
         currentLocation.indexOf("java.net") != -1)
    {
        //find the print link
        links = document.links
        for (i=0; i<links.length; i++)
        {
            href = links[i].href;
            if (href.indexOf("/lpt/a/") != -1)
            {
                return href; 
            }
        }
    }
    
    //Javaworld
    if (currentLocation.indexOf("javaworld.com") != -1 )
    {        
        return currentLocation.substring( 0, currentLocation.length - 6 ) + "_p.html";
    }
    
    //Gamasutra
    if (currentLocation.indexOf("gamasutra.com") != -1 )
    {
        document.cookie="GamaDemo2="+Math.random()+";path=/";
        var l="http://"+window.location.host+window.location.search.substring(6); 
        return l; 
    }

    //artima
    if (currentLocation.indexOf("artima.com") != -1 )
    {       
       // only if not in forums
       if (currentLocation.indexOf("forums") == -1 ) {
           return currentLocation.substring( 0, currentLocation.length - 5 ) + "P.html";  
       }
    }
    
    return null;
}

function viewPrintFriendly()
{    
    var current = window.location.href;
    
    var newLocation = makePrintFriendlyURL(current);
   
    if (newLocation != null)
    {
        window.location = newLocation;
    }
    else
    {
        alert("Unable to determine print-friendly page.\n\nIf you can help extend this Javascript\n\nEmail leigh@ldodds.com");
    }
}

viewPrintFriendly();

