	var CongClass = function () {};

	CongClass.extend = function(destClass,sourceClass) {		
		for(var p in sourceClass.prototype) {
			destClass.prototype[p] = sourceClass.prototype[p];
		}
		return destClass;
	}
	CongClass.prototype.extend = function(source) {		
		for(var p in sourceClass.prototype) {
			this.prototype[p] = sourceClass.prototype[p];
		}
		return this;
	}
	
	var CongEncoderClass = function() {}
	CongEncoderClass.encode = function(data) {
		   var encodedStr = '';
		   var str = ""+data;
		   for(var i=0;i<str.length;i=i+1) {
		      encodedStr += '&#';
		      encodedStr +=str.charCodeAt(i);
		      encodedStr +=';'
		   }
		   return escape(encodedStr);	
	};
	CongEncoderClass.prototype.encode = CongEncoderClass.encode;

	CongDomCursorClass = function(nd) {
		this.cursorNode = nd;
	}
	CongDomCursorClass.getNodeName = function(node) {
		var name = null;
		try {
			name = node.nodeName;
		}
		catch(err) {
			alert(err.message);
		}
		return name;
	}
	
	CongDomCursorClass.toRoot = function(node) {
		return node.ownerDocument.documentElement;
	}
	
	
	CongDomCursorClass.toParent = function(node) {
		 return node.parentNode;
	}
	
	
	CongDomCursorClass.toFirstChild = function(node) {
		var child = node.firstChild;
		while(child!=null && child.nodeType!=1) {
		   child = child.nextSibling;
		} 
		return child;
	}
	
	
	CongDomCursorClass.toLastChild = function(node) {
		var child = node.lastChild;
		while(child!=null && child.nodeType!=1) {
		   child = child.previousSibling;
		} 
		return child;
	}	
	
	CongDomCursorClass.toNextSibling = function(node) {
		var next = node.nextSibling;		
		while(next!=null && next.nodeType!=1) {
		   next = next.nextSibling;
		} 
		return next;
	}
	
	CongDomCursorClass.toPrevSibling = function(node) {
		var prev = node.previousSibling;
		while(prev!=null && prev.nodeType!=1) {
		   prev = prev.previousSibling;
		} 
		return prev;
	}
		
	CongDomCursorClass.hasChildNodes = function(node) {
		var child = node.firstChild;
		while(child!=null && child.nodeType!=1) {
		   child = child.nextSibling;
		} 		
		return (child!=null);
	}	

	
	CongDomCursorClass.getChildCount = function(node) {
		var count = 0;
		var next = node.firstChild;		
		while(next!=null) {
		   if(next.nodeType==1) count +=1;
		   next = next.nextSibling;
		} 
		return count;
	}
	
	CongDomCursorClass.getAttributeFromCursor = function(node,attname) {
		var val = null;
		if(node.nodeType==1) val = node.getAttribute(attname);
		return val;
	}
	
	
	CongDomCursorClass.prototype.cursorNode = null;
	CongDomCursorClass.prototype.getNodeName = function() {
		return CongDomCursorClass.getNodeName(this.cursorNode);
	}
	CongDomCursorClass.prototype.toRoot = function() {
		var root = CongDomCursorClass.toRoot(this.cursorNode);
		if(root!=null) this.cursorNode = root;
		return root;
	}
	CongDomCursorClass.prototype.toParent = function() {
		var parent = CongDomCursorClass.toParent(this.cursorNode);
		if(parent!=null) this.cursorNode = parent;
		return parent;
	}
	CongDomCursorClass.prototype.toFirstChild = function() {
		var child = CongDomCursorClass.toFirstChild(this.cursorNode);
		if(child!=null) this.cursorNode = child;
		return child;
	}
	CongDomCursorClass.prototype.toLastChild = function() {
		var child = CongDomCursorClass.toLastChild(this.cursorNode);
		if(child!=null) this.cursorNode = child;
		return child;	
	}
	CongDomCursorClass.prototype.toNextSibling = function() {
		var next = CongDomCursorClass.toNextSibling(this.cursorNode);
		if(next!=null) this.cursorNode = next;
		return next;		
	}
	CongDomCursorClass.prototype.toPrevSibling = function() {
		var prev = CongDomCursorClass.toPrevSibling(this.cursorNode);
		if(prev!=null) this.cursorNode = prev;
		return prev;		
	}
	CongDomCursorClass.prototype.hasChildNodes = function() {
		return CongDomCursorClass.hasChildNodes(this.cursorNode);
	}
	CongDomCursorClass.prototype.getChildCount = function() {
		return CongDomCursorClass.getChildCount(this.cursorNode);
	}
	CongDomCursorClass.prototype.getAttributeFromCursor = function(attname) {
		return CongDomCursorClass.getAttributeFromCursor(this.cursorNode,attname);
	}


	CongDomParserClass = function(xmldoc) {
		this.doc = xmldoc;
		this.cursorNode = xmldoc.documentElement;
	}
	CongClass.extend(CongDomParserClass,CongDomCursorClass);
	CongDomParserClass.serializeDoc = function (doc) {
		var xmlString = null;
		if(doc.documentElement) {
			var node = doc.documentElement;
	 		if(window.XMLSerializer){
		 		  try {		 		  
		 			xmlString =  node.innerHTML ? node.innerHTML : (new XMLSerializer()).serializeToString(node);
		 		  } catch(err) {
		 		  	    alert("ERR: "+err.message);
		 		  }
	 		} else {
			 	 	xmlString = node.innerHTML ? node.innerHTML : node.xml; 
		 	}		  
		}
 		return xmlString;	 
	}
	CongDomParserClass.parse = function(parentObject,depth,node,handler) {
		var root  = node;
		var pObj  = parentObject;
		if(root!=null) {
			pObj = handler.process(pObj,depth,root.nodeName,root);
			var child =  CongDomCursorClass.toFirstChild(root);
			while (child!=null) {
				CongDomParserClass.parse(pObj,depth+1,child,handler);
				child = CongDomCursorClass.toNextSibling(child);
			}			
		}
		return pObj;
	}
	CongDomParserClass.createCursor  = function(node) {
		return new CongDomCursorClass(node);		
	}


	CongDomParserClass.prototype.doc = null;
	CongDomParserClass.prototype.serializeDoc = function() {
		return CongDomParserClass.serializeDoc(this.doc);		
	}
	CongDomParserClass.prototype.parse = function(handler) {
		return CongDomParserClass.parse(null,0,this.doc.documentElement,handler);
	}
	CongDomParserClass.prototype.createCursor = function(node) {
		if(typeof(node)=='undefined') node = this.cursorNode;
		return CongDomParserClass.createCursor(node);
	}
	
	CongQueryString = function(enc) {
		if(typeof(enc)=='undefined') enc = false;
		this.bEncoding = enc;
	};
	CongQueryString.prototype.bEncoding = false;
	CongQueryString.prototype.queryString  = null;
	
	CongQueryString.prototype.add = function(name,val) {
			var value = val;
			if(this.bEncoding) {
				value = CongEncoderClass.encode(val);
			}
			if(this.queryString!=null) this.queryString += '&';
			else this.queryString = '';
			this.queryString += (name+"="+value);
	}
	CongQueryString.prototype.toString = function() {
			return this.bEncoding ? "CONGSVC_ENCODING=true&" + this.queryString : this.queryString;		
	}

	/*
	*/
	var CongAjaxClass = function() {
		this.proxy = null;
	};

	CongAjaxClass.prototype = {
		setProxy : function(proxyurl,svchost) {
			this.proxy = new Object();
			this.proxy.url = proxyurl;
			this.proxy.svchost = svchost;
		},
		onLoad  : function(httprequest,caller,callback) {
			var dom = null;
			if (httprequest.status == 200) {
				    if(window.DOMParser) {
					var txt = httprequest.responseText;
					dom = new DOMParser().parseFromString(txt,"text/xml");
				    } else {
				        dom = httprequest.responseXML;
				    }
				    callback.apply(caller,[httprequest,dom]);
			} else {
					alert('There was a problem with the request.2');
			}
		},
		request : function (url,query,callback) {
			var httprequest = false;
			var caller = this;
			if (window.XMLHttpRequest) {
					httprequest = new XMLHttpRequest();
					httprequest.onload = function() { 
					   CongAjaxClass.onLoad(httprequest,caller,callback);
					};
			} 
/*
			if (window.ActiveXObject) {
					httprequest = new ActiveXObject("Microsoft.XMLHTTP");
					httprequest.onreadystatechange = function() {
					    	if(httprequest.readyState==4) CongAjaxClass.onLoad(httprequest,caller,callback);
					}
			}
*/
			if(httprequest) {
				try {
						var requestUrl = url;
						var postData = null;
						if(typeof(query)=='undefined') postData='';
						else postData = query;
						httprequest.open("POST", requestUrl, true);
	          httprequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            httprequest.send(postData);
				} catch(error){
						alert(error.message);
				}	
			}
		},
		getResponse : function (url,query,isXml) {
	        var response = null;
			var httprequest = false;
			if (window.XMLHttpRequest) {
					httprequest = new XMLHttpRequest();
			} 
                        if (window.ActiveXObject) {
					httprequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			if(httprequest) {
				var requestUrl = url;
				var postData = null;
				if(typeof(query)=='undefined') postData='';
				else postData = query;
				if(this.proxy!=null) {
					postData += ['&SVCURL_FOR_PROXY=', this.proxy.svchost,requestUrl].join('');							
					requestUrl = this.proxy.url;
				}
				httprequest.open("GET", requestUrl, false);
				httprequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				httprequest.send(postData);

				if (httprequest.status == 200) {
					if(isXml) response = httprequest.responseXML;
					else      response = httprequest.responseText;
				} else {
debugger;
					alert('There was a problem with the request. 1');
				}
			}
			return response;
		},
		getResponseDom : function(url,postdata) {
			return this.getResponse(url,postdata,true);
		},
		getResponseText : function(url,postdata) {
			return this.getResponse(url,postdata,false);
		},
		getResponseAttributes : function(url,query,attnames) {
			var dom = this.getResponseDom(url,query);
			var result = new Array();
			if(dom!=null) {
				if(typeof attnames == 'string') {
				    return dom.documentElement.getAttribute(attnames);
				} else {
					for(attnm in attnames) {
						try {
							result[result.length] =  dom.documentElement.getAttribute(attnames[attnm]);
						} catch(ex) {
						}
					}
					return result;
				}
			}
			return null;
		}
		
	};
	
	CongClass.extend(CongAjaxClass,CongEncoderClass);	
	CongAjaxClass.prototype.getDom   = CongAjaxClass.prototype.getResponseDom;
	CongAjaxClass.prototype.getText  = CongAjaxClass.prototype.getResponseText;
	CongAjaxClass.prototype.getResultAttributes = CongAjaxClass.prototype.getResponseAttributes;
	
	var CongBasicService = function() {};
	CongBasicService.prototype.serviceURL = null;
	CongBasicService.createService = function(url) {
		var serviceClass = function(url) {
		};
		CongClass.extend(serviceClass,CongBasicService);
		serviceClass.prototype.serviceURL = url;
		return serviceClass;
	}
	
	
	var CongDirectoryClass = function() {
	   this.data = new Array();
	}
	
	CongDirectoryClass.prototype.put = function(key,obj) {
	   if(this.data.length==0) {
 	      this.data[this.data.length] = [key,obj];
	   } else {
	      var emptyEntry = null;
	      var bPuted = false;
	      for(var i=0;i<this.data.length;i++) {
	         if(this.data[i]==null) {
	            emptyEntry = i;
	         } else {
	            if(this.data[i][0]==key) {
	              this.data[i] = [key,obj];
	              bPuted = true;
	              break;
	            }
	         }
	      }
	      if(!bPuted) {
	         if(emptyEntry!=null) {
	              this.data[emptyEntry] = [key,obj];
	         } else {
                  this.data[this.data.length] = [key,obj];	         
	         }
	      }
	   }
	}
	
	CongDirectoryClass.prototype.get = function(key) {
        for(var i=0;i<this.data.length;i++) {
	         if(this.data[i]!=null) {
	            if(this.data[i][0]==key) {
	               return this.data[i][1];
	            }
	         }
	    }
	    return null;
	}
	
	CongDirectoryClass.prototype.getKey = function(idx) {
	    if(this.data[idx]==null) return null;	   
	    return this.data[idx][0];
	}
	CongDirectoryClass.prototype.getValue = function(idx) {
	    if(this.data[idx]==null) return null;	   
	    return this.data[idx][1];
	}	
	
	CongDirectoryClass.prototype.remove = function(key) {
        for(var i=0;i<this.data.length;i++) {
	         if(this.data[i]!=null) {
	            if(this.data[i][0]==key) {
	               this.data[i] = null;
	               return true;
	            }
	         }
	    }
	    return false;
	}    
	
	CongDirectoryClass.prototype.removeAll = function() {
	    this.data.length=0;
	}
	CongDirectoryClass.prototype.size  = function() {
	    return this.data.length;
	} 
