// JavaScript Document: Validate QuoteRequest form.
// #INCLUDE('jquery.js')
// #INCLUDE('validations.js')
// #INCLUDE('validation-helper.js')

// TODO: set label CSS classes.
var ErrorClass = 'error';
var ElementPrefix = "lbl"; /* e.g. the indicator id = 'lbl' + id_of_input_element */
var MessagePrefix = "msg"; /* the message id = 'msg' + id_of_input_element */

//------------ DO NOT EDIT from here onwards. ------------------------------------------------------
//
//

/*function validate_Multiselect(widgetId) {
	var $widget = $("#"+widgetId);
	var $l = getErrorDisplay(widgetId);
	var $m = getErrorMessage(widgetId);

	return ($widget.selectedCount() == 0) ? isValid($l, $m, false) : isValid($l, $m, true);
}*/

function validate_Description() {
	// check if the click event is still bound to the textarea.
	var widgetId = 'Description';
	var $widget = getWidget(widgetId);
	var $l = getErrorDisplay(widgetId);
	var $m = getErrorMessage(widgetId);
	var v = trim($widget.val());

	return isValid($l, $m, (!$.hasEventListener(document.getElementById(widgetId), "click") && v!=''));
}

function validate_RecyclingTypes() {
	var widgetId = 'RecyclingTypes';
	var $l = getErrorDisplay(widgetId);
	var $m = getErrorMessage(widgetId);

	return isValid($l, $m, $('#RecyclingTypes option:selected').length);
}

function validate_QRF_tab1() {
	var vOk=true; //validator status variable.

	// validate field: Description
	if(! validate_Description())
		vOk = false;

	// validate field: When
	// Though this is a drop-down control, the invalid value==""
	if(! validate_notEmpty('When'))
		vOk = false;

	// validate field: BusinessDomain
	// Though this is a drop-down control, the invalid value==""
	if(! validate_notEmpty('BusinessDomain'))
		vOk = false;

	// validate field: RecyclingTypes
	/*if(! validate_Multiselect('RecyclingTypes'))
		vOk = false;*/
	if(! validate_RecyclingTypes())
		vOk = false;

	return vOk;
}

function validate_QRF_tab2() {
	var vOk=true; //validator status variable.

	// validate field: Name
	if(! validate_notEmpty('Name'))
		vOk = false;

	// validate field: Email
	if(! validate_email('Email'))
		vOk = false;

	// validate field: Telephone
	if(! validate_notEmpty('Telephone'))
		vOk = false;

	// validate field: County
	// Though this is a drop-down control, the invalid value==""
	if(! validate_notEmpty('County'))
		vOk = false;

	// validate field: Municipality
	// Though this is a drop-down control, the invalid value==""
	if(! validate_notEmpty('Municipality'))
		vOk = false;

	return vOk;
}

// pass through and highlight all fields which fail the validation test.
function validate_QuoteRequestForm() {
	return validate_QRF_tab1() && validate_QRF_tab2();
} //endfunc

