﻿function psFindObj(n, doc) 
{ 
  var p, i, x;  
  if (!doc) 
    doc = document; 
    
  if ((p = n.indexOf("?")) > 0 && parent.frames.length) 
  {
    doc = parent.frames[n.substring(p + 1)].document; 
    n=n.substring(0, p);
  }
  
  if (!(x = doc[n]) && doc.all) 
    x = doc.all[n]; 
    
  for (i = 0; !x && i < doc.forms.length; i++) 
    x = doc.forms[i][n];
    
  for (i = 0; !x && doc.layers && i < doc.layers.length; i++) 
    x = psFindObj(n, doc.layers[i].document);
    
  if (!x && doc.getElementById) 
    x = doc.getElementById(n); 
    
  return x;
}

function psGetElementById(element)
{
  return document.getElementById(element)
}

function psOpenWindowModal(url, arguments, features)
{
  return window.showModalDialog(url, arguments, features);
}

function psPreloadImages() 
{ 
  var doc = document; 
  if (doc.images)
  { 
    if (!doc.psImages) 
      doc.psImages = new Array();
      
    var i,j = doc.psImages.length, arguments = psPreloadImages.arguments;     
    for(i = 0; i < arguments.length; i++)
    {
      if (arguments[i].indexOf("#") != 0)
      { 
        doc.psImages[j] = new Image; 
        doc.psImages[j++].src = arguments[i];
      }
    }
  }
}

function psRestoreSwapImage() 
{
  var i, x, arguments = document.psSource; 
  for (i = 0; arguments && i < arguments.length && (x = arguments[i]) && x.oSrc; i++) 
    x.src = x.oSrc;
}

function psShowDialog(url, height, width)
{
  var features = "dialogwidth:" + width + "px;dialogheight:" + height + "px;" +
                 "center:yes;scroll:no;help:no;resizable:no;status:no";
  return psOpenWindowModal(url, "", features);
}

function psSwapImage() 
{ 
  var i, j = 0, x, arguments = psSwapImage.arguments; 
  document.psSource = new Array; 
  
  for (i = 0; i < (arguments.length - 2); i += 3)
  {
    if ((x = psFindObj(arguments[i])) != null)
    {
      document.psSource[j++] = x; 
      if (!x.oSrc) 
        x.oSrc = x.src; 
        
      x.src = arguments[i + 2];
    }
  }
}
