function inverse($f)
{
  for($i=0;$i<$f.elements.length;$i++)

  {
    if($f.elements[$i].type=="checkbox")

    {
      $f.elements[$i].checked=!$f.elements[$i].checked;
    }
  }
  }
function check($f)
{
  $checked=0;
  for($i=0;$i<$f.elements.length;$i++)

  {
    if($f.elements[$i].type=="checkbox"&&$f.elements[$i].checked)

    {
      $checked++;
    }
  }
if($checked===0)
{
  alert('Select at least one file or collection');
  return false;
}
return true;
}
$last=false;
function shiftclick($evt)
{
  $e=window.event?window.event.srcElement:$evt.target;
  if((window.event?window.event:$evt).shiftKey&&$last)

  {
    $f=$e.form;
    $s=false;
    for($i=0;$i<$f.elements.length;$i++)

    {
      if($f.elements[$i].type=="checkbox")

      {
        if($f.elements[$i].name==$e.name||$f.elements[$i].name==$last)

        {
          if($s)

          {
            $f.elements[$i].checked=$e.checked;
          }
          $s=!$s;
        }
        if($s)
        {
          $f.elements[$i].checked=$e.checked;
        }
      }
    }
  }
$last=$e.name;
}
function catchshift($f)
{
  for($i=0;$i<$f.elements.length;$i++)

  {
    if($f.elements[$i].type=="checkbox")

    {
      $f.elements[$i].onclick=shiftclick;
    }
  }
  }
$ext=[];
function regxstuff($tname)
{
  $l=0;
  $re=new RegExp('\\".+\\.(\\w+)\\"');
  $rar=new RegExp('r[0-9][0-9]');
  $par=new RegExp('p[0-9][0-9]');
  $ace=new RegExp('c[0-9][0-9]');
  $zip=new RegExp('z[0-9][0-9]');
  $t=document.getElementById($tname);
  if($t.rows.length>2&&$t.rows[1].cells[1].innerHTML==' '||$t.rows[1].cells[1].innerHTML==='')

  {
    $offset=-1;
  }
  else
  {
    $offset=0;
  }
  for($i=0;$i<$t.rows.length;$i++)
  {
    $ex=$re.exec($t.rows[$i].cells[2].innerHTML);
    if($ex)

    {
      $e=$ex[1].toLowerCase();
      if(!isNaN(parseInt($e,10)))

      {
        continue;
      }
      else if($e.match($rar))
      {
        $e='rar';
      }
      else if($e.match($par))
      {
        $e='par';
      }
      else if($e.match($ace))
      {
        $e='ace';
      }
      else if($e.match($zip))
      {
        $e='zip';
      }
      if(!$ext[$e])
      {
        $ext[$e]=[];
        $l++;
      }
      $ext[$e].push($i+$offset);
    }
  }
if($l>0&&$l<10)
{
  $ext.sort();
  $h="Inverse by type: ";
  for(var xyz in $ext)

  {
    $h+="<input type=\"button\" onClick=\"invtype('"+xyz+"')\" value=\""+xyz+"\" class=\"b\"> ";
  }
  $h+="<p>";
  document.getElementById('invbyt').innerHTML=$h;
}
}
function invtype($t)
{
  $f=document.forms.r;
  for($i=0;$i<$f.elements.length;$i++)

  {
    if($f.elements[$i].type=="checkbox")

    {
      $offset=$i-1;
      break;
    }
  }
for($i=0;$i<$ext[$t].length;$i++)
{
  $e=$f.elements[$ext[$t][$i]+$offset];
  $e.checked=!$e.checked;
}
return false;
}
function getCookie($name)
{
  $dc=document.cookie;
  $prefix=$name+"=";
  $begin=$dc.indexOf("; "+$prefix);
  if($begin==-1)

  {
    $begin=$dc.indexOf($prefix);
    if($begin!==0)

    {
      return null;
    }
  }
else
{
  $begin+=2;
}
$end=document.cookie.indexOf(";",$begin);
if($end==-1)
{
  $end=$dc.length;
}
return unescape($dc.substring($begin+$prefix.length,$end));
}
function setSelect($name,$value)
{
  $sobj=document.forms[0].elements[$name];
  for($i=0;$i<$sobj.options.length;$i++)

  {
    if($sobj.options[$i].value==$value||$sobj.options[$i].text==$value)

    {
      $sobj.selectedIndex=$i;
      break;
    }
  }
  }
function handleCookies()
{
  if(location.search.indexOf('max=')==-1&&getCookie('cmax'))

  {
    $age=getCookie('cadv_age');
    if($age==200||$age==240||$age==300)

    {
      $age=365;
    }
    setSelect('max',getCookie('cmax'));
    setSelect('adv_age',$age);
  }
}
function addEvent(obj,evType,fn){
  if(obj.addEventListener){
    obj.addEventListener(evType,fn,false);
    return true;
  }else if(obj.attachEvent){
    var r=obj.attachEvent("on"+evType,fn);
    return r;
  }else{
    return false;
  }
}
function removeEvent(obj,evType,fn,useCapture){
  if(obj.removeEventListener){
    obj.removeEventListener(evType,fn,useCapture);
    return true;
  }else if(obj.detachEvent){
    var r=obj.detachEvent("on"+evType,fn);
    return r;
  }else{
    alert("Handler could not be removed");
    return false;
  }
}
function getViewportHeight(){
  if(window.innerHeight!==undefined){
    return window.innerHeight;
  }
  if(document.compatMode=='CSS1Compat'){
    return document.documentElement.clientHeight;
  }
  if(document.body){
    return document.body.clientHeight;
  }
  return undefined;
}
function getViewportWidth(){
  if(window.innerWidth!==undefined){
    return window.innerWidth;
  }
  if(document.compatMode=='CSS1Compat'){
    return document.documentElement.clientWidth;
  }
  if(document.body){
    return document.body.clientWidth;
  }
}
function getScrollTop(){
  if(self.pageYOffset)

  {
    return self.pageYOffset;
  }
  else if(document.documentElement&&document.documentElement.scrollTop)
  {
    return document.documentElement.scrollTop;
  }
  else if(document.body)
  {
    return document.body.scrollTop;
  }
}
function getScrollLeft(){
  if(self.pageXOffset)

  {
    return self.pageXOffset;
  }
  else if(document.documentElement&&document.documentElement.scrollLeft)
  {
    return document.documentElement.scrollLeft;
  }
  else if(document.body)
  {
    return document.body.scrollLeft;
  }
}
var gPopupMask=null;
var gPopupContainer=null;
var gPopFrame=null;
var gReturnFunc;
var gPopupIsShown=false;
var gDefaultPage="/submodal/loading.html";
var gHideSelects=false;
var gReturnVal=null;
var gTabIndexes=[];
var gTabbableTags=["A","BUTTON","TEXTAREA","INPUT","IFRAME"];
function keyDownHandler(e){
  if(gPopupIsShown){
    hidePopWin(false);
  }
}
if(!document.all){
  document.onkeypress=keyDownHandler;
}
function setMaskSize(){
  var theBody=document.getElementsByTagName("BODY")[0];
  var fullHeight=getViewportHeight();
  var fullWidth=getViewportWidth();
  if(fullHeight>theBody.scrollHeight){
    popHeight=fullHeight;
  }else{
    popHeight=theBody.scrollHeight;
  }
  if(fullWidth>theBody.scrollWidth){
    popWidth=fullWidth;
  }else{
    popWidth=theBody.scrollWidth;
  }
  gPopupMask.style.height=popHeight+"px";
  gPopupMask.style.width=popWidth+"px";
}
var gi=0;
function centerPopWin(width,height){
  if(gPopupIsShown){
    if(!width||isNaN(width)){
      width=gPopupContainer.offsetWidth;
    }
    if(!height){
      height=gPopupContainer.offsetHeight;
    }
    var theBody=document.getElementsByTagName("BODY")[0];
    var scTop=parseInt(getScrollTop(),10);
    var scLeft=parseInt(theBody.scrollLeft,10);
    setMaskSize();
    var titleBarHeight=parseInt(document.getElementById("popupTitleBar").offsetHeight,10);
    var fullHeight=getViewportHeight();
    var fullWidth=getViewportWidth();
    gPopupContainer.style.top=(scTop+((fullHeight-(height+titleBarHeight))/2))+"px";
    gPopupContainer.style.left=(scLeft+((fullWidth-width)/2))+"px";
  }
}
function disableTabIndexes(){
  if(document.all){
    var i=0;
    for(var j=0;j<gTabbableTags.length;j++){
      var tagElements=document.getElementsByTagName(gTabbableTags[j]);
      for(var k=0;k<tagElements.length;k++){
        gTabIndexes[i]=tagElements[k].tabIndex;
        tagElements[k].tabIndex="-1";
        i++;
      }
      }
    }
}
function restoreTabIndexes(){
  if(document.all){
    var i=0;
    for(var j=0;j<gTabbableTags.length;j++){
      var tagElements=document.getElementsByTagName(gTabbableTags[j]);
      for(var k=0;k<tagElements.length;k++){
        tagElements[k].tabIndex=gTabIndexes[i];
        tagElements[k].tabEnabled=true;
        i++;
      }
      }
    }
}
function hideSelectBoxes(){
  var x=document.getElementsByTagName("SELECT");
  for(i=0;x&&i<x.length;i++){
    x[i].style.visibility="hidden";
  }
  }
function displaySelectBoxes(){
  var x=document.getElementsByTagName("SELECT");
  for(i=0;x&&i<x.length;i++){
    x[i].style.visibility="visible";
  }
  }
function showPopWin(url,width,height,returnFunc,showCloseBox){
  if(showCloseBox===null||showCloseBox===true){
    document.getElementById("popCloseBox").style.display="block";
  }else{
    document.getElementById("popCloseBox").style.display="none";
  }
  gPopupIsShown=true;
  disableTabIndexes();
  gPopupMask.style.display="block";
  gPopupContainer.style.display="block";
  centerPopWin(width,height);
  var titleBarHeight=parseInt(document.getElementById("popupTitleBar").offsetHeight,10);
  gPopupContainer.style.width=width+"px";
  gPopupContainer.style.height=(height+titleBarHeight)+"px";
  setMaskSize();
  gPopFrame.style.width=parseInt(document.getElementById("popupTitleBar").offsetWidth,10)+"px";
  gPopFrame.style.height=(height)+"px";
  gPopFrame.src=url;
  gReturnFunc=returnFunc;
  if(gHideSelects){
    hideSelectBoxes();
  }
  window.setTimeout("setPopTitle();",600);
}
function initPopUp(){
  theBody=document.getElementsByTagName('BODY')[0];
  popmask=document.createElement('div');
  popmask.id='popupMask';
  popcont=document.createElement('div');
  popcont.id='popupContainer';
  popcont.innerHTML=''+'<div id="popupInner">'+'<div id="popupTitleBar">'+'<div id="popupTitle"></div>'+'<div id="popupControls">'+'<img src="submodal/close.gif" onclick="hidePopWin(false);" id="popCloseBox" />'+'</div>'+'</div>'+'<iframe src="'+gDefaultPage+'" style="width:100%;height:100%;background-color:transparent;" scrolling="auto" frameborder="0" allowtransparency="true" id="popupFrame" name="popupFrame" width="100%" height="100%"></iframe>'+'</div>';
  theBody.appendChild(popmask);
  theBody.appendChild(popcont);
  gPopupMask=document.getElementById("popupMask");
  gPopupContainer=document.getElementById("popupContainer");
  gPopFrame=document.getElementById("popupFrame");
  var brsVersion=parseInt(window.navigator.appVersion.charAt(0),10);
  if(brsVersion<=6&&window.navigator.userAgent.indexOf("MSIE")>-1){
    gHideSelects=true;
  }
  var elms=document.getElementsByTagName('a');
  for(i=0;i<elms.length;i++){
    if(elms[i].className.indexOf("submodal")===0){
      elms[i].onclick=function(){
        var width=680;
        var height=getViewportHeight()-100;
        params=this.className.split('-');
        if(params.length==3){
          width=parseInt(params[1],10);
          height=parseInt(params[2],10);
        }
        showPopWin(this.href,width,height,null,true);
        return false;
      };

  }
  }
}
addEvent(window,"load",initPopUp);
addEvent(window,"resize",centerPopWin);
addEvent(window,"scroll",centerPopWin);
window.onscroll=centerPopWin;
function hidePopWin(callReturnFunc){
  gPopupIsShown=false;
  var theBody=document.getElementsByTagName("BODY")[0];
  theBody.style.overflow="";
  restoreTabIndexes();
  if(gPopupMask===null){
    return;
  }
  gPopupMask.style.display="none";
  gPopupContainer.style.display="none";
  if(callReturnFunc&&gReturnFunc!==null){
    gReturnVal=window.frames.popupFrame.returnVal;
    window.setTimeout('gReturnFunc(gReturnVal);',1);
  }
  gPopFrame.src=gDefaultPage;
  if(gHideSelects){
    displaySelectBoxes();
  }
}
function setPopTitle(){
  if(window.frames.popupFrame.document.title===null){
    window.setTimeout("setPopTitle();",10);
  }else{
    document.getElementById("popupTitle").innerHTML=window.frames.popupFrame.document.title;
  }
}
