/* ############################### COPYRIGHT NOTICE BEGINS #############################
@ Copyright 2008 - 2009: WP Realty Team - Chad Broussard and Jared Ritchey
@ Copyright 2008: Greg Burghardt
@ Copyright URL: http://www.wprealty.org and http://fundamentaldisaster.blogspot.com/
@ Published by: Chad Broussard and Jared Ritchey
@ Scripting: In part by http://fundamentaldisaster.blogspot.com/ and Jared Ritchey Design
@ License: GNU / GPL
@ File Name: searchforms.js
############################### COPYRIGHT NOTICE ENDS ############################# */
/*
@ DISCLAIMER AND USAGE AND LICENSE:
You are free to use this script for whatever reason you so desire providing you leave the copyright details above in 
tact as required and you do not redistribute this code rebranded as your own work. You are free to include this 
code in any commercial or non-commercial application without further permission or obligation from EZProRealty or 
Chad Broussard. You may NOT republish this code absent of this copyright notice. LICENSED AS GNU/GPL Open Source 
with provisions.

@ PURPOSE OF THE SCRIPT:
This script was written to help in the reduction of processing burdens placed on servers for large search forms
that use the GET method for form processing.  It was designed in part to reduce the SQL search timeout issue 
common in Real Estate MLS Search forms that rely on the "GET" method to reduce the number of fields passed in the 
query string. If a search form field contains a NULL or no value it will not be passed on to the GET string.

@ CONFIGURATION OF THE SCRIPT:
To use this script a variable or perminant addition to the body tag is required as follows; 
EXAMPLE: <body onload="enableEmptyFields(document.choose);">
You must also add an onSubmit event handler (property) belonging to a Form object as follows:
EXAMPLE: <form action="the-name-of-your-script.php" method="get" onsubmit="disableEmptyFields(this);" name="choose">
############################### COPYRIGHT NOTICE ENDS ############################# */
function enableEmptyFields(wprform) {
var i = 0;
var field;
var j = 0;
var opt;
while (field = wprform.elements[i++]) {
	switch (field.nodeName) {
		case "input":
		switch (field.type) {
			case "checkbox":
			case "radio":
			field.disabled = !field.checked;
			break;
			default:
			field.disabled = false;
			break;
		}
		break;
		case "select":
		if (field.multiple) {
		j = 0;
			while (opt = field.options[j++]) {
			opt.disabled = !opt.selected;
			}
		} else {
			field.disabled = false;
		}
		break;
		default:
		field.disabled = false;
		break;
		}
	}
}
function disableEmptyFields(wprform) {
	var i = 0;
	var field;
	var j = 0;
	var opt;
  
while (field = wprform.elements[i++]) {
	switch (field.nodeName) {
	case "input":
		switch (field.type) {
			case "checkbox":
			case "radio":
            field.disabled = !field.checked;
            break;
			default:
            field.disabled = (field.value.length > 0) ? false : true;
			break;
		}
		break;
		case "select":
        if (field.multiple) {
			j = 0;
			while (opt = field.options[j++]) {
			opt.disabled = !opt.selected;
			}
		} else {
			field.disabled = (field.value.length > 0) ? false : true;
		}
		break;
		default:
		field.disabled = (field.value.length > 0) ? false : true;
		break;
		}
	}
}