﻿// Wonderful little function from prototype.js
    var req;

	function castContent(url,num,type) {
		// This demo uses simple Html/JS only, so we load a static html page
		//var url = "/ajax-demo/static-article-ranking.html";
		var callback = function() { processAjaxResponse(num,type) };
		//processAjaxResponse;
		executeXhr(callback, url);
	}

	function executeXhr(callback, url) {
		// branch for native XMLHttpRequest object
    		if (window.XMLHttpRequest) {
        		req = new XMLHttpRequest();
        		req.onreadystatechange = callback;//function() { processAjaxResponse(num) }; //callback;
        		req.open("GET", url, true);
        		req.send(null);
    		} // branch for IE/Windows ActiveX version
    		else if (window.ActiveXObject) {
        		req = new ActiveXObject("Microsoft.XMLHTTP");
       		if (req) {
            		req.onreadystatechange = callback;
            		req.open("GET", url, true);
            		req.send();
        		}
    		}
	}
  
 	function processAjaxResponse(num,type) {
    		// only if req shows "loaded"
    		if (req.readyState == 4) {
        		// only if "OK"
        		if (req.status == 200) {
        			  var txt=req.responseText;
        			  //alert(txt);
        			  var rstr="src=\"/blogcontent/"+num+"/images";
					  if(type=="2")
					  txt=txt.substr(0,1000);
					  //alert(type);
					  
        			  txt=txt.replace(/src=\"\.\/images/g,rstr);
        			  txt=txt.replace(/src=\"images/g,rstr);
        			  //alert(txt);
					  var blodiv="blogcontent_"+num;
            		$(blodiv).innerHTML = txt;
					if(type=="2")
					$(blodiv).innerHTML=$(blodiv).innerText;
					//alert($(blodiv));
            		//alert($('blogcontent').innerHTML);
        		} else {
            		//alert("There was a problem retrieving the XML data:\n" +
                //	req.statusText);
        		}
    		}
	} 
  
  

function $() {
  var elements = new Array();
  
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;
      
    elements.push(element);
  }
  
  return elements;
}

