function ajaxRequest(){
	var req=false;
	if(window.XMLHttpRequest){
		req=new XMLHttpRequest();
	} else if(window.ActiveXObject){
		try{
			req=new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e1){
			try{
				req=new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e2){
				alert("Not able to instantiate ajaxRequest");
			}
		}
	}
	return(req);
}

function ajaxHandler(req,func){
	if(req.overrideMimeType){
		req.overrideMimeType('text/xml');
	}
	return(function(){
		if(req.readyState==4){
			if(req.status==200){
				// fix for IE when mime-type not xml -> in this case cos its a tpl call
				if(window.ActiveXObject){
					var doc=new ActiveXObject("Microsoft.XMLDOM");
					doc.validateOnParse=false;
					doc.async=true;
					var cleaned=req.responseText;
					var cleaned_length = cleaned.length;
					for(var z=0;z<cleaned_length;z++){
						if(cleaned.charCodeAt(z) > 255){
							cleaned = cleaned.substring(0,z) + cleaned.substr(z+1);
						}
					}
					if(doc.loadXML(cleaned)){
						func(doc.documentElement);       
					}else{
						var doc_error=doc.parseError;
						alert("ERROR\nReason : "+doc_error.reason+"\nLine : " + doc_error.line + " at position " + doc_error.linepos);
					}
				}else{ 
					func(req.responseXML.documentElement);
				}
			}else{
				alert("HTTP error: "+req.status);
			}
		}
	});
}	

function addEvent(obj,type,fn){
	if(obj.addEventListener){
		obj.addEventListener(type,fn,false);
	}else if(obj.attachEvent){
		obj["e"+type+fn] = fn;
		obj[type+fn] = function(){
			obj["e"+type+fn](window.event);
		}
		obj.attachEvent("on"+type,obj[type+fn]);
	}
}

function callBack( fn, url ){
	var req = ajaxRequest();
	var handler = ajaxHandler( req, fn );
	req.onreadystatechange = handler;
	req.open( 'get', url, true );
	req.send( null );
}
	
function o(id){
	return document.getElementById(id);
}

function co( tag, id, cls, txt  ){
	var el = document.createElement( tag );
	if( id ){
		el.setAttribute( 'id', id );
	}
	if( cls ){
		el.className = cls;
	}
	if( txt ){
		el.appendChild( document.createTextNode( txt ) );
	}
	return el;
}

function getElementsByClassName(cls){
	var links = document.getElementsByTagName('a');
	var els = [];
	for(var i=0;i<links.length;i++){
		if(links[i].className && links[i].className.toString().indexOf(cls)>=0){
			els.push(links[i]);
		}
	}
	return els;
}

function removeItem( trg ){
	if( trg.removeNode ){
		trg.removeNode( true );
	}else{
		trg.parentNode.removeChild( trg );
	}
}

function prependNode( obj, previous ){
	obj.parentNode.insertBefore( obj, previous );
}
