var rewrite_prefix;
var do_rewrite  = 0;
var form_ids_ar = new Array();

function modRewriteSearch(p_id_ar, p_search_id, p_spec_ar)
{
    var i, k, x, max_k, fnd, reg_exp;
    var url         = 'dosearch';
    var ignore_ar   = new Array('', '-1', null);    
    
    for (i = 0; i < p_id_ar.length; i++) {
        x   = document.getElementById(p_id_ar[i]);
        
        if (p_spec_ar != null) {
            fnd = false;
            for (k =0, max_k = p_spec_ar.length; (k < max_k) && (!fnd); k++) {
                rx      = '^' + p_spec_ar[k] + '[0-9]+$';
                reg_exp = new RegExp(rx, '');
                if (reg_exp.exec(p_id_ar[i])) {
                    fnd         = true;
                    p_id_ar[i]  = p_spec_ar[k] + '[]';
                } //end if
            } //end for
        } //end if
        
        if (x != null) {                                    
            if (x.options) {                
                val = x.options[x.selectedIndex].value;
                fnd = false;
                for (k =0, max_k = ignore_ar.length; (k < max_k) && (!fnd); k++) {
                    if (val == ignore_ar[k]) {
                        fnd = true;
                    } //end if
                } //end for
                if (!fnd) {
                    url = url + '/' + p_id_ar[i] + '/' + x.options[x.selectedIndex].value;
                } //end if
            } else if (x.checked) {                
                url = url + '/' + p_id_ar[i] + '/' + x.value;
            } else if (x.value && (x.type == "text")) {                
                if (x.value != '') {
                    url = url + '/' + p_id_ar[i] + '/' + x.value;
                } //end if
            } //end if
        } //end if
    } //end for
    
    url = rewrite_prefix.toString() + url + '/s/' + p_search_id + '/st/' + p_search_id + '/index.html';
    
    return url;
} //end function modRwriteSearch

function ValidateForm1(thisForm)
{	
	if (!hasValue(thisForm.state_code, "SELECT")) {
		if  (!onError(thisForm.state_code, "You must select a state.")) {
			return false;
		} //end if
	} //end if
                 
    if (do_rewrite == 1) {
        document.location = modRewriteSearch(new Array('state_code', 'city', 'property_type'), 1);
	    return false;
    } else {
        return true;
    } //end if
} //end function ValidateForm1

function ValidateForm2(thisForm)
{	
    /*	
    if (!hasValue(thisForm.state_code, "SELECT" )) {
		if  (!onError(thisForm.state_code, "You must select a state.")) {
			return false;
		} //end if
	} //end if
    */
    
	if (!hasValue(thisForm.zip, "TEXT" )) {
		if (!onError(thisForm.zip, "Please enter a ZIP code.")) {
			return false;
		} //end if
	} //end if

	if (!checkzip(thisForm.zip.value)) {
		if (!onError(thisForm.zip, "Please enter a valid ZIP code.")) {
			return false;
		} //end if
	} //end if
	
    if (do_rewrite == 1) {
	    document.location = modRewriteSearch(new Array('zip'), 2);
	    return false;
    } else {
        return true;
    } //end if
} //end function ValidateForm2

function ValidateForm5(thisForm)
{	
    if (!hasValue(thisForm.city, "TEXT" )) {
		if (!onError(thisForm.city, "You must enter a value for city name.")) {
			return false;
		} //end if
	} //end if
	
	if (do_rewrite == 1) {	    
	    document.location = modRewriteSearch(new Array('city'), 5);
	    return false;
    } else {
        return true;
    } //end if
} //end function ValidateForm5

function ValidateForm6(thisForm)
{	
	if (!hasValue(thisForm.zip, "TEXT" )) {
		if (!onError(thisForm.zip, "Please enter a ZIP code.")) {
			return false;
		} //end if
	} //end if

	if (!checkzip(thisForm.zip.value)) {
		if (!onError(thisForm.zip, "Please enter a valid ZIP code.")) {
			return false;
		} //end if
	} //end if
	
	if (do_rewrite == 1) {
	    document.location = modRewriteSearch(new Array('zip'), 6);
	    return false;
    } else {
        return true;
    } //end if	
} //end function ValidateForm6

function ValidateForm3(thisForm)
{	
	if (!checkinteger(thisForm.listing_number.value)) {
		if (!onError(thisForm.listing_number, "Please enter a valid listing number (8 digits ).")) {
			return false;
		} //end if
	} //end if
	
	if (!numberrange(thisForm.listing_number.value, 1, 99999999)) {
		if (!onError(thisForm.listing_number, "Please enter a valid listing number (8 digits ).")) {
			return false;
		} //end if
	} //end if
	
    if (do_rewrite == 1) {
	    document.location = modRewriteSearch(new Array('listing_number'), 3);
	    return false;
    } else {
        return true;
    } //end if
} //end function function ValidateForm3

function ValidateForm4(thisForm)
{	
	if  (hasValue(thisForm.zip, "TEXT" )) {
		if (!checkzip(thisForm.zip.value)) {
		    if (!onError(thisForm.zip, "Please enter a valid ZIP code.")) {
				return false;
			} //end if
		} else {
            return true;
        } //end if
	} //end if


	if (!hasValue(thisForm.state_code, "SELECT" )) {
		if (!onError(thisForm.state_code, "You must select a state.")) {
			return false;
		} //end if
	} //end if
    
    /*	
	if (!hasValue(thisForm.city, "TEXT" )) {
		if (!onError(thisForm.city, "Please enter a city name.")) {
			return false;
		} //end if
	} //end if
    */
    
    if (do_rewrite == 1) {
        document.location = modRewriteSearch(form_ids_ar, 4, new Array('hFeature'));
	    return false;
    } else {
	    return true;
    } //end if
} //end function ValidateForm4
