var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 270;	// maximum image size.
var mousey = 0;
var ycoord = 0;
var xcoord = 0;
var countit = 0;
var docwidth = 0;

if (document.getElementById || document.all){
	document.write('<style type="text/css"><!-- #trailimageid {font-size: 0.75em; position: absolute; display: none; left: 0px; top: 0px; z-index: 200; background-color: lightyellow; padding: 5px; border: 1px dashed gray; color: black; text-decoration: none; } --></style>');
	document.write('<div id="trailimageid">');
	document.write('</div>');
}

function gettrailobj(){
	if (document.getElementById)
		return document.getElementById("trailimageid").style
	else if (document.all)
		return document.all.trailimagid.style
}

function gettrailobjnostyle(){
	if (document.getElementById)
		return document.getElementById("trailimageid")
	else if (document.all)
		return document.all.trailimagid
}


function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail(imagename,description,height){
	if (height > 0){
		currentimageheight = height;
	}
	document.onmousemove=followmouse;
	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;">';
	newHTML = newHTML + '<img src="' + imagename + '" border="0"></div>';
	newHTML = newHTML + description + '<br/>';
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}

function winSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [ myWidth, myHeight ];
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function showIFRAMEtrail(imagename,width,height){
	countit = 0;
	var my = winSize();
	var scrOf = getScrollXY();
	docwidth = scrOf[0]+my[0];
	docheigth = scrOf[1]+my[1];
	xcoord = (docwidth - width) / 2;
	ycoord = (docheigth - height + scrOf[1]) / 2;
	document.onmousemove = getMouseY;
	document.onmousedown = getMouseY;
	document.onmouseup = getMouseY;
	document.onclick = getMouseY;
	document.ondblclick = getMouseY;
	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<div align="center" style="padding: 6px 0px 0px 0px;">';
	newHTML = newHTML + '<iframe id="popupwindow" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" width="' + width + '" height="' + height + '" src="' + imagename + '"></iframe></div>';
	newHTML = newHTML + '<center><form><input type="button" value="Fenster Schliessen" onClick="hidetrail(); return false;" style="font-size:12px; width:130px; font-family:Arial, Helvetica, sans-serif; height:20px; background:#CCCCCC; border:double; font-weight:bold"></form></center>';
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}

function showIFRAMEtrail2(imagename,width,height){
	countit = 0;
	var my = winSize();
	var scrOf = getScrollXY();
	docwidth = scrOf[0]+my[0];
	docheigth = scrOf[1]+my[1];
	xcoord = (docwidth - width) / 2;
	ycoord = (docheigth - height + scrOf[1]) / 2;
	document.onmousemove = getMouseY;
	document.onmousedown = getMouseY;
	document.onmouseup = getMouseY;
	document.onclick = getMouseY;
	document.ondblclick = getMouseY;
	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<div align="center" style="padding: 6px 0px 0px 0px;">';
	newHTML = newHTML + '<iframe id="popupwindow" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" width="' + width + '" height="' + height + '" src="' + imagename + '"></iframe></div>';
	newHTML = newHTML + '<center><form><input type="button" value="Ich Akzeptiere" onClick="hidetrail(); return false;" style="font-size:12px; width:130px; font-family:Arial, Helvetica, sans-serif; height:20px; background:#CCCCCC; border:double; font-weight:bold"></form></center>';
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}

function showIFRAMEtrail3(imagename,width,height){
	countit = 0;
	var my = winSize();
	var scrOf = getScrollXY();
	docwidth = scrOf[0]+my[0];
	docheigth = scrOf[1]+my[1];
	xcoord = (docwidth - width) / 2;
	ycoord = (docheigth - height + scrOf[1]) / 2;
	document.onmousemove = getMouseY;
	document.onmousedown = getMouseY;
	document.onmouseup = getMouseY;
	document.onclick = getMouseY;
	document.ondblclick = getMouseY;
	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<div align="center" style="padding: 6px 0px 0px 0px;">';
	newHTML = newHTML + '<iframe id="popupwindow" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" width="' + width + '" height="' + height + '" src="' + imagename + '"></iframe></div>';
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}

function getMouseY(e) { // works on IE6,FF,Moz,Opera7
//	if (countit != 1) {
//		if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
//		if (e) { 
//			if (e.pageY) { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
//				mousey = e.pageY;
//			} else if (e.clientY) { // works on IE6,FF,Moz,Opera7
//				mousey = e.clientY + document.body.scrollTop;
//			} 
//		}
//		countit = 1;
//		ycoord = mousey-30;
//	}
	gettrailobj().left=xcoord+"px";
	gettrailobj().top=ycoord+"px";
	document.onmousemove="";
	document.onmousedown="";
	document.onmouseup="";
	document.onclick="";
	document.ondblclick="";
}

function hidetrail(){
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none";
	document.onmousemove="";
	gettrailobj().left="-800px";
}

function followmouse(e){
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}
	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 380){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

function tell_report(a, bfm_url) {
	info_x = document.getElementById('the_info');
	// AJAX stuff
	getAJAX = getHTTPObject();
	if (getAJAX.readyState == 4 || getAJAX.readyState == 0) {
		getAJAX.open("GET",bfm_url + "/chkaval.php?foldername=" + a , true);
		getAJAX.onreadystatechange = function () {
			if (getAJAX.readyState == 4){
				document.getElementById("the_info").style.display="block";
				info_x.innerHTML = getAJAX.responseText;
			}
		}
		getAJAX.send(null);
	}
}

function chkavailability(bfm_url) {
	var a ;
	var all_ele;
	all_ele = document.myform;
	a = all_ele.foldername.value;
	//more onLoad stuff
	tell_report(a, bfm_url);
	//var getAJAX;
	//getAJAX = getHTTPObject();
}

//initiates the XMLHttpRequest object
function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	@else
	xmlhttp = false;
	@end @*/

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} 
		catch (e) {
			xmlhttp = false;
		}
	}	
	return xmlhttp;
}
