
function createClinicaXMLHttpRequest(){
	  var req;
	  if (window.XMLHttpRequest){ 
		req = new XMLHttpRequest(); 
	} else if (window.ActiveXObject){ 
		req = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	return req;
  }
  
  
  function getClinicaAutonomyResponse(XMLHttpRec,title,query,conSize,relatedLink,recency,source) {
   // Abort any currently pending requests for this XMLHttpRequest Object
   XMLHttpRec.onreadystatechange = function () {}
   XMLHttpRec.abort();
   var urlMapping = "";
   // Get variables from form and build URL to call
   if(urlMapping ==""){
		urlMapping="";
	}else	{
		urlMapping="/" + urlMapping;
	}
	
	url = urlMapping + "/sectorDataServlet?autnQuery="+query+"&contentSize="+conSize+"&isReltated="+relatedLink+"&recency="+recency;
		
	// Tell the XMLHttpRequest object what the url is and that 
   // you will use the "GET" response not "POST" to call the external url
   XMLHttpRec.open("GET", url, true);

   // Assign the name of the JavaScript function which will be called 
   // when the request completed then send the request
   XMLHttpRec.onreadystatechange = function () { 
                                    callback(XMLHttpRec,title,source);
                                    }
   XMLHttpRec.send(null);
   
 } 
 
 function callback(req,sectionDiv,source){
	
	  if (req.readyState==4){ 
	      if (req.status == 200){ 
			if (window.ActiveXObject)
			{
	          	populateData(req,sectionDiv,source);
			} 
	        else if (window.XMLHttpRequest)
			{ 
	            populateData(req,sectionDiv,source); 
	        } 
	      } 
    } 

 }
 
  function populateData(r,sectionDiv,source){
	
    var resp = r.responseText;
    var myJSONObject = eval('(' + resp + ')');
	displayClinicaData(myJSONObject,sectionDiv,source);
  }
  
  
  
  function displayClinicaData(clinicaInfoObj,sectionDiv,source)
{	

	var i;
	var flag = false;
    var responseHTML = "";
	var moreID = "more"+sectionDiv;
	if (typeof(clinicaInfoObj.sectionData)=="undefined" || clinicaInfoObj.sectionData.length == 0)
	{
				
		if (document.getElementById(moreID)!=null){
			document.getElementById(moreID).style.display="none";
			//responseHTML = "<table><tr><td class='headlineTxt'>"+sectionDiv.replace('|','&')+"</td></tr>";
			//responseHTML +="<tr><td>Data not available for "+sectionDiv.replace('|','&')+".</td></tr>"
			//responseHTML +="<tr><td>Please provide the data.</tr></td></table>"
			//document.getElementById(moreID).innerHTML = responseHTML;
		}
		return;
	}
	
	for (i = 0; i < clinicaInfoObj.sectionData.length; i++) 
	{
		var clinicaData = clinicaInfoObj.sectionData[i];	
		
		if(source == "PEOPLE"){
		
			responseHTML +="<div class='peopleContainer'><span class='peopleTitle'><a href='"+clinicaData.articleUrl+"'>"+clinicaData.articleTitle+"</a></span>";
			responseHTML +="<span class='peopleTxt marginTop10'>"+clinicaData.bodyContent+"</span></div>";
			
		}
		else if (source == "BOTTOM ANALYSIS"){
		
			if (typeof(clinicaData.imgSrc)!="undefined" && clinicaData.imgSrc != null){
				responseHTML +="<div class='middleCommon'><div class='middleRight'><span class='interviewImg'><img src='"+clinicaData.imgSrc+"' border='0'/></span></div>";
				responseHTML +="<div class='middleLeft'><span class='headlineTitle'><a href='"+clinicaData.articleUrl+"'>"+clinicaData.articleTitle+"</a></span></div>";
				responseHTML +="<div class='middleLeft'><span class='italicText'>"+clinicaData.articleDate+"</span></div>";
				responseHTML +="<div class='middleLeft'><span class='italicText'><i>"+clinicaData.author+"</i></span></div>";
				responseHTML +="<p>"+clinicaData.bodyContent+"</p></div>";
			}else {
				responseHTML +="<div class='middleCommon'><span class='headlineTitle'><a href='"+clinicaData.articleUrl+"'>"+clinicaData.articleTitle+"</a></span></div>";
				responseHTML +="<div class='middleCommon'><span class='italicText'>"+clinicaData.articleDate+"</span></div>";
				responseHTML +="<div class='middleCommon'><span class='italicText'><i>"+clinicaData.author+"</i></span></div>";
				responseHTML +="<div class='middleCommon'><span class='middleTxt marginTop10'>"+clinicaData.bodyContent+"</span></div>";
			}
		
		}
		else if(source == "ANALYSIS"){
		
			responseHTML +="<div class='middleCommon'><span class='headlineTitle'><a href='"+clinicaData.articleUrl+"'>"+clinicaData.articleTitle+"</a></span></div>";
			responseHTML +="<div class='middleCommon'><span class='italicText'>"+clinicaData.articleDate+"</span></div>";
			responseHTML +="<div class='middleCommon'><span class='middleTxt marginTop10'>"+clinicaData.bodyContent+"</span></div>";
			
			if (typeof(clinicaData.relatedLink1)!="undefined"){
				responseHTML +="<div class='middleCommon'><span class='middleArrow'><img src='/template/ver1.0/Images/arrowImg.gif' height='7' width='5' border='0'/></span>";
				responseHTML +="<span class='middleInnerArrowtxt'> <a href='"+clinicaData.relatedUrl1+"'>"+clinicaData.relatedLink1.substring(0,60)+"...</a></span></div>";
				
			}
			if (typeof(clinicaData.relatedLink2)!="undefined"){
				responseHTML +="<div class='middleCommon'><span class='middleArrow'><img src='/template/ver1.0/Images/arrowImg.gif' height='7' width='5' border='0'/></span>";
				responseHTML +="<span class='middleInnerArrowtxt'> <a href='"+clinicaData.relatedUrl2+"'>"+clinicaData.relatedLink2.substring(0,60)+"...</a></span></div>";
				
			}
			
		}
		else if (source == "Events") {
		
			responseHTML +="<div class='rightCommon'><span class='headlineTitle marginLeft5'><a href='"+clinicaData.articleUrl+"'>"+clinicaData.articleTitle+"</a></span></div>";
			responseHTML +="<div class='rightCommon'><span class='italicText marginLeft5'>"+clinicaData.eventDate+"</span></div>";
			responseHTML +="<div class='rightCommon'><span class='newsContent marginLeft5'>"+clinicaData.eventLocation+"</span></div>";
		
		}
		else if (source == "REFINEMENT") {
			
			responseHTML +="<div class='middleCommon'><span class='refineTitle'>";
			responseHTML +="<a onclick='setParametric(\""+sectionDiv+"\",\""+clinicaData.refineBy.replace('\'','&#039;')+"\",\""+clinicaInfoObj.parametricText+"\")' style='cursor: pointer;'>"+clinicaData.refineBy+"</a></span></div>";		
			document.getElementById("hideRefineBy").style.display="block";
		}
		else{
			if (typeof(clinicaData.imgSrc)!="undefined" && clinicaData.imgSrc != null){
				responseHTML +="<div class=leftHeading><div class=leftImage><img src='"+clinicaData.imgSrc+"' border='0'/></div>";
				responseHTML +="<div class='leftContent'><span class='headlineSubTitle'><a href='"+clinicaData.articleUrl+"'>"+clinicaData.articleTitle+"</a></span>";
				responseHTML +="<span class='italicTextAlt'>"+clinicaData.articleDate+"</span></div><div class='leftContentTxt marginTop10'>"+clinicaData.bodyContent+"</div></div>";
			}else {
				responseHTML +="<div class='leftHeading'><span class='headlineTitle'><a href='"+clinicaData.articleUrl+"'>"+clinicaData.articleTitle+"</a></span></div>";
				responseHTML +="<div class='leftHeading'><span class='italicText'>"+clinicaData.articleDate+"</span></div>";
				responseHTML +="<div class='leftHeading marginTop10'><p>"+clinicaData.bodyContent+"</p></div>";
			}
			
			if (typeof(clinicaData.relatedLink1)!="undefined"){
				responseHTML +="<div class='leftHeading'><span class='leftArrow'><img src='/template/ver1.0/Images/arrowImg.gif' height='7' width='5' border='0' /></span>";
				responseHTML +="<span class='leftInnerTxt'><a href='"+clinicaData.relatedUrl1+"'>"+clinicaData.relatedLink1.substring(0,60)+"...</a></span></div>";
			}
			if (typeof(clinicaData.relatedLink2)!="undefined"){
				responseHTML +="<div class='leftHeading'><span class='leftArrow'><img src='/template/ver1.0/Images/arrowImg.gif' height='7' width='5' border='0' /></span>";
				responseHTML +="<span class='leftInnerTxt'><a href='"+clinicaData.relatedUrl2+"'>"+clinicaData.relatedLink2.substring(0,60)+"...</a></span></div>";
			}
		}
			
		
	}
	
	document.getElementById(sectionDiv).innerHTML = responseHTML;
}
 
 
 
  function getClinicaEventsResponse(XMLHttpRec,source) {
	
	 var urlMapping = "";
  
   // Get variables from form and build URL to call
   if(urlMapping ==""){
		urlMapping="";
	}else	{
		urlMapping="/" + urlMapping;
	}
	
   // Abort any currently pending requests for this XMLHttpRequest Object
   XMLHttpRec.onreadystatechange = function () {}
   XMLHttpRec.abort();
   // Get variables from form and build URL to call
   var url = urlMapping+"/latestEvents";

   // Tell the XMLHttpRequest object what the url is and that 
   // you will use the "GET" response not "POST" to call the external url
   XMLHttpRec.open("GET", url, true);

   // Assign the name of the JavaScript function which will be called 
   // when the request completed then send the request
   XMLHttpRec.onreadystatechange = function () { 
                                    callback(XMLHttpRec,source,source);
                                    }
   XMLHttpRec.send(null);
   
 }
 
 function getClinicaRefinementData(XMLHttpRec,title,query,source) {
	
	 var urlMapping = "";
   
   // Get variables from form and build URL to call
   if(urlMapping ==""){
		urlMapping="";
	}else	{
		urlMapping="/" + urlMapping;
	}
	
   // Abort any currently pending requests for this XMLHttpRequest Object
   XMLHttpRec.onreadystatechange = function () {}
   XMLHttpRec.abort();
   // Get variables from form and build URL to call
   var url = urlMapping+"/getRefineByList?autnQuery="+query;

   // Tell the XMLHttpRequest object what the url is and that 
   // you will use the "GET" response not "POST" to call the external url
   XMLHttpRec.open("GET", url, true);

   // Assign the name of the JavaScript function which will be called 
   // when the request completed then send the request
   XMLHttpRec.onreadystatechange = function () { 
                                    callback(XMLHttpRec,title,source);
                                    }
   XMLHttpRec.send(null);
   
 }