function changeType(type_id) {
	spec_selected = getElementClass('specs');
	tag_selected = getElementClass('tags');
	brand_selected = getElementClass('brands');

	old_tag_selected_element = document.getElementById(tag_selected);
	if(old_tag_selected_element != null)
		old_tag_selected_element.style.display = 'none';

	old_spec_selected_element = document.getElementById(spec_selected);
	if(old_spec_selected_element != null)
		old_spec_selected_element.style.display = 'none';

	old_brand_selected_element = document.getElementById(brand_selected);
	if(old_brand_selected_element != null)
		old_brand_selected_element.style.display = 'none';

	setElementClass('specs', 'spec_type_' + type_id);
	setElementClass('tags', 'tag_type_' + type_id);
	setElementClass('brands', 'brand_type_' + type_id);

	tag_selected_element = document.getElementById('tag_type_' + type_id);
	if(tag_selected_element != null)
		tag_selected_element.style.display = '';

	spec_selected_element = document.getElementById('spec_type_' + type_id);
	if(spec_selected_element != null)
		spec_selected_element.style.display = '';

	brand_selected_element = document.getElementById('brand_type_' + type_id);
	if(brand_selected_element != null)
		brand_selected_element.style.display = '';
}

function removeUnselectedType(frm) {
	typeSelect = frm.type_id;
	selected_type_id = typeSelect.options[typeSelect.selectedIndex].value;

	specs_element = document.getElementById('specs');

	elementToRemove = new Array();

	if(specs_element != null) {
		for(i = 0;i < specs_element.childNodes.length;i++) {
			child_spec = specs_element.childNodes[i];

			if(child_spec.nodeType == 1) {
				if((child_spec.id.substring(0, 10) == 'spec_type_') && (child_spec.id != 'spec_type_' + selected_type_id)) {
					elementToRemove.push(child_spec.id);
				}
			}
		}

		for(count in elementToRemove) {
			child_spec = document.getElementById(elementToRemove[count]);
			specs_element = child_spec.parentNode;
			specs_element.removeChild(child_spec);
		}
	}

	tags_element = document.getElementById('tags');

	elementToRemove = new Array();

	if(tags_element != null) {
		for(i = 0;i < tags_element.childNodes.length;i++) {
			child_tag = tags_element.childNodes[i];
		
			if(child_tag.nodeType == 1) {
				if((child_tag.id.substring(0, 9) == 'tag_type_') && (child_tag.id != 'tag_type_' + selected_type_id))
					elementToRemove.push(child_tag.id);
			}
		}

		for(count in elementToRemove) {
			child_tag = document.getElementById(elementToRemove[count]);
			tags_element = child_tag.parentNode;
			tags_element.removeChild(child_tag);
		}
	}

	brands_element = document.getElementById('brands');

	elementToRemove = new Array();

	if(brands_element != null) {
		for(i = 0;i < brands_element.childNodes.length;i++) {
			child_brand = brands_element.childNodes[i];

			if(child_brand.nodeType == 1) {
				if((child_brand.id.substring(0, 11) == 'brand_type_') && (child_brand.id != 'brand_type_' + selected_type_id)) {
					elementToRemove.push(child_brand.id);
				}
			}
		}

		for(count in elementToRemove) {
			child_brand = document.getElementById(elementToRemove[count]);
			brands_element = child_brand.parentNode;
			brands_element.removeChild(child_brand);
		}
	}

	price_optional_prototype_element = document.getElementById('price_optional_prototype');
	if(price_optional_prototype_element != null) {
		parentE = price_optional_prototype_element.parentNode;
		parentE.removeChild(price_optional_prototype_element);
	}

	product_relation_prototype_element = document.getElementById('product_relation_prototype');
	if(product_relation_prototype_element != null) {
		parentE = product_relation_prototype_element.parentNode;
		parentE.removeChild(product_relation_prototype_element);
	}

	product_link_prototype_element = document.getElementById('product_link_prototype');
	if(product_link_prototype_element != null) {
		parentE = product_link_prototype_element.parentNode;
		parentE.removeChild(product_link_prototype_element);
	}

	image_prototype_element = document.getElementById('image_prototype');
	if(image_prototype_element != null) {
		parentE = image_prototype_element.parentNode;
		parentE.removeChild(image_prototype_element);
	}
}

function addRow(referredId, beforeId, counterId, newId)
{
	referredE = document.getElementById(referredId);
	beforeE = document.getElementById(beforeId);
	parentE = beforeE.parentNode;
	counterE = document.getElementById(counterId);

	count = parseInt(counterE.value);
	if(isNaN(count))
		count = 0;

	count++;

	newE = referredE.cloneNode(true);

	insertedE = parentE.insertBefore(newE, beforeE);

	if(referredE.id != undefined)
		insertedE.id = newId + '_' +  count.toString();

	if(referredE.name != undefined)
		insertedE.name = referredE.name + '_' +  count.toString();

	children = insertedE.getElementsByTagName('*');

	for(i = 0;i < children.length;i++) {
		if((children[i].id != undefined) && children[i].id != '')
			children[i].id = children[i].id + '_' +  count.toString();

		if((children[i].name != undefined) && children[i].name != '')
			children[i].name = children[i].name + '_' +  count.toString();
	}

	counterE.value = count.toString();

	insertedE.style.display = '';
}

function removeRow(deletedId) {
	deletedE = document.getElementById(deletedId);

	if(deletedE != null) {
		parentE = deletedE.parentNode;

		parentE.removeChild(deletedE);
	}
}