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

function CheckPType(obj, form){
	form.elements['msg_delete[]'][0].checked = false;
}

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

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

function externalLinks() {
	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";
	}
}

/***********************************************
* 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, "")
}