var isIE = document.all?true:false;
var isMac = navigator.platform.toLowerCase().indexOf('mac') >= 0?true:false;  
var isFF = navigator.userAgent.toLowerCase().indexOf('firefox') >= 0?true:false;  
var isSafari = navigator.userAgent.toLowerCase().indexOf('safari') >= 0?true:false;

function preview(imagesid,resultid) {
  var param = '';
  if ( typeof imagesid != 'undefined' ) {
    if ( typeof resultid != 'undefined' ) {
      if ( resultid == 'lightbox' ) {
        param = 'imagesid='+imagesid+'&from_lightbox=1';
      }
      else {
        param = 'imagesid='+imagesid+'&resultid='+resultid;
      }
    } else {
      param = 'imagesid='+imagesid;
    }
  } 
 var winHandle = window.open('/preview.ep?'+param, ''+imagesid+'' , 'toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width=850, height=600, dependent' );
winHandle.focus();
 
}

function windowheight() {
  if ( window.innerHeight )  { // all except Explorer
    return window.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    return document.documentElement.clientHeight;
  }
  else if (document.body) { // other Explorers
    return document.body.clientHeight;
  }
 else return 0;
}
function windowwidth() {
  if ( window.innerWidth )  { // all except Explorer
    return window.innerWidth;
  }
  else if (document.documentElement && document.documentElement.clientWidth) { // Explorer 6 Strict Mode
    return document.documentElement.clientWidth;
  }
  else if (document.body) { // other Explorers
    return document.body.clientWidth;
  }
 else return 0;
}

function resizeStatic2 ( lb ) {
  var nav_height  = document.getElementById("Static1")?document.getElementById("Static1").offsetHeight:0;
  var foot_height = document.getElementById("Static3")?document.getElementById("Static3").offsetHeight:0;
  the_lightbox    = document.getElementById('lightbox');
  var win_height  = windowheight();
  
  var lb_height   = 0;
  var con_height = 0;
  
  var bug = 20;

  if ( lb == 'on' || ( the_lightbox && measure2num(the_lightbox.style.height) > 0 ) ) {
    lb_height = measure2num(getLbHeight() ) + bug ;
  }

  con_height  = win_height - (nav_height + foot_height + lb_height + 0); 
  
  document.getElementById("Static2").style.height = con_height + "px";

/* alert ( "nav_h: " + nav_height  + "\n" + 
   "foot_h: " + foot_height + "\n" + 
    "win_h: " + win_height  + "\n" + 
     "lb_h: " + lb_height   + "\n" + 
      "cookie: " + getCookie("userheight") + "\n" +
  "Übrig: " + document.getElementById("Static2").style.height ); */
  return true;
}
function measure2num ( the_value ) {
  var zahl = parseInt( the_value );
  if ( isNaN( zahl ) ) {
    return false ;
  } else {
    return zahl; 
  }
}
function toggle_all ( formname, boxname ) {
  if ( document.forms[formname].elements[boxname] ) { // gibt es überhaupt eine?
    if ( document.forms[formname].elements[boxname].length ) { // gibt es mehrere?
      i = document.forms[formname].elements[boxname].length;
      for ( n = 0; n < i; n++ ) {
        document.forms[formname].elements[boxname][n].checked = document.forms[formname].elements[boxname][n].checked?false:true
      }  
    } else {  // nur eins
      document.forms[formname].elements[boxname].checked = document.forms[formname].elements[boxname].checked?false:true;;
    }
  } 
}
function update_lightbox ( action , theItem ) {
   var source_lightbox = this.document.forms['lightbox_change'].elements['change_lightbox'].value;
   var dest_lightbox = '';
   switch (action) {
     case 'move':
       dest_lightbox = document.getElementById('to_lb2').value;
       break;
     case 'copy':
       dest_lightbox = document.getElementById('to_lb').value;
       break;
     case 'del_many':
   }
   if ( source_lightbox == dest_lightbox ) {
     return false;
   }
   var theForm = document.forms['lightbox_action'];
   theForm.elements['lbtool_action'].value = action;
   theForm.elements['to_lb'].value = dest_lightbox;
   var targets = new Array();
   var checked_Images = $(theForm).getInputs('checkbox', 'imagesid');
   checked_Images.map( function (val) {if (val.checked) { targets.push( theItem + val.value) } } );
/*   $A(theForm.elements['imagesid']).map( function (val) { if (val.checked) { targets.push( theItem + val.value) } } );*/
   
   var toUpdate = $(parent.frames['basketinfo'].document.getElementById('progress') );
   new Ajax.Request( '/funcs/func_lbtool.ep', { onComplete: function(req){ toUpdate.innerHTML = req.responseText },
                                                asynchronous:true, 
                                                parameters:Form.serialize(theForm)});

   switch (action) {
     case 'del_many':
     case 'move':
       targets.map (function ( item ) { Effect.Fade(item) }); 
       break;
     case 'copy':
       targets.map (function ( item ) { Effect.Pulsate(item,{pulse: 2, duration: 1, from: 0.7}) });
       break;
   }
   return false;
 }
 function update_basket_note ( transid ) {
  var note = $F('basket_note_' + transid);
  new Ajax.Updater($(parent.frames['basketinfo'].document.getElementById('progress')), '/funcs/func_basket.ep', 
                   { parameters: {basket_note: note , transid: transid, basket_action: "add_note"}
                    });
  parent.window.frames["basketinfo"].blink(true);
  parent.window.frames["basketinfo"].clear_progress();
 }
var ListFuncs = {
    findByImageId : function(imageid) {
                      return this.find(function(item){
                           return item.id.match(imageid);
                      });
                    },
    highest: function() {
              return this.sortBy(function(item) {
                return item.getHeight();
                }).last();
  }
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) {
    if ((obj=MM_findObj(args[i]))!=null) { 
      v=args[i+2];
      var submenu = document.getElementById(obj.id + '_submenu');
      var overflowStyle = ''; 
      if (obj.style) { 
      
        obj=obj.style; 
        if (v=='show') {
          v = 'visible';
          overflowStyle = "auto";      
        }
        if (v=='hide' ) {
          overflowStyle = "hidden";
          v = 'hidden';
        }
      }
      if ( submenu ) {
        submenu.style.overflow = overflowStyle;
        try { // force Safari to rerender:       
         var n = document.createTextNode('dummy'); // must be non whitespace
          submenu.appendChild(n);
          submenu.removeChild(n);
        } catch(e) { }
      }
      obj.visibility=v; 
    }
    
  }
}

function check4lbaction(elem) {
  if ( $F(elem) == 'create' ) {
    top.location.href="/index.ep?page=lbtool&amp;lbtool_action=create";
    return false;
  }
  if ( $F(elem) == '' || $F(elem) == null ) { // IE kann noch immer nicht "disabled"
    return false;
  }
  document.getElementById('lightbox_change').submit();
}
