﻿function getSvcResult(servicePath, method, request, successCallback, errorCallback) {
	///	<summary>
	///		Call's a Webservice
	///	</summary>
	///	<param name="servicePath" type="String">
	///		The Service to call
	///	</param>
	///	<param name="request" type="object">
	///		The request data to send
	///	</param>
	///	<param name="successCallback" type="Function">
	///		A function to execute on success
	///	</param>
	///	<param name="errorCallback" type="Function">
	///		A function to execute on error
	///	</param>
	var jsonReq = JSON2.stringify(request);

	//var jsonReq = this.getJson(request);
	var bare = false;

	$.ajax({
		type: 'POST',
		contentType: 'application/json; charset=utf-8',
		data: jsonReq == 'null' ? '{}' : jsonReq,
		//dataType: "text",  // not "json" we'll parse
		//processData: false,
		dataType: 'json',
		processData: true,
		parseResult: false,
		//url: document.location.protocol + '//' + document.location.host + servicePath,
		url: servicePath + '/' + method,
		//success: successCallback,
		success: function(res) {
			if (!successCallback) {
				return;
			}
			var result = res;
			if (this.parseResult) {
				// *** Use json library so we can fix up MS AJAX dates
				result = JSON2.parse(res);
			}

			// *** Bare message IS result
			if (bare) {
				successCallback(result);
				return;
			}
			// *** Wrapped message contains top level object node
			// *** strip it off
			for (var property in result) {
				successCallback(result[property]);
				break;
			}
		},
		//error: errorCallback ? errorCallback : defaultErrorHandler
		error: function(xhr) {
			if (!errorCallback) {
				errorCallback = defaultErrorHandler;
			}

			if (xhr.responseText) {
				var err = JSON2.parse(xhr.responseText);

				if (err) {
					errorCallback(err);
					return;
				}
			}
			errorCallback(xhr);
			return;
		}
	});
}

function showError(ex) {
	var html = '';

	html = 'Error:<br />';

	for (var p in ex) {
		html += '\t' + p + ' : ' + ex[p] + '<br/>';
	}

	alert(html);
}

function IsRandom(seed) {
	var interval = seed == undefined ? 4 : seed;
	return (new Date().getSeconds() % interval == 0);
}

$(document).ready(function() {
	var side = IsRandom(2) ? "photoLeft" : "photoRight";
	$('<div />').appendTo('.header').addClass(side);

	/*$(function() {
	$("body .nav li").each(function() {
	if ($(this).find("ul").length > 0) {

	//show subnav on hover  
	$(this).mouseenter(function() {
	$(this).find("ul").stop(true, true).slideDown();
	});

	//hide submenus on exit  
	$(this).mouseleave(function() {
	$(this).find("ul").stop(true, true).slideUp();
	});

	$(this).find("ul").mousemove(function() {
	$(this).stop(true, true).show();
	});
	}
	});
	});*/

	$('span.share').Share('ZaakM');
});
