﻿//
// BUSINESS TO HANDLE MOUSE POINTER LOCATION.
//
function getX(evt) {
    if (document.all) { return (evt.clientX); }
    return (evt.layerX);
}
function getY(evt) {
    if (document.all) { return (evt.clientY); }
    return (evt.layerY);
}
function getScrollX() {
    if (document.all) { return (document.body.scrollLeft); }
    return (window.pageXOffset);
}
function getScrollY() {
    if (document.all) { return (document.body.scrollTop); }
    return (window.pageYOffset);
}
function showValues(e) {

    var posStr = 'posX = ' + posx + ' posY = ' + posy
    document.getElementById('mousepos').innerHTML = posStr;
    window.status = posStr;
}

//
// FUNCTION: displayBusinessImage
// DESCRIPTION:
// This displays the selected business image.
//
function displayBusinessImage(newImage, imageHolder, videoHolder) {
    // Hide the video holder.
    $(videoHolder).hide();
    
    // Show the image holder.
    $(imageHolder).show();
    
    // Set the source of the image holder.
    $(imageHolder).src = $(newImage).src;
    
    return false;
}

//
// FUNCTION: displayBusinessVideo
// DESCRIPTION:
// This function diplays the currently selected business video.
//
function displayBusinessVideo(imageHolder, videoHolder) {
    // Hide image holder.
    $(imageHolder).hide();
    
    // Show video holder.
    $(videoHolder).show();
    
    return false;
}

//
// FUNCTION: hoursOfOperationHoverHandler
// DESCRIPTION:
// This function handles the hours of operation bubble on the business
// details page.
//
function showHoo(e, hooDivID) {
    var posx = 0;
    var posy = 0;
    posx = getX(e) + getScrollX();
    posy = getY(e) + getScrollY();
    $(hooDivID).setStyle({ top: posy + 'px', left: posx + 'px', display: 'block' });
}
function hideHoo(hooDivID) {
    $(hooDivID).setStyle({ display: 'none' });
} 

//
// FUNCTION: locationsHoverHandler
// DESCRIPTION:
// This function handles the locations bubble on the business
// details page.
//
function showLocations(e, locationsDivID) {
    var posx = 0;
    var posy = 0;
    posx = getX(e) + getScrollX();
    posy = getY(e) + getScrollY();
    $(locationsDivID).setStyle({ top: posy + 'px', left: posx + 'px', display: 'block' });
} 
function hideLocations(locationsDivID) {
    $(locationsDivID).setStyle({ display: 'none' });
} 

//
// FUNCTION: handleEnter
// DESCRIPTION:
// This function handles the pressing of the enter key on a form and blocks
// it form submitting the form.
//
function handleEnter(field, e)
{
    var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    if (keyCode == 13) {
        var i;
        for (i = 0; i < field.form.elements.length; i++)
            if (field == field.form.elements[i])
                break;
        i = (i + 1) % field.form.elements.length;
        return false;
    }else{
        return true;
    }
}

//
// FUNCTION: doSubmitFormOnEnter
// DESCRIPTION:
// This function handles the submits a form when enter is hit.
//
function doSubmitFormOnEnter(e, submitButton)
{
    var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    if(keyCode == 13) {
        document.getElementById(submitButton).click();
        return false;
    } else {
        return true;
    }
}   

//
// FUNCTION: doChangeFieldOnEnter
// DESCRIPTION:
// This function handles captures and enter and changes fieds on it.
//
function doChangeFieldOnEnter(e, nextField)
{
    var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    if(keyCode == 13) {
        document.getElementById(nextField).focus();
        return false;
    } else {
        return true;
    }
}
