var oPopup = createPopup();
var oPopupBody = oPopup.document.body;

function MsgBox(sTxt,heading) {
   oPopupBody.style.backgroundColor = "lightyellow";
   oPopupBody.style.border = "solid aaabbb 1px";
   oPopupBody.innerHTML = getPopupString(400,150,sTxt,heading);
   oPopup.show(200,100,400,150,document.body);
}

function ShowDetail(sTxt,heading,Twidth,Theight) {
   oPopupBody.style.backgroundColor = "lightyellow";
   oPopupBody.style.border = "solid aaabbb 1px";
   if (Twidth == null) {Twidth = 400;}
   if (Theight== null) {Theight= 150;}
   oPopupBody.innerHTML = getPopupString(Twidth,Theight,sTxt,heading);
   oPopup.show(200,100,Twidth,Theight,document.body);
}

function getPopupString(width,height,sTxt,heading) {
   
   if (heading == null) {
      heading = "Message";
   }

   sTxt = "<table width=100% height=100% cellspacing=1 style='font-familiy:Arial;font-size:10pt'>"
        + "<tr>"
        + "<td bgcolor=b0c4de valign=top width=95% style='height:10pt'><B><font face=Arial size=2 color=white>&nbsp;" + heading + "</font><B> </td>"
        + "<td title='Click to close the Message Window' width=5% nowrap valign=bottom align=center style='height:10pt'><span style='width:100%;height=100%;border:solid aaabbb 1px;cursor:hand' onclick='window.parent.hidePopup();'><font face=Arial size=1 color=aaabbb>X</font></span></td>"
        + "<td></td>"
        + "</tr>"
        + "<tr><td colspan=3 width=100%>"
        + "<div align='center'" 
        + "style='left-margin:0;background-color:f0ffff;SCROLLBAR-TRACK-COLOR: lightyellow ;SCROLLBAR-ARROW-COLOR: white;SCROLLBAR-SHADOW-COLOR: lightyellow;SCROLLBAR-DARKSHADOW-COLOR: lightblue;scrollbar-face-color:aaabbb;SCROLLBAR-3DLIGHT-COLOR: lightyellow;position:relative; z-index:0; overflow: scroll; width:" + (width - 1 * width / 100) + ";height:" + (height - 22) + ";'>"
        + sTxt 
        + "</div>"
        + "</td></tr>"
        + "</table>";
   
   return sTxt;
   
}

function hidePopup() {
   oPopup.hide();
}

/* ===========Create XML Document =======================*/
/* START */
function xmlDoc(){
   var myxmlDoc = new ActiveXObject("Microsoft.XMLDOM");
   var Tstr = "<?xml version='1.0'?>\n" +
              "<Data></Data>";
   myxmlDoc.async = false;
   myxmlDoc.resolveExternals = false;
   myxmlDoc.loadXML(Tstr);
   return myxmlDoc;
}
/* END */



/* ===========Create XML Record Node ==========================*/
/* START */
function createxmlNode(myxmlDoc,myxmlRecName,myxmlRecAttrib){
   myxmlRec = myxmlDoc.createElement(myxmlRecName);
   myxmlRec.setAttribute("RecID", myxmlRecAttrib);
   return myxmlRec;
}
/* END */



/* ===========Append XML Record Node ==========================*/
/* START */
function addxmlRec(myxmlDoc,myxmlRec){
      myxmlDoc.documentElement.appendChild(myxmlRec);
   return myxmlRec;
}
/* END */


/* ===========Add XML Field Node ==========================*/
/* START */
function addxmlField(myxmlDoc,myxmlRec,myxmlFieldName,myxmlFieldValue){
   myxmlField = myxmlDoc.createElement(myxmlFieldName);
   myxmlField.text= myxmlFieldValue;
   myxmlRec.appendChild(myxmlField);
    return myxmlRec; 
}
/* END */


/* ===========Modify XML Record Node ==========================*/
/* START */
function modxmlRec(myxmlDoc,myxmlRecAttrib){
   var objXMLDOMNodeList = myxmlDoc.documentElement.childNodes;
   for (i=0;i<objXMLDOMNodeList.length; i++) {
      if (objXMLDOMNodeList.item(i).getAttribute("RecID") == myxmlRecAttrib) {
         Tnewobj = objXMLDOMNodeList.item(i);
      myxmlDoc.documentElement.replaceChild(myxmlRec, Tnewobj);
      }
   }     
   return myxmlRec;
}
/* END */


/* ===========Delete XML Record Node ==========================*/
/* START */
function delxmlRec(myxmlDoc,myxmlRecAttrib){
   var objXMLDOMNodeList = myxmlDoc.documentElement.childNodes;
   for (i=0;i<objXMLDOMNodeList.length; i++) {
      if (objXMLDOMNodeList.item(i).getAttribute("RecID") == myxmlRecAttrib) {
          myxmlDoc.documentElement.removeNamedItem("RecID");
      }
   }     
   return myxmlRec;
}
/* END */

/* ===========Send Request To Get Response from Server ==========================*/
/* START */
function getxmlResponse(target,myxmlDoc)    {
   var response = "";
   try {
       var httpObj = new ActiveXObject("Microsoft.XMLHTTP");
       httpObj.Open("POST", target, false, "", "");
       httpObj.setRequestHeader("Content-Type","text/xml");
       httpObj.Send (myxmlDoc);
       response = httpObj.ResponseText;
   } catch (e) {
      response = false;
   }
   return response;
}
/* END */


/* ===========Load Response Received from Server ==========================*/
/* START */
function loadxmlResponse(sTxt) {
   try {
       if (sTxt) {
           var domObj = new ActiveXObject("Microsoft.XMLDOM");
           domObj.loadXML(sTxt);
           return domObj;
       } else {
           alert("Invalid Response !");
           return false;
       }
   } catch (e) {
       alert("XML Loading Failed !");
       return false;
   }
}
/* END */


/* ===========Retrieve Value from Tag  ====================================*/
/* START */
function getTagValue(domObj,tagname,i) {
   var sVal = "";
   i = i - 1;
   if (i < 1) {
      i = 0;
   }
   if (domObj) {
          if (domObj.getElementsByTagName(tagname)(i) != null) {
             return domObj.getElementsByTagName(tagname)(i).text;
          } else {
             return "";
      }
   } else {
      alert("Invalid XML Object passed to getValue()");
   }

   return sVal;
}
/* END */

/* =========== Set Value of an existing Tag  ====================================*/
/* START */
function setTagValue(domObj, i, tagname, tagval) {
   /* this function shall always return the domObj -- whether modified or not */
   i = i - 1;
   if (i < 1) {
      i = 0;
   }

   if (domObj) {
      if (domObj.getElementsByTagName(tagname)(i) != null) {
         domObj.getElementsByTagName(tagname)(i).text = tagval;
      }
   } else {
      MsgBox("Invalid XML Object passed to setTagValue()");
   }

   return domObj;
}
/* END */

/* ==================Functions specific for generating List View =====================*/

function generateviewlist(Toption,Tcount,Treposition,sTxt,fld1,pos1,fld2,pos2,fld3,pos3,fld4,pos4,fld5,pos5,fld6,pos6,fld7,pos7,fld8,pos8,fld9,pos9,fld10,pos10,fld11,pos11,fld12,pos12,fld13,pos13,fld14,pos14,fld15,pos15,fld16,pos16,fld17,pos17,fld18,pos18,fld19,pos19,fld20,pos20)
{      
  var i = 1;
  var htmlStr = '';
  htmlStr = '<TABLE BORDER= "0" CELLSPACING=1 CELLPADDING=1 WIDTH=600 ALIGN="center">' + 
            '<tr bgcolor=5F9EA0>';
            if (fld1 != null) {htmlStr += '<TD align="' + pos1 + '">' + fld1 + '</TD>' ;}
            if (fld2 != null) {htmlStr += '<TD align="' + pos2 + '">' + fld2 + '</TD>' ;}
            if (fld3 != null) {htmlStr += '<TD align="' + pos3 + '">' + fld3 + '</TD>' ;}
            if (fld4 != null) {htmlStr += '<TD align="' + pos4 + '">' + fld4 + '</TD>' ;}
            if (fld5 != null) {htmlStr += '<TD align="' + pos5 + '">' + fld5 + '</TD>' ;}
            if (fld6 != null) {htmlStr += '<TD align="' + pos6 + '">' + fld6 + '</TD>' ;}
            if (fld7 != null) {htmlStr += '<TD align="' + pos7 + '">' + fld7 + '</TD>' ;}
            if (fld8 != null) {htmlStr += '<TD align="' + pos8 + '">' + fld8 + '</TD>' ;}
            if (fld9 != null) {htmlStr += '<TD align="' + pos9 + '">' + fld9 + '</TD>' ;}
            if (fld10 != null) {htmlStr += '<TD align="' + pos10 + '">' + fld10 + '</TD>' ;}
            if (fld11 != null) {htmlStr += '<TD align="' + pos11 + '">' + fld11 + '</TD>' ;}
            if (fld12 != null) {htmlStr += '<TD align="' + pos12 + '">' + fld12 + '</TD>' ;}
            if (fld13 != null) {htmlStr += '<TD align="' + pos13 + '">' + fld13 + '</TD>' ;}
            if (fld14 != null) {htmlStr += '<TD align="' + pos14 + '">' + fld14 + '</TD>' ;}
            if (fld15 != null) {htmlStr += '<TD align="' + pos15 + '">' + fld15 + '</TD>' ;}
            if (fld16 != null) {htmlStr += '<TD align="' + pos16 + '">' + fld16 + '</TD>' ;}
            if (fld17 != null) {htmlStr += '<TD align="' + pos17 + '">' + fld17 + '</TD>' ;}
            if (fld18 != null) {htmlStr += '<TD align="' + pos18 + '">' + fld18 + '</TD>' ;}
            if (fld19 != null) {htmlStr += '<TD align="' + pos19 + '">' + fld19 + '</TD>' ;}
            if (fld20 != null) {htmlStr += '<TD align="' + pos20 + '">' + fld20 + '</TD>' ;}
               htmlStr += '</TR>';
  var httpObj = loadxmlResponse(sTxt);
  if (httpObj) 
  {   
    if (getTagValue(httpObj,'GetError',1) == '') 
    { 
      do {    
          switch (Toption)
             {
               case "Static":
                  htmlStr += '<TR onmouseover="this.style.backgroundColor=' + 
                       "'lightblue'" + ';" onmouseout="this.style.backgroundColor=' + 
                       "'f0ffff'" + ';" bgcolor=f0ffff >';
               break;
               case "Dynamic":
                  htmlStr += '<TR onmouseover="this.style.backgroundColor=' + 
                       "'lightblue'" + ';" onmouseout="this.style.backgroundColor=' + 
                       "'f0ffff'" + ';" bgcolor=f0ffff style=cursor:hand onclick="populatefield(sTxt,' + i + ');">';
               break;
             }
            
            if (fld1 != null) {htmlStr += '<TD id=A' + i + ' align="' + pos1 + '">' + getTagValue(httpObj,fld1,i) + '</TD>' ;}
            if (fld2 != null) {htmlStr += '<TD id=B' + i + ' align="' + pos2 + '">' + getTagValue(httpObj,fld2,i) + '</TD>' ;}
            if (fld3 != null) {htmlStr += '<TD id=C' + i + ' align="' + pos3 + '">' + getTagValue(httpObj,fld3,i) + '</TD>' ;}
            if (fld4 != null) {htmlStr += '<TD id=D' + i + ' align="' + pos4 + '">' + getTagValue(httpObj,fld4,i) + '</TD>' ;}
            if (fld5 != null) {htmlStr += '<TD id=E' + i + ' align="' + pos5 + '">' + getTagValue(httpObj,fld5,i) + '</TD>' ;}
            if (fld6 != null) {htmlStr += '<TD id=F' + i + ' align="' + pos6 + '">' + getTagValue(httpObj,fld6,i) + '</TD>' ;}
            if (fld7 != null) {htmlStr += '<TD id=G' + i + ' align="' + pos7 + '">' + getTagValue(httpObj,fld7,i) + '</TD>' ;}
            if (fld8 != null) {htmlStr += '<TD id=H' + i + ' align="' + pos8 + '">' + getTagValue(httpObj,fld8,i) + '</TD>' ;}
            if (fld9 != null) {htmlStr += '<TD id=I' + i + ' align="' + pos9 + '">' + getTagValue(httpObj,fld9,i) + '</TD>' ;}
            if (fld10 != null) {htmlStr += '<TD id=J' + i + ' align="' + pos10 + '">' + getTagValue(httpObj,fld10,i) + '</TD>' ;}
            if (fld11 != null) {htmlStr += '<TD id=K' + i + ' align="' + pos11 + '">' + getTagValue(httpObj,fld11,i) + '</TD>' ;}
            if (fld12 != null) {htmlStr += '<TD id=L' + i + ' align="' + pos12 + '">' + getTagValue(httpObj,fld12,i) + '</TD>' ;}
            if (fld13 != null) {htmlStr += '<TD id=M' + i + ' align="' + pos13 + '">' + getTagValue(httpObj,fld13,i) + '</TD>' ;}
            if (fld14 != null) {htmlStr += '<TD id=N' + i + ' align="' + pos14 + '">' + getTagValue(httpObj,fld14,i) + '</TD>' ;}
            if (fld15 != null) {htmlStr += '<TD id=O' + i + ' align="' + pos15 + '">' + getTagValue(httpObj,fld15,i) + '</TD>' ;}
            if (fld16 != null) {htmlStr += '<TD id=P' + i + ' align="' + pos16 + '">' + getTagValue(httpObj,fld16,i) + '</TD>' ;}
            if (fld17 != null) {htmlStr += '<TD id=Q' + i + ' align="' + pos17 + '">' + getTagValue(httpObj,fld17,i) + '</TD>' ;}
            if (fld18 != null) {htmlStr += '<TD id=R' + i + ' align="' + pos18 + '">' + getTagValue(httpObj,fld18,i) + '</TD>' ;}
            if (fld19 != null) {htmlStr += '<TD id=S' + i + ' align="' + pos19 + '">' + getTagValue(httpObj,fld19,i) + '</TD>' ;}
            if (fld20 != null) {htmlStr += '<TD id=T' + i + ' align="' + pos20 + '">' + getTagValue(httpObj,fld20,i) + '</TD>' ;}
            htmlStr += '</TR>';
            
            i++;
         } while ( getTagValue(httpObj,fld1,i) != '' );
         htmlStr += '</table>';
         mylist.innerHTML = htmlStr;
      }
    }

    if (getTagValue(httpObj,'GetError',1) != '') 
    {
       MsgBox(getTagValue(httpObj,'GetError',1), "Error");
       /* Reset the Tcount value to the previous value */
       switch (Treposition) {
         case "Prev":
            Tcount = parseInt(Tcount) + 1;
            break;
         case "Next":
            Tcount = parseInt(Tcount) - 1;
            break;
    }
  }
    return Tcount;          
}

function setcounter(Tcount,Treposition)
{
   switch (Treposition) {
   case "Prev":
     Tcount = parseInt(Tcount) - 1;
     break;
   case "Next":
     Tcount = parseInt(Tcount) + 1;
     break;
   }
   return Tcount;
}
/* END */




/* ==================Functions specific for generating Help List ====================*/
/* START */
function gblhelp(x, y, width, height, myopt, myprog, myfld1, myarg1, myfld2, myarg2, myfld3, myarg3, myfld4, myarg4, myfld5, myarg5, myfld6, myarg6, myfld7, myarg7, myfld8, myarg8, myfld9, myarg9, myfld10, myarg10, myfld11, myarg11, myfld12, myarg12, myfld13, myarg13, myfld14, myarg14, myfld15, myarg15,myfld16, myarg16, myfld17, myarg17, myfld18, myarg18, myfld19, myarg19, myfld20, myarg20) 
{
   var hlpurl = myprog +'?Woption=' + myopt + '&Wwidth=' + width + 
                '&FieldName1=' + myfld1 + '&FieldValue1=' + myarg1 + 
                '&FieldName2=' + myfld2 + '&FieldValue2=' + myarg2 + 
                '&FieldName3=' + myfld3 + '&FieldValue3=' + myarg3 + 
                '&FieldName4=' + myfld4 + '&FieldValue4=' + myarg4 +
                '&FieldName5=' + myfld5 + '&FieldValue5=' + myarg5 + 
                '&FieldName6=' + myfld6 + '&FieldValue6=' + myarg6 +
                '&FieldName7=' + myfld7 + '&FieldValue7=' + myarg7 +
                '&FieldName8=' + myfld8 + '&FieldValue8=' + myarg8 +
                '&FieldName9=' + myfld9 + '&FieldValue9=' + myarg9 +
                '&FieldName10=' + myfld10 + '&FieldValue10=' + myarg10 +
                '&FieldName11=' + myfld11 + '&FieldValue11=' + myarg11 +
                '&FieldName12=' + myfld12 + '&FieldValue12=' + myarg12 +
                '&FieldName13=' + myfld13 + '&FieldValue13=' + myarg13 +
                '&FieldName14=' + myfld14 + '&FieldValue14=' + myarg14 +
                '&FieldName15=' + myfld15 + '&FieldValue15=' + myarg15 +
                '&FieldName16=' + myfld16 + '&FieldValue16=' + myarg16 +
                '&FieldName17=' + myfld17 + '&FieldValue17=' + myarg17 +
                '&FieldName18=' + myfld18 + '&FieldValue18=' + myarg18 +
                '&FieldName19=' + myfld19 + '&FieldValue19=' + myarg19 +
                '&FieldName20=' + myfld20 + '&FieldValue20=' + myarg20 ;
   var wnd=showHelp(x, y, width, height, hlpurl);
   return;
}

function showHelp(x,y,width,height,target) {
   var sTxt = getxmlResponse(target,"");
   if (sTxt) {
       oPopupBody.style.backgroundColor = "lightblue";
       oPopupBody.style.border = "solid aaabbb 1px";
       oPopupBody.innerHTML = getPopupString(width,height,sTxt,"Help");
       oPopup.show(x,y,width,height,document.body);
   } 
   else
   {
      MsgBox("Error While Trying to Send Request to Server","ERROR");
   }
}


/*Quaid Johar start */
function isvalidxml(xmldoc)
{
  if (xmldoc.parseError.errorCode == 0)
    return true;
  else
    return false;
}

function getxmlerror(xmldoc)
{
  var str = '';
  str =  str + "ErrorCode     \t:"   +  xmldoc.parseError.errorCode + "\n";
  str =  str + "Reason        \t "   +  xmldoc.parseError.reason    + "\n";
//  str =  str + "Url         \t:"   +  xmldoc.parseError.url       + "\n";
//  str =  str + "File Position \t:"   +  xmldoc.parseError.filepos   + "\n";
//  str =  str + "Line          \t:"   +  xmldoc.parseError.line      + "\n"; commented by dilip
//  str =  str + "Line Position \t:"   +  xmldoc.parseError.linepos   + "\n"; commented by dilip
//  str =  str + "Source Text   \t:"   +  xmldoc.parseError.srcText   + "\n";
  return str;
}
/*Quaid Johar End */

/* Function for finding out whether the report will run in batch or online*/
/* Dilip 17/12/2003 Start*/
function checkReportMethod(Tuid,Tsessid,Tloctype,Tloccode,Treportid,Trange){
       chkrepDoc   = new xmlDoc();                                                                  
       chkrepRec   = createxmlNode(chkrepDoc,"Record","0");
       chkrepField = addxmlField(chkrepDoc,chkrepRec,"uid",Tuid);
       chkrepField = addxmlField(chkrepDoc,chkrepRec,"sessid",Tsessid);
       chkrepField = addxmlField(chkrepDoc,chkrepRec,"LocationType",Tloctype);
       chkrepField = addxmlField(chkrepDoc,chkrepRec,"LocationCode",Tloccode);
       chkrepField = addxmlField(chkrepDoc,chkrepRec,"ReportID",Treportid);
       chkrepField = addxmlField(chkrepDoc,chkrepRec,"Range",Trange);

       chkrepRec = addxmlRec(chkrepDoc,chkrepRec);                                                  
       sTxt     = getxmlResponse("GBLCheckRunMethod",chkrepDoc);
       var httpObj = loadxmlResponse(sTxt);
       if (httpObj)
         {
           Woption = getTagValue(httpObj,"RunMethod",1);
           return Woption;
         }
}
/* Dilip 17/12/2003 End*/
/* END */





