summaryrefslogtreecommitdiff
path: root/js/common.js
blob: 0577e944258d85ed9965afcfde3c180a15b06e70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
 * Copyright (c) 2007 Nathan Kinkade
 * 
 * This code is offered under an MIT (X11) license.  For more information
 * about the terms of this license see the file LICENSE included with this
 * software or visit: http://www.opensource.org/licenses/mit-license.php
 */

function validateNotEmpty(fields) {

	var myFields = new Array();
	myFields = fields.split(",");

	for ( idx = 0; idx < myFields.length; idx++ ) {
		var myField = getElement(myFields[idx]);
		/*
		change the bgcolor back to white just in case the this field
		was already colored and the user has since filled it in.
		*/
		myField.style.backgroundColor = "#ffffff";
		if ( empty(myField.value) ) {
			alert("Please fill in required field - highlighted in red.");
			myField.style.backgroundColor = "#efb5b5";
			myField.focus();
			return false;
		}
	}

}

function empty(field) {

	field = trim(field);
	if ( field ) {
		return false;
	} else {
		return true;
	}

}

function trim(string) {
	string = string.replace(/^\s+/, '');
	string = string.replace(/\s+$/, '');
	return string;
}

function getElement(elemid) {

		/* the former for Firefox and crew, the latter for IE */
        return (document.getElementById) ? document.getElementById(elemid) : document.all[elemid];

}

function submitForm(formid) {

	var myForm = getElement(formid);

	myForm.submit();

	return true;

}