/******* SCRIPT TO SWITCH BETWEEN BUYING AND RENTING SAVED SEARCH PARAMETERS ********/

// search parameter set constructor

function SearchParameterSet() {
	this.parameters = new Array(); 
	this.formRef = null;
	
	/**** methods ****/
	
	this.setFormRef = SPS_setFormRef;
	this.storeParameter = SPS_storeParameter;
	this.setParameters = SPS_setParameters;
	this.setDropdownIndex = SPS_setDropdownIndex;
}


function SPS_setFormRef(fr) {
	this.formRef = document.forms[fr];
}

// store name / value pair in parameters array
function SPS_storeParameter(inputName, inputValue) {
	this.parameters[inputName] = inputValue;
}

function SPS_setParameters() {
		if(this.formRef.location!=null){
			this.formRef.location.value = this.parameters["location"];
		}
		if(this.formRef.beds!=null){
			this.setDropdownIndex("beds", this.parameters["beds"]);
		}
		if(this.formRef.min!=null){
			this.setDropdownIndex("min", this.parameters["min"]);
		}
		if(this.formRef.max!=null){
			this.setDropdownIndex("max", this.parameters["max"]);
		}
		if(this.formRef.type!=null){
			this.setDropdownIndex("type",this.parameters["type"]);
		}
		if(this.formRef.ref!=null){
			this.formRef.ref.value = this.parameters["ref"];
		}
		if(this.formRef.items!=null){
			this.setDropdownIndex("items", this.parameters["items"]);
		}
}

function SPS_setDropdownIndex(ddName, valToMatch) {
		
		var thisDD = this.formRef.elements[ddName];
		
		if(thisDD) { //check to see if element exists as in the case of items, map search won't have it.
		var thisDDOps = thisDD.options;
		
		for(var counter = 0; counter<thisDDOps.length; counter++) {
			var thisValue = thisDDOps[counter].value;
			
			if(thisValue == valToMatch) {
				thisDD.selectedIndex = counter;
			}
		}
		}
}








