// Copyright 2000 Macromedia, Inc. All rights reserved.

//***************        GLOBALS       ***************

//??? The following globals should be moved in the localString file
//??? References will then be changed to the MM.STR... type.
var STR_UNTITLED = 'Untitled Document';     // global constant

var LEVEL_NOTE = 'NOTE';         // global constant
var LEVEL_ALERT = 'ALERT';       // global constant
var LEVEL_WARNING = 'WARNING';   // global constant
var LEVEL_ERROR = 'ERROR';       // global constant

var ARRAY_EXTENSION = new Array("HTM","HTML","SHTM","SHTML","STM","XML","LBI","DWT","ASP","CFM","CFML","PHP","LASSO","JSP");

//***************    LOCAL FUNCTIONS   ***************

//---------------
//??? Do not ship this code is temporary replace with DW line number API
function getLineNumber(curDOM, offsets) {
//??? I mean it!!!***********
  if (curDOM) {
    var searchText = curDOM.documentElement.outerHTML.substring(0,offsets[0]);
    return searchText.split('\r').length;
  } else {
    return null;
  }
}

//---------------
function getFileName(url) {
  var index = url.lastIndexOf('/');
  if (index != -1) retVal = url.substring(index + 1);
  else retVal = fileURL;
  return retVal;
}

//---------------
function reportItem(severity, fileURL, strDesc, offsets) {
  var strIcon = 1;
  var iStartSel = (offsets) ? offsets[0] : 0;
  var iEndSel = (offsets) ? offsets[1] : 0;
  var nameStr = getFileName(fileURL);
      // Get the line number from the selection and the document.
//??? Replace with the API that really computes the line numbers.
  var iLineNo = (offsets) ? getLineNumber(dw.getDocumentDOM(fileURL), offsets) : 0;

  
  switch (severity) {  // Convert severity to an icon
    case 'NOTE' :
      strIcon = 7;
      break;
    case 'ALERT' :
      strIcon = 7;
      break;
    case 'WARNING' :
      strIcon = 7;
      break;
    case 'ERROR' :
      strIcon = 6;
      break;
    default :
      break;
  }

  dw.results.addResultItem(this, fileURL, strIcon, nameStr, strDesc, iLineNo, iStartSel, iEndSel);

}


//---------------
// Emulates printf("blah blah %s blah %s",str1,str2)
// Used for concatenating report messages for easier localization.
// Returns assembled string.
//
function printString(formatStr) {
  var inArr = formatStr.split('%s');
  var outArr = new Array(inArr[0]);
  
  for (var i=1; i<inArr.length; i++) {
    outArr.push(arguments[i]);
    outArr.push(inArr[i]);
  }
  return outArr.join(''); // Convert Array to string for output.
}

//---------------
// Reads in the extension in Configuration/Extensions.txt and creates an array of extensions
//
// 
//
function isHTMLType(filename)
{
  var index,theExt, retVal=false;
  index = filename.lastIndexOf(".");
  if (index != -1)
  {
    theExt = filename.substring(index+1).toUpperCase();
    for (var i=0; i < ARRAY_EXTENSION.length; i++)
    {
      if (theExt == ARRAY_EXTENSION[i])
	  {
	    retVal=true;
	    break;
	  }
    }
  }
  return retVal;
}
