﻿

// add the Nm namespace to the global execution context for non dom browsers
var Nm;
if(Nm && (typeof Nm != "object"))
{
	throw new Error("GlobalNamespace: Nm already exists");
}


(function()
{	
	Nm = 
	{
		CanUseDom: function()
		{
			return _bCanUseDom;
		},
		
		SubmitEvent: function(sTarget, sType, sArgument, oElement)
		{	
			try { $(oElement).addClass("Clicked"); } catch(e){}
			try { event.stopPropagation() } catch(e){};
			var oForm = document.forms[0];
			oForm["__EVENTTARGET"].value = sTarget;
			oForm["__EVENTTYPE"].value = sType;
			oForm["__EVENTARGUMENT"].value = sArgument;
			oForm.submit();
		},
		
		_OnFormComplete: function()
		{
			// test for basic javascript support
			var oForm = document.forms[0];
			oForm["__JS"].value = "1";
			if($.boxModel) { oForm["__JS"].value ="1.1"; }		
		}
	};
	
	/*
	JavaScript (__JS) support is:
	0 - None
	1 - Basic - can use Nm.Functions (_OnFormComplete was able to update a form value via javascript)
	2 - Dom - can use $/jQuery.Functions (the jQuery(ready) function executed)
	
	If javascript is supported at level 1 or 2 and the browser supports the w3c box model then the
	.1 will be appended to the __JS value, i.e 1.1, 2.1
	*/
	
	var _bCanUseDom = false;
	jQuery(function()
	{
		// if this code executes then we can use the dom
		_bCanUseDom = true;
		var oForm = document.forms[0];
		oForm["__JS"].value = ($.boxModel) ? "2.1" : "2";
	});
})();