/***************************************************/
/*                                                 */
/* ---         © 2007 Kupferwerk GmbH          --- */
/*                                                 */
/* --- Standard CSS File for new Ruby projects --- */
/*                                                 */
/***************************************************/

/*
 * This file is available all over the project.
 *
 */


/*
 *
 * Browser Weiche
 * © 8/2002, 9/2005 Kristof Lipfert Duesseldorf
 *
 */

var d_version = 20070627;

var x = [];
if(document.ids) {
	x = ['nc4', 'Netscape Navigator 4'];
	if(!window.navigator.securityPolicy) x[1] += '.0'; else x[1] += '.5-4.8';
}
else if(document.all && !$) {
	if(!document.layers) x = ['ie4', 'Internet Explorer 4']; else x = ['ow4', 'OmniWeb 4.x'];
}
else if(window.opera && !document.createElement) x = ['op5', 'Opera 5'];
else if(window.opera && window.getComputedStyle) {
	if(window.getSelection) x = ['op9', 'Opera 9'];
	else if(document.createRange) x = ['op8', 'Opera 8'];
	else if(window.navigate) x = ['op75', 'Opera 7.5']; else x = ['op72', 'Opera7.2'];
}
else if(window.opera && document.compatMode) x = ['op7', 'Opera 7'];
else if(window.opera && document.releaseEvents) x = ['op6', 'Opera 6'];
else if(document.contains && !window.opera) {
	x = ['kq3', 'Safari / Konqueror 3'];
	x[1] += window.print ? '.1/.2' : '.0';
	if(document.compatMode) x[1] = 'kq3.4';
}
else if(window.pkcs11 && window.XML) x = window.external ? ['f20', 'Firefox 2 - Gecko'] : ['f15', 'Firefox - Gecko Deer Park '];
else if(window.pkcs11 && document.compatMode) x = ['nn7', 'Mozilla - Firefox - Gecko '];
else if(window.atob && document.defaultCharset) x = ['sf3', 'Safari 3'];
else if(window.getSelection && window.atob) x = ['nn7', 'Mozilla - Gecko'];
else if(window.getSelection && !document.compatMode) x = ['nn6', 'Netscape 6 - Mozilla Beta'];
else if(window.clipboardData && document.compatMode) {
	x = window.XMLHttpRequest ? 7 : 6;
	x = ['ie' + x, 'Internet Explorer ' + x];
}
else if(window.clipboardData) {
	x = ['ie5', 'Internet Explorer 5.0']; 
	if(!document.createDocumentFragment) x = ['ie5.5', 'Internet Explorer 5.5'];
}
else if(document.doctype && !window.print ) x = ['ie5m', 'Internet Explorer 5Mac'];
else if($ && !document.all) {
	x[0] = 'op4';
	x[1] = 'Opera 4';
	if(!window.RegExp) x[1] += '.0'; else x[1] += '.1';
}
else if(document.images && !document.all) x = ['nn3', 'Netscape Navigator 3'];
else if(!document.images) x = ['2-3', 'NS 2, IE 3'];
else if(document.clientWidth && !window.RegExp) x = ['kq2', 'Safari - Konqueror 2'];
else x = ['???', 'undefined'];



/*
 *
 * function to show the overlay
 * KE 
 */
function togglePopup(url) {   
  var overlay = $('overlay');
  if (overlay.visible() && url) {
    // hide popup
    overlay.fade({
      duration: 0.4,
      afterFinish: function(){
        overlay.update('');
        hideOrShowPopup(url);
      }
    });
  } else {
    hideOrShowPopup(url);
  };
  return false;
}

function hidePopup() {
  overlay.fade({
    duration: 0.4,
    afterFinish: function(){
      overlay.update('');
    }
  });
}

function hideOrShowPopup(url) {
  var overlay = $('overlay');  
  if (url) {
    var D = document;
    var height = Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
    overlay.setStyle({height: height + 'px'});
	  new Ajax.Updater('overlay', url, {
	    asynchronous:true, 
	    evalScripts:true, 
	    onComplete:function(){
	      overlay.show();
	      container = overlay.down('.overlay-container');
        container.setStyle({
                top: (document.viewport.getScrollOffsets().top + (document.viewport.getHeight() / 2) - container.getHeight() / 2) + 'px',
                left: (document.viewport.getWidth() / 2 - container.getWidth() / 2) + 'px'
            });
        overlay.hide();
        overlay.appear({ duration: 0.4 });
	    } 
	  });
  } else {
    // hide popup
    overlay.fade({
      duration: 0.4,
      afterFinish: function(){
        overlay.update('');
      }
    });
  }
  
  return false;
}

function test_order(order_item){
var checked = false;
  $('delete_order_addresses_form_' + order_item).select('input[type="checkbox"]').each(function(item) {
	if(item.checked) {
		checked = true;
	}

   });
   if (checked) {
     togglePopup('/checkout/show_confirm_delete_orderaddresses_popup?orderitem_id=' + order_item);		
   }
   else {
     togglePopup('/checkout/show_standard_error_popup?type=no_address_selected');	
   }
}


// global counter for charCount()
var max = 0;

//charCounter for the comment-limiter
// maxPos: maxNumber of chars 
function charCount(e, maxPos, textarea_name, span_name) {
  max = maxPos;
  keyCode = e.which; // nn6+

  if ($(textarea_name).value.length<max+1){
	if (span_name != ''){
      $(span_name).innerHTML = ' (max. ';
      $(span_name).innerHTML += max-$(textarea_name).value.length + ' Zeichen)';
    }
  }
  else {
    $(textarea_name).value = $(textarea_name).value.substring(0,max);
    if (span_name != ''){
      $(span_name).innerHTML = ' (max. 0 Zeichen)';
    }
  }
}


// checks if one Checkbox is checked
function isCheckboxChecked(name)
{
  var bool = false;
  if($(name)) {
  	if($(name).checked == true) {
	     bool = true;
	     return true;
	  }
   }  
  return bool;
}


// draws the rating_points active
function showPoints(name, client) {
  for(i=1; i < name+1; i++) {
    document.getElementById('point_' + i).src='/images/new_layout/star/yellow.jpg';
  }
}

// draws all rating_points inactive
function clearPoints() {
  for(i=1; i < 6; i++) {
    document.getElementById('point_' + i).src='/images/new_layout/star/grey.jpg';
  }
}


// changes the class-name  
function toggleClass(object_id, condition, class_1, class_2) {
  if(condition)
    $(object_id).className = class_1;
  else
	$(object_id).className = class_2;
}


// checks which option of the selected field is selected
function checkDropdownOption(feld){
  return $(feld).value;	
}


// clears the search input field, if the value is 'Suche' 
function clearSearchInput(feld){
  if ($(feld).value == "Suche")
    $(feld).value = "";
}


// clears the price input field, if the value is '0.00'
function clearPriceInput(feld){
  if ($(feld).value == "0.00")	
    $(feld).value = "";
}

// jumps on select from startpage
function jump_to_bundle_from_select(field){
	val= field.getValue();
	document.location ="/shop/detail/"+val;
}

// Array with active checkboxes
active_checkboxes = [];

// saves checked checkboxes in an array
function saveCheckedItems(inputs) {
  inputs.each(function(input) {
    if (input.checked) {
      active_checkboxes.push(input.id);
    };
  })
}

// checks saved checkboxes
function checkSavedCheckboxes(inputs) {
  inputs.each(function(input) {
    if (active_checkboxes.indexOf(input.id) != -1) {
      input.checked = true;
      input.up('tr').toggleClassName('checked');
    };
  })
  active_checkboxes = [];
}