function showHideDiv(id)
{
    //safe function to hide an element with a specified id
    if (document.getElementById) { // DOM3 = IE5, NS6
        if(document.getElementById(id).style.display == 'none')
        {
            document.getElementById(id).style.display = 'block';
            return;
        }
        else
        {
            document.getElementById(id).style.display = 'none';
            return;
        }
    }
    else {
        if (document.layers) { // Netscape 4
            if(document.id.display == 'none')
            {
                document.id.display = 'block';
                return;
            }
            else
            {
                document.id.display = 'none';
                return;
            }
        }
        else { // IE 4
            if(document.all.id.style.display == 'none')
            {
                document.all.id.style.display = 'block';
                return;
            }
            else
            {
                document.all.id.style.display = 'none';
                return;
            }
        }
    }
}
function openWindow(URL,name,attributes) 
{	
	popupWin = window.open(URL,name,attributes);
	popupWin.focus();
}
function getLeftPosition(obj)
{
	var curleft = 0;
	
    if(obj.offsetParent)
    {
		while(1) 
        {
			curleft += obj.offsetLeft;
			
			if(!obj.offsetParent)
            	break;
			
			obj = obj.offsetParent;
        }
	}
    else if(obj.x)
	{
		curleft += obj.x;
	}
	
	return curleft;
}

function getTopPosition(obj)
{
	var curtop = 0;
	
	if(obj.offsetParent)
	{
		while(1)
		{
			curtop += obj.offsetTop;
			
			if(!obj.offsetParent)
				break;
				
			obj = obj.offsetParent;
		}
	}
	else if(obj.y)
	{
		curtop += obj.y;
	}
	
	return curtop;
 }

function ajaxGetCall(url, targetDiv, onSuccessFunction, onFailureFunction)
{
	ajaxCall(modifyGetForIE(url), targetDiv, null, onSuccessFunction, onFailureFunction, false);
}

function modifyGetForIE(initialUrl)
{	
	var returnUrl = "" + initialUrl;
	
	if(initialUrl.indexOf("?") >= 0)
		return returnUrl + "&iehack=" + getCurrentTimestamp();
	else
		return returnUrl + "?iehack=" + getCurrentTimestamp();
}

function ajaxPostCall(url, targetDiv, formObject, onSuccessFunction, onFailureFunction)
{
	ajaxCall(url, targetDiv, formObject, onSuccessFunction, onFailureFunction, false);
}

function ajaxCall(url, targetDiv, formObject, onSuccessFunction, onFailureFunction, upload)
{
	var callback = 
	{
		success: function(response) 
		{      
			onSuccessFunction(response.responseText);
		},
		failure: function(response) 
		{	   
			onFailureFunction(response.responseText);
		},
        upload: function(response) 
        {
			onSuccessFunction(response.responseText);
  		}
	}
	
	if(targetDiv != null)
		targetDiv.innerHTML = '<table width=100%><tr><td align=center style=padding-top:15px;><img src="/tr3/images/ajax_loading.gif"><BR/><i>Loading</i></td></tr></table>';
			
	if(formObject == null)
	{
		YAHOO.util.Connect.asyncRequest("GET", url, callback, "");
	}
	else
	{
		YAHOO.util.Connect.setForm(formObject, upload);  //true allows it to support file uploads
		YAHOO.util.Connect.asyncRequest("POST", url, callback);
	}
}

function ajaxUploadCall(url, targetDiv, formObject, onSuccessFunction, onFailureFunction, additionalSuccessArguments)
{
	ajaxCall(url, targetDiv, formObject, onSuccessFunction, onFailureFunction, true);
}

function getCurrentTimestamp()
{
	var currentDateTime = new Date();
	var year = currentDateTime.getFullYear();
	var month = currentDateTime.getMonth() + 1;
	var day = currentDateTime.getDate();	
	var hours = currentDateTime.getHours();
	var minutes = currentDateTime.getMinutes();
	var seconds = currentDateTime.getSeconds();
	
	return "" + year + month + day + hours + minutes + seconds;
}
