// JavaScript Document

function view_invoice (invoice_id, invoice_action_invoice, invoice_id_box, invoice_form)
{
	if (invoice_action_invoice.checked == true)
	{
		document.location.href = '/admin/invoices/?i=' + invoice_id;
	}
	else
	{
		invoice_id_box.value = invoice_id;
		invoice_form.submit();
	}
}
function invoice_delete_confirm ()
{
	var invoice_form = document.invoice_form;
	var agree = confirm("Are you sure you wish to continue?");
	if (agree)
	{
		invoice_form.submit();
		return true;
	}
	else
	{
		return false;
	}
}
function invoice_frequency (product_select, frequency_select)
{
	if (product_select.options[product_select.selectedIndex].text.match(/(hosting|ip address|spam|filtering)/i))
	{
		frequency_select.selectedIndex=3;
	}
	else if (product_select.options[product_select.selectedIndex].text.match(/domain/i))
	{
		frequency_select.selectedIndex=4;
	}
	else
	{
		frequency_select.selectedIndex=0;
	}
}
function invoice_price_check (item_detail, product_select, frequency_select, price_box)
{
	price_box.value = '';
	price_box.focus();
}
function invoice_item_check (item_detail, product_select, frequency_select, price_box)
{
	var domain_selected = false;
	if (item_detail.value.length > 4 && (product_select.options[product_select.selectedIndex].value == 0 || product_select.options[product_select.selectedIndex].text == '' || product_select.options[product_select.selectedIndex].text.match(/domain/i)))
	{
		if (item_detail.value.match(/^[0-9a-z-]{2,}[.]co[.]uk$/i))
		{
			for (i=0;i<product_select.length;i++)
			{
				if (product_select.options[i].text == 'UK Domain Name')
				{
					product_select.selectedIndex=i;
					domain_selected = true;
				}
			}
		}
		else if (item_detail.value.match(/^[0-9a-z-]{2,}[.](com|net|org|info|biz)$/i))
		{
			for (i=0;i<product_select.length;i++)
			{
				if (product_select.options[i].text == 'Global Domain Name')
				{
					product_select.selectedIndex=i;
					domain_selected = true;
				}
			}
		}
		else if (item_detail.value.match(/^[0-9a-z-]{2,}[.]us$/i))
		{
			for (i=0;i<product_select.length;i++)
			{
				if (product_select.options[i].text == 'US Domain Name')
				{
					product_select.selectedIndex=i;
					domain_selected = true;
				}
			}
		}
		else if (item_detail.value.match(/^[0-9a-z-]{2,}[.]eu$/i))
		{
			for (i=0;i<product_select.length;i++)
			{
				if (product_select.options[i].text == 'EU Domain Name')
				{
					product_select.selectedIndex=i;
					domain_selected = true;
				}
			}
		}
		if (domain_selected)
		{
			frequency_select.selectedIndex=4;
		}
	}
}
function view_service (service_id, search_box, service_form)
{
	search_box.value = service_id;
	service_form.submit();
}
function renewals (months, input_box, this_button)
{
	if (months == '-1') // Set to inactive
	{
		this_button.style.display = 'none';
		input_box.value = '-1';
	}
	else
	{
		this_button.style.color = '#FFFFFF';
		this_button.style.backgroundColor = '#901010';
		input_box.style.display = 'inline';
		input_box.value = (input_box.value == '') ? parseFloat(months) : parseFloat(input_box.value) + parseFloat(months);
	}
}