/***********************************************
* select all / select none 
***********************************************/

function checkonoff(form , el){
	if (form.elements[el][0].checked){
	   for(i=1; i < form.elements[el].length; i++) {
		  form.elements[el][i].checked = true;
	   }
	} else {
	   for(i=1; i < form.elements[el].length; i++) {
		  form.elements[el][i].checked = false;
	   }
	}
}

/***********************************************
* external links
***********************************************/

function external_links() {
	if (!document.getElementsByTagName) return
	var anchors = document.getElementsByTagName("a")
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i]
		if( anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" ) anchor.target = "_blank"
	}
}

/***********************************************
* div show/hide
***********************************************/

function div_toggle(id) {

    if (document.getElementById(id).style.display == 'block') { document.getElementById(id).style.display = 'none' } 
    else { document.getElementById(id).style.display = 'block' }

}

/***********************************************
* email_mangler
***********************************************/

function email_mangler( _b , _a, img ) {

    var _l   = _a + '@' + _b
    
    document.write( "<a href='mailto:" + _l + "'>" + _l + "</a>" )
    return;

}

/***********************************************
* auto tab
***********************************************/


var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
		found = true;
	else
		index++;
	return found;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
	}
	return true;
}

/***********************************************
* validate input
***********************************************/

function valid(f) {
	var re = /^[0-9]*$/;
	if (!re.test(f.value)) {
		alert("Numeric values only, please");
		f.value = f.value.replace(/[^0-9]/g,"0");
	}
}

/***********************************************
* pop up
***********************************************/

function popUp( url , width, height) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = 20,top = 20');");
}

/***********************************************
* bookmark
***********************************************/

function bookmark(title, url){
	if (document.all) window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
}

