//To use the function below:
//Create a form with id, which you would pass to function
//Create Radio button and assign appropriate values to them
//Value is an action, which will be performed
//Currently supported actions: 
//optconfig_additem_[itemid]_qty_[quantity]
//itemid is internal id of an item
//quantity is a number, quanity of a current item (will be multiplied by main item quantity)
//an id of an input box where quantity could be found may be entered instead of quantity

function custecAddToCart(form_id, options_element_id, condition, codeifnotmet){
    var eq = document.getElementById("qtyadd").value; //get main quantity
    var multi = document.getElementById("item_internalid").value + "," + eq + "\;"; //set default multi value
    var form = document.forms[form_id]; //get form addtocart
	var parent_element = document.getElementById(options_element_id);
    var inputs = parent_element.getElementsByTagName("input"); //get all inputs in that form
    for (i = 0; i < inputs.length; i++) {
        type = inputs[i].type;
        if (type == "radio") { //if input is a radio button
           custecProcessRadio(inputs[i]) 
        }
    }
    function custecProcessRadio(this_radio){
        var value = this_radio.value; //get radio button value
        if (this_radio.checked) { //if radio button is checked
           custecProcessAction(value); //act according to value
        }
    }
    function custecProcessAction(action){
        if (action.match("optconfig_additem_")) {
            var regexpr = /(optconfig_additem_)([0-9]+)/;
            var regexpr2 = /(qty_)(.+)/;
            var it_qty = action.match(regexpr2)[2];
            if (it_qty.match(/[a-z]/)) { //if has to get quantity from another input box
                it_qty = document.getElementById(it_qty);
                it_qty = it_qty.value;
            }
            var item_id = action.match(regexpr)[2];
            multi = multi + item_id + "," + eq * it_qty + "\;";
        }
    }
	
	if (!condition || eval(condition)) { //if condition doesn't exist or if it's met
		document.getElementById("multi").value = multi;
	}
	else if (codeifnotmet){ //if there is code for not meeting condition
		eval(codeifnotmet);
	}
	else{ //if condition exists but there is no code
		return false;
	}
}

function custecRemoveElement(parent, child)
{
var parentElt = document.getElementById(parent);
  var childElt = document.getElementById(child);
  parentElt.removeChild(childElt);
}

function switchPicture(pic_id, new_url)
{
	var picture = document.getElementById(pic_id);
	picture.src = new_url;
}

