/* ----------------------------------------------------------------------------------------------------------------
*	
Function:	validateField, saveRecord

Functionality:
Makes Contact reason mandatory and allows user to add detailed Contact Reason Message.

Deployment:
The script can be deployed on External Contact Us form.

Event triggering the script:
	1) validateField.
	2) onSave
	
Custom Fields:
+-----------------------------------------------------------------------------------------------------------------+
| S. No.|	Id					|	Type			|	Level	|		Description							
+-----------------------------------------------------------------------------------------------------------------+
| (1)	|	_contact_reason	    |	List			|	Body	|	    This list contains title for all Contact reasons. |
| (2)	|	_detail				|	Free Form text	|	Body	|	    This field holds detailed Contact reason message. |
Create above custom fields with their id and type as mentioned in table.
*------------------------------------------------------------------------------------------------------------------
*/

// Global Variables
{
	// TODO: provide the detailed contact reason message here.
	strContactReason1	= "";
	strContactReason2	= "";
}
// End - Global Variables


function saveRecord(type,name)
{
	if ( (nlapiGetFieldValue('custbody_contact_reason')) == '')
	{
		alert("Please select a contact reason.");
		return false;
	}

	return true;
}

function validateField(type, name)
{
	if(name == 'custbody_contact_reason')
	{
		var contactReason = String(nlapiGetFieldValue('custbody_contact_reason'));
		
		if (contactReason == "1")
		{
 			nlapiSetFieldValue('custbody_detail', strContactReason1);
			return false;
		}
		else if (contactReason == "2")
		{
			nlapiSetFieldValue('custbody_detail', strContactReason2);
			return false;
		}
	}
	return true;
}