var popupFormTop;
var popupFormObject;
var popupFormID = "popupPage";
var popupViewerID = "popupPageViewer";
var popupScrollIncrements = new Array(40, 10, 3, 1);
var popupScrollIncrement = 0;
var popupFormInterval;
var allowPopup = true;
var messageSent = false;

function getObject(which)
{
	var obj;
	if (typeof(which) == "object")
	{
		obj = which;
	} 
	else if (typeof(which) == "string")
	{
		obj = document.getElementById(which);
	} 
	else
	{
		obj = null;
	}
	
	return obj;
}

function gotPopupForm() 
{
	popupFormObject = getObject(popupFormID);

	popupFormTop =  0 - (popupFormObject.offsetHeight + 10);
	popupFormObject.style.top = popupFormTop + "px";

	getObject(popupViewerID).style.height = (popupFormObject.offsetHeight + 10) + "px";
	show(popupViewerID);

	scrollPopupForm();
}

function hideSelectFieldsForPopup(visible_style)
{
	var select_tag_items2 = document.getElementsByTagName('object');
			
    for (var j = 0; j < select_tag_items2.length; j++)
    {
	    select_tag_items2[j].style.visibility = visible_style;
    }
    
    var select_tag_items3 = document.getElementsByTagName('a');

    var cursor_style = 'hand';
    
    if ('hidden' == visible_style)
    {
        cursor_style = 'default';
    }
    
    for (var k = 0; k < select_tag_items3.length; k++)
    {
        if ((null == select_tag_items3[k].getAttribute('ispopuplink')) || (select_tag_items3[k].getAttribute('ispopuplink') == ''))
        {
	        select_tag_items3[k].style.cursor = cursor_style;
	    }
    }
    
	var popupUA = navigator.userAgent.toLowerCase();
	var popupIsIE = ((popupUA.indexOf("msie") != -1) && (popupUA.indexOf("opera") == -1) && (popupUA.indexOf("webtv") == -1));
	
	if(popupIsIE)
	{
		var popupVer = parseFloat(navigator.appVersion); 

		if (popupVer >= 4)
		{
			popupVer = parseFloat(popupUA.substring(popupUA.indexOf('msie ') + 5 ));
        }
        
		if (popupVer < 7)
		{
			var select_tag_items = document.getElementsByTagName('select');
			
			for (var i = 0; i < select_tag_items.length; i++)
			{
				select_tag_items[i].style.visibility = visible_style;
			}
		}
	}
}

function scrollPopupForm()
{
	var distance = 0 - popupFormTop;
	
	if (distance < popupScrollIncrements[popupScrollIncrement] * 3)
	{
		popupScrollIncrement++;
	}
	
	if (popupScrollIncrement >= popupScrollIncrements.length)
	{
	    popupScrollIncrement = popupScrollIncrements.length - 1;
	}
	
	if (popupFormTop < 0)
	{
		popupFormTop += popupScrollIncrements[popupScrollIncrement];

		if (popupFormTop > 0)
		{
		    popupFormTop = 0;
		}
		
		popupFormObject.style.top = popupFormTop + "px";

		popupFormInterval = setTimeout("scrollPopupForm()", 10);
	}
	else
	{
		clearTimeout(popupFormInterval);
		popupScrollIncrement = 0;
	}
}

function cancelHidePopup()
{
	hide(popupViewerID);
	hideSelectFieldsForPopup("visible");
	
	if (messageSent == true)
	{
	    location.href = window.document.URL;
	}
}

function hidePopup()
{
	hide(popupViewerID);
	hideSelectFieldsForPopup("visible");
	
    location.href = window.document.URL;

}

function show(which)
{
	var obj = getObject(which);
	
	if (obj)
	{
	    obj.style.visibility = "inherit";
	}
}

function hide(which)
{
	var obj = getObject(which);
	
	if (obj)
	{
	    obj.style.visibility = "hidden";
	}
}