<!--
// First add this to the top of the page that you want scrolling:
//		<script type="text/javascript" src="/www/common/client_scripts/scroll.js"></script>
//
// ** CAN ONLY BE USED ON THE PAGE LEVEL (NOT INSIDE A CONTROL).
// For scrolling to work it needs to have a hidden input INSIDE the form called scrollY: (initialized with value=0)
//			<input type="hidden" name="scrollY" id="scrollY" runat="server" value="null">
//
// It also needs to call the setScroll() method at the end of the html page 
//	** PUT IT AT THE VERY END OF THE PAGE... AFTER THE </html>.. after the BottomPH placeholders
//			<script type="text/javascript">setScroll();</script>
//
// And then in needs to add to each object that postbacks the script that calls the saveScrollY(),
// so that before every PostBack the scroll is saved in the hidden input.
//			For example for a btn, it will add it in the onClick event:
//				onClick="javascript:saveScrollY();"
//
// *****************************************************
// Another way of maintaining scroll when reloading the same page: (ex. prescViewer when you click on a calendar day)
//
// Do first three steps above.. and instead of adding a saveScrollY() for each postback control..do:
//
// in the query string send: onClick="javascript:this.href=this.href+'&scr='+document.body.scrollTop;" OR 
// if it has to be done in the back end
//		then add onClick="javascript:saveScrollY();" to ctrl and then get it from scrollY.value.
// 
// Then in the page get scr value and set it to scrollY:
//		strQueryVars = Request.QueryString.GetValues("scr"); //s=scroll
//			if (strQueryVars != null)
//				scrollY.Value = strQueryVars[0].ToString();
//

var scrollCookieName = '';

function getPageScrollY()
{
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;
}

function saveScrollY()
{
	var scrollY = getScrollElem();//document.getElementById("scrollY");
	var pageScroll = getPageScrollY();
			    
	if (scrollY != null)
		scrollY.value = pageScroll;
	
	//alert(scrollCookieName+'='+pageScroll);
	if (scrollCookieName != '')
	    createCookie(scrollCookieName, pageScroll, 1/48);
   
	return true;
}

function setScroll()
{
    
    var scrollY = getScrollElem();//document.getElementById("scrollY");
	if (scrollY != null && scrollY.value != "null" )
	{
	    //alert('setScroll');
	    window.scroll(0, scrollY.value);
		scrollY.value = "null";	
	}
    
    
}

function getScrollElem()
{
    if(null != document.forms[0])
        for(i=0;i<document.forms[0].elements.length;i++)
            if(document.forms[0].elements[i].name.indexOf("scrollY")>-1)
                return document.forms[0].elements[i];
    return null;
}

function setToTop()
{
	window.scrollTo(0,0);
}

function setScrollToObject(targetObjID)
{
    // Make sure you can view the animation
    var aeTargetY = getAbsoluteTop(targetObjID);
    var pageScroll = getPageScrollY();
    var height = (typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight);
   
    if (aeTargetY < pageScroll)
    {
        aeTargetY -= 300;
        if (aeTargetY < 0)
            aeTargetY = 0;
        window.scrollTo(0, aeTargetY);
       
	    
    }
    else if (aeTargetY > (pageScroll+height))
    {
        aeTargetY -= 400;
        window.scrollTo(0, aeTargetY);
    }
}

//-->
