
function addFeature(elm) {	
	
	var from = $(elm);
	var to = $(elm+'_selected');	
	var fromLen = from.length ;
	
	for ( i=0; i<fromLen ; i++){
	  if (from.options[i].selected == true ) {
	    var toLen = to.length;
	    to.options[toLen] = new Option(from.options[i].text, from.options[i].value);
	  }
	}
	for ( i = (fromLen -1); i>=0; i--){
	  if (from.options[i].selected == true ) {
	    from.options[i] = null;
	  }
	}
	
}

function removeFeature(elm) {
	
	var from = $(elm);
	var to = $(elm+'_selected');	
	var toLen = to.length ;
	
	for ( i=0; i<toLen ; i++){
		if (to.options[i].selected == true ) {
			var fromLen = from.length;
			from.options[fromLen] = new Option(to.options[i].text, to.options[i].value);
		}
	}
	for ( i=(toLen-1); i>=0; i--) {
		if (to.options[i].selected == true ) {
			to.options[i] = null;
		}
	}
	
}

function goFeatures(){
	
	// facilities
	if($('form_facilities_selected')) {
		var facilities = $('form_facilities_selected');	
		for (i=0; i<facilities.length; i++) {
			facilities.options[i].selected = true;
		}
	}
	// leisure_facilities
	if($('form_leisure_facilities_selected')) {
		var leisure_facilities = $('form_leisure_facilities_selected');	
		for (i=0; i<leisure_facilities.length; i++) {
			leisure_facilities.options[i].selected = true;
		}
	}
	// room facilities
	if($('form_room_facilities_selected')) {
		var room_facilities = $('form_room_facilities_selected');	
		for (i=0; i<room_facilities.length; i++) {
			room_facilities.options[i].selected = true;
		}
	}
	// languages
	if($('form_spoken_languages_selected')) {
		var languages = $('form_spoken_languages_selected');	
		for (i=0; i<languages.length; i++) {
			languages.options[i].selected = true;
		}
	}
	// payment_options
	if($('form_payment_options_selected')) {
		var payment_options = $('form_payment_options_selected');	
		for (i=0; i<payment_options.length; i++) {
			payment_options.options[i].selected = true;
		}
	}
	xajax_saveHotelFeatures(xajax.getFormValues('edit_features'));
	
}

function getValidationFields(formName){						
	var validateType= new Array(9);
	validateType[0]="required";
	validateType[1]="validate-alpha";
	validateType[2]="validate-number";
	validateType[3]="validate-alphanum";
	validateType[4]="validate-alphanum-extra";
	validateType[5]="validate-email";
	validateType[6]="clear-on-error";
	validateType[7]="validate-password";
	validateType[8]="validate-url";
	
	var f = $(formName);
	var retArray = new Array();
				
	//validateType.each(function(vt){
		//var elm = f.getElementsByClassName(vt);
		// elm may be an array of elements so loop through elm in case
		//z=0;
		//elm.each(function(e){
			//retArray[z+'_'+vt]=e.id;
			//z++;
		//});												
	//});
	
	for (var indexA = 0; indexA < validateType.length; ++indexA) {
	  
		var className = validateType[indexA];
        var elm = f.getElementsByClassName(className);
        
        // elm may be an array of elements so loop through elm in case
		var z=0;        
		for (var indexB = 0; indexB < elm.length; ++indexB) {
		
			var e = elm[indexB];
			retArray[z+'_'+className]=e.id;
			z++;
		 		
		}
       	
	}	
			
	return retArray;
			  
}

function ret(){
	return;
}

function elmFade(elm) {
	if(elm == 'seasonal_from') {
		new Effect.Fade('open_fromMsg', {duration: 0.4});
		Field.clear('open_from');			
	} else if(elm == 'seasonal_to') {
		new Effect.Fade('open_tillMsg', {duration: 0.4});
		Field.clear('open_till');		
	} else if(elm = 'opening_times') {
		new Effect.Fade('opening_times', {duration: 0.4});	
	}
	new Effect.Fade(elm, {duration: 0.4});
}

function elmAppear(elm) {
	new Effect.Appear(elm, {duration: 0.4});
}

function elmToggle(elm) {
	if(elm == 'feedback_div') {	// clear the field and fade any error message it has
		new Effect.Fade('first_nameMsg', {duration: 0.3});
		new Effect.Fade('feedbackMsg', {duration: 0.3});
		new Effect.Fade('msg', {duration: 0.3});
		Field.clear('first_name');
		Field.clear('feedback');		
	}	
	if($(elm)) {	// check if this element exists before toggling
		new Effect.toggle(elm, 'appear', {duration: 0.3});
	}
}

function newCityCheck() {
	var value = $F('city_select');
	if(value != "") {
		// fade any error message it has
		new Effect.Fade('new_city_nameMsg', {duration: 0.3});
		// clear and fade city name & city checkbox fields
		Field.clear('new_city_name');
		$('add_new_city').checked = false;	// clear the checkbox
		new Effect.Fade('new_city_checkbox', {duration: 0.3});
		new Effect.Fade('new_city', {duration: 0.3});
		// check if province_select exists before clearing & fading
		if($('province_select')){
			Field.clear('province_select');
			new Effect.Fade('province', {duration: 0.3});
		}				
	} else {
		// display the new city checkbox
		new Effect.Appear('new_city_checkbox', {duration: 0.4});
	}
}

function newCityReset() {
	// This function is run after onchange event on the country_select		
	// fade possible new_city error message
	new Effect.Fade('new_city_nameMsg', {duration: 0.3});
	// clear and fade city name & city checkbox fields
	Field.clear('new_city_name');
	$('add_new_city').checked = false;	// clear the checkbox
	new Effect.Appear('new_city_checkbox', {duration: 0.3});
	new Effect.Fade('new_city', {duration: 0.3});
	// check if province_select exists before clearing
	if($('province_select')){ Field.clear('province_select'); }
	// check if province div exists before fading it
	if($('province')){ new Effect.Fade('province', {duration: 0.3}); }
}

function newChainCheck() {
	var value = $F('hotel_chain_select');
	if(value != "") {
		// fade any error message it has
		new Effect.Fade('new_chain_nameMsg', {duration: 0.3});
		// clear and fade chain name & chain checkbox fields
		Field.clear('new_chain_name');
		$('add_new_chain').checked = false;	// clear the checkbox
		new Effect.Fade('new_chain_checkbox', {duration: 0.3});
		new Effect.Fade('new_chain', {duration: 0.3});
	} else {
		// display the new chain checkbox
		new Effect.Appear('new_chain_checkbox', {duration: 0.4});
	}
}

function processUserLogin() {
	xajax_validateForm(xajax.getFormValues('userLogin'), getValidationFields('userLogin'), 'userLogin', 'userLogin');	
}

function openProgress() {
	Dialog.info(null,{width:100, height:36, showProgress: true});
}
function closeProgress() {
	Dialog.closeInfo();
}

function processHotelCheckBeforeAdd() {
	xajax_validateForm(xajax.getFormValues('hotelCheckBeforeAdd'), getValidationFields('hotelCheckBeforeAdd'), 'hotelCheckBeforeAdd', 'hotelCheckBeforeAdd');		
}

function processHotelAddPropertyInfo() {
	xajax_validateForm(xajax.getFormValues('hotelAddPropertyInfo'), getValidationFields('hotelAddPropertyInfo'), 'hotelAddPropertyInfo', 'hotelAddPropertyInfo');
}

function processHotelEditPropertyInfo() {
	xajax_validateForm(xajax.getFormValues('hotelEditPropertyInfo'), getValidationFields('hotelEditPropertyInfo'), 'hotelEditPropertyInfo', 'hotelEditPropertyInfo');
}

function processHotelierRegistration() {
	xajax_validateForm(xajax.getFormValues('hotelierRegistration'), getValidationFields('hotelierRegistration'), 'hotelierRegistration', 'userRegistration');
}

function processDeleteHotel(val) {
	xajax_hotelDelete(val);
}

function deletePhoto(val) {
	var hotel_id = document.getElementById("hotel_id").value;
	xajax_deleteHotelPhoto(val, hotel_id);
}
function editPhoto(val1, val2) {
	xajax_showEditHotelPhoto(val1, val2);
}
function saveEditPhoto(val) {
	xajax_saveEditHotelPhoto(val, xajax.getFormValues('photoEdit'));
}
function addPhotoIframePost() {
	new iframe(document.getElementById("photoAdd")); return false;
	document.getElementById("photoAdd").submit();		
}

function addPhoto() {
	xajax_validateForm(xajax.getFormValues('photoAdd'), getValidationFields('photoAdd'), 'photoAdd', 'photoAddCallback');		
}

function goDescriptions() {	
	xajax_saveHotelDescription(xajax.getFormValues('edit_descriptions'));	
}

// ====================================

function clearPasswordFields(formName) {
	var f = $(formName);
	var p = f.getInputs('password');	
	p.each(function(e){
		Field.clear(e.id);
	});
}

function swapColour(val) {
	if(val==1) {
		$('ans_1_td').className = 'txt24 red';
		$('ans_2_td').className = 'txt20 blue';
	} else {
		$('ans_1_td').className = 'txt24 red';
		$('ans_2_td').className = 'txt24 red';
	}	
}
function checkTF() {
	Field.clear($('answer3'));
	Field.clear($('answer4'));
	$('answer3').disable();
	$('answer4').disable();
}
function enableAns(){
	$('answer3').enable();
	$('answer4').enable();
}

function goQaForm() {	
	if(($('type_1').checked == false) && ($('type_2').checked == false) && ($('type_3').checked == false)) return false;
	if($('question').value == "") return false;
	if($('answer1').value == "") return false;
	if($('answer2').value == "") return false;
	document.getElementById("qaForm").submit();
}

function goLogin() {
	xajax_validateForm(xajax.getFormValues('login_form'), getValidationFields('login_form'), 'login_form', 'signinUser');	
}
function goReg() {
	xajax_validateForm(xajax.getFormValues('registration_form'), getValidationFields('registration_form'), 'registration_form', 'registerUser');	
}
function goResetPw() {
	xajax_validateForm(xajax.getFormValues('reset_password_form'), getValidationFields('reset_password_form'), 'reset_password_form', 'resetPassword');	
}
function goFeedback() {
	xajax_validateForm(xajax.getFormValues('feedback_form'), getValidationFields('feedback_form'), 'feedback_form', 'emailFeedback');	
}


function goGold() {
	//if(!confirm('Please Note: Our current practice tests are based on the FIRST edition of the Life in the United Kingdom handbook. If you are taking your test from 2 July 2007, you must study the SECOND edition. We will be releasing our SECOND edition questions closer to the time.')) {
		//return false;
	//}	
	document.getElementById("formGold").submit();		
}
function goSilver() {
	//if(!confirm('Please Note: Our current practice tests are based on the FIRST edition of the Life in the United Kingdom handbook. If you are taking your test from 2 July 2007, you must study the SECOND edition. We will be releasing our SECOND edition questions closer to the time.')) {
		//return false;
	//}
	document.getElementById("formSilver").submit();		
}
function goBronze() {
	//if(!confirm('Please Note: Our current practice tests are based on the FIRST edition of the Life in the United Kingdom handbook. If you are taking your test from 2 July 2007, you must study the SECOND edition. We will be releasing our SECOND edition questions closer to the time.')) {
		//return false;
	//}
	document.getElementById("formBronze").submit();		
}
function goBook() {
	//if(!confirm('Please Note: Our current practice tests are based on the FIRST edition of the Life in the United Kingdom handbook. If you are taking your test from 2 July 2007, you must study the SECOND edition. We will be releasing our SECOND edition questions closer to the time.')) {
		//return false;
	//}
	document.getElementById("formBook").submit();		
}

function goNewPW() {
	xajax_validateForm(xajax.getFormValues('newpassword_form'), getValidationFields('newpassword_form'), 'newpassword_form', 'newPassword');	
}

function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
