﻿// JScript File
Type.registerNamespace('PlatformScript');

PlatformScript.Failed = function(response) {
    var result = Sys.Serialization.JavaScriptSerializer.serialize(response);
    alert(result);
}

Type.registerNamespace('PlatformScript.ProjectItem');

PlatformScript.ProjectItem.Subscription = function(id, cbx) {
    PlatformService.UpdateSubscription(id, $get(cbx).checked, PlatformScript.ProjectItem.UpdateSubscriptionSuccess, PlatformScript.Failed);
}

PlatformScript.ProjectItem.UpdateSubscriptionSuccess = function(response) {
    $('#subscriptionFeedback').hide('fast', function() { $get('subscriptionFeedback').innerHTML = response; });
    $('#subscriptionFeedback').show('slow');
}

PlatformScript.ProjectItem.Spotlight = function(id, cbx) {
    PlatformService.UpdateSpotlight(id, $get(cbx).checked, PlatformScript.ProjectItem.UpdateSpotlightSuccess, PlatformScript.Failed);
}

PlatformScript.ProjectItem.UpdateSpotlightSuccess = function(response) {
    $('#spotlightFeedback').hide('fast', function() { $get('spotlightFeedback').innerHTML = response; });
    $('#spotlightFeedback').show('slow');
}

Type.registerNamespace('PlatformScript.Voting');

PlatformScript.Voting.VoteElement = null;
PlatformScript.Voting.Vote = function(positive, itemId) {
    PlatformScript.Voting.VoteElement = 'showVote_' + itemId;
    PlatformService.Vote(positive, itemId, PlatformScript.Voting.VoteSuccess, PlatformScript.Failed);
}

PlatformScript.Voting.VoteSmall = function(positive, itemId) {
    PlatformScript.Voting.VoteElement = 'showVote_' + itemId;
    PlatformService.VoteSmall(positive, itemId, PlatformScript.Voting.VoteSuccess, PlatformScript.Failed);
}

PlatformScript.Voting.VoteSuccess = function(response) {
    if(PlatformScript.Voting.VoteElement != null) {
        if($get(PlatformScript.Voting.VoteElement)) $get(PlatformScript.Voting.VoteElement).innerHTML = response;
    }
}

PlatformScript.Voting.VoteDoeMee = function(positive, itemId) {
    PlatformScript.Voting.VoteElement = 'showVote_' + itemId;
    PlatformService.VoteDoeMee(positive, itemId, PlatformScript.Voting.VoteSuccess, PlatformScript.Failed);
}

PlatformScript.Voting.VoteEnrichmentElement = null;
PlatformScript.Voting.VoteEnrichment = function(itemId) {
    PlatformScript.Voting.VoteEnrichmentElement = 'showEnrichmentVote_' + itemId;
    PlatformService.VoteEnrichment(itemId, PlatformScript.Voting.VoteEnrichmentSuccess, PlatformScript.Failed);
}

PlatformScript.Voting.VoteEnrichmentSuccess = function(response) {
    if(PlatformScript.Voting.VoteEnrichmentElement != null) {
        if($get(PlatformScript.Voting.VoteEnrichmentElement)) $get(PlatformScript.Voting.VoteEnrichmentElement).innerHTML = response;
    }   
}

PlatformScript.Voting.VoteNotDesiredElement = null;
PlatformScript.Voting.VoteNotDesired = function(itemId) {
    PlatformScript.Voting.VoteNotDesiredElement = 'showNotDesiredVote_' + itemId;
    PlatformService.VoteNotDesired(itemId, PlatformScript.Voting.VoteNotDesiredSuccess, PlatformScript.Failed);
}

PlatformScript.Voting.VoteNotDesiredSuccess = function(response) {
    alert('Gerapporteerd aan de moderators.');
    if (PlatformScript.Voting.VoteNotDesiredElement != null) {
        if ($get(PlatformScript.Voting.VoteNotDesiredElement)) $get(PlatformScript.Voting.VoteNotDesiredElement).innerHTML = response;
    }
}

Type.registerNamespace('PlatformScript.Project');

PlatformScript.Project.ShowLatest = function(id) {
    PlatformService.ShowLatestProject(id, PlatformScript.Project.ShowLatestSuccess, PlatformScript.Failed);
}

PlatformScript.Project.ShowLatestSuccess = function(response) {
    $get('showLatest').innerHTML = response;
}

Type.registerNamespace('PlatformScript.Reaction');

PlatformScript.Reaction.ItemId = null;
PlatformScript.Reaction.Edit = function(id) {
    PlatformScript.Reaction.ItemId = id;  
    PlatformService.ReactionEdit(id, PlatformScript.Reaction.EditSucces, PlatformScript.Failed);
}

PlatformScript.Reaction.EditSucces = function(response) {
    $get('reaction_' + PlatformScript.Reaction.ItemId).innerHTML = response;
}

PlatformScript.Reaction.CancelEdit = function(id) {
    PlatformScript.Reaction.ItemId = id;  
    PlatformService.ReactionCancelEdit(id, PlatformScript.Reaction.UpdateSucces, PlatformScript.Failed);
}

PlatformScript.Reaction.Update = function(txt, id) {
    PlatformScript.Reaction.ItemId = id;  
    var text = encodeURIComponent(txt.value);
    PlatformService.ReactionUpdate(id, text, PlatformScript.Reaction.UpdateSucces, PlatformScript.Failed);
}

PlatformScript.Reaction.UpdateSucces = function(response) {
    $get('reaction_' + PlatformScript.Reaction.ItemId).innerHTML = response;
}

PlatformScript.Reaction.Quote = function(id) {
    PlatformService.ReactionQuote(id, PlatformScript.Reaction.QuoteSucces, PlatformScript.Failed);
}

PlatformScript.Reaction.QuoteSucces = function(response) {
    window.location.hash = 'add_item';
    if($get('addReaction')) {
		$get('addReaction').firstChild.innerHTML = response;
		$get('addReaction').firstChild.focus();
    }
}

Type.registerNamespace('PlatformScript.News');

PlatformScript.News.Show = function(id) {
    PlatformService.ShowNews(id, PlatformScript.News.ShowSuccess, PlatformScript.Failed);
}

PlatformScript.News.ShowSuccess = function(response) {
    $get('showLatest').innerHTML = response;
}

Type.registerNamespace('PlatformScript.Tag');

PlatformScript.Tag.ItemId = null;
PlatformScript.Tag.Type = null;
PlatformScript.Tag.Add = function(tag, itemId, type, cat) {
    PlatformScript.Tag.ItemId = itemId;
    PlatformScript.Tag.Type = type; 
    PlatformService.AddTag(tag, itemId, type, cat, PlatformScript.Tag.Success, PlatformScript.Failed);
}

PlatformScript.Tag.Remove = function(tag, itemId, type) {
    PlatformScript.Tag.ItemId = itemId;
    PlatformScript.Tag.Type = type;
    PlatformService.RemoveTag(tag, itemId, type, PlatformScript.Tag.Success, PlatformScript.Failed);
}

PlatformScript.Tag.Success = function(response) {
    $get('tags_' + PlatformScript.Tag.Type + '_' + PlatformScript.Tag.ItemId).innerHTML = response;
}

Type.registerNamespace('PlatformScript.User');

PlatformScript.User.RssElement = null;
PlatformScript.User.GenerateRss = function(elem) {
    PlatformScript.User.RssElement = elem;
    PlatformService.GenerateRss(PlatformScript.User.GenerateRssSuccess, PlatformScript.Failed);
}

PlatformScript.User.GenerateRssSuccess = function(response) {
    PlatformScript.User.RssElement.value = response;
}

Type.registerNamespace('PlatformScript.Shoutbox');

PlatformScript.Shoutbox.Add = function(txt) {
    var text = txt.value;
    if(text.length > 250) {
		alert('bericht bevat meer dan 250 karakters');
    }
    else {
		if ((text != '') && (text != 'Typ hier uw bericht')) {
			PlatformService.ShoutboxAdd(text, PlatformScript.Shoutbox.AddSuccess, PlatformScript.Failed);
			txt.value = '';
			document.getElementById("Warning").style.display = "none";

		} else {
			//txt.value = ''; 
			document.getElementById("Warning").style.display = "block";
		}
    }
}

PlatformScript.Shoutbox.AddSuccess = function(response) {
    $get('shouts').innerHTML = response;
}

Type.registerNamespace('PlatformScript.Dossier');

PlatformScript.Dossier.Subscription = function(id, cbx) {
    PlatformService.UpdateDossierSubscription(id, $get(cbx).checked, PlatformScript.Dossier.UpdateSubscriptionSuccess, PlatformScript.Failed);
}

PlatformScript.Dossier.UpdateSubscriptionSuccess = function(response) {
    $('#subscriptionFeedback').hide('fast', function() { $get('subscriptionFeedback').innerHTML = response; });     
    $('#subscriptionFeedback').show('slow');
}

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
