// Forthcoming consultations http://www.opinionsuite.com/cumbria/rss?loc=hub&st=forthcoming
// Open consiltations        http://www.opinionsuite.com/cumbria/rss?loc=hub&st=open
// Closed consultations      http://www.opinionsuite.com/cumbria/rss?loc=hub&st=closed


google.load("feeds", "1");
function getConsultation(Code, Items) {
var Consultationfeed = new google.feeds.Feed("http://www.opinionsuite.com/cumbria/cumbria-county-council/rss?loc=hub&st=" + Code);      
Consultationfeed.load(function(result) {        
if (!result.error) {          
var strTitle = result.feed.title;
var intCount = result.feed.entries.length;

strConsultationDiv = Code + "consultations";
var container = document.getElementById(strConsultationDiv);
var div = document.createElement("div");            
//div.appendChild(document.createTextNode(strTitle));



for (i=0;i<intCount;i++)
{

if (i<Items)
{
var leftDiv = document.createElement("div");

leftDiv.setAttribute("style", "float: left;");
leftDiv.style.styleFloat = "left";
leftDiv.style.width = "160px";
leftDiv.style.fontSize = "0.85em";
leftDiv.style.padding = "7px 0px 0px";


//Hyperlink to consultation item
var myLink = document.createElement("a");
var myTextNode = document.createTextNode(result.feed.entries[i].title);
myLink.setAttribute("href", result.feed.entries[i].link);
myLink.setAttribute("title", "View this consultation");
myLink.appendChild(myTextNode);

leftDiv.appendChild(myLink);
div.appendChild(leftDiv);            
container.appendChild(div);

var description = result.feed.entries[i].contentSnippet;
intStart = description.indexOf("Closing");
intEnd = description.indexOf("]");
if (intStart>0 && intEnd > 0)
{ 
   strClosingDate = description.substring(intStart+7, intEnd);
}
else
   strClosingDate = "(unknown)";

//Abbreviate dates
strClosingDate = strClosingDate.replace("January", "Jan");
strClosingDate = strClosingDate.replace("February", "Feb");
strClosingDate = strClosingDate.replace("March", "Mar");
strClosingDate = strClosingDate.replace("April", "Apr");
strClosingDate = strClosingDate.replace("May", "May");
strClosingDate = strClosingDate.replace("June", "Jun");
strClosingDate = strClosingDate.replace("July", "Jul");
strClosingDate = strClosingDate.replace("August", "Aug");
strClosingDate = strClosingDate.replace("September", "Sep");
strClosingDate = strClosingDate.replace("October", "Oct");
strClosingDate = strClosingDate.replace("November", "Nov");
strClosingDate = strClosingDate.replace("December", "Dec");




var rightDiv = document.createElement("div");
rightDiv.appendChild(document.createTextNode(strClosingDate));
//rightDiv.innerText = strClosingDate;
rightDiv.setAttribute("style", "float: right;");
rightDiv.style.styleFloat = "right";
rightDiv.style.textAlign = "right";
rightDiv.style.width = "80px";
rightDiv.style.fontSize = "0.85em";
rightDiv.style.padding = "7px 0px 0px";

div.appendChild(rightDiv); 

//Line break
var br = document.createElement("div");
br.style.clear = "both";
div.appendChild(br);
container.appendChild(div);

//Item description
//div.appendChild(document.createTextNode(result.feed.entries[i].contentSnippet));
//container.appendChild(div);

//Line separator
//div.appendChild(document.createElement('hr'));            
//container.appendChild(div);

}
}
}


//strLocationAnchor = "BBCWeatherLocation" + Code;
//var anchor = document.getElementById(strLocationAnchor);
//anchor.href = "http://news.bbc.co.uk/weather/forecast/" + Code;
//anchor.title = "BBC weather forecast for " + strLocation;
//anchor.innerHTML = strLocation;

}      
);  
}
