var url = "/register/check/";

function updateName(which) {
  document.getElementById('un').innerHTML = "Checking...";
  //var name = document.getElementById("r_username").value;
  var name = which.value;
  http.open("GET", url + escape(name), true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function handleHttpResponse() {
  if (http.readyState == 4) {
    results = http.responseText;
    var name = document.getElementById("username").value;
    if(results == "") results = "<font color=\"green\">Available!</font>";
    document.getElementById('un').innerHTML = results;
  }
}

function getHTTPObject() {
  	var xmlhttp;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
var http = getHTTPObject();

function handleInitialPageDraw() {
	if (document.getElementById("username").value != "") {
		updateName(); 
	}
}

function changeDiv(the_div,the_change)
{
  var the_style = getStyleObject(the_div);
  if (the_style != false)
  {
    the_style.display = the_change;
  }
}

function hideAll()
{
  changeDiv("cat_questions","none");
  changeDiv("dog_questions","none");
  changeDiv("bird_questions","none");
}

function getStyleObject(objectId) {
  if (document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
    return document.all(objectId).style;
  } else {
    return false;
  }
}


function resubmitSearchAll(mode, searchStr) {
	//f = document.getElementById("searchForm");
	f = document.forms["searchForm"];
	//f.elements["findall"].value = "true";
	f.elements["type"].selectedIndex = mode; // 0 = Song, 1 = Band
	f.elements["q"].value = searchStr;
	f.submit();
}

function goURL(url) {
	window.location = url;
}

function goNewWin(url) {
	window.open(url);	
}

function popup(width, height, url) {
	var win = window.open(url,url,"menubar=no,width=" + width + ",height=" + height + ",toolbar=no,location=no,menubar=no,scrollbars=yes,status=no,resizable=yes,directories=no");
	win.focus();
}

function show_loading() {
	
	var div_loading = document.getElementById("loading_overlay");
	//document.body.style.overflow = "hidden";
	div_loading.style.height = document.body.offsetHeight + "px";
	div_loading.style.display = "block";
	
	try {
		tb_remove(); //close popup if it's there.
	}catch (e) { null; }
	
}

function hide_loading() {
	
	var loading_div = document.getElementById("loading_overlay");
	if(loading_div != null) loading_div.style.display = "none";	
	//document.body.style.overflow = "auto";
	
}

function showRefer() {

	document.getElementById("ReferLink").style.display = "none";
	animatedcollapse.toggle('PageReferLink');

}

function hideRefer() {
	document.getElementById("ReferLink").style.display = "block";
	animatedcollapse.toggle('PageReferLink');
}