function toggleCheckoutButton()
{
	$('btn-checkout').hide();
	$('btn-checkout2').show();
}

function toggleShippingAddress(e)
{	
	if($F(e) == 'on')
	{
		//clear the values
		$('name').value = '';	
		$('address1').value = '';
		$('address2').value = '';
		$('city').value = '';
		$('state').value = '';
		$('zipcode').value = '';
		
		//disable them
		$('name').disable();
		$('address1').disable();
		$('address2').disable();
		$('city').disable();
		$('state').disable();
		$('zipcode').disable();
	}
	else
	{
		//enable the fields
		$('name').enable();
		$('address1').enable();
		$('address2').enable();
		$('city').enable();
		$('state').enable();
		$('zipcode').enable();
	}
}

function askfirst(text, url)
{
	var answer = confirm (text);
	
	if (answer)
		window.location=url;
}

//provide a random timestamp with each call to foil caching
function getTimestamp()
{
	var t = new Date();
	var r = "" + t.getFullYear() + t.getMonth() + t.getDate() + t.getHours() + t.getMinutes() + t.getSeconds(); 

	return(r);
}

function deleteProductOption(group, name, p, id)
{
	var answer = confirm ('Are you sure you want to delete the option ' + group + '/' + name + '?');
	
	if(answer)
	{
		var url = '/wp-content/plugins/strangerproducts/services/updateoptions.php';
		var pars = 'p=' + p + '&delete=' + id + '&ts=' + getTimestamp();
		
		var myAjax = new Ajax.Updater('product_options_container', url, { method: 'get', parameters: pars, evalScripts: true }); 
	}	
}

function updateShipping(s)
{
	var url = '/wp-content/plugins/strangerproducts/services/updateshipping.php';
	var pars = 'shipping=' + s + '&ts=' + getTimestamp();	
	$('cartshipping').innerHTML = '<blink>' + $('cartshipping').innerHTML + '</blink>';
	var myAjax = new Ajax.Updater('cartshipping', url, {method: 'get', parameters: pars, evalScripts: true});
}

function updateShippingWithProduct(s, p, q)
{
	var url = '/wp-content/plugins/strangerproducts/services/updateshipping.php';
	var pars = 'shipping=' + s + '&p=' + p + '&q=' + q + '&ts=' + getTimestamp();	
	$('cartshipping').innerHTML = '<blink>' + $('cartshipping').innerHTML + '</blink>';
	var myAjax = new Ajax.Updater('cartshipping', url, {method: 'get', parameters: pars, evalScripts: true});
}

function toggleProductOptionEdit(o)
{
	if($('option_'+o).style.display == 'none')
	{	//edit form is shown
		$('option_edit_'+o).hide();
		$('option_'+o).show();
	}
	else //table is shown
	{	
		$('option_'+o).hide();
		$('option_edit_'+o).show();
	}
}

function updateProductOptions(p,o)
{	
	if(o)
	{
		if(!$('editoption_group_'+o).value)
			alert('Please enter a group name.');
		else if(!$('editoption_name_'+o).value)
			alert('Please enter an option name.');
		else
		{
			var url = '/wp-content/plugins/strangerproducts/services/updateoptions.php';
			var pars = 'p=' + p + '&oid=' + o + '&ogroup=' + $('editoption_group_'+o).value + '&oorder=' + $('editoption_order_'+o).value + '&oname=' + $('editoption_name_'+o).value + '&oprice=' + $('editoption_price_'+o).value + '&oqty=' + $('editoption_qty_'+o).value + '&ts=' + getTimestamp();
			
			var myAjax = new Ajax.Updater('product_options_container', url, { method: 'get', parameters: pars, evalScripts: true }); 
		}
	}
	else
	{
		if(!$('newoption_group').value)
			alert('Please enter a group name.');
		else if(!$('newoption_name').value)
			alert('Please enter an option name.');
		else
		{
				var url = '/wp-content/plugins/strangerproducts/services/updateoptions.php';
				var pars = 'p=' + p + '&ogroup=' + $('newoption_group').value + '&oorder=' + $('newoption_order').value + '&oname=' + $('newoption_name').value + '&oprice=' + $('newoption_price').value + '&oqty=' + $('newoption_qty').value + '&ts=' + getTimestamp();
				
				var myAjax = new Ajax.Updater('product_options_container', url, { method: 'get', parameters: pars, evalScripts: true }); 
		}
	}
}

function showProductOptions(p)
{
	var url = '/wp-content/plugins/strangerproducts/services/updateoptions.php';
	var pars = 'p=' + p + '&ts=' + getTimestamp();	
	var myAjax = new Ajax.Updater('product_options_container', url, { method: 'get', parameters: pars, evalScripts: true }); 
}

function getAdminProductList(target, category)
{
	if($(target).firstChild)
	{
		//if there is a child in the target, remove the innerHTML content
		$(target).innerHTML = '';		
	}
	else
	{	
		//else we are 'opening'. get the product list.
		var url = '/wp-content/plugins/strangerproducts/services/stranger_products_data.php';
		var pars = 'action=adminproductlist&category=' + category + '&ts=' + getTimestamp();	
	
		var myAjax = new Ajax.Updater(target, url, { method: 'get', parameters: pars, evalScripts: true }); 
	}
}