<!--hide this script from non-javascript-enabled browsers

function formtool_count_chars(textField, countField, maxlen,show_alert) {
    if(textField != null && textField.value != null) {
	    if (textField.value.length > maxlen){
            if(show_alert)
               alert('This field cannot exceed ' +  maxlen + ' characters.');
            textField.value = textField.value.substring(0, maxlen);
	    } else {
            countField.value = maxlen - textField.value.length;
	    }
    }
}

function VF_insert_session(){ //v2.0
	var theForm = document.forms['insert_session'];
	var sFlg_f_venue_id = false;
	var errMsg = "";
	var setfocus = "";

	for(var s0=0;s0<theForm['f_venue_id'].length;s0++){if(theForm['f_venue_id'].options[s0].selected){if(theForm['f_venue_id'].options[s0].text==theForm['f_venue_id'].options[0].text)sFlg_f_venue_id=true;}}

	if (sFlg_f_venue_id){
		errMsg = "Please select a Venue";
		setfocus = "['f_venue_id']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}

function VF_insert_venue(){ //v2.0

	var theForm = document.forms['insert_venue'];
	var errMsg = "";
	var setfocus = "";

	if (theForm['f_venue_id'].value == ""){
		errMsg = "Please add the Venue ID";
		setfocus = "['f_venue_id']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}

function VF_add_user(){
	var theForm = document.forms['add_user'];
	var emailRE = /(@\w[-._\w]*\w\.\w{2,3})$/;
	var errMsg = "";
	var setfocus = "";

	if (theForm['f_phone'].value == ""){
		errMsg = "Please enter the phone";
		setfocus = "['f_phone']";
	}
	if (theForm['f_country'].value == ""){
		errMsg = "Please enter the country";
		setfocus = "['f_country']";
	}
	if (theForm['f_city'].value == ""){
		errMsg = "Please enter the city";
		setfocus = "['f_city']";
	}
	if (theForm['f_address2'].value == ""){
		errMsg = "Please enter the address 2";
		setfocus = "['f_address2']";
	}
	if (theForm['f_address1'].value == ""){
		errMsg = "Please enter the address 1";
		setfocus = "['f_address1']";
	}
	if (theForm['f_lastname'].value == ""){
		errMsg = "Please enter the last name";
		setfocus = "['f_lastname']";
	}
	if (theForm['f_firstname'].value == ""){
		errMsg = "Please enter the first name";
		setfocus = "['f_firstname']";
	}
	if (theForm['f_new_password'].value == ""){
		errMsg = "Please enter a valid password";
		setfocus = "['f_new_password']";
	}
	if (!emailRE.test(theForm['f_email'].value)){
		errMsg = "Please enter a valid email";
		setfocus = "['f_email']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}

function VF_update_user(){ 

	var theForm = document.forms['update_user'];
	var dte_f_expiry_dateRE = /^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20)\d\d$/;
	var errMsg = "";
	var setfocus = "";

	if (theForm['f_expiry_date'].value != ""){
		if (!dte_f_expiry_dateRE.test(theForm['f_expiry_date'].value)){
			errMsg = "";
			setfocus = "['f_expiry_date']";
		}
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function validateUseremail(f){
	if(!notifyUser(f.useremail, 'email')) return false;
	if(!isEmail(f.useremail, 'email')) return false;
}
function validate_article(f) {
	if(!notifyUser(f.f_author, 'name')) return false;
	if(!notifyUser(f.f_email, 'email')) return false;
	if(!isEmail(f.f_email, 'email')) return false;
}

function validate_edit_employee(f){
	if(!notifyUser(f.f_last_name, 'Last Name')) return false;
	if(!notifyUser(f.f_rescare_id, 'Rescare ID')) return false;
}

function validate_edit_user(f){
	if(!notifyUser(f.f_pass, 'password')) return false;
}

function notifyUser(ctl, msg){
	if(ctl.value == '')	{
	    alert('Please enter a valid ' + msg + '.');
        status='Please enter a valid ' + msg + '.';
        document.MM_returnValue = true;
	    ctl.select();
	    return false;
    }
    return true;
}

			
var MAXDESCLENGTH = 8;
function checkPword(theField) {
	if (theField.value.length<MAXDESCLENGTH)
		alert("Sorry, this password must be "+MAXDESCLENGTH+" characters or more.  Please re-enter.");
	else if (document.theForm.f_password_v.value != document.theForm.f_password.value) 
			if(document.theForm.f_password_v.value != "")
			alert("The password differs from the password validation.  Please re-enter.");
}

var reEmail = /^.+\@.+\..+$/
function isEmail(ctl)
{   
    if(!reEmail.test(ctl.value) || ctl.value == '')
    {
        alert('Please enter a valid email address. \n\nFor example: someone@somewhere.co.nz');
        status='Please enter a valid email address.';
        document.MM_returnValue = true;
        ctl.select();
        return false;
    }
    return true;
}

var reDate = new RegExp("[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]");
function isDate(ctl)
{   
    if(!reDate.test(ctl.value) )
    {
        alert('Please enter a valid date. \n\nUse format: DD/MM/YYYY or 23/11/2003');
        status='Please enter a valid date.';
        document.MM_returnValue = true;
        ctl.select();
        return false;
    }
    return true;
}
function printWindow(){
browserVersion = parseInt(navigator.appVersion)
if (browserVersion >= 4) window.print()
}


function MM_jumpMenu(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function confirmDelete(URL) {
	if ( confirm("Are you sure you want to delete this record ?") ) {
		document.location=URL;
	}
}
function jumper(selectList) {
	urlAppend = selectList.options[selectList.selectedIndex].value;
	selectList.form.reset();
	document.location = urlAppend;
}
function deciCorr(value) {
	if (value<=0.99) {
		newDoll = '0';
	} else {
		newDoll = parseInt(value);
	}
	newCents = parseInt((value+.0008 - newDoll)* 100);
	if (eval(newCents) <= 9) newCents='0'+newCents;
	newString = newDoll + '.' + newCents;
	return (newString);
}

function changeSQL(table) {
	document.export_form.filename.value = table+".txt";
	document.export_form.sql.value = "select * from "+table;
}

function moregroup() 
{popup = window.open("groups.htm","POPUP", "status=no,toolbar=no,location=no,scrollbars=yes,width=600,height=400");
}	


var MAXACTIVITIES = 6;
var activityCount = 6;
function activityClick(theCheck) {
	if (theCheck.checked) {
		activityCount++;
		if (activityCount>MAXACTIVITIES) {
			theCheck.checked = false;
			activityCount--;
			alert("Sorry, you may only select a maximum of "+MAXACTIVITIES+" .");
		}
	}
	else
		activityCount--;
}

var MAXACTIVITIES = 6;
var featureCount = 2;
function featureClick(theCheck) {
	if (theCheck.checked) {
		featureCount++;
		if (featureCount>MAXACTIVITIES) {
			theCheck.checked = false;
			featureCount--;
			alert("Sorry, you may only select a maximum of "+MAXACTIVITIES+" .");
		}
	}
	else
		featureCount--;
}

var MAXDESCLENGTH = 250;
function checkCharSize(theField) {
	if (theField.value.length>MAXDESCLENGTH) {
		alert("Sorry, this description cannot be more than "+MAXDESCLENGTH+" characters (about 35 words).  Please reduce it's size.");
	}
}


var MAXLARGELENGTH = 560;
function checkLargeSize(theField) {
	if (theField.value.length>MAXLARGELENGTH) {
		alert("Sorry, this description cannot be more than "+MAXLARGELENGTH+" characters (about 60 words).  Please reduce the size.");
	}
}

function doSubmit() {	//tuncates fields
	if (document.op_form.when_started.value.length>MAXDESCLENGTH)
		document.op_form.when_started.value = (document.op_form.when_started.value).substring(0, MAXDESCLENGTH);
	if (document.op_form.what_inspires.value.length>MAXDESCLENGTH)
		document.op_form.what_inspires.value = (document.op_form.what_inspires.value).substring(0, MAXDESCLENGTH);
	if (document.op_form.meetings.value.length>MAXDESCLENGTH)
		document.op_form.meetings.value = (document.op_form.meetings.value).substring(0, MAXDESCLENGTH);
	if (document.op_form.fchurch_idea.value.length>MAXDESCLENGTH)
		document.op_form.fchurch_idea.value = (document.op_form.fchurch_idea.value).substring(0, MAXDESCLENGTH);
	if (document.op_form.others_descript.value.length>MAXDESCLENGTH)
		document.op_form.others_descript.value = (document.op_form.others_descript.value).substring(0, MAXDESCLENGTH);
	document.op_form.submit();
}

// stop hiding -->
