﻿
//Displays or hides specified object
function toggle(object) {
    e = document.getElementById(object);
    if (e.style.display == 'none') {
        e.style.display = 'block';
    } else {
        e.style.display = 'none';
    }
}

// Returns the name of the page user is currently browsing
function getPageName() {
    var sPath = window.location.pathname;
    //var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    return sPage;
}

//Displays correct navigational sub items, dependign on the page the user is currently on.
function displayNav(page, area) {
    var homeSubItems = document.getElementById('home_sub_items');
    var applicationsSubItems = document.getElementById('applications_sub_items');
    var supportSubItems = document.getElementById('support_sub_items');
    var newsSubItems = document.getElementById('news_sub_items');
    var aboutSubItems = document.getElementById('about_sub_items');

    //Hides all navigational sub items.
    homeSubItems.style.display = 'none';
    applicationsSubItems.style.display = 'none';
    supportSubItems.style.display = 'none';
    newsSubItems.style.display = 'none';
    aboutSubItems.style.display = 'none';

    if (page == 'index.html' || page == 'overview.html' || page == 'howitworks.html' || page == 'costs.html' ) {
        homeSubItems.style.display = 'block';
    }
    else if (page == 'applications.html' || area == 'Applications' ) {
        applicationsSubItems.style.display = 'block';
    }
    else if (page == 'support.html' || area == 'Support' ) {
        supportSubItems.style.display = 'block';
    }
    else if (page == 'news.html') {
        newsSubItems.style.display = 'block';
    }
    else if (page == 'about.html' || area == 'About' ) {
        aboutSubItems.style.display = 'block';
    }
}

function addLanguageOption(name, uri, select) {
    var option = document.createElement('option');
    option.setAttribute('value', uri);
    if (typeof (option.innerText) != 'undefined') {
        option.innerText = name;
    }
    else {
        option.text = name;
    }
    if (document.URL.indexOf(uri,0) != -1) option.setAttribute('selected', 'selected');
    select.appendChild(option);
}

// creates a list of languages for user selection
function createLanguageList() {
    var div = document.getElementById('drop_down_box');
    var select = document.createElement('select');
    select.setAttribute('id', 'country');
    select.setAttribute('class', 'reduce_font_size');
    select.setAttribute('onchange', 'document.location.href=document.getElementById("country").value');
    div.appendChild(select);
    addLanguageOption('English', 'http://www.general-alert.com', select);
    addLanguageOption('Français', 'http://www.general-alert.fr', select);
    addLanguageOption('Deutsch', 'http://www.general-alert.de', select);
    // other options here
}

