var baseURL = 'http://look.gd/';

function populateTweet(text) {
l = document.getElementById('top_bar');
t = document.getElementById('tweet');
btn = document.getElementById('twitter_login_btn');
if (l == null) {
alert("You must be logged-in to tweet.");
} else {
if (btn == null) {
t.innerHTML = text;
t.focus();
} else {
open(btn.alt,'AuthorizeTwitter','width=600,height=400');
}
}
}




function checkMatch(textbox1, textbox2, spanID) {
txt1 = document.getElementById(textbox1);
txt2 = document.getElementById(textbox2);
s = document.getElementById(spanID);
if (txt2.value != "") {
if (txt1.value != "") {
if (txt1.value == txt2.value) {
s.innerHTML = "<span class='confirm'>Passwords match.</span>";
} else {
s.innerHTML = "<span class='error'>Passwords don't match.</span>";
}
} else {
s.innerHTML = "";
}
} else {
s.innerHTML = "";
}
}




window.onload = function() {
var inputs=document.getElementsByTagName("input");
for (var i=0;i<inputs.length;i++){
if (inputs[i].type == "text" || inputs[i].type == "password")  {
inputs[i].onfocus = function(){focusText(this);}
inputs[i].onblur = function(){blurText(this);}
}
}
var textboxes=document.getElementsByTagName("textarea");
for (var i=0;i<textboxes.length;i++){
textboxes[i].onfocus = function(){focusText(this);}
textboxes[i].onblur = function(){blurText(this);}
}
}

function confirmLink(text, link) {
p = confirm(text);
if (p) {
window.location = link;
}
}

function textLimit(field, maxlen, leftspan) {
left = maxlen-field.value.length;
if (left < 0) {
left = 0;
}
document.getElementById(leftspan).innerHTML = left;
if (field.value.length > maxlen) {
field.value = field.value.substring(0, maxlen);
} 
}


function focusText(textbox) {
    textbox.setAttribute("class", "input_sel");
    textbox.className = "input_sel";
    if (textbox.id != "tweet") {
    if (textbox.alt == textbox.value) {
      textbox.value = "";
    }
}
}

function blurText(textbox) {
    textbox.setAttribute("class", "");
    textbox.className = "";
    if (textbox.id != "tweet") {
    if (textbox.value == "") {
    textbox.value = textbox.alt;
    }
}
}

function toggleDiv(divID) {
d = document.getElementById(divID);
if (d.style.display == "none") {
d.style.display = "block";
} else {
d.style.display = "none";
}
}



function createURL(textbox, ckey) {
t = document.getElementById(textbox);
c = document.getElementById(ckey);
s = document.getElementById('status');
page = baseURL+"ajax/create_url.php?url="+t.value+"&ckey="+c.value;


var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function() {
if(ajaxRequest.readyState == 4){
response = ajaxRequest.responseText;
s.innerHTML = response;
}
}
	ajaxRequest.open("GET", page, true);
	ajaxRequest.send(null); 

s.style.display = "block";
s.innerHTML = "<div class='notice'><img src='"+baseURL+"images/loading.gif'> &nbsp; creating url...</div>";

}


function focusT(textbox, default_t) {
if (textbox.value == default_t) {
textbox.value = "";
}
textbox.setAttribute("class", "url_shortner_input_sel");
textbox.className = "url_shortner_input_sel";
}
function blurT(textbox, default_t) {
if (textbox.value == "") {
textbox.value = default_t;
}
textbox.setAttribute("class", "url_shortner_input");
textbox.className = "url_shortner_input";
}