//----------------------------------------------------
//global variables
var arMsg = new Array();
var arOffset = new Array();
var arColor = new Array();

var currentMsgID = 1;

//----------------------------------------------------
//initialize functions
function initPage()
{
    arMsg[0]    = "Printing...";
    arOffset[0] = 40;
    arColor[0] = "green";
    
    arMsg[1]    = "Please drop anything.";
    arOffset[1] = 10;
    arColor[1] = "blue";
    
    arMsg[2]    = "Drop, drop it!";
    arOffset[2] = 30;
    arColor[2] = "maroon";

    arMsg[3]    = "Can't print the item.";
    arOffset[3] = 12;
    arColor[3] = "red";    
    
    showMessage(1);
}

//----------------------------------------------------
function showMessage( msgID )
{
    var msg = document.getElementById("quickMessage");
    
    try
    {
        msg.style.left = arOffset[msgID];
        msg.innerHTML = arMsg[msgID];
        msg.style.color = arColor[msgID];
    }
    catch ( err )
    {
        msg.style.left = 17;
        msg.innerHTML = "Incorrect message!";
        msgID = 1;
    }
    
    msg.style.visibility = "visible";
    
    currentMsgID = msgID;
}

//----------------------------------------------------
function printDoc(path) 
{
    var syspath = System.Environment.getEnvironmentVariable("windir");
    
    System.Shell.execute('rundll32.exe', syspath + '\\system32\\mshtml.dll,PrintHTML "' + path);
}

//----------------------------------------------------
function fileDragDropped()
{
    var oFile = null;
    var i=0;
   
    showMessage(0);

    try 
    {
        while(true)
        {
            oFile = System.Shell.itemFromFileDrop(event.dataTransfer, i);
            
            if ( oFile == null )
              break;
            
            var theFile = System.Shell.itemFromPath(oFile.path);
            
            // checking: is it folder?
            if( !theFile.isFolder )
            {
                //this is doc - try to print it
                printDoc(oFile.path);
            }
            else
            {
                //if it's folder - show message
                showMessage(3);
                break;
            }
            
            i++;
        }
    } 
    catch ( err ) 
    { 
         showMessage(3);
    }

    if ( currentMsgID != 3 )
      showMessage(1);
}

//----------------------------------------------------
function fileDragOver()
{
    showMessage(2);
}

//----------------------------------------------------
function fileDragLeave()
{
    if ( currentMsgID != 0 && currentMsgID != 3)
        showMessage(1);
}