﻿function setVisibility(ids,visible,isRow)
{
	var i;
	var display;

	if(visible)
	{
		if(isRow)display='';
		else display='block';
	}
	else
		display='none';

	for(i=0;i<ids.length;i++)
	{
		var obj=document.getElementById(ids[i]);
		if(obj!=null)
			obj.style.display=display;
	}
}

function toggleRowWithCheckbox(cbId,rowId){
	setVisibility(Array(rowId),document.getElementById(cbId).checked,true);
}

function elc(linkIds,expandIds,expand,visible)
{
	var i;

	setVisibility(expandIds,visible,true);
	if(expand)document.getElementById(linkIds[0]).src=expandPath;
	else document.getElementById(linkIds[0]).src=collapsePath;
	for(i=0;i<linkIds.length;i++)
		document.getElementById(linkIds[i]).onclick=bindElc(linkIds,expandIds,!expand,!visible);
}
function bindElc(linkIds,expandImgIds,expand,visible)
{
	return function() { elc(linkIds,expandImgIds,expand,visible); }
}

function syncDate(yearInput,monthSelect,daySelect,otherYearInput,otherMonthSelect,otherDaySelect)
{
	var otherIntValue = ((otherYearInput.value/1)*10000)+
						((otherMonthSelect.options[otherMonthSelect.selectedIndex].value/1)*100)+
						(otherDaySelect.options[otherDaySelect.selectedIndex].value/1);

	var intValue = ((yearInput.value/1)*10000)+
					((monthSelect.options[monthSelect.selectedIndex].value/1)*100)+
					(daySelect.options[daySelect.selectedIndex].value/1);

	if (intValue > otherIntValue)
	{
		otherYearInput.value = yearInput.value;
		otherMonthSelect.selectedIndex = monthSelect.selectedIndex;
		otherDaySelect.selectedIndex = daySelect.selectedIndex;
	}
}

function syncDateShort(select,otherSelect)
{
	var otherIntValue = ((otherSelect.value.substring(4,8)/1)*10000)+
						((otherSelect.value.substring(0,2)/1)*100)+
						(otherSelect.value.substring(2,4)/1);

	var intValue = ((select.value.substring(4,8)/1)*10000)+
					((select.value.substring(0,2)/1)*100)+
					(select.value.substring(2,4)/1);
	
	if (intValue > otherIntValue)
		otherSelect.value = select.value;
}

function showWarmFuzzy(cellId,imgId,imgUrl)
{
	if(typeof(Page_IsValid)=='undefined'||Page_IsValid)
	{
		document.getElementById(cellId).style.visibility = 'visible';
		document.images[imgId].src = imgUrl;
	}
}

function lTrim(str) 
{
	while (str.substring(0,1) == ' ')
		str = str.substring(1, str.length);
	return str;
}
function rTrim(str) 
{
	while (str.substring(str.length-1, str.length) == ' ')
		str = str.substring(0, str.length-1);
	return str;
}
function trim(str) { return lTrim(rTrim(str)); }

function findPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
