//---- h_maro 2010-02-15
if (!ASYOUJS) { var ASYOUJS = new Object(); }
ASYOUJS.cacheAjax = function() {
	this.ScriptFragment= '<script[^>]*>([\\S\\s]*?)<\/script>';
	this.uniq=null;
	this.subvc=null;
	this.setUniq= function(uniqs){
		this.uniq=uniqs;
	}
	this.setSubvc= function(subvc){
		this.subvc=subvc;
	}
	this.createHttpRequest= function(){
	//alert(window.ActiveXObject);
		if(window.ActiveXObject){
			try {
				return new ActiveXObject("Msxml2.XMLHTTP")
			} catch (e) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP")
				} catch (e2) {
					return null
				}
			}
		} else if(window.XMLHttpRequest){
			return new XMLHttpRequest()
		} else {
			return null
		}
	}
	this.request= function( data , method , fileName , div){
		if(data==null) data='';
		if(this.subvc !=null){
			data+=(data? '&':'')+'subvc='+this.subvc;
		}
		if(div !=null && div !=''){
			data+=(data? '&':'')+'div='+div;
		}
		if((method=='get' || method=='GET') && data !=''){
			if(fileName.indexOf('?') > -1){
			fileName +='&'+encodeURI(data);
			} else {
			fileName +='?'+encodeURI(data);
			}
		}
		if(typeof('setCircle')=='function'){
			setCircle();
		}
		var httpoj = this.createHttpRequest();
		httpoj.open( method , fileName , true );
		var myobj=this;
		if(window.ActiveXObject){
			httpoj.onreadystatechange = function() {
				if (httpoj.readyState==4) {
					myobj.on_loaded(httpoj,div);
				}
			}
		} else {
			httpoj.onload=function() { myobj.on_loaded(httpoj,div); }
		}
		//alert(this.uniq);
		if(this.uniq !=null){
			httpoj.setRequestHeader( "X-UNIQ", this.uniq );
		}
			httpoj.setRequestHeader("Content-Type", " application/x-www-form-urlencoded");
		httpoj.send( data );
	}
	this.on_loaded= function(oj,div) {
		if(document.getElementById('spinner')){
			document.getElementById('spinner').parentNode.removeChild(document.getElementById('spinner'));
		}
		if(div !=null){
			if(typeof(div)=='string') div=document.getElementById(div);
			if(div){
				div.innerHTML = this.stripScripts(oj.responseText);
			}
		}
		this.evalScripts(oj.responseText);
		//oj.responseText=null;
	}
	this.stripScripts= function(text) {
		var matchAll = new RegExp(this.ScriptFragment, 'img');
		if(text.match(matchAll)){
		return text.replace(matchAll, '');
		} else {
		return text;
		}
	}
	this.evalScripts= function(text) {
		var matchAll = new RegExp(this.ScriptFragment, 'img');
		var matchOne = new RegExp(this.ScriptFragment, 'im');
		var scrAry=text.match(matchAll);
		if(scrAry && scrAry.length > 0){
			for(var i=0; i < scrAry.length; i++){
				var scrInn=scrAry[i].match(matchOne);
				if(scrInn && scrInn.length > 0) eval(scrInn[1]);
			}
		}
	}
}
function serialize(formid,enc){
	var qry='';
	var parents=document.getElementById(formid);
	//alert(parents.elements.length);
	for(var i=0;i<parents.elements.length;i++) {
		if(parents.elements[i].nodeName=='INPUT'){
			var elms=parents.elements[i].type.toLowerCase();
			if(elms=='text' || elms=='password' || elms=='hidden'){
				qry+=qry? '&':'';
				qry+=parents.elements[i].getAttribute('name');
				qry+='=';
				qry+=enc? brackets(parents.elements[i].value):parents.elements[i].value;
			} else if((elms=='radio' || elms=='checkbox') && 
					  parents.elements[i].checked==true){
				qry+=qry? '&':'';
				qry+=parents.elements[i].getAttribute('name');
				qry+='=';
				qry+=enc? brackets(parents.elements[i].value):parents.elements[i].value;
			}
		} else if(parents.elements[i].nodeName=='TEXTAREA'){
			qry+=qry? '&':'';
			qry+=parents.elements[i].getAttribute('name');
			qry+='=';
			qry+=enc? brackets(parents.elements[i].value):parents.elements[i].value;
		} else if(parents.elements[i].nodeName=='SELECT'){
			var optionAry=parents.elements[i].childNodes;
			for(var j=0; j < optionAry.length; j++){
				if(optionAry[j].nodeName=='OPTION' && optionAry[j].selected==true){
					qry+=qry? '&':'';
					qry+=parents.elements[i].getAttribute('name');
					qry+='=';
					qry+=enc? brackets(optionAry[j].value):optionAry[j].value;
				}
			}
		}
	}
	//alert("qry: "+qry);
	return qry;
}
function brackets(str){
return encodeURIComponent(str);
//return str.replace(/&(amp|gt|lt|quot);/g,"[$1]");
}
