var querystring = "Please enter your tweet ID";
var userstring = "Or please enter your username";
var querystringbutton = "Search For Replies";
var userstringbutton = "Search User's Tweets";
var whichinput = "querystring";
var validatestring = new RegExp("^\\d+$");

function clearBox(theid){
	if(document.getElementById(theid).value !== ""){
		document.getElementById(theid).value = "";
		document.getElementById(theid).style.color = "black";
	}
	else{	
	}
	whichinput = theid;
	document.getElementById("submitbutton").value = eval(theid + "button");
}

function unClearBox(theid){
	if(document.getElementById(theid).value == ""){
		document.getElementById(theid).value = eval(theid);
		document.getElementById(theid).style.color = "gray";
		document.getElementById("submitbutton").value = "Search";
	}
	else{
	}
	
}

function  validateSend(){
	
	if(whichinput == "querystring"){
		if(validatestring.test(document.getElementById('querystring').value)){
			document.location = "http://replies.twitterfall.com/search?q=" + document.getElementById('querystring').value;
		}
		else{
			document.getElementById('querystring').value = querystring;
			document.getElementById('querystring').style.color = "gray";
		}
	}
	
	if(whichinput == "userstring"){

		if(document.getElementById('userstring').value == userstring || document.getElementById('userstring').value == ""){
			
		}
		else{

	
			$("#searchtweet table").remove();
			$("#throbber").css("display", "block");
			
			document.getElementById('introtabs').style.display = "none";
			document.getElementById('searchtweet').style.display = "block";
			document.getElementById('addusernameheader').innerHTML = document.getElementById('userstring').value + "'s Tweets";
			
			$.getJSON("http://twitter.com/statuses/user_timeline/"+ $("#userstring").val() +".json?count=5&callback=?",
			function(data){
				var tablestring = "<table>";
				if(data[0].text == null){
					alert("OH HAI");
				}
				else{
				
					for(i in data){
						tablestring += "<tr><td><img src='" + data[i].user.profile_image_url + "' /></td>";
						tablestring += "<td>" + data[i].text + "</td>";
						tablestring += "<td><a href='http://replies.twitterfall.com/search?q=" + data[i].id + "'>View</a></td></tr>";
						
					}
	
				}
				tablestring += "</table>";
				$("#throbber").css("display", "none");
				$("#searchtweet").append(tablestring);
			});
		}	
	}	
}

function switchbox(switchin, switchout){
	document.getElementById(switchout).style.display = "none";
	document.getElementById(switchout + "text").className = "inactive";
	
	document.getElementById(switchin).style.display = "block";
	document.getElementById(switchin + "text").className = "active";
		
}