﻿// Displays a scripture reference in a popup window
function showReference(ref_id, e)
{
	ref_div = getElement(ref_id);
	main_table = getElement('mainTable');
	main_div = getElement('mainDiv');
	refDivTop = ((e.pageY) ? e.pageY : e.y+document.documentElement.scrollTop) + 15;
	refDivLeft = ((e.pageX) ? e.pageX : e.x+document.documentElement.scrollLeft) + 15;
	ref_div.style.top = addPx(refDivTop);
	ref_div.style.left = addPx(refDivLeft);
	adjustToLeft = main_div.offsetWidth - (refDivLeft + removePx(ref_div.style.width));
	ref_div.style.left = (adjustToLeft<0) ? addPx(refDivLeft + adjustToLeft) : ref_div.style.left;
	ref_div.style.visibility = "visible";
	
}
// Hides a scripture reference popup window
function cancelShowReference(ref_id)
{
	ref_div = getElement(ref_id);
	ref_div.style.visibility = "hidden";			
}

// Adds "px" to a number
function addPx(number)
{
    return (number.toString() + "px");
}
// Removes "px" from a string
function removePx(str)
{
    return new Number(str.replace("px", ""));
}
// Clears an element's value
function clearValue(element)
{
   element.value="";
}
// Launches a new window with Yahoo driving directions
function drivingDirections()
{
    url = "http://maps.yahoo.com/beta/#mvt=m&q2=3536+Prince+Rd+Alton+IL";
    //box = getElementByPartialId('directionsTextBox');
    //startAddress = box.value;
    //window.open(url.replace("START", startAddress));
    window.open(url);
}
// Returns a page element
function getElement(element_id)
{
	return document.getElementById(element_id);
}
// Finds an element by the end of it's .Net ClientId.  Used
// to find elements regardless of their containing control's
// .Net-assigned Id.  For example, searching for "MyDropDown"
// will find a control named "_ctl10_MyDropDown"
function getElementByPartialId(elementId)
{
	regex = new RegExp(elementId + '$');
	for(i=0;i<document.aspnetForm.elements.length;i++)
		if(document.aspnetForm.elements[i].id.match(regex)!=null)
			return document.aspnetForm.elements[i];
	return null;
}