function clearMe(thefield){
	if (thefield.defaultValue==thefield.value) {
		thefield.value = "";
	}
} 

function pop(ShowPage, intwidth, intheight) {

	var leftpos = (screen.width - intwidth) / 2;
	var toppos = (screen.height - intheight) / 2;
	var winprops = 'toolbar=0, scrollbars=1, location=0, statusbars=0, menubar=0, width=' + intwidth + ', height=' + intheight + ', left=' + leftpos + ', top=' + toppos + ', resizable=1';
    var popupwindow = window.open(ShowPage, 'poppage', winprops);

}

// toggle visibility

function toggle(targetID) {
	if (document.getElementById) {
		target = document.getElementById(targetID);
		if (target.style.display == "none") {
			target.style.display = "";
		} else {
			target.style.display = "none";
		}
	}
}

function toggleItem(targetID, target2ID) {
	if (document.getElementById) {
		target = document.getElementById(targetID);
		target2 = document.getElementById(target2ID);
		if (target.style.display == "none") {
			target.style.display = "";
			target2.style.backgroundImage = "url('../../images/triangle-open.gif')";
		} else {
			target.style.display = "none";
			target2.style.backgroundImage = "url('../../images/triangle-close.gif')";
		}
	}
}

function newImage(arg) {	
	if (document.images) {		
		rslt = new Image();		
		rslt.src = arg;		
		return rslt;	
	}
}

function changeImages() {	
	if (document.images && (preloadFlag == true)) {		
		for (var i=0; i<changeImages.arguments.length; i+=2) {			
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];		
		}	
	}
}
	
function goJump(which_form) {
	self.location.href=which_form.jump.options[which_form.jump.selectedIndex].value;
}

function selectJump(formname, listname) {
	var sel = document.forms[formname].elements[listname];
	var foo = sel.options[sel.selectedIndex].value;
	self.location.href=foo;
}

/*
form validation functions 
combine function calls in an onsubmit handler on the form tag
e.g.  onSubmit="return (validateList(this.contact, 'Please select a contact') && validateString(this.firstname, 'Please provide a surname', 1, 200))"
*/

function validateNumber(field, msg, min, max) {
	if (!min) { min = 0 }
	if (!max) { max = 255 }
	if ( (parseInt(field.value) != field.value) || field.value.length < min || field.value.length > max) {
		alert(msg);
		field.focus();
		field.select();
		return false;
	}
	return true;
}

function validateCheckbox(boxname, msg) {

	foo = boxname.checked;
	
	if (foo) {
		return true;
	} else {
		alert(msg);
		return false;
	}
	
}

function validateString(field, msg, min, max) {
	if (!min) { min = 1 }
	if (!max) { max = 65535 }
	if (!field.value || field.value.length < min || field.value.max > max) {
		alert(msg);
		field.focus();
		field.select();
		return false;
	}
	return true;
}

function validateEmail(email, msg, optional) {
	if (!email.value && optional) {
		return true;
	}

	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	
	if (!re_mail.test(email.value)) {
		alert(msg);
		email.focus();
		email.select();
		return false;
	}
	return true;
}

function validateList(listname, msg) {

	var foo = listname.selectedIndex;

	if (foo == 0 || foo == -1) {
		alert(msg);
		return false;
	}
	
	return true;
	
}