//



// Allgemeine Helperfunktionen, um ein form zu submitten,
// ein neues Fenster zu öffnen, usw.



/*function winOpen(url, name, features){
	if(!name) {
		name = "_blank";
	}
	if(features){
//		newWin = window.open(url, name, features);
		newWin = window.open('', name, features);
		newWin.open(url, '_self', features);
	} else {
//		newWin = window.open(url, name);
		newWin = window.open('', name);
		newWin.open(url, '_self');
	}
	newWin.focus();
}*/

      
function winOpen(url, w_width, w_height, w_scr, w_tool,loc)
{
var param="WIDTH="+w_width+",HEIGHT="+w_height+",screenY=5,toolbar="+w_tool+",location="+loc+",scrollbars="+w_scr+",resizable=yes";

time =new Date();
helpzahl=time.getMilliseconds();
// 19.4.2008 geändert damit der fensternamen noch zufaelliger wird
fenstername=helpzahl.toString()+Math.random().toString().replace(/\./,"_");

extern = window.open(url,fenstername,param);
  browser = navigator.appName;
  if (browser == "Netscape")
{
     extern.focus();
     }
     
     return;
}

function zufzahlgen(min, max)
{
    return  Math.floor(min+(max-min)*(Math.random()));
    
}

function scrollIntverallTo(selectedPosX,selectedPosY,step)
{
	if (!step)
		step=20;
		
	// Zuerst schauen ob wir schon am ziel sind
	if ((document.documentElement) && (document.documentElement.scrollTop)) 
   		aktscroll=document.documentElement.scrollTop;
   	else
   	{
   		 if ((document.body) && (document.body.scrollTop))  
   		 	aktscroll=document.body.scrollTop;
   		 else
   		 	aktscroll=0;
	}
	
	if (aktivdurchzaehler>=selectedPosY)
	{
		window.clearInterval(aktivwindowscroll);
		window.scrollTo(selectedPosX,selectedPosY);   	
		aktivwindowscroll=0;		
		aktivdurchzaehler=0;   
	}
    else
	{
		aktivdurchzaehler+=step;		
		window.scrollBy(0,step);
	}
}
var aktivwindowscroll;
var aktivdurchzaehler=0;
function ScrollToElement(theElement){

	if (aktivwindowscroll)
		return false;
		


  var selectedPosX = 0;
  var selectedPosY = 0;
   
  while (theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
   step=20;
   if ((document.documentElement) && (document.documentElement.scrollTop)) 
   {   	      	   
  	selectedPosY=selectedPosY-(aktuelle_cursor_position_global_y-document.documentElement.scrollTop);
  	step=Math.ceil((selectedPosY-document.documentElement.scrollTop)/20);  	  	
  	aktivdurchzaehler=document.documentElement.scrollTop;  
   }
  else
  {
  	  if ((document.body) && (document.body.scrollTop))
  	  {  	  	  
  	  	  selectedPosY=selectedPosY-(aktuelle_cursor_position_global_y-document.body.scrollTop);   
  	  	  step=Math.ceil((selectedPosY-document.body.scrollTop)/20);
  	  	  aktivdurchzaehler=document.body.scrollTop;  		  
  	  	  
	  }
  	  else
  	  {  	  	    	  	  
  	  	selectedPosY=selectedPosY-aktuelle_cursor_position_global_y;  	 
  	  	aktivdurchzaehler=0; 	
  	  	step=Math.ceil(selectedPosY/20);
	  }
  }
  
  if (step<20)
  		step=20;

 aktivwindowscroll = window.setInterval("scrollIntverallTo("+selectedPosX+","+selectedPosY+","+step+")", 10);

   
}



function CheckAlloudwinOpen(text,url, w_width, w_height, w_scr, w_tool,loc)
{
    zahl1=zufzahlgen(1,10);
    zahl2=zufzahlgen(1,10);
    ergebnis=0;
    text=text+' '+zahl1+' + '+zahl2+' = ';
    
    while (!ergebnis)
    {
        ergebnis=prompt(text,'');
        if (ergebnis==(zahl1+zahl2))
               winOpen(url, w_width, w_height, w_scr, w_tool,loc);
        else
        {
            if (ergebnis)
            {
                alert(zahl1+' + '+zahl2+' = '+ergebnis+' ? Bitte nochmal rechnen.');
                ergebnis=0;
            }
            else
            {
                // Dann auf abbrechen gedrückt
                ergebnis=1;   
            }
        }
        
    }
    

            
    return ;            
}


function CheckAlloudwinOpenStatus(text,url, w_width, w_height, w_scr, w_tool,loc)
{
    zahl1=zufzahlgen(1,10);
    zahl2=zufzahlgen(1,10);
    ergebnis=0;
    text=text+' '+zahl1+' + '+zahl2+' = ';
    
    while (!ergebnis)
    {
        ergebnis=prompt(text,'');
        if (ergebnis==(zahl1+zahl2))
               winOpenStatus(url, w_width, w_height, w_scr, w_tool,loc);
        else
        {
            if (ergebnis)
            {
                alert(zahl1+' + '+zahl2+' = '+ergebnis+' ? Bitte nochmal rechnen.');
                ergebnis=0;
            }
            else
            {
                // Dann auf abbrechen gedrückt
                ergebnis=1;   
            }
        }
        
    }
    
    return ;            
}


// 4.5.2009
function CheckAlloudToDelete(text,url)
{
    zahl1=zufzahlgen(1,10);
    zahl2=zufzahlgen(1,10);
    ergebnis=0;
    text=text+' '+zahl1+' + '+zahl2+' = ';
    
    while (!ergebnis)
    {
        ergebnis=prompt(text,'');
        if (ergebnis==(zahl1+zahl2))
        {
            if (window.document.getElementById("delhelpframe"))
            {
                deletefenster=window.document.getElementById("delhelpframe");
                url=url+'&useiframe=1';            
                deletefenster.src=url;                
            }
            else // ansonstne wie bisher mit neuem fenster löschen
            {                    
                deletefenster=winOpen(url,500,400,false,false,false);
            }
            showWaitImage();   
        }
        else
        {
            if (ergebnis)
            {
                alert(zahl1+' + '+zahl2+' = '+ergebnis+' ? Bitte nochmal rechnen.');
                ergebnis=0;
            }
            else
            {
                // Dann auf abbrechen gedrückt
                ergebnis=1;   
            }
        }
        
    }
    
    return ;            
}

function ShowSecureQuestionForDialogForm(transimagename,text,url,w_width, w_height, w_scr, w_tool,loc) 
{
    sperre_fuer_change_back_color_on=transimagename;
    
   fensterparam="WIDTH="+w_width+",HEIGHT="+w_height+",screenY=5,toolbar="+w_tool+",location="+loc+",scrollbars="+w_scr+",resizable=yes,status=yes";
   document.getElementById('secureform_fensterparam').value=fensterparam;   
   ShowSecureQuestionForm(text,url,'dialog');   
   
}

function ShowSecureQuestionForDeleteForm(transimagename,text,url)
{
sperre_fuer_change_back_color_on=transimagename;
    
  ShowSecureQuestionForm(text,url,'delete');     
}

function setSecureFormPosition()
{
    
    x=aktuelle_cursor_position_global_x;
    y=aktuelle_cursor_position_global_y;
    
   document.all["securequesteionmodal"].style.height=document.body.offsetHeight+document.body.scrollTop;  
   document.all["securequesteionmodal"].style.display='block'; 
     
   document.all["securequestionform"].style.left = x;
   document.all["securequestionform"].style.top = y + 15;   
   document.all["securequestionform"].style.display='block';

}

function ShowSecureQuestionForm(text,url,urlart)
{
    
    
    
    
    zahl1=zufzahlgen(1,10);
    zahl2=zufzahlgen(1,10);    
    aufgabe=zahl1+' + '+zahl2+' = ';
    
    document.getElementById('secureform_zahl1').value=zahl1;
    document.getElementById('secureform_zahl2').value=zahl2;    
    document.getElementById('secureform_url').value=url;
    document.getElementById('secureform_urlart').value=urlart;
    document.getElementById('secureform_ergebnis').value='';
    
    
    document.getElementById('secureform_fragetext').innerHTML=text;
    document.getElementById('secureform_aufgabe').innerHTML=aufgabe;
    
    setSecureFormPosition();
    hideAllSelect('inhalt');    
    document.getElementById('secureform_ergebnis').focus();
    return;
          
}

function abort_secureQuestionForm()
{
  document.all["securequestionform"].style.display='none';     
  document.all["securequesteionmodal"].style.display='none';   
  help=sperre_fuer_change_back_color_on;  
  sperre_fuer_change_back_color_on=''; 
  changeBackColorOff(help);
  showAllSelect('inhalt');   
}


function secureQuestionCheckErg()
{
    zahl1=parseInt(document.getElementById('secureform_zahl1').value);   
    zahl2=parseInt(document.getElementById('secureform_zahl2').value);
    url=document.getElementById('secureform_url').value;
    urlart=document.getElementById('secureform_urlart').value;
    fensterparam=document.getElementById('secureform_fensterparam').value;      
    ergebnis=document.getElementById('secureform_ergebnis').value;
    
    if ((zahl1+zahl2)==ergebnis)
    {
        if (urlart=='delete')
        {
            if (window.document.getElementById("delhelpframe"))
            {
                deletefenster=window.document.getElementById("delhelpframe");
                url=url+'&useiframe=1';                      
                deletefenster.src=url;                
            }
            else // ansonstne wie bisher mit neuem fenster löschen
            {                    
                deletefenster=winOpen(url,500,400,false,false,false);
            }
            showWaitImage();    
            return false;
        }  
        
        if (urlart=='dialog')
        {           
            time =new Date();
            helpzahl=time.getMilliseconds();
            // 19.4.2008 geändert damit der fensternamen noch zufaelliger wird
            fenstername=helpzahl.toString()+Math.random().toString().replace(/\./,"_");

            extern = window.open(url,fenstername,fensterparam);
            
            abort_secureQuestionForm();
            
            return false;
        }     
        
    }
    else
    {
        alert(zahl1+' + '+zahl2+' = '+ergebnis+' ? Bitte erneut versuchen!');      
        return false;
    }
        
    
}


function winOpenStatus(url, w_width, w_height, w_scr, w_tool,loc)
{
	var param="WIDTH="+w_width+",HEIGHT="+w_height+",screenY=5,toolbar="+w_tool+",location="+loc+",scrollbars="+w_scr+",resizable=yes,status=yes";

	time =new Date();
	helpzahl=time.getMilliseconds();
	fenstername=helpzahl.toString();

	extern = window.open(url,fenstername,param);
	  browser = navigator.appName;
	  if (browser == "Netscape")
	  {
	  	extern.focus();
	  }
	  
	  return ;
}



function openInOpener(url){
	window.opener
	window.opener.open(url, "_self");
	window.opener.focus();
}

function newWindow(url, features){
	if(!features) features = "";
  window.open(url, "_blank", features);
}

function doCmd(command, form){
	if(!form) form = "immoniaForm";

	if(document.forms[form]){
		f = document.forms[form];
	} else {
		alert("das formular "+form+" iss nich da...");
		return false;
	}
	if(command){
  	f.elements["cmd"].value = command;
  }
 
  f.submit();
//  return(true);
}

function doScreenid(id,form)
{
	document.forms[form].screenid.value=id;
	document.forms[form].submit();
}

//fiacco*******************************************
function doCmdQuery(command, id, form)
{
  if(!form) form = "immoniaForm";	
  
  document.forms[form].savedqueryid.value = id;
  document.forms[form].cmd.value = command;
  
  document.forms[form].submit();
  return(true);
}

function doSubmit(formname)
{
  document.forms[formname].submit();
}

function check_enter(formname)
{
  if (window.event.keyCode==13)
  {
  	doSubmit(formname);
  }

}

function check_enter_cmd(formname,cmd)
{
  if (window.event.keyCode==13)
  {
  	doCmd(cmd,formname);
  }

}

function doSkip(form,name,wert)
{
  f=getForm(form);
  si=getFormElement(f,name);  
  si.value=wert;
  f.submit();
  return(true);

}


//ende fiacco**********************************************

function doSkipItems(num, form){
	f = getForm(form);
	si = getFormElement(f, "skipItems");
	si.value = num;  
  f.submit();
  return(true);
}

function doSkipCurItems(num,form)
{
   f = getForm(form);
   f.curFoto.value=0;
   doSkipItems(num,form);
   return true;
}

function doSkipFotos(num){
  document.immoniaForm.curFoto.value = num;
  document.immoniaForm.submit();
  return(true);
}

function doChallengeResponse(form,sess) {
	if(!form) form = "loginForm";
	f = getForm(form);
	
  str = f.loginName.value + ":" +
        f.loginPass.value + ":" +
        f.loginChallenge.value;
 
  f.loginResponse.value = MD5(str);
  // rausgenommen da ich loginResponse abgeschaltet habe
  // da dies nicht mit umlauten funktioniert
  //f.loginPass.value = "";
  f.submit();
}

function doChallengeResponseParent(form,sess) {
	if(!form) form = "loginForm";
	f = getForm(form);
	
  str = f.loginName.value + ":" +
        f.loginPass.value + ":" +
        f.loginChallenge.value;
  if (!sess)
 	 parent.frames['Linkes_Fenster'].location.href="links.php4";
  else
  	 parent.frames['Linkes_Fenster'].location.href="links.php4?ImmoniaSession="+sess;

  f.loginResponse.value = MD5(str);
  f.loginPass.value = "";
  f.submit();
}

// Die nächsten Funktionen werden für die Administrationsseiten gebraucht,
// und überprüfen vor dem Absenden die eingegebenen Werte.

function checkSaveUser(){

  document.immoniaForm.cmd.value = "save";
  document.immoniaForm.submit();
  return(true);
}

function checkSaveMakler(){

  document.immoniaForm.cmd.value = "save";
  document.immoniaForm.submit();
  return(true);
}

function checkSaveObjekt(){

  document.immoniaForm.cmd.value = "save";
  document.immoniaForm.submit();
  return(true);
}

function checkSaveFoto(){
  document.immoniaForm.submit();
  return(true);
}

function checkSaveKat(){
  document.immoniaForm.cmd.value = "save";
  document.immoniaForm.submit();
  return(true);
}

function deleteReally(){
  document.immoniaForm.really.value = 1;
  document.immoniaForm.submit();
  return(true);
}

function doRegisterUser(){
  document.immoniaForm.cmd.value = "saveuser";
  document.immoniaForm.submit();
  return(true);
}

//login and close (von fiacco, damit man weiss wo man meckern muss...)
function doLoginClose()
{
	doChallengeResponse();
	window.close();
}


// Die nächsten Funktionen werden hauptsächlich aus den SUchformularen
// aufgerufen, um bspw. das formular bei bedarf zu reloaden, oder die
// suchergebnisse abzurufen

function changed(what){

  switch(what){
  case 'suchkatid':
    if(immoniaForm.elements['objartids[]']){
      for (var i = 0; i < immoniaForm.elements['objartids[]'].options.length; i++) {
        immoniaForm.elements['objartids[]'].options[i].selected = 0;
      }
    }
    if(document.immoniaForm.kaufartid){
      document.immoniaForm.kaufartid.value = 0;
    }
    document.immoniaForm.submit();
    break;
  case 'kontaktart':
    document.immoniaForm.submit();
    break;
  case 'kaufart':
    document.immoniaForm.submit();
    break;
  case 'lage':
    document.immoniaForm.submit();
    break;
  case 'maklerid':
    document.immoniaForm.submit();
    break;
  case 'ortid':
    if(document.immoniaForm.ortsteilid){
      document.immoniaForm.ortsteilid.value = 0;
    }
    document.immoniaForm.submit();
    break;
  case 'ortsteilid':
    if(document.immoniaForm.cmd.value == 'search'){
      document.immoniaForm.submit();
    }
    break;
  case 'ortidedit':
//    document.immoniaForm.cmd.value='edit';
    if(document.immoniaForm.ortsteilid){
      document.immoniaForm.ortsteilid.value = 0;
    }
    document.immoniaForm.submit();
  case 'waehrungid':
//  	document.immoniaForm.waehrungchanged.value = "jawoll";
    document.immoniaForm.submit();
    break;
  default:
  	document.immoniaForm.submit();
    break;
  }
  return(true);
}

// FIACCO neu für immobasic
function doReload()
{
  document.immoniaForm.submit();
}

function okatchanged(which, form){
	f = getForm(form);
	x = getFormElement(f, which);
	katid = getFormElement(f, "kategorieid");
	katid.value = x[x.selectedIndex].value;
	f.submit();
	return true;
}



IMG01 = "js/on.gif";  //image when mouse is over the link
IMG02 = "js/off.gif"; //image when mouse isn't over the link
IMG03 = "js/onrot.gif"; //wenn nix hinter dem link

function imgover(imgname, auswahl){
    if (auswahl == IMG01)
    {
    	imgname.src = IMG01;
    }
    else
    {
     imgname.src = IMG03;
    }
}

function imgout(imgname){
     imgname.src = IMG02
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function doSelectOrt(){
	form = document.forms["immoniaForm"];
	if(form.ortids.value.length){
		ortids = form.ortids.value.split(",");
	}	else 	{
		ortids = new Array();
	}
	curid = form.ortid.value;
	schondrin = false;
	for(i in ortids){
		if(ortids[i] == curid) schondrin = true;
	}
	
	if(false == schondrin){
		ortids[ortids.length] = curid;
	}
	
	form.ortids.value = ortids.join(",");
	
	form.submit();
	return true;
}

function doUnselectOrt(id){
	form = document.forms["immoniaForm"];
	
	ids = form.ortids.value.split(",");
	newids = new Array();
	wardrin = false;
	for(i in ids){
		if(ids[i] != id){
			//newids.push(ids[i]);
			newids[newids.length] = ids[i];
		} else {
			wardrin = true;
		}
	}
	form.ortids.value = newids.join(",");

	if(wardrin){
		form.submit();
		return true;
	}
}

function doSelectOrtsteil(id){
	form = document.forms["immoniaForm"];

	if(form.ortsteilids.value.length){
		ids = form.ortsteilids.value.split(",");
	}	else {
		ids = new Array();
	}
	schondrin = false;
	for(i in ids){
		if(ids[i] == id) schondrin = true;
	}
	
	if(!schondrin) {
		ids[ids.length] = id;
	}
	
	form.ortsteilids.value = ids.join(",");
	
	form.submit();
	return true;
}

function doUnselectOrtsteil(id){
	form = document.forms["immoniaForm"];
	if(form.ortsteilids.value.length == 0) return false;
	
	ids = form.ortsteilids.value.split(",");
	newids = new Array();
	for(i in ids)  {
	if(ids[i] != id) 
	{  //newids.push(ids[i]);
	     newids[newids.length] = ids[i];}
	  }
	form.ortsteilids.value = newids.join(",");

	form.submit();
	return true;
}


function changeImage(image,url)
{
	image.src=url;
}
// vbscript kann nur globale variablen ansprechen
// darum müssen die 2 folgenden aus der funktion genommen werdne und deklariert werden
var MM_contentVersion=9;
var MM_Canflash=false;
function checkFlashInstalled(version)
{
	MM_contentVersion=version;
	// Nur Flash anzeigen wenn auch installiert
	if (((!document.all || navigator.userAgent.indexOf('Opera')!=-1) && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin))
	{
		MM_Canflash=true;
	}
	if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0
	   && (navigator.appVersion.indexOf("Win") != -1))
	   {	   	
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag		
		document.write('on error resume next \n');
		document.write('MM_Canflash = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');		
		document.write('</SCR' + 'IPT\> \n');
	}
	return MM_Canflash;

}


function addbookmark(url,title)
{
  if (!url)
  	url=window.location.href;
  if (!title)
  	title='Immobilien';

  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) 
  {
  	window.external.AddFavorite(url,title);
  } 
  else if (navigator.appName == "Netscape") 
  {
    window.sidebar.addPanel(title,url,"");
  } 
  else 
  {
    alert("Drücken Sie STRG-D (Netscape), STRG-T (Opera) oder STRG-D (Safari) um diese Seite Ihren Favoriten hinzuzufügen.");
  }
}
