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;
  if ( lb == 'on' || ( the_lightbox && measure2num(the_lightbox.style.height) > 0 ) ) {
    lb_height = measure2num(getLbHeight() ) + 20 ;
  }
  con_height  = win_height - (nav_height + foot_height + lb_height + 20); 
  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 = 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();
   $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 +"&amp;transid=" + transid + "&amp;basket_action=add_note"
                    });
 }
 
 function hideIt() {
	  document.getElementById("srPrev").style.display = "none";
	}
	function preLoadImages(){
	  var myimages = new Array(preLoadImages.arguments.length);
	  for (i=0;i<preLoadImages.arguments.length;i++) {
	    myimages[i]=new Image()
	    myimages[i].src=preLoadImages.arguments[i]
	  }
	}
	 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();
	            },
	    removeEventhandler: function(event) {
	       switch (event) {
	         case 'onmouseover':
	         case 'mouseover':
	            this.each(function(item) { var thefunction = item.onmouseover; item.onmouseover = ''; });
	            break;
	         default:
	          alert(event + "not yes handeled. Edit default.js");
	       }
	       
	     }
	}
	function add_selected_to_basket( thelink ) {
	  var theForm = document.forms['lightbox_action'];
	  var checked_Images = Form.serializeElements( $(theForm).getInputs('checkbox', 'imagesid') );
	  thelink.href = thelink.href.replace(/(\?)(.*)/, "");
	  thelink.href += "?basket_action=add_many&amp;"+checked_Images;
	  return true;
	  // KISS, baby, KISS, wir brauchen hier keinen AJAX Request
	/*
	  new Ajax.Updater($(parent.frames['basketinfo'].document.getElementById('progress')), '/basketinfo.ep', 
	                   { parameters: {basket_action: "add_many"},
	                     postBody: checked_Images+"&basket_action=add_many",
	                     evalScripts: true
	                    });
	  return false;  
	  */ 
	}

	function enlargeElementWidth (elId) {
	  document.getElementById(elId).style.width='200px';
	  return false;
	}


