var errors, hddnSmsId, edtSmsNumber, edtSmsMessage, cbSmsSent, edtSmsReply, edtSmsKey, selClientId;
var module = baseRootURL + "sms_message/";

function registerSmsMessage(action)
{
	errors = false;
	validate_hddnSmsId();
	validate_edtSmsNumber();
	validate_edtSmsMessage();
	validate_cbSmsSent();
	validate_edtSmsReply();
	validate_edtSmsKey();
	validate_selClientId();
	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("hddnSmsId") != null) data.hddnSmsId = hddnSmsId;
		data.edtSmsNumber = edtSmsNumber;
		data.edtSmsMessage = edtSmsMessage;
		data.cbSmsSent = cbSmsSent;
		data.edtSmsReply = edtSmsReply;
		data.edtSmsKey = edtSmsKey;
		data.selClientId = selClientId;
		callModule("sms_message/sms_message_val.php", data);
	}
}
function insertSmsMessage(){registerSmsMessage(0)}
function modifySmsMessage(){registerSmsMessage(1)}

function validate_hddnSmsId(){
	if (document.getElementById("hddnSmsId") != null) hddnSmsId=document.getElementById("hddnSmsId").value;}
function validate_edtSmsNumber(){edtSmsNumber=validatePhoneNumber("edtSmsNumber", "Phone number is required.", true);}
function validate_edtSmsMessage(){edtSmsMessage=validateRequiredText("edtSmsMessage", "This field is required.");}
function validate_cbSmsSent(){cbSmsSent = document.getElementById("cbSmsSent").checked;}
function validate_edtSmsReply(){edtSmsReply=validateRequiredText("edtSmsReply", "This field is required.");}
function validate_edtSmsKey(){edtSmsKey=validateRequiredText("edtSmsKey", "This field is required.");}
function validate_selClientId(){selClientId=validateRequiredSelection("selClientId", "Please make a valid selection.");}

function viewSmsMessage(id)
{
	var data = {}
	data.dummy = "";
	data.hddnSmsId = id;
	data.action = 2;
	callModule("sms_message/sms_message_val.php", data);
}

function viewSMSReply(id)
{
	var data = {}
	data.dummy = "";
	data.hddnSmsId = id;
	data.action = 5;
	callModule("sms_message/sms_message_val.php", data);
}

function editSmsMessage(id)
{
	var data = {}
	data.dummy = "";
	data.hddnSmsId = id;
	data.action = 3;
	callModule("sms_message/sms_message_val.php", data);
}

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