//mail formatiing function

function mf(user,isp) {
	var text = '<a href="mailto:' + user + '@' + isp + '">';
        text += '<IMG SRC="/images/mailto.gif" ALT="' + user + '@' + isp + '">';
	document.write(text);
}

function mlFormat(user,isp) {
	var text = '<a href="mailto:' + user + '@' + isp + '">';
	document.write(text);
}
//------------------------->

function footer(created,updated) {

	document.write('<FONT size=1>' );
	//document.write('<HR align="center" width="90%" size="2">' );
	document.write('<P align="center">All material on this WEB site is for personal use only. No ' );
	document.write('commercial use of the material is permitted.<BR>' );
	document.write('This page created: ' + created + '. Last updated ' + updated + '.' );
	document.write('<ADDRESS>' );
	document.write('<P align="center">Brian Fisk ' );
	mf("brian","fiskfamily.org.uk");
	document.write('</A>' );
	document.write('</ADDRESS>' );
	document.write('</FONT>' );
	//document.write('<HR align="center" width="90%" size="3">' );
	//document.write('<a href="/index.htm">home page</a>' );
}


function aSubmitEventHandler(form) {
	alert("amanda");
}

//-----------------utility functions -------------------------------

function mailFormat(user,isp) {
	var text = '<a href="mailto:' + user + '@' + isp + '">';
	document.write(text);
}

//-----------------functions from updateEntry.php---------------------

function ueUpdateSurname(id_surname,id_submitter) {
	this.document.surnameForm.action = "updateEntry.php?id=" + id_surname + "&replace=true&surname=true";
	this.document.surnameForm.action += "&id_submitter=" + id_submitter;
    this.document.surnameForm.submit();
}

function ueUpdateSubmitter(id) {
	this.document.submitterForm.action = "updateEntry.php?id=" + id + "&replace=true&submitter=true";
    this.document.submitterForm.submit();
}

function ueDuplicate(id_source,id_submitter) {
	var s = "updateEntry.php?source=" + id_source + "&submitter=";
	s += id_submitter + "&duplicate=true";
	this.document.surnameForm.action = s;
	this.document.surnameForm.submit();
}

function ueBackButtonPress(form,name) {
	form.action = "searchName.php?arg=" + name ;
	form.submit();
}

function ueSubmitButtonPress(form,id) {
	form.action = "updateEntry.php?id=" + id + "&replace=1" ;
	form.submit();
}

// functions used by searchName.php

function deleteButtonPress(id) {
        this.document.myform.action = "deleteEntry.php?id=" + id;
        this.document.myform.submit();
}

function deleteUserButton(id) {
        this.document.myform.action = "deleteUser.php?id=" + id;
        this.document.myform.submit();
}

function updateButtonPress(id) {
        this.document.myform.action = "updateEntry.php?id=" + id;
        this.document.myform.submit();
}

function tsUpdateButtonPress(id) {
	document.myform.action = "..\/viewUser.php?id=" + id;
	this.document.myform.submit();
}

function testButtonPress(id) {
	this.document.myform.action = "testEntry.php?id=" + id + "&submitter=true";
	this.document.myform.submit();
}

function convButtonPress(id) {
        this.document.myform.action = "convEntry.php?id=" + id;
        this.document.myform.submit();
}

function get_radio_value(form){
    //this function polls the radio buttons to see which one is checked
    var rad_val = "?";

    for (var i=0; i < form.rmode.length; i++) {
        if (form.rmode[i].checked) {
            rad_val = form.rmode[i].value;
        }
    }
    //alert( rad_val );
    return rad_val;

}

function submitIt(form) {
    // this function acts on the form submit button
    form.action = "searchName.php?arg=" + form.property.value + "\&mode=" + get_radio_value(form);
    return true;
}

//-----------------functions from searchX.php---------------------

function sx_get_radio_value(form){
    //this function polls the radio buttons to see which one is checked
    var rad_val = "?";

    for (var i=0; i < form.rmode.length; i++) {
        if (form.rmode[i].checked) {
            rad_val = form.rmode[i].value;
        }
    }
    //alert( rad_val );
    return rad_val;

}

function sxSubmit(form) {
    // this function acts on the form submit button
    form.action = "searchX.php?arg=" + form.property.value + "\&mode=" + sx_get_radio_value(form);
    return true;
}


//-----------------functions from listID.php---------------------

function liSubmit(form,url) {
    // this function acts on the form submit button
	txt = "range: " + "il=" + form.lower.value + "ir=" + form.range.value;
	//alert(txt);
	form.action = url + "?il=" + form.lower.value + "&ir=" + form.range.value
		+ "\&mode=" + get_radio_value(form);
	return true;
}

function liNext(il,ir) {
    // display next ir entries
    this.document.myform.action = "listID.php?il=" + il + "&ir=" + ir;
    this.document.myform.submit();
}

function liPrevious(il,ir) {
    // display previous ir entries
    this.document.myform.action = "listID.php?il=" + il + "&ir=" + ir;
    this.document.myform.submit();
}

function liDelete(id) {
        this.document.myform.action = "deleteEntry.php?id=" + id;
        this.document.myform.submit();
}

function liUpdate(id) {
        this.document.myform.action = "updateEntry.php?id=" + id;
        this.document.myform.submit();
}

//-----------------functions from dbUpdate.php---------------------

function dbuBackButtonPress(form) {
	form.action = "newSurname.php";
	form.submit();
}

//-----------------functions from newSurname.php---------------------

function nsGetParish(form) {
	return form.Parish.options[form.Parish.selectedIndex].value;
}

function nsAddParish(form) {
	text = form.Place.value;
	if (text != "") text += " | ";
    text += nsGetParish(form);
    form.Place.value = text;
    form.Places.value = text;
}

function nsResetField(form) {
	form.Place.value = "";
	form.Places.value = "";
	form.Parish.selectedIndex=0;
}

function nsValidateIt(form) {

	var ok = true, text = "";

	if (form.Surname.value == "") {
    	text += "Please fill in surname before submitting this page.\n";
    	ok = false;
    }

    if (form.Period1.value == "CHOOSE") {
    	text += "Please fill in period before submitting this page.\n";
        ok = false;
    }

	if (form.Period1.value == "ALL") {
    	form.Period1.value = "1500";
    	form.Period2.value = "date";
    }

    if (form.Places.value == "") {
        text += "Please fill in parish(es) before submitting this page.\n";
        ok = false;
    }

    if (!ok) {
        form.errortext.value = text;
    	//form.errors.value = text;
        //form.errors.disabled = 0;
        alert("One or more errors have been detected.  Please correct before submitting page\n" + text);
    }

    return ok;
}

function nsSubmitButtonPress(form) {
    ok = nsValidateIt(form);
    //the following only seems to work if placed here!
    if (ok) {
        form.action = "newSurname.php?action=review";
    } else {
        form.action = "newSurname.php?action=revise";
    }
    form.submit();
}

function nsClearButtonPress(form) {
	form.reset();
}

function nsReviseButtonPress(form) {
	form.action = "newSurname.php?action=revise";
	form.submit();
}

function nsAddButtonPress(form) {
	form.action = "dbupdate.php";
	form.submit();
}

function func( field ) {
 	for ( i = 0; i < field.length; i++ ) field[i].checked = true ;
}

function dsuDeleteButtonPress(form) {
	form.action = "displaySubmitters.php?action=delete";
	form.submit();
}

function senActionButtonPress(form,arg,mode) {
	var s = "searchName.php?action=test&arg=" + arg + "&mode=" + mode;
	//alert( s );
	form.action = s;
	form.submit();
}

//-----------------functions from queryHugh.php---------------------

function qhOnSubmitEventHandler(form) {
	var s = "queryHugh.php?name=" + form.namex.value;
	s += "&father=" + form.father.value;
	s += "&spouse=" + form.spouse.value;
	s += "&bornin=" + form.bornin.value;
	s += "&bdates=" + form.bdates.value;
	s += "&bdatee=" + form.bdatee.value;
	alert( s );
	form.action = s;
}

//-----------------functions from searchEmail.php---------------------

function seOnSubmitEventHandler(form) {
	var s = "searchemail.php?arg=" + form.emailAddr.value;
	//alert(s);
	form.action = s;
	return true;
}

function seEmailButtonPress(f) {
	var ok = 0;
	var s = "testing(" + f.length + "):";
	for (var i=0;i<f.length;i++) {
		var e = f.elements[i];
		if ((e.type == "checkbox") && (e.checked)) {
			ok = 1;
		}
	}
	if (ok > 0) {
		s += "button checked";
	} else {
		s += "no button checked";
	}
	alert(s);
}


function tsCbPress(id,object) {
	var s = "id=" + id;
	s += "\nname=" + object.name;
	s += "\nchecked=" + object.checked;
	s += "\nvalue=" + object.value;
	s += "\ntype=" + object.type;
	//alert(s);
}



//action for the Change E-mail button
//  causes the e-mail address from the current line to be copied
//  to the old-email address input field

function seButtonPress(email) {
        this.document.myform.action = "searchemail.php?arg=" + email;
        this.document.myform.submit();
}

//action for the REPLACE button
//  this causes an SQL query to update the e-mail addresses

function seNewButtonPress(form) {
        // replace email address
	var new_addr = form.newEmailAddr.value;
	var old_addr = form.oldEmailAddr.value
        form.action = "searchemail.php?replace=email&arg=" + old_addr + "&new_addr=" + new_addr;
        form.submit();
}


//-----------------functions from viewUser.php---------------------

function vuOnSubmitEventHandler(form) {
	form.action = "viewUser.php?arg=" + form.emailAddr.value;
}

function vuSelectButtonPress(form,id) {
	form.action = "viewUser.php?id=" + id;
	form.submit();
}

function vuValidatePassword(form) {
	alert(form.password.value);
	//no need for action as form will be redisplayed with current arguments
	return true;
}

function vuModifyUser(form,id) {
	//alert(form.name.value);
	form.action = "viewUser.php?id=" + id;
	form.action += "&update=true"
	return true;
}

function vuEmailButtonPress(form, id) {
	form.action = "emailPassword.php?id=" + id;
	form.submit();
}

function vuRequestButtonPress(form, id) {
	form.action = "requestEmail.php?id=" + id;
	form.submit();
}

function vuAddButtonPress(form, id) {
	form.action = "newSurname.php?id=" + id;
	form.submit();
}

function reModifyMail(form,id) {
	//alert(form.new_email.value);
	form.mode.value = "2";
	//no need for action as form will be redisplayed with current arguments
	return true;
}

function ceModifyMail(form) {
	//alert(form.new_email.value);
	form.mode.value = "2";
	//no need for action as form will be redisplayed with current arguments
	return true;
}


function epReturnButtonPress(form, id) {
	form.action = "viewUser.php?id=" + id;
	form.submit();
}

//-----------------functions from deleteEntry.php---------------------

function duDeleteButton(form,id) {
	//alert( id );
	form.action = "deleteUser.php?id=" + id + "&confirm=yes";
	form.submit();
}

function eusConfirmButton(form,ids) {
	alert( ids );
	form.action = "email.php?ids=" + ids + "&confirm=yes";
	form.submit();
}

//-----------------functions from newEntries.php---------------------


function neNextButton(form) {
	form.action = "newSurname.php";
	form.submit();
}

function neCorrectButton(form) {
	form.action = "newEntries.php";
	form.submit();
}

//generic functions to select everything or nothing in a form

function AllButton(f) {
	//alert("All");
	for (var i=0;i<f.length;i++) {
		var e = f.elements[i];
		if (e.type == "checkbox") {
			e.checked = true;
		}
	}
}

function NoneButton(f) {
	for (var i=0;i<f.length;i++) {
		var e = f.elements[i];
		if (e.type == "checkbox") {
			e.checked = false;
		}
	}
}






