
	var titleClickedOnce=false;
	function setTitle() {
		if (!titleClickedOnce) { $("reviewsummary").value=""; }
		$("reviewsummary").className=' clicked';
		titleClickedOnce=true;
	}

	function doClicked(clickedNode) {
		containingElem=clickedNode.parentNode.parentNode

		var aNodes = containingElem.getElementsByTagName('a');
		for (i=0; i<aNodes.length; i++){
		   aNodes[i].className=aNodes[i].className.replace("clicked","");
		}
		clickedNode.className+=" clicked"
		fieldName=clickedNode.parentNode.parentNode.id.replace("_list","");
		$(fieldName).value=clickedNode.innerHTML;

		clearError(fieldName+"_label");

		var outof=0;
		sc_atmosphere=parseInt($F("atmosphere"));
		if (sc_atmosphere>0) { outof++; }
		sc_friendliness=parseInt($F("friendliness"));
		if (sc_friendliness>0) { outof++; }
		sc_location=parseInt($F("location"));
		if (sc_location>0) { outof++; }
		sc_cleanliness=parseInt($F("cleanliness"));
		if (sc_cleanliness>0) { outof++; }
		sc_facilities=parseInt($F("facilities"));
		if (sc_facilities>0) { outof++; }
		sc_security=parseInt($F("security"));
		if (sc_security>0) { outof++; }
		sc_valueformoney=parseInt($F("valueformoney"));
		if (sc_valueformoney>0) { outof++; }

		var score=sc_atmosphere+sc_friendliness+sc_location+sc_cleanliness+sc_facilities+sc_security+sc_valueformoney;
		score=score/outof;
		score=score.toFixed(1)
		$("totalscore").innerHTML=score
		$("overall").style.display="block"

		return false;

	}

	function clearError(id) {
		$(id).className=$(id).className.replace(/errormsg/g,"")
	}

	function GetXmlHttpObject()
	{
		var xmlHttp=null;

		try
		{
		// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
		// Internet Explorer
			try
			{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}

		return xmlHttp;
    }

function chooseCity(countrySelect) {

	//get the td above the select, and the span in that
	countryCell 	= countrySelect.parentNode;
	cityContainer	= countryCell.getElementsByTagName('span');
	cityContainer	= cityContainer[0];

	//get the incremental value of this select for form population
	var count = countrySelect.name.replace(/\D/g, '');

	//populate city select
	if (countrySelect.selectedIndex == 0) {
		cityContainer.innerHTML = '';
	}

	else {
		var postVars = 'ajax=1&country=' + countrySelect.value + '&count=' + count;
		new Ajax.Updater(cityContainer, '?', {method: 'post', postBody: postVars, onLoading:whenLoading, onSuccess:whenComplete, evalScripts:true, onComplete:getAccom(count)});
	}

	//populate overall country impressions
	//country changed? remove existing block
	if ($('overall_country_' + count) != undefined && count) {
		$('overall_country_' + count).remove();
		try {
			$('overall_city_' + count).remove();
		}
		catch(e) {}
	}

	if (countrySelect.value != '') {
		//test for duplicates
		var existingCountries 	= $$('.destination_country');
		var addSection 			= false;
		var matches				= 0;

		for (i=0;i<existingCountries.length;i++) {
			if (existingCountries[i].value == countrySelect.value) {
				matches++;
			}
		}


	}
}

function getAccom(count) {
	var list = $$('.destination_city');

	var cities = '';

	for (i=0;i<list.length;i++) {
		cities += '&city[]=' + list[i].value;
	}

	if (cities != '') {
		var postVars = 'ajax=1&' + cities;
		new Ajax.Request('?type=prop', {method: 'post', postBody: postVars, onLoading: whenLoading, onSuccess:whenComplete, evalScripts:true, onComplete:updateAcom});

		//populate overall city impressions
		if ($('overall_city_' + count) != undefined && count) {
			$('overall_city_' + count).remove();
		}

		//test for duplicates
		var existingCities 	= $$('.destination_city');
		var addSection 		= false;
		var matches			= 0;

		var citySelect = document.getElementsByName('destination[' + count + '][city]');

		if (citySelect.length > 0) {
			citySelect = citySelect[0];

			for (i=0;i<existingCities.length;i++) {
				if (existingCities[i].value == citySelect.value) {
					matches++;
				}
			}

		}
	}
}

function updateAcom(ajax) {
	var response	= ajax.responseText;
	var containers	= $$('.cont_proploc');

	for (i=0;i<containers.length;i++) {
		//todo: test for existing selection, if exists save, apply new HTML and try to re-add
		//existingSelect 	= accomContainers[i].getElementsByTagName('select');
		containers[i].innerHTML = response;
	}
}

function whenLoading() {
	var offset 	= Position.page($('loading'));
	offset		= offset.toArray();
	offset 		= offset[1] * -1;
	$('loading').style.top 		= offset + 'px';
	$('loading').style.display 	= 'block';
}

function whenComplete() {
	setTimeout('hideLoading()', 500);
}

function hideLoading() {
	$('loading').style.display = 'none';
}

function getDateObject(dateString,dateSeperator) {
	//This function return a date object after accepting
	//a date string ans dateseparator as arguments
	var curValue=dateString;
	var sepChar=dateSeperator;
	var curPos=0;
	var cDate,cMonth,cYear;

	//extract day portion
	curPos=dateString.indexOf(sepChar);
	cDate=dateString.substring(0,curPos);

	//extract month portion
	endPos=dateString.indexOf(sepChar,curPos+1);
	cMonth=dateString.substring(curPos+1,endPos);
	cMonth--;
	//extract year portion
	curPos=endPos;
	endPos=curPos+5;
	cYear=curValue.substring(curPos+1,endPos);

	//Create Date Object
	dtObject=new Date(cYear,cMonth,cDate);
	return dtObject;
}

