
function getElement(id)
{
  if(document.getElementById)
    return document.getElementById(id);
  else if(document.all)
    return document.all[id];
  else
    return null;
}


function getSelectByName(name) {
    var fArray = document.getElementsByTagName('select');
    for(i=0; i<fArray.length; i++) {
         if(fArray[i].name == name) {
            return(fArray[i]);
        }
    }
     return(null);
}


function getAnchorByName(name) {
    var fArray = document.getElementsByTagName('a');
    for(i=0; i<fArray.length; i++) {
         if(fArray[i].name == name) {
            return(fArray[i]);
        }
    }
     return(null);
}
 

function setup_options(caller) {
    if(!caller) return(false);
    if(!caller.options) return(false);
    caller.title = caller.options[caller.selectedIndex].title;
    if(caller.options[0].title) return(true);
    var lenop = caller.length;
    for(var i=0; i<lenop; i++) {
        if(caller.options[i].value == -1) 
            caller.options[i].title = caller.options[i].text;
        else
            caller.options[i].title = caller.options[i].value;
    }
    //caller.options[0].title = "---- Wybierz temat i kliknij na link w naglówku ----";
} 

function mark_snp(caller) {
	thisName = "";
	if(caller) {
		setSnpMainLink(caller);
		thisName = caller.name.slice("select_".length);
	}
	var fArray = document.getElementsByTagName('form');
	var xName;
	for(var i=0; i<fArray.length; i++) {
		xName = fArray[i].name.slice("jumpbox_".length);
		xsName = "snp_" + xName;
		xs = getElement(xsName);
		if(xs) {
			xs.style.borderWidth = 0;
			xs.style.borderColor = "black";
			xs.style.borderStyle = "solid";
			if(xName==thisName) xs.style.borderWidth = "1 0 1 0";
		}
	}
}

function openInOther(caller) {
	var xName = "select_" + caller.name.slice("goButton_".length);
	var x = getElement(xName);
    if(!x) x = getSelectByName(xName);
	if(x.options[x.selectedIndex].value != -1) {
		mw = window.open(x.options[x.selectedIndex].value); 
		mw.focus();
	} 
	else return(false);
}

function setSnpMainLink(caller) {
	var xName = "select_" + caller.name.slice("select_".length);
	var x = getElement(xName);
    if(!x) x = getSelectByName(xName);
	var a1 = getElement("snp_main_link");
	var a2 = getElement("snp_supp_link");
    if(!a1) a1 = getAnchorByName("snp_main_link");
    if(!a2) a2 = getAnchorByName("snp_supp_link");
	if(!a1 || !a2) {return(false); }
 	if(x.options[x.selectedIndex].value != -1) {
		var opTextMain = x.options[x.selectedIndex].text;
		var opValueMain = x.options[x.selectedIndex].value;
		var opTextSupp = "";
		var opValueSupp = "";
		if(opTextMain.charCodeAt(0)==160) {
			opTextSupp = opTextMain;
			opValueSupp = opValueMain;
			for(i=x.selectedIndex; i>0; i--) {
				opTextMain = x.options[i].text;
				opValueMain = x.options[i].value;
				if(opTextMain.charCodeAt(0)!=160) {
					if(opValueMain == -1) {
						opValueMain = "";
						opTextMain = "<font style='{text-decoration:none}'>" + opTextMain + "</font>";
					}
					break;
				}
			}
		}
		a1.href = opValueMain; 
		a1.innerHTML = opTextMain;
		a2.href = opValueSupp; 
		a2.innerHTML = opTextSupp;
	} 
	else return(false);
}

function showInBar(caller) { //disabled
	return(false);
	var xName = "select_" + caller.name.slice("goButton_".length);
	var x = getElement(xName);
    if(!x) x = getSelectByName(xName);
	if(x.options[x.selectedIndex].value != -1) {
		if(windows.status) window.status = x.options[x.selectedIndex].value; 
	} 
	else return(false);
}

function getLinkOnRighClick(caller) { //disabled
	return(false);
	if (event.button=='2') {
		var xName = "select_" + caller.name.slice("goButton_".length);
		var x = getElement(xName);
        if(!x) x = getSelectByName(xName);
		if(x.options[x.selectedIndex].value != -1) {
			copyToClipboard(x.options[x.selectedIndex].value)
			alert("URL copied to clipboard");
		} 
	}
}
