// ViewImages.js



var gMouseX = 0;

var gMouseY = 0;



document.onmousemove = CaptureMousePosition;

//window.onscroll = KeepAdsInView;



function CaptureMousePosition(e) {

    if (document.layers) {

        // When the page scrolls in Netscape, the event's mouse position

        // reflects the absolute position on the screen. innerHight/Width

        // is the position from the top/left of the screen that the user is

        // looking at. pageX/YOffset is the amount that the user has

        // scrolled into the page. So the values will be in relation to

        // each other as the total offsets into the page, no matter if

        // the user has scrolled or not.

        gMouseX = e.pageX;

        gMouseY = e.pageY;



    } else if (document.all) {

        // When the page scrolls in IE, the event's mouse position

        // reflects the position from the top/left of the screen the

        // user is looking at. scrollLeft/Top is the amount the user

        // has scrolled into the page. clientWidth/Height is the height/

        // width of the current page the user is looking at. So, to be

        // consistent with Netscape (above), add the scroll offsets to

        // both so we end up with an absolute value on the page, no

        // matter if the user has scrolled or not.

        gMouseX = window.event.x+document.body.scrollLeft;

        gMouseY = window.event.y+document.body.scrollTop;



    } else if (document.getElementById) {

        // Netscape 6 behaves the same as Netscape 4 in this regard

        gMouseX = e.pageX;

        gMouseY = e.pageY;

    }

}



function HiliteStarsUpTo(sID)

{   

    var sRoot = GetIDRoot(sID);

    for (var i = 1; i <= 5; i++)

    {

        var ele = GetRatingImage(sRoot, i);

        if (ele.id <= sID)

            ele.src = ele.src.replace("icn_star2.gif", "icn_star.gif");

    }

}



function UnhiliteStars(sID)

{

    var sRoot = GetIDRoot(sID);

    for (var i = 1; i <= 5; i++)

    {

        var ele = GetRatingImage(sRoot, i);

        ele.src = ele.src.replace("icn_star.gif", "icn_star2.gif");

    }

}



function GetRatingImage(sRoot, i)

{

    return document.getElementById(sRoot + "btnRate" + i);

}





function GetIDRoot(sID)

{

    return sID.substring(0, sID.lastIndexOf("_") + 1);

}



// TOOL TIPS



function GetElement(sID)

{

    return document.getElementById(sID);

}



function HideTooltip(sDivId)

{   

    var ele = document.getElementById(sDivId);

    ShowHideEle(ele, false);

    document.onmousemove = gLastMouseMove;

    document.oncontextmenu = null;

}



function MoveTooltip(sDivId)

{

    var ele = document.getElementById(sDivId);

    if (ele.style.visibility == "hidden") return;

    ele.style.top = gMouseY;

    ele.style.left = gMouseX;

}



var gLastMouseMove = null;



function ShowTooltip(sDivId, sMsg)

{

    gLastMouseMove = document.onmousemove;

    gLastMouseDown = document.onmousedown;

    

    document.onmousemove = CaptureMousePosition;

    document.oncontextmenu = PreventClick;

        

    var ele = document.getElementById(sDivId);

    ele.innerHTML = sMsg;

    ShowHideEle(ele, true);

    MoveTooltip(sDivId);

}



function ShowHideEle(ele, bShow)

{

    if (ele == null)

        return;

    if (typeof(ele) == "string")

        ele = GetElement(ele);

    if (bShow)

        ele.style.visibility = "visible";

    else

        ele.style.visibility = "hidden";

}



function FocusControl(sCtrlID)

{

    var ele = GetElement(sCtrlID);

    if (!ele) return;

    ele.focus();

}



// email form

function ShowEmailForm(sID)

{

    // position

    var ele = GetElement(sID);

    var pos = FindPos(ele.parentNode);

    

    ele.style.left = pos[0] - (ele.offsetWidth/3);

    ele.style.top = pos[1] - (2*ele.offsetHeight/3);

    // show, set focus and select text

    ShowHideEle(ele, true);

    FocusControl("ctrlResultsview_compView_txtEmailFrom");

    GetElement("ctrlResultsview_compView_txtEmailFrom").select();

}



function HideEmailForm(sID)

{

    ShowHideEle(sID, false);

}



function FindPos(ele) 

{

	var curleft = curtop = 0;

	if (ele.offsetParent) {

		curleft = ele.offsetLeft

		curtop = ele.offsetTop

		while (ele = ele.offsetParent) {

			curleft += ele.offsetLeft

			curtop += ele.offsetTop

		}

	}

	return [curleft,curtop];

}



function PreventClick(e) 

{

    if (e.which) // firefox, netscape

    {    

        if (e.type == "contextmenu" || e.which == 1)

        {

            alert('Design Copyright Helen Hartley 2007. This picture is for viewing purposes only. No reproduction or distribution rights are granted.');

            return false;

        }

    }

    else if (e.button)

    {

        //if (e.button == 2 || e.button == 3)

        alert('Design Copyright Helen Hartley 2007. This picture is for viewing purposes only. No reproduction or distribution rights are granted.');

        return false;

    }

    return true;

}





function RedirectToTop(sPartner, sPhrase)

{

    // if location does not have a partner, add current domain as partner

    // if location does not have a phrase, get referrer phrase

    var sLoc = document.location.href;

    if (sLoc.indexOf("?") < 0)

        sLoc += "?";

    if (sLoc.indexOf("Partner=") < 0 && sLoc.indexOf("partner=") < 0)

        sLoc += "&Partner=" + sPartner;

    if (sLoc.indexOf("phrase=") < 0)

        sLoc += "&phrase=" + sPhrase;

    top.location.href=sLoc;

}



var gRightSideAdsTop = 210;  // figure this out dynamically?



function KeepAdsInView(e)

{

    var ele = GetElement("divRightSideAds");

    if (!ele)

        return;

    if (ele.style.top == "" || !ele.style.top)

        ele.style.top = "0px";

    //alert(ele.style.top);

    

    if (document.layers) {

        if (window.pageYOffset > gRightSideAdsTop)

        {

            ele.style.top = "" + (window.pageYOffset - gRightSideAdsTop) + "px";

        }

        else 

        {

            ele.style.top = "0px";

        }

    } else if (document.all) {

        if (document.body.scrollTop > gRightSideAdsTop)

        {

            ele.style.top = "" + (document.body.scrollTop - gRightSideAdsTop) + "px";

        }

        else 

        {

            ele.style.top = "0px";

        }



    } else if (document.getElementById) {

        if (window.pageYOffset > gRightSideAdsTop)

        {

            ele.style.top = "" + (window.pageYOffset - gRightSideAdsTop) + "px";

        }

        else 

        {

            ele.style.top = "0px";

        }

    }

}