<!--

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

var HOST = 'www.tennis-hosemann.at';

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "/") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "/") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    setCookie('mtcmtauth', f.author.value, now, '', HOST, '');
    setCookie('mtcmtmail', f.email.value, now, '', HOST, '');
    setCookie('mtcmthome', f.url.value, now, '', HOST, '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '', HOST);
    deleteCookie('mtcmthome', '', HOST);
    deleteCookie('mtcmtauth', '', HOST);
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}

function externalLinks() { 
	 if (!document.getElementsByTagName) return; 
	 var anchors = document.getElementsByTagName("a"); 
	 for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
		anchor.target = "_blank"; 
	 } 
} 

function emailCloak() {
		if (document.getElementById) {
			var alltags = document.all? document.all : document.getElementsByTagName("*");
			for (i=0; i < alltags.length; i++) {
			  if (alltags[i].className == "email") {
			  	var oldText = alltags[i].firstChild;
			  	var emailAddress = alltags[i].firstChild.nodeValue;
			  	var user = emailAddress.substring(0, emailAddress.indexOf("("));
			  	var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
			  	var newText = user+"@"+website;
			  	var a = document.createElement("a");
			  	a.href = "mailto:"+newText;
				var address = document.createTextNode(newText);
				a.appendChild(address);
				alltags[i].replaceChild(a,oldText);
			  }
			}
		}
	}
	
function popup(url,breite,hoehe)
{
	var url;
	var width=breite + 66;
	var height=hoehe + 105;
	var l = (screen.availWidth - width) / 2;
	var t = (screen.availHeight - height) / 2;
	nw = window.open(url,"","width="+width+",height="+height+",screenX="+l+",screenY="+t+",left=" +l+",top="+t+",scrollbars=0,resizable=0,menubar=no");
	var nwb = nw.document;
	nwb.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
	nwb.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="de">');
	nwb.write('<head>');
	nwb.write('<title>Tennis Hosemann &amp; Parkclub Neunkirchen &raquo; Bild</title>');
	nwb.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
	nwb.write('<link rel="stylesheet" type="text/css" href="/css/js.css" />');
	nwb.write('</head>');
	nwb.write('<body onblur="javascript:window.close();">');
	nwb.write('<div id="content">');
	nwb.write('<h1>Vergr&ouml;&szlig;erte Ansicht</h1>');
	nwb.write('<div><a href="javascript:window.close();" title="Fenster schlie&szlig;en"><img src="'+url+'" alt="" /></a></div>');
	nwb.write('<p><a href="javascript:window.close();" title="Fenster schlie&szlig;en">Fenster schlie&szlig;en</a></p>');
	nwb.write('</div>');
	nwb.write('</body>');
	nwb.write('</html>');
	nw.focus();
	nwb.close();
}	

function reloadName() {
	var newName = document.getElementById('name').value;
	var nameElement = document.getElementById('pname');
	if ((newName.length==0) ||(newName==null)) {
		nameElement.innerHTML = 'Autor';
	} else {
		nameElement.innerHTML = newName; 
	}
}

function backCheck() {
	var valid = 1;
	form = document.getElementById("commentform");
	namePlace = document.getElementById("name");
	email = document.getElementById("email");
	website = document.getElementById("web");
	message = document.getElementById("message");
	errorField = document.getElementById("achtung");
	if (namePlace.value == "") {
		document.getElementById("lname").className = "error";
		errorField.style.display = "block";
		valid = 0;
	}
	if (email.value == "") {
		document.getElementById("lemail").className = "error";
		errorField.style.display = "block";
		valid = 0;
	}
	if (message.value == "") {
		document.getElementById("lmessage").className = "error";
		errorField.style.display = "block";
		valid = 0;
	}
	
	if (namePlace.value != "") {document.getElementById("lname").className = "";}
	if (email.value != "") {document.getElementById("lemail").className = "";}
	if (message.value != "") {document.getElementById("lmessage").className = "";}
	if (valid == 0) {return false;}
	return true;
}

window.onload = function() {
	externalLinks();
	emailCloak();
}

var searchFieldId = 'message'; 
var resultFieldId = 'pcont';
var processURI    = '/adm/lib/livepreview.php';
var emptyString   = '<p>Beitrag</p>';
var liveReq = false;
var t = null;
var liveReqLast = "";
var isIE = false;

if (window.XMLHttpRequest) {
	liveReq = new XMLHttpRequest();
}

function liveReqInit() {
	
	var checkSearchField = document.getElementById(searchFieldId);
	if(checkSearchField) {
	
		if (navigator.userAgent.indexOf("Safari") > 0) {
			document.getElementById(searchFieldId).addEventListener("keydown",liveReqStart,false);
			
		} else if (navigator.product == "Gecko") {
			document.getElementById(searchFieldId).addEventListener("keypress",liveReqStart,false);
			
		} else {
			document.getElementById(searchFieldId).attachEvent('onkeydown',liveReqStart);
			isIE = true;
		}
	}
	
	if(resultFieldId == '') {
		// if a result field isn't on the page, this will sneak one in...
		resultFieldId = "liveRequestResults";
		displayArea = document.createElement('div');
		displayArea.id = "liveRequestResults";
		document.getElementsByTagName('body')[0].appendChild(displayArea);		
	}
	
	var checkResultFieldId = document.getElementById(resultFieldId);
	if(checkResultFieldId) {
	
		if(emptyString == '') {
			document.getElementById(resultFieldId).style.display = "none";
		} else {
			document.getElementById(resultFieldId).innerHTML = emptyString;
		}
	}
}

addLoadEvent(liveReqInit);

function liveReqStart() {
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("liveReqDoReq()",400);
}

function liveReqDoReq() {
	if (liveReqLast != document.getElementById(searchFieldId).value && document.getElementById(searchFieldId).value != "") {
		if (liveReq && liveReq.readyState < 4) {
			liveReq.abort();
		}
		if (window.XMLHttpRequest) {
		} else if (window.ActiveXObject) {
			liveReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		liveReq.onreadystatechange = liveReqProcessReqChange;
		liveReq.open("GET", processURI + "?s=" + escape(document.getElementById(searchFieldId).value));
		liveReqLast = document.getElementById(searchFieldId).value;
		liveReq.send(null);
	} else if(document.getElementById(searchFieldId).value == "") {
		if(emptyString == '') {
			document.getElementById(resultFieldId).innerHTML = '';
			document.getElementById(resultFieldId).style.display = "none";
		} else {
			document.getElementById(resultFieldId).innerHTML = emptyString;
		}
	}
}

function liveReqProcessReqChange() {
	if (liveReq.readyState == 4) {
		document.getElementById(resultFieldId).innerHTML = liveReq.responseText;
		if(emptyString == '') {
			document.getElementById(resultFieldId).style.display = "block";
		}
	}
}

//-->
