	var loadedobjects=""
	var rootdomain="http://"+window.location.hostname
	// holds an instance of XMLHttpRequest
	var xmlHttp = create_XML_http_request_object();
	//Initialize the validation requests cache
 	var cache = new Array();
 	var validateURL = 'loaddata.php?page=validate'
 	
	/**
	*
	* Creates an XMLHttpRequest instance
	*
	*/
	function create_XML_http_request_object() 
	{
		// will store the reference to the XMLHttpRequest object
	  	var xmlHttp;
	  	// this should work for all browsers except IE6 and older
	  	try
	  	{
	    	// try to create XMLHttpRequest object
			xmlHttp = new XMLHttpRequest();
	  	}
	  	catch(e)
	  	{
	    	// assume IE6 or older
	    	var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
	        	                            "MSXML2.XMLHTTP.5.0",
	            	                        "MSXML2.XMLHTTP.4.0",
	                	                    "MSXML2.XMLHTTP.3.0",
	                    	                "MSXML2.XMLHTTP",
	                        	            "Microsoft.XMLHTTP");
	    	// try every id until one works
	    	for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
	    	{
	      		try 
	      		{ 
	        		// try to create XMLHttpRequest object
	        		xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
	      		} 
	      		catch (e) {} // ignore potential error
	    	}
	  	}
	  	// return the created object or display an error message
	  	if (!xmlHttp)
	    	return false;
	  	else 
	   		return xmlHttp;
	}//create_XML_http_request_object	
	
	
	/**
	*
	* Function that handles the HTTP response
	*
	*/
	function handle_request_state_change() 
	{
		// when readyState is 4, we read the server response
		if (xmlHttp.readyState == 4) 
		{
			// continue only if HTTP status is "OK"
			if (xmlHttp.status == 200) 
			{
				try
				{
					// read the response from the server
					read_validate_response();
				}
				catch(e)
				{
					// display error message
					//displayError(e.toString());
				}
			}
			else
			{
				// display error message
				//displayError(xmlHttp.statusText);
			}
		}//if
	}//handle_request_state_change
	

	/**
	*
	* Read server's response 
	*
	*/
	function read_validate_response()
	{
  		// retrieve the server's response 
  		var response = xmlHttp.responseText;
  		// server error?
  		if (response.indexOf("ERRNO") >= 0 
      	|| response.indexOf("error:") >= 0
      	|| response.length == 0)
    	throw(response.length == 0 ? "Server error." : response);
    	//alert(response);
		//alert(1);
		// get response in XML format (assume the response is valid XML)
		responseXml = xmlHttp.responseXML;
		// get the document element
		xmlDoc = responseXml.documentElement;
		strError = xmlDoc.getElementsByTagName("error")[0].firstChild.data;
		if(strError!=0)
		{
  			strErrorHTML = '<img src="_sysimg/form/warning.gif" alt="' + strError +'" title="' + strError +'">';
		}//if-strError
		else strErrorHTML = '';
			
		strField = xmlDoc.getElementsByTagName("field")[0].firstChild.data;
		var intStringLength = strField.length;
		
		//Remove possible [X] from strField if given to prevent javascript error
		if(strField.charAt(intStringLength-3)=="[")
		{
			strField = strField.substring(0, intStringLength-3);
		}//if
		
		try
		{
			objError = document.getElementById('error_'+strField);
			objError.innerHTML = strErrorHTML;
		}//try
		catch(e) {}
	
		var strInfo = xmlDoc.getElementsByTagName("info")[0].firstChild.data;
		
		//Return info if given
		if(strInfo!=0)
		{
			try
			{
				objInfo = document.getElementById('info_'+strField);
				objInfo.innerHTML = strInfo;
			}//try
			catch(e){}
		}//if
		else if(strInfo==0)
		{
			try
			{
				objInfo = document.getElementById('info_'+strField);
				objInfo.innerHTML = '';
			}//try
			catch(e){}
		}//if

		// call validate() again, in case there are values left in the cache
		setTimeout("validate();", 500);
	}//read_validate_response
	
	
	// the function handles the validation for any form field
	function validate(strValue, strId, strValidateType, strCompareValue)
	{
		// only continue if xmlHttp isn't void{
		if (xmlHttp)
		{
			// if we received non-null parameters, we add them to cache in the
			// form of the query string to be sent to the server for validation
			if (strId)
			{
				// encode values for safely adding them to an HTTP request query string
				strValue = encodeURIComponent(strValue);
				if(strCompareValue) strCompareValue = encodeURIComponent(strCompareValue);
				strId = encodeURIComponent(strId);
				strValidateType = encodeURIComponent(strValidateType);
				// add the values to the queue
				cache.push("form_value=" + strValue + "&form_compare_value=" + strCompareValue + "&form_id=" + strId + "&validate_type=" + strValidateType);
			}
			// try to connect to the server
			try
			{
				// continue only if the XMLHttpRequest object isn't busy
				// and the cache is not empty
				if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) && cache.length > 0)
				{	
					// get a new set of parameters from the cache
					var cacheEntry = cache.shift();
					// make a server request to validate the extracted data
					xmlHttp.open("POST", validateURL, true);
					
					xmlHttp.setRequestHeader("Content-Type", 
										 "application/x-www-form-urlencoded");
					xmlHttp.onreadystatechange = handle_request_state_change;
					xmlHttp.send(cacheEntry);
				}//if
			}//try
			catch (e)
			{
			  // display an error when failing to connect to the server
			  //alert(e.toString());
			}
		}//if-xmlHttp
	}//validate
	
	/**
	* Set timeout for use in mozilla and under parent window
	*
	*/
	function _load_ajax_page(url, containerid, custom_function)
	{
		
		setTimeout(function(){
			ajax_page(url, containerid, custom_function)
		}, 0);
	}
	
	/**
	*
	* Creates the XMLHttpRequest object
	*
	* @uses ajax_load_page()
	* @uses create_XML_http_request_object
	*
	*/
	function ajax_page(url, containerid, custom_function)
	{
		try
		{			
			var page_request = false
			page_request = create_XML_http_request_object();
						
			//When ready, load data into container
			page_request.onreadystatechange=function()
			{

				ajax_load_page(page_request, containerid, custom_function)
			}//
			page_request.open('GET', url, true)
			page_request.send(null)
		}
		catch(e)
		{
			//alert(e.description);
		}	
	}// ajax_page
	 
	/**
	*
	* Insert GET response into container
	*
	* @param url The request url
	* @param containerid Id of the anchor element
	* @param strPosition Insert position relative to anchor: {top | bottom | above | below }
	* @param custom_function Function executed after insertion is complete
	* 
	* @uses ajax_insert_page()
	* @uses create_XML_http_request_object
	*
	*/
	function ajax_insert(url, containerid, strPosition, custom_function)
	{
		try
		{			
			var page_request = false
			page_request = create_XML_http_request_object();
						
			//When ready, load data into container
			page_request.onreadystatechange=function()
			{
				ajax_insert_page(page_request, containerid, strPosition, custom_function);
			}//
			page_request.open('GET', url, true)
			page_request.send(null)
		}
		catch(e)
		{
			//alert(e.description);
		}	
	}// ajax_insert

	/**
	*
	* Replace html in container with GET response
	*
	* @param url The request url
	* @param containerid Id of the anchor element
	* @param custom_function Function executed after replacement is complete
	* 
	* @uses ajax_replace_page()
	* @uses create_XML_http_request_object
	*
	*/
	function ajax_replace(url, containerid, custom_function)
	{
		try
		{			
			var page_request = false
			page_request = create_XML_http_request_object();
						
			//When ready, load data into container
			page_request.onreadystatechange=function()
			{
				ajax_replace_page(page_request, containerid, custom_function);
			}//
			page_request.open('GET', url, true)
			page_request.send(null)
		}
		catch(e)
		{
			//alert(e.description);
		}	
	}// ajax_replace
	
	/**
	*
	* Delete html in container after GET response
	*
	* @param url The request url
	* @param containerid Id of the element to delete
	* @param custom_function Function executed after deletion is complete
	* 
	* @uses ajax_delete_page()
	* @uses create_XML_http_request_object
	*
	*/
	function ajax_delete(url, containerid, custom_function)
	{
		try
		{			
			var page_request = false
			page_request = create_XML_http_request_object();
						
			//When ready, load data into container
			page_request.onreadystatechange=function()
			{
				ajax_delete_page(page_request, containerid, custom_function);
			}//
			page_request.open('GET', url, true)
			page_request.send(null)
		}
		catch(e)
		{
			//alert(e.description);
		}	
	}// ajax_replace

	/**
	*
	* Loads data into container
	*
	*/
	function ajax_load_page(page_request, containerid, custom_function)
	{
	
		try
		{
		
			if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
			{
				
				if(containerid.id)
				{
					obj = $(containerid);
				}//if
				else
				{
					obj = $(containerid);
				}//else
				
				obj.innerHTML = page_request.responseText;
				
				if(custom_function)
				{
					try
					{
						eval(custom_function);
					}
					catch(e){}
				}//custom function
				
				//fix png if ie5.5 or ie6
				try
				{
					if (glb_browser ==  'ie' && glb_browser_ver >= 5.5 && glb_browser_ver < 7) 
					{
						pgn_fix_run();
					}//if
				}//try
				catch(e){}//catch
	
				
				
			}//if
		}// try
		catch(e)
		{
			//alert('There was an error: ' . e.description);
		}// catch
	}//loadpage

	/**
	*
	* Replace container
	*
	*/
	function ajax_replace_page(page_request, containerid, custom_function)
	{
	
		try
		{
		
			if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
			{
				
				if(containerid.id)
				{
					obj = $(containerid);
				}//if
				else
				{
					obj = $(containerid);
				}//else
				
				// replace element using prototype
				obj = $(obj).replace(page_request.responseText);
				
				if(custom_function)
				{
					try
					{
						eval(custom_function);
					}
					catch(e){}
				}//custom function
				
				//fix png if ie5.5 or ie6
				try
				{
					if (glb_browser ==  'ie' && glb_browser_ver >= 5.5 && glb_browser_ver < 7) 
					{
						pgn_fix_run();
					}//if
				}//try
				catch(e){}//catch
				
				
				
			}//if
		}// try
		catch(e)
		{
			//alert('There was an error: ' . e.description);
		}// catch
	}// ajax_replace_page	
	
	/**
	*
	* Insert GET response into container
	* 
	* @param page_request The request
	* @param containerid Id of the anchor element
	* @param strPosition Insert position relative to anchor: {top | bottom | above | below }
	* @param custom_function Function executed after insertion is complete
	*/
	function ajax_insert_page(page_request, containerid, strPosition, custom_function)
	{
	
		try
		{
		
			if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
			{
				
				if(containerid.id)
				{
					obj = $(containerid);
				}//if
				else
				{
					obj = $(containerid);
				}//else
				
				// insert element using prototype
				switch(strPosition)
				{
				case 'top':
					$(obj).insert({'top': page_request.responseText});
					break;
				case 'bottom':
					$(obj).insert({'bottom': page_request.responseText});
					break;
				case 'above':
					$(obj).insert({'before': page_request.responseText});
					break;
				case 'below':
					$(obj).insert({'after': page_request.responseText});
					break;
				}
				
				if(custom_function)
				{
					try
					{
						eval(custom_function);
					}
					catch(e)
					{
						alert(e);	
					}
				}//custom function
				
				//fix png if ie5.5 or ie6
				try
				{
					if (glb_browser ==  'ie' && glb_browser_ver >= 5.5 && glb_browser_ver < 7) 
					{
						pgn_fix_run();
					}//if
				}//try
				catch(e){}//catch				
				
				
			}//if
		}// try
		catch(e)
		{
			//alert('There was an error: ' . e.description);
		}// catch
	}// ajax_insert_page	

	/**
	*
	* Delete container on GET response
	* 
	* @param page_request The request
	* @param containerid Id of the anchor element
	* @param custom_function Function executed after deletion is complete
	*/
	function ajax_delete_page(page_request, containerid, strPosition, custom_function)
	{
	
		try
		{
		
			if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
			{
				
				if(containerid.id)
				{
					obj = $(containerid);
				}//if
				else
				{
					obj = $(containerid);
				}//else
				
				// remove element using prototype
				$(obj).remove();
								
				if(custom_function)
				{
					try
					{
						eval(custom_function);
					}
					catch(e)
					{
						alert(e);	
					}
				}//custom function
				
				//fix png if ie5.5 or ie6
				try
				{
					if (glb_browser ==  'ie' && glb_browser_ver >= 5.5 && glb_browser_ver < 7) 
					{
						pgn_fix_run();
					}//if
				}//try
				catch(e){}//catch				
				
				
			}//if
		}// try
		catch(e)
		{
			//alert('There was an error: ' . e.description);
		}// catch
	}// ajax_delete_page	

	/**
	*
	* Loads style and script files. 
	* If allready loaded, it will skip the file
	*
	*/
	function ajax_load_objs()
	{
		if (!document.getElementById) return

		for (i=0; i<arguments.length; i++)
		{
			var file=arguments[i]
			var fileref=""
			if (loadedobjects.indexOf(file)==-1)
			{ //Check to see if this object has not already been added to page before proceeding
				if (file.indexOf(".js")!=-1)
				{ //If object is a js file
					fileref=document.createElement('script')
					fileref.setAttribute("type","text/javascript");
					fileref.setAttribute("src", file);
				}//if
				else if (file.indexOf(".css")!=-1)
				{ //If object is a css file
					fileref=document.createElement("link")
					fileref.setAttribute("rel", "stylesheet");
					fileref.setAttribute("type", "text/css");
					fileref.setAttribute("href", file);
				}//else if
			}//if
			if (fileref!="")
			{
				document.getElementsByTagName("head").item(0).appendChild(fileref)
				loadedobjects+=file+" " //Remember this object as being already added to page
			}//if
		}//for

	}//loadobjs
	
	
	function ajax_post(objForm, containerid, custom_function)
	{
	
		try
		{
			strParams = ajax_post_prepare(objForm.elements);
			
			// indicate that this is a ajax posting...
			strParams += '&cimajaxpost=1';
			
			page_request = create_XML_http_request_object();
			//When ready, load data into container
			page_request.onreadystatechange=function()
			{
				ajax_load_page(page_request, containerid, custom_function)
			}//
			
			page_request.open('POST', objForm.action, true);
			page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			page_request.setRequestHeader("Content-length", strParams.length);
			page_request.setRequestHeader("Connection", "close");
			page_request.send(strParams);
			
			
		}
		catch(e)
		{
			
		}
		
	}//
	
	/**
	*
	* Replace container with page post response
	* 
	* @param objForm The form element
	* @param containerid Id of the anchor element
	* @param custom_function Function executed after insertion is complete
	*/
	function ajax_post_replace(objForm, containerid, custom_function)
	{
	
		try
		{
			strParams = ajax_post_prepare(objForm.elements);
			
			// indicate that this is a ajax posting...
			strParams += '&cimajaxpost=1';
			
			page_request = create_XML_http_request_object();
			//When ready, load data into container
			page_request.onreadystatechange=function()
			{
				ajax_replace_page(page_request, containerid, custom_function)
			}//
			
			page_request.open('POST', objForm.action, true);
			page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			page_request.setRequestHeader("Content-length", strParams.length);
			page_request.setRequestHeader("Connection", "close");
			page_request.send(strParams);
			
			
		}
		catch(e)
		{
			
		}
		
	}//
	
	/**
	*
	* Insert POST response into container
	* 
	* @param objForm The form element
	* @param containerid Id of the anchor element
	* @param strPosition Insert position relative to anchor: {top | bottom | above | below }
	* @param custom_function Function executed after insertion is complete
	*/
	function ajax_post_insert(objForm, containerid, strPosition, custom_function)
	{
	
		try
		{
			strParams = ajax_post_prepare(objForm.elements);
			
			// indicate that this is a ajax posting...
			strParams += '&cimajaxpost=1';
			
			page_request = create_XML_http_request_object();
			//When ready, load data into container
			page_request.onreadystatechange=function()
			{
				ajax_insert_page(page_request, containerid, strPosition, custom_function)
			}//
			
			page_request.open('POST', objForm.action, true);
			page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			page_request.setRequestHeader("Content-length", strParams.length);
			page_request.setRequestHeader("Connection", "close");
			page_request.send(strParams);
			
			
		}
		catch(e)
		{
			
		}
		
	}//
	
	/**
	* Create the post string
	*/
	function ajax_post_prepare(elements)
	{
		intElements = elements.length;
		strQuery = '';
		for(i = 0; i < intElements; i++)
		{
			if(elements[i].name)
			{
				
				if(elements[i].type == 'checkbox')
				{
					if(strQuery) strQuery = strQuery +'&';
					strQuery = strQuery + elements[i].name + '=';
					if(elements[i].checked)
					{
						strQuery = strQuery	+ encodeURI(elements[i].value);
					}
				}//if
				else if(elements[i].type == 'radio')
				{
					
					if(elements[i].checked)
					{
						if(strQuery) strQuery = strQuery +'&';
						strQuery = strQuery + elements[i].name + '=';
						strQuery = strQuery	+ encodeURI(elements[i].value);
					}
				}
				else
				{
					if(strQuery) strQuery = strQuery +'&';
					strQuery = strQuery + elements[i].name + '=';
					strValue = encodeURI(elements[i].value);
					while(strValue.indexOf('&') > -1) strValue = strValue.replace('&', '*amp*');
					while(strValue.indexOf('+') > -1) strValue = strValue.replace('+', '%2B');
					
					strQuery = strQuery	+ strValue;
				}//else
			}//if
		}//for
		
		return strQuery;
	}//
	

	
	
	
