﻿// <!--


// Variables used to store the URLs to the directory search
var sPersonSearchUrl = "http://212.9.21.212/80256C0D005D32A8/WhiteContactDetails";
var sBusinessSearchUrl = "http://www.thejerseydirectory.com/bussearch.aspx";
var sLocationSearchUrl = "http://www.thejerseydirectory.com/mapsearch.aspx";

//= override the on key down event
if (document.all) { //ie has to block in the key down
    document.onkeydown = stopEvent;
} else if (document.layers || document.getElementById) { //NS and mozilla have to block in the key press
    document.onkeypress = stopEvent;
}

//= stops event bubbling
function stopEvent(evt) {

    if (evt != null) {

        //= if the key that has been pressed is enter, 
        if ((evt.which && evt.which == 13) || (evt.keyCode && evt.keyCode == 13)) {

            //= cancel the event
            var oEvent = (window.event) ? window.event : evt;
            try {
                oEvent.returnValue = false;
                oEvent.cancelBubble = true;

                if (document.all) { //IE
                    oEvent.keyCode = 0;
                } else { //NS
                    oEvent.preventDefault();
                    oEvent.stopPropagation();
                }
                window.status = msg;
            } catch (ex) {
                //alert(ex);
            }
        }
    }
}

//= determine which search to run
function search(evt, SearchType) {

    //= if the enter key was pressed, cancel any events and perform the search
    if ((evt.which && evt.which == 13) || (evt.keyCode && evt.keyCode == 13)) {

        stopEvent(evt);

        if (SearchType == "p") {
            submit_personsearch(document.forms[0])
        }
        else if (SearchType == "c") {
            submit_businesssearchclassification(document.forms[0])
        }
        else if (SearchType == "b") {
            submit_businesssearchname(document.forms[0])
        }
        else if (SearchType == "l") {
            submit_locationsearch(document.forms[0])
        }

    }
}

//= assemble the url for person search and open it in a new fixed sized window
function submit_personsearch(objForm) {

    // SURNAME
    var vSurnameQuery = "[Surname] EQUALS " + objForm.searchSN.value;

    //LOCATION
    var vLocationQuery = ""; //= " AND [Location] EQUALS " + objForm.searchLoc.value;

    //INITIAL
    if (objForm.searchFirst.value == "") {
        var vInitialQuery = "";
    }
    else {
        var vInitialQuery = " AND [FirstInitial] EQUALS " + objForm.searchFirst.value
    }

    //= construct the query
    vQuery = "(" + vSurnameQuery + vLocationQuery + vInitialQuery + ")";

    //= set the url and open the window
    vResultURL = sPersonSearchUrl + "?SearchView&Query=" + vQuery + "&Start=1&SearchOrder=4";
    window.open(vResultURL, "popup", "height=500,width=320,scrollbars=yes");

    objForm.searchSN.value = "";
    objForm.searchFirst.value = "";

    return false;
}

function submit_businesssearchclassification(objForm) {

    vResultURL = sBusinessSearchUrl + "?stype=" + objForm.classification_name.value;
    window.open(vResultURL, "popup", "height=800,width=1050,scrollbars=yes");
    objForm.classification_name.value = "";

    return false;
}

function submit_businesssearchname(objForm) {

    vResultURL = sBusinessSearchUrl + "?sname=" + objForm.business_name.value;
    window.open(vResultURL, "popup", "height=800,width=1050,scrollbars=yes");

    objForm.business_name.value = "";

    return false;
}


//= assemble the url for location search and open it in a new window
function submit_locationsearch(objForm) {
    vResultURL = sLocationSearchUrl + "?sroad=" + objForm.strSearch.value;
    window.open(vResultURL, "popup", "height=800,width=1050,scrollbars=yes");
    objForm.strSearch.value = "";
    return false;
}

//-->

