//$Id: common.js 3013 2006-10-18 16:24:11Z joe $

function toggle(id)
{
	e=document.getElementById(id);
	if (e) { e.style.display=='none'?e.style.display='':e.style.display='none';}
}

function show(id)
{
  e=document.getElementById(id);
	if (e) { e.style.display = ''; }
}

function hide(id)
{
	e=document.getElementById(id);
	if (e) { e.style.display = 'none'; }
}

//AJAX CALLS
function check_username_available()
{
	var username = document.getElementById('username');
	hide('check-username');
	if (username) {
		ajaxRequest('ajax-handlers.php', 'check_username_available', username.value);
	}
}

function check_username_available_result(http)
{
	var box1, box2;

	//box1 will try to find an existing error div generated by php
	//and hide it if neccesary
	box1 = document.getElementById('ac_error_username');
	if (box1) {	hide('ac_error_username'); }
					
	//box2 will try to find the hidden div in the page change it's 
	//content and become visible
	txtDoc = http.responseText;
	box2 = document.getElementById('check-username');
	if (box2) {
		if (txtDoc == 'SUCCESS') {
			box2.innerHTML = "<div class='success'><p><b>Yes!</b> That username is available.</p></div>";
		} else {
			box2.innerHTML = "<div class='error'><p>"+txtDoc+"</p></div>";
		}
		show('check-username');
	}
}

function forgot_pass()
{
  var email = document.getElementById('email');
	hide('lp-msg');
  if (email) {
		ajaxRequest('ajax-handlers.php', 'forgot_pass', email.value);
	}
}

function forgot_pass_result(http)
{
	var box1;
	var email = document.getElementById('email');
	
	box1 = document.getElementById('lp-msg');
	txtDoc = http.responseText;
	if (box1 && email) {
		if (txtDoc== 'SUCCESS') {
			box1.innerHTML = "<div class='success'><p>An email with instructions to reset your password has been sent to "+ email.value + ".</p></div>";
		} else {
			box1.innerHTML = "<div class='error'><p>"+txtDoc+"</p></div>";
		}
		show('lp-msg');
	}
}

function confirm_delete_network()
{
	var agree = confirm("Are you sure you want to delete this network?");
	if (agree) { return true; }
	else { return false; }
}

function populate_addnetwork_box()
{
	var ip = document.getElementById('current-ip');
	if (ip) {
		ip=ip.innerHTML;
		var octets = ip.split('.');
		for (i=0 ; i<4 ; i++) {
			document.addnetwork['cidr_base_octet'+(i+1)].value=octets[i];
		}
		document.addnetwork.cidr_prefix.value = 32;
	}
}

