﻿
// Application Form File Uploads Styling

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
    var allHTMLTags = document.getElementsByTagName("*");
    for (i = 0; i < allHTMLTags.length; i++) {
        if (allHTMLTags[i].className == "file") {
            allHTMLTags[i].style.opacity = "0";
            allHTMLTags[i].style.filter = "alpha(opacity: 0)";
        }
    }
    if (!W3CDOM) return;
    var fakeFileUpload = document.createElement('div');
    fakeFileUpload.className = 'fakefile';
    var inputField = document.createElement('input');
    inputField.className = 'fakefileinput';
    fakeFileUpload.appendChild(inputField);
    var image = document.createElement('img');
    image.src = '/media/images/form_upload.gif';
    fakeFileUpload.appendChild(image);
    var clear = document.createElement('input');
    clear.type = 'button';
    var x = document.getElementsByTagName('input');
    for (var i = 0; i < x.length; i++) {
        if (x[i].type != 'file') continue;
        if (x[i].parentNode.className != 'fileinputs') continue;
        x[i].className = 'file hidden';
        var clone = fakeFileUpload.cloneNode(true);
        x[i].parentNode.appendChild(clone);
        x[i].relatedElement = clone.getElementsByTagName('input')[0];
        x[i].onchange = x[i].onmouseout = function() {
            this.relatedElement.value = this.value;
        }
    }
}

function clearFileInputs() {
    var x = document.getElementsByTagName('input');
    for (var i = 0; i < x.length; i++) {
        if (x[i].className == 'file hidden') {
            x[i].value = '';
        }
        if (x[i].className == 'fakefileinput') {
            x[i].value = '';
            this.focus();
        }

    }
}

// News Page Hide & Show Functions

function NewsLoad() {
    hidenewsitem();
    if (window.location.hash != "") {
        var param = window.location.hash.substr(1);
        if (param < 10)
            param = "0" + param;
        ShowOrHideNews(param);
    }
}

function hidenewsitem() {
    var allHTMLTags = document.getElementsByTagName("*");
    for (i = 0; i < allHTMLTags.length; i++) {
        if (allHTMLTags[i].className == "news_main") {
            allHTMLTags[i].style.display = "none";
        }
    }
}

function ShowOrHideNews(id) {
    if (document.getElementById("main" + id)) {
        var currentDisplay = document.getElementById("main" + id).style.display;
        if (currentDisplay == "block") {
            document.getElementById("main" + id).style.display = "none";
            document.getElementById("intro" + id).style.display = "block";
            document.getElementById("link" + id).innerHTML = "Show article";
            document.getElementById("news" + id).scrollIntoView(true);
        } else {
            document.getElementById("main" + id).style.display = "block";
            document.getElementById("intro" + id).style.display = "none";
            document.getElementById("link" + id).innerHTML = "Hide article";
            document.getElementById("news" + id).scrollIntoView(true);

        }
    } else {
        return false;
    }
}

// Jobs Page Hide & Show Functions

function JobsLoad() {
    hidejobsitem();
    if (window.location.hash != "") {
        ShowOrHideNews(window.location.hash.substr(1));
    }
}

function hidejobsitem() {
    var allHTMLTags = document.getElementsByTagName("*");
    for (i = 0; i < allHTMLTags.length; i++) {
        if (allHTMLTags[i].className == "jobs_main") {
            allHTMLTags[i].style.display = "none";
        }
    }
}

function ShowOrHideJobs(id) {
    if (document.getElementById("main" + id)) {
        var currentDisplay = document.getElementById("main" + id).style.display;
        if (currentDisplay == "block") {
            document.getElementById("main" + id).style.display = "none";
            document.getElementById("intro" + id).style.display = "block";
            document.getElementById("link" + id).innerHTML = "Read Full Job Sepcification";
            document.getElementById("jobs" + id).scrollIntoView(true);
        } else {
            document.getElementById("main" + id).style.display = "block";
            document.getElementById("intro" + id).style.display = "none";
            document.getElementById("link" + id).innerHTML = "Hide Full Job Specification";
            document.getElementById("jobs" + id).scrollIntoView(true);

        }
    } else {
        return false;
    }
}