//If the user is authenticated, open the link in a new window. Otherwise, open it 
//in the same window. The optional additionalData parameter allows users to specify data which 
//should be appended to the final URL used.
//var newWindow;
function openLink(URL, additionalData)
{
try
{
    if(!additionalData)
        additionalData = '';

    //if(document.cookie == "")
    if(document.cookie.indexOf("OmniAuth") == -1)
    {
        URL += "&referrer=" + window.location.href + additionalData;
        //alert(URL);
        
        window.location.href = URL;
    }
    else
    {
        var fileName = getParam("fileName", URL);
        var folder = getParam("folder", URL);
    
        //var settings = "copyHistory=no,location=no,menubar=no,status=no,toolbar=no,directories=no,resizable=yes";
        
        var winWidth = 800;
        var winHeight = 700;
        var winTop = 150;
        var winLeft = 300;        
        if(fileName.search(".zip") != -1)
        {
            winWidth = -1;
            winHeight = -1;
            
            winTop = 9000;
            winLeft = -9000;
        }
        
        
        var settings = "copyHistory=no,location=no,menubar=no,status=no,toolbar=no,directories=no,resizable=yes,";
        settings += "width=" + winWidth + ",height=" + winHeight + ",";
        settings += "left=" + winLeft + ",top=" + winTop;
        
        var link = "/docsandsoftware/downloadPage.aspx?fileName=" + fileName + "&folder=" + folder + "&market=.SM" + additionalData;
        
        var newWindow;
        if( fileName.search(".pdf") > -1 )
            newWindow = window.open(link, "myWin", settings);
        else
            window.location.href = link;
        
        
        //Close the new/blank window after a few seconds. This is necissary for FF, which doesn't
        //automatically close blank windows. We only close the window, though, if it's indeed blank
        //(ie: it shows a Save/Open dialog box and nothing more). Below, we assume that anything other
        //than a .pdf will display the Save/Open dialog.
        
        
        if( fileName.search(".pdf") == -1 )
        {
            //newWindow.document.write( "<script language='javascrip'>alert('');</script>"  );
            //newWindow.document.close();
            
            
            //newWindow.resizeTo(1,1);
            
            //self.focus();
        
        
            //if( newWindow && newWindow != null )
            //    setTimeout( 'newWindow.close()', 10000 );
                //setTimeout( 'CloseWin(' + newWindow + ')', 10000 );
        
            
        }
                
    }
    
    
    return false;
}
catch(error)
{}
}


function CloseWin( win )
{
    try
    {
       // if(win)
       //     alert(win);
            
        //if(win && win != null && win.open && !win.closed)
            win.close();
    }
    catch(err)
    {}
    
}