var quickAjaxJSModuleIncluded=true;

function getXMLHttpRequest() {
	var xmlHttpReq = null;
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlHttpReq;
}

function AjaxRequest(method, url, data, async, stateChangeHandler) {
	var xmlHttpReq = getXMLHttpRequest();
	if (xmlHttpReq == null)
		return false;
	
	xmlHttpReq.onreadystatechange = function() { stateChangeHandler(xmlHttpReq); };
	xmlHttpReq.open(method, url, async);
	if(method=="POST"){
		xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpReq.setRequestHeader('Connection', 'close');
		xmlHttpReq.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
	}
	xmlHttpReq.send(data);
	return true;
}

function getNodeValue(parent, tagName) {
	var e = parent.getElementsByTagName(tagName);
	return (e != null && e[0] != null && e[0].hasChildNodes()) ? e[0].firstChild.nodeValue : "";
}

function submitForm(form, url, responseHandler) {
	var qs = "";
	//form.submit_button.disabled = true;
	for (var i=0; i<form.elements.length; i++) {
		qs += form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value) + "&";
	}
	var tmpReturn=AjaxRequest("POST", url, qs, true, responseHandler);
	//form.submit_button.disabled = false;
}

function getAjaxAction(url,responseHandler){
	var tmpReturn=AjaxRequest("GET", url, 'testGet=0&', true, responseHandler);
}


function getAttributesFromXML(cNodeName,cKey,cTimes){
	if(arguments.length<3)
		var cTimes=0;
	return this.getAttributeValue(this.singleTag(this.getTagNames(cNodeName),cTimes),cKey);

}

function getValuesFromXML(cNodeName,cTimes){
	if(!cNodeName)
		return "";
	if(arguments.length<2)
		var cTimes=0;
	this.tmpSingleTag=this.singleTag(this.getTagNames(cNodeName),cTimes);
	return this.getNodeValue(this.tmpSingleTag);
}

function getSingleTag(cTagColl,cTimes){
	if(cTagColl.length==0)
		return "";
	if(cTagColl[cTimes]==undefined)
		return "";
	return cTagColl[cTimes];

}

function getElementsByTag(cNodeName){
	return this.xmlCollection.getElementsByTagName(cNodeName);
}

function getValueFromNode(cSingleNode){
	if(!cSingleNode)
		return "";
	if(cSingleNode==undefined)
		return "";
	if(cSingleNode.childNodes[0]==undefined)
		return "";
	return cSingleNode.childNodes[0].nodeValue;

}

function getAttributesFromNode(cNodeCollection,cKey){
	if(cNodeCollection.length<1)
		return "";
	for(var ii=0; ii<cNodeCollection.attributes.length; ii++){
		if(cNodeCollection.attributes[ii].nodeName==cKey){
			return cNodeCollection.attributes[ii].nodeValue;
		}
	}
	return "";
}

function getXMLArray(xmlColl) {
	this.xmlCollection=xmlColl;

	this.getTagNames=getElementsByTag;
	this.getNodeValue=getValueFromNode;
	this.getAttributeValue=getAttributesFromNode;
	this.attribute=getAttributesFromXML;
	this.value=getValuesFromXML;
	this.singleTag=getSingleTag;

}

function XML_getNodeValue(cTag,cColl){
	var tmpElem=cColl.getElementsByTagName(cTag);
	if(tmpElem.length>0) return (tmpElem[0]!=null && tmpElem[0].hasChildNodes() ? tmpElem[0].firstChild.nodeValue : "");
	else return "";
}
function XML_getAttribute(cTag,cAttr,cColl){
	var tmpElem=cColl.getElementsByTagName(cTag);
	if(tmpElem.length>0){
		if(tmpElem[0]!=null && tmpElem[0].hasChildNodes()){
			for(var ii=0; ii<tmpElem[0].attributes.length; ii++){
				if(tmpElem[0].attributes[ii].nodeName==cAttr){
					return tmpElem[0].attributes[ii].nodeValue;
				}
			}
		}else return "";
	}else return "";
	return "";
}

function event_getXMLHttpRequest() {
	var xmlHttpReq = null;
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlHttpReq;
}

function event_AjaxRequest(cClass,cReturnObject,cReturnFunction,method, url, data, async, stateChangeHandler) {
	var xmlHttpReq = this.getXMLHttpRequest();
	if (xmlHttpReq == null)
		return false;
	
	xmlHttpReq.onreadystatechange = function() { stateChangeHandler(xmlHttpReq,cClass,cReturnObject,cReturnFunction); };
	xmlHttpReq.open(method, url, async);
	if(method=="POST"){
		xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpReq.setRequestHeader('Connection', 'close');
		xmlHttpReq.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
	}
	xmlHttpReq.send(data);
	return true;
}

function event_submitForm(cClass, form,cReturnObject,cReturnFunction, url, responseHandler) {
	var qs = "";
	for (var i=0; i<form.elements.length; i++) {
		qs += form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value) + "&";
	}
	var tmpReturn=this.AjaxRequest(cClass,cReturnObject,cReturnFunction,"POST", url, qs, true, responseHandler);
}


function event_runAjax(cSource,cReturnObject,cParams,cReturnFunction){
	this.submitForm(this.classKey,this.form,cReturnObject,cReturnFunction, this.url+'&section='+cSource+'&class='+this.classKey+'&returnType='+this.returnType+cParams, this.xmlHttpReq);
}

function event_xmlHttpReq(xmlHttpReq,cClass,cReturnObject,cReturnFunction){
	if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200){
		var thisObject=eval(cClass);
		if(thisObject.returnType=='html' && xmlHttpReq.responseText.length>1){
			if(cReturnObject) cReturnObject.innerHTML=xmlHttpReq.responseText;
		}else if(thisObject.returnType=='xml'){
		}
		if(cReturnFunction) eval(cReturnFunction + '(xmlHttpReq);');

		
	}
}

function AjaxClassCollection(cUrl,cForm,cClassKey,cReturnType){
	this.url=cUrl;
	this.form=eval(cForm);
	this.classKey=cClassKey;
	this.source='';
	this.params='';
	this.returnObject='';
	this.returnFunction='';
	this.returnType=(cReturnType==null ? 'html' : (cReturnType=='' ? 'html' : cReturnType));

	this.setParams=new Function('params','this.params=params;');
	this.setSource=new Function('source','this.source=source;');
	this.setReturnFunction=new Function('func','this.returnFunction=func;');
	this.setReturnObject=new Function('obj','this.returnObject=obj;');


	this.runAjax=event_runAjax;
	this.xmlHttpReq=event_xmlHttpReq;
	this.submitForm=event_submitForm;
	this.getXMLHttpRequest=event_getXMLHttpRequest;
	this.AjaxRequest=event_AjaxRequest;
	
}

function createAjaxClass(cClassKey,cUrl,cForm,cReturnType){
	if(arguments.length==3) 
		cReturnType='html';
	else
		cReturnType=(cReturnType=='' ? 'html' : cReturnType);
	eval('var ' + cClassKey + ' = new AjaxClassCollection(\''+ cUrl +'\',\''+ cForm +'\',\''+ cClassKey +'\',\''+ cReturnType +'\');');
	return eval(cClassKey);
}
