function clear_input(){
	if(check_default(this.value)){
		this.value = "";
	}
}
function set_default_input(){
	if(check_default(this.value)){
		this.value = "Paste URL of the chosen thread from plugin cafe";
	}
}
function check_default(val){
	default_val = "Paste URL of the chosen thread from plugin cafe"
	if (val==default_val || val==""){
		return true;
	}
	return false;
}

function makeRSSURL(){
	url = $('thread_input').getValue();
	feed_id = getID(url);
	if(feed_id){
		new Ajax.Request('includes/check-url.php',
		  {
			method:'get',
			parameters: {url: url},
			onLoading: function(){
				updateRSSURL("Verifying Forum Page...");
			},
			onSuccess: function(transport){
				if(transport.responseText=="true"){
					rss_url = "http://chriskelley.tv/plugincafe/cafe_rss_thread.php?TID="+feed_id;
					updateRSSURL("<a href=\""+rss_url+"\" target=\"_self\">"+rss_url+"</a>");
				}else{
					updateRSSURL("-Invalid URL provided-");
				}
			},
			onFailure: function(){ 
			  updateRSSURL("-URL Could not be verified-");
			}
		  });
	}else{
		updateRSSURL("-Can't create a feed for that URL-");
	}
}

function updateRSSURL(str){
	$('thread_follow_url').update(str);
}

function getID(url){	
	re_pattern = "TopicID=([0-9]+)";
	re = new RegExp(re_pattern);
	thread_vars = re.exec(url);
	if(thread_vars){
		return thread_vars[1];
	}
	return false;
}
