// Dialog window for all bottom-level dialog operations

function OpenDialogWindow(url) {
  aPopup=OpenWindow(url, 'Dialog', 500, 400)
}

// Dialog window for file/open operations

function OpenFileDialogWindow(url) {
  aPopup=window.open(url,'_FDialog','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=400');
  //aPopup=window.open(url, '_FDialog');
  aPopup.focus();
}

// Error window for projectDirectory error messages

function OpenErrorWindow(Message) {
  aPopup=OpenWindow('','Error',400,150)
  nDoc=aPopup.document;
  nDoc.open();
  aStr = "<html><head><title>Error Message</title>";
  aStr+="<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/peak-styles.css\">";
  aStr += "<body class=\"error\">\n";
  aStr += "<p class=\"error\">Error</p>\n";
  aStr += "<p class=\"sans12ptc\">";
  aStr += Message + "</p>\n";
  aStr += "<div align=\"center\"><a href=\"javascript:self.close()\">";
  aStr += "<img src=\"images/btnOK.gif\" border=\"0\"></a></div>\n";
  nDoc.write(aStr);
  nDoc.close();
}

// Create a window for a chat session

function OpenChatWindow(AccountID, RoomID, UserID) {
  Op = ((UserID>0)?"invite":"init");
  url='chatLoad.php?Op=' + Op + '&AccountID=' + AccountID + '&RoomID=' + RoomID + '&UserID=' + UserID;
  aPopup=OpenWindow(url, 'Chat', 500, 220)
}

// Create a window for message center

function OpenMsgWindow(AccountID, ForumID, MsgID, Op) {
  url='msgMessage.php?Op=' + Op + '&AccountID=' + AccountID + '&ForumID=' + ForumID + '&MsgID=' + MsgID;
  aPopup=window.open(url,'_Message','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=400');
  aPopup.focus();
  if (!aPopup.opener) aPopup.opener = window;  // AOL IE bug
}

// Create a generic browser window

function OpenWindow(url, winName, width, height) {
  aPopup=window.open(url,'_'+winName,'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,copyhistory=no,width=' + width + ',height=' + height)
  //aPopup=window.open(url,'_'+winName)
  aPopup.focus()
  return aPopup
}
// Create a generic browser window

function OpenScrollWindow(url, winName, width, height) {
  aPopup=window.open(url,'_'+winName,'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + width + ',height=' + height)
  //aPopup=window.open(url,'_'+winName)
  aPopup.focus()
  return aPopup
}

// Open a tool window and start the processflow tool

function OpenProcessflowTool(DocID, DB, Access) {
  if (DocID)
    url='startTool.php?DocumentID=' + DocID + '&Access=' + Access;
  else 
    url='/cgi-bin/processflow';
  aPopup = OpenWindow(url, 'PFT', 600, 600);
}

// Open a tool window and start the questionnaire tool

function OpenQuestionTool(QDefID, Access) {
  url='quesTool.php?QDefID=' + QDefID + '&Access=' + Access
  aPopup = OpenScrollWindow(url, 'QT', 800, 600);
}

// Open a tool window and start the ISO tool

function OpenISOTool(quesName) {
  url='isoTool.php?ISOOp=start&QuesName=' + escape(quesName)
  aPopup = OpenScrollWindow(url, 'QT', 800, 650)
}

// Open a tool window and start the questionaire editing tool

function OpenQuestionnaireTool(DocID, DB, Access) {
  if (DocID)
    url='startTool.php?DocumentID=' + DocID + '&Access=' + Access;
  else 
    url='quesEditor.php';
  aPopup = OpenWindow(url, 'QET', 800,600);
}

// Open a tool window and start the data model class editing tool

function OpenDataModelClassEditor(DocID, DB, Access) {
  if (DocID)
    url='startTool.php?DocumentID=' + DocID + '&Access=' + Access;
  else 
    url='dmDataModelClassEditor.php';
  aPopup = OpenWindow(url, 'DMCE', 800,600);
}

// Open a tool window and start the data model class editing tool

function OpenRelationshipDefsEditor(DocID, DB, Access) {
  if (DocID)
    url='startTool.php?DocumentID=' + DocID + '&Access=' + Access;
  else 
    url='dmRelationshipDefsEditor.php';
  aPopup = OpenWindow(url, 'DMRE', 800,600);
}

// Call up the appropriate URL for document editing
// Parm1 is DocumentID.  Parm2 is DB.  Parm3 is DocType.

var Parm1,Parm2,Parm3

function InvokeTool(Access) {
  if (1<<Parm3 & gExtDocTypes)
    self.location='documentDump.php?DocumentID=' + Parm1;
  else if (Parm3 == gDocTypeProcess)
    OpenProcessflowTool(Parm1,Parm2,Access);
  else if (Parm3 == gDocTypeQues)
    OpenQuestionTool(Parm1,'',Access);
  else if (Parm3 == gDocTypeQuesXML)
    OpenQuestionnaireTool(Parm1,Parm2,Access);
  else if (Parm3 == gDocTypeDMCXML)
    OpenDataModelClassEditor(Parm1,Parm2,Access);
  else if (Parm3 == gDocTypeRELXML)
    OpenRelationshipDefsEditor(Parm1,Parm2,Access);
}

// resize the window so the content fits

function FixWindow(id,maxOnly) {
  if (gIsIE) {
    winHeight = document.body.clientHeight
    docHeight = document.all[id].offsetTop
  }
  else if (gIsN6) {
    winHeight = window.innerHeight
    docHeight = document.getElementById(id).offsetTop
  }
  else {
    winHeight = window.innerHeight
    docHeight = document.layers[id].pageY
  }
  if (!maxOnly || docHeight > winHeight)
    window.resizeBy(0, docHeight-winHeight+10)
}

// get a file from the server for download

function getFileByID(id) {
  URL='getFile.php?ID=' + id
  self.location.href=URL
}

function getFileByName(name) {
  URL='getFile.php?IDName=' + name
  self.location.href=URL
}

// get a doc file from the server for download

function getDocFileByID(id) {
  URL='getDocFile.php?ID=' + id
  self.location.href=URL
}

// Determine which browser is being used

function CheckBrowser() {
  aStr = 'browserCheck.php?'

  if (window.innerWidth)
    aStr += '&Width=' + window.innerWidth + '&Height=' + window.innerHeight
  else if (document.body.clientWidth)
    aStr += '&Width=' + document.body.clientWidth + '&Height=' + document.body.clientHeight
  else
    aStr += '&Width=-1&Height=-1'
  document.location=aStr
}

// insert URLS into page to avoid SPAMMer scraping
var dRefIds = new Array()

function addRef(refId) {
    dRefIds[dRefIds.length] = refId
}
    
function displayURLRefs(objId) {
    for (i=0; i<dRefIds.length; i++) {
        obj = document.getElementById(dRefIds[i])
        if (obj) {
            mail = obj.getAttribute('dMail')
            host = obj.getAttribute('dHost')
            domain = obj.getAttribute('dDomain')
            tld = obj.getAttribute('dTld')

            proto = (mail?'mailto:':'http://')
            url = (mail?mail+'@':'') + (host?host+'.':'') + domain + '.' + tld

            obj.href = proto + url
            obj.innerHTML = url
        }
    }
}

