var closeTimeout = null;

function Offshore_OpenInfoDiv(tr){
if (closeTimeout != null) clearTimeout(closeTimeout);

var offshoreInfoDiv = document.getElementById("offshoreInfoDiv");

offshoreInfoDiv.innerHTML = tr.childNodes[3].innerHTML;
tr.childNodes[0].style.color = 'white';

offshoreInfoDiv.style.display = "";

offshoreInfoDiv.style.top = FindTopEdge(tr, true) + 48 - scrollDiv._scrollTop;
offshoreInfoDiv.style.left = FindLeftEdge(tr, true);
offshoreInfoDiv.style.width = tr.clientWidth;
offshoreInfoDiv.style.zIndex = 10000;
}

function Offshore_CloseInfoDiv(tr){
closeTimeout = setTimeout("Offshore_DoCloseInfoDiv()", 50);
tr.childNodes[0].style.color = '#FF6600';
}

function Offshore_DoCloseInfoDiv(){
var offshoreInfoDiv = document.getElementById("offshoreInfoDiv");
if (offshoreInfoDiv != null) offshoreInfoDiv.style.display = "none";
closeTimeout = null;
}

function LinkOver(){
event.cancelBubble = true;
return false;
}

var tabOffshore = null;
var currentSort = 2;
function SortOffShoreSociete() {
if (tabOffshore == null) FillTabOffshore();
if (currentSort == 0) { tabOffshore = tabOffshore.sort(SocieteSortDec); currentSort = 4; }
else {tabOffshore = tabOffshore.sort(SocieteSort); currentSort = 0;}
ReconstructTable();
document.getElementById("OffShoreSoc").className = "HeaderSelected";
document.getElementById("OffShorePays").className = "Header";
document.getElementById("OffShorePos").className = "Header";
}

function SortOffShorePays() {
if (tabOffshore == null) FillTabOffshore();
if (currentSort == 1) { tabOffshore = tabOffshore.sort(CountrySortDec); currentSort = 5; }
else { tabOffshore = tabOffshore.sort(CountrySort); currentSort = 1; }
ReconstructTable();
document.getElementById("OffShoreSoc").className = "Header";
document.getElementById("OffShorePays").className = "HeaderSelected";
document.getElementById("OffShorePos").className = "Header";
}

function SortOffShorePositions() {
if (tabOffshore == null) FillTabOffshore();
if (currentSort == 2) { tabOffshore = tabOffshore.sort(PositionsSortDec); currentSort = 6;}
else { tabOffshore = tabOffshore.sort(PositionsSort); currentSort = 2;}
ReconstructTable();
document.getElementById("OffShoreSoc").className = "Header";
document.getElementById("OffShorePays").className = "Header";
document.getElementById("OffShorePos").className = "HeaderSelected";
}

function FillTabOffshore()
{
var tb = document.getElementById("List_OffShore");
tabOffshore = new Array();
for (var i = 0; i < tb.rows.length; i++)
{
	var o = new Object();
	o.Name = tb.rows[i].cells[0].innerHTML;
	o.Country = tb.rows[i].cells[1].innerHTML;
	o.Position = tb.rows[i].cells[2].innerHTML;
	o.Popup = tb.rows[i].cells[3].innerHTML;
	if ((typeof(tb.rows[i].cells[4]) != "undefined") && (tb.rows[i].cells[4] != null))
		o.Link = tb.rows[i].cells[4].innerHTML;
	else
		o.Link = null;
	
	tabOffshore.push(o);
}
}

function ReconstructTable() {
var tb = document.getElementById("List_OffShore");
for (var i = tb.rows.length - 1; i >= 0; i--) {
tb.deleteRow(i);
}

for (var i = 0; i < tabOffshore.length; i++) {
	var tr = tb.insertRow(-1);
	tr.style.cursor = "pointer"; 
	tr.onmouseover = function() { Offshore_OpenInfoDiv(this); }
	tr.onmouseout = function() { Offshore_CloseInfoDiv(this); }
	var td = tr.insertCell(-1); 
	td.className = "name"; td.vAlign = "top"; td.innerHTML = tabOffshore[i].Name; td.noWrap = true;
	var td = tr.insertCell(-1); 
	td.className = "country"; td.noWrap = true; td.innerHTML = tabOffshore[i].Country;
	var td = tr.insertCell(-1);
	td.className = "position"; td.innerHTML = tabOffshore[i].Position;
	var td = tr.insertCell(-1); td.style.display = "none";
	td.innerHTML = tabOffshore[i].Popup;
	if (tabOffshore[i].Link != null) {
		var td = tr.insertCell(-1); 
		td.innerHTML = "<a onmouseover='LinkOver()' target=_blank href='http://" + tabOffshore[i].Link + "'>" + tabOffshore[i].Link + "</a>";
	}
}

if (typeof(scrollDiv) != "undefined") scrollDiv.RefreshSize();

}

function SocieteSort(a, b){
if (a.Name < b.Name) return -1;
else if (a.Name > b.Name) return 1;
else return 0;
}

function SocieteSortDec(a, b){
if (a.Name < b.Name) return 1;
else if (a.Name > b.Name) return -1;
else return 0;
}

function CountrySort(a, b){
if (a.Country < b.Country) return -1;
else if (a.Country > b.Country) return 1;
else return 0;
}

function CountrySortDec(a, b){
if (a.Country < b.Country) return 1;
else if (a.Country > b.Country) return -1;
else return 0;
}

function PositionsSort(a, b) {
var p1 = parseInt(a.Position, 10);
var p2 = parseInt(b.Position, 10);
if (p1 < p2) return 1;
else if (p1 > p2) return -1;
else return 0;
}

function PositionsSortDec(a, b) {
var p1 = parseInt(a.Position, 10);
var p2 = parseInt(b.Position, 10);
if (p1 < p2) return -1;
else if (p1 > p2) return 1;
else return 0;
}