﻿// (C) Rögg Corporation - All rights reserved

/*
 * Limit characters in an textarea input box to certain number.
 */
function limitChars(textid, limit) {

	var textlength = $('#' + textid).val().length;

	if (textlength > limit) {
		$('#' + textid).val($('#' + textid).val().substr(0, limit));
		
		return false;
	}
	else {
		return true;
	}
}

function onSelectedIndexChanged_LocationSelector(obj,additionalInfoElementId,justHereToInitialize) {

	selectedValue = obj.options[obj.selectedIndex].value;
	moreTextIndex = selectedValue.indexOf('_');	// Search for "1_Which hotel?" for instance.

	if (-1 < moreTextIndex) {

		var setClearHook = false;

		if (0 >= document.getElementById(additionalInfoElementId).value.length || (!justHereToInitialize && document.getElementById(additionalInfoElementId).value != selectedValue.substr(moreTextIndex + 1)))
		{
			document.getElementById(additionalInfoElementId).value = selectedValue.substr(moreTextIndex + 1);
			setClearHook = true;
		}

		if (setClearHook || document.getElementById(additionalInfoElementId).value == selectedValue.substr(moreTextIndex + 1))
		{
			// Set hint-text and arrange for the text to be cleared upon FIRST click or focus in the text box.
			$("#" + additionalInfoElementId).addClass("error");

			$("#" + additionalInfoElementId).bind('focus', function(event) { $(this).removeClass("error"); this.value = ''; $(this).unbind('focus'); });
		}

		$("#" + additionalInfoElementId).removeClass('hidden_from_sight');
		//$("#" + additionalInfoElementId).show();
	}
	else {
		document.getElementById(additionalInfoElementId).value = '';

		$("#" + additionalInfoElementId).addClass('hidden_from_sight');
		//$("#" + additionalInfoElementId).hide();
	}
}

function onSelectedIndexChanged_TimeSelector(obj) {

	if (obj.options[0].value == "X") {

		obj.remove(0);
	}
}

function onVehicleOptionSelected(checkboxId, comboId) {

	if ($("#" + checkboxId).attr('checked')) {
		$("#" + comboId).attr("disabled", false);
	}
	else {
		$("#" + comboId).attr("disabled", true);
	}
}

