function enquiryTypeSelect(value) {
    var timeRow = document.getElementById("timeRow");
    var enquiryRow = document.getElementById("enquiryRow");
    if (value == "question") {
        timeRow.style.display = "none";
        try { enquiryRow.style.display = "table-row"; }
        catch (e) { enquiryRow.style.display = "block"; } // IE6 doesn't recognise 'table-row' so use 'block' instead
    } else if (value == "demo") {
        try { timeRow.style.display = "table-row"; }
        catch (e) { timeRow.style.display = "block"; } // IE6 doesn't recognise 'table-row' so use 'block' instead
        enquiryRow.style.display = "none";
    }
}

function existingClientSelect(value) {
    var dateRow = document.getElementById("dateRow");
    if (value == "yes") {
        dateRow.style.display = "none";
    } else if (value == "no") {
        try { dateRow.style.display = "table-row"; }
        catch (e) { dateRow.style.display = "block"; } // IE6 doesn't recognise 'table-row' so use 'block' instead
    }
}

function ShowHideHover(hoverId, show, top, left, evt) {
    var target = document.getElementById(hoverId + "Target");
    var panel = document.getElementById(hoverId + "Panel");
    if (target && panel) {
        var scrollY = document.documentElement.scrollTop;
        var scrollX = document.documentElement.scrollLeft;

        if (show && panel.style.display == "none") {
            var clientHeight = GetClientHeight();
            var clientWidth = GetClientWidth();

            // Show hover
            panel.style.display = "block";

            // Calculate vertical position, make sure panel is not off the window
            if (!top || isNaN(top))
                top = GetTop(target);
            var height = GetHeight(panel);
            var bottom = top + height;
            if (bottom > scrollY + clientHeight - 8)
                top = scrollY + clientHeight - height - 8;
            if (top < 0) top = 0;

            // Calculate horizontal position, make sure panel is not off the window
            if (!left || isNaN(left))
                left = GetLeft(target);
            var width = GetWidth(panel);
            var right = left + width;
            if (right > scrollX + clientWidth - 20)
                left = scrollX + clientWidth - width - 20;
            if (left < 0) left = 0;

            panel.style.left = left + "px";
            panel.style.top = top + "px";
        }
        else if (!show && panel.style.display == "block") {
            var pointerY = scrollY + evt.clientY;
            var pointerX = scrollX + evt.clientX;

            // To avoid flicker, if pointer is still over the target then ignore
            if (GetLeft(target) < pointerX - 1 && pointerX - 1 <= GetRight(target)
				&& GetTop(target) < pointerY - 1 && pointerY - 1 <= GetBottom(target))
                return;

            // To avoid flicker, if pointer is still over the panel then ignore
            if (GetLeft(panel) < pointerX - 1 && pointerX < GetRight(panel)
				&& GetTop(panel) < pointerY - 1 && pointerY < GetBottom(panel))
                return;

            // Hide panel
            panel.style.display = "none";
        }
    }
}

function GetClientHeight() {
    if (document.body)
    // Quirks - IE/Firefox/Opera + Webkit (Safari/Chrome)
        return document.body.clientHeight;
    else if (document.documentElement && document.documentElement.clientHeight)
    // IE/Firefox/Opera Strict Mode
        return document.documentElement.clientHeight;
    else if (self.innerHeight)
    // fallback
        return self.innerHeight;
}

function GetClientWidth() {
    if (self.innerWidth)
    // All except IE
        return self.innerWidth;
    else if (document.documentElement && document.documentElement.clientWidth)
    // IE 6 Strict Mode
        return document.documentElement.clientWidth;
    else if (document.body)
    // Other IE
        return document.body.clientWidth;
}

function GetBottom(element) {
    return GetTop(element) + GetHeight(element);
}

function GetLeft(element) {
    if (!element) return 0;

    var left = element.offsetLeft;
    var parent = element.offsetParent;
    while (parent != null) {
        left += parent.offsetLeft;
        parent = parent.offsetParent;
    }

    return left;
}

function GetHeight(element) {
    if (!element) return 0;

    return element.offsetHeight;
}

function GetRight(element) {
    return GetLeft(element) + GetWidth(element);
}

function GetTop(element) {
    if (!element) return 0;

    var top = element.offsetTop;
    var parent = element.offsetParent;
    while (parent != null) {
        top += parent.offsetTop;
        parent = parent.offsetParent;
    }

    return top;
}

function GetWidth(element) {
    if (!element) return 0;

    return element.offsetWidth;
}

function WatchVideo(name) {
    $j.modal('<iframe width="853" height="480" src="http://www.youtube.com/embed/' + name + '" frameborder="0" allowfullscreen></iframe>',
            { zIndex: 90, overlayClose: true });
}

function enquiryRoleSelect(select) {
    
    var otherIsSelected = select.options[select.selectedIndex].text == "Other";

    $j('#RoleOther').css("display", (otherIsSelected ? "" : "none"));

    if (!otherIsSelected)
        $j('#JobRoleOther').val("");
}
