function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=50;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-300;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);	
	
}

function cms_showpic(file,width,height,scrollbar) {
	var scroll = "no";
	
	if(!cms_showpic.arguments[1]) {
		width="";
	}
	if(!cms_showpic.arguments[2]) {
		height="";
	}
	if(cms_showpic.arguments[1] || cms_showpic.arguments[2]) {
		scroll="yes";
	}
	//Scrollbars "yes" OR "no"
	if(cms_showpic.arguments[3]) {
		var scroll = scrollbar;
	}

	//Bildgrösse bekannt
	lenWidth = width.replace(/\r/g, " ");
	lenHeight = height.replace(/\r/g, " ");

	//Bildpfad speichern
	path = "http://www.wetrok.ch/cms/cmsAdmin/modules/popup.cfm?picfile="+escape(file);
	
	//Breite und Höhe wird übergeben, sofern vorhanden
	if (lenWidth != '' && lenHeight != '') {
		path = path+"&width="+width+"&height="+height;
	}
	
	var picwindow=window.open(path, "picwindow", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scroll + ",resizable=yes,top=50,left=50");
  picwindow.focus();
}

function trim(item)	{
  item = item.replace(/\r/g, " ");
  item = item.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");
  item = item.replace(/'/g, "");
  item = item.replace(/ +/g, " ");  
  item = item.replace(/^\s/g, "");
  item = item.replace(/\s$/g, "");	
  if (item.value == ' ') {
		item.value = '';
	}
	return item
}
function isdate(datum) {
	date = trim(datum);
	if (date.length > 0) {
		if (date.search(/\d\d.\d\d.\d\d/) != -1 || date.search(/\d\d.\d\d.\d\d\d\d/) != -1 || date.search(/\d.\d.\d\d/) != -1 || date.search(/\d.\d.\d\d\d\d/) != -1 || date.search(/\d\d.\d.\d\d/) != -1 || date.search(/\d\d.\d.\d\d\d\d/) != -1 || date.search(/\d.\d\d.\d\d/) != -1 || date.search(/\d.\d\d.\d\d\d\d/) != -1) {
			dDate = new Date();
			iYear = dDate.getFullYear();
			if (iYear == "2000") {
				isLeapyear = false;
			}
			else {
				leapyear = iYear / 4;
				calc = 4 * leapyear;
				if (calc == iYear) {
					isLeapyear = true;
				}
				else {
					isLeapyear = false;
				}
			}
			aDate = date.split(".");
			iMonth = 1 * aDate[1];
			iDay = 1 * aDate[0];
			switch(iMonth) {
				case 1:
					iDayCount = 31;
				break;
				case 2:
					if (isLeapyear == true) {
						iDayCount = 29;
					}
					else {
						iDayCount = 28;
					}
				break;
				case 3:
					iDayCount = 31;
				break;
				case 4:
					iDayCount = 30;
				break;
				case 5:
					iDayCount = 31;
				break;
				case 6:
					iDayCount = 30;
				break;
				case 7:
					iDayCount = 31;
				break;
				case 8:
					iDayCount = 31;
				break;
				case 9:
					iDayCount = 30;
				break;
				case 10:
					iDayCount = 31;
				break;
				case 11:
					iDayCount = 30;
				break;
				case 12:
					iDayCount = 31;
				break;
			}
			if (iDay >= 1 && iDay <= iDayCount) {
				return true;
			}
			else {
				return false;
			}
		}
		else {
			return false;
		}
	}
	else {
		return false;
	}
}
function ismail(mail) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(mail)) {
		return true;
	}
	else {
		return false;
	}
}

function cms_reload() {
	location.reload();
}
function cms_popup(Ziel,Breite,Hoehe,Status,Toolbar,Location,Menu) {
	popup=window.open(Ziel,"PopUp","status=" + Status + ",toolbar=" + Toolbar + ",location=" + Location + ",menu=" + Menu + ",width=" + Breite + ",height=" + Hoehe + ",left=" + (screen.width - Breite) / 2 +	",top=" + (screen.height - Hoehe) / 2);
	popup.focus();
}

function cm_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera 
  this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera   
  this.ie5 = (this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6)
  this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  this.ie6 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6)
	this.ie4=(this.agent.indexOf("msie")>-1 && document.all &&!this.op5 &&!this.op6 &&!this.ie5&&!this.ie6)
  this.ie = (this.ie4 || this.ie5 || this.ie6)
	this.mac=(this.agent.indexOf("mac")>-1)
	this.ns6=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ns4=(!this.dom && document.layers)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6)
  this.usedom= this.ns6//Use dom creation
  this.reuse = this.ie||this.usedom //Reuse layers
  this.px=this.dom&&!this.op5?"px":""
	return this
}
var bw=new cm_bwcheck();


