var errors, hddnCountryId, edtCountryIso, edtCountryName, edtCountryNicename, edtCountryIso3, edtCountryNumcode, edtCountryPhonecode;
var module = baseRootURL + "country/";

function registerCountry(action)
{
	errors = false;
	validate_hddnCountryId();
	validate_edtCountryIso();
	validate_edtCountryName();
	validate_edtCountryNicename();
	validate_edtCountryIso3();
	validate_edtCountryNumcode();
	validate_edtCountryPhonecode();
	if (!errors)
	{
		var data = {};
		data.dummy = ""; //we seem to get errors from the first value, so always add a dummy value first.
		data.action = action;
		if (document.getElementById("hddnCountryId") != null) data.hddnCountryId = hddnCountryId;
		data.edtCountryIso = edtCountryIso;
		data.edtCountryName = edtCountryName;
		data.edtCountryNicename = edtCountryNicename;
		data.edtCountryIso3 = edtCountryIso3;
		data.edtCountryNumcode = edtCountryNumcode;
		data.edtCountryPhonecode = edtCountryPhonecode;
		callModule("country/country_val.php", data);
	}
}
function insertCountry(){registerCountry(0)}
function modifyCountry(){registerCountry(1)}

function validate_hddnCountryId(){
	if (document.getElementById("hddnCountryId") != null) hddnCountryId=document.getElementById("hddnCountryId").value;}
function validate_edtCountryIso(){edtCountryIso=validateRequiredText("edtCountryIso", "Country Iso is required.");}
function validate_edtCountryName(){edtCountryName=validateRequiredText("edtCountryName", "Country Name is required.");}
function validate_edtCountryNicename(){edtCountryNicename=validateRequiredText("edtCountryNicename", "Country Nicename is required.");}
function validate_edtCountryIso3(){edtCountryIso3=validateRequiredText("edtCountryIso3", "Country Iso3 is required.");}
function validate_edtCountryNumcode(){edtCountryNumcode=validateRequiredText("edtCountryNumcode", "Country Numcode is required.");}
function validate_edtCountryPhonecode(){edtCountryPhonecode=validateRequiredText("edtCountryPhonecode", "Country Phonecode is required.");}

function viewCountry(id)
{
	var data = {}
	data.dummy = "";
	data.hddnCountryId = id;
	data.action = 2;
	callModule("country/country_val.php", data);
}

function editCountry(id)
{
	var data = {}
	data.dummy = "";
	data.hddnCountryId = id;
	data.action = 3;
	callModule("country/country_val.php", data);
}

function deleteCountry(id, desc)
{
	if (confirm("Are you sure you want to delete "+desc+" and all associated records?"))
	{
		var data = {}
		data.dummy = "";
		data.hddnCountryId = id;
		data.action = 4;
		callModule("country/country_val.php", data);
	}
}

function setCountryName()
{
	"use strict"; 
	var sel = document.getElementById('selCountryId');
	document.getElementById('edtCountryName').value = sel.options[sel.selectedIndex].innerHTML;
}
