﻿function frameMe() {
    if (window.name != "main") {
        page = new String(self.document.location);
        var pos = page.lastIndexOf("/") + 1;
        var file = page.substr(pos);

        var s = "/Index.htm?" + file;
        top.location.replace(s);
    } else {
        parent.frames['header'].window.location.reload();
        parent.frames['GoogleAdSense'].window.location.reload();
        parent.frames['candidateDisplay'].window.location.reload();
    }    
    return;
}

function frameMeFromSubDir() {
    if (window.name != "main") {
        page = new String(self.document.location);
        var pos = page.lastIndexOf("/") + 1;
        var file = page.substr(pos);
        var directory = page.substr(0, pos-1);
        var subDirPos = directory.lastIndexOf("/") + 1;
        var dirWithoutHost = directory.substr(subDirPos);

        var s = "/Index.htm?" + dirWithoutHost + "/" + file;
        top.location.replace(s);
    }
    return;
}

function frameMenu() {
    if (window.name != "menu") {
        top.location.replace("Index.htm");
    }
    return;
}

function frameHeader() {
    if (window.name != "header") {
        top.location.replace("Index.htm");
    }
    return;
}

function frameRight() {
    if (window.name != "rightmenu") {
        top.location.replace("Index.htm");
    }
    return;
}

function setMainDoc() {
    var args = location.search.split('&');
    var page = args[0].substr(1);
    
    var s = "FirstPage.aspx";
    if (page) {
        s = page;
    }
    var objFrame = document.getElementById("main");
    objFrame.src = s;
    return;
}

function DatePicker(ctl, w, h) {
    var PopupWindow = null;
    settings = 'width=' + w + ',height=' + h + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';
    PopupWindow = window.open('DatePicker.aspx?Ctl=' + ctl, 'DatePicker', settings);
    PopupWindow.focus();
}

function ShowCriteriaInfo(txt, w, h) {
    var PopupWindow = null;
    settings = 'width=' + w + ',height=' + h + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';
    PopupWindow = window.open('ShowCriteriaInfo.aspx?Txt=' + txt, 'CriteriaInfo', settings);
    PopupWindow.focus();
}

function ShowCriteriaInfo(txt, id, w, h) {
    var PopupWindow = null;
    settings = 'width=' + w + ',height=' + h + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=yes,dependent=no';
    PopupWindow = window.open('ShowCriteriaInfo.aspx?Txt=' + txt + '&CriterionID=' + id, 'CriteriaInfo', settings);
    PopupWindow.focus();
}

function ShowCompetition(CompElectionDistrictList) {
    var PopupWindow = null;
    var edids = CompElectionDistrictList.options;
    for (var i = 0; i < edids.length; i++) {
        if (edids[i].selected) {
            settings = 'width=770,height=680,location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,dependent=no';
            PopupWindow = window.open('CompetitionExt.aspx?ElectionDistrictID=' + edids[i].value, 'Competition', settings);
            PopupWindow.focus();
        }
    }
}

function DisplayCandidateFrame() {
    var _showCandidateFrameLabel = document.getElementById('ShowCandidateFrameLabel');
    if (_showCandidateFrameLabel.innerHTML == 'true') {
        showElement('CandidateSearchResultFrame');
    } else {
        hideElement('CandidateSearchResultFrame');
    }
}

function hideElement(elementId) {
    var _docElement = document.getElementById(elementId);
    _docElement.style.display = 'none';
}

function showElement(elementId) {
    var _docElement = document.getElementById(elementId);
    _docElement.style.display = 'block';
}

function enableElement(elementId) {
    var _docElement = document.getElementById(elementId);
    alert('got element...' + _docElement.ID);
    _docElement.Enabled=true;
}


function hideParentElement(elementId) {
    var _docElement = parent.document.getElementById(elementId);
    _docElement.style.display = 'none';
}

function showParentElement(elementId) {
    var _docElement = parent.document.getElementById(elementId);
    _docElement.style.display = 'block';
}

function CustomizeResultPage() {
    var _parentShowCandidateFrame = parent.document.getElementById('ShowCandidateFrameLabel');
    if (_parentShowCandidateFrame.innerHTML == 'true') {
        var _searchResultHeader = document.getElementById('SearchResultHeaderLabel');
        _searchResultHeader.innerHTML = "<h3>Vet du vem du vill kryssa på valsedeln?</h3>";
        hideElement('NewSearchLink');
        hideElement('NavigationSeparator');
        hideElement('PartyTestLink');
        hideElement('PoweredByLabel');
    }    
}

function ToggleFilterOptions() {
    var _filterOptDiv = document.getElementById('filterOptions');
    var _searchButton = document.getElementById('SearchCandidateButton');
    var _electionDistrictList = document.getElementById('__ELECTION_DISTRICT_LIST__');
    var _filterOptTextDiv = document.getElementById('filterOptionsText');    
    var _filterOptText = document.getElementById('ToogleFilterOptions');
    if (_filterOptDiv.style.display == 'block') {
        _filterOptDiv.style.display = 'none';
        _filterOptTextDiv.style.display = 'block';
        if (_electionDistrictList.style.display == 'none') {
            _searchButton.style.display = 'none';
        }
        _filterOptText.innerHTML = "Visa filtrering >>";
    } else {
        _filterOptDiv.style.display = 'block';
        _filterOptTextDiv.style.display = 'none';
        _searchButton.style.display = 'block';
        _filterOptText.innerHTML = "Dölj filtrering <<<";
    }
}

function ToggleShowPartyResult() {
    var _partySearchDiv = document.getElementById('PartySearchResult');
    var _partySearchOptText = document.getElementById('TooglePartySearchResult');
    if (_partySearchDiv.style.display == 'block') {
        _partySearchDiv.style.display = 'none';
        _partySearchOptText.innerHTML = "Visa partiresultat >>";
    } else {
        _partySearchDiv.style.display = 'block';
        _partySearchOptText.innerHTML = "Dölj partiresultat <<<";
    }
}