    function getAjaxBaseURL()
    {
    	var urlArray = location.href.match(/(https?:\/\/[^\/]*\/[^\/]*\/?).*/);
    	var baseURL = RegExp.$1;
    	if (baseURL.substring(baseURL.length-1) != '/')
    	{
    		baseURL += '/';
    	}
			
			//if(location.href.match(document.dev1) || location.href.match(document.dev2))
				//return location.href.match(/.*[^index.php&]/);
			//else
    		return baseURL;
    }
    
    function getTourBaseURL()
    {
    	var urlArray = location.href.match(/(https?:\/\/.*\/[^\?]*\/?)\??.*/);
    	
    		return RegExp.$1;
    }
    
	var dropdownHandler =
  	{
  		clearDropdown: function(dropdown)
  		{
  	  		var i;
  	  		for(i=dropdown.options.length-1; i>=0; i--)
  	  		{
  	  			dropdown.remove(i);
  	  		}
  		},
		
      	fillDropdown: function(dropdown, options)
      	{
      		var i;
      		for(var i in options)
      		{
      			dropdown.options.add(options[i]);
      		}
      	},

      	setLoading: function(dropdown)
      	{
      		if (!dropdown.options[0])
      		{
      			this.resetDropdown(dropdown, 'Loading...');
	      	  	dropdown.disabled = true;
      		}
      		else
      		{
	    		dropdown.options[0].text = 'Loading...';
	      	  	dropdown.disabled = true;
	      	  	dropdown.selectedIndex = 0;
      		}
      	},
      	
		resetDropdown: function(dropdown, text)
		{
    		var firstOption = document.createElement('option');
    		firstOption.value = '0';
    		firstOption.text = text;
        		
    		this.clearDropdown(dropdown);
    		dropdown.options.add(firstOption);
		}
  	}
  	
  	function getStates(country)
  	{
        dropdownHandler.resetDropdown(document.form.sel_locCity,
                					  'Select a state/prov first');
		dropdownHandler.setLoading(document.form.sel_locState);
		
  	  	$.ajax({ type: "POST", url: getAjaxBaseURL(), 
  	  		     data: "action=ll&sel_locCountry=" + country.value,
				   success: function(xml) {
						var states = [];
	                    $(xml).find('state_list').find('option').each(function(){
	                    state = document.createElement("option");
	                    state.value = $(this).attr('value');
	                    state.text = $(this).text();
						states.push(state);
	                    });
              	        dropdownHandler.resetDropdown(document.form.sel_locState,
													  'Select a state/prov');
						dropdownHandler.fillDropdown(document.form.sel_locState,
													 states);
						document.form.sel_locState.disabled = false;
	                     }
	                    });
  	}

  	function getCities(country, state)
  	{
		dropdownHandler.setLoading(document.form.sel_locCity);
  	  	$.ajax({ type: "POST", url: getAjaxBaseURL(), 
  	  	  	     data: "action=ll&sel_locCountry=" + country.value + 
  	  	  	           "&sel_locState=" + state.value,
				 success: function(xml) {
						var cities = [];
	                    $(xml).find('city_list').find('option').each(function(){
	                    city = document.createElement("option");
	                    city.value = $(this).attr('value');
	                    city.text = $(this).text();
						cities.push(city);
	                    });
              	        dropdownHandler.resetDropdown(document.form.sel_locCity,
						  							  'Select a city');
						dropdownHandler.fillDropdown(document.form.sel_locCity,
								 					 cities);
						document.form.sel_locCity.disabled = false;
	                     }
	                    });
  	}

  	function getSexualOrientations(i_am, looking_for)
  	{
  	  	var len = looking_for.length;
  	  	var preferences = [];
  	  	for (var i in looking_for)
  	  	{
  	  	  	if (looking_for[i].checked)
  	  	  	{
  	  	  	  	preferences.push(looking_for[i].value);
  	  	  	}
  	  	}
  	  	if (preferences.length == 0)
  	  	{
  	  	  	dropdownHandler.resetDropdown(document.form.sel_orientation_1,
										  'Select looking for first');
  	  	  	dropdownHandler.resetDropdown(document.form.sel_orientation_2,
				  						  'Select looking for first');
  	  	}
  	  	else
  	  	{
    		dropdownHandler.setLoading(document.form.sel_orientation_1);
    		dropdownHandler.setLoading(document.form.sel_orientation_2);
      	  	$.ajax({ type: "POST", url: getAjaxBaseURL(), 
    	  	  	     data: "action=ol&sel_gender=" + i_am.value + 
    	  	  	     "&cbx_genderPreference[]=" +
    	  	  	 	 preferences.join('&cbx_genderPreference[]='),
    			 success: function(xml) {
    				   var dropdowns = [document.form.sel_orientation_1,
    				 				    document.form.sel_orientation_2];
    				   var i = 0;
                       $(xml).find('orientation_list').each(function(){
    					   var orientations = [];
                    	   var dropdown = dropdowns[i];
                           $(this).find('option').each(function(){
                       orientation = document.createElement("option");
                       orientation.value = $(this).attr('value');
                       orientation.text = $(this).text();
    				   orientations.push(orientation);
                       });
                        dropdownHandler.clearDropdown(dropdown);
    					dropdownHandler.fillDropdown(dropdown, orientations);
    					i++;
                        })
                        for (var j in dropdowns)
                        {
                        	dropdowns[j].disabled = false;
                        }
      	  		}
      	  	});
  	  	}
  	}
  	
  	function checkCouples(gender)
  	{
  	  	var partnerProfile = document.getElementById('partnerProfile');
  	  	var formDiv = document.getElementById('formDiv');
  	  	if (gender.options[gender.selectedIndex].value > 2)
  	  	{
  	  	  	formDiv.className = 'form h_600';
  	  	  	partnerProfile.style.display = 'block';
  	  	}
  	  	else
  	  	{
  	  	  	formDiv.className = 'form h_564';
  	  	  	partnerProfile.style.display = 'none';
  	  	}
  	}
  	

