function headerflip_block (span_id_a)
{
	displayType = (document.getElementById(span_id_a).style.visibility=='hidden') ? 'visible' : 'hidden';
	document.getElementById(span_id_a).style.visibility = displayType;
}

function headerflip( span_id_a )
 {
	displayType = ( document.getElementById( span_id_a ).style.display == 'none' ) ? 'block' : 'none';
	document.getElementById( span_id_a ).style.display = displayType;
}
       

function newWindow(url,name){
	if (url.search("http://") == -1){
		url="http://" + url;
	}
	window.open(url,"");
}


function swapsize(element,stdwidth,stdheight,bigwidth,bigheight){

	var image=document.getElementById(element);
	if (image.width == stdwidth && image.height == stdheight){
		image.width = bigwidth;
		image.height = bigheight;
	} else if (image.width == bigwidth && image.height == bigheight){
		image.width = stdwidth;
		image.height = stdheight;
	}
}


function openPlantoolWindow(id){
	newWindow(_gcmsv5 + 'view_plan_by_customer.php/id/' + id,'Plantool');
}



function windowstate(filename, name, scroll, width, height, left, top)
{
	windowops = eval("'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scroll + ",resizable=yes,copyhistory=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + "'");

	newWindow = window.open(filename, name, windowops);
	newWindow.focus();
	return;
}  

function doLayout(){
	var pagetext = document.getElementById('pagetext');
	var layout = document.getElementById('layout');
	if (!document.all){
		pagetextheight = window.innerHeight - (document.getElementById('copyright').clientHeight + document.getElementById('pagetitel').clientHeight) - 90;
		pagetext.style.height = pagetextheight + 'px';
	} 
	
}


		
function gemeindechange(){
		var gemeinden = document.getElementById("gemeinden");
		if (gemeinden.value != 0 && document.getElementById("gemeinde_info_bulp") == null){
			var icon = new Image();
			icon.src = _document_root+"icons/stock_dialog-info-16.png";
			icon.width=16;
			icon.height=16;
			icon.id = "gemeinde_info_bulp";
			icon.onclick=cleargemeindelist;
			gemeinden.parentNode.appendChild(icon);
		} else if (gemeinden.value == 0){
			var icon = document.getElementById("gemeinde_info_bulp");
			if (icon != null){
				icon.parentNode.removeChild(icon);
			}
		}
}


function cleargemeindelist(){
	var gemeinden = document.getElementById("gemeinden");
	gemeinden.value = 0;
	var icon = document.getElementById("gemeinde_info_bulp");
	if (icon != null){
		icon.parentNode.removeChild(icon);
	}
}

function fade_new_image(id, new_url){
        var oldimg = document.getElementById(id);
        if (document.all){
                oldimg.style.filter='';
                oldimg.style.filter="blendTrans(duration=2)";
                oldimg.filters.item(0).Apply();
        }
        oldimg.src=new_url;

        if (document.all){
                oldimg.filters.item(0).Play();
        }
}

function openUrl(url){
	window.location.href=_document_root + url;
}

function openSub(url){
	window.location.href="http://"+url+"."+_tld;
}

function focus_first_textfield(){
	var fields = document.getElementsByTagName("input");
	var field;
	var focused=false;
	var i;
	for (i=0;i<fields.length;i++){
		fields[i].onfocus=myfocus;
		fields[i].onblur=myblur;
		if (fields[i].type == "text"){
			if (!focused){
				try{
					fields[i].focus();
				} catch (asdf){
					
				}
				focused=true;
			}	
		}
	}
	
	fields = document.getElementsByTagName("select");
	for (i=0;i<fields.length;i++){
		fields[i].onfocus=myfocus;
		fields[i].onblur=myblur;
	}
	
	fields = document.getElementsByTagName("textarea");
	for (i=0;i<fields.length;i++){
		fields[i].onfocus=myfocus;
		fields[i].onblur=myblur;
	}
}


function myfocus(){
	this.style.backgroundColor='#ffffa0';
}


function myblur(){
	this.style.backgroundColor='';
}

function createxmlhttp(){
	var xmlhttp = false;
	
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function imagesize(myid){
	var myimg = new Image();
	myimg.src = document.getElementById(myid).src;
	myimg.onload = function(event){
		eval("var myitem = document.getElementById('"+myid+"');");
		myitem.width = this.width;
		myitem.height = this.height;
	}
}
	
