/* used for redirection if content directory is called directly */
  function redirect() { 
    var URL = window.location.pathname;
    URL = URL.substr(0,URL.lastIndexOf("/"));  /* w/o filename */
    URL = URL.substr(1,URL.length);
    if(URL.indexOf("/") == -1) {
      URL = "";
    } else { 
      URL = URL.substr(URL.indexOf("/"), URL.length);
    };
  window.location.replace("/cgi-bin/content-page.cgi?path=" + URL ); 
  };

/* used to switch pictures in edit mode */
  function ChangePic(no) {
    var start_pictures = 0;
    var no_objects = 5;

    start_pictures = -1; 
    do {
      start_pictures++; 
      element_name = document.form1.elements[start_pictures].name;
    } while( element_name != "PictureSelect1" );

     elem_idx = start_pictures + no_objects*(no-1)
     with(document.form1) {
       sel_idx = elements[elem_idx].selectedIndex;

       if (sel_idx == elements[elem_idx].length-1) {           /* last index = absolute link */
         newsrc = elements[elem_idx+1].value;
       } else {

          elements[elem_idx+1].value = "";
          if (sel_idx == 0) {					/* first index = no picture */
            newsrc = "/global/platzhalter.gif";
          } else {
            newsrc = elements[elem_idx].options[sel_idx].text;
          };
       };

     };

     var shortname_newsrc = newsrc;

     if (newsrc.substr(0,4) == "http") {
       /* don't change link */

     } else {
       if( newsrc.substr(0,1) == "/" ) {
         newsrc = "http://" + window.location.hostname + newsrc;
       } else {
         newsrc = "http://" + document.form1.WebPath.value + "/" + newsrc;
       };
     };

     new_pic = new Image();
     new_pic.src = newsrc;
    
     now = new Date();
     start = now.getTime();

     do {
       now = new Date();
     } while( (new_pic.height == 0) && (now.getTime() - start < 2000) && (shortname_newsrc != "") );
     /* dont wait too long */

     var w, h, ratio, comment = "\n--- Anzeige verkleinert: ", square_length = 200;

     if(  new_pic.width == 0 ) {
       w = square_length; h = square_length;
     } else {
       if ( new_pic.width > square_length || new_pic.height > square_length ) {
         ratio = new_pic.height / new_pic.width;

         if (ratio > 1) {
           h = square_length; w = parseInt( square_length / ratio );
         } else {
           w = square_length; h = parseInt( square_length * ratio );
         };
         comment = comment + String( Math.round(100 * w / new_pic.width) ) + "%";
       } else {
         w = new_pic.width; h = new_pic.height; comment = "\n--- Anzeige in Originalgröße";
       };
     };

     status_line = "--- GRAFIK: " + shortname_newsrc + " \n--- BREITE: " + new_pic.width +  "  --- HÖHE: " + new_pic.height;

     with (document.images[no-1]) {
       width = w;
       height = h;
       src = new_pic.src;
       if (shortname_newsrc == "") {
         alt = "kein Bild ausgewählt";
       } else { 
         alt = status_line + comment;
       };
     };
  };

/* initialise picture sizes in edit mode */
  function InitialisePics() {
    with(document.form1) {
      for (i = 1; i <= NumberPictures.value-2; i++) {
        ChangePic(i);
      };
    };
  };


/* used to reload the document after submitting a form and returning to it */

function force_reload() {
  if ( document.ReloadForm ) {
    document.ReloadForm.Reload.value='1';
  };
};

function reload_request() {
  if ( document.ReloadForm ) {
    if ( document.ReloadForm.Reload.value == '1' ) {
      window.location.reload();
    };
  };
};

function load( url, target ) {
  if(target == 1) {
	newwin = window.open(url,"extern","");
  } else {
      location.href=url;
      statuswin = window.open("/global/loading.html","Fenster1","width=200,height=100,screenX=0,screenY=0");
      statuswin.focus();
  }
};

function goodbye() {
/*  window.open("/global/goodbye.html",""); */
};

/* popup-window */

function winpopup( url ) {
/*
  popupwin = window.open(url,"Popup","locationbar=no,status=no");
*/
  popupwin = window.open(url,"Popup","width=200,height=100,screenX=0,screenY=0");
  popupwin.focus();
};

  
function popup_resize( aktiv ) {
  if(document.images[0].complete == true) {
    window.resizeTo(document.images[0].width + 30, document.images[0].height + 100);
    window.clearInterval(aktiv); 
  }
  
};

