function collectElementbyClass (classname){ //Returns an array containing DIVs with specified classname
	var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element
	var pieces=[]
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (var i=0; i<alltags.length; i++){
		if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1)
			pieces[pieces.length]=alltags[i]
	}
	return pieces
}

togglePrices = {}

togglePrices.toggle_visiblility = function (strSection, objSelect) {
  switch (strSection) {
    case 'type':
      this._type = objSelect.options[objSelect.selectedIndex].value      
      break;
    case 'period':
      this._period = objSelect.options[objSelect.selectedIndex].value     
      break;    
  }
   
 	for (var i = 0; i < this.prices.length; i++){
   value = eval('arr'+this._type+this._period+'['+this.prices[i].attributes.name.value+']')
   value = (isNaN(value)) ? '' : value; 
   this.prices[i].innerHTML = value    
  }
  
  bannerPrices.resum()

}
togglePrices.init = function (typeSelectID, periodSelectID, className) {
  this.prices = collectElementbyClass(className)

  objType = document.getElementById(typeSelectID)
  objPeriod = document.getElementById(periodSelectID)

  this._type = objType.options[objType.selectedIndex].value
  this._period = objPeriod.options[objPeriod.selectedIndex].value 
  
  objType.onchange = function (){togglePrices.toggle_visiblility('type', objType)} 
  objPeriod.onchange = function (){togglePrices.toggle_visiblility('period', objPeriod)}    
  
}



bannerPrices = {}

bannerPrices.resum = function () {
  sum = 0
 	for (var i = 0; i < this.boxes.length; i++){
    if(this.boxes[i].checked == true) {
    value = eval('arr'+togglePrices._type+togglePrices._period+'['+this.boxes[i].value+']')
    sum += (isNaN(value)) ? 0 : value;
    }
  }
  this.objInput.value =  sum
  sum = (sum > 0)? sum : '';
  this.objField.innerHTML = sum + ' EEK'  
}

bannerPrices.sum = function (obj) {

  var value = 0
   value = eval('arr'+togglePrices._type+togglePrices._period+'['+obj.value+']')
   value = (isNaN(value)) ? 0 : value; 
  
  if(obj.checked == true) {
    value = - value
  }else {
    value = + value
  }
  
  sum = (this.objInput.value.length > 0)? eval(this.objInput.value) : 0
  this.objInput.value =  sum + value
  this.objField.innerHTML = sum + value + ' EEK' 


}

//checkboxes parent id and dest tag id
bannerPrices.init = function (className, valueFieldID) {
  
//  parent = document.getElementById(parentID)    
//  this.boxes = parent.getElementsByTagName('input');
   this.boxes = collectElementbyClass(className)
  this.objField = document.getElementById(valueFieldID)
  this.objInput = document.getElementById(valueFieldID+'_sum')
  
  
// 	for (var i = 0; i < this.boxes.length; i++){
//    this.boxes[i].onchange = function (){bannerPrices.sum(this)}
//  }

    
}

/*bannerPrices = {}

bannerPrices.resum = function () {

  sum = 0
 
 	for (var y = 0; y < this.boxes.length; y++){
    if(this.boxes[y].checked == true) {
      spans = this.boxes[y].parentNode.getElementsByTagName('span')
    	for (var i = 1; i < spans.length; i++){
        if (spans[i].attributes.name.value == togglePrices._prefix + '_' + togglePrices._type + '_' + togglePrices._period) {
          sum += (spans[i].innerHTML.length > 0)? eval(spans[i].innerHTML) : 0
        }
      }
    }
  }
  sumto = (sum > 0)? sum : '';
  this.objField.innerHTML = sumto
}

bannerPrices.sum = function (obj) {

  var value = 0
  spans = obj.parentNode.getElementsByTagName('span')
	for (var i = 1; i < spans.length; i++){
    if (spans[i].attributes.name.value == togglePrices._prefix + '_' + togglePrices._type + '_' + togglePrices._period) {
      value = (spans[i].innerHTML.length > 0)? eval(spans[i].innerHTML) : 0    
    }
  }
  

  
  if(obj.checked == true) {
    value = + value
  }else {
    value = - value
  }
  
  sum = (this.objField.innerHTML.length > 0)? eval(this.objField.innerHTML) : 0
  this.objField.innerHTML = sum + value 


}
*/


