var iRecordCount = 0;
var iPageSize = 0;
var iPageCount = 0;
var iPage = 0;

function fValidateRiddle() {
	var oForm = document.forms["frm"]
	var bError = false;
	if (oForm.elements["q1"].value == "") bError = true;
	if (oForm.elements["q2"].value == "") bError = true;
	if (oForm.elements["q3"].value == "") bError = true;
	if (oForm.elements["age"].value == "") bError = true;
	if (oForm.elements["sex"].selectedIndex == 0) bError = true;
	if (oForm.elements["email"].value == "") bError = true;
	if (bError) {
		alert("Bitte vervollständigen Sie Ihre Angaben.");
	}
	else {
		oForm.submit();
	}
}

function fValidateRegistration() {
	var oForm = document.forms["frm"]
	var bError = false;
	if (oForm.elements["name"].value == "") bError = true;
	if (oForm.elements["organization"].value == "") bError = true;
	if (oForm.elements["email"].value == "") bError = true;
	if (bError) {
		alert("Bitte vervollständigen Sie Ihre Angaben.");
	}
	else {
		oForm.submit();
	}
}

function fInit() {
	//check
	if (!iRecordCount && !iPageSize && !iPageCount && !iPage) {
		return;
	}
	if (iPageCount == 1 || iRecordCount == 0) {
		return;
	}
	
	//get pager objects
	var oPager = document.getElementsByName("oPager");
	var oMovePrevious = document.getElementsByName("oMovePrevious");
	var oMoveNext = document.getElementsByName("oMoveNext");
	var oPage = document.getElementsByName("oPage");
	var oPageSize = document.getElementsByName("oPageSize");
	
	if (!iPageCount) iPageCount = 1;
	
	//update oMovePrevious
	for (var i=0; i<oMovePrevious.length; i++) {
		if (iPage == 1) {
			//oMovePrevious[i].href = "#";
			oMovePrevious[i].style.color = "#999999";
		}
		else {
			oMovePrevious[i].href = fBuildURL(location,Array("page")) + "page=" + (iPage-1);
		}
	}
	
	//update oMoveNext
	for (var i=0; i<oMoveNext.length; i++) {
		if (iPage == iPageCount) {
			//oMoveNext[i].href = "#";
			oMoveNext[i].style.color = "#999999";
		}
		else {
			oMoveNext[i].href = fBuildURL(location,Array("page")) + "page=" + (iPage+1);
		}
	}
	
	//update oPage
	for (var i=0; i<oPage.length; i++) {
		for (var ii=1; ii<=iPageCount; ii++) {
			oPage[i].options[oPage[i].length] = new Option(ii);
			oPage[i].options[oPage[i].length-1].value = ii;
		}
		for (var ii=oPage[i].length-1; ii>=0; ii--) {
			if (oPage[i].options[ii].value == iPage) oPage[i].options[ii].selected = true;
		}
	}
	
	//update oPageSize
	for (var i=0; i<oPageSize.length; i++) {
		for (var ii=5;ii<=90;ii+=5) {
			if (ii >= iRecordCount) break;
			oPageSize[i].options[oPageSize[i].length] = new Option(ii);
			oPageSize[i].options[oPageSize[i].length-1].value = ii;
		}
		for (var ii=100;ii<=1000;ii+=100) {
			if (ii >= iRecordCount) break;
			oPageSize[i].options[oPageSize[i].length] = new Option(ii);
			oPageSize[i].options[oPageSize[i].length-1].value = ii;
		}
		oPageSize[i].options[oPageSize[i].length] = new Option("alle");
		oPageSize[i].options[oPageSize[i].length-1].value = iRecordCount;
		for (var ii=oPageSize[i].length-1;ii>=0;ii--) {
			if (oPageSize[i].options[ii].value == iPageSize) oPageSize[i].options[ii].selected = true;
		}
	}
	
	//show oPager
	for (var i=0; i<oPager.length; i++) {
		oPager[i].style.display = "inline";
	}
}

function fChangePageSize(obj) {
	location.href = fBuildURL(location,Array("pagesize","page")) + "pagesize=" + obj.value + "&page=1";
}

function fChangePage(obj) {
	location.href = fBuildURL(location,Array("page")) + "page=" + obj.value;
}

function fPopUp(url,intID) {
	win1 = open(url + "?id=" + intID,"win1","height=250,width=350,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1");
	win1.focus();
}

function fPopUpSize(url,intID,intHeight,intWidth) {
	win1 = open(url + "?id=" + intID,"win1","height=" + intHeight + ",width=" + intWidth + ",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1");
	win1.focus();
}

function fPopUpDia(url,intHeight,intWidth) {
	win1 = open(url,"win1","height=" + intHeight + ",width=" + intWidth + ",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1");
	win1.focus();
}


function fResizePopUp() {
	var blnNS = (navigator.appName == "Netscape") ? true : false;
	var iWidth = (blnNS) ? window.innerWidth : document.body.clientWidth;
	var iHeight = (blnNS) ? window.innerHeight : document.body.clientHeight;
	window.resizeTo(iWidth, iHeight);
	self.focus();
}

function fBuildURL(oLocation,aExclude) {
	var sURL = oLocation.protocol + "//" +
			   oLocation.hostname +
			   oLocation.pathname + "?";
	var sSearch = "";
	if (oLocation.search != "") {
		var aSearch = oLocation.search.substring(1,oLocation.search.length).split("&");
		for (i=0;i<aSearch.length;i++) {
			var bExclude = false;
			var aParam = aSearch[i].split("=");
			for (ii=0;ii<aExclude.length;ii++) {
				if (aParam[0] == aExclude[ii]) bExclude = true;
			}
			//if (!bExclude) sSearch += aParam[0] + "=" + escape(aParam[1]) + "&";
			if (!bExclude) sSearch += aParam[0] + "=" + escape(unescape(aParam[1])) + "&";
		}
	}
	return sURL + sSearch;
}

function fncCheckEmail(strEmail) {
	var objRegEx = /(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})/;
	return objRegEx.test(strEmail);
}

function fMaskEmail(sUser,sDomain,sLable) {
	if (!sLable) sLable = sUser + "@" + sDomain;
	document.write("<a href=\"mailto:" + sUser + "@" + sDomain + "\">" + sLable + "</a>");
}

function doExpandText(paraNum,arrowNum) {
	var obj = document.getElementById(paraNum);
	var img = document.getElementById(arrowNum);
	if (obj.style.display == "none") {
		obj.style.display = "";
		img.src = "/img/arw_down.gif"
	}
	else {
		obj.style.display = "none";
		img.src = "/img/arw_right.gif"
	}
}

function doExpandGraphics(paraNum,arrowNum) {
	var obj = document.getElementById(paraNum);
	var img = document.getElementById(arrowNum);
	if (obj.style.display == "none") {
		obj.style.display = "";
		img.src = "HideGraphics.gif";
		obj.style.bgcolor = "#803680";
	}
	else {
		obj.style.display = "none";
		img.src = "ShowGraphics.gif"
	}
}


function printPage() 
{
	if (window.print) {
	printnow = confirm('Seite drucken ?');
	if (printnow) window.print();
   }
}

function fSendPage() {
	mail_str = "mailto:?subject=Hinweis auf www.elternrat-relli.de";
	mail_str += "&body=Schauen Sie sich diese Seite auf elternrat-rell.de an: " + location.href; 
	location.href = mail_str;
}

function sendpage() {
	var str;
	str = "mailto:?subject= Hinweis auf einen Artikel der Seite www.elternrat.relli.de";
	str += "&body=Schauen Sie sich mal den Artikel auf folgenender Seite an: " + fBuildURL(location,Array());
	location.href = str;
}

function fBookmark() {
	if (document.all) {
		window.external.AddFavorite(location.href,document.title);
	}
	else {
		alert("Zum Ablegen des Lesezeichens drücken Sie 'Strg+Umschalt+G'.");
	}
}

function linkopener(a) {
	var b=a?"_blank":"_self";
	var c=document.links;
		for(var i=0;i<c.length;i++) {if(c[i].href.search("elternrat-relli.de")==-1) c[i].target=b};
}
// Links extern

var mydomain = document.location.host;
var extimagesrc = "/img/ico_extern.gif";
var extimageoversrc = "/img/ico_extern_over.gif";

function isExternLink(host) {
	if (host == "") return false;
	var expr = new RegExp(mydomain, "i");
	if (expr.test(host)) return false;
	return true;
}

function init() {
	var alllinks = document.getElementsByTagName("a");

	for (var i = 0; i < alllinks.length; i++) {
		if (isExternLink(alllinks[i].host)) {
			var extimg = document.createElement("img");
			extimg.src = extimagesrc;
			extimg.width = 12;
			extimg.height = 12;
			extimg.title = "Link in einem neuen Fenster öffnen.";
			if (!document.all) extimg.style.cursor = "pointer";
			extimg.longDesc = alllinks[i].href;
			extimg.onmouseover = function() {
				this.src = extimageoversrc;
			}
			extimg.onmouseout = function() {
				this.src = extimagesrc;
			}
			extimg.onclick = function() {
				window.open(this.longDesc);
			}
			alllinks[i].parentNode.insertBefore(extimg, alllinks[i]);
		}
	}
}


