function confirmthis (jsmsg) { 
	Check = confirm(jsmsg);
	if(Check == false) {
		return false;
	}
}

var openpopupWindow = null;
function openpopup (mypage,myname,w,h,pos,infocus,scrolling,resizable){
	if (openpopupWindow) {
		openpopupWindow.close();
	}
	if(pos=='random'){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=='center'){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	} else if((pos!='center' && pos!='random') || pos==null){
		LeftPosition=100;TopPosition=100;
	}
	settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=' + scrolling + ',resizable=' + resizable + ',dependent=no';
	openpopupWindow = window.open('',myname,settings);
	if(infocus=='front'){
		openpopupWindow.focus();
		openpopupWindow.location=mypage;
	}
	return false;
}

function external_init() {
	var a;
	var f;
	var node;

	if(!document.getElementsByTagName) return;
	
	a = document.getElementsByTagName("a");

	for(i = 0; i < a.length; i++) {
		if(!a[i].getAttribute("href") ||
		   a[i].getAttribute("rel") != "external") continue;
		a[i].target = "_blank";
	}

	f = document.getElementsByTagName("form");

	for(i = 0; i < f.length; i++) {
		if(f[i].className != "external") continue;
		f[i].target = "_blank";
	}
}

function resizeMyDocument() {
	if (screen.width < 1024) {
		document.getElementsByTagName('h1')[0].style.width = '770px';
		document.getElementById('desktop').style.width = '770px';
		document.getElementById('task').style.width = '145px';
		document.getElementById('main').style.width = '460px';
		document.getElementById('teaser').style.width = '145px';
	}
}

function init_all() {
	resizeMyDocument();
	external_init();
	WorldClock();
}

window.onload = init_all;

zone=0;
isitlocal=true;
ampm='';

function updateclock(z){
	zone = z.options[z.selectedIndex].value;
	isitlocal = (z.options[0].selected) ? true : false;
}

function WorldClock(){
	now = new Date();
	ofst = now.getTimezoneOffset() / 60;
	secs = now.getSeconds();
	sec = -1.57 + Math.PI * secs / 30;
	mins = now.getMinutes();
	min = -1.57 + Math.PI * mins / 30;
	hr = (isitlocal) ? now.getHours() : (now.getHours() + parseInt(ofst)) + parseInt(zone);
	hrs = -1.575 + Math.PI * hr / 6 + Math.PI * parseInt(now.getMinutes()) / 360;
	if (hr < 0) hr += 24;
	if (hr > 23) hr -= 24;
	ampm = (hr > 11) ? "PM" : "AM";
	statusampm = ampm.toLowerCase();
	hr2 = hr;
	if (hr2 == 0) hr2 = 12;
	(hr2 < 13) ? hr2 : hr2 %= 12;
	if (hr2 < 10) hr2= "0" + hr2
	var finaltime = hr+'.' + ((mins < 10) ? "0" + mins:mins) + '.' + ((secs < 10) ? "0" +secs : secs);
	if (document.all) {
		worldclock.innerHTML = finaltime;
	} else if (document.getElementById) {
		document.getElementById("worldclock").innerHTML = finaltime;
	} else if (document.layers) {
		document.worldclockns.document.worldclockns2.document.write(finaltime);
		document.worldclockns.document.worldclockns2.document.close();
	}
	setTimeout('WorldClock()',1000);
}

function showMapTooltip(posX, posY, myname, myx, myy, myqm, cName, cId, cStatus) {
	st = new Array();
	st['rented'] = 'Vermietet';
	st['free'] = 'Verf&uuml;gbar';
	st['reserved'] = 'Reserviert';
	posXplus = 15;
	posYplus = 70;
	
	x = "<strong>Raum " + myname + "</strong>";
	if (cStatus != "") {
		x += "<br /><span>Status:</span> <strong class=\"" + cStatus + "\">" + st[cStatus] + "</strong>";
		posYplus += 16;
	}
	x += "<br /><span>Fl&auml;che:</span> " + myqm + " qm (" + myx + " x " + myy + ")";
	if (cId != "") {
		x += "<br /><span>Mieter:</span> <a href=\"microsite.php?client=" + cId + "\" target=\"_blank\">" + cName +"</a>";
		posYplus += 16;
	} else if (cName != "") {
		x += "<br /><span>Mieter:</span> " + cName;
		posYplus += 16;
	}
	document.getElementById('tooltipContent').innerHTML = x;
	posX = posX + posXplus;
	posY = posY - posYplus;
	document.getElementById('tooltip').style.left = posX + 'px';
	document.getElementById('tooltip').style.top = posY + 'px';
	document.getElementById('tooltip').style.display = 'block';
}
