ver = navigator.appVersion;
DOM = document.getElementById ? 1 : 0; 
IE4 = (document.all) ? 1 : 0; 
NS5 = (DOM && parseInt(ver) >= 5) ? 1 : 0; 

var opac=0;
var Img = "slide1";

var fpath='fileadmin/images/slides/';
var d1 = document;
d1.lastSlide = 35;
var freq = 5000;

function FindImage(doc, name, j) {
	var theImage = false;
	if (doc.images) {
		theImage = doc.images[name];
	}
	if (theImage) {
		return theImage;
	}
	if (doc.layers) {
		for (j = 0; j < doc.layers.length; j++) {
			theImage = FindImage(doc.layers[j].document, name, 0);
			if (theImage) {
				return (theImage);
			}
		}
	}
    return 0;
}

function loadImages() {
    if (d1.images) {
		if (!d1.imageList) {
			d1.imageList = new Array();
		}
		var i,j = d1.imageList.length;
		a = loadImages.arguments;
		for (i=0; i<a.length; i++) {
			fnd = 0;
			for (k=0; k < d1.imageList.length; k++) {
				if (d1.imageList[k].src.indexOf(a[i]) > -1) {
					fnd = 1;
				}
			}

			if (fnd == 0) {
				d1.imageList[j]=new Image;
				d1.imageList[j++].src=a[i];
			}
		}
	}
}

function getObj(name) {
	if (document.getElementById) {
		return document.getElementById(name).style;
	} else if (document.all) {
		return document.all[name].style;
	} else if (document.layers) {
		return document.layers[name];
	} else {
		return false;
	}
}


function startSlideShow() {
	loadImages("fileadmin/images/slides/bild_" + d1.curSlide + ".jpg");
	setTimeout("doSlideShow()", freq);
	d1.curSlide++;
	if (d1.curSlide > d1.lastSlide) {
		d1.curSlide = 1;
	}
	return true;
}

function doSlideShow() {
	NewSrc = fpath + "bild_" + d1.curSlide + ".jpg";
	if (d1.images) {
		Img = (Img == "slide1") ? "slide2" : "slide1";
		var theImage = FindImage(d1, Img, 0)
		if (theImage) {
			theImage.src = NewSrc;
		}
	}
	//if (theImage.complete) {
		if (Img == "slide2") {
			opac = 0;
			sTimer = setInterval("doBlend(2)", 50);
		} else {
			opac = 100;
			sTimer = setInterval("doBlend(-2)", 50);
		}
	//}
}

function doBlend(stp) {
	layerObj = getObj("slider");
	layerObj.visibility="visible";
	opac += stp;
	if (IE4) {
		layerObj.filter="alpha(opacity=0)";
		document.all["slider"].filters.alpha.opacity = opac;
	} else if (NS5) {
		layerObj.MozOpacity = 0;
		layerObj.MozOpacity = (opac / 100); // + '%';
	} else {
		if (opac < 50) {
			layerObj.visibility="hidden";
		}
	}
			
	if ((opac < 1) || (opac > 99)) {		
		clearInterval(sTimer);
		startSlideShow();
	}
	return true;
}		

function submitForm(val) {
	if (val == 1) {
		document.searchform.mode.value = "inc";
	} else {
		document.searchform.mode.value = "dec";
	}
	document.searchform.submit();
}

function showEditor(fname, uid) {
	var x = (screen.availWidth - 1000);
	fname = fname + "?uid=" + uid;
	title = "NewsEditor";

	awinh = window.open(fname, title, "width=1000 ,height=740, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1");

	awinh.moveTo(x, 50);
	awinh.resizeTo(1000, 740);
	awinh.focus();

 }

function showNewsTxt(fname) {
	var x = (screen.availWidth - 1000);
	title = "Newstxt";

	awinh = window.open(fname, title, "width=1000, height=740, toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=yes");

	awinh.moveTo(x, 50);
	awinh.resizeTo(1000, 740);
	awinh.opener = this;
	awinh.focus();

}
 
function reloadPage() {
	location.reload();
}

function resetOptions(fo) {
	for (i=0; i<document[fo].elements.length; i++) {
		if (document[fo].elements[i].type == 'radio') {
			document[fo].elements[i].checked = 0;
		}
	}
}

function requestDelete(fo) {
	if (confirm("Sind Sie sicher?")) {
		document[fo].mode.value = "delete";
		document[fo].submit();
	}
	return true;
}

function requestSend(fo) {
	if (confirm("Sind Sie sicher?")) {
		document[fo].mode.value = "invoke";
		document[fo].submit();
	}
	return true;
}

function markLink(lname, tname, cl) {
	//lObj = getObj(lname);
	//lObj.color = cl;
	
	//if (lname != "") {
		//for (i=0; i<document.links.length; i++) {
		//	if (document.links[i].name == lname) {
		//		document.links[i].style.color = cl;
		//		break;
		//	}
		//}
	//}
	if (tname != "") {
		lObj = getObj(tname);
		lObj.borderTop = "1px dashed "+cl;
		lObj.borderBottom = "1px dashed "+cl;
	}
	d.srcOver = lObj;
}

function markNewPos(lname, pos) {
	if (d.lastOver) {
		if (d.lastOver != d.srcOver) {
			d.lastOver.borderTop = "1px solid #FFFFFF";
			d.lastOver.borderBottom = "1px solid #FFFFFF";
			d.lastOver = null;
		}
	}
	if (d.cUid > -1) {
		if (lname) {
			lObj = getObj(lname);
			if (pos < d.lastPos) {
				lObj.borderTop = "1px solid #000000";
			}
			if (pos > d.lastPos) {
				lObj.borderBottom = "1px solid #000000";
			}
			d.lastOver = lObj;
		}
	}
}

// Ajax

function testMail(ctrlid, addr, rHandler, modulePath, typoPath) {
	http.open('GET', 'fileadmin/scripts/rpc.php?func=testMail&modulepath='+modulePath+'&typopath='+typoPath+'&ctrlid='+ctrlid+'&testaddr='+addr, true);
    http.onreadystatechange = rHandler;
    http.send(null);
}

function setNewPosition(opuid, npuid, rHandler, modulePath, typoPath, noSel, doSel, ctrlid, editPID) {
	http.open('GET', 'fileadmin/scripts/rpc.php?func=setPosition&modulepath='+modulePath+'&typopath='+typoPath+'&opuid='+opuid+'&npuid='+npuid+'&nosel='+noSel+'&dosel='+doSel+'&ctrlid='+ctrlid+'&editPID='+editPID, true);
    http.onreadystatechange = rHandler;
    http.send(null);
}

function getNewsList(ctrlid, rHandler, modulePath, typoPath, editPID) {
	http.open('GET', 'fileadmin/scripts/rpc.php?func=getNewsList&modulepath='+modulePath+'&typopath='+typoPath+'&ctrlid='+ctrlid+'&editPID='+editPID, true);
    http.onreadystatechange = rHandler;
    http.send(null);
}

function saveCurSelection(rHandler, modulePath, typoPath, noSel, doSel) {
	http.open('GET', 'fileadmin/scripts/rpc.php?func=saveSelection&modulepath='+modulePath+'&typopath='+typoPath+'&nosel='+noSel+'&dosel='+doSel, true);
    http.onreadystatechange = rHandler;
    http.send(null);
}

function createRequestObject() {
    var ro;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		ro = new XMLHttpRequest();
		//if (ro.overrideMimeType) {
		//	ro.overrideMimeType('text/xml');
		//}
		
	} else if (window.ActiveXObject) { // IE
    	try {
			ro = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				ro = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!ro) {
		alert('Ende :( Kann keine XMLHTTP-Instanz erzeugen');
		return false;
	}
    return ro;
}

var http = createRequestObject();



