function popupNeighbour(page)
{
    var optionWin = window.open(page,'option','titlebar=yes,toolbar=no,menubar=no,status=no,top=100,left=100,width=460,height=460;')
    optionWin.focus();
    return true;
}


function searchNeighbour(contextPath, term)
{
    var path = contextPath + "/portlets/neighbourBrowse/searchNeighbour.jsp?term=" + term;
    var options = "titlebar=yes,scrollbars=yes,toolbar=no,menubar=no,status=no,top=100,left=100,width=480,height=540;";
    var popupWin = window.open(path, 'searchNeighbour', options);
    popupWin.focus();    
}

function selectNeighbour(contextPath, my)
{
    var term = my.options[my.selectedIndex].value;
    searchNeighbour(contextPath, term);
    return false;
}

function viewLargerMap(contextPath)
{
    var path = contextPath + "/portlets/neighbourBoundaries/viewLargerMap.jsp";
    var options = "resizable=yes,scrollbars=yes,top=50,left=100,width=750,height=600";
    var popupWin = window.open(path, 'largerMap', options);
    popupWin.focus();    
}

function emptyDefault(curValue)
{
    if (curValue == "<Type in Keywords>")
        return "";
    else
        return curValue;
}

function gotoNewGateway(serverURL, target)
{
    var url = serverURL + "/" + target + "/begin.do";
    window.open(url, "_blank");
    return false;
}

function popupSaveQuery(contextPath)
{
    var path = contextPath + "/portlets/result/popupSaveQuery.jsp";
    var options = 'top=100,left=100,width=325,height=130;';
    var popupWin = window.open(path, 'partners', options);
    popupWin.focus();
}

function popupPartners(contextPath, no)
{
    var path = contextPath + "/portlets/partners/popup.jsp#" + no;
    var options = 'scrollbars=yes,top=100,left=100,width=560,height=600;';
    var popupWin = window.open(path, 'htyPartners', options);
    popupWin.focus();
}

function viewLarger(contextPath)
{
    var path = contextPath + "/portlets/resultDetail/popup/viewLarger.jsp";
    var options = "resizable=yes,scrollbars=yes,top=10,left=10";
    var popupWin = window.open(path, 'htyPopupViewLarger', options);
    popupWin.focus();
}

function viewTrans(contextPath)
{
    var path = contextPath + "/portlets/resultDetail/popup/viewTrans.jsp";
    var options = "resizable=yes,scrollbars=yes,top=10,left=10,width=720,height=400";
    var popupWin = window.open(path, 'htyPopupViewTrans', options);
    popupWin.focus();
}

function popupTerm(contextPath)
{
    var path = contextPath + "/portlets/resultDetail/popup/term.jsp";
    var options = "resizable=yes,scrollbars=yes,top=10,left=10,width=530,height=540";
    var popupWin = window.open(path, 'htyPopupTerm', options);
    popupWin.focus();
}

// send email
function emailOption(contextPath)
{
    var path = contextPath + "/portlets/resultDetail/popup/emailOption.jsp";
    var options = "resizable=yes,scrollbars=yes,top=10,left=10,width=560,height=250";
    var popupWin = window.open(path, 'htyEmailOption', options);
    popupWin.focus();
    }

function emailPreview(contextPath)
{
    var path = contextPath + "/portlets/resultDetail/popup/emailPreview.jsp";
    path += "?from=" + document.paramForm.from.value;
    path += "&to=" + document.paramForm.to.value;
    path += "&comments=" + document.paramForm.comments.value;
    
    var options = "resizable=yes,scrollbars=yes,top=10,left=10,width=620,height=650";
    var popupWin = window.open(path, 'htyEmailPreview', options);
    popupWin.focus();
}

function emailSending(from, to, comments)
{
    document.getElementById(getNetuiTagName("idYourEmail")).value = from;
    document.getElementById(getNetuiTagName("idToEmail")).value = to;
    document.getElementById(getNetuiTagName("idComments")).value = comments;
    document.getElementById(getNetuiTagName("idSendEmail")).submit();
}
// send email

function printOption(contextPath)
{
    var path = contextPath + "/portlets/resultDetail/popup/printOption.jsp";
    var options = "resizable=yes,scrollbars=yes,top=10,left=10,width=345,height=200";
    var popupWin = window.open(path, 'htyPrintOption', options);
    popupWin.focus();
}

function printPreview(contextPath)
{
    var path = contextPath + "/portlets/resultDetail/popup/printPreview.jsp";
    path += "?image=" + document.paramForm.image.checked;
    path += "&descr=" + document.paramForm.descr.checked;
    path += "&trans=" + document.paramForm.trans.checked;
    
    var options = "resizable=yes,scrollbars=yes,top=10,left=10,width=620,height=800";
    var popupWin = window.open(path, 'htyPrintPreview', options);
    popupWin.focus();
}

function advancedUncheckId(id)
{
    for (var i=0; i<document.forms.length; i++)
    {
        var form = document.forms[i];
        if (form.id == getNetuiTagName("idAdvancedSearch"))
        {
            for (var j=0; j<form.elements.length; j++)
            {
                var element = form.elements[j];
                if (element.name == getNetuiTagName(id))
                {
                    element.checked = false;
                }
            }
        }  
    }
}

function advancedUncheck(me, id)
{
    if (me.checked)
    {
        advancedUncheckId(id);
    }
}

function addCity()
{
    var x = document.getElementById("citySectionSelect");
    var y = document.getElementById("cityYearSelect");
    for (var i=0; i<document.forms.length; i++)
    {
        var form = document.forms[i];
        if (form.id == getNetuiTagName("idAddCity"))
        {
            form.elements[0].value = x.options[x.selectedIndex].text;
            form.elements[1].value = y.options[y.selectedIndex].text;
            form.submit();
        }
    }
}

function removeCity(index)
{
    for (var i=0; i<document.forms.length; i++)
    {
        var form = document.forms[i];
        if (form.id == getNetuiTagName("idRemoveCity"))
        {
            form.elements[0].value = index;
            form.submit();
        }
    }
}

function removeAllCity(me)
{
    if (me.checked)
    {
        removeCity(-1);
    }
}

// neighbourList
function addNeighbour1()
{
    var t = document.getElementById('neighbourSelect');
    addNeighbour2(t.options[t.selectedIndex].text);
}

function addNeighbour2(option)
{
    var img = '<img src="/webHTY/framework/skins/dch/tpl/remove.gif" width="52" height="15" border="0" style="margin:1px !important;" onclick="deleteNeighbourRow(this.parentNode.parentNode.rowIndex)">';    
    var t = document.getElementById('idNeighbourTable');
    var row = t.insertRow(t.rows.length);
    var c1 = row.insertCell(0);
    var c2 = row.insertCell(1);
    c1.innerHTML = option;
    c2.innerHTML = img;
    updateNeighbourList();    
    advancedUncheckId('idAnyToronto'); //
}

function deleteNeighbourRow(i)
{
    document.getElementById('idNeighbourTable').deleteRow(i);
    updateNeighbourList();
}

function deleteAllNeighbourRow(me)
{
    if (me.checked)
    {
        var t = document.getElementById('idNeighbourTable');
        var l = t.rows.length;
        for (var i=0; i<l; i++)
        {
            document.getElementById('idNeighbourTable').deleteRow(0);
        } 
        updateNeighbourList();
    }
}

function updateNeighbourList()
{
    var t = document.getElementById('idNeighbourTable');
    var p = document.getElementById(getNetuiTagName("idNeighbourList"));
    p.value = "";
    
    for (var i=0; i<t.rows.length; i++)
    {
        var c = t.rows[i].cells[0];
        p.value += c.innerText + ",";
    }
}
// neighbourList

function addNeighbourhood()
{
    var x = document.getElementById("neighbourhoodSelect");
    for (var i=0; i<document.forms.length; i++)
    {
        var form = document.forms[i];
        if (form.id == getNetuiTagName("idAddNeighbourhood"))
        {
            form.elements[0].value = x.options[x.selectedIndex].text;
            form.submit();
        }
    }
}

function removeNeighbourhood(index)
{
    for (var i=0; i<document.forms.length; i++)
    {
        var form = document.forms[i];
        if (form.id == getNetuiTagName("idRemoveNeighbourhood"))
        {
            form.elements[0].value = index;
            form.submit();
        }
    }
}

function addRefine()
{
    var x = document.getElementById("refineFieldSelect");
    var y = document.getElementById("refineValueSelect");
    for (var i=0; i<document.forms.length; i++)
    {
        var form = document.forms[i];
        if (form.id == getNetuiTagName("idAddRefine"))
        {
            form.elements[0].value = x.options[x.selectedIndex].value;
            form.elements[1].value = y.value;
            form.submit();
        }
    }
}

function removeRefine(index)
{
    for (var i=0; i<document.forms.length; i++)
    {
        var form = document.forms[i];
        if (form.id == getNetuiTagName("idRemoveRefine"))
        {
            form.elements[0].value = index;
            form.submit();
        }
    }
}

function copyrightToCTR(URL, work, rep)
{
    var url = URL + "/webCTR/copyright.do?work=" + work + "&rep=" + rep;
    window.open(url, "_blank");
    return false;
}

function closeOptionsSearch()
{
    if (OptionsSearchResultsForm.radiobutton[0].checked)
    {
        closeOptionsSearchForm.action += "#loc_searchresults";
        closeOptionsSearchForm.param1.value = "1";
        closeOptionsSearchForm.submit();
    }
    else if (OptionsSearchResultsForm.radiobutton[1].checked)
    {
        closeOptionsSearchForm.action += "#loc_searchresults";
        closeOptionsSearchForm.param1.value = "2";
        closeOptionsSearchForm.submit();
    }
    else
    {
        closeOptionsSearchForm.action += "#loc_Search";
        closeOptionsSearchForm.submit();
    }
    return false;
}

function closeOptionsBrowse()
{
    if (OptionsBrowseResultsForm.radiobutton[0].checked)
    {
        closeOptionsBrowseForm.action += "#loc_thiscategory";
        closeOptionsBrowseForm.param1.value = "1";
        closeOptionsBrowseForm.submit();
    }
    else if (OptionsBrowseResultsForm.radiobutton[1].checked)
    {
        closeOptionsBrowseForm.action += "#loc_thiscategory";
        closeOptionsBrowseForm.param1.value = "2";
        closeOptionsBrowseForm.submit();
    }
    else if (OptionsBrowseResultsForm.radiobutton[2].checked)
    {
        closeOptionsBrowseForm.action += "#loc_browsedc";
        closeOptionsBrowseForm.param1.value = "3";
        closeOptionsBrowseForm.submit();
    }
    else
    {
        closeOptionsBrowseForm.action += "#loc_search";
        closeOptionsBrowseForm.submit();
    }
    return false;
}

function changeYear(ind)
{
    var sec = document.getElementById("citySectionSelect");
    sec.options.length = 0;
    switch (ind)
    {
        case 0: 
            sec.options.length = 3;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Minutes and Lists of Inhabitants", "Minutes and Lists of Inhabitants");
            sec.options[2] = new Option("Index", "Index");
            break;
        case 1: 
            sec.options.length = 5;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Guide", "Street Guide");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("End Matter", "End Matter");
            sec.options[4] = new Option("Advertisements", "Advertisements");
            break;
        case 2: 
            sec.options.length = 4;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Directory", "Street Directory");
            sec.options[2] = new Option("Home District", "Home District");
            sec.options[3] = new Option("General Intelligence", "General Intelligence");
            break;
        case 3: 
            sec.options.length = 4;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Guide", "Street Guide");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("End Matter", "End Matter");
            break;
        case 4: 
            sec.options.length = 5;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("General Intelligence", "General Intelligence");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Home District Directory", "Home District Directory");
            sec.options[4] = new Option("Advertisements", "Advertisements");
            break;
        case 5: 
            sec.options.length = 5;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("General Intelligence", "General Intelligence");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("County of York", "County of York");
            sec.options[4] = new Option("Advertisements", "Advertisements");
            break;
        case 6: 
            sec.options.length = 8;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Directory", "Street Directory");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Business", "Business");
            sec.options[4] = new Option("Governmental & Departmental", "Governmental & Departmental");
            sec.options[5] = new Option("Banking", "Banking");
            sec.options[6] = new Option("Advertisements", "Advertisements");
            sec.options[7] = new Option("Almanack", "Almanack");
            break;
        case 7: 
            sec.options.length = 5;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Directory", "Street Directory");
            sec.options[2] = new Option("Subscribers' Classification", "Subscribers' Classification");
            sec.options[3] = new Option("Miscellaneous", "Miscellaneous");
            sec.options[4] = new Option("Advertisements", "Advertisements");
            break;
        case 8: 
            sec.options.length = 9;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Directory", "Street Directory");
            sec.options[2] = new Option("Street Summary", "Street Summary");
            sec.options[3] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[4] = new Option("Professional and Trades Directory", "Professional and Trades Directory");
            sec.options[5] = new Option("Banking Directory", "Banking Directory");
            sec.options[6] = new Option("City Corporation", "City Corporation");
            sec.options[7] = new Option("Miscellaneous", "Miscellaneous");
            sec.options[8] = new Option("Advertisements", "Advertisements");
            break;
        case 9: 
            sec.options.length = 6;
            sec.options[0] = new Option("Advertisements", "Advertisements");
            sec.options[1] = new Option("Front Matter", "Front Matter");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Street Directory", "Street Directory");
            sec.options[4] = new Option("Business Directory", "Business Directory");
            sec.options[5] = new Option("Appendix", "Appendix");
            break;
        case 10: 
            sec.options.length = 5;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[2] = new Option("Street Directory", "Street Directory");
            sec.options[3] = new Option("Business Directory", "Business Directory");
            sec.options[4] = new Option("Appendix", "Appendix");
            break;
        case 11: 
            sec.options.length = 5;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Sketch of Toronto", "Sketch of Toronto");
            sec.options[2] = new Option("Business Directory", "Business Directory");
            sec.options[3] = new Option("Appendix", "Appendix");
            sec.options[4] = new Option("Advertisements", "Advertisements");
            break;
        case 12: 
            sec.options.length = 7;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Directory", "Street Directory");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Classified Business Directory", "Classified Business Directory");
            sec.options[4] = new Option("Counties of York and Peel", "Counties of York and Peel");
            sec.options[5] = new Option("Appendix", "Appendix");
            sec.options[6] = new Option("Advertising Directory", "Advertising Directory");
            break;
        case 13: 
            sec.options.length = 6;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Guide", "Street Guide");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Manufacturing Establishments", "Manufacturing Establishments");
            sec.options[4] = new Option("Business Directory", "Business Directory");
            sec.options[5] = new Option("Appendix", "Appendix");
            break;
        case 14: 
            sec.options.length = 6;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Directory", "Street Directory");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Alphabetical Directory of Yorkville", "Alphabetical Directory of Yorkville");
            sec.options[4] = new Option("Business Directory", "Business Directory");
            sec.options[5] = new Option("Appendix", "Appendix");
            break;
        case 15: 
            sec.options.length = 4;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[2] = new Option("Street Directory", "Street Directory");
            sec.options[3] = new Option("Business Directory", "Business Directory");
            break;
        case 16: 
            sec.options.length = 4;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[2] = new Option("Street Directory", "Street Directory");
            sec.options[3] = new Option("Business Directory", "Business Directory");
            break;
        case 17: 
            sec.options.length = 4;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[2] = new Option("Street Directory", "Street Directory");
            sec.options[3] = new Option("Business Directory", "Business Directory");
            break;
        case 18: 
            sec.options.length = 6;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Business Directory", "Business Directory");
            sec.options[2] = new Option("Street Directory", "Street Directory");
            sec.options[3] = new Option("Description of Toronto", "Description of Toronto");
            sec.options[4] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[5] = new Option("Miscellaneous Directory", "Miscellaneous Directory");
            break;
        case 19: 
            sec.options.length = 5;
            sec.options[0] = new Option("Advertising Directory", "Advertising Directory");
            sec.options[1] = new Option("Front Matter", "Front Matter");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Street Directory", "Street Directory");
            sec.options[4] = new Option("Business Directory", "Business Directory");
            break;
        case 20: 
            sec.options.length = 6;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Business Directory", "Business Directory");
            sec.options[2] = new Option("Street Directory", "Street Directory");
            sec.options[3] = new Option("Description of Toronto", "Description of Toronto");
            sec.options[4] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[5] = new Option("Miscellaneous Directory", "Miscellaneous Directory");
            break;
        case 21: 
            sec.options.length = 5;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Business Directory", "Business Directory");
            sec.options[2] = new Option("Street Directory", "Street Directory");
            sec.options[3] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[4] = new Option("Miscellaneous Directory", "Miscellaneous Directory");
            break;
        case 22: 
            sec.options.length = 5;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Directory", "Street Directory");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Business Directory", "Business Directory");
            sec.options[4] = new Option("Miscellaneous Directory", "Miscellaneous Directory");
            break;
        case 23: 
            sec.options.length = 6;
            sec.options[0] = new Option("Advertising", "Advertising");
            sec.options[1] = new Option("Front Matter", "Front Matter");
            sec.options[2] = new Option("Street Directory", "Street Directory");
            sec.options[3] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[4] = new Option("Business Directory", "Business Directory");
            sec.options[5] = new Option("Miscellaneous Directory", "Miscellaneous Directory");
            break;
        case 24:
            sec.options.length = 7;
            sec.options[0] = new Option("Advertising", "Advertising");
            sec.options[1] = new Option("Front Matter", "Front Matter");
            sec.options[2] = new Option("Street Directory", "Street Directory");
            sec.options[3] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[4] = new Option("Neighbourhood Directory ", "Neighbourhood Directory ");
            sec.options[5] = new Option("Business Directory", "Business Directory");
            sec.options[6] = new Option("Miscellaneous Directory", "Miscellaneous Directory");
            break;
        case 25:
            sec.options.length = 6;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Directory", "Street Directory");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Neighbourhood Directory ", "Neighbourhood Directory ");
            sec.options[4] = new Option("Business Directory", "Business Directory");
            sec.options[5] = new Option("Miscellaneous Directory", "Miscellaneous Directory");
            break;
        case 26:
            sec.options.length = 6;
            sec.options[0] = new Option("Front Matter", "Front Matter");
            sec.options[1] = new Option("Street Directory", "Street Directory");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Neighbourhood Directory", "Neighbourhood Directory");
            sec.options[4] = new Option("Business Directory", "Business Directory");
            sec.options[5] = new Option("Miscellaneous Directory", "Miscellaneous Directory");
//            sec.options[6] = new Option("Street Directory", "Street Directory");
//            sec.options[7] = new Option("Alphabetical Directory", "Alphabetical Directory");
//            sec.options[8] = new Option("Places in Neighbourhoods", "Places in Neighbourhoods");
//            sec.options[9] = new Option("Business Directory", "Business Directory");
            break;
        case 27:
            sec.options.length = 6;
            sec.options[0] = new Option("Advertising", "Advertising");
            sec.options[1] = new Option("Street Directory", "Street Directory");
            sec.options[2] = new Option("Alphabetical Directory", "Alphabetical Directory");
            sec.options[3] = new Option("Neighbourhood Directory", "Neighbourhood Directory");
            sec.options[4] = new Option("Business Directory", "Business Directory");
            sec.options[5] = new Option("Miscellaneous Directory", "Miscellaneous Directory");
            break;
    }
}




