function setPermStates2($contIds) {
	var urlRegExp = /^http:\/\/(?:.*\/)+(?:(.*)(\.\w{3,4})?)?$/;
	$urlName = location.href.replace(urlRegExp, '$1') || 'index';
	for(var $i = 0; $i < $contIds.length; ++$i) {
		$container = document.getElementById($contIds[$i]);
		if($container != null) {
			$links = $container.getElementsByTagName('a');
			for(var $j = 0; $j < $links.length; ++$j) {
				if($urlName.indexOf($links[$j].href.replace(urlRegExp, '$1')) >= 0) {
					$links[$j].className += ' selected';
					break;
				}
			}
		}
	}
}

function setPermStates($contIds) {
	
	//setPermStates2 ($contIds);
	// REAL CODE BELOW //
	var $container, $links, $i, $j, $pathname;
	// special case for join first page
	var $join_p1 = '/pub/nlms/processform/join';
	var $join_p1_sub = '/pub/nlms/assist/membership';
	
	$pathname = location.pathname == $join_p1 ? $join_p1_sub : location.pathname;
	
	for($i = 0; $i < $contIds.length; ++$i) {
		$container = document.getElementById($contIds[$i]);
		if($container != null) {
			$links = $container.getElementsByTagName('a');
			for($j = 0; $j < $links.length; ++$j) {
				if($pathname.indexOf($links[$j].className) >= 0) {
					$links[$j].className += ' selected';
					//break;
				}
			}
		}
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////

var popPullDown = undefined;

function populatePullDown (srcPullDown, optionsArray) {
	
	var idx, optionElement;
	
	srcPullDown.selectedIndex = 0;
	
	for (idx = srcPullDown.options.length - 1; idx > 0; --idx) {
		srcPullDown.options [idx] = null;
	}
	
	for (idx = 0; idx < optionsArray.length; ++idx) {
		optionElement = new Option (optionsArray [idx].text, optionsArray [idx].value);
		srcPullDown.options [srcPullDown.options.length] = optionElement;
	}
}

function requestCallBack (responseCode) {
	
	populatePullDown (popPullDown, eval (responseCode));
	popPullDown = undefined;
}

function populateCasinosByLocation (srcPullDown, destPullDown) {
	
	if ((srcPullDown.selectedIndex != 0) && (popPullDown == undefined)) {
		
		// execute Code
		popPullDown = destPullDown;
		
		wsPlaces.createRequest ('get_casinos_by_location.php', requestCallBack, '',
			[[srcPullDown.id, srcPullDown.options [srcPullDown.selectedIndex].value]]);
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////

// for now this function assumes $object is a text input field or textarea field
function jsMaxLength ($object, $maxLength) {
	
	if ($object.value.length > $maxLength) {
		$object.value = $object.value.substr (0, $maxLength);
		return false;
	}
	return true;
}

/************************************************************************************************/
function load_advs_in_container ($advs) {
	
	document.getElementById ('advs_container').innerHTML = $advs;
}

function load_advs ($advs_cat_id) {
	
	$advs_cat_id = parseInt ($advs_cat_id, 10);
	
	if ((isNaN ($advs_cat_id))) $advs_cat_id = '';
	
	var web_service = new WebService ();
	
	web_service.createRequest (location.protocol + '//' + location.host + '/pub/gen/advs/' + $advs_cat_id, load_advs_in_container);
}