/*
  $Id: $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2007 osCommerce

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License v2 (1991)
  as published by the Free Software Foundation.
  WJR aanpassingen aan het script omdat de for...in... loops
  bij IE anders werken
*/

function refreshVariants() {
  var price = null;
  var availability = null;
  var model = null;
  var id = null;

  for (c in combos) {
	if (isNaN(c)) continue;
    id = null;

    variants_loop:
    for (group_id in combos[c]['values']) {
	  if (isNaN(group_id)) continue;
      for (value_id in combos[c]['values'][group_id]) {
		if (isNaN(value_id)) continue;
        if (document.getElementById('variants_' + group_id) != undefined) {
          if (document.getElementById('variants_' + group_id).type == 'select-one') {
            if (value_id == document.getElementById('variants_' + group_id).value) {
              id = c;
			} else if ("custom" == document.getElementById('variants_' + group_id).className) {
              id = c;
            } else {
              id = null;

              break variants_loop;
            }
          }
        } else if (document.getElementById('variants_' + group_id + '_1') != undefined) {
          j = 0;

          while (true) {
            j++;

            if (document.getElementById('variants_' + group_id + '_' + j).type == 'radio') {
              if (document.getElementById('variants_' + group_id + '_' + j).checked) {
                if (value_id == document.getElementById('variants_' + group_id + '_' + j).value) {
                  id = c;
				} else if (custom_value == document.getElementById('variants_' + group_id + '_' + j).value) { 
                  id = c;
                } else {
                  id = null;

                  break variants_loop;
                }
              }
            }

            if (document.getElementById('variants_' + group_id + '_' + (j+1)) == undefined) {
              break;
            }
          }
        }
      }
    }

    if (id != null) {
      break;
    }
  }

  if (id != null) {
    price = combos[id]['price'];
    availability = productInfoAvailability;
    model = combos[id]['model'];
  	for (c in combos) {
		if (isNaN(c)) continue;
    	for (group_id in combos[c]['values']) {
			if (isNaN(group_id)) continue;

			var valid = false;
			for (vg in combos[id]['values']) {
				if (isNaN(vg)) continue;
				if( vg == group_id ) {
					valid = true;
					break;
				}
			}
			if( document.getElementById('block_variants_' + group_id) ) {
				if( valid )
					document.getElementById('block_variants_' + group_id).style.display = 'block';
				else
					document.getElementById('block_variants_' + group_id).style.display = 'none';
			}
		}
	}
  } else {
    price = originalPrice;
    availability = productInfoNotAvailable;
    model = '';
  }

  if(document.getElementById('productInfoPrice') != null ) {
  document.getElementById('productInfoPrice').innerHTML = price;
  }
  if(document.getElementById('productInfoAvailability') != null ) {
  document.getElementById('productInfoAvailability').innerHTML = availability;
  }
  if(document.getElementById('productInfoModel') != null ) {
  document.getElementById('productInfoModel').innerHTML = model;
  }
}

