
<!-- // Detect Client Browser type

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;

setTimeoutReplace = function (context, func, delay) {
	var argsStart=3;
	var args = [];
	for (var i = argsStart; i < arguments.length; i++) {
		args.push(arguments[i]);
	}
	Interval = setTimeout(function () { func.apply(context, args); }, delay);
	return Interval; 
}

//Create an ajax pipe
var AjaxObject = function ()
{
	function createRequestObject()
	{
			var ro;
			if(isIE){
					ro = new ActiveXObject("Microsoft.XMLHTTP");
			}else{
					ro = new XMLHttpRequest();
			}
			return ro;
	}


/*Initialise basic variables: 
	Ajax pipe,
	Ajax variables array,
	AjaxScript the script called for responses
	current focused field,
	uri links base 
*/
	var http = createRequestObject();
	var AjaxVars = new Object ();
	var AjaxScript = '';
	var FocusObj = '';
	var LinksBase = '';
	var ResponseFunction = "AjaxHandleResponse";
	var AjaxDestInform = 'ajaxinform';
	var AjaxDestContent = 'ajaxcontent';
	var AjaxTimeOutDuration = 500;
	var timeoutCodeIntervalId = '';
	
//Set this flag to true if the fields are
//returned inside the ajax response;
//they will be reset to the correct values and the caret 
//placed at the end of the input
	var AjaxResetFieldsFlag = false;

// Deal with Ajax response
	function AjaxHandleResponse() {
		dynamiccontent(AjaxDestInform, "handling response");
		if(http.readyState == 4)
		{
			//Check if response was normal
			if (http.status == 200) {
				var response = http.responseText;
				dynamiccontent(AjaxDestContent, response);
				dynamiccontent(AjaxDestInform, "");
				if (AjaxResetFieldsFlag)
				{
					this.ResetFieldsFromArray();
				}
			}
			else
			{
				//Problem dealing with call
				dynamiccontent(AjaxDestInform, "Cannot verify at this moment...");
			}
		}
		else
		{
			//Still waiting for response
			dynamiccontent(AjaxDestInform, "Checking... If no results return in 5 seconds, please tap the CTRL key.");
		}
	}



//Send Ajax call
	this.sndReq = function () {
//		this.SetAjaxDest(DestInform, DestContent);
		if (eval(document.getElementById(FocusObj)))
		{
			this.SetAjaxVar(FocusObj.id, FocusObj.value);
		}
		if (document.getElementById(AjaxDestInform).innerHTML == "") {
			QueryString = GetQueryString();
			http.open('get', AjaxScript+QueryString);
			//http.onreadystatechange = "AjaxHandleResponse('"+DestInform+"', '"+DestContent+"');";
			http.onreadystatechange = AjaxHandleResponse;
			http.send(null);
			AjaxHandleResponse();
		} else {
			dynamiccontent(AjaxDestInform, "Returning content");
		}
	}

//set the value of an element on the page
//	used to display the ajax response
//	and to fill in input fields with last known value 
	function dynamiccontent(elementid,content)
	{
		if (document.all)
		{
			el = document.getElementById(elementid);
			el.innerHTML=content;
		}
		else
		{
			rng = document.createRange();
			el = document.getElementById(elementid);
			rng.setStartBefore(el);
			htmlFrag = rng.createContextualFragment(content);
			while (el.hasChildNodes())
			el.removeChild(el.lastChild);
			el.appendChild(htmlFrag);
		}
	}
	
	this.TimeOutCallback = function()
	{
		this.sndReq();
	}

//AjaxObject.prototype.bind = function( object )
//{
//	var method = this;
//	return function()
//	{
//		method.apply( object );
//	}
//}

	

	this.ReqTimeOut = function() 
	{
			window.clearTimeout(timeoutCodeIntervalId);
			timeoutCodeIntervalId = setTimeoutReplace(this, this.TimeOutCallback, AjaxTimeOutDuration);
	}


/*General Variable Functions*/
	this.ChangeLinksBase = function(Path)
	{
		LinksBase = Path;
	}
	
	this.SetResetFlag = function(Bool)
	{
		AjaxResetFieldsFlag = Bool;
	}
	
	this.SetFocusObj=function(NewFocusObject)
	{
		FocusObj=NewFocusObj;
	}
	
	this.ChangeAjaxBase = function(NewBase)
	{
		AjaxScript = NewBase;
	}
	
	this.SetAjaxDest = function (DestInform, DestContent)
	{
		if (null == DestInform || '' == DestInform)
		{
			AjaxDestInform = 'ajaxinform'; 
		} else {
			AjaxDestInform = DestInform; 
		}
		if (null == DestContent || '' == DestContent)
		{
			AjaxDestContent = 'ajaxcontent'; 
		} else {
			AjaxDestContent = DestContent; 
		}
	}

	this.SetAjaxVar = function(varname, varval)
	{
		AjaxVars[varname] = varval;
	}

	this.SetAjaxVars = function(VarArray)
	{
		for (Var in VarArray)
		{
			this.SetAjaxVar(Var, VarArray[Var]);
		}
	}

	this.GetAjaxVar = function(varname)
	{
		return AjaxVars[varname];
	}
	
/*set up GET from all the values in the value array*/
	function GetQueryString()
	{
		QueryString = '?Ajax=1';
		for ( variable in AjaxVars )
		{
			if (AjaxVars[variable] != '') 
			{
				QueryString = QueryString+"&"+variable+"="+AjaxVars[variable];
			}
		}
		return QueryString;
	}


/*set a variable value and call script 
	e.g. user changes the option in a select box
*/
	this.SetVarAndGo = function(aVar, aVal)
	{
		this.SetAjaxVar(aVar, aVal);
		this.sndReq();
	}

/*Insert value of a field (eg. input box) in the 
	variable array and call script
*/
	this.SetFieldAndGo = function(Field)
	{
		FocusField(Field);
		this.SetAjaxVar(Field.id, Field.value);
		this.ReqTimeOut();
	}

/*focus a field:
	used to reset the focus of current field (e.g. input box)
	after call */
	function FocusField(Field) 
	{
		FocusObj = Field;
	}

/*check the items in the Ajax array:
	if a text field set value to this value
*/
	this.ResetFieldsFromArray = function()
	{
		for (variable in AjaxVars)
		{
//the next two lines need to be checked again for IE
			var element = document.getElementById(variable); 
			if (element)
			{
				if ("text" == element.type)
				{
					element.value = AjaxVars[variable];
				}
			}
		}
		if (FocusObj) {
			Id = FocusObj.id;
			FocusObj = document.getElementById(Id);
			SetCaretToEnd(FocusObj);
		}
	}

	function SetCaretToEnd (Field) {
		Field.focus();
		if (Field.createTextRange) {
			var range = Field.createTextRange();
			range.collapse(false);
			range.select();
		}
		else if (Field.setSelectionRange) {
			var length = Field.value.length;
			Field.setSelectionRange(length, length);
		}
	}

	function ResetField(Field) 
	{
		Field.value = AjaxVars[Field.id];
	}


/*Pagination Variable Functions*/
//Change sort direction or sort col
	this.ClickHeader = function(ClickedCol)
	{
		SortDir = AjaxVars['aSortDir'];
		CurrentCol = AjaxVars['aSortCol'];
		if (CurrentCol == ClickedCol)
			{
			if (SortDir == 'DESC') {
				AjaxVars['aSortDir'] = 'ASC';
			}
			else
			{
				AjaxVars['aSortDir'] = 'DESC';
			}
		}
		else
		{
			AjaxVars['aSortDir'] = 'DESC';
			AjaxVars['aSortCol'] = ClickedCol;
		}
		AjaxVars['aPageNum'] = '1';
		this.sndReq();
	}

	this.ResetPagination = function()
	{
		AjaxVars['aPageNum'] = '1';
	}


//go to page number in paginated list
	this.GotoPage = function(PageNum)
	{
		// goto page in the pagination
		AjaxVars['aPageNum'] = PageNum;
		this.sndReq();
	}

	this.GotoUri = function(Link)
	{
		document.location = Link;
	}

//goto another page using the LinkBase variable set by the script
	this.GotoLinkedPage = function(linked)
	{
		//goto a page the is connected with the ajax page (linksbase can be set by the ajax page)
		this.GotoUri(LinksBase+linked);
	}

//reset pagination and call script (changed col heading for example)
	this.SetVarRepageAndGo = function(aVar, aVal) 
	{
		AjaxVars['aPageNum'] = 1;
		this.SetVarAndGo(aVar, aVal);
	}

	this.AjaxSerialise = function(formid)
	{
		var form = document.getElementById(formid);
		var inputs = form.getElementsByTagName('input');
		var out = new Array();
		
		var serialiseSingle = function(element)
		{
			if (element.name && element.value)
			{
				return encodeURIComponent(element.name)+'='+encodeURIComponent(element.value);
			}	else {
				return '';
			}
		}
		
		var serialiseGroup = function (tag)
		{
			group = form.getElementsByTagName(tag);
			
			for (var i=0; i < group.length; i++) {
				tag = group[i];
				single = serialiseSingle(tag);
				if (single) 
				{
					out.push(single);
				}
			}
		}
		
		//input tags	
		for (var i=0; i < inputs.length; i++) {
			inputTag = inputs[i];
			if ( 'checkbox' == inputTag.type || 'radio' == inputTag.type )
			{			
				if (!inputTag.checked) {
					continue;
				}
			}
			single = serialiseSingle(inputTag);
			if (single) 
			{
				out.push(single);
			}
		}
		
		//othertags
		serialiseGroup('select');
		serialiseGroup('button');
		serialiseGroup('textarea');
	
		return out.join('&');	
	}


	this.PostForm = function (formid)
	{
		//this PostForm handles array fields in forms without problem
		//however it does not provide a means to change:
		var encodedForm = this.AjaxSerialise(formid);
		if (document.getElementById(AjaxDestInform).innerHTML == "") 
		{
			http.open('post', AjaxScript);
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.onreadystatechange = AjaxHandleResponse;
			http.send(encodedForm);
			AjaxHandleResponse();
		} else {
			dynamiccontent(AjaxDestInform, "Returning content");
		}
	}
	
	this.AjaxDebug = function()
	{
		if ("block" == document.getElementById('AjaxDebug').style.display)
		{
			document.getElementById('AjaxDebug').style.display="none";
		}
		else
		{
			Result = '';
			for (variable in AjaxVars)
			{
				if (AjaxVars[variable] != '') 
				{
					Result = Result+"<br/>\n"+variable+"="+AjaxVars[variable];
				}
			}
			dynamiccontent('AjaxDebug', Result);
			document.getElementById('AjaxDebug').style.display="block";
		}
	}
}

// -->