// AJAX Framework Version 1.4 
// Copyright 2005 Jason Graves (GodLikeMouse)
// This file is free to use and distribute under the GNU open source
// license so long as this header remains intact.
// For more information please visit http://www.godlikemouse.com
// To have changes incorporated into the AJAX Framework please contact godlikemouse@godlikemouse.com
// Supported Browsers: IE 6.0+, Opera 8+, Mozilla based browsers
//
// Developer Note: .NET WebService Methods must be tagged with [SoapRpcMethod, WebMethod] for parameters to be passed. 



//AJAX main class
function AJAX(){

	var nameSpace = "http://tempuri.org/";
	
	var getAJAXIdentity = function(){
		return "AJAX" + (AJAX.indentity++);
	}
	
	this.toString = function(){
		return "AJAX Framework Class";
	}
    
   	this.onError = function(error){
	        alert(error);
	};

    this.__doPostBack = function(eventTarget, eventArgument, callbackFunction) {
        var l_theForm = document.forms['aspnetForm'];
        if (!l_theForm) {
            l_theForm = document.aspnetForm;
        }
    
        if (!l_theForm.onsubmit || (l_theForm.onsubmit() != false)) {
            l_theForm.__EVENTTARGET.value = eventTarget;
            l_theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }

	this.submitForm = function(in_form, callbackFunction)
	{
		var i;
		var outstr = "";
		for(i = 0; i < in_form.length; i++)
		{
			switch(in_form[i].type)
			{
				case "text": 
				case "textarea": 
				case "select-one":
				case "submit":
				case "button":
				case "hidden":
					if(escape(in_form[i].name) > "")
					{
						if(outstr != "") outstr += "&";
						outstr += encodeURIComponent(in_form[i].name) + "=" + encodeURIComponent(in_form[i].value).replace(/\+/g, "%2B");;
					}
					break;
				case "radio":
				case "checkbox":
					if(in_form[i].checked)
					{
						if(escape(in_form[i].name) > "")
						{
							if(outstr != "") outstr += "&";
							outstr += encodeURIComponent(in_form[i].name) + "=" +  encodeURIComponent(in_form[i].value).replace(/\+/g, "%2B");;
						}
					}
					break;
					
					
			}
		}
		
		if(in_form.method == "post")
		{
			this.callHTML(in_form.action, "POST", outstr, callbackFunction);
		}
		else
		{
			this.callHTML(in_form.action + "?" + outstr, "GET", null, callbackFunction);
		}
		
		
	}	

	this.getXMLHttpRequest = function(){
		var xmlhttp = false;

		/*@cc_on @*/

		/*@if (@_jscript_version >= 5)

		// JScript gives us Conditional compilation, we can cope with old IE versions.
		// and security blocked creation of the objects.

		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
		}

		/*@end @*/

		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		return xmlhttp;
	}

	this.callHTMLSync = function(url, method, data)
	{
			var xmlhttp = false;

			/*@cc_on @*/

			/*@if (@_jscript_version >= 5)

			// JScript gives us Conditional compilation, we can cope with old IE versions.
			// and security blocked creation of the objects.

			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (E) {
					xmlhttp = false;
				}
			}

			/*@end @*/

			if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
				xmlhttp = new XMLHttpRequest();
			}

			
			xmlhttp.open(method, url, false);
			if(method == "POST") xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			xmlhttp.send(data);
			//if(xmlhttp.status == 200) {
				return xmlhttp.responseText;
			//}
			//else
			//{
			//	return "";
			//}
	}

	this.callHTML = function(url, method, data, callbackFunction){

		var xmlhttp = this.getXMLHttpRequest();
		xmlhttp.open(method, url, true);
		
		if(method == "POST") xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange=function() {
	
				if (xmlhttp.readyState == 4) {
						callbackFunction(xmlhttp.responseText);
				}
		}
		xmlhttp.send(data)

			
	}


	this.callPage = function(url, callbackFunction){
		this.callHTML(url, "GET", null, callbackFunction);
		return;
	};
	
	
	
	this.setNameSpace = function(ns){
		nameSpace = ns;
	}
	
	
	this.getNameSpace = function(){
		return ns;
	}
	
			
}

AJAX.indentity = 0;


