﻿// JScript File
Type.registerNamespace("EteachUI");

// Constructor
EteachUI.ScriptDetector = function(element) {
	EteachUI.ScriptDetector.initializeBase(this, [element]);

	this._callID = 0;
	this._currentCallID = -1;
}

EteachUI.ScriptDetector.prototype = {

	initialize: function() {
		EteachUI.ScriptDetector.callBaseMethod(this, 'initialize');

		this.detect();
	},

	dispose: function() {
		EteachUI.ScriptDetector.callBaseMethod(this, 'dispose');
	},
	
	detect: function() {
		this._currentCallID = ++this._callID;
		Sys.Net.WebServiceProxy.invoke("/AJAX/ScriptDetector.asmx", "Detected", false,null,
			Function.createDelegate(this, this._onMethodComplete), Function.createDelegate(this, this._onMethodError),
			this._currentCallID);
	},

	//
	// Event delegates
	//

	_onMethodComplete : function (result, userContext, methodName) {
		// ignore if it's not the current call.
		if (userContext != this._currentCallID) return;
		this._currentCallID = -1;
	},

	_onMethodError : function(webServiceError, userContext, methodName) {
		// ignore if it's not the current call.
		if (userContext != this._currentCallID) return;
		this._currentCallID = -1;
	}

	//
	// Control properties
	//
}

EteachUI.ScriptDetector.registerClass('EteachUI.ScriptDetector', Sys.UI.Control);

// Since this script is not loaded by System.Web.Handlers.ScriptResourceHandler
// invoke Sys.Application.notifyScriptLoaded to notify ScriptManager 
// that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();