﻿var loadComplete = false;

function loadjscssfile(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)
}

var filesadded = "" //list of files already added

function checkloadjscssfile(filename, filetype) {
  if (filesadded.indexOf("[" + filename + "]") == -1) {
    loadjscssfile(filename, filetype)
    filesadded += "[" + filename + "]" //List of files added in the form "[filename1],[filename2],etc"
  }
};

checkloadjscssfile(PageUrlPath + "/Javascript/pci.js", "js");
checkloadjscssfile(PageUrlPath + "/Javascript/Directory.js", "js");
checkloadjscssfile(PageUrlPath + "/Javascript/Event.js", "js");
checkloadjscssfile(PageUrlPath + "/Javascript/overlib.js", "js");

if (PageRequiresJQueryJavascript == 'True') {
    checkloadjscssfile("https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js", "js");
    checkloadjscssfile(PageUrlPath + "/javascript/jquery-1.3.2/PCI/PCI.jQuery.js", "js");
    checkloadjscssfile(PageUrlPath + "/javascript/jquery-1.3.2/jquery.blockUI.js", "js");
      checkloadjscssfile(PageUrlPath + "/javascript/jquery-1.3.2/alphanumeric/jquery.alphanumeric.pack.js", "js");
      checkloadjscssfile(PageUrlPath + "/modules/common/javascript/COMNDialog.js", "js");
      checkloadjscssfile(PageUrlPath + "/modules/common/javascript/COMNJQuery_1_3_2_Plugin_Stars.js", "js");
      checkloadjscssfile(PageUrlPath + "/modules/common/css/COMNJQuery_1_3_2_Plugin_Stars.css", "css");
      checkloadjscssfile(PageUrlPath + "/javascript/jquery-1.3.2/tablesorter/jquery.tablesorter.js", "js");
      checkloadjscssfile(PageUrlPath + "/javascript/jquery-1.3.2/tablesorter/chili-1.8b.pack.js", "js");
      checkloadjscssfile(PageUrlPath + "/javascript/jquery-1.3.2/tablesorter/addons/pager/jquery.tablesorter.pager.js", "js");
      checkloadjscssfile(PageUrlPath + "/javascript/jquery-1.3.2/tablesorter/jquery.tablesorter.js", "js");
      checkloadjscssfile(PageUrlPath + "/javascript/jquery-1.3.2/js/themeswitcher.js", "js");

      j1_3_2.preloadImages = function() {
        for (var i = 0; i < arguments.length; i++) {
          jQuery("<img>").attr("src", PageUrlPath + "/" + arguments[i]);
        }
      }
      j1_3_2.preloadImages("schools/common/images/ajax-loader.gif");

      j1_3_2(document).ready(function() {
      j1_3_2("body").append('<div id="AjaxLoaderImage" class="AjaxLoader" style="width:100%;height:0px;overflow:hidden;text-align:center;visibility:hidden;"><img src="/schools/common/images/ajax-loader.gif" border="0" /></div>');
      });
};

function addLoadEvent(func)  { 
	var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
	  window.onload = func; 
	} else { 
	  window.onload = function() { 
	    if (oldonload) { 
	      oldonload(); 
	    } 
	    func();
	  } 
  }
};

addLoadEvent(function() {
  loadComplete = true; 
});