/* js/cfe_tvbg_buy.tvbgpro.js */

var itemid_tvbgone_pro_NA = "TVBGPRONA03";
var itemid_tvbgone_pro_EU = "TVBGPROEU03";
var arrSoldout_tvbgpro = new Array();

function additem_tvbgpro( hrefAddItem, arrSoldout ) {
	var g_model = getRadioValue( document.formItem.radioModel );
	
//	alert('will add item to the cart: model:' + g_model);
//debugger;

	var itemID = '';
	
		// otherwise, interpret color and pass info on to AddItem page
	
	switch( g_model ) {

		case 'NA':
			itemID = itemid_tvbgone_pro_NA;
			break;

		case 'EU': 
			itemID = itemid_tvbgone_pro_EU;
			break;

		default:
			alert('Please select a TV-B-Gone Pro model.'); 
			//alert('additem: unknown model(\'' + g_model + '\') encountered!'); 
			return;
	}

		// make sure this item is not in the Soldout Items array
		//	if itemID in list1, show that that item is sold out
	if (arrSoldout[itemID]) {
		alert (arrSoldout[itemID] + " is sold out!");
		return;
	}


		// test the validity of qty
		
	var qty = document.formItem.itemQty.value;
	
	if ( qty < 1 ) {
		alert('Please enter a quantity of at least 1.'); 
		return;		
	}	
		
		
		// now take this itemID and send it with the AddToCart url on the query string
		// - but only if itemID is valid! (not blank)

	if ( itemID != '' ) {		
		var url = hrefAddItem + '&item=' + itemID + '&qty=' + qty; 
		document.location = url;
	}
}


function getRadioValue(r) {
    var radioLength = r.length;
	for(var i = 0; i < radioLength; i++) {
		if (r[i].checked) {
			return r[i].value;
			break;
			//return radioObj[i].value;
		}
	}
	return null;
}
