function FitSite(){

	var searchstring = window.location.search

	/* Messpunkt checkLength suchen */
	var pos, element
	element=document.getElementById('checkLength');
	pos=getPosition(element);

	top.document.getElementById('resultlist').height = pos.y

	if (top.window.document.getElementById('iconLoad')) {
		top.window.document.getElementById('iconLoad').style.display = 'none'
	}
	//setHiddenProduct();
}


function getPosition(element) {
/* der Aufruf dieser Funktion ermittelt die absoluten Koordinaten
   des Objekts element */
	var elem=element,tagname="",x=0,y=0;
  
/* solange elem ein Objekt ist und die Eigenschaft offsetTop enthaelt
   wird diese Schleife fuer das Element und all seine Offset-Eltern ausgefuehrt */
	while ((typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined")) {
		y+=elem.offsetTop;     /* Offset des jeweiligen Elements addieren */
		x+=elem.offsetLeft;    /* Offset des jeweiligen Elements addieren */
		tagname=elem.tagName.toUpperCase(); /* tag-Name ermitteln, Grossbuchstaben */

/* wenn beim Body-tag angekommen elem fuer Abbruch auf 0 setzen */
		if (tagname=="BODY")
			elem=0;

/* wenn elem ein Objekt ist und offsetParent enthaelt
   Offset-Elternelement ermitteln */
		if (typeof(elem)=="object")
		if (typeof(elem.offsetParent)=="object")
			elem=elem.offsetParent;
	}

/* Objekt mit x und y zurueckgeben */
	position=new Object();
	position.x=x;
	position.y=y;
	return position;
}

function setIframe() {
	var strText;
	var dbname;
	var strProduct;
	var strType;
	var strEShop = '0';
	strText = top.window.document.forms['resellersearchbox'].resellersearch.value;
	
	if(document.forms['resellersearchbox'].fldEShopFilter.checked == true){
		strEShop = '1';
	}

	var searchstring = top.window.location.search
	if (searchstring.lastIndexOf('&artikelnummer=') == '-1') {
		strProduct = ''
		} else {		
		strProduct  = searchstring.substring((searchstring.lastIndexOf('&artikelnummer=') + 15),1000)
		if (strProduct.lastIndexOf('&') == '-1') {
			strProduct = strProduct;
			strType = '0';
		} else {
			strProduct = strProduct.substring(0,strProduct.lastIndexOf('&'));
			strType = searchstring.substring((searchstring.lastIndexOf('&type=') + 6),1000);
		}
	}
	dbname = top.window.document.getElementById('webdbname').value
	
	if (strProduct == '') {
	 	top.frames.resultlist.location = '/' + dbname + '/agSearchResellers?OpenAgent&q=' + encodeURI(strText) + '&eshop=' + strEShop
	} else {
		top.frames.resultlist.location = '/' + dbname + '/agSearchResellers?OpenAgent&q=' + encodeURI(strText) + '&eshop=' + strEShop + '&artikelnummer=' + strProduct + '&type=' + strType
	}
	
	};

function setIframeNew(strText) {
/* Frame neu setzen */
	var dbname;
	var strProduct;
	var strType;
	var strEShop = '0';
	
	if(top.document.forms['resellersearchbox'].fldEShopFilter.checked == true){
		strEShop = '1';
	}
	top.window.document.forms['resellersearchbox'].resellersearch.value = strText
	var searchstring = top.window.location.search
	if (searchstring.lastIndexOf('&artikelnummer=') == '-1') {
		strProduct = ''
		} else {		
		strProduct  = searchstring.substring((searchstring.lastIndexOf('&artikelnummer=') + 15),1000)
		if (strProduct.lastIndexOf('&') == '-1') {
			strProduct = strProduct;
			strType = '0';
		} else {
			strProduct = strProduct.substring(0,strProduct.lastIndexOf('&'));
			strType = searchstring.substring((searchstring.lastIndexOf('&type=') + 6),1000);
		}
	}
	dbname = top.window.document.getElementById('webdbname').value
	
	//top.frames.resultlist.location = '/' + dbname + '/agSearchResellers?OpenAgent&q=' + encodeURI(strText)
	
	if (strProduct == '') {
	 	top.frames.resultlist.location = '/' + dbname + '/agSearchResellers?OpenAgent&q=' + encodeURI(strText) + '&eshop=' + strEShop
	} else {
		top.frames.resultlist.location = '/' + dbname + '/agSearchResellers?OpenAgent&q=' + encodeURI(strText) + '&eshop=' + strEShop + '&artikelnummer=' + strProduct + '&type=' + strType
	}
};

function resetRSearch1() {
	var strText
	strText = top.window.document.forms['resellersearchbox'].resellersearch.value;
	if (strText =='Ihre Postleitzahl, Strasse, Stadt...') {
		top.window.document.forms['resellersearchbox'].resellersearch.value = '';
	}
};

function resetRSearch2() {
	var strText
	strText = top.window.document.forms['resellersearchbox'].resellersearch.value;
	if (strText =='') {
		top.window.document.forms['resellersearchbox'].resellersearch.value = 'Ihre Postleitzahl, Strasse, Stadt...';
		top.window.document.forms['resellersearchbox'].resellersearch.select()
	}
};

function checkKCode() {
// Unterscheidung Firefox / IE
if (event.which) {
	KCode = event.which; 
} else if (event.keyCode) {
	KCode = event.keyCode;
};

if (KCode==13 ){
	setIframe()
	}
}

function checkKCodeContact() {
// Unterscheidung Firefox / IE
if (event.which) {
	KCode = event.which; 
} else if (event.keyCode) {
	KCode = event.keyCode;
};

if (KCode==13 ){
	top.document.getElementById("directions").innerHTML = '';
	//setDirections(top.window.document.forms['resellersearchbox'].resellersearch.value,'Kolkkampweg 1, 32278 Kirchlengern, Germany', 'de');
	}
}

function setDivHTML() {
	top.document.getElementById("directions").innerHTML = document.getElementById("directions").innerHTML;
	}

// Google Routenplaner ################################################
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
                    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad(){ 
          // Use this function to access information about the latest load()
          // results.
          if (document.getElementById('checkLength')) {
		window.setTimeout("FitSite()", 1000);
		}
          // e.g.
	  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}
// Google Routenplaner ################################################

function SwitchHiddenProduct(type) {
	if (type == 'show') {
		document.getElementById('HiddenProduct').style.visibility='visible';
		document.getElementById('HiddenProduct').style.position='static';
		document.getElementById('HiddenProductNav').style.visibility='hidden';
		document.getElementById('HiddenProductNav').style.position='absolute';
		FitSite()

	} else if (type == 'hide') {
		document.getElementById('HiddenProduct').style.visibility='hidden';
		document.getElementById('HiddenProduct').style.position='absolute';
		document.getElementById('HiddenProductNav').style.position='static';
		document.getElementById('HiddenProductNav').style.visibility='visible';
		FitSite()
	}
}



function openFlyer(url, scrollbars) {
  var flyerinteractive = window.open(url, 'flyerinteractive', 'width=950,height=700,scrollbars=' + scrollbars);
  if (flyerinteractive) {
  flyerinteractive.focus();
  }
}

function openShippingInfo(url, scrollbars) {
  var infowindow = window.open(url, 'flyerinteractive', 'width=590,height=180,scrollbars=' + scrollbars);
  if (infowindow) {
  	infowindow.focus();
  }
}


function setHiddenProduct() {
	if ( document.getElementById("HiddenProductContainer")) {
	top.document.getElementById("HiddenProductContainer").innerHTML = document.getElementById("HiddenProductContainer").innerHTML;
	} else {
	 top.document.getElementById("HiddenProductContainer").innerHTML = '';
	 }
}