var xmlHttpGetSuggestions = createXmlHttpRequestObject();

var timeoutId = -1;

function createXmlHttpRequestObject() 
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
 
      { 
        // try to create XMLHttpRequest object
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


var timer_start_massage_wait = -1;
var preloadImage = new Image();
function massage_wait(url, breite, hoehe) {

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var objBody = document.getElementsByTagName("body").item(0);

	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay_massage_wait');
	objOverlay.onclick = function() { massage_wait_stop(); return false; };
	objOverlay.style.position = 'absolute';
	objOverlay.style.padding = '0px';
	objOverlay.style.margin = '0px';
	objOverlay.style.left = '0px';
	objOverlay.style.top = '0px';
	objOverlay.style.opacity = (70 / 100);
	objOverlay.style.MozOpacity = (70 / 100);
	objOverlay.style.KhtmlOpacity = (70 / 100);
	objOverlay.style.filter = "alpha(opacity=" + 70 + ")";
	objOverlay.style.backgroundColor = '#666666';
	objBody.appendChild(objOverlay);
	objOverlay.style.width=(arrayPageSize[0]-21)+'px';
	objOverlay.style.height=(arrayPageSize[1])+'px';

	var objInlay1 = document.createElement("div");
	objInlay1.setAttribute('id','inlay1_massage_wait');
	objInlay1.style.padding = '25px 5px 5px 5px';
	objInlay1.style.position = 'absolute';
	objInlay1.style.backgroundColor = '#ffffff';
	objInlay1.style.border = '1px solid #666666';
	objInlay1.style.textAlign = 'center';
	objBody.appendChild(objInlay1);
	
	objInlay1.style.width= (breite + 10) + 'px';
	objInlay1.style.height= (hoehe + 20) + 'px';

	objInlay1.style.left = ((arrayPageSize[0]/2)-455)+'px';
	objInlay1.style.top = '20px';

	document.getElementById("inlay1_massage_wait").innerHTML = '<iframe src="'+url+'" style="width:'+(breite+5)+'px; height:'+(hoehe+5)+'px; left:0px; top:0px;" frameborder="0" ></iframe>';

	var objBild2 = document.createElement("img");
	objBild2.setAttribute('src','/bilder/close_20.jpg');
	objBild2.onclick = function() { massage_wait_stop(); return false; };
	objBild2.setAttribute('id','Bild2_massage_wait');
	objBild2.style.position = 'absolute';
	objBild2.style.cursor = 'pointer';
	objBild2.style.right = '0px';
	objBild2.style.top = '0px';
	objInlay1.appendChild(objBild2);
	
}

	var timeoutId=0;
		function get_content() {
			
			set_get_content();
		
		}
		
		function set_get_content() {
		
				if (xmlHttpGetSuggestions.readyState == 4 || xmlHttpGetSuggestions.readyState == 0) 
				{   
					xmlHttpGetSuggestions.open('GET', "/Broschuere/broschuere.php", true);
					xmlHttpGetSuggestions.onreadystatechange = set_get_content_yes; 
					xmlHttpGetSuggestions.send(null);
				}
				// if the XMLHttpRequest object is busy...
				else
				{
					if(timeoutId != -1)
					clearTimeout(timeoutId);          
					// try again in 0.1 seconds     
					timeoutId = setTimeout("set_get_content();", 100);
				}
		
		}
		
		function set_get_content_yes() 
		{
		  //if the process is completed, decide what to do with the returned data
		  if (xmlHttpGetSuggestions.readyState == 4) 
		  {
			// only if HTTP status is "OK"
			if (xmlHttpGetSuggestions.status == 200) 
			{ 
				document.getElementById('inlay1_massage_wait').innerHTML = xmlHttpGetSuggestions.responseText;
			} 
		  }
		
		}


function massage_wait_stop(){

	var id_array = new Array("overlay_massage_wait","inlay1_massage_wait","Bild_massage_wait","Bild2_massage_wait")

	for (var i = 0 ; i < id_array.length ; i++) {
		var merker = document.getElementById(id_array[i]);
		if(merker) {
			document.getElementById(id_array[i]).style.display = "none";
			var objOverlay = document.getElementById(id_array[i]);
			objOverlay.setAttribute('id', id_array[i]+'_close');
		}
	}

}


