/*
 * Copyright IPVision, Inc 2003 - 2005.   All rights reserved.
 */
 
/** The constructor for a new AppDocInfo object */
function AppDocInfo(docInfo)
{
	appDocInfoInit(this);

	this.docId = docInfo.docId;
	this.descr = docInfo.description;
	this.histTree = adaptInfoTree(docInfo);
	this.notes = docInfo.Note;
    if (docInfo.ResultInfo)
        this.resultInfo = docInfo.ResultInfo;
}

/** The initializer for an AppDocInfo object */
function appDocInfoInit(object)
{
	uiElementInit(object);
	object.descr = 'document';
	object.histTree = false;
	object.notes = new Array();

	object.build = appDocInfoBuildHTML;
}

/** Builds the HTML for the document info object */
function appDocInfoBuildHTML()
{
	this.resetHTML();
	this.addHTML('<table border="0" cellpadding="3" cellspacing="0">');
	this.addHTML('<tr><td><font class="infoSect">DESCRIPTION:</font></td></tr>');
	this.addHTML('<tr><td><font class="info">' + ToXmlText(this.descr) + '</font></td></tr>');
	this.addHTML('<tr><td><font class="infoSect">HISTORY:</font></td></tr>');
	this.addHTML('<tr><td>' + this.histTree.getHTML() + '</td></tr>');
	if (this.resultInfo && this.resultInfo.length > 0)
	{
	    this.addHTML('<tr><td><font class="infoSect">RESULT INFO:</font></td></tr>');
	    for ( var iResult = 0; iResult < this.resultInfo.length; iResult++ )
	    {
	        var result = this.resultInfo[iResult];
	        var iconImg = GetResultInfoTypeIconImg(result);
	        this.addHTML('<tr><td>');
	        if (iconImg != null)
	        {
	            this.addHTML('<img src="' + IMG_PATH + iconImg + '" width=17 height=16 </img>');
	        }
	        this.addHTML('<font class="info">' + ToXmlText(result.type.substring(0,1).toUpperCase() + result.type.substring(1)) +  " : " + ToXmlText(result.message) + '</font></td></tr>');
        }
	}
	this.addHTML('<tr><td><font class="infoSect">NOTES:</font></td></tr>');
	if ( this.notes.length < 1 )
	{
		this.addHTML('<tr><td><font class="info">Document has no notes</font></td></tr>');
    }
	for ( var iNote = 0; iNote < this.notes.length; iNote++ )
	{
		var note = this.notes[iNote];
        var dateTimeText = FormatDateTime(note.noteTs);
		this.addHTML('<tr><td><font class="info">Note added by ' + note.user + ' on ' + dateTimeText + '</font>');
        this.addHTML('<tr><td><table border="0" cellpadding="3" cellspacing="0">');
		this.addHTML('<tr><td>&nbsp&nbsp&nbsp<td><font class="info">' + ToXmlText(note.note) + '</font></td></tr>');
        this.addHTML('</table></td></tr>');
	}

    if(currentDocPath)
	{
        var url = DocPathToUri(currentDocPath, this.docId);
        if(typeof(currentDocParams) == "string")
            url = url + "&" + currentDocParams;
        this.addHTML('<tr><td><font class="infoSect">FILE LINK:</font>');
		if(IsIE()) {
			this.addHTML('<input id="docLink" type="hidden" value="' + url + '"></input>');
			this.addHTML('&nbsp;&nbsp;&nbsp;<a class="info" href="#" ')
			this.addHTML('onclick="GetDomElem(\'docLink\').createTextRange().execCommand(\'copy\');">(Copy link to clipboard)</a>');
		}
		this.addHTML('</td></tr>');
		this.addHTML('<tr><td><font class="info">' + url + '</font></td></tr>');
   }

	this.addHTML('</table>');
}

//====================================================================================
// GLOBAL FUNCTION
//====================================================================================

var gDocInfoObj = new AppDocInfo(docInfo);
gDocInfoObj.render();