// JavaScript Document
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){		
		var pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		var pageWidth = windowWidth;
	} else {
		var pageWidth = xScroll;
	}


	var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}




// Functions to set, get and delete cookies
	// First, to set a cookie - set a 3 month expiry date. Year is handled automatically if the month spills over
	var theDate=new Date();
	var month="";
    	month=theDate.getMonth();
    	month=month+3;
    	theDate.setMonth(month);   // this is all for the cookie expiry
		
	function set_cookie(cookiename,value) {
		document.cookie = cookiename + "=" + value +";expires=" + theDate.toGMTString() +";path=/";
		//alert("Cookie set");
	}

	function get_cookie(cookiename) {
		// document.cookie gives us a list of all the cookies from this domain
		// we need to find just the cookie we are interested in
		// take a substring between "cookiename=" and ";" - this is the value of the cookie
		// this function will return either the value of the cookie, or a null value if it's not there

  		var nameStr = cookiename + "=";
  		var maxLen = document.cookie.length
  		var i = 0
  		while (i < maxLen) {
            var j = i + nameStr.length
            if (document.cookie.substring(i,j) == nameStr) {
                var cookieEnd = document.cookie.indexOf(";",j);
                if (cookieEnd == -1) {
                    cookieEnd = document.cookie.length;
                }
                return unescape(document.cookie.substring(j,cookieEnd));
            }
    		i++
  		}
  		return "";
	}

	// simply erase the cookie by making it expire before now
	function erase_cookie(cookiename) {
		document.cookie = cookiename + "=0;expires=Sun, 26 Mar-2000 12:00:00 GMT;path=/";
		//alert("Cookie erased");
	}

	// do they accept cookies?
	// simply drop a test cookie and try to retrieve it. if it's not there, they don't take cookies
	function check_cookie_accept() {
		set_cookie('testaccept','1');
		var ck=get_cookie('testaccept');
		if (ck==1) {
			//alert('This browser accepts cookies');
			erase_cookie('testaccept');
			return 1;
		}
		else {
			//alert('This browser is not cookie capable');
			return 0;
		}
		// erase it for good measure
		//
	}


// Divs anzeigen
function showDiv($show) {
if (document.getElementById){
	document.getElementById($show).style.display = "block";
	
	if ( $show == "forumlar"){
		if (document.getElementById('formular')	){
			var arrayPageSize = getPageSize;
			document.getElementById('formular').style.height= arrayPageSize[0]+"px";
			document.getElementById('formular').style.height= arrayPageSize[1]+"px";;			
		}
	}
	
	if ( $show =="loginformular"  ){
		if ( document.getElementById('loginform'))
		document.loginform.uname.focus();
	}
	if ( $show =="register"  ){
		if ( document.getElementById('registerform'))
		document.registerform.uname.focus();
	}

}
}
// Divs verstecken
function hideDiv($hide) {
if (document.getElementById) 	
document.getElementById($hide).style.display = "none";
}

// Tabs anzeigen auf der Selektionsseite
function showtab($show){
document.getElementById($show).style.zIndex="9";
document.getElementById($show).style.backgroundColor="#fff";

switch($show){
case "countrybox1":	document.getElementById("countrybox2").style.zIndex='11';
					document.getElementById("countrybox3").style.zIndex="11";
					
					document.getElementById("countrybox2").style.backgroundColor="#ccc";
					document.getElementById("countrybox3").style.backgroundColor="#ccc";
					
					document.getElementById("reiter1").style.display= "block";
					document.getElementById("reiter2").style.display= "none";
					document.getElementById("reiter3").style.display= "none";
					break;
					
case "countrybox2":	document.getElementById("countrybox1").style.zIndex="11";
					document.getElementById("countrybox3").style.zIndex="11";
					
					document.getElementById("countrybox1").style.backgroundColor="#ccc";
					document.getElementById("countrybox3").style.backgroundColor="#ccc";
					
					document.getElementById("reiter2").style.display= "block";
					document.getElementById("reiter1").style.display= "none";
					document.getElementById("reiter3").style.display= "none";
					break;
					
case "countrybox3":	document.getElementById("countrybox1").style.zIndex="11";
					document.getElementById("countrybox2").style.zIndex="11";
					
					document.getElementById("countrybox1").style.backgroundColor="#ccc";
					document.getElementById("countrybox2").style.backgroundColor="#ccc";
					
					document.getElementById("reiter3").style.display= "block";
					document.getElementById("reiter1").style.display= "none";
					document.getElementById("reiter2").style.display= "none";
					break;
}
}

function category_click(){
	document.category.submit();
	
}

function showreg(){
	if ( document.getElementById('reg_con')){		
	if ( document.getElementById('reg_con').style.display == 'block')
		document.getElementById('reg_con').style.display = 'none';
	else
		document.getElementById('reg_con').style.display = 'block';
	}
}

// Funktion zum Hinzufügen von Input Elementen ( Selektion )
function foo(){}

function add($land){
// Div markieren
var div = document.getElementById($land);
var Feld_von = document.createElement("input");
var Feld_bis = document.createElement("input");
var umbruch = document.createElement("br");
var o=1;
var i=0;

if ( $land == "d"){
	
for ( i=1;i<=10;i++){	
	var von = 'plz_vonD'+i;
	
	if (document.getElementsByName(von)[0]){		
		o++;
	}
	else
		break;
}
	
foo.d = ++ foo.d || o;
Feld_von.setAttribute("name","plz_vonD"+foo.d);
Feld_von.setAttribute("value","00000");
Feld_von.setAttribute("maxLength","5");
Feld_von.setAttribute("size","5");



Feld_bis.setAttribute("name","plz_bisD"+foo.d);
Feld_bis.setAttribute("value","99999");
Feld_bis.setAttribute("maxLength","5");
Feld_bis.setAttribute("size","5");
}

if ( $land == "a"){
for ( i=1;i<=10;i++){	
	var von = 'plz_vonA'+i;
	
	if (document.getElementsByName(von)[0]){		
		o++;
	}
	else
		break;
}
	
foo.a = ++ foo.a || o;

Feld_von.setAttribute("name","plz_vonA"+foo.a);
Feld_von.setAttribute("value","0000");
Feld_von.setAttribute("maxLength","4");
Feld_von.setAttribute("size","5");

Feld_bis.setAttribute("name","plz_bisA"+foo.a);
Feld_bis.setAttribute("value","9999");
Feld_bis.setAttribute("maxLength","4")
Feld_bis.setAttribute("size","5");
}

if ( $land == "ch"){
for ( i=1;i<=10;i++){	
	var von = 'plz_vonCH'+i;
	
	if (document.getElementsByName(von)[0]){		
		o++;
	}
	else
		break;
}
	
foo.ch = ++ foo.ch || o;

Feld_von.setAttribute("name","plz_vonCH"+foo.ch);
Feld_von.setAttribute("value","0000");
Feld_von.setAttribute("maxLength","4");
Feld_von.setAttribute("size","5");

Feld_bis.setAttribute("name","plz_bisCH"+foo.ch);
Feld_bis.setAttribute("value","9999");
Feld_bis.setAttribute("maxLength","4")
Feld_bis.setAttribute("size","5");
}

// Hinzufügen zu Seite
if ( (foo.d < 10) || (foo.ch < 10) || (foo.a < 10) ){

div.appendChild(umbruch);
div.appendChild(document.createTextNode(" von"));
div.appendChild(document.createTextNode(" "));
div.appendChild(Feld_von);

div.appendChild(document.createTextNode(" bis "));
div.appendChild(Feld_bis);
div.appendChild(umbruch);
// Anzeigen
div.style.display = 'block';
}
else
alert("Maximale Anzahl von PLZ Gebieten ist erreicht !");
}



function resets(){
	document.suchbegriff.s.value="";
}