function editRecord(sID)
{
	location.href = getDBURL() + '/Data?OpenPage&ID='+sID;
}


function invalidField( vField, sAlertMessage )
{
	if( jsGetFieldValue(vField) == "")
	{
		alert( sAlertMessage );
		jsFieldFocus(vField);
		return true;
	}	
	return false;
}


function doSecurity()
{
	jsDialog('dlgSecurity', 700, 500, '&RoleName=AllowAccess');
}

function saveFormData()
{
	var vForm = document.forms[0];	
	//check for mandatory fields.
	var gAllElements = vForm.elements;	
	for(i=0; i<gAllElements.length; i++) 
	{ 
		if(gAllElements[i].attributes['mandatory'] && gAllElements[i].attributes['mandatory'].nodeValue == '1')
		{
			var sValidText = gAllElements[i].attributes['validationText'].nodeValue;
			if(sValidText=='') sValidText = 'Please enter a value in this field, it is mandatory';
			if(invalidField(gAllElements[i], sValidText)) return;
		}
	} 
			
	vForm.submit();
}

function toggleRecordActive(sActiveYN)
{
	var vForm = document.forms[0];
	var sID = jsGetFieldValue(vForm.ID);
	if(sID=='*')
	{
		alert('Please save this record first...');
		return;
	}
	
	if(confirm('Are you sure you want to change this record?')) location.href=getDBURL() + '/ToggleInactive?OpenAction&ID='+sID+'&Active='+sActiveYN;
}

function deleteRecord()
{
	var vForm = document.forms[0];
	var sID = jsGetFieldValue(vForm.ID);
	if(sID=='*')
	{
		alert('Please save this record first...');
		return;
	}
	
	if(confirm('Are you sure you want to delete this record?')) location.href=getDBURL() + '/DeleteData?OpenAction&ID='+sID;
}

function doSearch()
{
	var vForm = document.forms[0];
	if(invalidField(vForm.Search, "Please enter a term to search for")) return;
	
	vForm.submit();
}


function saveImportData()
{
	var vForm = document.forms[0];	
	vForm.submit();
}

