// http://www.dexign.net/post/2008/07/16/jQuery-To-Call-ASPNET-Page-Methods-and-Web-Services.aspx

function PageMethod(pagePath, fn, paramArray, successFn, errorFn) {   
	if (pagePath == '')
		pagePath = window.location.pathname;

	if (pagePath == '/')
		pagePath = 'default.aspx';
		
	var paramList = '';
	if (paramArray.length > 0)
	{
		for (var i=0; i<paramArray.length; i+=2)
		{
			if (paramList.length > 0) paramList += ',';
			paramList += '"' + paramArray[i] + '":"' + paramArray[i+1].replace(/"/g, '\\\"') + '"';
		}
	}
	paramList = '{' + paramList + '}';
	
	//Call the page method   
	$.ajax({
		type: "POST",
		url: pagePath + '/' + fn,
		contentType: "application/json; charset=utf-8",
		data: paramList,
		dataType: "json",
		success: successFn,
		error: errorFn
	})
;}

function GenericFail(xml, options, msg) {
	alert(xml.statusText + ": " + xml.responseText + " - " + options + " / " + msg.d);
}
