function MM_openSectorWindow(theURL)
{
	window.open(theURL + '&TID=' + getTimeID(),'','width=600,height=525,resizable=1,status=1');
}

function styleSelected(style)
{
	// 13.04.2005 Emil - return false if we receive a null - bug 3187
	if(!style)
		return false;
	if(style.backgroundColor == "rgb(0,0,136)" || style.backgroundColor == "rgb(0, 0, 136)")
		return true;
	return false;
}

//reworked these scripts to work with a the table instead of a select; old ones are below in comment
function updateSectFromString(secTableName, secStringName)
{
    secs = document.getElementById(secStringName).value.split(";");
    secTable = document.getElementById(secTableName);

    if (isIExplorer())
        while (secTable.rows.length > 0)
        secTable.deleteRow();
    else
        while (secTable.rows.length > 0)
        secTable.deleteRow(0);

    var text;
    var row;
    var cell;
    var i;

    //always have 1 bogus row to keep the width of the table constant
    if (isIExplorer()) {
        row = secTable.insertRow();
        cell = row.insertCell();
    }
    else {
        row = secTable.insertRow(0);
        cell = row.insertCell(0);
    }

    cell.innerHTML = "<div style='overflow : hidden; cursor: default; width: 185px; height: 1px'>&nbsp;</div>";

    for (i = 0; i < secs.length; i++) {
        text = secs[i].substr(0, secs[i].indexOf(':'));
        if (isIExplorer()) {
            row = secTable.insertRow();
            cell = row.insertCell();
        }
        else {
            row = secTable.insertRow(secTable.rows.length);
            cell = row.insertCell(0);
        }

        cell.innerHTML = "<div id='sp' onselectstart='javascript:if(isIExplorer()) event.returnValue=false;' style='text-overflow: ellipsis; overflow : hidden; cursor: default; width: 185px'>" + text + "</div>";
        cell.title = text;
        cell.onclick = selectSect;
        cell.style.backgroundColor = "#ffffff";
        cell.style.color = "#000000";
        cell.noWrap = true;
    }
}

function selectSect()
{
	var	cell = getEventSrcElement();
	var	tableBody;
	var	myspan;
	var	i;
	var	pin;
	
	if (isIExplorer())
	{
		tableBody =	cell.parentElement.parentElement.parentElement;
		myspan = tableBody.parentElement.parentElement;
	}
	else
	{
		cell = cell.parentNode.parentNode;
		tableBody =	cell.parentNode.parentNode.parentNode;
		myspan = tableBody.parentNode;
	}
	
	if (isIExplorer())
	{
		for	(i=0; i<myspan.all.length; i++)
		{
			if(myspan.all[i].tagName.toUpperCase() == "INPUT")
			{
				pin=myspan.all[i];
				break;
			}
		}
	}
	
	if (isIExplorer() && event.shiftKey)
	{
		var	ourcell	= -1;
		for(i=1; i<tableBody.rows.length; i++)
		{
			if(i ==	cell.parentElement.parentElement.sectionRowIndex)
			{
				if(pin.value ==	"")
				{
					cell.style.backgroundColor = "#000088";
					cell.style.color = "#ffffff";
					pin.value =	i;
					return;
				}
				else
				{
					ourcell	= i;
				}
			}
		}
		var	min;
		var	max;
		if (ourcell<pin.value)
		{
			min=ourcell;
			max=pin.value;
		}
		else
		{
			min=pin.value;
			max=ourcell;
		}
		for(i=1; i<tableBody.rows.length; i++)
		{
			if ( min<=i	&& i<=max )
			{
				tableBody.rows[i].cells[0].all.sp.style.backgroundColor	= "#000088";
				tableBody.rows[i].cells[0].all.sp.style.color =	"#ffffff";
			}
			else
			{
				tableBody.rows[i].cells[0].all.sp.style.backgroundColor	= "#ffffff";
				tableBody.rows[i].cells[0].all.sp.style.color =	"#000000";
			}
		}
		
		return;
	}
	
	if (isIExplorer() && event.ctrlKey)
	{
		for(i=1; i<tableBody.rows.length; i++)
		{
			if(i ==	cell.parentElement.parentElement.sectionRowIndex)
			{
				pin.value =	i;
				break;
			}
		}
		
		if(cell.style.backgroundColor != "#000088")
		{
			cell.style.backgroundColor = "#000088";
			cell.style.color = "#ffffff";
		}
		else
		{
			cell.style.backgroundColor = "#ffffff";
			cell.style.color = "#000000";
		}
		
		return;
	}
	
	if (isIExplorer())
	{
		for(i=1; i<tableBody.rows.length; i++)
		{
			if(i ==	cell.parentElement.parentElement.sectionRowIndex)
			{
				cell.style.backgroundColor = "#000088";
				cell.style.color = "#ffffff";
				pin.value =	i;
			}
			else
			{
				tableBody.rows[i].cells[0].all.sp.style.backgroundColor	= "#ffffff";
				tableBody.rows[i].cells[0].all.sp.style.color =	"#000000";
			}
		}
	}
	else
	{
		// 13.04.2005 Emil - set style where it exists - bug 3187
		if(cell.childNodes[0].style)
		{
			if(styleSelected(cell.childNodes[0].style))
			{
				cell.childNodes[0].style.backgroundColor = "#ffffff";
				cell.childNodes[0].style.color = "#000000";
			}
			else
			{
				cell.childNodes[0].style.backgroundColor = "#000088";
				cell.childNodes[0].style.color = "#ffffff";
			}
		}
		else if(styleSelected(cell.style))
		{
			cell.style.backgroundColor = "#ffffff";
			cell.style.color = "#000000";
		}
		else
		{
			cell.style.backgroundColor = "#000088";
			cell.style.color = "#ffffff";
		}
	}
}

function removeSector(secTableName, secStringName) 
{
    secStr = document.forms[0].elements[secStringName];
    secTable = document.getElementById(secTableName);

    if (secStr.value.length == 0) return;

    secs = secStr.value.split(";");
    secStr.value = "";

    var i;

    if (isIExplorer()) {
        for (i = 0; i < secs.length; i++) {
            if (secTable.rows[i + 1].cells[0].all.sp.style.backgroundColor != "#000088") {
                secStr.value += ";" + secs[i];
            }
        }
    }
    else {
        for (i = 0; i < secs.length; i++) {
            if (styleSelected(secTable.rows[i + 1].cells[0].childNodes[0].style)
				|| styleSelected(locTable.rows[i + 1].cells[0].style))
                continue;

            secStr.value += ";" + secs[i];
        }
    }

    //remove ';' before first location
    if (secStr.value.length > 0)
        secStr.value = secStr.value.substr(1);

    updateSectFromString(secTableName, secStringName);
}

function clearSectors(secTableName, secStringName) 
{
	secTable = document.getElementById(secTableName);

	if (isIExplorer())
	    while (secTable.rows.length > 0)
	    secTable.deleteRow();
	else
	    while (secTable.rows.length > 0)
	    secTable.deleteRow(0);

	//always have 1 bogus row to keep the width of the table constant
	var row;
	var cell;

	if (isIExplorer()) {
	    row = secTable.insertRow();
	    cell = row.insertCell();
	}
	else {
	    row = secTable.insertRow(0);
	    cell = row.insertCell(0);
	}

	cell.innerHTML = "<div style='overflow : hidden; cursor: default; width: 185px; height: 1px'>&nbsp;</div>";

	document.getElementById(secStringName).value = "";
}

