function GetXmlHttpObject() {
	var objXMLHttp = null;
	if (window.XMLHttpRequest) {
		objXMLHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

function UpdateStats(id) {
	xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null) {
		alert('Din browser er forældet!');
		return;
	}
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
			var content = xmlHttp.responseText;
			var singlecontent = content.split("------");
			if(singlecontent[0]) document.getElementById('box1').innerHTML = singlecontent[0];
			if(singlecontent[1]) document.getElementById('box2').innerHTML = singlecontent[1];
			if(singlecontent[2]) document.getElementById('box3').innerHTML = singlecontent[2];
			if(singlecontent[3]) document.getElementById('box4').innerHTML = singlecontent[3];
			//document.getElementById('box5').innerHTML = singlecontent[4];
		}
	};
	xmlHttp.open('POST', '/getstats.php?id=' + id, true);
	xmlHttp.send(null);
	setTimeout(function() {UpdateStats(id)}, 5000);
}

var IE = document.all?true:false;
if(!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var mouseX = 0;
var mouseY = 0;
function getMouseXY(e) {
	if(IE)	{
		mouseX = event.clientX + document.documentElement.scrollLeft;
		mouseY = event.clientY + document.documentElement.scrollTop;
	} else {
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
   if(mouseX < 0){mouseX = 0;}
   if(mouseY < 0){mouseY = 0;}
   return true;
}

function showimage(url) {
	elm = document.getElementById('imageviewer');
	elm.style.display = 'block';
	elm.style.top = mouseY + "px";
	elm.style.left = mouseX + 5 + "px";
	elm.innerHTML = '<img src="' + url + '" class="border" />';
}

function hideimage() {
	elm = document.getElementById('imageviewer');
	elm.style.display = 'none';
}

var IE = document.all?true:false;
if(!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var mouseX = 0;
var mouseY = 0;
function getMouseXY(e) {
	if(IE)	{
		mouseX = event.clientX + document.documentElement.scrollLeft;
		mouseY = event.clientY + document.documentElement.scrollTop;
	} else {
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
if(mouseX < 0){mouseX = 0;}
if(mouseY < 0){mouseY = 0;}
return true;
}

function getXYcoord ( htmlElemObj ) {  // ikke til NS4, men ok i IE4+ og NS6+
    var elm = htmlElemObj;
    var rd = { x:0 ,y:0 };
    do { rd.x += parseInt( elm.offsetLeft );
        rd.y += parseInt( elm.offsetTop );
        elm = elm.offsetParent;
    } while ( elm );
    return rd
}


function showtip(text, id, xcor, ycor, cubepos) {
	
	obj = document.getElementById(id);
	var coordinates = getXYcoord(obj);
	elm = document.getElementById('tip');
	elm.style.top = coordinates.y + ycor + "px";
	elm.style.left = coordinates.x + xcor + "px";
	elm.innerHTML = '<img src="/images/tip.png" style="float:left;margin:3px 5px 5px 0;" alt="" />' + text;
	elm.style.display = 'block';

	if(!isNaN(cubepos)) {
		cube = document.getElementById('tipcube');
		if(cubepos == 1) {
			cube.style.top = coordinates.y + ycor - 4 + "px";
			cube.style.left = coordinates.x + xcor + 10 + "px";
		} else if(cubepos == 2) {
			cube.style.top = coordinates.y + ycor + 10 + "px";
			cube.style.left = coordinates.x + xcor + elm.offsetWidth - 3 + "px";
		} else if(cubepos == 3) {
			cube.style.top = coordinates.y + ycor + elm.offsetHeight - 3 + "px";
			cube.style.left = coordinates.x + xcor + 10 + "px";
		} else if(cubepos == 4) {
			cube.style.top = coordinates.y + ycor + 10 + "px";
			cube.style.left = coordinates.x + xcor - 4 + "px";
		}
		cube.style.display = 'block';
	}
}

function hidetip() {
	elm = document.getElementById('tip');
	elm.style.display = 'none';
	
	cube = document.getElementById('tipcube');
	cube.style.display = 'none';
}


function showscreen(url) {
	elm = document.getElementById('screenshotviewer');
	elm.style.display = 'block';
	elm.style.top = mouseY - 125 + "px";
	elm.style.left = mouseX + 5 + "px";
	elm.innerHTML = '<img src="'+ url + '?width=190" class="border" />';
}

function hidescreen() {
	elm = document.getElementById('screenshotviewer');
	elm.style.display = 'none';
}

function popupimage(image) {
	window.open('http://www.livecounter.dk/popupimage.php?' + image, '', 'resizable=1, HEIGHT=550, WIDTH=750');
}

function checkform(fieldsarray) {
	var warnings = new Array();
    var fields = fieldsarray.split(';');
    for(x = 0; x < fields.length; x++) {
		var field = fields[x].split('-');
		var obj = document.getElementById(field[0]);
		if(obj.value.length == 0) {
			warnings[warnings.length] = fields[x];
			obj.className += (obj.className.indexOf('fieldbgwarning') == -1) ? ' fieldbgwarning' : '';
		} else {
			obj.className = obj.className.replace('fieldbgwarning', '');
		}
    }
	if(warnings.length == 0) {
		return true;
	} else {
		var warning = 'Du mangler at udfylde følgende felter:';
		for(x = 0; x < warnings.length; x++) {
			var field = warnings[x].split('-');
			warning += "\n- " + field[1];
		}
		alert(warning);
		return false;
	}
}

function newcaptcha() {
	document.getElementById('captchaimg').src = '/captcha.php?' + Math.random();	
}
function osSwitchTime(counterid) {
	location.href = '/viewvisitors/' + counterid + '/1/' + document.getElementById('osWeek').value + '/';
}
function browserSwitchTime(counterid) {
	location.href = '/viewvisitors/' + counterid + '/2/' + document.getElementById('browserWeek').value + '/';
}
function countrySwitchTime(counterid) {
	location.href = '/viewvisitors/' + counterid + '/3/' + document.getElementById('countryWeek').value + '/';
}
function checkdomain() {
	window.open(document.getElementById('form').action + document.getElementById('homepage').value)
}

function toggleextra(itemid, selfid, opentext, closetext) {
	var itemid = document.getElementById(itemid);
	var selfid = document.getElementById(selfid);
	if(itemid.style.display == 'block') {
		itemid.style.display = 'none';
		selfid.innerHTML = opentext;
	} else {
		itemid.style.display = 'block';
		selfid.innerHTML = closetext;
	}
}
function ajax(url) {
	xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null) return false;
	xmlHttp.open('GET', url, false);
	xmlHttp.send(null);
	return xmlHttp.responseText;
}
