﻿// JavaScript Document
// Alle JS Funktionen des Portals Taunusebene.de
// 
var text;
var value = 1;
var ivalue = 100;
var i;
var newAnzeige;
var slidephp;
var insertreturn;



function showSlide(pic,galerie,fademe,page){
	
	
		if (fademe == 'true'){
			var arrayPageSize = getPageSize();
			
			document.getElementById("inactive").style.width=arrayPageSize[0]+"px";
			document.getElementById("inactive").style.height=arrayPageSize[1]+"px";
			var popupLeft = ((arrayPageSize[0] - 20 - 820) / 2);
			

				document.getElementById("popup").style.left = (popupLeft < 0) ? "0px" : popupLeft + "px";
				document.getElementById("popup").style.left = (popupLeft < 0) ? "0px" : popupLeft + "px";
			Fadeout("inactive", 400);
		
		}
		
		var mySlide = new teAjax();
		
		mySlide.url="http://www.taunusebene.de/galerie_cms/galerien/slide.php?bild="+pic+"&gallerie="+galerie+"&page="+page;
						
		mySlide.onSuccess=function(txt2,xml) {
			if (agHasError(txt2)) {
				
			  mySlide.onError(agGetError(txt2));
			  return null;
			} else {
			  try {
				  slidephp = txt2;
				
			  } catch(e) {
			   
				mySlide.onError(e.name+": "+e.message);
				return null;
			  } 
			}    
				

				document.getElementById("popup").innerHTML="<div align='right' style='cursor:pointer' onclick='closeSlide()'><u>schliessen x</u></div>"+ slidephp;
				document.getElementById("popup").style.display="block";
				
				
				
				if (page > 0){
	
					pic = document.getElementById("largepic").value;
					document.getElementById("test1").src= pic;
					showComment();
					
				}else{
				
					window.setTimeout("sh()",500);
		
				}
				
				// Pagesize nochmal setzten
				arrayPageSize = getPageSize();
				document.getElementById("inactive").style.width=arrayPageSize[0]+"px";
				document.getElementById("inactive").style.height=arrayPageSize[1]+"px";
				
		}
			
		mySlide.onError=function(msg2) {
			alert(msg2);
		  }

mySlide.doRequest();

}


function sh(){
	
	pic = document.getElementById("largepic").value;
	document.getElementById("test1").src= pic;
//	document.getElementById("test1").style.visibility = "hidden";
	//document.getElementById("test2").style.visibility = "visible";
	
}

function closeSlide(){

	document.getElementById("popup").innerHTML="";
	document.getElementById("popup").style.display="none";
	document.getElementById("inactive").style.display="none"
}

function showAnzeigen(){
	
		
	newAnzeige = "";
		
		if (text == null){
			
			document.getElementById("showsearch").style.display = "none";
			
		}else{
		
			document.getElementById("showsearch").style.display = "block";
			

		
		
		newAnzeige += "<div align = 'right'><img class='rahmen3' src='http://www.taunusebene.de/ajax/cross.gif' alt='Suche schliessen' style='cursor:pointer' onclick='document.getElementById(\"showsearch\").style.display = \"none\"' /> </div>";
		newAnzeige += "<b>" + text.length + " Suchergebnisse </b><br /><br />";
		for (var i=0; i<text.length; i++) {
			
			headline = text[i]["headline"];
			id = text[i]["id"];
			
			newAnzeige += "<a class='search' href='http://www.taunusebene.de/taunus/branchen/"+headline+"/"+id+"'>"+headline+"</a><br />";
			
			
			document.getElementById("showsearch").innerHTML = newAnzeige;
	
		}
}
		
}


function testme(wert){
	
	document.getElementById("showsearch").style.display = "block";
	if (wert != ""){
	var myAjax = new teAjax();
  	myAjax.url="http://www.taunusebene.de/ajax/data.php?value="+wert;
	
	myAjax.onSuccess=function(txt) {
    if (agHasError(txt)) {
		
      myAjax.onError(agGetError(txt));
      return null;
    } else {
      try {
		  
	//	alert(txt);
        //JSON auswerten
		text = eval('('+txt+')');
	
      } catch(e) {
       //Fehler bei JSON-Auswertung
        myAjax.onError(e.name+": "+e.message);
        return null;
      } 
    }    
		showAnzeigen();
	}
	
myAjax.onError=function(msg) {
    alert(msg);
  }
  
  myAjax.doRequest();
  
	}else{
	
	newAnzeige = "<img src = 'http://www.taunusebene.de/bilder/ajax-loader.gif' />";
	document.getElementById("showsearch").style.display = "none";
	document.getElementById("showsearch").innerHTML = newAnzeige;
	
	}
}



//Überprüft Rückgabe eines PHP-Skripts, ob es eine Fehlermeldung ist
function agHasError(msg)
{
  //Hat msg einen Inhalt?
  if (!msg) return false; 
  
  //Befindet sich Zeichenkette AOERROR: am Anfang von msg?
  if (msg.indexOf("AGERROR:") == 0) {
    return true;
  } else {
    return false;
  }
}


// ################################################ F A D E   O U T ########################################

function Fadeout(id, geschwindigkeit) {
        var fps = Math.round(geschwindigkeit / 100); 
        var tmp = 0;
    for(i = 1; i <= 60; i++) {
        setTimeout("Fadeout_fade('" + id + "'," + i + ")", (tmp * fps));
        tmp++;
    }
}

function Fadeout_fade(id, pas) {
        var heurix = document.getElementById(id).style;
        if(pas < 60) {
               heurix.opacity = (0.01 * pas);
               heurix.MozOpacity = (0.01 * pas);

if(pas == 1){document.getElementById("inactive").style.display="block";}

               heurix.KhtmlOpacity = (0.01 * pas);
               heurix.filter = "alpha(opacity=" + (1 * pas) + ")"; 
        } else {
               heurix.display = "block";
        }
}

// ################################################ E N D E ####################################################


//Aufbereiten der Fehlermeldung eines PHP-Skripts
function agGetError(msg)
{
  //AOERROR: aus Fehlermeldung entfernen
  return msg.replace(/AGERROR:/, ""); 
}

//Allgemeine Funktion für alle Fehlerfälle
function agErrorHandler(msg)
{
  //Fehler als Meldungsfenster anzeigen
  alert(msg);
}

function setSession(value){
		
		var getstr = "?";
		var url = "http://www.taunusebene.de/ajax_im/setsession.php";
		getstr += "value="+value;
	    insertAjax(url,getstr);
	
}

function showComment(){
		
		var commentstyle;
		
		commentstyle = document.getElementById("kommentare1").style.display;
		
		if (commentstyle == "none"){
			
					
			document.getElementById("kommentare1").style.display = "block";
			document.getElementById("showcomment").innerHTML = "Kommentare ausblenden";
			document.getElementById("writecomment").style.display = "none";
			document.getElementById("showwritecomment").innerHTML = "Kommentar schreiben";
			
			var arrayPageSize = getPageSize();
			document.getElementById("inactive").style.width=arrayPageSize[0]+"px";
			document.getElementById("inactive").style.height=arrayPageSize[1]+"px";
			
		}else{
			
			document.getElementById("kommentare1").style.display = "none";
			document.getElementById("showcomment").innerHTML = "Kommentare anzeigen";
			
			var arrayPageSize = getPageSize();
			document.getElementById("inactive").style.width=arrayPageSize[0]+"px";
			document.getElementById("inactive").style.height=arrayPageSize[1]+"px";
			
		}
}

function writeComment(){
	
	var writecommentstyle;
	
	writecommentstyle = document.getElementById("writecomment").style.display;
	
		
	if (writecommentstyle == "none"){
		
			document.getElementById("kommentare1").style.display = "none";
			
			document.getElementById("showcomment").innerHTML = "Kommentare anzeigen";
			document.getElementById("writecomment").style.display = "block";
			document.getElementById("showwritecomment").innerHTML = "Kommentar schreiben ausblenden";
		
	}else{
		
            document.getElementById("writecomment").style.display = "none";
			document.getElementById("showwritecomment").innerHTML = "Kommentar schreiben";
		
	}
	

}

function get(pic,galerie) {
      	 
		var getstr = "?";
		var kommentar;
		var url = "http://www.taunusebene.de/galerie_cms/galerien/slide.php";
		 
		
		var kommentar = document.getElementById("kommentar").value;
		
		kommentar = encodeURIComponent(kommentar);
		
		getstr += "kommentar=" + kommentar + "&bild="+pic+"&gallerie="+galerie+"&action=insert";	
		
		insertAjax(url,getstr);
		
		showSlide(pic,galerie,"false",1);
	
   }



  function querykontakt(url,action,anfrageid,user_id,art,art2){


	var getstr = "?";
	

	document.getElementById(art).innerHTML = "Warte auf best&auml;tigung...";
	document.getElementById(art2).innerHTML = "";


	getstr += "action=" + action + "&anfrageid=" + anfrageid + "&user_id=" + user_id;
		
	insertAjax(url,getstr);

	} 


   
  function insertAjax(url,param){
	
					
		var myInsert = new teAjax();
		
		myInsert.url=url + param;

	  	  	
		myInsert.onSuccess=function(inserttxt) {
			if (agHasError(inserttxt)) {
				
			  myInsert.onError(agGetError(inserttxt));
			  return null;
			} else {
			  try {
				 
			  } catch(e) {
			   
				myInsert.onError(e.name+": "+e.message);
				return null;
			  } 
			}    
		}
			
		myInsert.onError=function(insertmsg) {
			alert(insertmsg);
		  }

		myInsert.doRequest();

}

   function picAllo(allocation,pic,galerie){
	   
	   var getstr = "?";
		var url = "http://www.taunusebene.de/galerie_cms/galerien/slide.php";
		getstr += "bild="+pic+"&gallerie="+galerie+"&action="+allocation;
	     insertAjax(url,getstr);
   }
   
   

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;
}