var sDir = 5;
var tId;
var runDelay = 20;
var scrollVar;
var stillScroll;

function showMe(text, ev) {
	var theDiv = document.getElementById('showMeDiv');
	theDiv.scrollTop = 0;
	theDiv.style.left = (ev.clientX + 15 + document.documentElement.scrollLeft)+ "px";
	theDiv.style.top = (ev.clientY + document.documentElement.scrollTop)+ "px";
	theDiv.innerHTML = text;
	theDiv.style.visibility = 'visible';
	theDiv.style.width = "250px";
	var wid, hei, dWid, dHei;
	if (window.innerWidth) {
		wid = window.innerWidth;
		hei = window.innerHeight;
	}
	else {
		wid = document.body.clientWidth;
		hei = document.body.clientHeight;
	}
	wid -= 15;
	
	dWid = theDiv.clientWidth;
	dHei = theDiv.clientHeight;
	if (ev.clientX + dWid > wid)
		theDiv.style.left = (parseInt(theDiv.style.left+document.documentElement.scrollTop) - dWid - 30) + "px";
	if (ev.clientY + dHei > hei)
		theDiv.style.top = (parseInt(theDiv.style.top+document.documentElement.scrollTop) - dHei) + "px";
}

function hideMe() {
	var theDiv = document.getElementById('showMeDiv');
	theDiv.style.visibility = 'hidden';
	stillScroll = false;
	if (tId)
		clearTimeout(tId);
}

function moveMe(ev) {
	var theDiv = document.getElementById('showMeDiv');
	theDiv.style.left = (ev.clientX + 15 + document.documentElement.scrollLeft)+ "px";
	theDiv.style.top = (ev.clientY + document.documentElement.scrollTop)+ "px";
	var wid, hei, dWid, dHei;
	if (window.innerWidth) {
		wid = window.innerWidth;
		hei = window.innerHeight;
	}
	else {
		wid = document.body.clientWidth;
		hei = document.body.clientHeight;
	}
	wid -= 15;
	
	dWid = theDiv.clientWidth;
	dHei = theDiv.clientHeight;
	
	if (ev.clientX + dWid > wid)
		theDiv.style.left = (parseInt(theDiv.style.left) - dWid - 30) + "px";
		
	if (ev.clientY + dHei > hei)
		theDiv.style.top = (parseInt(theDiv.style.top) - dHei) + "px";
}

function sizeMe(x) {
	var theDiv = document.getElementById('showMeDiv');
	if (x != '')
		theDiv.style.width = x + 'px';
	else
		theDiv.style.width = '';
	theDiv.style.height = '';
}

function scrollMe() {
	scrollVar = 0;
	stillScroll = true;
	sDir = 5;
	nextScrollStep();	
	var theDiv = document.getElementById('showMeDiv');
}

function nextScrollStep() {
	var theDiv = document.getElementById('showMeDiv');
		
	runDelay = 20;
	
	theDiv.scrollTop = scrollVar;
	scrollVar += sDir;
	
	if (scrollVar <= 0) {
		scrollVar = 0;
		sDir = -sDir;
		runDelay = 1500;
	}
	
	if (scrollVar >= theDiv.scrollHeight - parseInt(theDiv.style.height) +25 ) {
		scrollVar = theDiv.scrollHeight - parseInt(theDiv.style.height) + 25;
		sDir = -sDir;
		runDelay = 1500;
	}
	
	if (stillScroll)
		tId = setTimeout('nextScrollStep()', runDelay);
}
function getInfo(text_value){
	new Ajax.Updater('showMeDiv','jax/return_img_text.php',{method:'post',postBody:'text_value='+text_value});
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function make_focus(obj){
		obj.focus();	
	}

function verifyPassPresse(doc_id,code,file,zip){
	new Ajax.Updater('presse_detail_div','jax/load_presse_pass.jax.php',{evalScripts:true,method:'post',postBody:'doc_id='+doc_id+'&file='+file+'&code='+code+'&zip='+zip});
}

function png_changes()
{	
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	   
	   //change the default buttons
	   var divs = document.getElementsByTagName("div");
		for (i = 0; i!=divs.length; i++)
		{
			if (divs[i].className == "default_button_FF") divs[i].className="default_button_IE";
		}
	}
}



/*standort*/
function standort(use_Gmap)
{	
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	/*document.write('<script type="text/javascript" src="js/prototype.js"></script>');*/
	/*$('showMeDiv').innerHTML='<script type="text/javascript" src="js/scripta/effects.js"></script>';*/
	hideSelectBoxes();
	hideFlash();
	Element.show('overlay_div');
	new Ajax.Updater('standort_div', 'jax/load_map.jax.php', {evalScripts:true, method:'post', postBody:'sid=&use_Gmap='+use_Gmap});	
}

function closeStandort(use_Gmap,zoom_out_map)
{	
	if (use_Gmap==0)
	{
		Element.hide('map_img');
		$('map_img').src=zoom_out_map;
	}
	Element.hide('standort_div');
	Element.hide('overlay_div');	
	showSelectBoxes();
	showFlash();		
}

function change_map_display(use_Gmap)
{
	if (use_Gmap=='0') standort(1);
	else standort(0);
}

function map_zoom_in(has_Gmap,zoom_in_map)
{
	if (has_Gmap==0) {Element.hide('map_img');$('map_img').src=zoom_in_map;}
	else map.zoomIn(); 
}

function map_zoom_out(has_Gmap,zoom_out_map)
{
	if (has_Gmap==0) {Element.hide('map_img');$('map_img').src=zoom_out_map;}
	else map.zoomOut();
}

function map_close(has_Gmap,zoom_out_map)
{
	Element.hide('map_img');
	if (has_Gmap==0) $('map_img').src=zoom_out_map;
}

function map_print()
{
	var url_address='map_print.php';
	popup = window.open( url_address, 'printpage', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=no,width=' + '708' + ', height=' + '900'  );
	popup.focus();
}

/*--------------------------------------------------------------------------*/
				/* overlay div */
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	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){ // 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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	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) { // 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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}

}

