﻿function hideMultiSelectDropDown(hypThisItem) {

    var allInputElements = document.getElementsByTagName("input");
    for (var j = 0; j < allInputElements.length; j++) {
        var input = allInputElements[j];
        if (input.id != hypThisItem && input.type == "image" && input.src.indexOf("images/addShrink.gif") >= 0) {
            input.click();
            break;
        }
    }
}

function copyWidth(idCopyWidth, idCopyWidthTo) {
    if (idCopyWidth != "")
        $get(idCopyWidthTo).style.width = $get(idCopyWidth).offsetWidth;
}

function swapDivide(divideName, hypThisItem, cmbCtrlUID, idFocus, bIsSmall) {

    var sSmall = (bIsSmall ? "Sm" : "");
    var isHide = $get(divideName).style.display != "none";

    // if we are showing then close any open first
    if (!isHide) { hideMultiSelectDropDown(hypThisItem); }

    $get(divideName).style.display = (isHide ? "none" : "block");
    if (idFocus != "" && !isHide) {
        setFocusControl(idFocus);
    }

    if (hypThisItem != "") {
        $get(hypThisItem).src = (isHide ? "images/addExpand" + sSmall + ".gif" : "images/addShrink" + sSmall + ".gif");
    }

    CombosVisible(cmbCtrlUID, isHide);
}

function hideDivide(divideName, hypThisItem, cmbCtrlUID, idFocus, bIsSmall) {

    var sSmall = (bIsSmall ? "Sm" : "");
    var isHide = true;

    // if we are showing then close any open first
    if (!isHide) { hideMultiSelectDropDown(hypThisItem); }

    $get(divideName).style.display = (isHide ? "none" : "block");
    if (idFocus != "" && !isHide) {
        setFocusControl(idFocus);
    }

    if (hypThisItem != "") {
        $get(hypThisItem).src = (isHide ? "images/addExpand" + sSmall + ".gif" : "images/addShrink" + sSmall + ".gif");
    }

    CombosVisible(cmbCtrlUID, isHide);
}

function CombosVisible(cmb, visible) {
    var cmbs = cmb.split(",");

    for (var i = 0; i < cmbs.length; i++) {
        if (cmbs[i] != "") {
            try {
                $get(cmbs[i]).style.visibility = (visible ? "visible" : "hidden");
            } catch (e) { }
        }
    }
}

function sendOneCheckedToLabel(chk, chkID, targetCell, cellName1, cellName2, cellName3, cellName4, sep) {//, targetOrder, cellOrder

    var idBuilder = chkID.substring(0, chkID.indexOf(chk));  //chkID.substring(0, chkID.length - chk.length);

    var iStrt = 0; var iEnd = 0; var sLocator = ""; var sCtrlTxt = ""; var sCellText = "";

    if (cellName1 != "") { // Control
        sCtrlTxt = "" + $get(idBuilder + cellName1).innerHTML;

        // if it ends with a space or if contains a br then break before it
        if (sCtrlTxt.toLowerCase().indexOf(sep.toLowerCase()) >= 0) {
            sCtrlTxt = sCtrlTxt.substring(0, sCtrlTxt.toLowerCase().indexOf(sep.toLowerCase()));
        }
        if (sCtrlTxt.lastIndexOf(" ") == (sCtrlTxt.length - 1)) {
            sCtrlTxt = sCtrlTxt.substring(0, sCtrlTxt.length - 1);
        }

        if ($get(targetCell).type == "text") {
            do {
                sCtrlTxt = sCtrlTxt.replace("&amp;", "&");
            } while (sCtrlTxt.indexOf("&amp;") >= 0)
        }

        iStrt = sCtrlTxt.indexOf("<A id=");
        if (iStrt >= 0) {
            iEnd = sCtrlTxt.indexOf(" ", iStrt + 3) + 1;
            sLocator = sCtrlTxt.substring(iStrt, iEnd);
        }

        if (cellName2 != "" && sCtrlTxt.substring(sCtrlTxt.length - 1, sCtrlTxt.length) != " ") {
            sCellText += " - ";
        }
    }
    if (cellName2 != "") { // Name
        sCellText += $get(idBuilder + cellName2).innerHTML;
    }
    if (cellName3 != "") { // Extra
        sCellText += " " + $get(idBuilder + cellName3).innerHTML;
    }
    if (cellName4 != "") { // Brakets
        sCellText += " (" + $get(idBuilder + cellName4).innerHTML + ")";
    }
    // uppercase tags required for replace function to work
    sCellText += sep;

    //	var sOrderText = "";
    //	if (cellOrder != "") 
    //	{ // Order Of Ticks
    //		sOrderText += $get(idBuilder + cellOrder).value + ",";
    //	}

    if ($get(chkID).checked) {

        if ($get(targetCell).innerHTML == "Any Town") $get(targetCell).innerHTML = "";

        if (sCellText != sep || sCtrlTxt != "") {
            if ($get(targetCell).type == "text") {
                $get(targetCell).value += sCtrlTxt + sCellText;
            }
            else {
                $get(targetCell).innerHTML += sCtrlTxt + sCellText;
            }

        }
        //if (sOrderText != "") { $get(targetOrder).value += sOrderText; }
    }
    else {
        if (sCellText != sep || sCtrlTxt != "") {

            if (cellName1 != "" && sLocator != "") { // Control
                iCrtlStrt = $get(targetCell).innerHTML.indexOf(sLocator);

                if (iCrtlStrt >= 0) {
                    iCtrlEnd = $get(targetCell).innerHTML.indexOf("</A> ", iCrtlStrt);
                    sCtrlTxt = $get(targetCell).innerHTML.substring(iCrtlStrt, iCtrlEnd + 4);
                }
            }

            if ($get(targetCell).type == "text") {
                $get(targetCell).value = $get(targetCell).value.replace(sCtrlTxt + sCellText, "");
            }
            else {
                $get(targetCell).innerHTML = $get(targetCell).innerHTML.replace(sCtrlTxt + sCellText, "");
            }
        }
        //if (sOrderText != "") { $get(targetOrder).value = $get(targetOrder).value.replace(sOrderText, ""); }
        if ($get(targetCell).innerHTML == "") $get(targetCell).innerHTML = "Any Town";
    }

}

function sendSelectedToTextBox(CellID, textBoxID) {

    var sStandardText = $get(CellID).innerHTML;
    var sTargetTextBox = $get(textBoxID);
    sTargetTextBox.value += sStandardText;
    sTargetTextBox.focus();
    //Sets the cursor to the end of the text//
    if (sTargetTextBox.createTextRange) {
        var FieldRange = sTargetTextBox.createTextRange();
        FieldRange.moveStart('character', sTargetTextBox.value.length);
        FieldRange.collapse();
        FieldRange.select();
    }
}

function loadScrollWindow(fT, fB) {
    if (fT)
        document.documentElement.scrollTop = 0;
    else if (fB || parseInt($get('windowScroll').value) > (document.documentElement.scrollHeight - document.documentElement.clientHeight))
        document.documentElement.scrollTop = (document.documentElement.scrollHeight - document.documentElement.clientHeight);
    else
        document.documentElement.scrollTop = $get('windowScroll').value;

    window.onscroll = scrollItemWindow;
}

function scrollItemWindow() {
    $get('windowScroll').value = document.documentElement.scrollTop;
}

function loadScroll(divName, divPos) {
    if (parseInt($get(divPos).value) > $get(divName).scrollHeight)
        $get(divName).scrollTop = $get(divName).scrollHeight;
    else
        $get(divName).scrollTop = $get(divPos).value;

    var funcScroll = scrollItem(divName, divPos);
    $get(divName).attachEvent("onscroll", funcScroll);
}

function scrollItem(divName, divPos) {
    return function () {
        $get(divPos).value = $get(divName).scrollTop;
    }
}

function tickAll(gridID, chkName, toggleID, callOnClick) {

    var tick;
    if (toggleID == "true" || toggleID == "false") {
        tick = (toggleID == "true");
    } else {
        tick = $get(toggleID).checked;
    }

    var max = document.forms[0].elements.length;

    for (var i = 0; i < max; i++) {
        if (document.forms[0].elements[i].id.indexOf(gridID) >= 0
			&& document.forms[0].elements[i].id.indexOf(chkName) >= 0) {

            if (!document.forms[0].elements[i].disabled && document.forms[0].elements[i].checked != tick) {
                document.forms[0].elements[i].checked = tick;

                if (callOnClick)
                    try { document.forms[0].elements[i].onclick(); }
                    catch (e) { try { document.forms[0].elements[i].onclick; } catch (e) { } }
            }
        }
    }
}



Image1 = new Image(286, 436)
Image1.src = "images/map/MAPWITHARROWS.gif"

Image2 = new Image(286, 436)
Image2.src = "images/map/CENTRAL.gif"

Image3 = new Image(286, 436)
Image3.src = "images/map/EAST.gif"

Image4 = new Image(286, 436)
Image4.src = "images/map/LONDON.gif"

Image5 = new Image(286, 436)
Image5.src = "images/map/NORTH.gif"

Image6 = new Image(286, 436)
Image6.src = "images/map/SOUTH-EAST.gif"

Image7 = new Image(286, 436)
Image7.src = "images/map/SOUTH-WEST.gif"

Image8 = new Image(286, 436)
Image8.src = "images/map/WALES.gif"

function loadMap(imgMap) {
    document.imgMap.src = imgMap.src; return true;
}

function hotspot(MapId) {
    $get(MapId).checked = !$get(MapId).checked;
    //document.aspnetForm.ctl00_ContentPlaceHolder1_conSearch1_chk24.checked = true;
}

function toggle(num, txt, lnk) {
    toggleImage(num);
    setLevel1(num, txt, lnk);
    //toggleCheckBox(num);
}

function toggleCheckBox(num) {
    cb = document.getElementById('srch_reg_' + num);
    if (cb.checked == true) { var cbToggle = false } else { cbToggle = true };
    document.getElementById('srch_reg_' + num).checked = cbToggle;
}

function toggleImage(num) {
    regionVisi = (document.getElementById('imgMap' + num).style.visibility == 'visible') ? 'hidden' : 'visible';
    document.getElementById('imgMap' + num).style.visibility = regionVisi;
}

function showRegion(num) {  //rollovers only
    document.getElementById("imgMap").src = "images/map/map" + num + ".gif";
}

function setLevel1(num, txt, lnk) {
    if ($get(txt).value.indexOf(num) > -1) {
        $get(txt).value = ($get(txt).value.replace(num, ""));
    }
    else {
        $get(txt).value = $get(txt).value + num;
    }
//    try { $get(lnk).click(); }
//    catch (e) { try { $get(lnk).click; } catch (e) { } }

    if ($get(lnk).dispatchEvent) {
        var e = document.createEvent("MouseEvents");
        e.initEvent("click", true, true);
        $get(lnk).dispatchEvent(e);
    }
    else {
        $get(lnk).click();
    }

}


