﻿/********************************************************************
* AMGAJAXHELPER
*
* Authors:
*  Gerald de Bueger (gerald@ldvproduction.be)
* 
* Copyright LDV Production 2010-2011
* http://www.ldvproduction.com
*
* DO NOT COPY OR USE WITHOUT PRIOR AGREEMENT FROM LDV Production
* 
*
********************************************************************/


/*********************************************************/
var AMGAjaxHelper = {
	Options: {
		type: "POST",
		url: "/WS/Broadcast.asmx/HelloWorld",
		data: '',
		mode: 'queue',
		cache: false,
		dataType: 'xml',
		success: function(__Resp) {
			return (__Resp)
		}
		, dataFilter: function(__Response, type) {
			try {
				var __Filtered = "";
				if ($().jquery <= 1.3) {
					__Filtered = __Response.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, 'new $1');
				}
				else {
					__Filtered = __Response.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, '"new $1"');
				}
				if (__Filtered.indexOf('{"d":') == 0) {
					__Filtered = __Filtered.substring(5, __Filtered.length - 1);
					return __Filtered;
				}
				else {
					return __Response;
				}
			}
			catch (e) {
				return __Response
			}
		}
		//, complete: function(jqXHR, textStatus) {
		//	alert(jqXHR)
		//	alert(textStatus)
		//}
		 //, error: function(XMLHttpRequest, textStatus, errorThrown) {
//
		 //	alert(errorThrown);
		 //}
	},
	GetJsonResponse: function(__Resp) {
		//GetObjectProperties(__Resp, true);
		return (__Resp.d);
	},
	GetResponse: function(__Resp) {
		var RetVal = (window.ActiveXObject) ? __Resp.selectSingleNode("//string").text : __Resp.getElementsByTagName('string')[0].textContent;
		RetVal = eval('(' + RetVal + ')')
		return RetVal;
	},
	CallXml: function(__Options) {
		//alert(44)
		this.CallBack = __Options.success;
		this.Options = $.extend(this.Options, __Options, { success: __Options.success });
		//LogDebug(1, this.Options);
		$.ajax(this.Options);
	},
	Call: function(__Options) {
		this.CallBack = __Options.success;
		this.Options = $.extend(this.Options, __Options, { dataType: 'xml', contentType: "application/x-www-form-urlencoded", success: __Options.success });
		$.ajax(this.Options);
		//jQuery.ajaxQueue(this.Options);
	},
	CallJson: function(__Options) {
		try {
			this.Options = $.extend(this.Options, __Options, { dataType: 'json', contentType: "application/json; charset=utf-8", success: __Options.success });
			//GetObjectProperties(this.Options, true)
			$.ajax(this.Options);
			//jQuery.ajaxQueue(this.Options);
		}
		catch (e) { alert('CallJson : ' + jQuery.ajaxQueue) }
	}
	,Escape: function(__Value) {
		if (__Value) {
			return __Value.replace(/'/g, "\\'");
		}
		else {
			return "";
		}
	}

}


function EscapeAjaxChars(__Value) {
	if (__Value) {
		return __Value.replace(/'/g, "\\'");
	}
	else {
		return "";
	}
}


