onloadLoader = function()
{
	var isSelectSelectedClicked = false;
	var isSelectSelected = false;
		
	document.getElementsByTagName("body")[0].onclick = function()
	{
		
		var documentULs = document.proSearch.getElementsByTagName("ul");
		for (var i=0; i<documentULs.length; i++)
		{
			if (documentULs[i].className.indexOf("select-open") != -1)
			{
				var objULselected = documentULs[i];

				isSelectSelected = true;
			}
		}

		if (isSelectSelected)
		{

			if (isSelectSelectedClicked && typeof objULselected != "undefined")
			{
				var lis = objULselected.getElementsByTagName('li');
				
				for (var ii=0; ii<lis.length; ii++)
					if (lis[ii].className.indexOf("selected") != -1)
						selectMe(lis[ii]);
			}
			else
			{
				isSelectSelectedClicked = true;
			}
		}
		else
		{
			isSelectSelectedClicked = false;
		}
	}
	
	var proSearchBtn = document.getElementById('pro-search-submit');

	var projectSelect = document.proSearch.project;
	var countrySelect = document.proSearch.country;
	
	proSearchBtn.className = "show";
	
	proSearchBtn.onclick = function()
	{
		if (projectSelect.value != "none" && countrySelect.value != "none")
		{
			var href = this.href + "?content=" + document.proSearch.project.value + "/" + document.proSearch.country.value + "/";
			this.href = href;
		}
		else if (projectSelect.value != "none")
		{
			var href = this.href + "?content=" + document.proSearch.project.value + "/";
			this.href = href;
		}
		else
		{
			var href = this.href;
			this.href = href;
		}
	}
	
	//
	optionsForProjectSelect = function()
	{
		var projectSelect = document.proSearch.project;
	
		removeOptionsFromSelect(projectSelect);
		
		var projects = proSearchJSON;
		
		for (var projectKey in projects)
		{
			var optionNode = document.createElement("option");
			var optionTxt = document.createTextNode(projects[projectKey]["caption"].replace(/\ and\ /, " & "));
			optionNode.value = projectKey;
			optionNode.appendChild(optionTxt);
			projectSelect.appendChild(optionNode);
		}
		
		selectRepl(projectSelect);
		
		projectSelect.onchange = function()
		{
			optionsForDestinationSelect();
		}
	}
	
	//
	optionsForDestinationSelect = function()
	{
		var destinationSelect = document.proSearch.country;
		
		removeOptionsFromSelect(destinationSelect);
		
		var projectSelecteded = document.proSearch.project.value;
		var destinations = proSearchJSON[projectSelecteded];
		
		for (var destinationKey in destinations)
		{
			if (destinationKey != "caption")
			{
				var optionNode = document.createElement("option");
				var optionTxt = document.createTextNode(destinations[destinationKey]["caption"].replace(/\&amp\;/, "&"));
				optionNode.value = destinationKey;
				optionNode.appendChild(optionTxt);
				destinationSelect.appendChild(optionNode);
			}
		}
		
		selectRepl(destinationSelect);
	}
	
	//
	removeOptionsFromSelect = function(selectObj)
	{
		if(selectObj.hasChildNodes())
		{
			while(selectObj.childNodes.length >= 1 && selectObj.lastChild.value !== "none")
			{
				selectObj.removeChild(selectObj.lastChild);
			}
		}
	}
	
	//
	resetCalculatedPriceBox = function()
	{
		calculatedPriceBox.value = calculatedPriceBoxDefault;
	}
	
	setClassAttribute = function(elem, valueAttr)
	{
		navigator.userAgent.indexOf('MSIE') != -1 ? elem.setAttribute("className", valueAttr) : elem.setAttribute("class", valueAttr);
	}
	
	getClassAttribute = function(elem)
	{
		classValue = navigator.userAgent.indexOf('MSIE') != -1 ? elem.getAttribute("className") : elem.getAttribute("class");
		return classValue != null ? classValue : "";
	}
	
	//
	selectRepl = function(obj)
	{
		if (obj.parentNode.getElementsByTagName("ul").length != 0)
		{
			obj.parentNode.removeChild(obj.parentNode.getElementsByTagName("ul")[0]);
		}
		
		obj.className += ' replaced';
		var ul = document.createElement('ul') ;
		ul.onmouseout = function()
		{
			this.className.replace(new RegExp(" select-open\\b"), '')
		}
		ul.className = 'select' ;
		var opts = obj.options ;
		for (var i=0; i<opts.length; i++)
		{
			var selectedOpt;
			if (opts[i].selected)
			{
				selectedOpt = i;
				break;
			}
			else
			{
				selectedOpt = 0;
			}
		}
		for (var i=0; i<opts.length; i++)
		{
			var li = document.createElement('li');
			var span = document.createElement('span');
			var txt = document.createTextNode(opts[i].text);
			li.appendChild(span);
			span.appendChild(txt);
			li.selIndex = opts[i].index;
			li.selectID = obj.id;
			li.onclick = function()
			{
				selectMe(this);
			}
			if (i == selectedOpt)
			{
				li.className = 'selected';
				li.onclick = function()
				{
					this.parentNode.className += ' select-open';
					this.onclick = function()
					{
						selectMe(this);
					}
				}
			}
			if (window.attachEvent)
			{
				li.onmouseover = function()
				{
					this.className += ' hover';
				}
				li.onmouseout = function()
				{
					this.className = this.className.replace(new RegExp(" hover\\b"), '') ;
				}
			}
			ul.appendChild(li);
		}
		
		obj.parentNode.insertBefore(ul,obj);
	}

	selectMe = function(obj)
	{
		
		var lis = obj.parentNode.getElementsByTagName('li');
		for (var i=0; i<lis.length; i++)
		{
			if (lis[i] != obj)
			{
				lis[i].className='';
				lis[i].onclick = function()
				{
					selectMe(this);
				}
			}
			else
			{
				setVal(obj.selectID, obj.selIndex);
				obj.className = 'selected';
				obj.parentNode.className = obj.parentNode.className.replace(new RegExp(" select-open\\b"), '') ;
				obj.onclick = function()
				{
					obj.parentNode.className += ' select-open';
					this.onclick = function()
					{
						selectMe(this);
					}
				}
			}
		}
		
		isSelectSelectedClicked = false;
		isSelectSelected = false;
		
	}

	setVal = function(objID, selIndex)
	{
		var obj = document.getElementById(objID) ;
		obj.selectedIndex = selIndex ;
		
		if (objID == "project")	optionsForDestinationSelect();
	}
	
	//
	optionsForProjectSelect();
	optionsForDestinationSelect();
}