/* 	Copyright Comintell AB 2007
	2007-04-12	KXC 5.1 Anders Thulin
	
	Basic KXC AJAX Component with one function, getData(dataSource, divID),  which returns data from any cfm file to a div:
	Get results from a file (variable1=datasourse) and put the results in a div (variable2=div id)
	Parameters may be passed as url params
	Example of usage:
	 <form>
      <input type = "button" value = "Display Message" 
        onclick = "getData('do_data.cfm?infoelementid=1', 'targetDiv')"> 
    </form>
    <div id="targetDiv">
      <p>The fetched data will go here.</p> 
    </div> 
 */     
 function getData(dataSource, divID) 
      { 
	  var XMLHttpRequestObject = false; 
      try { 
          XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP"); 
      } catch (exception1) { 
          try { 
              XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); 
          } catch (exception2) { 
              XMLHttpRequestObject = false; 
          } 
      } 
      if (!XMLHttpRequestObject && window.XMLHttpRequest) { 
        XMLHttpRequestObject = new XMLHttpRequest(); 
      } 
        if(XMLHttpRequestObject) {
          var obj = document.getElementById(divID); 
          XMLHttpRequestObject.open("GET", dataSource); 

          XMLHttpRequestObject.onreadystatechange = function() 
          { 
            if (XMLHttpRequestObject.readyState == 4 && 
              XMLHttpRequestObject.status == 200) { 
                obj.innerHTML = XMLHttpRequestObject.responseText; 
            } 
          } 
          XMLHttpRequestObject.send(null); 
        }
      }
	function encode(string) {  /* urlencodes with javascript data sent with AJAX*/ 
        string = string.replace(/\r\n/g,"\n");   
        var utftext = "";   
        for (var n = 0; n < string.length; n++) {   
  
            var c = string.charCodeAt(n);   
  
            if (c < 128) {   
                utftext += String.fromCharCode(c);   
            }   
            else if((c > 127) && (c < 2048)) {   
                utftext += String.fromCharCode((c >> 6) | 192);   
                utftext += String.fromCharCode((c & 63) | 128);   
            }   
            else {   
                utftext += String.fromCharCode((c >> 12) | 224);   
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);   
                utftext += String.fromCharCode((c & 63) | 128);   
            	}     
        	}   
		 return utftext;  
		} 	  
