﻿function test() {

	AdminService.HelloWorld(onHelloWorldRequestComplete, onUpdateInvokeError);
}

function onHelloWorldRequestComplete(result) {
}

function onUpdateInvokeError(result) {
}


function addCostume() {
	var costumePicId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	var costumeDesc = $('#ctl00_m_MainContent_m_AddCharacterDesc').val();
	AdminService.AddCharacterCostume(g_CharacterId, costumePicId, costumeDesc, onAddCostumeResponse, onUpdateInvokeError);
	$('#m_AddCharacterCostumeDlg').jqmHide()
}


function setCharacterOutfitImage() {
	var costumeNewPicId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	var costumeImageId = $('#ctl00_m_MainContent_m_SetCharacterOutfitDropDown').val();
	AdminService.SetCharacterOutfitImage(g_CharacterId, costumeNewPicId, costumeImageId, onAddCostumeResponse, onUpdateInvokeError);
	$('#m_SetOutfitPicDlg').jqmHide()
}


function delCostume(id) {
	AdminService.DeleteCharacterCostume(g_CharacterId, id, onAddCostumeResponse, onUpdateInvokeError);
}


function onAddCostumeResponse(result) {
	$('#ctl00_m_MainContent_m_CostumeTable').html(result);
	$('#ctl00_m_MainContent_m_Costumes').show();
	$("a[rel*=lightbox]").lightBox();
}


function delCharacter(id) {
	AdminService.DeleteCharacterFromLocation(g_LocationId, id, onAddCharacterToLocationResponse, onUpdateInvokeError);
}

function updateCharacterNeedToMeet(id, needToMeet) {
	AdminService.UpdateCharacterLocationNeedToMeet(g_LocationId, id, needToMeet, onAddCharacterToLocationResponse, onUpdateInvokeError);
}

function updateCharacterIsHistorical(id, isHistorical) {
	AdminService.UpdateCharacterLocationIsHistorical(g_LocationId, id, isHistorical, onAddCharacterToLocationResponse, onUpdateInvokeError);
}

function addCharacterLocation() {
	var characterId = $('#ctl00_m_MainContent_m_AddCharacterDropDown').val();
	var costumePicId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	var costumeDesc = $('#ctl00_m_MainContent_m_AddCharacterDesc').val();
	var isHistorical = $('#ctl00_m_MainContent_m_AddCharacterIsHistorical')[0].checked;
	var needToMeet = $('#ctl00_m_MainContent_m_AddCharacterNeedToMeet')[0].checked;
	var addCostume = $('#ctl00_m_MainContent_m_AddCharacterAddCostume')[0].checked;
	var costumeDescription = $('#ctl00_m_MainContent_m_CostumeDescription').val();
	AdminService.AddCharacterToLocation(g_LocationId, characterId, costumePicId, costumeDesc, isHistorical, needToMeet, addCostume, costumeDescription, onAddCharacterToLocationResponse, onUpdateInvokeError);
	$('#m_AddCharacterDlg').jqmHide()
}

function setCharacterLocationImage() {
	var locationPicId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	var characterImageId = $('#ctl00_m_MainContent_m_SetCharacterDropDown').val();
	var costumeDesc = $('#ctl00_m_MainContent_m_SetCharacterDesc').val();
	AdminService.SetCharacterLocationImage(characterImageId, locationPicId, costumeDesc, onAddCharacterToLocationResponse, onUpdateInvokeError);
	$('#m_SetCharacterPicDlg').jqmHide()
}

function onAddCharacterToLocationResponse(result) {
	if (result != null && result != "") {
		$('#ctl00_m_MainContent_m_CharactersTable').html(result);
		$('#ctl00_m_MainContent_m_Characters').show();
	}

	updateScriptToRun();
}


function addFeatutedToLocation() {
	var photoId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	var desc = $('#ctl00_m_MainContent_m_AddFeaturedDesc').val();
	AdminService.AddFeaturedToLocation(g_LocationId, photoId, desc, onAddFeaturedToLocationResponse, onUpdateInvokeError);
	$('#m_AddFeaturedDlg').jqmHide()
}


function onAddFeaturedToLocationResponse(result) {
	if (result != null && result != "") {
		$('#ctl00_m_MainContent_m_FeaturedPhotosTable').html(result);
		$('#ctl00_m_MainContent_m_FeaturedPhotos').show();
	}
}



function addCharacterTrip() {
	var tripReportId = getQueryStringArgument("TripReportId");
	var characterId = $('#ctl00_m_MainContent_m_AddCharacterDropDown').val();
	var costumePicId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	var costumeDesc = $('#ctl00_m_MainContent_m_AddCharacterDesc').val();
	AdminService.AddCharacterToTripReport(tripReportId, characterId, costumePicId, costumeDesc, onAddCharacterToTripReportResponse, onUpdateInvokeError);
	$('#m_AddCharacterDlg').jqmHide()
}

function setCharacterTripImage() {
	var locationPicId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	var characterImageId = $('#ctl00_m_MainContent_m_SetCharacterDropDown').val();
	var costumeDesc = $('#ctl00_m_MainContent_m_SetCharacterDesc').val();
	AdminService.SetCharacterTripReportImage(characterImageId, locationPicId, costumeDesc, onAddCharacterToTripReportResponse, onUpdateInvokeError);
	$('#m_SetCharacterPicDlg').jqmHide()
}

function onAddCharacterToTripReportResponse(result) {
	if (result != null && result != "") {
		$('#ctl00_m_MainContent_m_CharactersTable').html(result);
		$('#ctl00_m_MainContent_m_Characters').show();
	}
}

function addCharacterProduction() {
	var tripReportId = g_ProductionId;
	var characterId = $('#ctl00_m_MainContent_m_AddCharacterDropDown').val();
	var costumePicId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	var costumeDesc = $('#ctl00_m_MainContent_m_AddCharacterDesc').val();
	AdminService.AddCharacterToProduction(tripReportId, characterId, costumePicId, costumeDesc, onAddCharacterToProductionResponse, onUpdateInvokeError);
	$('#m_AddCharacterDlg').jqmHide()
}

function setCharacterProductionImage() {
	var locationPicId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	var characterImageId = $('#ctl00_m_MainContent_m_SetCharacterDropDown').val();
	var costumeDesc = $('#ctl00_m_MainContent_m_SetCharacterDesc').val();
	AdminService.SetCharacterProductionImage(characterImageId, locationPicId, costumeDesc, onAddCharacterToProductionResponse, onUpdateInvokeError);
	$('#m_SetCharacterPicDlg').jqmHide()
}

function delCharacterProduction(id) {
	AdminService.DeleteCharacterFromProduction(g_ProductionId, id, onAddCharacterToProductionResponse, onUpdateInvokeError);
}
function onAddCharacterToProductionResponse(result) {
	if (result != null && result != "") {
		$('#ctl00_m_MainContent_m_CharactersTable').html(result);
		$('#ctl00_m_MainContent_m_Characters').show();
	}
}



function setCharacterMainImage() {
	var costumePicId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	AdminService.SetCharacterMainImage(g_CharacterId, costumePicId, onSetMainImageResponse, onUpdateInvokeError);
}

function setLocationMainImage() {
	var costumePicId = $('#ctl00_m_MainContent_m_CharacterImageToSet').val();
	AdminService.SetLocationMainImage(g_LocationId, costumePicId, onSetMainImageResponse, onUpdateInvokeError);
}

function onSetMainImageResponse(result) {
	if (result != null && result != "") {
		$('#m_MainImageCell').html(result);
	}
}


function getQueryStringArgument (sArgName) 
{
	var sSearchStr = location.search.substring(1);
	if (sSearchStr == null) 
		return null;
		
	var aArgs = sSearchStr.split('&');
	var aArgParts;
	for (var iArgCnt = 0; iArgCnt < aArgs.length; iArgCnt++) {
		aArgParts = aArgs[iArgCnt].split('=');
		if (aArgParts[0].toLowerCase() == sArgName.toLowerCase()) 
		{
			var sValue = aArgParts[1].split('+').join(' ');
			return unescape(sValue);
			
		}
	}
	return null;
}

$(charStartup);

function charStartup() {
	$("#CharacterLocationTabParent").tabs();
	var $tabs = $("#PictureTabParent").tabs({
		load: function(event, ui) {

			try {
				// Select all links that contains lightbox in the attribute rel
				$("#PictureTabParent a[rel*=lightbox]").lightBox();
				if (typeof (charOnPictureLoad) != "undefined")
					charOnPictureLoad();
			}
			catch (e) {
			}

			$('#navigation a', ui.panel).click(function() {
			var selected = $tabs.tabs('option', 'selected');
			$tabs.tabs('url', selected, this.href);
			$tabs.tabs('load', selected);
				/*$(ui.panel).load(this.href, function() {
					alert('Load was performed.');
				});*/
				return false;
			});
		}
	});
}
