var gIssueId;

// Function to create a smart issue
function createIssue(ProblemDescription)
{
  try
  {
    // Make sure that the si control was loaded 
    if (document.si != null && document.si.ModuleVersion != null)
    {
      //var curServer = '<%=sdcHTMLEncode(sdcGlobalServer)%>'; 
      //document.si.SetCurrentServer(curServer);
      //alert(gTemplateFn);
      document.si.SetDataSpecFile(gTemplateFn);    
      var issueId = document.si.NewIssue(ProblemDescription);     
      gIssueId = issueId;
      document.si.SetCurrentIssue(issueId); 
      //document.write("<hr><b>New Issue Created</b></hr> "+issueId);
      //document.write("<br>");
    }
  }
  catch (err)
  {
    //alert("Smartissue data will not be available");
  }

}
////////////////////////////////////////////////////////////////////////
// Function to retrieve the value of a smart issue property, given 
// its fully qualified name.
// Name has to be in the form class::instance::property, 
// class::?::property, or class::*::property where class and property names
// are as defined in the default.xml file.
// e.g. Win32_OperatingSystem::?::OSVersion
// If ? is passed, the value of the property is returned.
// If * is passed, the value returned is <instancename,propertyValue>
//
// If no smart issue data was gathered, returns a blank
function getSmartVal(smartValStr)
{ 
  var result = "";
  try 
  {  
    if (document.si != null && document.si.ModuleVersion != null)
    {
      var issueId = document.si.GetCurrentIssue();
      if (issueId == "") issueId = gIssueId;
      //alert(issueId);
      if(issueId != "") {
        result = unescape(document.si.ExpandMacros(document.si.GetIssueFile(issueId), "%"+smartValStr+"%"));
        // if the smart issue wasn't harvested, return a blank
        if (result.charAt(0) == '%') result = "";      
      }
    }
  }
  
  catch (err)
  {
    //alert("Smartissue data not available");
  }
  return result;
}

function getClassInstances(className)
{
  var result = "";
  try
  {
    if (document.si != null && document.si.ModuleVersion != null)
    {
      var issueId = document.si.GetCurrentIssue();
      if (issueId == "") issueId = gIssueId;
      //alert(issueId);
      if(issueId != "") 
      {
        document.si.StartXMLIO(document.si.GetIssueFile(issueId));
        result = document.si.GetXMLSections(className);
        // if the smart issue wasn't harvested, return a blank
        if (result.charAt(0) == '%') result = "";      
        document.si.EndXMLIO();
      }
    }
  }
  catch (err)
  {
    //alert("Smartissue data not available");
  }
  
  return result;
}

