var currentHost = unescape(window.location.host);

function DllURL() {
  var sPath = unescape(window.location.pathname);
  var iPos = sPath.lastIndexOf('/', sPath.length);
  var sResult = "http://"+currentHost+sPath.substring(0, iPos); 
  return sResult; 
}
function SubDblQuotes(theText) {
  var newText = theText.replace('&quot;','"');
  while (newText.search('&quot;') != -1) 
    newText = newText.replace('&quot;','"');
  return newText;
}
function SubSingleQuotes(theText) {
  var newText = theText.replace('&rsquo;','\'');
  while (newText.search('&rsquo;') != -1) 
    newText = newText.replace('&rsquo;','\'');
  return newText;
}
function SubEncodedChars(theText) {
  var newText = theText.replace('&quot;','"');
  while (newText.search('&quot;') != -1) 
    newText = newText.replace('&quot;','"');
  while (newText.search('&lt;') != -1) 
    newText = newText.replace('&lt;','<');
  while (newText.search('&gt;') != -1) 
    newText = newText.replace('&gt;','>');	
  while (newText.search('zb') != -1) 
    newText = newText.replace('zb','&nbsp;');	
  while (newText.search('\n') != -1) 
    newText = newText.replace('\n','<br>');			
		
  return newText;
}
function AddRowToTable(toTableName, columnArray)
{
  var theTable, theTableBody;
  theTable = document.getElementById(toTableName);
  theTableBody = theTable.tBodies[0];
  var newCell;
  var atRow = theTable.rows.length;
  if (theTableBody == undefined)
     var newRow = theTable.insertRow(atRow);
  else	 
     var newRow = theTableBody.insertRow(atRow);
  var numCols = columnArray.length;
  for (var i = 0; i < numCols; i++) {
      newCell = newRow.insertCell(i);
	  newCell.width = columnArray[i].Width;
      newCell.innerHTML = '_';
	  newCell.align = columnArray[i].Align;
      <!-- newCell.style.backgroundColor = "salmon" -->
  }
}
function GetJsonValue(jsonText, sColumnName)
{
  var j = 0;
  var k = 0;
  var theValue = '';
  j = jsonText.indexOf(sColumnName,j);
  if (j > 0) {
	 k = jsonText.indexOf(':"', j);
	 if (k > 0) {
	    theValue = SubDblQuotes(jsonText.substring(k+2,jsonText.indexOf('"',k+2)));
	 }
	 j = k;
  } 
  return theValue; 
}
function BindRowToTable(toTableName, toRow, idValue, columnArray, bindValues)
{
  var theTable, theTableBody;
  theTable = document.getElementById(toTableName);
  theTableBody = theTable.tBodies[0];
  var theTableRow = theTable.rows[toRow];
  var numCols = columnArray.length;
  var sResponseValue = '';
  var sColumnName = '';
  for (var i = 0; i < numCols; i++) {
     sColumnName = columnArray[i].Name;
	 sResponseValue = GetJsonValue(bindValues, sColumnName);
	  <!-- alert(i+'. '+sColumnName+'='+sResponseValue);   --> 
     theTableRow.cells[i].innerHTML = sResponseValue;
  }  
}
function GetSaveURL(columnArray, idValue) 
{
  var numCols = columnArray.length; 
  var sURL = '';
  for (var i = 0; i < numCols; i++) {
     if (columnArray[i].Editable == 'true') { 
        var sColumnName = columnArray[i].Name;
	    var sInputName = 'gf' + sColumnName + idValue;
	    sURL = sURL + '&' + sColumnName + '=' + document.getElementById(sInputName).value;
	 }
  }	 
  return sURL;
}
function InsertTableRow(toTableName, numCols, atRow, widthsString, alignString)
{
  var alignArray = alignString.split(',');
  var widthsArray = widthsString.split(',');
  var theTable, theTableBody;
  theTable = document.getElementById(toTableName);
  theTableBody = theTable.tBodies[0];
  var newCell;
  if (theTableBody == undefined)
     var newRow = theTable.insertRow(atRow);
  else	 
     var newRow = theTableBody.insertRow(atRow);
  for (var i = 0; i < numCols; i++) {
      newCell = newRow.insertCell(i);
	  newCell.width = widthsArray[i];
      newCell.innerHTML = '_';
	  newCell.align = alignArray[i];
      <!-- newCell.style.backgroundColor = "salmon" -->
  }
}
function DeleteTableRow(toTableName, delRow)
{
  var theTable, theTableBody;
  theTable = document.getElementById(toTableName);
  theTableBody = theTable.tBodies[0];
  theTable.deleteRow(delRow);
}
function RowIndexOnTable(toTableName, idVal)
{
  var iIndex = -1;
  var theTable;
  theTable = document.getElementById(toTableName); 
   <!-- alert(idVal + '  and rows=' + theTable.rows.length + ' and id of row0 = ' + theTable.rows[0].id);  -->
  for (var i = 0; i < theTable.rows.length; i++) {
    if (theTable.rows[i].id == idVal) {
	   iIndex = i;
	   break;
	}
  }
  return iIndex;
}
function ClearElementInnerHtml(idName) {
  var element = document.getElementById(idName);
  while (element.firstChild) {
    oldNode = element.removeChild(element.firstChild);
  }
}

var preEl;
var orgBColor;
var orgTColor;
function ChangeTextColor(a_obj,a_color) { 
   for (i=0;i<a_obj.cells.length;i++)
      a_obj.cells(i).style.color=a_color;
}
function HighLightTR(el, backColor,textColor) {
  if (typeof(preEl)!='undefined') {
     preEl.bgColor=orgBColor;
     try{ChangeTextColor(preEl,orgTColor);}catch(e){;}
  }
  orgBColor = el.bgColor;
  orgTColor = el.style.color;
  el.bgColor=backColor;

  try{ChangeTextColor(el,textColor);}catch(e){;}
  preEl = el;
}

function CreateBookmarkLink(title, url) {
  if (window.sidebar)  // Mozilla Firefox Bookmark
	 window.sidebar.addPanel(title, url,"");
  else if (window.external )  // IE Favorite
	window.external.AddFavorite( url, title); 
  else if (window.opera && window.print) { // Opera Hotlist
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
  }	
}
function getOffset( el ) {
    var _x = 0;
    var _y = 0;
    while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
        _x += el.offsetLeft - el.scrollLeft;
        _y += el.offsetTop - el.scrollTop;
        el = el.offsetParent;
    }
    return { top: _y, left: _x };
}
function getFormValues(theForm) {
  var str = '';
  var elems = theForm.elements;
  for(var i = 0; i < elems.length; i++) {
     if (elems[i].type != 'button') {
        if (i == 0)
          str += elems[i].name+'='+elems[i].value;
        else
          str += '&'+elems[i].name+'='+elems[i].value;
     }
  }
  return str;
}


