function setrun(what) {
	if(what) {
		document.getElementById('tr_end').style.display = 'none';
		document.getElementById('tr_run').style.display = 'block';
		document.body.style.cursor='wait';
	} else {
		document.getElementById('tr_run').style.display = 'none';
		document.getElementById('tr_end').style.display = 'block';
		document.body.style.cursor='default';
	}
}

function toggle_idn(inputid) {
	var offsettop = document.getElementById(inputid).offsetTop+21;
	var offsetleft = document.getElementById(inputid).offsetLeft;
	document.getElementById('idn').style.top = offsettop+"px";
	document.getElementById('idn').style.left = offsetleft+"px";
	if(document.getElementById('idn').style.display == 'block') {
		document.getElementById('idn').style.display = 'none';
	} else {
		document.getElementById('idn').style.display = 'block';
	}
}

function idna(inputid,char) {
	document.getElementById(inputid).value = document.getElementById(inputid).value + char;
}

function showsub(submenu) {
	document.getElementById(submenu).style.display = (document.getElementById(submenu).style.display == 'none') ? 'block' : 'none';
}

function showallsub(hide) {
	var sub = new Array('net','string','list','mail','web');
	var display = (hide == true) ? 'none' : 'block';
	for(i = 0; i<5;i++) {
		document.getElementById('sub_'+sub[i]).style.display = display;
	}
}

function pretext(obj,blur,lang) {
	var edflt = "\n\n\n           Enter your text here";
	var ddflt = "\n\n\n           Text hier eingeben";
	var dflt = (lang == "de") ? ddflt : edflt;
	if (blur) {
		if(obj.value == "") {
			obj.value = dflt;
		}
	} else {
		if(obj.value == dflt) {
			obj.value = "";
		}
	}
}

function toggletab(myid,tabid) {
    if(document.getElementById(myid).getAttribute('className') == 'tab_inactive'
        || document.getElementById(myid).getAttribute('class') == 'tab_inactive') {
        document.getElementById(myid).setAttribute('class','tab_active');
        document.getElementById(myid).setAttribute('className','tab_active');
        document.getElementById(tabid).style.display = 'block';
    } else {
        document.getElementById(myid).setAttribute('class','tab_inactive');
        document.getElementById(myid).setAttribute('className','tab_inactive');
        document.getElementById(tabid).style.display = 'none';
    }
}

function activatetab(targetid) {
	document.getElementById('tab_'+targetid).blur();
    if(document.getElementById('tab_'+targetid).getAttribute('className') == 'inf'
        || document.getElementById('tab_'+targetid).getAttribute('class') == 'inf') {
		document.getElementById('tab_'+targetid).setAttribute('class','infact');
		document.getElementById('tab_'+targetid).setAttribute('className','infact');
	} else {
		document.getElementById('tab_'+targetid).setAttribute('class','act');
		document.getElementById('tab_'+targetid).setAttribute('className','act');
	}
	try {
		document.getElementById('cont_'+targetid).style.display = 'block';
	} catch(e) { }
}

function deactivatetab(targetid) {
	if(document.getElementById('tab_'+targetid) == null) {
		return;
	}
    if(document.getElementById('tab_'+targetid).getAttribute('className') == 'infact'
        || document.getElementById('tab_'+targetid).getAttribute('class') == 'infact') {
		document.getElementById('tab_'+targetid).setAttribute('class','inf');
		document.getElementById('tab_'+targetid).setAttribute('className','inf');
	} else {
		document.getElementById('tab_'+targetid).setAttribute('class','inact');
		document.getElementById('tab_'+targetid).setAttribute('className','inact');
	}
	try {
		document.getElementById('cont_'+targetid).style.display = 'none';
	} catch(e) { }
}

function tog_tab(targetid, nohash) {
	nohash = nohash || false;
	var activetab = document.getElementById('activetab').value;
	document.getElementById('activetab').value = targetid;
	deactivateall();
//	deactivatetab(activetab);
	activatetab(targetid);
	try {
		document.getElementById('cont_'+activetab).style.display = 'none';
        document.getElementById('cont_'+targetid).style.display = 'block';
		if(!nohash) {
			document.location.hash = targetid;
		}
	} catch(e) { }
	document.getElementById('defaultfocus').focus();
}

function deactivateall() {
	var emel = getElementsByClassName('infact');
	for(var i=0; i<emel.length; i++) {
		try {
			deactivatetab(emel[i].id.substr(4,emel[i].id.length -4));
		} catch(e) {
		}
	}
	var emel = getElementsByClassName('act');
	for(var i=0; i<emel.length; i++) {
		try {
			deactivatetab(emel[i].id.substr(4,emel[i].id.length -4));
		} catch(e) {
		}
	}
}

function autoset_tab() {
	var phash = document.location.hash;
	if(phash && phash != '' && phash.length > 1) {
		phash = phash.substr(1,phash.length-1);
		if(document.getElementById('tab_'+phash) != null) {
			deactivateall();
			activatetab(phash);
		}
	}
}

function showtab(targetid) {
	document.getElementById('tab_'+targetid).style.display = 'block';
}

function setnum(targetid,num) {
    document.getElementById(targetid).innerHTML = num;
}
function setcol(targetid,col) {
	try {
		document.getElementById(targetid).style.fontWeight = 'bold';
		document.getElementById(targetid).style.color = col;
	} catch(e) { }
}
function change_ssl2(boxobj) {
    document.getElementById('wssl2').style.display = (boxobj.checked) ? 'inline' : 'none';
}

function selectall(masterid) {
	var x = document.getElementById(masterid).childNodes;
	var todo = document.getElementById('checkall').checked;
	try {
		for(i = 0; i<x.length;i++) {
			if(x[i].nodeName == 'SPAN' && x[i].childNodes[0].nodeName == 'INPUT') {
				x[i].childNodes[0].checked = !todo;
			}
		}
	} catch(e) { }
}

function togglebox(boxid) {
    document.getElementById(boxid).checked = document.getElementById(boxid).checked ? false : true;
}

function qs(app,option) {
    var ip = document.getElementById('defaultfocus').value;
	if(app == 'net.traceroute') {
    	top.location.href='net.traceroute?ip='+ip+'&t='+option+'&p=80';
	}
	if(app == 'net.ping') {
		var port = (option == 'https') ? '443' : '80';
	    top.location.href='net.ping?ip='+ip+'&t='+option+'&p='+port;
	}
	if(app == 'net.whois') {
    	top.location.href='net.whois?ip='+ip+'&t='+option;
	}
	if(app == 'net.tcp') {
    	top.location.href='net.tcp?ip='+ip+'&p='+option+'&n=4';
	}
	if(app == 'string.ip') {
	    top.location.href='string.ip?ip='+ip;
	}
}

/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

function addidn(inputField,inserthere) {
	var addTest = '<div><a id="idnbutton" href="javascript:toggle_idn(\''+inputField+'\');"><img src="http://clez.net/img/button_idn.png" style="width:22px; height:22px; border:0; float:left" alt="IDN" title=""/></a></div><table id="idn"><tr><td class="nop" colspan="4"><a href="javascript:toggle_idn(\''+inputField+'\');">&raquo; close</a></td>';
	fchar = new Array('&#x00E1;','&#x00E0;','&#x0103;','&#x00E2;','&#x00E5;','&#x00E4;','&#x00E3;','&#x0105;','&#x0101;','&#x00E6;','&#x0107;','&#x0109;',
	'&#x010D;','&#x010B;','&#x00E7;','&#x010F;','&#x0111;','&#x00E9;','&#x00E8;','&#x0115;','&#x00EA;','&#x011B;','&#x00EB;','&#x0117;','&#x0119;','&#x0113;','&#x011F;','&#x011D;',
	'&#x0121;','&#x0123;','&#x0125;','&#x0127;','&#x00ED;','&#x00EC;','&#x012D;','&#x00EE;','&#x00EF;','&#x0129;','&#x012F;','&#x012B;','&#x0131;','&#x0135;','&#x0137;','&#x013A;',
	'&#x013E;','&#x013C;','&#x0142;','&#x0144;','&#x0148;','&#x00F1;','&#x0146;','&#x014B;','&#x00F3;','&#x00F2;','&#x014F;','&#x00F4;','&#x00F6;','&#x0151;','&#x00F5;','&#x00F8;',
	'&#x014D;','&#x0153;','&#x0138;','&#x0155;','&#x0159;','&#x0157;','&#x015B;','&#x015D;','&#x0161;','&#x015F;','&#x0165;','&#x0163;','&#x0167;','&#x00FA;','&#x00F9;','&#x016D;',
	'&#x00FB;','&#x016F;','&#x00FC;','&#x0171;','&#x0169;','&#x0173;','&#x016B;','&#x0175;','&#x00FD;','&#x0177;','&#x00FF;','&#x017A;','&#x017E;','&#x017C;','&#x00F0;','&#x00FE;');
	for(x=0; x<fchar.length; x++) {
		addTest += '<td><a href="javascript:idna(\''+inputField+'\',\''+fchar[x]+'\');">'+fchar[x]+'</a></td>';
		if((x+5)%16==0) {
			addTest += '</tr><!-- '+x+'-->';
			addTest += x==91?'</table>':'<tr>';
		}
	}
	document.getElementById(inserthere).innerHTML = addTest;
}

/*
var MyURI="/css/toolkit.js";
if (window.location.search == "" || window.location.search == "?") {
	var StD=(navigator.appName != "Netscape") ? screen.colorDepth : screen.pixelDepth;
    var StSiWi;
    if (document.documentElement && document.documentElement.clientWidth) {
        StSiWi = document.documentElement.clientWidth + 'x' + document.documentElement.clientHeight;
    } else if (document.body && document.body.clientWidth) {
        StSiWi = document.body.clientWidth + 'x' + document.body.clientHeight;
    } else {
        StSiWi = window.innerWidth + 'x' + window.innerHeight;
	}
	var StImg = MyURI+'?screen='+screen.width+"x"+screen.height+'&win='+StSiWi+'&cdi='+StD;
	document.write('<img style="display:none; height:0; width:0; border:0" src="'+ StImg +'" alt="" />')
}
*/
