var modalName;
var loginFailed;

 $(document).ready(function() {
	if (loginFailed == "True" && modalName != '') {
		setLoginModalAction(modalName);
		showLoginModal();
	} else if (modalName == "video_upload") {
		// if the widget names change or you add the video upload button to another page, you must put an if statement here
		if(typeof(widget) !== "undefined") {
			widget.photoVideoTabWidget.switchTab(1);
		} else if (typeof(communityWidget) !== "undefined") {
			communityWidget.tabs[0].widget.photoVideoTabWidget.switchTab(1);
		}
	};

	if ($("body").hasClass("hotel")) {
		setLoginModalAction("hotel_modal");
	}
	if ($("body").hasClass("restaurant")) {
		setLoginModalAction("restaurant_modal");
	}
  	if ($("body").hasClass("nightlife")) {
		setLoginModalAction("nightlife_modal");
	}
  	if ($("body").hasClass("thingstodo")) {
		setLoginModalAction("thingstodo_modal");
	}
  	if ($("body").hasClass("shopping")) {
		setLoginModalAction("shopping_modal");
	}

});


function setLoginModalAction(redirectModalName) {
	$('#modalLoginForm').attr("action", "https://" + window.APP_HOST + "/j_spring_security_check?modal=" + redirectModalName);
}


function showSpinner() {
	$("#loadingVideo").show();
	$("#add_a_video_button").attr("disabled", "true");
}

function setTripModalActionToVideoUploadModal() {
	if(typeof(widget) != "undefined") {
		$('#redirectModal').val("widget.photoVideoTabWidget.tabs[1].widget.videoUploadWidget");
	} else if (typeof(communityWidget) != "undefined") {
		$('#redirectModal').val("communityWidget.tabs[0].widget.photoVideoTabWidget.tabs[1].widget.videoUploadWidget");
	} else if (typeof(memberWidget) != "undefined") {
		if (typeof (memberWidget.contextWidget.photoVideoTabWidget) != "undefined") {
	        	$('#redirectModal').val("memberWidget.contextWidget.photoVideoTabWidget.tabs[1].widget.videoUploadWidget");
		} else if (typeof (memberWidget.contextWidget.videoListWidget) != "undefined") {
			$('#redirectModal').val("memberWidget.contextWidget.videoListWidget.videoUploadWidget");
		}
	} else if (typeof(galleryWidget) != "undefined") {
		$('#redirectModal').val("galleryWidget.videoUploadWidget");
	}
}

function setTripModalActionToPhotoUploadModal() {
	$('#redirectModal').val("custom_multipleFileUploadWidget");
}