﻿function CheckItem(ctrlimage, ctrlitem){ 
  if (ctrlitem.checked) {
    ctrlimage.src = "images/no_check.gif";
    ctrlitem.checked = false;
  }else {
    ctrlimage.src = "images/check_on.gif";
    ctrlitem.checked = true;
  }  
  return true; 
}

function ShowPdf(pdf) {
	sRef = 'pdfWindow';
  wnd = window.open(pdf, 'pdfWindow', 'menubar=no,toolbars=yes,resizable=yes,status=no,location=no,width=550,height=360,');
  if (wnd) wnd.focus();
  return true;
}

function FilterYear() {
  var frm = document.aspnetForm;
  frm.submit();
} 

function FilterSede() {
  var frm = document.aspnetForm;
  frm.submit();
} 

function removejscssfile(filename, filetype){
  var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from
  var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
  var allsuspects=document.getElementsByTagName(targetelement)
  for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
    if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
    allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
  }
}

function createjscssfile(filename, filetype){
  if (filetype=="js"){ //if filename is a external JavaScript file
    var fileref=document.createElement('script')
    fileref.setAttribute("type","text/javascript")
    fileref.setAttribute("src", filename)
  }
  else if (filetype=="css"){ //if filename is an external CSS file
    var fileref=document.createElement("link")
    fileref.setAttribute("rel", "stylesheet")
    fileref.setAttribute("type", "text/css")
    fileref.setAttribute("href", filename)
  }
  if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

function replacejscssfile(oldfilename, newfilename, filetype){
  var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist using
  var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
  var allsuspects=document.getElementsByTagName(targetelement)
  for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
    if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(oldfilename)!=-1){
      var newelement=createjscssfile(newfilename, filetype)
      allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])         
    }
  }
}
