//cool html previewer

var qpv = '[Preview Schematic Data]';
var cpv = '[Close Preview Window]';
var psize = '650';

function pv(url, id, pwidth) {
  if(document.all || document.getElementById) {
    document.write('<a title="Click this link to schematic" class="newwindow" id="link'+id+'" href="'+url+'" onClick="pview(this, '+pwidth+');return false">'+qpv+'</a>');
  }
}

function pview(link, pwidth) {
// Testing for IE 4, since IE4 does not recognize document.getElementById
  var ie4 = (document.all && !document.getElementById) ? true : false;
// If it is IE 4, we set document.all. If we are not IE 4 then we use the standard getElementById
  if (ie4 == 1) {
    var iframe = document.all['if'+link.id];
  }
  else {
    var iframe = document.getElementById('if'+link.id);
  }
  if(link.innerHTML == qpv) {
    if(iframe) {

      // Reuses the IFrame if open already

      iframe.src = link.href;
      iframe.style.height = psize;
      iframe.style.visibility = 'visible';

    } else {

      // Build the Frame and Load the URL

      myBR = document.createElement('br');
      myBR.setAttribute('id','br'+link.id);

      link.parentNode.appendChild(myBR);

      myIframe = document.createElement('iframe');
      myIframe.setAttribute('id','if'+link.id);
      myIframe.setAttribute('width',pwidth);
      myIframe.setAttribute('height',psize);
      myIframe.setAttribute('class','pframe');
      myIframe.setAttribute('src',link.href);

      link.parentNode.appendChild(myIframe);
    }

    link.innerHTML = cpv;
  } else if(iframe) {
    if (ie4 == 1) {
      myBR = document.all['br'+link.id];
    } else {
      myBR = document.getElementById('br'+link.id);
    }
    link.innerHTML = qpv;
    link.parentNode.removeChild(iframe);
    link.parentNode.removeChild(myBR);
  }
}

function resizeRSBox() {
 if (document.getElementById('toolboxTop').style.height != "auto") {
  document.getElementById('toolboxTop').style.height = "auto";
  document.getElementById('tbButtonClose').style.display = "block";
  document.getElementById('tbButtonOpen').style.display = "none";
 } else {
  document.getElementById('toolboxTop').style.height = 80;
  document.getElementById('tbButtonOpen').style.display = "block";
  document.getElementById('tbButtonClose').style.display = "none";
 }
}

function ga(o,e){
 if (document.getElementById){
     a=o.id.substring(1);
     p = "";
     g = e.target;
     if (g) 
     {
         t = g.id;
         f = g.parentNode;
         if (f) {
             p = f.id;
             h = f.parentNode;
                 if (h) r = h.id;
         }
      } else{
          h = e.srcElement;
          f = h.parentNode;
              if (f) p = f.id;
               t = h.id;
      }
      if (t==a || p==a)return true;
      location.href=document.getElementById(a).href
 }
}


//<!-- character/URL encoding function -->
function getEncodedPv (val) {
 if (val == "$") { return("%24"); }
 if (val == "&") { return("%26"); }
 if (val == "+") { return("%2b"); }
 if (val == ",") { return("%2c"); }
 if (val == "/") { return("%2f"); }
 if (val == ":") { return("%3a"); }
 if (val == ";") { return("%3b"); }
 if (val == "=") { return("%3d"); }
 if (val == "?") { return("%3f"); }
 if (val == "@") { return("%40"); }
 if (val == ".") { return("%2e"); }
 if (val == "'") { return("%27"); }
 if (val == "%") { return("%25"); }

return val;
}

//<!-- Widget tracking function (Web version) -->
function trackURLPv(loc, elemid, linknum, brand, view, channel, encquery, fromPage) {
 var bstr="";
 var i=0;
 for (i=0; i<loc.length; i++) {
  bstr = bstr + getEncodedPv(loc.charAt(i));
 }
 return bstr;
}


