function fireSifr(){	
	if(typeof sIFR == "function"){
		
		sIFR.replaceElement(named({sSelector:"#content_ajax_body h1", sFlashSrc:"../images/swf/avenir.swf", sColor:"#87A321", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"#content_ajax_body h2", sFlashSrc:"../images/swf/vag-rounded-thin-bold.swf", sColor:"#FFFFFF", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:6, nPaddingBottom:6, nPaddingLeft:15, nPaddingRight:15, sWmode:"transparent", sCase:"upper", sFlashVars:"textalign=left&offsetTop=0"}));
	
	};
}	


function hideSuburb(field){
	document.getElementById(field).style.display="none";
}
function showSuburb(field){
	document.getElementById(field).style.display="block";
	return false;
}


function hideTimes(field){
	if (document.getElementById)
	{ 
		exit;
	}
	document.getElementById(field).style.display="none";
	
	if(document.getElementById("form-all-day-no").checked==true){
		document.getElementById(field).style.display="block";
	}
}

function showTimes(field){
	document.getElementById(field).style.display="block";
}



function hideSeasonal(field,field2){

	document.getElementById(field).style.display="none";
	document.getElementById(field2).style.display="none";
	
	if(document.getElementById("form-year-round-no").checked==true){
		document.getElementById(field).style.display="block";
		document.getElementById(field2).style.display="block";
	}
}

function showSeasonal(field,field2){
	document.getElementById(field).style.display="block";
	document.getElementById(field2).style.display="block";
}



function openWin(url){
	window.open(url,"AddFile","width=620,height=500,scrollbars=yes")
	return false;
}

function addFeature(elm) {	
	
	var from = $(elm);
	var to = $(elm+'_selected');	
	var fromLen = from.length ;
	
	// remove any blank option (blank options are there due to FF 'XX' bug)
	if((to.options[0]) && (to.options[0].value=='')) {
		to.remove(0);
	}
	
	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');
		if(facilities.length==0) {
			facilities.options[0] = new Option('', '');	// add a blank option - for FF 'XX' bug
		} else {	
			for (i=0; i<facilities.length; i++) {
				if(facilities.options[i].value!='') facilities.options[i].selected = true;
			}
		}
	}
	// leisure_facilities
	if($('form_leisure_facilities_selected')) {
		var leisure_facilities = $('form_leisure_facilities_selected');
		if(leisure_facilities.length==0) {
			leisure_facilities.options[0] = new Option('', '');
		}	else {
			for (i=0; i<leisure_facilities.length; i++) {
				if(leisure_facilities.options[i].value!='') leisure_facilities.options[i].selected = true;
			}
		}
	}
	// room facilities
	if($('form_room_facilities_selected')) {
		var room_facilities = $('form_room_facilities_selected');
		if(room_facilities.length==0) {
			room_facilities.options[0] = new Option('', '');		// add a blank option - for FF 'XX' bug
		} else {	
			for (i=0; i<room_facilities.length; i++) {
				if(room_facilities.options[i].value!='') room_facilities.options[i].selected = true;
			}
		}
	}
	// languages
	if($('form_spoken_languages_selected')) {
		var languages = $('form_spoken_languages_selected');
		if(languages.length==0) {
			languages.options[0] = new Option('', '');		// add a blank option - for FF 'XX' bug
		} else {	
			for (i=0; i<languages.length; i++) {
				if(languages.options[i].value!='') languages.options[i].selected = true;
			}
		}
	}
	// payment_options
	if($('form_payment_options_selected')) {
		var payment_options = $('form_payment_options_selected');
		if(payment_options.length==0) {
			payment_options.options[0] = new Option('', '');		// add a blank option - for FF 'XX' bug
		} else {
			for (i=0; i<payment_options.length; i++) {
				if(payment_options.options[i].value!='') payment_options.options[i].selected = true;
			}
		}
	}
	xajax_saveHotelFeatures(xajax.getFormValues('edit_features'));
	
}

function addRoomType(){
	
	// roomCount is the id used for each new row. if the hidden room_cnt is not set
	// roomCount is based on the number of hidden form fields - 1 (room_cnt is hidden)
	// if room_cnt is set, room_cnt is incremented and roomCount is given its value
	
	var roomCount = $F("room_cnt");
	if(!roomCount) {
		var f = $('editRooms');
		var p = f.getInputs('hidden');
		roomCount = p.length - 1;
		$("room_cnt").value = roomCount;	
	} else {
		roomCount ++;
		$("room_cnt").value = roomCount;
	}		
	
	// get a 'copy' of the first room type select box to build a new one
	var e = $$('select');	
	roomTypeList = $(e[1].id);
		
	roomTypeOptionValue = new Array();
	roomTypeOptionText = new Array();
	
	newRoomTypeOption = new Array();
	
	for(i=0;i<roomTypeList.length;i++){
		roomTypeOptionValue[i] = roomTypeList.options[i].value;
		roomTypeOptionText[i] = roomTypeList.options[i].innerHTML;
	}
	
	for(i=0;i<roomTypeList.length;i++){
		newRoomTypeOption[i] = document.createElement("option");
		newRoomTypeOption[i].setAttribute("value",roomTypeOptionValue[i]);
		newRoomTypeOption[i].appendChild(document.createTextNode(roomTypeOptionText[i]));
	}

	roomType = document.createElement("select");	
	roomType.setAttribute("name","form-room-type["+roomCount+"]");
	roomType.setAttribute("id","form-room-type["+roomCount+"]");
	
	for(i=0;i<roomTypeList.length;i++){
		roomType.appendChild(newRoomTypeOption[i]);
	}
	
	roomNumber = document.createElement("input");
	roomNumber.setAttribute("type","text");
	roomNumber.setAttribute("name","form-room-numbers["+roomCount+"]");
	roomNumber.setAttribute("id","form-room-numbers["+roomCount+"]");
	roomNumber.setAttribute("value","");
	roomNumber.setAttribute("class","text");
	roomNumber.setAttribute("className","text");
	
	roomHighPrice = document.createElement("input");
	roomHighPrice.setAttribute("type","text");
	roomHighPrice.setAttribute("name","form-room-high-price["+roomCount+"]");
	roomHighPrice.setAttribute("id","form-room-high-price["+roomCount+"]");
	roomHighPrice.setAttribute("value","");
	roomHighPrice.setAttribute("class","text");
	roomHighPrice.setAttribute("className","text");
	
	roomLowPrice = document.createElement("input");
	roomLowPrice.setAttribute("type","text");
	roomLowPrice.setAttribute("name","form-room-low-price["+roomCount+"]");
	roomLowPrice.setAttribute("id","form-room-low-price["+roomCount+"]");
	roomLowPrice.setAttribute("value","");
	roomLowPrice.setAttribute("class","text");
	roomLowPrice.setAttribute("className","text");
	
	// row_id in the DB ... blank for all new rows
	roomRowId = document.createElement("input");
	roomRowId.setAttribute("type","hidden");
	roomRowId.setAttribute("name","form-row-id["+roomCount+"]");
	roomRowId.setAttribute("id","form-row-id["+roomCount+"]");
	roomRowId.setAttribute("value","");
		
	roomTypeTd = document.createElement("td");
	roomTypeTd.appendChild(roomType)
	
	roomLowPriceTd = document.createElement("td");
	roomLowPriceTd.appendChild(roomLowPrice)
	
	roomHighPriceTd = document.createElement("td");
	roomHighPriceTd.appendChild(roomHighPrice)
	
	roomNumberTd = document.createElement("td");
	roomNumberTd.appendChild(roomNumber);
	roomNumberTd.appendChild(roomRowId)
	
	deleteTd = document.createElement("td");
	deleteTd.innerHTML = '<img src="../images/delete.png" class="img-link" style="margin-top:4px;" onclick="delRoom('+roomCount+'); return false;" />';
		
	roomRow = document.createElement("tr");
	roomRow.setAttribute("name","row["+roomCount+"]");
	roomRow.setAttribute("id","row["+roomCount+"]");	
	
	roomRow.appendChild(roomTypeTd);
	roomRow.appendChild(roomLowPriceTd);
	roomRow.appendChild(roomHighPriceTd);
	roomRow.appendChild(roomNumberTd);
	roomRow.appendChild(deleteTd);
	
	// the row to display any messages
	msgTd = document.createElement("td");
	msgTd.setAttribute("colspan",5);
	msgTd.setAttribute("style","display:none;");
	
	msgRow = document.createElement("tr");
	msgTd.setAttribute("name","msg-row["+roomCount+"]");
	msgTd.setAttribute("id","msg-row["+roomCount+"]");
	msgRow.appendChild(msgTd);
	
	roomTab = document.getElementById("room-types")
	roomBody = roomTab.getElementsByTagName("tbody");
	roomBody[0].appendChild(roomRow);
	roomBody[0].appendChild(msgRow);
	
}

function delRoom(row_id) {
	
	// need to ensure user does not delete all the rows, must always be 1 row minimum
	// else addRoomType() will not work
	var f = $('editRooms');
	var p = f.getInputs('hidden');
	var roomCount = p.length - 2; // hotel_id, room_cnt are also hidden fields
	
	// check if this row has a physical record in the DB by looking up the
	// value of the hidden field "form-row-id". If not blank, records exists in DB
	
	var dbID = $F("form-row-id["+row_id+"]");
	if(!dbID) {	// no value in DB can simply remove the element
		if(roomCount > 1) {	// only delete if there are more than 1 room rows
			$("row["+row_id+"]").remove();
			$("msg-row["+row_id+"]").remove();
		} else {	// reset this rows fields but do not remove the row
			$("form-room-numbers["+row_id+"]").value = "";
			$("form-room-high-price["+row_id+"]").value = "";
			$("form-room-low-price["+row_id+"]").value = "";
			$("form-room-type["+row_id+"]").options[0].selected = true;
			new Effect.Fade("msg-row["+row_id+"]", {duration: 0.3});
		}
	} else {	// value in DB, pass the records db row_id to the xajax enabled function
		if(roomCount <= 1) {	// add a new room row if this is the only one
			addRoomType();
		}
		xajax_deleteHotelRoom(dbID, row_id);		
	}
			
}


function addLang(field){

	if(field=="directions"){
		fieldset = document.getElementById("directions");
		langs = document.getElementById("form_directions_lang");
		fieldname = "form_directions_";
		fieldlabel = "Directions";
		fieldparent = "field_dir_";
	}
	
	if(field=="description"){
		fieldset = document.getElementById("descriptions");
		langs = document.getElementById("form_description_lang");
		fieldname = "form_description_";
		fieldlabel = "Description & Comments";
		fieldparent = "field_desc_";
	}
	
	newLang = langs.options[langs.selectedIndex].innerHTML;
	newLangCode = langs.options[langs.selectedIndex].value;

	if(!document.getElementById(fieldname+newLangCode)){
	newTextArea = document.createElement("textarea");
	newTextArea.setAttribute("name",fieldname+newLangCode);
	newTextArea.setAttribute("id",fieldname+newLangCode);
	newTextArea.setAttribute("cols","40");
	newTextArea.setAttribute("rows","5");
	
	newLabel = document.createElement("label");
	newLabel.setAttribute("for",fieldname+newLangCode);
	newLabel.appendChild(document.createTextNode(fieldlabel))
	newLabelSmall = document.createElement("small");
	newLabelSmall.appendChild(document.createTextNode(newLang));
	newLabel.appendChild(newLabelSmall);
	
	newDeleteLink = document.createElement("a");
	newDeleteLink.setAttribute("href","javascript:removeLang('"+fieldparent+newLangCode+"','"+fieldset.id+"');");
	newDeleteLink.appendChild(document.createTextNode("Remove this language"))
	
	createField();
	
	newElementDiv.appendChild(newTextArea);
	newElementDiv.appendChild(newDeleteLink);
	newLabelDiv.appendChild(newLabel);	
	
	newFieldDiv.setAttribute("id",fieldparent+newLangCode);
	newFieldDiv.appendChild(newLabelDiv);
	newFieldDiv.appendChild(newElementDiv);
	
	fieldset.appendChild(newFieldDiv);
	}
}


function addDealLang(field){

	fieldset = document.getElementById("deal-description");
	langs = document.getElementById("form-deal-description-lang");
	newLang = langs.options[langs.selectedIndex].innerHTML;
	newLangCode = langs.options[langs.selectedIndex].value;

	newHR = document.createElement("hr")
	
	
	if(!document.getElementById("form-deal-title-"+newLangCode)){

	newDeleteLink = document.createElement("a");
	newDeleteLink.setAttribute("href","javascript:removeDealLang('"+newLangCode+"');");
	newDeleteLink.appendChild(document.createTextNode("Remove this language"))

	
	newSmall = document.createElement("small");
	newSmall.appendChild(document.createTextNode(newLang));

	
	newLabel = document.createElement("label");
	newLabel.setAttribute("for","form-deal-title-"+newLangCode);
	newLabel.appendChild(document.createTextNode("Deal Title"));
	newLabel.appendChild(newSmall);
	
	newSmall = document.createElement("small");
	newSmall.appendChild(document.createTextNode(newLang));
	
	newLabel2 = document.createElement("label");
	newLabel2.setAttribute("for","form-deal-subtitle-"+newLangCode);
	newLabel2.appendChild(document.createTextNode("Deal Subtitle"));
	newLabel2.appendChild(newSmall);

	
	newSmall = document.createElement("small");
	newSmall.appendChild(document.createTextNode(newLang));
	
	newLabel3 = document.createElement("label");
	newLabel3.setAttribute("for","form-deal-description-"+newLangCode);
	newLabel3.appendChild(document.createTextNode("Deal Description"));	
	newLabel3.appendChild(newSmall);

	
	newTextInp = document.createElement("input");
	newTextInp.setAttribute("type","text");
	newTextInp.setAttribute("name","form-deal-title-"+newLangCode);
	newTextInp.setAttribute("id","form-deal-title-"+newLangCode);
	newTextInp.setAttribute("class","text");
	newTextInp.setAttribute("className","text");	
	
	newTextInp2 = document.createElement("input");
	newTextInp2.setAttribute("type","text");
	newTextInp2.setAttribute("name","form-deal-subtitle-"+newLangCode);
	newTextInp2.setAttribute("id","form-deal-subtitle-"+newLangCode);
	newTextInp2.setAttribute("class","text");
	newTextInp2.setAttribute("className","text");	
	
	newTextArea = document.createElement("textarea");
	newTextArea.setAttribute("name","form-deal-description-"+newLangCode);
	newTextArea.setAttribute("id","form-deal-description-"+newLangCode);
	newTextArea.setAttribute("cols","40");
	newTextArea.setAttribute("rows","5");
	
	createField();
	
	newElementDiv.appendChild(newTextInp);
	newLabelDiv.appendChild(newLabel);
	
	newFieldDiv.setAttribute("id","field-deal-title-"+newLangCode);
	newFieldDiv.appendChild(newLabelDiv);
	newFieldDiv.appendChild(newElementDiv);
	
	fieldset.appendChild(newHR);	
	fieldset.appendChild(newFieldDiv);
	
	createField();
	
	newElementDiv.appendChild(newTextInp2);
	newLabelDiv.appendChild(newLabel2);
	
	newFieldDiv.setAttribute("id","field-deal-subtitle-"+newLangCode);
	newFieldDiv.appendChild(newLabelDiv);
	newFieldDiv.appendChild(newElementDiv);
	

	fieldset.appendChild(newFieldDiv);
	
	
	createField();
	
	newElementDiv.appendChild(newTextArea);
	newElementDiv.appendChild(newDeleteLink);
	newLabelDiv.appendChild(newLabel3);
	
	newFieldDiv.setAttribute("id","field-deal-desc-"+newLangCode);
	newFieldDiv.appendChild(newLabelDiv);
	newFieldDiv.appendChild(newElementDiv);
	
	
	fieldset.appendChild(newFieldDiv);		
	
	
	}
	
}

function createField(){

	newFieldDiv = document.createElement("div");
	newFieldDiv.setAttribute("class","field clear");
	newFieldDiv.setAttribute("className","field clear");	
	
	newElementDiv = document.createElement("div");
	newElementDiv.setAttribute("class","element");
	newElementDiv.setAttribute("className","element");

	newLabelDiv = document.createElement("div");
	newLabelDiv.setAttribute("class","label");
	newLabelDiv.setAttribute("className","label");
	
}

function removeLang(field,prnt){

	fieldLyr = document.getElementById(field);
	if(prnt=="directions"){
		fieldset = document.getElementById("directions");
	}
	
	if(prnt=="description"){
		fieldset = document.getElementById("descriptions");
	}

	fieldset.removeChild(fieldLyr);

}

function removeDealLang(lang){

	titleLyr = document.getElementById("field-deal-title-"+lang);
	subTitleLyr = document.getElementById("field-deal-subtitle-"+lang);
	descLyr = document.getElementById("field-deal-desc-"+lang);
	fieldset = document.getElementById("deal-description");
	
	fieldset.removeChild(titleLyr.previousSibling);
	fieldset.removeChild(titleLyr);
	fieldset.removeChild(subTitleLyr);
	fieldset.removeChild(descLyr);

}

function updateTitle(elmnt){
	document.getElementById("form-deal-title").value = elmnt.options[elmnt.selectedIndex].innerHTML;
}

var cost
function updatePrice(){
	
	costOptions = document.getElementById("form-cost-impression");
	cost = costOptions.options[costOptions.selectedIndex].value/1000;
	
	document.getElementById("impression-cost").removeChild(document.getElementById("impression-cost").firstChild)
	
	document.getElementById("impression-cost").appendChild(document.createTextNode(cost));
}


window.onload = init

function init(){
	if(document.getElementById("impression-cost")){updatePrice();}
	setup();
}

function setup()
{
	if (document.getElementById("package_text_platinum"))
		document.getElementById("package_text_platinum").className="hide";
	if (document.getElementById("package_text_gold"))
		document.getElementById("package_text_gold").className="hide";
	if (document.getElementById("package_text_silver"))	
		document.getElementById("package_text_silver").className="hide";
	if (document.getElementById("package_text_bronze"))
		document.getElementById("package_text_bronze").className="hide";
}

function getValidationFields(formName){						
	var validateType= new Array(11);
	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';
	validateType[9]='validate-price';
	validateType[10]='validate-date-1';
	
	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){
		
			if((vt=='required') && (Element.hasClassName(e.id, 'parent'))) {
				// we now know this field is required and it is a parent field
				// we now check if for its child element(s) and build an array of their ids
				var childArray = new Array();
				retArray[z+'_'+vt]=e.id;
				var cElm = f.getElementsByClassName('child_'+e.id);
				// cElm may be an array of elements so loop through cElm in case
				x=0;
				cElm.each(function(cE){
					childArray[x]=cE.id;
					x++;
				});
				retArray[z+'_child']=childArray;			
				z++;
			} else {	
				retArray[z+'_'+vt]=e.id;
				z++;
			}			
		});												
	});
				
	return retArray;
			  
}

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 == 'lhMenu') {	// show/hide the hotelier menu		
		var currLnk = $('toggleLnk').innerHTML;
		var openLnk = $('open').innerHTML;
		var closeLnk = $('close').innerHTML;
		if(currLnk == openLnk) {	// must change currLnk to close
			$('toggleLnk').innerHTML = closeLnk;
		} else {	// must change currLnk to open
			$('toggleLnk').innerHTML = openLnk;
		}		
	}
	if(elm == 'new_password') {	// clear the 3 fields and fade any error message they have
		Field.clear('current_password');
		Field.clear('password');
		Field.clear('password2');
		if($('change_password').checked == true) {
			// user wants to change their password - update the fields class
			$('current_password').addClassName('required');
			$('current_password').addClassName('validate-password');
			//$('current_password').addClassName('clear-on-error');
			$('password').addClassName('required');
			$('password').addClassName('validate-password');
			//$('password').addClassName('clear-on-error');
			$('password2').addClassName('required');
			$('password2').addClassName('validate-password');
			//$('password2').addClassName('clear-on-error');
		} else {
			new Effect.Fade('current_passwordMsg', {duration: 0.3});
			new Effect.Fade('passwordMsg', {duration: 0.3});
			new Effect.Fade('password2Msg', {duration: 0.3});
			$('current_password').removeClassName('required');
			$('current_password').removeClassName('validate-password');
			//$('current_password').removeClassName('clear-on-error');
			$('password').removeClassName('required');
			$('password').removeClassName('validate-password');
			//$('password').removeClassName('clear-on-error');
			$('password2').removeClassName('required');
			$('password2').removeClassName('validate-password');
			//$('password2').removeClassName('clear-on-error');
		}
	}
	if($(elm)) {	// check if this element exists before toggling
		new Effect.toggle(elm, 'appear', {duration: 0.3});
	}
}

function newPasswordCheck() {
	if($('change_password').checked == true) {
		$('change_password').checked = false;
		elmToggle('new_password');
	}
}

function clearPasswordFields(formName) {
	var f = $(formName);
	var p = f.getInputs('password');	
	p.each(function(e){
		Field.clear(e.id);
	});
}

function newCityCheck() {
	
	// executed by the onchange event on the 'city_select' dropdown box	
	
	var value = $F('city_select');
	if(value != "") {

		Field.clear('new_city_name');
		$('add_new_city').checked = false;	// clear the checkbox		
		new Effect.Fade('new_city_nameMsg', {duration: 0.0});
		new Effect.Fade('add_new_cityTt', {duration: 0.0});
		new Effect.Fade('new_city_nameTt', {duration: 0.0});
		if($('province_selectTt')) new Effect.Fade('province_selectTt', {duration: 0.0});	
		new Effect.Fade('new_city_checkbox', {duration: 0.0});
		new Effect.Fade('new_city', {duration: 0.0});
		
		if($('province_select')){
			Field.clear('province_select');
			new Effect.Fade('province', {duration: 0.0});
		}
		
	} else {
		new Effect.Appear('new_city_checkbox', {duration: 0.3});
	}
	
	
}

function newCityReset() {
	
	// executed by the onchange event on the 'country_select' dropdown box

	Field.clear('new_city_name');
	$('add_new_city').checked = false;	// clear the checkbox
	new Effect.Fade('city_selectTt', {duration: 0.0});
	new Effect.Fade('add_new_cityTt', {duration: 0.0});
	new Effect.Fade('new_city_nameTt', {duration: 0.0});
	new Effect.Fade('province_selectTt', {duration: 0.0});	
	new Effect.Fade('new_city_nameMsg', {duration: 0.0});
	new Effect.Fade('new_city', {duration: 0.0});
	
	new Effect.Appear('new_city_checkbox', {duration: 0.3});

	if($('province_select')) Field.clear('province_select');
	if($('province')) new Effect.Fade('province', {duration: 0.0});
		
}

function newChainCheck() {
	
	// executed by the onchange event on the 'hotel_chain_select' dropdown box
	
	var value = $F('hotel_chain_select');
	if(value != "") {	// chain has been selected
		
		Field.clear('new_chain_name');
		$('add_new_chain').checked = false;	// clear the checkbox
		new Effect.Fade('new_chain_nameMsg', {duration: 0.0});
		new Effect.Fade('new_chain_checkbox', {duration: 0.00});
		new Effect.Fade('new_chain', {duration: 0.0});
		new Effect.Fade('add_new_chainTt', {duration: 0.0});
		new Effect.Fade('new_chain_nameTt', {duration: 0.0});
			
	} else {	// no chain has been selected
		new Effect.Appear('new_chain_checkbox', {duration: 0.3});
	}
}

function chainSwitch() {
	
	// executed if user clicks 'Add a new hotel chain?' checkbox
	
	new Effect.Fade('new_chain_nameMsg', {duration: 0.0});
	Field.clear('new_chain_name');			
	if($('add_new_chain').checked == false) new Effect.Fade('new_chain_nameTt', {duration: 0.0});
	elmToggle('new_chain');
	
}

function citySwitch() {
	
	// executed if user clicks 'Add a new city?' checkbox
		
	new Effect.Fade('new_city_nameMsg', {duration: 0.0});
	Field.clear('new_city_name');
	if($('add_new_city').checked == false) {
		new Effect.Fade('new_city_nameTt', {duration: 0.0});
		new Effect.Fade('province_selectTt', {duration: 0.0});
	}
	elmToggle('new_city');
	
	if($('province_select')){
		Field.clear('province_select');
		elmToggle('province');
	}	
	
}

function resetSelect(id) {
	$(id).options[0].selected = true;
}

function dealFilterReset(val) {

	if(val == 'category') {
	
		// reset the country and city selects and disable them + update the entity placeholder (x_deal)
		if($('category_select').value == "") {
			resetSelect('deal_type_select');
			Field.disable('deal_type_select');		
      new Effect.Fade('x_deal', {duration: 0.0});
		} else if($('category_select').value == "hotel") {
			Field.enable('deal_type_select');
			resetSelect('deal_type_select');
    	xajax_insertPlaceholder('hotel');
		} else if($('category_select').value == "hotel chain") {
			Field.enable('deal_type_select');
			resetSelect('deal_type_select');
      xajax_insertPlaceholder('hotel chain');
		} else if($('category_select').value == "airline") {
			Field.enable('deal_type_select');
			resetSelect('deal_type_select');
      xajax_insertPlaceholder('airline');
		} else if($('category_select').value == "car rental") {
			Field.enable('deal_type_select');
			resetSelect('deal_type_select');
      xajax_insertPlaceholder('car rental');
		}
		resetSelect('country_select');
		Field.disable('country_select');
		resetSelect('city_select');
		Field.disable('city_select');
		
		// update the fields placeholder in deal summary section & the fields values
		var category_ind = $('category_select').selectedIndex;
		if(category_ind == 0) {
			$('category-placeholder').innerHTML = '';	// replace with blank, not 'Please select ...'
		  Field.clear('category');	// the hidden form var
		} else {
			$('category-placeholder').innerHTML = $('category_select').options[category_ind].text;
			$('category').value = $('category_select').value;
		}
		$('company-placeholder').innerHTML = ''; 
		$('type-placeholder').innerHTML = '';
		$('country-placeholder').innerHTML = '';
		$('province-placeholder').innerHTML = '';
		$('city-placeholder').innerHTML = '';
		
		// clear the hidden vars + others
		Field.clear('country_id');
		Field.clear('province_id');
		Field.clear('city_id');
		Field.clear('type_id');
		Field.clear('entity_id');						
					
	} else if(val == 'type') {
	
		if($('deal_type_select').value == "") {
			$('country_select').options[0].selected = true;
			$('country_select').disabled=true;    	
			$('city_select').options[0].selected = true;
			$('city_select').disabled=true;
			if($('hotel_select')) {
				$('hotel_select').options[0].selected = true;
				$('hotel_select').disabled=true;
			} else if ($('hotel_chain_select')) {
				$('hotel_chain_select').options[0].selected = true;
				$('hotel_chain_select').disabled=true;			
			} else if ($('airline_select')) {
				$('airline_select').options[0].selected = true;
				$('airline_select').disabled=true;			
			} else if ($('car_rental_select')) {
				$('car_rental_select').options[0].selected = true;
				$('car_rental_select').disabled=true;			
			}		
		} else {
			$('country_select').disabled=false;	
		}
		
		// update the fields placeholder in deal summary section & fields values
		var type_ind = $('deal_type_select').selectedIndex;
		if(type_ind == 0) {
			$('type-placeholder').innerHTML = '';	// replace with blank, not 'Please select ...'
			Field.clear('type_id');
		} else {
			$('type-placeholder').innerHTML = $('deal_type_select').options[type_ind].text;
			$('type_id').value = $('deal_type_select').value;
		}
		
		// NB: no need to clear the hidden vars + others here as no other select boxes are linked to this one		
				
	} else if(val == 'country') {
	
		if($('city_select')) {
			$('city_select').options[0].selected = true;
			$('city_select').disabled=true;
		}
		if($('hotel_select')) {
			$('hotel_select').options[0].selected = true;
			$('hotel_select').disabled=true;
		}

		// update the fields placeholder in deal summary section & fields values
		var country_ind = $('country_select').selectedIndex;
		if(country_ind == 0) {
			$('country-placeholder').innerHTML = '';	// replace with blank, not 'Please select ...'
			Field.clear('country_id');
			$('country_id').checked = false;
		} else {
			$('country-placeholder').innerHTML = $('country_select').options[country_ind].text;
			$('country_id').value = $('country_select').value;
			$('country_id').checked = true;
		}
		
		// clear the hidden vars + others and if was addin a hotel deal, clear the company place holder end entity id
		$('province-placeholder').innerHTML = '';
		$('city-placeholder').innerHTML = '';
		Field.clear('province_id');
		$('province_id').checked = false;
		Field.clear('city_id');
		$('city_id').checked = false;
		if($('hotel_select')) {
			$('company-placeholder').innerHTML = '';		
			Field.clear('entity_id');
		}						
				
	} else if(val == 'city') {
	
		if($('hotel_select')) {
			$('hotel_select').options[0].selected = true;
			$('hotel_select').disabled=true;
		}
		
		// update the fields placeholder in deal summary section & fields values
		var city_ind = $('city_select').selectedIndex;
		if(city_ind == 0) {
			$('city-placeholder').innerHTML = '';	// replace with blank, not 'Please select ...'
			Field.clear('city_id');
			$('city_id').checked = false;
		} else {
			$('city-placeholder').innerHTML = $('city_select').options[city_ind].text;
			$('city_id').value = $('city_select').value;
			$('city_id').checked = true;
		}

		if($('hotel_select')) {
			$('company-placeholder').innerHTML = '';
			Field.clear('entity_id');
		}		
				
	} else {	// it will either be hotel, hotel chain, airline or car rental
	
		if($('hotel_select')) {	// user wants to add a hotel
			
			var ind = $('hotel_select').selectedIndex;
			$('company-placeholder').innerHTML = $('hotel_select').options[ind].text;
			$('entity_id').value = $('hotel_select').value;
			
		} else if($('hotel_chain_select')) {

			var ind = $('hotel_chain_select').selectedIndex;
			$('company-placeholder').innerHTML = $('hotel_chain_select').options[ind].text;
			$('entity_id').value = $('hotel_chain_select').value;
		
		} else if($('airline_select')) {

			var ind = $('airline_select').selectedIndex;
			$('company-placeholder').innerHTML = $('airline_select').options[ind].text;
			$('entity_id').value = $('airline_select').value;
		
		} else if($('car_rental_select')) {

			var ind = $('car_rental_select').selectedIndex;
			$('company-placeholder').innerHTML = $('car_rental_select').options[ind].text;
			$('entity_id').value = $('car_rental_select').value;
				
		}
	
	}	

}

function checkVlmDeal() {

	if($('vlm_deal').checked == false) {
		
		$('price').disabled = true;
		$('price').removeClassName('required');
		$('price').value="";
		new Effect.Fade('priceMsg', {duration: 0.0});
		
		$('deal_price').disabled = true;
		$('deal_price').removeClassName('required');
		$('deal_price').value="";
		new Effect.Fade('deal_priceMsg', {duration: 0.0});
		
		$('barter_quantity').disabled = true;
		$('barter_quantity').removeClassName('required');
		$('barter_quantity').value="";
		new Effect.Fade('barter_quantityMsg', {duration: 0.0});		
		
		$('barter_value').disabled = true;
		$('barter_value').removeClassName('required');
		$('barter_value').value="";
		new Effect.Fade('barter_valueMsg', {duration: 0.0});
								
	} else {
		$('price').disabled = false;
		$('price').addClassName('required');		
		$('deal_price').disabled = false;
		$('deal_price').addClassName('required');		
		$('barter_quantity').disabled = false;
		$('barter_quantity').addClassName('required');		
		$('barter_value').disabled = false;
		$('barter_value').addClassName('required');
	}

}

function clearDeal() {

	$('vlm_deal').checked = false;
	$('price').value = '';
	$('price').disabled = true;
	$('deal_price').value = '';
	$('deal_price').disabled = true;
	$('barter_quantity').value = '';
	$('barter_quantity').disabled = true;
	$('barter_value').value = '';
	$('barter_value').disabled = true;
  $('start_date').value = '';
  $('end_date').value = '';
  $('book_phone').value = '';
  $('book_web').value = '';
  $('book_email').value = ''; 
  $('meal_id').options[0].selected = true;
	$('status_select').options[0].selected = true; 
  $('deal_title').value = '';
  $('summary').value = '';
  $('description').value = '';
  
}

function openAllYrSwitch(val) {
	
	// executed if user clicks 'open_all_year' radio buttons
	if(val == 'y') {
		new Effect.Fade('open_fromTt', {duration: 0.0});
		new Effect.Fade('open_tillTt', {duration: 0.0});
		elmFade('seasonal_from');
		elmFade('seasonal_to');
	} else {
		elmAppear('seasonal_from');
		elmAppear('seasonal_to');
	}
	
}

function reviewCheck(val) {
	
	// executed from admin_authorise_form	
	if(val==1) {	// review-ok has been clicked		
		if($('review-error')) $('review-error').checked = false;		
	} else if(val==2) {	// review-error has been clicked	
		if($('review-ok')) $('review-ok').checked = false;
		if($('verify-hotel')) $('verify-hotel').checked = false;
		if($('send-verify-email')) $('send-verify-email').checked = false;		
	} else if(val==3) {	// verify-hotel OR send-verify-email has been clicked		
		if($('review-error')) $('review-error').checked = false;	
	} else if(val==4) {	// pass to admin has been clicked
	  if($('pass-to-user')) $('pass-to-user').checked = false;
	} else if(val==5) {	// pass to user has been clicked
	  if($('pass-to-admin')) $('pass-to-admin').checked = false;
	} else if(val==6) {	// err-email has been clicked
	  if($('gen-email')) $('gen-email').checked = false;
	} else if(val==7) {	// gen-email has been clicked
	  if($('err-email')) $('err-email').checked = false;
	}
	
}

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 goMyAccount() {	
	xajax_validateForm(xajax.getFormValues('myAccount'), getValidationFields('myAccount'), 'myAccount', 'updateUser');
}

function goNewPassword() {	
	xajax_validateForm(xajax.getFormValues('newPassword'), getValidationFields('newPassword'), 'newPassword', 'newPassword');
}

function goRooms() {
	xajax_editRooms(xajax.getFormValues('editRooms'));		
}

function goContact() {	
	xajax_validateForm(xajax.getFormValues('contact_us_form'), getValidationFields('contact_us_form'), 'contact_us_form', 'emailContactUs');
}

function goAddDeal() {	
	xajax_validateForm(xajax.getFormValues('deal-form'), getValidationFields('deal-form'), 'deal-form', 'addDeal');
}

function goUpdateDeal() {	
	xajax_validateForm(xajax.getFormValues('deal-form'), getValidationFields('deal-form'), 'deal-form', 'updateDeal');
}

function goCheckout() {	
	xajax_validateForm(xajax.getFormValues('cart_form'), getValidationFields('cart_form'), 'cart_form', null);
}

function newEditBox() {
	// Create a div window (see window.js). It will appear in center of page and remain so even during scrolling.
	// The div window has the id=edit-div and class=hp-edit (see default.css). The innerHTML of this 'floating' 
	// div can then be replaced with xajax to hold any forms etc
	if(!$('edit-div')) {	// if the edit win is not already open, create it
		var win = new Window('edit-div', {className: 'hp-edit', width:512, height:380, zIndex: 100, resizable:false, closable: false, minimizable:false, maximizable:false, draggable:false, showEffectOptions: {duration:0.1}}); 
		win.setDestroyOnClose();
		win.showCenter();
	}	
}
function closeEditBox() {
	var box;
	if(box=$('edit-div')) {
		box.remove();
	}	
}

function checkCheckout() {
	if($('agree_total').checked == true) {
		
		var str = $('cart_total').innerHTML;	
	  var iLen = String(str).length;	
		if(String(str).substring(iLen, iLen - 5) == ' 0.00') {
		  $('agree_total').checked = false;		
		} else {
			$('submit_checkout').disabled = false;
		  new Effect.Opacity($('submit_checkout'), {duration: 0.0,transition:Effect.Transitions.linear,from: 0.5,to: 1.0});
		}
		
	} else {
	  $('submit_checkout').disabled = true;
	  new Effect.Opacity($('submit_checkout'), {duration: 0.0,transition:Effect.Transitions.linear,from: 1.0,to: 0.5});
	}
}

function update_wp_amount() {

	var curr = $('currency').value;
	
	if(curr == 'GBP') {
		$('amount').value = $('MC_gbp_total').value;
		$('cart_total').innerHTML = 'GBP ' + $('MC_gbp_total').value;
	} else if(curr == 'EUR') {
	  $('amount').value = $('MC_eur_total').value;
		$('cart_total').innerHTML = 'EUR ' + $('MC_eur_total').value;
	} else {
	  $('amount').value = $('MC_usd_total').value;
		$('cart_total').innerHTML = 'USD ' + $('MC_usd_total').value;
	}
	
}

function update_wp_payment_type() {

	// reset the select box
	resetSelect('paymentType');
	
	// get the currently selected currency
	var curr = $('currency').value;
	
	// only display the compatible card types for the selected currency
	if(curr == 'EUR' || curr == 'USD') {
		for ( i = 0; i<=4; i++){
			var op = document.getElementById('paymentType');
			op.options[4] = null;
		}
	} else if(curr == 'GBP') {
			var op = document.getElementById('paymentType');
			op.options[4] = new Option('Visa Electron','VIED');
			op.options[5] = new Option('Visa purchasing','VISP');
			op.options[6] = new Option('JCB','JCB');
			op.options[7] = new Option('Solo','SOLO');
			op.options[8] = new Option('Maestro UK','SWIT');	
	}
	
}