/**
 * @version $Id basic.js
 * @version $Revision 1.0$ 2005-09-08
 * @version Basic Ajax Functionality Page
 * @author selvaraj_47AG04
 *
 * @copyright Copyright (c) 2005 Agriya Infoway (http://www.agriya.com)
 */

//Common Ajax functions
var replace_word = "check||||||||||valid||||||||login";
var find_word = "heck||||||||||valid||||||||login";

function AG_xml(url, cmd)
	{
		if(url.length<=0 || cmd.length<=0)
			{
				alert("Error: Unable to Found the URL");return false;
			}
		this.url = url;
		this.cmd = cmd;
		this.result = "";
		this.req = null;
		if (window.XMLHttpRequest)
			{
				var req = new XMLHttpRequest();
				if (req.overrideMimeType)
					{
						req.overrideMimeType('text/html');
				 	}
			}
			else if (window.ActiveXObject)
				{
					req = new ActiveXObject("Microsoft.XMLHTTP");
				}
		this.req = req;
		return true;
	}

function AG_post_xml(url,cmd, fieldValues)
	{
		this.output = "NoRecords";
		var x = new AG_xml(url,cmd);
		x.popen();
		try
			{
				x.req.onreadystatechange = function()
					{
						if (x.req.readyState==4)
							{
								if(x.req.status==200)
									{
										if(x.req.responseText)
											{
												x.result = escape(x.req.responseText);
												x.getOp();
											}
									}
							}
					}
			}
		catch(e){}
		x.psend(AG_getURI(fieldValues));
		return true;
	}

function AG_ajax(url,cmd)
	{
		this.output = "NoRecords";
		var x = new AG_xml(url,cmd);
		x.opens();
		try
			{
				x.req.onreadystatechange = function()
					{
						if (x.req.readyState==4)
							{
								if(x.req.status==200)
									{
										if(x.req.responseText)
											{
												x.result = escape(x.req.responseText);
												x.getOp();
											}
									}
							}
					}
			}
		catch(e){}
		x.sends();
	}
function AG_getURI(fieldValueArray){
	var uri = "";
	for(var i in fieldValueArray){
	uri += i+"="+fieldValueArray[i]+"&";
	}
	if(uri.length>1){
	uri = uri.substr(0, uri.length-1);
	}
	return uri;
}

AG_xml.prototype.opens = function()
	{
		this.req.open("GET", this.url, true);
	}

AG_xml.prototype.sends = function()
	{
		this.req.send(null);
	}

AG_xml.prototype.popen = function()
	{
		this.req.open("POST", this.url, true);
	}

AG_xml.prototype.psend = function(p)
	{
		this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		this.req.setRequestHeader("Content-length",p.length);
		this.req.send(unescape(p));
	}

AG_xml.prototype.getOp=function()
	{
		if(arguments.length>1)
			{
				this.cmd = arguments[0];
				alert(this.cmd+"(\""+this.result+"\")");
			}
		eval(this.cmd+"(\""+this.result+"\")");
	}

window.onerror=showError

function showError(msg, url, linenumber)
	{
		//alert('Error(s) Found....!\n Error message= '+msg+'\nURL= '+url+'\nLine Number= '+linenumber);
		return false;
	}