/**

* Checks that any attributes have been selected properly, and modifies price as necessary

*/

function checkAttributes( form, ids, msg ){

  var bValid = true;

  var oFocus;

  var obj;



  for( i in ids ){

    obj = form[ids[i]];

    if( obj.options[obj.selectedIndex].value == '' ){

      if( bValid ){

        bValid = false;

        oFocus = obj;

      }

      obj.style.backgroundColor = '#ff8080';

    }else{

      obj.style.backgroundColor = '#ffffff';

    }

    if( !bValid ){

      if( msg != '' ){

        alert(msg);

      }

      oFocus.focus();

      return false;

    }

  }

  if( !bValid ){

    if( msg != '' ){

      alert(msg);

    }

    oFocus.focus();

    return false;

  } else {

    gEBI('iPrice').value = gEBI('price').value;

    return true;

  }

} // end function checkAttributes

/**

* Checks each attribute select and adjusts the display price

*/

function checkAttributes_Offset(obj){

  var aOff = attributeOffsets;

  aOff[obj.name][1] = false;

  if( obj.options[obj.selectedIndex].value == '' ){aOff[obj.name][0] = 0;}

  else{

    var pattern = /[+|-]\d+[\.]\d+%?/g;

	  var result = obj.options[obj.selectedIndex].text.match(pattern);

  	if( result != null ){

      var offset = result[result.length-1];

      if( offset.substr(offset.length-1) == '%' ){

        aOff[obj.name][0] = offset.substr(0,offset.length-1);

        aOff[obj.name][1] = true;

      }else{aOff[obj.name][0] = offset;}

    }else{aOff[obj.name][0] = 0;}

  }

  var show = gEBI('price');

  var hide = gEBI('iPrice');

  var nPrice = parseFloat(hide.value);

  var oPrice = parseFloat(hide.value);

  for(var i in aOff){

    if(parseFloat(aOff[i][0]) != 0){

      //percentages are based on original price

      if(aOff[i][1] == true){nPrice = nPrice + ((oPrice * parseFloat(aOff[i][0])) / 100);}

      else{nPrice = nPrice + parseFloat(aOff[i][0]);}

    }

  }

  show.value = fix(nPrice);

} // end function checkAttributes_Offset

/**

* Sets up the array for use by the checkAttributes_Offset function above

*/

function checkAttributes_Setup(ary){

  var rtn = new Object();

  for(var i in ary){rtn[ary[i]] = Array(0,false);}

  return rtn;

} // end function checkAttributes_Setup


