/*
	AJAX.js - Simple AJAX Library
	Author: Nitin Menon
*/

var AJAX = {
	Init: function(){
		ajaxRequest = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			ajaxRequest = new XMLHttpRequest();
			if (ajaxRequest.overrideMimeType) ajaxRequest.overrideMimeType('text/html'); 
		} else if (window.ActiveXObject ) { // IE
			try {
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
		   			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!ajaxRequest) return false;
	},
	$: function(){
		var es = new Array();
		for (var i = 0; i < arguments.length; i++){
			var e = arguments[i];
			if (typeof e == 'string') e = document.getElementById(e);
			if (arguments.length == 1) return e;
			es.push(e);
		}
		return es;	
	},
	LoadURL: function( type, url, parameters ) {
		this.Init()
		ajaxRequest.open( type, url, false );
		if( type.toUpperCase() == 'GET' ){
			ajaxRequest.send( null );	
		}else{
			ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			ajaxRequest.setRequestHeader("Content-length", parameters.length );
			ajaxRequest.setRequestHeader("Connection", "close");
			ajaxRequest.send(parameters);
		}
		return ajaxRequest.responseText; 
	},
	ToXML: function( s ){
		var xmlDoc = null;
		try{
			// Attempt to parse the string using the IE method.
			var xmlDOMObj = new ActiveXObject("Microsoft.XMLDOM");
			xmlDOMObj.async = false;
			xmlDOMObj.loadXML( s );
			xmlDoc = xmlDOMObj;
		}catch (e){
			// The IE method didn't work. Try the Mozilla way.
			try{
				var domParser = new DOMParser;
				xmlDoc = domParser.parseFromString( s, 'text/xml');
			}catch (e){
				xmlDoc = null;
			}
		}
		return xmlDoc;
	},
	XmlNodeValue: function( obj, tag ){
		return obj.getElementsByTagName( tag )[ 0 ].firstChild.nodeValue;
	},
	InsertAfter: function ( p, n ){
		p.parentNode.insertBefore( n, p.nextSibling );
	},
	Remove: function( e ) {
		if( typeof( e ) == 'string' ) e = this.$( e );
		e.parentNode.removeChild( e );
	}
};