﻿
// added for new way to show and hide question boxes

var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
var TopLeftofDivXposition = 400
var TopLeftofDivYposition = 200
var HeightofQuesImage = 0
var HeightOfDiv = 300
var WidthOfDiv = 300
var OffsetHtOfQuesImage = 85
var TopofQuesImage = 0

var LeftPosOfDivEmail = 400
var TopPosOfDivEmail = 200
var HeightofDivEmail = 125
var WidthofDivEmail = 220
var LeftPosOfContact = 0
var TopPosOfContact = 0
var HeightofDivContact = 400
var WidthofDivContact = 225
function getMouseXY(e) {
    if (IE) { // grab the x-y pos.s if browser is IE
        tempX = event.clientX + document.body.scrollLeft;
        tempY = event.clientY + document.body.scrollTop;
    }
    else {  // grab the x-y pos.s if browser is NS
        tempX = e.pageX;
        tempY = e.pageY;
    }
    if (tempX < 0) { tempX = 0; }
    if (tempY < 0) { tempY = 0; }
    document.getElementById("scrollpos").value = document.documentElement.scrollTop;
    document.getElementById("posY").value = tempY;

    // test position of cursor relative to drop down question boxes if any have been dropped down
    if (document.getElementById("hdnActiveQuesBox").value != "none")  //something has been dropped down
    {
        if (document.getElementById("hdnActiveQuesBox").value == "email" || document.getElementById("hdnActiveQuesBox").value == "call")
        {
            if (document.getElementById("hdnActiveQuesBox").value == "email")
            {
            setdivemailparams();
            }
        if (document.getElementById("hdnActiveQuesBox").value == "call") {
            setdivcallparams();
            }
    // the email box or the call box has been dropped down
       // {
            // test to see if the cursor is left of the box or above the dropdown box plus the image height

        //if (tempX < LeftPosOfDivEmail || tempY < TopPosOfDivEmail - OffsetHtOfQuesImage) {
        if (tempX < LeftPosOfDivEmail || tempY < TopPosOfDivEmail - OffsetHtOfQuesImage - document.documentElement.scrollTop) {
        //if (tempX < LeftPosOfDivEmail || tempY < (TopPosOfDivEmail - document.documentElement.scrollTop) - OffsetHtOfQuesImage) {
            ////if (tempX < LeftPosOfDivEmail || tempY < TopofQuesImage) {
                //alert('hit first');
                document.getElementById("hdnActiveQuesBox").value = "none";
                document.getElementById('divEmail').style.display = 'none';
                document.getElementById('divCall').style.display = 'none';
            }
            // test to see if the cursor is right of the box or below the dropdown box plus the image height
            if (IE) {
                //if (tempX > (LeftPosOfDivEmail + (WidthofDivEmail)) || tempY > (TopPosOfDivEmail + (HeightofDivEmail - 20))) {
                // with IE we have to allow for the new position if the page has been scrolled
                if (tempX > (LeftPosOfDivEmail + (WidthofDivEmail)) || tempY > (TopPosOfDivEmail - document.documentElement.scrollTop + (HeightofDivEmail - 20))) {
                 //if (tempX > (LeftPosOfDivEmail + (WidthofDivEmail)) || tempY > ((TopPosOfDivEmail - document.documentElement.scrollTop) - HeightofDivEmail - 20)) {
                     //alert('hit second y=' + tempY + ' scrltp=' + document.documentElement.scrollTop);
                    document.getElementById("hdnActiveQuesBox").value = "none";
                    document.getElementById('divEmail').style.display = 'none';
                    document.getElementById('divCall').style.display = 'none';
                }
            }
            if (!IE) {
                if (tempX > (LeftPosOfDivEmail + WidthofDivEmail) || tempY > (TopPosOfDivEmail + (HeightofDivEmail - 25))) {
                    document.getElementById("hdnActiveQuesBox").value = "none";
                    document.getElementById('divEmail').style.display = 'none';
                    document.getElementById('divCall').style.display = 'none';
                }
            }

        }
        if (document.getElementById("hdnActiveQuesBox").value == "contact") {
            setdivcontactparams();
            //alert('got to contact');
            if (IE) {
                // test for left of box or above box & image
                // with IE we have to allow for the new position if the page has been scrolled
                if (tempX < LeftPosOfDivContact || tempY < TopPosOfDivContact - OffsetHtOfQuesImage - document.documentElement.scrollTop) {
                    //if (tempX < LeftPosOfDivContact || tempY < TopPosOfDivContact - OffsetHtOfQuesImage)
                        document.getElementById("hdnActiveQuesBox").value = "none";
                    document.getElementById('divContact').style.display = 'none';
                    //document.getElementById('divContact').style.visibility = 'hidden'
                    //var thisiframe = document.getElementById('frForm');  PUT BACK IN AFTER FIXING
                    //alert('got here 1');
                    document.getElementById('hrefdummy').focus(); //for IE9 bug
                }
            }
            if (!IE) {
                // test for left of box or above box & image
                if (tempX < LeftPosOfDivContact || tempY < TopPosOfDivContact - OffsetHtOfQuesImage) {
                    if (tempX < LeftPosOfDivContact || tempY < TopPosOfDivContact - OffsetHtOfQuesImage)
                        document.getElementById("hdnActiveQuesBox").value = "none";
                    document.getElementById('divContact').style.display = 'none';
                    //document.getElementById('divContact').style.visibility = 'hidden'
                    var thisiframe = document.getElementById('frForm');
                }
            }
            if (IE) 
            {
                //if (tempX > (LeftPosOfDivContact + WidthofDivContact) || tempY > (TopPosOfDivContact + (HeightofDivContact - 20))) {
                if (tempX > (LeftPosOfDivContact + WidthofDivContact) || tempY > (TopPosOfDivContact + (HeightofDivContact - 20 - document.documentElement.scrollTop))) {
                    document.getElementById("hdnActiveQuesBox").value = "none";
                    document.getElementById('divContact').style.display = 'none';
                    //document.getElementById('divContact').style.visibility = 'hidden'
                    //alert('got here 2');
                    document.getElementById('hrefdummy').focus(); //for IE9 bug
                }
            }
            if (!IE) {
                if (tempX > (LeftPosOfDivContact + WidthofDivContact) || tempY > (TopPosOfDivContact + (HeightofDivContact - 25))) {
                    document.getElementById("hdnActiveQuesBox").value = "none";
                    document.getElementById('divContact').style.display = 'none';
                    //document.getElementById('divContact').style.visibility = 'hidden'
                }
            }

        }
    }

    return true;
}
function findDivPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findDivPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
function setdivemailparams() {
    document.getElementById('divContact').style.display = 'none';
    document.getElementById('hrefdummy').focus(); //for IE9 bug

    LeftPosOfDivEmail = findDivLeftEmail(document.getElementById("divEmail"))
    TopPosOfDivEmail = findDivTopEmail(document.getElementById("divEmail"))
    document.getElementById("hdnActiveQuesBox").value = "email";
    HeightofQuesImage = getHeightofObject(document.getElementById('divCall'));
    TopofQuesImage = getTopPosOfQuesImage()
    //document.getElementById("imgHeight").value = HeightofQuesImage;
    //document.getElementById("imgTop").value = TopofQuesImage;
    //document.getElementById("hdnvalue").value = document.getElementById("hdnActiveQuesBox").value
    
}
function setdivcallparams() {
    // ************ WE CAN USE THE EMAIL HERE BECAUSE IT IS THE SAME SIZE AS THE CALL
    document.getElementById('divContact').style.visibility = 'none';
    document.getElementById('hrefdummy').focus(); //for IE9 bug

    LeftPosOfDivEmail = findDivLeftEmail(document.getElementById("divCall"))
    TopPosOfDivEmail = findDivTopEmail(document.getElementById("divCall"))
    document.getElementById("hdnActiveQuesBox").value = "call";
    //TopLeftofDivXposition = getLeftPosOfQuesImage();
    //TopLeftofDivYposition = getTopPosOfQuesImage();
    //alert('got here');
    //HeightofQuesImage = getHeightofQuesImage();
    HeightofQuesImage = getHeightofObject(document.getElementById('divCall'));
    TopofQuesImage = getTopPosOfQuesImage()
    //document.getElementById("imgHeight").value = HeightofQuesImage;
    //document.getElementById("imgTop").value = TopofQuesImage;
    var aryPosition = ObjectPosition(document.getElementById('imgQuestions'));
    //document.getElementById("hdnvalue").value = document.getElementById("hdnActiveQuesBox").value
    //document.getElementById("imgLeft").value = TopLeftofDivXposition;
    //document.getElementById("imgTop").value = TopLeftofDivYposition;

}
function setdivcontactparams() {
    document.getElementById('divContact').style.visibility = 'visible'
    LeftPosOfDivContact = findDivLeftEmail(document.getElementById("divContact"))
    TopPosOfDivContact = findDivTopEmail(document.getElementById("divContact"))
    document.getElementById("hdnActiveQuesBox").value = "contact";
    HeightofQuesImage = getHeightofObject(document.getElementById('divContact'));
    TopofQuesImage = getTopPosOfQuesImage()
    //document.getElementById("divContact").focus();
    if (IE) {
        var myIframe = document.frames['frForm'];
        var myField = document.frames['frForm'].document.getElementById('Name');
    }
    else {
        var myIframe = document.getElementById('frForm');
        var myField = document.getElementById('frForm').contentDocument.getElementById('Name');
    }
    //if (!safari) {
        myIframe.focus();
    //}
    myField.focus();
    //document.getElementById("imgHeight").value = HeightofQuesImage;
   // document.getElementById("imgTop").value = TopofQuesImage;
   // document.getElementById("hdnvalue").value = document.getElementById("hdnActiveQuesBox").value

}

function findDivLeftEmail(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findDivTopEmail(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
function getLeftPosOfQuesImage() {
    //alert('it is ' + document.getElementById('divCall').offsetLeft)
    return document.getElementById('divCall').offsetLeft;
}
function getTopPosOfQuesImage() {
    //alert('it is ' + document.getElementById('divCall').offsetLeft)
    //return document.getElementById('divCall').offsetLeft;
    return document.getElementById('imgQuestions').offsetTop;
}
function getHeightofQuesImage() {
    //alert('ht=' + document.getElementById('imgQuestions').height);
    return document.getElementById('imgQuestions').height;
}
function getHeightofObject(obj) {
    //alert('ht=' + document.getElementById('imgQuestions').height);
    //alert('obj=' + obj)
    //return document.getElementById(obj).offsetHeight
    return obj.offsetHeight
}
function ObjectPosition(obj) {
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent) 
    {
        do { curleft += obj.offsetLeft; curtop += obj.offsetTop; }
        while (obj = obj.offsetParent);
    }
    //alert('l=' + curleft + ' t=' + curtop);
    return [curleft, curtop]; 

  } 

 
