function contactpopup(src) {
	win =window.open(src,"","top=20,left=20,height=550,width=650,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes")
}

function friendpopup(src) {
	win =window.open(src,"","top=20,left=20,height=650,width=750,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes")
}

function copy_to_billing(f) {
	if (f.same_as_shipping.checked) {
		f.bill_name.value = f.ship_name.value	
		f.bill_address1.value = f.ship_address1.value
		f.bill_address2.value = f.ship_address2.value
		f.bill_city.value = f.ship_city.value		
		f.bill_state.selectedIndex = f.ship_state.selectedIndex
		f.bill_zip.value = f.ship_zip.value
		f.bill_phone.value = f.ship_phone.value
	}
	else {
		f.bill_name.value = ''		
		f.bill_address1.value = ''
		f.bill_address2.value = ''
		f.bill_city.value = ''		
		f.bill_state.selectedIndex = ''
		f.bill_zip.value = ''
		f.bill_phone.value = ''
	}
}

function copy_traits(f) {
	if (f.traits_apply_to_all.checked) {
		f.trait_value.value = f.trait_value_title.value.replace(/ /g, "_").toLowerCase()	
		f.trait_value_short_title.value = f.trait_value_title.value
		f.trait_value_meta_keywords.value = f.trait_value_title.value.toLowerCase()	
		f.trait_value_meta_description.value = f.trait_value_title.value		
		f.trait_value_description.value = f.trait_value_title.value		
	}
	else {
		f.trait_value.value = ''		
		f.trait_value_short_title.value = ''
		f.trait_value_meta_keywords.value = ''
		f.trait_value_meta_description.value = ''		
		f.trait_value_description.value = ''		
	}
}


function addGroup() {
	
	//***** get the last group *******
	var groupsContainerElement = document.getElementById('groups_container:');
	var groupElement = groupsContainerElement.lastChild;
	var groupID = groupElement.getAttribute('id')

	var iGroup = groupsContainerElement.childNodes.length 
	var iNewGroup = iGroup+1;
	var newGroupID = "group:-"+iNewGroup;			
	
	//***** create the new group ******
	var newGroup = document.createElement('div');
	newGroup.setAttribute("id", newGroupID);
	newGroup.style.cssText  = "border: 1px solid #C0C0C0; padding: 10px; margin: 5px;";	
	
	var deleteLink = "";
	if (iGroup == 1) {
		deleteLink = " <a href=\"javascript:;\" onclick=\"remove('" + newGroupID + "')\">Delete</a>";
	}	
	
	//***** replace all references to the first group, to that of the new group *****
	var input = new RegExp(":-"+iGroup,"g");
	var output = ':-'+iNewGroup;
	newGroup.innerHTML = groupElement.innerHTML.replace(input,output) + deleteLink;
		
	//***** finally, add the new group ******				
	groupsContainerElement.appendChild(newGroup);
	
}

function addOption(namei) {
	
	//***** parse the input *****
	var nameArray = new Array();
	nameArray 		= namei.split('-');
	var nameBase 	= nameArray[0];
	var namei 		= nameArray[1];
	var iGroup 		= namei * 1;

	//***** get the option container for the group and increment its id *******
	var optionsContainerID = "options_container:-"+iGroup;
	var optionsContainerElement = document.getElementById(optionsContainerID);
	var optionElement = optionsContainerElement.lastChild;

	//get the last child's id
	var childID 			= optionElement.id;
	//parse the name of the id
	var childIDArray	= new Array();
	childIDArray			= childID.split(':-');
	var index					= childIDArray[1];
	//parse the index of the id
	var jArray				= new Array();
	jArray 						= index.split('-');
	var j							= jArray[1];

	//add 1 to the Option digit
	var jOption					= j * 1;
	var jNewOption 			= jOption + 1;
	var newOptionID 		= 'option:-'+iGroup+'-'+jNewOption;

	//***** create the new option ******
	var newOption = document.createElement('div');
	newOption.setAttribute("id", newOptionID);

	var deleteLink = "";
	if (jOption == 1) {
		deleteLink = " <a href=\"javascript:;\" onclick=\"remove('" + newOptionID + "')\">Delete</a>";
	}

	//***** replace all references in the first option, to that of the new option *****
	var input = new RegExp(":-"+iGroup+"-"+jOption,"g");
	var output = ':-'+iGroup+'-'+jNewOption; 
	newOption.innerHTML = optionElement.innerHTML.replace(input,output) + deleteLink;
	
	//***** add new option ******
	optionsContainerElement.appendChild(newOption);
			
}

function addSKU(namei) {
	
	//***** parse the input *****
	var nameArray = new Array();
	nameArray 		= namei.split('-');
	var nameBase 	= nameArray[0];
	var namei 		= nameArray[1];
	var iGroup 		= namei * 1;

	//***** get the sku container for the group and increment its id *******
	var skusContainerID 			= "skus_container:-"+iGroup;
	var skusContainerElement 	= document.getElementById(skusContainerID);
	var skuElement 						= skusContainerElement.lastChild;

	//get the last child's id
	var childID 			= skuElement.id;
	//parse the name of the id
	var childIDArray	= new Array();
	childIDArray			= childID.split(':-');
	var index					= childIDArray[1];
	//parse the index of the id
	var jArray				= new Array();
	jArray 						= index.split('-');
	var j							= jArray[1];
	
	//add 1 to the SKU digit
	var jSKU					= j * 1;
	var jNewSKU 			= jSKU + 1;
	var newSKUID 			= 'sku:-'+iGroup+'-'+jNewSKU;

	//***** create the new SKU ******
	var newSKU = document.createElement('div');
	newSKU.setAttribute("id", newSKUID);
	
	var deleteLink = "";
	if (jSKU == 1) {
		deleteLink = " <a href=\"javascript:;\" onclick=\"remove('" + newSKUID + "')\">Delete</a>";
	}

	//***** replace all references in the first option, to that of the new option *****
	var input = new RegExp(":-"+iGroup+"-"+jSKU,"g");
	var output = ':-'+iGroup+'-'+jNewSKU;
	newSKU.innerHTML = skuElement.innerHTML.replace(input,output) + deleteLink;
	
	//***** add new sku ******
	skusContainerElement.appendChild(newSKU);
	
}

function remove(divIdName) {
	var item = document.getElementById(divIdName);
	//item.parentElement.removeChild(item);
	item.parentNode.removeChild(item);
}
