var on_page_load = '';
function add_on_page_load(code) {
	on_page_load += code + "\n";
}

function init() {
	if (on_page_load) {
		eval(on_page_load);
	}

}

function controlSkyscraper () {
	var x;
	if (self.innerHeight) {
		x = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
	} else if (document.body) {
		x = document.body.clientWidth;
	}
	
	var skyscraper = document.getElementById('skyscraper');
	if(x < 1130) {
		skyscraper.style.display = "none";
	} else {
		skyscraper.style.display = "block";
	}
}

function presetAgeTo(fromSelect, toSelectID) {
	var toSelect = document.getElementById(toSelectID);
	if(toSelect) {
		var minAge = Number(fromSelect.options[fromSelect.selectedIndex].value);
		var ageDifference = null;
		if(minAge < 20) {
			ageDifference = 8;
		} else if(minAge < 30) {
			ageDifference = 10;
		} else if(minAge < 40) {
			ageDifference = 12;
		} else if(minAge < 50) {
			ageDifference = 15;
		} else {
			ageDifference = 20;
		}

		var maxAge = ageDifference + minAge;

		for(var i=0; i < toSelect.options.length; i++) {
			if( (ageDifference + minAge) == toSelect.options[i].value ) {
				toSelect.selectedIndex = i;
			}
		}
	}	
}

function allowSearchPerDistance(plzFieldId, distanceSelectId, countrySelectId) {
	var plzField = document.getElementById(plzFieldId);
	var distanceSelect = document.getElementById(distanceSelectId);
	var countrySelect = document.getElementById(countrySelectId);
				
	if(plzField && distanceSelect && countrySelect) {
		var disableDistance = false;
		if(countrySelect.value == 'de') {
			if(plzField.value.length < 5) {
				disableDistance = true;
			}
		} else if(countrySelect.value == 'at') {
			if(plzField.value.length < 4) {
				disableDistance = true;
			}
		}
		
		if(disableDistance) {
			distanceSelect.disabled = true;
		} else {
			distanceSelect.disabled = false;
		}
	} 
}

function show(id) {
	var element = document.getElementById(id);
	if(element) {
		element.style.display = "block";
	}
}

function hide(id) {
	var element = document.getElementById(id);
	if(element) {
		element.style.display = "none";
	}
}


/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function utfUtility() {

	this.decode = function (utftext) {
		var plaintext = ""; var i=0; var c=c1=c2=0;
		while(i<utftext.length) {
			c = utftext.charCodeAt(i);
				if (c<128) {
        	    	plaintext += String.fromCharCode(c);
					i++;
				}  else if((c>191) && (c<224)) {
            	     c2 = utftext.charCodeAt(i+1);
        	         plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
    	             i+=2;
	            }  else {
        		   	c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
					plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
    	            i+=3;
	            }
		}
		return plaintext;
	}	

	this.encode = function (rawstring) {
		rawstring = rawstring.replace(/\r\n/g,"\n");
		var utftext = "";
		for(var n=0; n<rawstring.length; n++) {
			var c=rawstring.charCodeAt(n);
			if (c<128) {
				utftext += String.fromCharCode(c);
			} else if((c>127) && (c<2048)) {
				utftext += String.fromCharCode((c>>6)|192);
				utftext += String.fromCharCode((c&63)|128);
			} else {
			utftext += String.fromCharCode((c>>12)|224);
			utftext += String.fromCharCode(((c>>6)&63)|128);
			utftext += String.fromCharCode((c&63)|128);}
		}
	return utftext;
  };	


  return this;	
};