/**********

//	Restore object - use when you want to restore form values onload
//	create the object after the end of the form tag

//var rObj = new restoreObject('formName');
//rObj.optionClear(selectName); //in case you are using a component with a default selected
//rObj.restoreCheck('checkbox','checkbox1');
//rObj.restoreCheck('checkbox','checkbox2');
//rObj.restoreCheck('checkbox','checkbox3');
//rObj.restoreCheck('checkbox','checkbox4');
//rObj.restoreCheck('checkbox','checkbox5');
//rObj.restoreRadio('rcheckbox','checkbox4');
//rObj.restoreOption('selectOne','21');
//rObj.restoreOption('selectTwo','21');
//rObj.restoreOption('selectTwo','7');

**********/

function restoreObject(formName) {

	this.form = document.forms[formName];
	this.optionClear = option_clear;
	this.restoreOption = option_restore;
	this.restoreRadio = radio_restore;
	this.restoreCheck = check_restore;
	this.restoreText = text_restore;

}

function option_clear(optionList) {
	for (i=0;i<this.form.elements[optionList].length;i++) {
		if (this.form.elements[optionList][i].type=='select-multiple' || this.form.elements[optionList][i].type=='select-single') {
			for(j=0;j<this.form.elements[optionList][i].options.length;j++) {
				this.form.elements[optionList][i].options[j].selected=false;
			}
		}
	}
}

function option_restore(optionName, elValue) {
	for (i=0;i<this.form.elements[optionName].options.length;i++) {
		if (this.form.elements[optionName].options[i].value == elValue) {
			this.form.elements[optionName].options[i].selected=true; //setAttribute('selected','true');
		}
	}
}

function radio_restore(radioName, elValue) {

	for (i=0;i<this.form.elements[radioName].length; i++) {
		if (this.form.elements[radioName][i].value == elValue) {
			this.form.elements[radioName][i].setAttribute('checked',true);
		}
	}

}

function check_restore(checkName, elValue) {
	this.form.elements[checkName].setAttribute('checked',true);
}

function text_restore(textName, elValue) {

	el = this.form.elements[textName];
	el.value = elValue;

}

//not part of the object - decode some values:

function getBaseMealPlan(mealPlan) {

	// decode base meal plan given HB, BB etc

	var baseMeals = new Array("HB,Half Board","BB,Bed and Breakfast","SC,Self Catering","RO,Room Only","CA,Catered Chalet Board","FB,Full Board");
	for (i=0;i<baseMeals.length;i++) {
	var temp = baseMeals[i].split(',');	
		for(j=0;j<temp.length;j++) {
			if (temp[j]==mealPlan) {
					return temp[j+1];
					break;					
			}
		}
	}
}
			
function getAirport(airportCode) {

	// extract airport code from arrays in file DepartureLocations.js

	for(i=0;i<aList.length;i=i+2) {
		if(aList[i]==airportCode) {
			return aList[i+1];
			break;
		}
	}
	for(j=0;j<oList.length;j=j+2) {
		if(oList[j]==airportCode) {
			return oList[j+1];
			break;
		}
	}
	for(var k=0;k<airportCountryList.length;k++) 
	{
		var airportCountryMap = airportCountryList[k].split(',');
		if(airportCountryMap[1]==airportCode) {
			return airportCountryMap[2];
			break;
		}
	}
	
	return airportCode;
}

	function getCarrierFlightNo(inString) {

	// split carrier code from flight num in JFA string
       
		inString = stripSpace(inString);
		var re = new RegExp('\\d');
		var m = re.exec(inString);
		var retString = "";
		if (m!=null) {
			//retString += 'Carrier Code: ' + inString.substring(0,m.index) + '; ';
			retString = 'Flight No: ' + inString.substring(m.index,inString.length);
		}		
		return retString;
	}

function getCarrierName(carrierCode) {
   
	// extract carrier code from array in file DepartureLocations.js
        inString = stripSpace(carrierCode);
		var re = new RegExp('\\d');
		var m = re.exec(inString);
		var retString = "";
		if (m!=null) {
			retString = inString.substring(0,m.index); 
			//retString = 'Flight No: ' + inString.substring(m.index,inString.length);
		}		
		
	for(i=0;i<CarrierList.length;i=i+2) {
		if(CarrierList[i]==retString) {
			return CarrierList[i+1];
			break;
		}
	}
//alert(carrierCode);
return carrierCode;
}

function getCarrier(carrierCode) {

	// extract carrier code from array in file DepartureLocations.js

	for(i=0;i<CarrierList.length;i=i+2) {
		if(CarrierList[i]==carrierCode) {
			return CarrierList[i+1];
			break;
		}
	}

	return carrierCode;
}