﻿function openPopupWindow( pUrl )
{
  var popupWindow = window.open( pUrl, '', 'scrollbars=yes,status=yes,resizable=yes,width=600,height=500,left=100,top=100');
  popupWindow.focus();
  return false;
}

function openPopupDatePicker( pControlName )
{
	var popupDatePicker = null;
	settings = 'width=220,height=200,location=no,directories=no,' +
			   'menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,' +
			   'dependent=no';
			   
	popupDatePicker = window.open( "DatePicker.aspx?ControlName=" + pControlName,'DatePicker', settings );
	popupDatePicker.focus();
}

function checkMaxLength( cntl, maxLength )
{
	value = cntl.value;
	if( value.length > maxLength-1 )
	{
		event.returnValue = false;
	}
}

function swapDatabaseDesc(obj)
{
	var desc = ''; 

	if( obj.selectedIndex == 0 )
	{
		desc = '(search prices based on actual consumer reports)'; 
	}
	else
	{
		desc = '(search prices based on actual Medicare reimbursements)';
	}
	document.all['lbDatabaseDesc'].innerHTML = desc;
}
			
function Show( pPopupName, e )
{

    var ie5=document.all&&document.getElementById;
    var ns6=document.getElementById&&!document.all;

    if( ie5 )
    {
        //alert( "IE5+" );
    }
    else if( ns6 )
    {
       //alert( "Netscape or firefox" );
    }
    else
    {
        //alert( "unknown unsupported browser" );
    }

	var posx = 0;
	var posy = 0;
	if (!e)
	{
		alert("Using window.event");
		var e = window.event;
	}

	if (e.clientX || e.clientY) 	
	{
		alert("Using clientXY + scrollLeft");
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	else if (e.pageX || e.pageY)
 	{
		alert("Using pageXY");
		posx = e.pageX;
		posy = e.pageY;
	}
	else
	{
		alert("position unavaiable");
	}
	
	// posx and posy contain the mouse position relative to the document
	// Do something with this information

        //var rightedge = ie5 ? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX;
    //var bottomedge = ie5 ? document.body.clientHeight-event.clientY : window.innerHeight-e.clientY;

    //alert( "rightedge=" + rightedge );
    //alert( "bottomedge=" + bottomedge );
    
    var x = 0;
    var y = 0;
    if( ie5 )
    {
        //x = event.pageX;
        //y = event.pageY;
        x = event.clientX;
        y = event.clientY;
    }
    else
    {
        /* get the mouse position */
        x = e.clientX;
        y = e.clientY;
        //x = event.clientX + document.body.scrollLeft;
        //y = event.clientY + document.body.scrollTop + 35;
    }
    
    var p = document.getElementById( pPopupName );
    p.style.display="block";
    p.style.left = posx;
    p.style.top = posy;
}

function Hide( pPopupName )
{
    var p = document.getElementById( pPopupName );
    p.style.display="none";
}

function $() 
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

