// Java Script Datei 
// Dateiname: gvsFramesetToggle.js
// Autor: Dr. Peter Fabi

//---------------------------------------------------------------------------------
// function ForceHostToHomeUrl()
//---------------------------------------------------------------------------------
   function ForceHostToHomeUrl(){
        var host=self.location.href;
        alert("host="+host);
    
      if(parent != null && parent != self) {
        host=parent.location.hostname;
        alert("host="+host);
        if(host != "http://www.geschichtsverein-setterich.de") {
          top.location.href=self.location.href;
        }
      } 

   }
//---------------------------------------------------------------------------------
// function GetParameterFromURL(url, parametername)
//---------------------------------------------------------------------------------
   function GetParameterFromURL(url, parametername){
      res = '';
      s = url;
      if(s.indexOf('?') != -1){s = s.substring(1,s.length)}
      while(s != ''){
         b = s.substring(0,s.indexOf('='));
         c = s.substring(s.indexOf('=')+1,s.indexOf('&'));
         if(s.indexOf('&') == -1){c = s.substring(s.indexOf('=')+1,s.length);}
         if(b == parametername){res = c; break;}
         if(s.indexOf('&') == -1){s = '';}
         else{s = s.substring(s.indexOf('&')+1,s.length)}
      }      
      return unescape(res);
   }   

//---------------------------------------------------------------------------------
// function printPage(frame, arg)
//---------------------------------------------------------------------------------
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage(frame, arg) {
  if (frame == window) {
    printThis();
  } else {
    link = arg; // a global variable 
    printFrame(frame);
  }
  return false;
}

function printThis() {
  if (pr) { // NS4, IE5
    window.print();
  } else if (da && !mac) { // IE4 (Windows)
    vbPrintPage();
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

function printFrame(frame) {
  if (pr && da) { // IE5
    frame.focus();
    window.print();
    link.focus();
  } else if (pr) { // NS4
    frame.print();
  } else if (da && !mac) { // IE4 (Windows)
    frame.focus();
    setTimeout("vbPrintPage(); link.focus();", 100);
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

//---------------------------------------------------------------------------------
// function InFrameZurueck(fname)
//---------------------------------------------------------------------------------
	function InFrameZurueck(fname) {
     	   parent.frames[fname].history.back();
  	} 
//---------------------------------------------------------------------------------
// function InFrameVor(fname)
//---------------------------------------------------------------------------------
	function InFrameVor(fname) {
     	   parent.frames[fname].history.forward();
  	} 
//---------------------------------------------------------------------------------
// function SetFrameWithWindowSize(url,framename,fsid,fstyp,vtyp,size,unit) {
//---------------------------------------------------------------------------------
  	function SetFrameWithWindowSize(url,framename,fsid,fstyp,vtyp,size,unit) {
          SetFrame(url,framename);
     	  WindowSize(fsid,fstyp,vtyp,size,unit);
  	}
//---------------------------------------------------------------------------------
// function ReplaceFrame(url,framename)
//---------------------------------------------------------------------------------
	function ReplaceFrame(url,framename) {
            parent.frames[framename].location.replace(url);
 	}
//---------------------------------------------------------------------------------
// function SetFrame(url,framename)
//---------------------------------------------------------------------------------
	function SetFrame(url,framename) {
           parent.frames[framename].location.href=url;
 	}
//---------------------------------------------------------------------------------
// function WindowSize(fsid,fstyp,vtyp,size,unit)
// fsid   = frameset ID
// fstyp  : 'cols' oder 'rows'
// vtyp   : 'f*v', '*fv', etc
// size   : 0 ... 100, mit size in unit='%','pt', ...
//---------------------------------------------------------------------------------
	function WindowSize(fsid,fstyp,vtyp,size,unit) {
           size *= 1; // size als Zahl konvertieren
	   ToggleWindowSize(fsid,fstyp,vtyp,size,size,unit);  
 	}
//---------------------------------------------------------------------------------
// function WindowResize(fsid,fstyp,vtyp,c,delta,unit)
// fsid   = frameset ID
// fstyp  : 'cols' oder 'rows'
// vtyp   : 'f*v', '*fv', etc mit f=fixed, *=Stern, v=variablel
// c      : '+' oder '-' mit '+'=vergroessern, '-'=verkleinern
// delta  : 0 ... 100, vergroessern bzw vekleinern um delta units
//---------------------------------------------------------------------------------
	function WindowResize(fsid,fstyp,vtyp,c,delta,unit) {
	   var nr=GetNr(fsid,fstyp,vtyp,unit);
           nr *= 1;  // nr als Zahl konvertieren    
	   if (c=='+') 
	      nr += delta;
	   else
              nr -= delta;
           if (unit=='%') {
              if (nr<20)  nr = 20;
              if (nr>100) nr = 100;
           }
	   SetNr(fsid,fstyp,vtyp,nr,unit);  
 	}
//---------------------------------------------------------------------------------
// function ToggleWindowSize(fsid,fstyp,vtyp,maxunit,minunit,unit)
// fsid   = frameset ID
// fstyp  : 'cols' oder 'rows'
// vtyp   : 'f*v', '*fv', etc
// maxunit: max units
// minunit: min units aber mit maxunit >= minunit
//---------------------------------------------------------------------------------
	function ToggleWindowSize(fsid,fstyp,vtyp,maxunit,minunit,unit) {
	   var nr=GetNr(fsid,fstyp,vtyp,unit);		  
  	   if(nr==0) 
              SetNr(fsid,fstyp,vtyp,maxunit,unit);		  
	   else 
              SetNr(fsid,fstyp,vtyp,minunit,unit);		  
	}

 	function GetNr(fsid,fstyp,vtyp,unit) {
  	   if(vtyp.charAt(0)=='v')    
	      var nr=GetFirstNr(fsid,fstyp,unit);		  
           if(vtyp.charAt(1)=='v') 
	      var nr=GetMiddleNr(fsid,fstyp,unit);
	   if(vtyp.charAt(2)=='v') 
	      var nr=GetLastNr(fsid,fstyp,unit);
	   return nr;
	}

 	function SetNr(fsid,fstyp,vtyp,nr,unit) {
	   if(vtyp.charAt(0)=='v') 
	      SetNrA(0,fsid,fstyp,nr,unit);		  
	   if(vtyp.charAt(1)=='v') 
	      SetNrA(1,fsid,fstyp,nr,unit);
	   if(vtyp.charAt(2)=='v') 
	      SetNrA(2,fsid,fstyp,nr,unit);
	}

 	function SetNrA(atyp,fsid,fstyp,nr,unit) {
                var nrfirst  = GetFirstNr(fsid,fstyp,unit);
                var nrmiddle = GetMiddleNr(fsid,fstyp,unit);
                var nrlast   = GetLastNr(fsid,fstyp,unit);
                if(atyp==0) nrfirst  = nr;
                if(atyp==1) nrmiddle = nr;
                if(atyp==2) nrlast   = nr;
                
                var s = FormatNr(nrfirst,nrmiddle,nrlast,unit);
                
		if((nr==100) && (unit=='%')) {
		   var styp=0;
		   if(nrfirst=='*')  styp+=1;
		   if(nrmiddle=='*') styp+=10;
		   if(nrlast=='*')   styp+=100;
                   s=Korrekt100(styp,atyp,nrfirst,nrmiddle,nrlast,unit);
                }

  	        if(fstyp=='cols')  	             
		   top.document.getElementById(fsid).cols = s;
                else
   	           top.document.getElementById(fsid).rows = s;
 	}

        function Korrekt100(styp,atyp,n1,n2,n3,unit) {
             if(unit=='%') {
                // es wird nur auf ein * korrigiert !
                if((styp!=1) || (styp!=10) || (styp!=100)) {
                   return FormatNr(n1,n2,n3,unit);   
                } 
                if(styp==1) {
                   //nur First=*
                   n2*=1; n3*=1;
                   if(atyp==1) {if(n2+n3>100) n2=100-n3;}                 
                   if(atyp==2) {if(n2+n3>100) n3=100-n2;}                 
                } 
                 if(styp==10) {
                   //nur Middle=*
                   n1*=1; n3*=1;
                   if(atyp==0) {if(n1+n3>100) n1=100-n3;}                 
                   if(atyp==2) {if(n1+n3>100) n3=100-n1;}                 
                } 
                if(styp==100) {
                   //nur Last=*
                   n1*=1; n2*=1;
                   if(atyp==0) {if(n1+n2>100) n1=100-n2;}                 
                   if(atyp==1) {if(n1+n2>100) n2=100-n1;}                 
                } 
             }
             return FormatNr(n1,n2,n3,unit);
        }

        function FormatNr(n1,n2,n3,unit) {
           var s = n1+unit+","+n2+unit+","+n3+unit;
           return s;
        }

 	function GetFirstNr(fsid,fstyp,unit) {
	    	if(fstyp=='cols')
		   var s=top.document.getElementById(fsid).cols;
		else
		   var s=top.document.getElementById(fsid).rows;
		var posProz=FindFirstCharPos(s,unit.charAt(0));
		var value = "";
		if(posProz >= 1) {
		    value=s.substring(0,posProz);                      			
                    if (value=="")
		       value="*"; //*-Zeichen holen                        			
		} 
		return value;
	}
 
 	function GetLastNr(fsid,fstyp,unit) {
	    	if(fstyp=='cols')
		   var s=top.document.getElementById(fsid).cols;
		else
		   var s=top.document.getElementById(fsid).rows;
		var posProz=FindLastCharPos(s,unit.charAt(0));
		var posKomma=FindLastCharPos(s,',');
		var value = "";
		if((posProz >= 1) && (posKomma >= 1) && (posKomma<s.length-1)) {
	           value=s.substring(posKomma+1,posProz);
                   if (value=="")
  	              value="*"; //*-Zeichen holen                    			                       
		} 
                //window.status=value;
		return value;
	}

 	function GetMiddleNr(fsid,fstyp,unit) {
	    	if(fstyp=='cols')
		   var s=top.document.getElementById(fsid).cols;
		else
		   var s=top.document.getElementById(fsid).rows;
                //window.status=s;
		var posFirstKomma=FindFirstCharPos(s,',');
		var posLastKomma=FindLastCharPos(s,',');
		var value = "";
		if((posFirstKomma >= 1) && (posLastKomma >= 1) && (posFirstKomma<s.length-1)) {
			value=s.substring(posFirstKomma+1,posLastKomma-unit.length); //-1 wegen %-Zeichen
                        if (value=="")
  			   value="*"; //*-Zeichen holen
                        //window.status=s+':'+value;			
		} 
		return value;
	}

 	function FindFirstCharPos(s,c) {
	   if(s.length==0) {return -1;}
	   else {
	  	   for(i=0; i<=s.length-1; i++) {
		      if(s.charAt(i)==c)
			return i;
		   }
		   return -1;
		}
 	}
 	
 	function FindLastCharPos(s,c) {
	   if(s.length==0) {return -1;}
	   else {
	  	   for(i=s.length-1; i>0; i--) {
		      if(s.charAt(i)==c)
		         return i;
		   }
		   return -1;
		}
 	}

