// JavaScript Document

function swatch(clr) {
	if(clr=="green") {
		document.getElementById("logoimg").src = "images/theradar_green.png";
		document.getElementById("style").href = "style/green.css";
	}
	else if(clr=="red") {
		document.getElementById("logoimg").src = "images/theradar_red.png";
		document.getElementById("style").href = "style/red.css";
	}
	else if(clr=="blue") {
		document.getElementById("logoimg").src = "images/theradar_blue.png";
		document.getElementById("style").href = "style/blue.css";
	}
	else if(clr=="black") {
		document.getElementById("logoimg").src = "images/theradar_black.png";
		document.getElementById("style").href = "style/black.css";
	}
}

function toggle(imgEl,descEl,feedItemEl) {
	var image = document.getElementById(imgEl);
	var description = document.getElementById(descEl);
	var feedItem = document.getElementById(feedItemEl);
	
	if(image.src.replace(/.*\//,'') == "expand.png") { // Item is currently collapsed
		image.src = "images/collapse.png";
		description.style.display = "block";
		feedItem.style.borderTop = "1px dotted #C3C3C3";
		feedItem.style.borderBottom = "1px dotted #C3C3C3";
	} else { // Item is currently expanded
		image.src = "images/expand.png";
		description.style.display = "none";
		feedItem.style.borderTop = "none";
		feedItem.style.borderBottom = "none";
	}
}

function rate(post_id) {
	var email = document.ratingForm.ratingEmail.value;
	var comments = document.ratingForm.ratingComments.value;
	var el = document.ratingForm.rating;
	var rating = "";
	for(var i=0;i<5;i++) {
		rating = (el[i].checked) ? (el[i].value) : (rating);
	}
	var url = "submitRating.php?p=" + post_id + "&r=" + rating + "&e=" + email + "&c=" + comments;
	xmlreqGET(url,"ratingBox");
}

function charactersLeft(display,text,limit) {
	var displayEl = document.getElementById(display);
	var textEl = document.getElementById(text);
	var textStr = textEl.value;
	charsLeft = limit - textStr.length;
	if(charsLeft <= 5) {
		displayEl.className = "red";
	}
	else {
		displayEl.className = "";
	}
	if(charsLeft <= 0) {
		charsLeft = 0;
		textEl.value = textStr.substring(0,limit);
	}
	displayEl.innerHTML = charsLeft;
}

function loadFeeds() {		
	var url1 = "php/printFeed.php?f=http://www.digital-web.com/news/rss/&s=DigitalWeb&ie=module1" + new Date().getTime();
	xmlreqGET(url1,"module1");
	var url2 = "php/printFeed.php?f=http://feeds.feedburner.com/vitaminmasterfeed&s=Vitamin&ie=module2" + new Date().getTime();
	xmlreqGET(url2,"module2");
	var url3 = "php/printFeed.php?f=http://www.cssdrive.com/index.php/main/rss_2.0/&s=CSSDrive&ie=module3" + new Date().getTime();
	xmlreqGET(url3,"module3");
	var url5 = "php/printFeed.php?f=http://www.cssbeauty.com/rss/news/&s=CSSBeauty&ie=module5" + new Date().getTime();
	xmlreqGET(url5,"module5");
	var url6 = "php/printFeed.php?f=http://feeds.feedburner.com/ajaxian&s=Ajaxian&ie=module6" + new Date().getTime();
	xmlreqGET(url6,"module6");
	var url4 = "php/printFeed.php?f=http://www.oreillynet.com/pub/feed/12?format=rss2&s=ONLamp.com&ie=module4" + new Date();
	xmlreqGET(url4,"module4");
	var url7 = "php/printFeed.php?f=http://feeds.feedburner.com/DevxLatestWebDevelopmentContent&s=DevX&ie=module7" + new Date().getTime();
	xmlreqGET(url7,"module7");
	var url8 = "php/printFeed.php?f=http://www.devshed.com/rss.xml&s=DevShed&ie=module8" + new Date().getTime();
	xmlreqGET(url8,"module8");
}

function toggleTwitter() {
	var textarea = document.getElementById("twitterTextArea");
	var button = document.getElementById("twitterSubmit");
	if(textarea.style.display == "block") {
		textarea.style.display = "none";
		button.style.display = "none";
	} else {
		textarea.style.display = "block";
		button.style.display = "block";
	}
}

function updateTwitter() {
	var tweet = document.getElementById("tweet").value;
	var url = "php/twitterPing.php?tweet=" + tweet;
	xmlreqGET(url,"twitterStatus");
	toggleTwitter();
	tweet = "";
}

function printSocialFeed(feed,limit,el) {
	var url = "php/printSocialFeed.php?f=" + feed + "&l=" + limit;
	xmlreqGET(url,el);
}

function printDiggActivityFeed(user,limit,el) {
	var url = "php/printDiggActivityFeed.php?u=" + user + "&l=" + limit;
	xmlreqGET(url,el);
}

function gethash(hash,string,el) {
	var url = "php/hash.php?hash=" + hash + "&string=" + string;
	xmlreqGET(url,el);
}
