var licenceTypes = new Array();

$( function() {
	
	$('#licenceTypeField').bind('change', showHideContent);
	showHideContent();	

	$('input[name=workSelectGroup]').click(function(e) {
		$('#contentUploadContainer .rowContent').show('normal');
		if($.trim($(e.target).val()) == $.trim($('input[name=workSelectGroup]:last').val())) {
			$('#userCitationContainer .rowContent').show('normal');
			$('#enteringUserCitation').val('true');
		} else {
			$('#userCitationContainer .rowContent').hide('normal');
			$('#enteringUserCitation').val('');
		}
		$('#providingContent').val('true');
	});

	if($('.fieldError').length == 0) {
		$('input[name=workSelectGroup]').attr('checked', '');
	} else {
		if(isValueTrue( $.trim( $('#enteringUserCitation').val()))) {
			$('#userCitationContainer .rowContent').show('normal');
		}
	}

	//show provide content as opened.
	if(isValueTrue($.trim($('#providingContent').val()))) {
		$('#contentUploadContainer .rowContent').show();
	}
	 	
});

function isValueTrue(value) {
	return value == 'true' || value == 'Strue';
}

function showHideContent() {
	licenceSelection = $('#licenceTypeField :selected').text();
	
	if(licenceTypes) {
		for (var i=0; i<licenceTypes.length; i++){
			if (licenceTypes[i].name == licenceSelection ) {
				if ( licenceTypes[i].allowsUpload ) {
					$('#contentUploadGroup').show();						
				} else {
					$('#contentUploadGroup').hide();						
				}
				return;
			}					
		}
	}			
}