HttpConnect={
	msxmlVer:[
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		],
	
	query:'',
	
	setQuery:function( key , value ){
		if(this.query.length > 0){
			this.query = this.query+"&"+key+"="+value;
		}
		else{
			this.query = key+"="+value
		}	
	},	
	
	sendRequest:function(url, params, callback, method, sync) {		
		var type  = true;
		var conn  = this.getConnection();
		var httpMethod = method ? method : 'GET';
		if (httpMethod != 'GET' && httpMethod != 'POST'){
			httpMethod = 'GET';
		}
		
		try{
			var httpParams = (params == null || params == '') ? null : params;
			var httpUrl = url;
			
			if (httpMethod == 'GET' && httpParams != null) {
				httpUrl = httpUrl + "?" + httpParams;
			}
			
			if(sync)
			{
				type = sync;
			}
			
			conn.open(httpMethod, httpUrl, type);
			conn.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			
			conn.onreadystatechange = function(){
				HttpConnect.getResponse(conn, callback);
			};			
			
			conn.send(httpMethod == 'POST' ? httpParams : null);
		}catch(e){										
			//Display Error Page
			try{
				errorObj = this.getExceptionData();
				if(!callback.scope){
					callback.failure([responseObject]);
				}else{
					callback.failure.apply(callback.scope,[errorObj]);
				}
				this.release();
			}catch(e) {
				alert(e);
				this.release();
			}
		}
	},
	
	getResponse:function(conn, callback){		
		var httpStatus ;
		try{
			if(conn.readyState == 4){									
				try{
					if( conn.status != undefined && conn.status != 0 ){
						httpStatus = conn.status;
					}else{
						httpStatus = 900;
					}
				}catch(e){				
					httpStatus = 900;
				}
				
				if(httpStatus >= 200 && httpStatus < 300){
					try{					
						responseObject = this.getResponseData(conn);						
						if(callback.success){
							if(!callback.scope){						
								callback.success([responseObject]);
							}else{								
								callback.success.apply(callback.scope,[responseObject]);
							}
						}
					}
					catch(e){}
				}else{
					try{
						switch(httpStatus){
						    case 403:
						    case 404:
						    case 500:
							case 900: 
							default:
								responseObject = this.getExceptionData();
								if(callback.failure){
									if(!callback.scope){
										callback.failure([responseObject]);
									}else{
										callback.failure.apply(callback.scope,[responseObject]);
									}
								}
						}
					}catch(e){alert(e);}
			 	}		 	
			}
		}catch(e){
			alert(e);	
		}
		finally{
		  this.release();
		}
	},
		
	getExceptionData:function(conn){
		var obj = {};
		if(conn){
			obj.status = conn.status;
			obj.statusText = conn.statusText;
			obj.getResponseHeader = {};
			obj.getAllResponseHeaders = '';
			obj.responseText = conn.responseText;
			obj.responseXML = conn.responseXML;
		}
		return obj;
	},
	
	getResponseData:function(conn)
	{
		var obj = {};
		var headerObj = {};
		try
		{
			var headerStr = conn.getAllResponseHeaders();			
			var header = headerStr.split('\n');
			for(var i=0; i < header.length; i++){
				var delimitPos = header[i].indexOf(':');
				if(delimitPos != -1){
					headerObj[header[i].substring(0,delimitPos)] = header[i].substring(delimitPos + 2);
				}
			}
		}
		catch(e){}		
		obj.status = conn.status;
		obj.statusText = conn.statusText;
		obj.getResponseHeader = headerObj;
		obj.getAllResponseHeaders = headerStr;
		obj.responseText = conn.responseText;
		obj.responseXML = conn.responseXML;
		return obj;
	},	
	
	//Get HttpRequest Connection
	getConnection:function()
	{
		var conn;
		try	{			
			conn = new XMLHttpRequest();
		}catch(e){
			for(var i=0; i<this.msxmlVer.length; i++){
				try{
					conn = new ActiveXObject(this.msxmlVer[i]);
					break;
				}catch(e){
					alert(e);					
				}
			}
		}finally{
			this.release();
			return conn;
		}
	},
	
	release:function(){
		this.query = '';
	}
}
