

function getSelectedOptionId(){
   if(document.images) {
      var which = document.productForm;

      for(i=0;i<which.length;i++) {
         var tempobj=which.elements[i];
         if(tempobj.name.substring(0,7)=='options' || tempobj.name.substring(0,16)=='checkbox_options') {
            var fieldType = tempobj.type;
            if(fieldType=='select-one'){
               if(tempobj.selectedIndex > -1){
                  //var myval = tempobj[tempobj.selectedIndex].value;
                  var myval = tempobj.selectedIndex;
               	  return myval;
               }

            } else {
				//ignore
            }
         }
      }
   }
}


function getChildOptionElement(){
   if(document.images) {
      var which = document.productForm;

      for(i=0;i<which.length;i++) {
         var tempobj=which.elements[i];
         if(tempobj.name.substring(0,10)=='options[2]') {
            return tempobj;           
         }
      }
   }
}

function updatePrice(formName){
   if (typeof formName !== 'undefined' && formName.length > 0){
       var which = document.getElementById(formName);
   } else {
       var which = document.productForm;
   }
   
   var myoptions = getSelectedOptions(formName);
   var productId = which.productID.value;
   var extraField = '';
   
   if(which.extraField){
       var extraField = which.extraField.value;
   }
   if (typeof formName !== 'undefined' && formName.length > 0){
    x_getLiveProductTotal(myoptions, productId, extraField, '1', false, true, function(response){document.getElementById('price-'+productId).innerHTML = response;});
   } else {
    x_getLiveProductTotal(myoptions, productId, extraField, '1', false, false, totalHandler);
   }
}

function totalHandler(response){
   if(response){
   		document.getElementById('price').innerHTML = response;
   }
}

function getSelectedOptions(formName){
   var myoptions = '';

   if(document.images) {
      if (typeof formName !== 'undefined' && formName.length > 0){
       var which = document.getElementById(formName);
      } else {
           var which = document.productForm;
      }

      for(i=0;i<which.length;i++) {
         var tempobj=which.elements[i];
         if(tempobj.name.substring(0,7)=='options' || tempobj.name.substring(0,16)=='checkbox_options') {
            var fieldType = tempobj.type;
            if(fieldType=='select-one'){
               if(tempobj.selectedIndex > -1){
                  var myval = tempobj[tempobj.selectedIndex].value;
               	  myoptions += ',' + myval;
               }

            } else if(fieldType=='radio' || fieldType=='checkbox'){
               if(tempobj.checked){
                  var myval = tempobj.value;
                  myoptions += ',' + myval;
               }

            } else {
		//ignore
            }
         }
      }
   }

   return myoptions;
}

