/**
 * createRoster
 *
 * @param index		the index of the product's roster on the page
 * @param quantity	the quantity the customer entered for the product
 * @param prefix	the string to prepend to the name and number fields
 */
function createRoster(index, quantity, prefix) {
	var roster = document.getElementById('roster-' + index);

	if (roster === null) {
		return;
	}

	var players = roster.getElementsByTagName('div');
	var delta = quantity - players.length;

	/**
	 * Add players if the quantity has increased. Use the first player node
	 * as a template and clone it to create the necessary additions. Update
	 * the line number in the label for each player.
	 */
	for (var i=0; i < delta; i++) {
		var clone = players[0].cloneNode(true);

		var label = document.createTextNode(window.PLAYER_LABEL + ' ' + (players.length + 1) + ':');
		clone.getElementsByTagName('b').item(0).replaceChild(label, clone.getElementsByTagName('b').item(0).firstChild);


		var input = clone.getElementsByTagName('input');

		for (var j=0; j < input.length; j++) {
			input.item(j).value='';
			switch (input.item(j).className) {
				case 'name' :
					input.item(j).setAttribute('name', prefix + index + 'Player[' + players.length + '].Player_Name');
					input.item(j).setAttribute('id', 'name' + players.length);
					break;
				case 'number' :
					input.item(j).setAttribute('name', prefix + index + 'Player[' + players.length + '].Player_Number');
					input.item(j).setAttribute('id', 'number' + players.length);
					break;
				default:
			}
		}

		roster.insertBefore(clone, players.item(players.length - 1).nextSibling);
	}

	/**
	 * Remove players if the quantity has decreased, but leave at least one
	 * player at all times; it is our template.
	 */
	for (; delta < 0 && players.length > 1; delta++) {
		roster.removeChild(players.item(players.length - 1));
	}

	if (quantity >= 1) {
		roster.style.display = 'block';
		toggleRoster(index, true);
	} else {
		roster.style.display = 'none';
	}
}

/**
 * toggleRoster
 *
 * @param index		the index of the product's roster on the page
 * @param maximize	(optional) force minimize or maximize
 */
function toggleRoster(index /* , maximize */) {
	var roster = document.getElementById('roster-' + index);
	var minimizer = document.getElementById('roster-minimizer-' + index);

	if (roster === null) {
		return;
	}

	var players = roster.getElementsByTagName('div');

	if (players.length <= window.MINIMIZE_TO) {
		minimizer.style.display = 'none';
		return;
	}

	var maximize = (players.item(window.MINIMIZE_TO).style.display === 'none');

	/**
	 * If the optional parameter, maximize, is a boolean, override the
	 * calculated action.
	 */
	if (typeof arguments[1] === 'boolean') {
		maximize = arguments[1];
	}

	if (maximize) {
		var state = 'block';
		var text = document.createTextNode(window.MINIMIZE_TEXT);
	} else {
		var state = 'none';
		var text = document.createTextNode(window.MAXIMIZE_TEXT);
	}

	/**
	 * Show or hide the players above the minimum threshold depending on
	 * what action is needed (or was specified).
	 */
	for (var i = window.MINIMIZE_TO; i < players.length; i++) {
		players.item(i).style.display = state;
	}

	/**
	 * Update the text for the minimizing/maximizing hyperlink and display
	 * it (it may have been previously hidden due to quantity).
	 */
	minimizer.firstChild.replaceChild(text, minimizer.firstChild.firstChild);
	minimizer.style.display = 'block';
}

/**
 * preview
 *
 * @param template	index of the template in the ClubTemplateVector
 * @param product	index of the product in the ClubTemplateSubProductVector
 * @param productId
 * @param player	(optional) the player HTML node to use for names/numbers
 */
function preview(template, product, productId /* , player */) {

	var name = 'SAMPLE';
	var number = 10;

	/**
	 * If the optional parameter, player, exists and is an HTML node
	 * (typeof "object" in JavaScript), override the default name and
	 * number values.
	 */
	if (typeof arguments[3] === 'object') {
		var player = arguments[3];

		var input = player.getElementsByTagName('input');

		for (var j=0; j < input.length; j++) {
			switch (input.item(j).className) {
				case 'name' :
					var name = input.item(j).value;
					break;
				case 'number' :
					var number = input.item(j).value;
					break;
				default:
			}
		}
	}

/*
	switch (productId) {
		case 195614 :
			window.open('/IWCatClubOrderingProductDetail.process?Template=' + template + '&Product=' + product + '&sku=609530.RW.YL&size=600&phototype=AP38&orientation=back&modifiers[0][category]=NAME&modifiers[0][location]=back&modifiers[0][x]=300&modifiers[0][y]=150&modifiers[0][arced]=false&modifiers[0][radius]=100&modifiers[0][rotation]=0&modifiers[0][point_size]=40&modifiers[0][font]=STPRONRW&modifiers[0][fill]=FFFFFF&modifiers[0][stroke]=000000&modifiers[0][stroke_weight]=4&modifiers[0][value]=' + name + '&modifiers[1][category]=NUMBER&modifiers[1][location]=back&modifiers[1][x]=300&modifiers[1][y]=300&modifiers[1][arced]=false&modifiers[1][radius]=100&modifiers[1][rotation]=0&modifiers[1][point_size]=200&modifiers[1][font]=STPRONRW&modifiers[1][fill]=FFFFFF&modifiers[1][stroke]=000000&modifiers[1][stroke_weight]=8&modifiers[1][value]=' + number + '&modifiers[2][category]=LOGO&modifiers[2][location]=front&modifiers[2][x]=360&modifiers[2][y]=205&modifiers[2][asset]=goldsborofc.png', 'preview', 'width=600,height=740,toolbars=no');
			break;
		case 196046 :
			window.open('/IWCatClubOrderingProductDetail.process?Template=' + template + '&Product=' + product + '&sku=609521.BW.YL&size=600&orientation=front&modifiers[0][category]=NAME&modifiers[0][location]=front&modifiers[0][x]=126&modifiers[0][y]=450&modifiers[0][arced]=false&modifiers[0][radius]=100&modifiers[0][rotation]=8&modifiers[0][point_size]=80&modifiers[0][font]=STPRONRW&modifiers[0][fill]=FFFFFF&modifiers[0][stroke]=000000&modifiers[0][stroke_weight]=0&modifiers[0][value]=' + number, 'preview', 'width=600,height=740,toolbars=no');
			break;
		case 125627 :
			window.open('/IWCatClubOrderingProductDetail.process?Template=' + template + '&Product=' + product + '&sku=216239.WB.L&size=600&orientation=front', 'preview', 'width=600,height=740,toolbars=no');
			break;
		case 195575 :
			window.open('/IWCatClubOrderingProductDetail.process?Template=' + template + '&Product=' + product + '&sku=397170..5&size=600&orientation=front', 'preview', 'width=600,height=740,toolbars=no');
			break;
		case 183049 :
*/
			window.open('/IWCatClubOrderingProductDetail.process?Product_Id=124129&Template=' + template + '&Product=' + product + '&sku=267998.BK&size=600&orientation=front&modifiers[0][category]=NAME&modifiers[0][location]=back&modifiers[0][x]=300&modifiers[0][y]=150&modifiers[0][arced]=false&modifiers[0][radius]=100&modifiers[0][rotation]=0&modifiers[0][point_size]=40&modifiers[0][font]=STPRONRW&modifiers[0][fill]=FFFFFF&modifiers[0][stroke]=000000&modifiers[0][stroke_weight]=4&modifiers[0][value]=&modifiers[1][category]=NUMBER&modifiers[1][location]=back&modifiers[1][x]=300&modifiers[1][y]=300&modifiers[1][arced]=false&modifiers[1][radius]=100&modifiers[1][rotation]=0&modifiers[1][point_size]=200&modifiers[1][font]=STPRONRW&modifiers[1][fill]=FFFFFF&modifiers[1][stroke]=000000&modifiers[1][stroke_weight]=8&modifiers[1][value]=&modifiers[2][category]=LOGO&modifiers[2][location]=front&modifiers[2][x]=488&modifiers[2][y]=306&modifiers[2][rotation]=0&modifiers[2][shear]=-11&modifiers[2][asset]=goldsborofc.png', 'preview', 'width=600,height=740,toolbars=no');
//			break;
//		default:
//	}
}

/**
 * previewSingleTeam
 *
 * @param bundleId	the id of the bundle to preview
 * @param productId
 * @param player	(optional) the player HTML node to use for names/numbers
 */
function previewSingleTeam(bundleId, productId, player) {

	var theName = 'SAMPLE';
	var theNumber = 10;

	/**
	 * If the optional parameter, player, exists and is an HTML node
	 * (typeof "object" in JavaScript), override the default name and
	 * number values.
	 */
	if (typeof arguments[2] === 'object') {
		var player = arguments[2];

		var input = player.getElementsByTagName('input');
		var err = '';
		for (var j=0; j < input.length; j++) {
			switch (input.item(j).className) {
				case 'name' :
					if (input.item(j).value=="") {
						err = 'name';
						break;
					} else {
						var validName = authenticateName(input.item(j).value);
						if(validName){
							var theName = input.item(j).value;
							break;
						} else{
							return false;
						}
					}
				case 'number' :
					if (input.item(j).value=="") {
						err = (err!=''?'name and number':'number');
						break;
					} else {
						var validNumber = authenticateNumber(input.item(j).value);
						if(validNumber){
							var theNumber = input.item(j).value;
							break;
						}else{
							return false;
						}
					}

				default:
				
			}
		}
		if(err!=''){
			alert("Please enter a "+err+" to preview customization.");
			return false;
		}
	}
	if(document.getElementById('color'))
	{
		var c_el = document.getElementById('color');
		color = (c_el.options[c_el.selectedIndex].value == '') ? null : c_el.options[c_el.selectedIndex].value;
		var jerseyColor = document.getElementById("color").options[document.getElementById("color").selectedIndex].innerHTML;
	} else if (document.getElementById('singlecolor')) {
		var c_el = document.getElementById('singlecolor');
		color = (c_el.value == '') ? null: c_el.value;
		var jerseyColor = document.getElementById("selectedsinglecolor").innerHTML;
  }
	var q = 0;

	if(color) {
		for(i in sProduct.Variants)
		{
			if(color == sProduct.Variants[i].Color_Value_Id)
			{
				color_code = sProduct.Variants[i].Color_Code;
				break;
			}
		}
	} else {
		for(i in sProduct.Variants)
		{
			if(q <= sProduct.Variants[i].I)
			{
				q = sProduct.Variants[i].I;
				color_code = sProduct.Variants[i].Color_Code;
				break;
			}
		}
	}

	var ColorSelectID = "bundle-" + bundleId + "-modifier-0-color-option-0";
	var StrokeSelectName = "Bundle" + bundleId + "StrokeColor";
	var FillSelectName = "Bundle" + bundleId + "FillColor";
	var fillColor = document.getElementsByName(FillSelectName)[0].value;
	if (document.getElementsByName(StrokeSelectName).length>0) {
		var strokeColor = document.getElementsByName(StrokeSelectName)[0].value;
	} else {
		var strokeColor = '';
	}

	var previewPopup = window.open('/jerseycustomization/PreviewSingleTeam.php5?id='
	+ bundleId + '&name=' + theName + '&number=' + theNumber + '&productId=' +
	productId + '&fillColor=' + fillColor + '&strokeColor=' + strokeColor + '&jerseyColor=' + color_code +
	'&size=600&orientation=front', 'preview',
	'width=400,height=400,toolbars=no');
	previewPopup.focus();
}

function previewSingleTeam(bundleId, productId, player, clubFlag) {

	var theName = 'SAMPLE';
	var theNumber = 10;

	/**
	 * If the optional parameter, player, exists and is an HTML node
	 * (typeof "object" in JavaScript), override the default name and
	 * number values.
	 */
	if (typeof arguments[2] === 'object') {
		var player = arguments[2];

		var input = player.getElementsByTagName('input');
		var err = '';
		for (var j=0; j < input.length; j++) {
			switch (input.item(j).className) {
				case 'name' :
					if (input.item(j).value=="") {
						err = 'name';
						break;
					} else {
						var validName = authenticateName(input.item(j).value);
						if(validName){
							var theName = input.item(j).value;
							break;
						} else{
							return false;
						}
					}
				case 'number' :
					if (input.item(j).value=="") {
						err = (err!=''?'name and number':'number');
						break;
					} else {
						var validNumber = authenticateNumber(input.item(j).value);
						if(validNumber){
							var theNumber = input.item(j).value;
							break;
						}else{
							return false;
						}
					}

				default:
				
			}
		}
		if(err!=''){
			alert("Please enter a "+err+" to preview customization.");
			return false;
		}
	}
	if(document.getElementById('color'))
	{
		var c_el = document.getElementById('color');
		color = (c_el.options[c_el.selectedIndex].value == '') ? null : c_el.options[c_el.selectedIndex].value;
		var jerseyColor = document.getElementById("color").options[document.getElementById("color").selectedIndex].innerHTML;
	} else if (document.getElementById('singlecolor')) {
		var c_el = document.getElementById('singlecolor');
		color = (c_el.value == '') ? null: c_el.value;
		var jerseyColor = document.getElementById("selectedsinglecolor").innerHTML;
  }
	var q = 0;

	if(color) {
		for(i in sProduct.Variants)
		{
			if(color == sProduct.Variants[i].Color_Value_Id)
			{
				color_code = sProduct.Variants[i].Color_Code;
				break;
			}
		}
	} else {
		for(i in sProduct.Variants)
		{
			if(q <= sProduct.Variants[i].I)
			{
				q = sProduct.Variants[i].I;
				color_code = sProduct.Variants[i].Color_Code;
				break;
			}
		}
	}

	var ColorSelectID = "bundle-" + bundleId + "-modifier-0-color-option-0";
	var StrokeSelectName = "Bundle" + bundleId + "StrokeColor";
	var FillSelectName = "Bundle" + bundleId + "FillColor";
	var fillColor = document.getElementsByName(FillSelectName)[0].value;
	if (document.getElementsByName(StrokeSelectName).length>0) {
		var strokeColor = document.getElementsByName(StrokeSelectName)[0].value;
	} else {
		var strokeColor = '';
	}

	var previewPopup = window.open('/jerseycustomization/PreviewSingleTeam.php5?id='
	+ bundleId + '&name=' + theName + '&number=' + theNumber + '&productId=' +
	productId + '&fillColor=' + fillColor + '&strokeColor=' + strokeColor + '&jerseyColor=' + color_code +
	'&size=600&orientation=front&clubFlag=' + clubFlag, 'preview',
	'width=400,height=400,toolbars=no');
	previewPopup.focus();
}


function authenticateName(input) {
	var Regex = new RegExp("^[A-Za-z .-]+$");
	if( !input.match( Regex ) ) {
  		alert('Names can only contain letters a-z, a space, a dot(.), or a hyphen(-)');
  		return false;
 	} else {
		return true;
		}
}

function authenticateNumber(input) {
	var Regex = new RegExp("^[0-9]+$");
	if( !input.match( Regex ) ) {
  		alert('Numbers can only contain the numbers 0-9');
  		return false;
 	} else {
		return true;
		}
}

/**
 * preview
 *
 * @param template	index of the template in the ClubTemplateVector
 * @param product	index of the product in the ClubTemplateSubProductVector
 * @param productId
 * @param player	(optional) the player HTML node to use for names/numbers
 */
function previewClub(clubTemplateProductId, productId, PGC, cid /* , player , name , number */) {

	var name = 'SAMPLE';
	var number = 10;

	/**
	 * If the optional parameter, player, exists and is an HTML node
	 * (typeof "object" in JavaScript), override the default name and
	 * number values.
	 */
	if (typeof arguments[4] === 'object') {
		var player = arguments[4];

		var input = player.getElementsByTagName('input');

		for (var j=0; j < input.length; j++) {
			switch (input.item(j).className) {
				case 'name' :
					var name = input.item(j).value;
					break;
				case 'number' :
					var number = input.item(j).value;
					break;
				default:
			}
		}
	} else {
		if (arguments[5] != '' || arguments[6] != '') {
			var name = arguments[5];
			var number = arguments[6];
		}
	}

	window.open('/jerseycustomization/preview.php5?ClubTemplateProductId=' + clubTemplateProductId + '&productId=' + productId + '&name=' + name + '&number=' + number + '&product=' + PGC + '&cid=' + cid + '&orientation=Back', 'preview', 'width=310,height=330,toolbars=no');

}


/**
 * isInteger
 *
 * Gets called onkeydown
 *
 * @param objectsKeyDownEvent	event fired from <input> tag
 */
function isInteger( objectsKeyDownEvent ) {

	var keynum;		// keystroke number code
					// var keychar;
	var isInt;		// boolean
	var isXorY;		// boolean

	if (window.event)
	{
			keynum = objectsKeyDownEvent.keyCode;	// For IE

	} else if (objectsKeyDownEvent.which){

			keynum = objectsKeyDownEvent.which;		// For Netscape, FF, ...
	}

	//keychar = String.fromCharCode(keynum);

	isInt = /^(8|9|13|20|35|36|37|38|39|40|46|48|49|50|51|52|53|54|55|56|57|96|97|98|99|100|101|102|103|104|105|144)+$/.test(keynum);

	isXorY = /^(88|89)+$/.test(keynum);

	return (isInt && !isXorY ? true : false);

}


/**
 * isAlpha
 *
 * Gets called onkeydown
 *
 * @param objectsKeyDownEvent	event fired from <input> tag
 */
function isAlpha( objectsKeyDownEvent ) {

	var keynum;		// keystroke number code
	var keychar;	// keystroke string value
	var isSpecial;	// boolean
	var isAlpha;	// boolean
	var isNumPad;	// bollean

	if (window.event)
	{
			keynum = objectsKeyDownEvent.keyCode;	// For IE

	} else if (objectsKeyDownEvent.which){

			keynum = objectsKeyDownEvent.which;		// For Netscape, FF, ...
	}

	keychar = String.fromCharCode(keynum);
//alert("keychar and keynum " + keychar + " " + keynum);
	isNumPad = /^(96|97|98|99|100|101|102|103|104|105)+$/.test(keynum);
	isSpecial = /^(8|9|13|20|32|35|36|37|38|39|40|46|109|144|189|190)+$/.test(keynum);
	isAlpha = /^[a-zA-Z]+$/.test(keychar);

	//stopEvent(objectsKeyDownEvent);

	return ((isAlpha || isSpecial) && !isNumPad ? true : false);

}


/**
 * maxQuantity
 *
 * Gets called onchange event
 *
 * @param prodQtyObj	element Object <input> tag
 * @param prodIndex		used to call the createRoster function
 */
function maxQuantity( prodQtyObj, prodIndex ) {

	var prodQty = prodQtyObj.value;

	if (prodQty >= 200) {

		alert("Please enter a quantity less than 200");

		prodQtyObj.value = '0';
		createRoster(prodIndex, '0', 'Product');
		prodQtyObj.focus();

	}
}


/**
 * stopEvent
 *
 * Third party function
 *
 * @param e		event
 */
function stopEvent(e) {

	if(!e) var e = window.event;

	//e.cancelBubble is supported by IE - this will kill the bubbling process.
	e.cancelBubble = true;
	e.returnValue = false;

	//e.stopPropagation works only in Firefox.
	if (e.stopPropagation) {
		e.stopPropagation();
		e.preventDefault();
	}
	return false;
}

function previewSinglePlayer(bundleId, productId, player) {

	var theName = 'SAMPLE';
	var theNumber = 10;

	/**
	 * If the optional parameter, player, exists and is an HTML node
	 * (typeof "object" in JavaScript), override the default name and
	 * number values.
	 */
	if (typeof arguments[2] === 'object') {
		var player = arguments[2];

		var input = player.getElementsByTagName('input');
		var err = '';
		for (var j=0; j < input.length; j++) {
			switch (input.item(j).className) {
				case 'name' :
					if (input.item(j).value=="") {
						err = 'name';
						break;
					} else {
						var validName = authenticateName(input.item(j).value);
						if(validName){
							var theName = input.item(j).value;
							break;
						} else{
							return false;
						}
					}
				case 'number' :
					if (input.item(j).value=="") {
						err = (err!=''?'name and number':'number');
						break;
					} else {
						var validNumber = authenticateNumber(input.item(j).value);
						if(validNumber){
							var theNumber = input.item(j).value;
							break;
						}else{
							return false;
						}
					}

				default:
				
			}
		}
		if(err!=''){
			alert("Please enter a "+err+" to preview customization.");
			return false;
		}
	}
	if(document.getElementById('color'))
	{
		var c_el = document.getElementById('color');
		color = (c_el.options[c_el.selectedIndex].value == '') ? null : c_el.options[c_el.selectedIndex].value;
		var jerseyColor = document.getElementById("color").options[document.getElementById("color").selectedIndex].innerHTML;
	} else if (document.getElementById('singlecolor')) {
		var c_el = document.getElementById('singlecolor');
		color = (c_el.value == '') ? null: c_el.value;
		var jerseyColor = document.getElementById("selectedsinglecolor").innerHTML;
  }
	var q = 0;

	if(color) {
		for(i in sProduct.Variants)
		{
			if(color == sProduct.Variants[i].Color_Value_Id)
			{
				color_code = sProduct.Variants[i].Color_Code;
				break;
			}
		}
	} else {
		for(i in sProduct.Variants)
		{
			if(q <= sProduct.Variants[i].I)
			{
				q = sProduct.Variants[i].I;
				color_code = sProduct.Variants[i].Color_Code;
				break;
			}
		}
	}

	var ColorSelectID = "bundle-" + bundleId + "-modifier-0-color-option-0";
	var StrokeSelectName = "Bundle" + bundleId + "StrokeColor";
	var FillSelectName = "Bundle" + bundleId + "FillColor";
	var fillColor = document.getElementsByName(FillSelectName)[0].value;
	if (document.getElementsByName(StrokeSelectName).length>0) {
		var strokeColor = document.getElementsByName(StrokeSelectName)[0].value;
	} else {
		var strokeColor = '';
	}

	window.open('/jerseycustomization/Preview.php5?productId=' + productId + '&name=' + theName + 
	'&number=' + theNumber + '&cid=' + Get_Cookie('Club') + '&orientation=back', 'preview',
	'width=400,height=400,toolbars=no');
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}

function CheckCustomizationQuantity () {
	var ProductsRows = document.getElementsByName('Quantity');
		for ( i = 0; i < ProductsRows.length; i++ ) {
			if (ProductsRows[i].value > 0) {  //product has quantity entered
				ProductId=document.getElementsByName('Product_Id')[i].value;
				roster=document.getElementById('roster-' + ProductId);
				if (roster !== null) {  //Product can be customized and should get a name and/or number value
					inputs=roster.getElementsByTagName('input');
					for ( inputindex = 0; inputindex < inputs.length; inputindex++ ) {
						if(inputs[inputindex].value == '') {  //if name or number was not entered for at least 1 player then throw error
							alert("You must enter the customization details (name/number) for each item.");
							return false;
						}
					}
				}
			}
		}
		findEmptyFormElements('ClubOrderForm');
		return true;
}

function ValidateCustomization (Parameter) {
	if (document.getElementById('number')) {
		var cust_number=document.getElementById('number');
	} else {
		var cust_number = null;
	}
	if (document.getElementById('name')) {
		var cust_name=document.getElementById('name');
	} else {
		var cust_name = null;
	}
	if (cust_name !== null && cust_name.value == '') {  //Product can be customized and should get a name value
		alert("You must customize this product with a name.");
		return false;
	}
	
	if (cust_number !== null && cust_number.value == '') {  //Product can be customized and should get a number value
		alert("You must customize this product with a number.");
		return false;
	}
	return validateQTY(Parameter);
}

function findEmptyFormElements(frmId) {

	var elem = document.getElementById(frmId).elements;
	var index = elem.length-1;
	for(var i = index;i >= 0; i--){
	
		if(elem[i] && elem[i].name == 'Quantity' && elem[i].value == 0){
			
			var pid = elem[i].id.substring(8);
			removeFormElement('Product_Id'+pid);
			removeFormElement('Club_Template_Product_Id'+pid);
			removeFormElement('Quantity'+pid);
			
		}
	}
}


function removeFormElement(elId) {
	if(document.getElementById(elId) != null){
		document.getElementById(elId).parentNode.removeChild(document.getElementById(elId));
	}
}
