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', url, { method: 'get', parameters: pars, evalScripts: true }); 
	}	
}

function updateProductOptions(p)
{
	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 + '&oname=' + $('newoption_name').value + '&oprice=' + $('newoption_price').value + '&oqty=' + $('newoption_qty').value + '&ts=' + getTimestamp();
			
			var myAjax = new Ajax.Updater('product_options', 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 }); 
	}
}