
var docwin;

var countEl, delayEl;
var cdInt, cdTOut;
var currentCount;


function addDoc() {
	if (f.id.value == 'new') {
		alert('Please save the case before adding a document.')
		return false;
	}
	var url = '_adddoc.html?' + getqs('id,label');
	url += '&linktext=' + urlencode(getSelText(txtEl));
	
	docwin = window.open(url, 'docwin', 'width=590,height=520,resizable=yes,scrollbars=yes,location=no,toolbar=no');
	if (docwin.opener == null) 
		docwin.opener = window;
	docwin.opener.name = 'opener';
	docwin.focus();
	
	return false;
}


function formInit() {
	return true;
}


function initExtra() {
	delayEl = document.getElementById('delayDiv');
	if (delayEl != null) {
		delayEl.style.visibility = 'hidden';
		showIn(10);
	} else {
		hiFirst();
	}
}


function validate() {
	if (f.pw.value.length < 4) {
		alert('Please enter a password, minimum 4 characters');
		f.pw.focus();
		return false;
	} else {
		return true;
	}
}

/*
function hiFirst() {
	if (f == null) return;
	
	for (var i = 0;  (e = f.elements[i]);  i++) {
		if ((e.type == 'text' || e.type == 'password' || e.type == 'textarea') && e.value == '') {
			e.focus();
			break;
		}
	}
}
*/

function showIn(secs) {
	currentCount = secs;
	
	countEl = document.getElementById('countDiv');
	countEl.style.visibility = 'visible';
	countEl.innerHTML = currentCount;
	
	cdInt   = setInterval(countDown, 1000);
	cdTOut  = setTimeout(showNow, secs * 1000);
}

function showNow() {
	countEl.style.visibility = 'hidden';
	delayEl.style.visibility = 'visible';
	cancelCount();
	hiFirst();
}


function countDown() {
	currentCount--;
	countEl.innerHTML = currentCount;
	if (currentCount <= 0) 
		clearInterval(cdInt);
}

function cancelCount() {
	clearInterval(cdInt);
	clearTimeout(cdTOut);
	return false;
}


