// Passes the RAVE RSS xml to xml-json-proxy.php which returns the XML

var url = "https://www.getrave.com/rss/pasadena/channel2";

// AJAX request
var xhr2 = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
xhr2.onreadystatechange = XHRhandler;
xhr2.open("GET", "/_resources/includes/scripts/xml-json-proxy.php?url=" + escape(url), true);
xhr2.send(null);
// handle response
function XHRhandler() {

	if (xhr2.readyState == 4) {

		// parse response as JSON
		var json;
		if (JSON && JSON.parse) {
			json = JSON.parse(xhr2.responseText);
			//console.log(json);
		}
		else {
			eval("var json = " + xhr2.responseText);
		}
		
		var rtitle = json.channel.item.title;
		
		if (json.channel.item.description){
			var rdesc = json.channel.item.description;
		}
		else {
			var rdesc = '';
		}
		if(json.channel.item.link.valueOf() != '{}'){
			var rlink = json.channel.item.link;
			//console.log(json.channel.item.link.valueOf());
		}
		else{
			var rlink = '';
		}
		if(json.channel.image){

			var rimg = json.channel.image.url;
		}
		else{
			var rimg = '/_resources/img/rss/notice-default.png';
		}
		
		if (rtitle !== "Website Notice Off"){
			
			$("#notice-container").loadTemplate($("#notice-template"),
	    {
	        title: rtitle,
	        description: rdesc,
	        link: rlink,
	        image: rimg
	    })
	    $("#notice-container").css('display', 'block');
		}
		else {
			$("#notice-container").css('display', 'none');
		}
		// Debugging code
		//console.log(json);
		//alert(rtitle);
		
		xhr2 = null;

	}
	else {
		$("#notice-container").css('display', 'none');
	}

}