// clear text input default value onclick

function clickclear(thisfield, defaulttext) {if (thisfield.value == defaulttext) {thisfield.value = "";}}

function clickrecall(thisfield, defaulttext) {if (thisfield.value == "") {thisfield.value = defaulttext;}}

function update_recent_tags(direction){div_change("recent_rtags").innerHTML = direction;}

function save_alert_settings(){
	the_form = document.forms['alerts'];
	the_form.submit();
}

function set_vote(vote,cid){
	field_name = "vote_" + cid;
	form_name = "form_" + cid;
	if(document.forms[form_name].public_difficulty.value != "0"){
	document.forms[form_name].vote.value = vote;
	document.forms[form_name].submit();
	}
	else {
		alert("You must select a difficulty.");	
	}
}

function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET","ajax/" + url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function state_Change() {
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
    document.getElementById('right_column_tags').innerHTML=xmlhttp.responseText;
    }
  else
    {
    alert("Problem retrieving data:" + xmlhttp.statusText);
    }
  }
}

function validate_new_challenge(){
	the_form = document.forms['challenge_form'];
	send_flag = 1;
	the_msg = "You need to fix:\n\n";
	
	if(the_form.title.value == ""){
		send_flag = 0;
		the_msg = the_msg + "Title\n";	
	}
	
	if(the_form.description.value == ""){
		send_flag = 0;
		the_msg = the_msg + "Description\n";	
	}
	
	if(the_form.duration_days.value == "0" && the_form.duration_hours.value == "0"){
		send_flag = 0;
		the_msg = the_msg + "Duration\n";	
	}
	
	if(the_form.difficulty.value == "0"){
		send_flag = 0;
		the_msg = the_msg + "Difficulty\n";	
	}
	
	if(send_flag == 1){
		the_form.submit();
	}
	else {
		alert(the_msg);	
	} 	
}