 function JimetInputLoaderObj() { 
 	this.jimetAjaxObj = null;
 	this.selectId = null;
 	this.postData = null;
 	this.url = null;
 	this.required = false;
 	this.endFunc = null;
 	this.loaderIcon = null;
 	this.loadingDiv = null;
 	this.isCombo	= false;
 	
 	this.finPosition = function(obj) {
		var curleft = curtop = 0;
		var elem;
		if(this.isCombo)
			elem = this.selectId.DOMelem;
		else
			elem =  document.getElementById(this.selectId);
		var jq = jQuery(elem); 
		var position = jq.offset(); 

		if(position!=null){
		curleft = position.left;
		curtop = position.top;
		}
		return [curleft,curtop];
	};	
	
  	this.init = function(selectId,url,data,required,isCombo){
  		this.selectId = selectId; 	
  		this.isCombo = isCombo;
 		var loadIc = document.createElement('div');
 		var loadDiv = document.createElement('div');
 		
 		loadIc.style.cssText = 'position:absolute;display:none;';
 		loadDiv.className = 'loadingDiv';
 		
		var loadImg = document.createElement('img');
		loadImg.src = '/images/loading.gif';

		loadImg.style.width = 16;
		loadImg.style.height = 16;
		
		document.getElementById("formContainer").appendChild(loadIc);
		document.getElementById("formContainer").appendChild(loadDiv);
		
		
		loadIc.appendChild(loadImg);

		this.loaderIcon = loadIc;
		this.loadingDiv = loadDiv;
		


 		this.jimetAjaxObj = new JimetAjaxObj();
 		this.url = appRoot + url;
 		this.postData = data;
 		this.required = required;
 		
 	}	
 	
 	this.doLoad = function (selectId,url,data,required) {
 		this.init(selectId,url,data,required);
		this.toggleLoading(true);
		
 		var self = this;
		
		this.jimetAjaxObj.setPostData(this.postData);
		this.loaderResult = function(result){
			
			if( typeof(result)!='object' && result=='ajaxError'){
 				self.toggleLoading();
 				ajaxOnWork = false;
 				return;
 			}			
			self.loadSelect (result,self);
 			if (self.endFunc) {
 				if(typeof(self.endFunc)=='function')
 					self.endFunc();
 				else if(typeof(self.endFunc)=='string')
 					eval(self.endFunc);
 					
 				}
			
		};
		this.jimetAjaxObj.doPost(this.url,self.loaderResult,'xml');		
 	} 
 	
 	this.doLoadCombo = function (combo,url,data,required) {
 		this.init(combo,url,data,required,true);
 		this.toggleLoading(true);
 		var self = this;
		
		this.jimetAjaxObj.setPostData(this.postData);
		this.loaderResult = function(result){
			if( typeof(result)!='object' && result=='ajaxError'){
				self.toggleLoading();
 				ajaxOnWork = false;
 				return;
 			}			
			self.loadCombo (result,self);
 			if (self.endFunc) {
 				if(typeof(self.endFunc)=='function')
 					self.endFunc();
 				else if(typeof(self.endFunc)=='string')
 					eval(self.endFunc);
 					
 				}
			
		};
		this.jimetAjaxObj.doPost(this.url,self.loaderResult,'xml');		
 	} 
 	
 	this.loadSelect = function(result,self){
 
		if( result==null && result.text && (result.text.length>0) && result.text=='ajaxError'){
			self();
	 		ajaxOnWork = false;
			return;
		}

  		var selectObj = document.getElementById(self.selectId);
 		var y = result.getElementsByTagName("optionItem");
 		
 		var grps;
 		if(result.getElementsByTagName("optionGroup"))
 			grps = result.getElementsByTagName("optionGroup");

 		
 		var x;
 		if(result.getElementsByTagName("optionAttribute"))
 			x = result.getElementsByTagName("optionAttribute");

 		var a;
 		if(result.getElementsByTagName("optionAttribute1"))
 			a = result.getElementsByTagName("optionAttribute1");
 		
 		var b;
 		if(result.getElementsByTagName("optionAttribute2"))
 			b = result.getElementsByTagName("optionAttribute2");
 		
 		var c;
 		if(result.getElementsByTagName("optionAttribute3"))
 			c = result.getElementsByTagName("optionAttribute3");
 		
 		var val = '';

 		if(selectObj!=null&&selectObj.getAttribute('validator'))
 			val = selectObj.getAttribute('validator');
 		
 		var pair = val.split(';');
 		if (selectObj!=null&&y.length >0){
 			if (selectObj.length>0)
 				firstOpt = selectObj.options[0];
	 		selectObj.options.length=0;	
	 		var j = 0;
	 		if (firstOpt){
	 			selectObj.options[0] = new Option(firstOpt.text,firstOpt.value);
	 			j++;
	 		}		
	 		for (i=0;i<y.length;i++){
	 			if(grps.item(i)!=null){
		 			var myVal=grps[i].childNodes[0].nodeValue;
		 			
		 			if(myVal!='-1'){
		 				optGrp = document.createElement('optgroup');
		 				optGrp.label = myVal;
		 				selectObj.appendChild(optGrp);
		 				//selectObj.options[i+j].setAttribute(x[i].childNodes[0].nodeValue,myAtt.value);
		 				
		 			}	
	 			}

	 			var attlist=y.item(i).attributes;
	 			var att=attlist.getNamedItem("optionValue");//alert(y[i].childNodes[0].nodeValue);
	 			var nodeValStr = '';
	 			if(y[i].childNodes[0] && y[i].childNodes[0].nodeValue !='#empty#')
	 				nodeValStr = y[i].childNodes[0].nodeValue
	 			selectObj.options[i+j] = new Option(nodeValStr,att.value);
	 			if(attlist.getNamedItem("selected")&&attlist.getNamedItem("selected").value=='selected')
	 			{
	 				selectObj.options[i+j].selected = 'selected';
	 			}
	 			
	 			if(x.item(i)!=null){
	 			var myAttlist=x.item(i).attributes;
	 			var myAtt=myAttlist.getNamedItem("attValue");
	 			selectObj.options[i+j].setAttribute(x[i].childNodes[0].nodeValue,myAtt.value);
	 			}
	 			
	 			if(a.item(i)!=null){
		 			var myAttlist=a.item(i).attributes;
		 			var myAtt=myAttlist.getNamedItem("attValue1");
		 			selectObj.options[i+j].setAttribute(a[i].childNodes[0].nodeValue,myAtt.value);
		 			}	 			

	 			if(b.item(i)!=null){
		 			var myAttlist=b.item(i).attributes;
		 			var myAtt=myAttlist.getNamedItem("attValue2");
		 			selectObj.options[i+j].setAttribute(b[i].childNodes[0].nodeValue,myAtt.value);
		 			}	 			
	
	 			if(c.item(i)!=null){
		 			var myAttlist=c.item(i).attributes;
		 			var myAtt=myAttlist.getNamedItem("attValue3");
		 			selectObj.options[i+j].setAttribute(c[i].childNodes[0].nodeValue,myAtt.value);
		 			}	 			
	 			
	 		}
			//selectObj.disabled = false;	
			if (this.required == true && selectObj.getAttribute('validator'))
				str1 = '1' + ';' + pair[1] + ';' + pair[2] + ';' + pair[3] + ';' + pair[4];
			else if(this.required == false && selectObj.getAttribute('validator'))
				str1 = '0' + ';' + pair[1] + ';' + pair[2] + ';' + pair[3] + ';' + pair[4];
		
	 		if(selectObj.getAttribute('validator'))
	 			selectObj.setAttribute('validator',str1);

 		}
		else if(selectObj!=null){
	  		var firstOpt = selectObj.options[0];
	  		if (firstOpt){
		 		selectObj.options.length=0;	
		 		selectObj.options[0] = new Option(firstOpt.text,firstOpt.value);		
		 		//selectObj.disabled = true;
		 		if(selectObj.getAttribute('validator'))
		 		str1 = '0' + ';' + pair[1] + ';' + pair[2] + ';' + pair[3] + ';' + pair[4];
		 		
		 		if(selectObj.getAttribute('validator'))
		 			selectObj.setAttribute('validator',str1);

		 	}
		}

 		ajaxOnWork = false;
 		self.toggleLoading();

 	}
 	
 	this.loadCombo = function(result,self){
		if( result==null && result.text && (result.text.length>0) && result.text=='ajaxError'){
			self();
	 		ajaxOnWork = false;
			return;
		}
			
  		var selectObj = this.selectId;
		
 		var y = result.getElementsByTagName("optionItem");
 		
 		
 		var x;
 		if(result.getElementsByTagName("optionAttribute"))
 			x = result.getElementsByTagName("optionAttribute");

 		
 		if (y.length >0){
 			
	 				
	 		for (i=0;i<y.length;i++){
	 			
	 			var attlist=y.item(i).attributes;
	 			var att=attlist.getNamedItem("optionValue");
	 			var nodeVal = "";
	 			if(y[i].childNodes.length>0)
	 				nodeVal = y[i].childNodes[0].nodeValue;
	 			if(nodeVal =='#empty#')
	 				nodeVal = '';
	 			
	 			selectObj.addOption(att.value,nodeVal);
	 			 			
	 			
	 		}
	 		
	 		var optLength = selectObj.optionsArr.length
	 		selectObj.attachEvent("onOpen",function(){
		 		if(optLength < 5)
	 			{
	 				var height = optLength * 17;
	 				changeCss('.dhx_combo_list','height', height);
	 				selectObj.DOMlist.style.height=height+"px";				//firefox
	 			}
	 			else 
	 			{
	 				height = 110;
	 				changeCss('.dhx_combo_list','height', height);
	 				selectObj.DOMlist.style.height=height+"px";				//firefox
	 			}
	 		})
	 		selectObj.selectOption(0);

 		}
		
 		ajaxOnWork = false;
 		self.toggleLoading();

 	} 
 
 	this.setEndFunc = function(func) {
 		this.endFunc = func;
	};
	
	this.toggleLoading = function(show){
		var mainDiv;
		if(this.isCombo)
			mainDiv = this.selectId.DOMelem;
		else
			mainDiv = document.getElementById(this.selectId);
		
		var pos = this.finPosition(mainDiv);
		
		if (this.loadingDiv){



			this.loaderIcon.style.position = 'absolute';
			
			if(mainDiv&&show){
				this.loaderIcon.style.display = 'block';
				this.loaderIcon.className = 'none';
				this.loadingDiv.style.display = 'block';
				
				this.loadingDiv.style.zIndex = mainDiv.style.zIndex+1;
				this.loaderIcon.style.zIndex = this.loadingDiv.style.zIndex+1;
				this.loaderIcon.style.left = (pos[0]+(mainDiv.offsetWidth/2))-(this.loaderIcon.offsetWidth/2) + 'px';
				this.loaderIcon.style.top = (pos[1]+((mainDiv.offsetHeight/2))-(this.loaderIcon.offsetWidth/2)) + 'px';
				
				this.loadingDiv.style.position = 'absolute';

				this.loadingDiv.style.height = (mainDiv.offsetHeight<this.loaderIcon.offsetHeight?this.loaderIcon.offsetHeight:mainDiv.offsetHeight) + 'px';
				this.loadingDiv.style.width = mainDiv.offsetWidth+ 'px';
				this.loadingDiv.style.left = pos[0]+ 'px';
				this.loadingDiv.style.top = pos[1]+ 'px';				
				
			}
			else if(this.loadingDiv){
				
				jQuery(this.loaderIcon).animate({opacity: 0}, "slow",function(){
					this.style.display = 'none';
					this.className = 'none';
					document.getElementById("formContainer").removeChild(this);

				});
				
				jQuery(this.loadingDiv).animate({opacity: 0}, "slow",function(){
					this.style.display = 'none';
					document.getElementById("formContainer").removeChild(this);

				}); 				

			}
			
			

	

		}
	}; }
 
