// Function to load javascript files into the head section of a document
// Seems to load files slower than using <script src=""> in the document

// Will contain a comma separated list of loaded files
var filesLoaded = "";

function addLoadedFile(fileName) {
    filesLoaded += "[" + fileName + "]";
}

function loadJsFile(filename) {
  if (filesLoaded.indexOf("["+filename+"]") == -1) {
    var jsFile = document.createElement('script');
    jsFile.setAttribute("type","text/javascript");
    jsFile.setAttribute("src", filename);

    document.getElementsByTagName("head")[0].appendChild(jsFile);
    filesLoaded += "[" + filename + "]";
  }
}

function checkForForms() {
  // If there is a form on the page then load needed javascript
  if (document.forms.length > 0) {
    loadJsFile("/js/ValueFunctions.js");
    loadJsFile("/js/ajaxRequest.js");
    loadJsFile("/js/htmlFormHelper.js");
  }
} 


