//---------------------------------------------------------------------------/*	Title: Default Form Texts	Author: Joshua Shelfer	Last Modified: 3/22/07		Description: Loads default text for form text boxes when loading the page,		clears the text on focus, and restores the text on blur if the text is		empty. Also, clears the text boxes that contain default values when		validating and restores them if validation fails.		Notes: As written, this only works with one form per page, and there must		be a separate copy of this file for each page that uses this file.		Implementation:		1. Complete the TODO items in the following section.		2. Execute defaulttext() onload.		3. Implement a JavaScript validation function with this signature:				function ValidateFormId(FormHandle)		   Replace "FormId" with the id of your form tag and "FormHandle" with		   the handle of your form. The validation function should return the		   form field that fails validation or return null if validation succeeds.		4. Include the following in the form tag to validate the form:				onsubmit="return SubmitForm()"		5. Include the following in each text box tag of the form, replacing 0		   with the field number that corresponds to the text box:				onfocus="ClearText(0)"				onblur="FillText(0)"*///---------------------------------------------------------------------------// COMPLETE THE FOLLOWING "TODO" ITEMSvar form;var Field = new Array();var textField = new Array();var count;// TODO: Substitute "MyForm" with your form idvar formId = "StudentApplicationForm";// TODO: Substitute "Default Text 0" etc. with your default textstextField[0] = "Enter your name";textField[1] = "##########";textField[2] = "Enter your major";textField[3] = "Enter your mailing address";textField[4] = "Enter your city";textField[5] = "#####";textField[6] = "(###) ###-####";textField[7] = "(###) ###-####";textField[8] = "Enter your career goal";textField[9] = "###";textField[10] = "Enter your email address";// ...// Fill all text boxes with default text. Filling them on load saves those// with JavaScript disabled from having to empty the text boxes.function defaulttext() {	form = document.getElementById(formId);		// TODO: Substitute "MyField0" etc. with your field ids	Field[0] = form.Name;	Field[1] = form.StudentID;	Field[2] = form.Major;	Field[3] = form.Address;	Field[4] = form.City;	Field[5] = form.Zip;	Field[6] = form.HomePhone;	Field[7] = form.CellPhone;	Field[8] = form.CareerGoal;	Field[9] = form.Age;	Field[10] = form.Email;	// ...		count = Field.length;	ResetTexts();}// DO NOT EDIT ANYTHING BEYOND THIS POINT//---------------------------------------------------------------------------// Reset form fieldsfunction ResetTexts() {	for(var i = 0; i < count; i++) {		Field[i].value = textField[i];	}}//---------------------------------------------------------------------------// Clear text box of index "item".function ClearText(item) {	if(Field[item].value == textField[item]) {		Field[item].value = "";	}}//---------------------------------------------------------------------------// Fill text box of index "item" with default text of index "item".function FillText(item) {	if(Field[item].value == "") {		Field[item].value = textField[item];	}}//---------------------------------------------------------------------------// Clear text boxes that still have default text in them so validation will work.function ClearDefaultTexts() {	for(var i = 0; i < count; i++) {		if(Field[i].value == textField[i]) Field[i].value = "";	}}//---------------------------------------------------------------------------// If/when validation fails, fill the empty text boxes with default text.function FillEmptyTexts() {	for(var i = 0; i < count; i++) {		if(Field[i].value == "") Field[i].value = textField[i];	}}//---------------------------------------------------------------------------// Clear default texts, validate the form, and if the validation fails then// fill the empty texts with default texts.function SubmitForm() {	var result = true;	var badItem;		ClearDefaultTexts();	// example: badItem = ValidateMyForm(form);	badItem = eval("Validate" + formId)(form);	// If an item does not pass validation then fill empty texts with default	// texts, give the item focus, and clear the text in the item.	if(badItem != null) {		FillEmptyTexts();		badItem.focus();		if(badItem.type == "text" || badItem.type == "textarea") badItem.value = "";		result = false;	}	return result;}//---------------------------------------------------------------------------