var content_breite = 0;
var content_hoehe  = 0;
var hoehe_center   = 0;
var zoombg         = 0;
var preloads       = new Array();

function MM_validateForm2() { //v4.0
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) {errors+='- '+nm+' muss eine E-Mail Adresse enthalten.\n';}
          else if (val.match(/\s/)) errors+='- '+nm+' darf keine Leerzeichen enthalten.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' muss eine Zahl sein.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' muss eine Zahl zwischen '+min+' und '+max+' sein.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+q+' ist erforderlich.\n'; }
    } 
    return errors;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { if (args[i+1] != "") { nm=args[i+1]; } else { nm=val.name; } if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' muss eine echte E-Mail-Addresse sein.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' muss eine Zahl sein.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' muss eine Zahl zwischen '+min+' und '+max+' sein.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' ist erforderlich.\n'; }
  } if (errors) alert('Folgende Fehler traten auf:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function clearkontakt() {
	$('#anrede').attr('checked',false);
	$('#anrede2').attr('checked',false);
	$('#firma').attr('value','');
	$('#vorname').attr('value','');
	$('#name').attr('value','');
	$('#strasse_hausnr').attr('value','');
	$('#plz').attr('value','');
	$('#ort').attr('value','');
	$('#telefon').attr('value','');
	$('#email_from').attr('value','');
	$('#nachricht').attr('value','');
	$('#wunschtermin').attr('value','');
	$('#uhrzeit').attr('value','');
	$('#alternativtermin').attr('value','');
	$('#alternativtermin_uhrzeit').attr('value','');
	$('#auftragsnr').attr('value','');
}

function check_transporter() {
	if($('#transporter').attr('checked')) {
		$('#kontaktzusatz').show();
		$('#buttons1').hide();
	} else {
		$('#kontaktzusatz').hide();
		$('#buttons1').show();
	}
}

function sendkontakt() {
	var f = $('#kontaktform');
	if($('#transporter').attr('checked')) {
		var errors = MM_validateForm('name','Name','R','strasse_hausnr','Strasse, Haus-Nr','R','plz','Postleitzahl','R','ort','Ort','R','telefon','Telefonnummer','R','email_from','eMail','RisEmail','wunschtermin','Wunschtermin','R','uhrzeit','Uhrzeit','R','auftragsnr','Auftrags-Nr','R');
	} else {
		$('#wunschtermin').attr('value','');
		$('#uhrzeit').attr('value','');
		$('#alternativtermin').attr('value','');
		$('#alternativtermin_uhrzeit').attr('value','');
		$('#auftragsnr').attr('value','');
		var errors = MM_validateForm('name','Name','R','strasse_hausnr','Strasse, Haus-Nr','R','plz','Postleitzahl','R','ort','Ort','R','telefon','Telefonnummer','R','email_from','eMail','RisEmail');
	}
	var email = $('#email_from').attr('value');
	$('#email').attr('value',email);
	if (document.MM_returnValue) {f.submit();}
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i, x, a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){
  	document.MM_sr[j++]=x; 
	if (!x.oSrc) x.oSrc=x.src; 
	x.src=a[i+2];
  }
}

function preload() {
  var d = document; 
  if (d.images){ 
  	if (!d.MM_p) d.MM_p = new Array();
    var j = d.MM_p.length;
    for (var i = 0; i < preloads.length; i++) {
		if (preloads[i].indexOf("#") != 0) {
			d.MM_p[j] = new Image; 
			d.MM_p[j++].src = preloads[i];
		}
    }
  }
}

function getSel()
{
	var txt = '';
	var foundIn = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
		foundIn = 'window.getSelection()';
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
		foundIn = 'document.getSelection()';
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
		foundIn = 'document.selection.createRange()';
	}
	else return;
	document.forms[0].selectedtext.value = 'Found in: ' + foundIn + '\n' + txt;
}

function addResizeEvent(func) {
  var old = window.onresize;
  if (typeof window.onresize != 'function') {
    window.onresize = func;
  } else {
    window.onresize = function(e) {
      old(e);
      func(e);
    }
  }
}

function addScrollEvent(func) {
  var old = window.onscroll;
  if (typeof window.onscroll != 'function') {
    window.onscroll = func;
  } else {
    window.onscroll = function(e) {
      old(e);
      func(e);
    }
  }
}

var vme_error = "";
function initVMEIframeAutoResice(o) {
  setInterval(function () {
    if (o[0] && o[0].contentDocument) {
	    var height;
	    try {
	      height = o[0].contentDocument.height + 20
	    } catch (e) {
	      vme_error=e;
	      o[0].scrolling = 'auto';
	      return;
	    }
	    o[0].scrolling = 'no';
	    if (height && height != o.height()) o.height(height);
	}
  }, 500)
}

function set_zoom_bg() {
	if (zoombg) {
		div = document.getElementById('zoombg');
	
		if (div) {
			var xScroll, yScroll;
	
			if (window.innerHeight && window.scrollMaxY) {
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else {
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
	
			var windowWidth, windowHeight;
	
			if (self.innerHeight) { // all except Explorer                                                                                                                                                                                                                                                                                                                                                             
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth;
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) {
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) {
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
	
			if (yScroll < windowHeight){
				hoehe = windowHeight;
			} else {
				hoehe = yScroll;
			}
	
			if (xScroll < windowWidth){
				breite = xScroll;
			} else {
				breite = windowWidth;
			}
	
	
			div.style.width= breite + 'px';
			div.style.height= hoehe + 'px';
			div.style.display='';
			return 1
		}
	}
	return 0
}

function showzoom(count) {
	var zoom;
	img = document.getElementById('zoomimg');

	if ((count < 50) && (img.width < 20)) {
		count++;
		window.setTimeout("showzoom(" + count + ")", 50);
	} else {
		if (window.innerWidth) {
			breite = window.innerWidth;
		} else if (document.body && document.body.offsetWidth) {
			breite = document.body.offsetWidth;
		} else {
			breite = 0;
		}
	
		if (window.innerHeight) {
			hoehe = window.innerHeight;
		} else if (document.body && document.body.offsetHeight) {
			hoehe = document.body.offsetHeight;
		} else {
			hoehe = 0;
		}
	
		var windowWidth, windowHeight, xScroll, yScroll;
	
		if (self.innerHeight) { // all except Explorer                                                                                                                                                                                                                                                                                                                                                             
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth;
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) { // other Explorers                                                                                                                                                                                                                                                                                                                                                             
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;
		}
	
		var img = document.getElementById('zoomimg');
		if (img.width > 964) {
			img.width = 964;
		};
	
		yScroll = yScroll + (windowHeight - img.height) / 2;
		xScroll = xScroll + (windowWidth - img.width) / 2;
		
		if (yScroll < 0) {
			yScroll = 0;	
		}
	
		if (xScroll < 0) {
			xScroll = 0;	
		}
	
		zoom = document.getElementById('zoom');
		zoom.style.top= yScroll + 'px';
		zoom.style.left= xScroll + 'px';
		set_zoom_bg();
	}
}

function zoom(bild) {
	zoombg=1;
  if (set_zoom_bg()) {
		zoomdiv = document.getElementById('zoom');

		newdiv = document.createElement('div');
		newdiv.style.border='4px #7db948 solid';
		newdiv.style.backgroundColor='#FFFFFF';

		img = document.createElement('img');
		img.id= "zoomimg";
		img.src=bild;

		climg = document.createElement('a');
		climg.href = 'javascript:closeZoom();';
		climg.onfocus = 'this.blur()';
		climg.appendChild(img);
		newdiv.appendChild(climg);

		a = document.createElement('a');
		a.href = 'javascript:closeZoom();';
		a.onfocus = 'this.blur()';

		img2 = document.createElement('img');
		img2.src='/shared/pics/schliessen.gif';

		a.appendChild(img2);

		schliessen = document.createElement('div');
		schliessen.style.textAlign = 'right';
		schliessen.appendChild(a);
	
		zoomdiv.appendChild(newdiv);
		zoomdiv.appendChild(schliessen);
    zoomdiv.style.top='-1000px';
    zoomdiv.style.left='-1000px';
		zoomdiv.style.display='';
		window.setTimeout("showzoom(1)", 50);
	} else {
		zoombg=0;
	}
}

function closeZoom() {
	var div = document.getElementById('zoombg');
	if (div) {
		div.style.display='none';
		newdiv = document.getElementById('zoom');
		newdiv.style.display='none';
		newdiv.innerHTML = "";
	}
	zoombg=0;
}

addResizeEvent(set_zoom_bg);
addScrollEvent(set_zoom_bg);