window.xbUI = true;  // mark that this file has been loaded into the document

var ie = (navigator.userAgent.indexOf('MSIE') > -1 && document.all);

function getElementById(id,doc) {
  if(doc!=null && typeof(doc)=='object' && doc.getElementById) { } else { doc = document; }
  
  var returnVar = null;
  
  if(returnVar==null) { returnVar = doc.getElementById(id); }
  if(returnVar==null) { returnVar = doc.getElementsByName(id); if(returnVar.length > 0) { returnVar = returnVar[0]; } else { returnVar = null; } }
 
  return returnVar;
}

function setVisibility(id,visible,bDoDisplayAttribute) {
  visible = (visible==true);
  bDoDisplayAttribute = !(bDoDisplayAttribute==false);
  var el = document.getElementsByName(id); if(el.length>0) { el = el[0]; } else { el = null; }
  if(el==null && document.getElementById) { el = document.getElementById(id); }
  if(el!=null) { try {
	if(el.style) { if(bDoDisplayAttribute) { el.style.display = visible ? 'inline' : 'none'; }; el.style.visibility = visible ? 'visible' : 'hidden'; }
	else { if(document.layers) { if(bDoDisplayAttribute) { el.display = visible ? 'inline' : 'none'; }; el.visibility = visible ? 'visible' : 'hidden'; } }
  } catch(ex) { alert('Error: ' + ex); } }
}
function getVisibility(id) {
  var returnVar = true;
  var el = document.getElementsByName(id); if(el.length>0) { el = el[0]; } else { el = null; }
  if(el!=null) { try {
	if(el.style) { returnVar = (el.style.visibility!='hidden' && el.style.display!='none'); }
	else { if(document.layers) { returnVar = (el.visibility!='hidden'); } }
  } catch(ex) { alert('Error: ' + ex); } }
  return returnVar;
}


function getViewportSize(win) {
  if((typeof(win)+'').toLowerCase()!='object') { win = self; }

  var iWidth = 0, iHeight = 0;
  if( typeof( win.innerWidth ) == 'number' ) {
    //Non-IE
    iWidth = win.innerWidth;
    iHeight = win.innerHeight;
  } else if( win.document.documentElement && ( win.document.documentElement.clientWidth || win.document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    iWidth = win.document.documentElement.clientWidth;
    iHeight = win.document.documentElement.clientHeight;
  } else if( win.document.body && ( win.document.body.clientWidth || win.document.body.clientHeight ) ) {
    //IE 4 compatible
    iWidth = win.document.body.clientWidth;
    iHeight = win.document.body.clientHeight;
  }
  var returnVar = new Object();
  returnVar.width = iWidth;
  returnVar.height = iHeight;
  
  return returnVar;
}

function getElementSize(el) {
  var returnVar = new Object();
  returnVar.width = NaN;
  returnVar.height = NaN;

  if(el != null && (el.document || el.documentElement) && el.parent) {
    if(el.document && el.document.documentElement && el.document.documentElement.clientWidth && el.document.documentElement.clientHeight) {
	  returnVar.width = el.document.documentElement.clientWidth;
	  returnVar.height = el.document.documentElement.clientHeight;
	  return returnVar;
	} else {
      if(el.document && el.document.body && el.document.body.scrollWidth && el.document.body.scrollHeight) {
	    returnVar.width = win.document.body.scrollWidth;
	    returnVar.height = win.document.body.scrollHeight;
	    return returnVar;
  } } }

  if(el.innerWidth && el.innerHeight) {
    returnVar.width = el.innerWidth;
	returnVar.height = el.innerHeight;
	return returnVar;
  }
  if(el.clientWidth && el.clientHeight) {
    returnVar.width = el.clientWidth;
	returnVar.height = el.clientHeight;
	return returnVar;
  }
  if(el.width && el.height) {
    returnVar.width = el.width;
	returnVar.height = el.height;
	return returnVar;
  }
  
  return returnVar;
}

function setElementSize(nameOrObject,width,height) {
  var el = null;
  if(typeof(nameOrObject)=='string') {
	el = document.getElementsByName(nameOrObject);
    if(el.length > 0) { el = el[0]; } else { el = null; }
    if(el==null) { el = document.getElementById(nameOrObject); }
  }
  if(typeof(nameOrObject)=='object') { el = nameOrObject; }
  
  if(el!=null) {
    if(width!=null && isFinite(width*1)) {
	  if(el.style) { el.style.width = width; }
	  if(el.width) { el.width = width; }
	}
    if(height!=null && isFinite(height*1)) {
	  if(el.style) { el.style.height = height; }
	  if(el.height) { el.height = height; }
	}
  }// else { alert("Can't find element: '" + name); }
}

function getFrame(sFrameName,doc) {
  if(doc != null && typeof(doc)=='object' && doc.getElementById) { } else { doc = document; }
  if(sFrameName!=null && (sFrameName+'').length>0) {
    var ifs = doc.getElementsByName('ifBrowser');
    var frm = null;
    if(ifs.length > 0) { frm = ifs[0]; }
    if(doc.all && doc.frames) { frm = doc.frames('ifBrowser'); }
    return frm;
  } else { return null; }
}
function getFrameDocument(frm) {
  if(frm!=null) {
    return (frm.contentDocument ? frm.contentDocument : frm.document);
  } else { return null; }
}
function getDocumentUrl(doc) { return (doc!=null) ? doc.location.href : null; }


function getElementInnerHtml(el) {
  var returnVar = null;
  if(typeof(el)=="string") { el = getElementById(el); }

  if(typeof(el.innerHTML)=='string') { returnVar = el.innerHTML; }
  return returnVar;
}
function getElementInnerText(el) {
  var returnVar = null;
  if(typeof(el)=="string") { el = getElementById(el); }

  if(typeof(el.innerText)=='string') { returnVar = el.innerText; }
  else {
	if(typeof(el.textContent)=='string') { returnVar = el.textContent; }
	else {
      returnVar = convertHtmlToText(getElementInnerHtml(el));
  } }
  return returnVar;
}

function setElementInnerHtml(el,sHtml) {
  if(typeof(el)=="string") { el = getElementById(el); }

  if(typeof(el.innerHTML)=='string') { el.innerHTML = sHtml; } else { throw null; }
}
function setElementInnerText(el, sText) {
  if(typeof(el)=="string") { el = getElementById(el); }

  if(typeof(el.innerText)=='string') { el.innerText = sText; }
  else {
	if(typeof(el.textContent)=='string') { el.textContent = sText; }
	else {
	  if(typeof(el.innerHTML)=='string') { el.innerHTML = sText; }
	  else { throw null; }
} } }

function convertHtmlToText(sHtml) {
  var returnVar = sHtml;
  if(returnVar != null) {
	while(returnVar.indexOf("<a ") > -1) { returnVar = returnVar.replace("<a ","<anc "); }
	while(returnVar.indexOf("<A ") > -1) { returnVar = returnVar.replace("<A ","<anc "); }
	while(returnVar.indexOf("</a>") > -1) { returnVar = returnVar.replace("</a>","</anc>"); }
	while(returnVar.indexOf("</A>") > -1) { returnVar = returnVar.replace("</A>","</anc>"); }
  }
  return returnVar;
}