/*ERROR loading file clouds.js*//*
 *
 * Copyright (c) 2006-2009 Sam Collett (http://www.texotela.co.uk)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version 2.2.4
 * Demo: http://www.texotela.co.uk/code/jquery/select/
 *
 * $LastChangedDate$
 * $Rev$
 *
 */
 
;(function($) {
 
/**
 * Adds (single/multiple) options to a select box (or series of select boxes)
 *
 * @name     addOption
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @type     jQuery
 * @example  $("#myselect").addOption("Value", "Text"); // add single value (will be selected)
 * @example  $("#myselect").addOption("Value 2", "Text 2", false); // add single value (won't be selected)
 * @example  $("#myselect").addOption({"foo":"bar","bar":"baz"}, false); // add multiple values, but don't select
 *
 */
$.fn.addOption = function()
{
	var add = function(el, v, t, sO)
	{
		var option = document.createElement("option");
		option.value = v, option.text = t;
		// get options
		var o = el.options;
		// get number of options
		var oL = o.length;
		if(!el.cache)
		{
			el.cache = {};
			// loop through existing options, adding to cache
			for(var i = 0; i < oL; i++)
			{
				el.cache[o[i].value] = i;
			}
		}
		// add to cache if it isn't already
		if(typeof el.cache[v] == "undefined") el.cache[v] = oL;
		el.options[el.cache[v]] = option;
		if(sO)
		{
			option.selected = true;
		}
	};
	
	var a = arguments;
	if(a.length == 0) return this;
	// select option when added? default is true
	var sO = true;
	// multiple items
	var m = false;
	// other variables
	var items, v, t;
	if(typeof(a[0]) == "object")
	{
		m = true;
		items = a[0];
	}
	if(a.length >= 2)
	{
		if(typeof(a[1]) == "boolean") sO = a[1];
		else if(typeof(a[2]) == "boolean") sO = a[2];
		if(!m)
		{
			v = a[0];
			t = a[1];
		}
	}
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase() != "select") return;
			if(m)
			{
				for(var item in items)
				{
					add(this, item, items[item], sO);
				}
			}
			else
			{
				add(this, v, t, sO);
			}
		}
	);
	return this;
};

/**
 * Add options via ajax
 *
 * @name     ajaxAddOption
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @type     jQuery
 * @param    String url      Page to get options from (must be valid JSON)
 * @param    Object params   (optional) Any parameters to send with the request
 * @param    Boolean select  (optional) Select the added options, default true
 * @param    Function fn     (optional) Call this function with the select object as param after completion
 * @param    Array args      (optional) Array with params to pass to the function afterwards
 * @example  $("#myselect").ajaxAddOption("myoptions.php");
 * @example  $("#myselect").ajaxAddOption("myoptions.php", {"code" : "007"});
 * @example  $("#myselect").ajaxAddOption("myoptions.php", {"code" : "007"}, false, sortoptions, [{"dir": "desc"}]);
 *
 */
$.fn.ajaxAddOption = function(url, params, select, fn, args)
{
	if(typeof(url) != "string") return this;
	if(typeof(params) != "object") params = {};
	if(typeof(select) != "boolean") select = true;
	this.each(
		function()
		{
			var el = this;
			$.getJSON(url,
				params,
				function(r)
				{
					$(el).addOption(r, select);
					if(typeof fn == "function")
					{
						if(typeof args == "object")
						{
							fn.apply(el, args);
						} 
						else
						{
							fn.call(el);
						}
					}
				}
			);
		}
	);
	return this;
};

/**
 * Removes an option (by value or index) from a select box (or series of select boxes)
 *
 * @name     removeOption
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @type     jQuery
 * @param    String|RegExp|Number what  Option to remove
 * @param    Boolean selectedOnly       (optional) Remove only if it has been selected (default false)   
 * @example  $("#myselect").removeOption("Value"); // remove by value
 * @example  $("#myselect").removeOption(/^val/i); // remove options with a value starting with 'val'
 * @example  $("#myselect").removeOption(/./); // remove all options
 * @example  $("#myselect").removeOption(/./, true); // remove all options that have been selected
 * @example  $("#myselect").removeOption(0); // remove by index
 * @example  $("#myselect").removeOption(["myselect_1","myselect_2"]); // values contained in passed array
 *
 */
$.fn.removeOption = function()
{
	var a = arguments;
	if(a.length == 0) return this;
	var ta = typeof(a[0]);
	var v, index;
	// has to be a string or regular expression (object in IE, function in Firefox)
	if(ta == "string" || ta == "object" || ta == "function" )
	{
		v = a[0];
		// if an array, remove items
		if(v.constructor == Array)
		{
			var l = v.length;
			for(var i = 0; i<l; i++)
			{
				this.removeOption(v[i], a[1]); 
			}
			return this;
		}
	}
	else if(ta == "number") index = a[0];
	else return this;
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase() != "select") return;
			// clear cache
			if(this.cache) this.cache = null;
			// does the option need to be removed?
			var remove = false;
			// get options
			var o = this.options;
			if(!!v)
			{
				// get number of options
				var oL = o.length;
				for(var i=oL-1; i>=0; i--)
				{
					if(v.constructor == RegExp)
					{
						if(o[i].value.match(v))
						{
							remove = true;
						}
					}
					else if(o[i].value == v)
					{
						remove = true;
					}
					// if the option is only to be removed if selected
					if(remove && a[1] === true) remove = o[i].selected;
					if(remove)
					{
						o[i] = null;
					}
					remove = false;
				}
			}
			else
			{
				// only remove if selected?
				if(a[1] === true)
				{
					remove = o[index].selected;
				}
				else
				{
					remove = true;
				}
				if(remove)
				{
					this.remove(index);
				}
			}
		}
	);
	return this;
};

/**
 * Sort options (ascending or descending) in a select box (or series of select boxes)
 *
 * @name     sortOptions
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @type     jQuery
 * @param    Boolean ascending   (optional) Sort ascending (true/undefined), or descending (false)
 * @example  // ascending
 * $("#myselect").sortOptions(); // or $("#myselect").sortOptions(true);
 * @example  // descending
 * $("#myselect").sortOptions(false);
 *
 */
$.fn.sortOptions = function(ascending)
{
	// get selected values first
	var sel = $(this).selectedValues();
	var a = typeof(ascending) == "undefined" ? true : !!ascending;
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase() != "select") return;
			// get options
			var o = this.options;
			// get number of options
			var oL = o.length;
			// create an array for sorting
			var sA = [];
			// loop through options, adding to sort array
			for(var i = 0; i<oL; i++)
			{
				sA[i] = {
					v: o[i].value,
					t: o[i].text
				}
			}
			// sort items in array
			sA.sort(
				function(o1, o2)
				{
					// option text is made lowercase for case insensitive sorting
					o1t = o1.t.toLowerCase(), o2t = o2.t.toLowerCase();
					// if options are the same, no sorting is needed
					if(o1t == o2t) return 0;
					if(a)
					{
						return o1t < o2t ? -1 : 1;
					}
					else
					{
						return o1t > o2t ? -1 : 1;
					}
				}
			);
			// change the options to match the sort array
			for(var i = 0; i<oL; i++)
			{
				o[i].text = sA[i].t;
				o[i].value = sA[i].v;
			}
		}
	).selectOptions(sel, true); // select values, clearing existing ones
	return this;
};
/**
 * Selects an option by value
 *
 * @name     selectOptions
 * @author   Mathias Bank (http://www.mathias-bank.de), original function
 * @author   Sam Collett (http://www.texotela.co.uk), addition of regular expression matching
 * @type     jQuery
 * @param    String|RegExp|Array value  Which options should be selected
 * can be a string or regular expression, or an array of strings / regular expressions
 * @param    Boolean clear  Clear existing selected options, default false
 * @example  $("#myselect").selectOptions("val1"); // with the value 'val1'
 * @example  $("#myselect").selectOptions(["val1","val2","val3"]); // with the values 'val1' 'val2' 'val3'
 * @example  $("#myselect").selectOptions(/^val/i); // with the value starting with 'val', case insensitive
 *
 */
$.fn.selectOptions = function(value, clear)
{
	var v = value;
	var vT = typeof(value);
	// handle arrays
	if(vT == "object" && v.constructor == Array)
	{
		var $this = this;
		$.each(v, function()
			{
      				$this.selectOptions(this, clear);
    			}
		);
	};
	var c = clear || false;
	// has to be a string or regular expression (object in IE, function in Firefox)
	if(vT != "string" && vT != "function" && vT != "object") return this;
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase() != "select") return this;
			// get options
			var o = this.options;
			// get number of options
			var oL = o.length;
			for(var i = 0; i<oL; i++)
			{
				if(v.constructor == RegExp)
				{
					if(o[i].value.match(v))
					{
						o[i].selected = true;
					}
					else if(c)
					{
						o[i].selected = false;
					}
				}
				else
				{
					if(o[i].value == v)
					{
						o[i].selected = true;
					}
					else if(c)
					{
						o[i].selected = false;
					}
				}
			}
		}
	);
	return this;
};

/**
 * Copy options to another select
 *
 * @name     copyOptions
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @type     jQuery
 * @param    String to  Element to copy to
 * @param    String which  (optional) Specifies which options should be copied - 'all' or 'selected'. Default is 'selected'
 * @example  $("#myselect").copyOptions("#myselect2"); // copy selected options from 'myselect' to 'myselect2'
 * @example  $("#myselect").copyOptions("#myselect2","selected"); // same as above
 * @example  $("#myselect").copyOptions("#myselect2","all"); // copy all options from 'myselect' to 'myselect2'
 *
 */
$.fn.copyOptions = function(to, which)
{
	var w = which || "selected";
	if($(to).size() == 0) return this;
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase() != "select") return this;
			// get options
			var o = this.options;
			// get number of options
			var oL = o.length;
			for(var i = 0; i<oL; i++)
			{
				if(w == "all" || (w == "selected" && o[i].selected))
				{
					$(to).addOption(o[i].value, o[i].text);
				}
			}
		}
	);
	return this;
};

/**
 * Checks if a select box has an option with the supplied value
 *
 * @name     containsOption
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @type     Boolean|jQuery
 * @param    String|RegExp value  Which value to check for. Can be a string or regular expression
 * @param    Function fn          (optional) Function to apply if an option with the given value is found.
 * Use this if you don't want to break the chaining
 * @example  if($("#myselect").containsOption("val1")) alert("Has an option with the value 'val1'");
 * @example  if($("#myselect").containsOption(/^val/i)) alert("Has an option with the value starting with 'val'");
 * @example  $("#myselect").containsOption("val1", copyoption).doSomethingElseWithSelect(); // calls copyoption (user defined function) for any options found, chain is continued
 *
 */
$.fn.containsOption = function(value, fn)
{
	var found = false;
	var v = value;
	var vT = typeof(v);
	var fT = typeof(fn);
	// has to be a string or regular expression (object in IE, function in Firefox)
	if(vT != "string" && vT != "function" && vT != "object") return fT == "function" ? this: found;
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase() != "select") return this;
			// option already found
			if(found && fT != "function") return false;
			// get options
			var o = this.options;
			// get number of options
			var oL = o.length;
			for(var i = 0; i<oL; i++)
			{
				if(v.constructor == RegExp)
				{
					if (o[i].value.match(v))
					{
						found = true;
						if(fT == "function") fn.call(o[i], i);
					}
				}
				else
				{
					if (o[i].value == v)
					{
						found = true;
						if(fT == "function") fn.call(o[i], i);
					}
				}
			}
		}
	);
	return fT == "function" ? this : found;
};

/**
 * Returns values which have been selected
 *
 * @name     selectedValues
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @type     Array
 * @example  $("#myselect").selectedValues();
 *
 */
$.fn.selectedValues = function()
{
	var v = [];
	this.selectedOptions().each(
		function()
		{
			v[v.length] = this.value;
		}
	);
	return v;
};

/**
 * Returns text which has been selected
 *
 * @name     selectedTexts
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @type     Array
 * @example  $("#myselect").selectedTexts();
 *
 */
$.fn.selectedTexts = function()
{
	var t = [];
	this.selectedOptions().each(
		function()
		{
			t[t.length] = this.text;
		}
	);
	return t;
};

/**
 * Returns options which have been selected
 *
 * @name     selectedOptions
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @type     jQuery
 * @example  $("#myselect").selectedOptions();
 *
 */
$.fn.selectedOptions = function()
{
	return this.find("option:selected");
};

})(jQuery);
/*
 * jQuery selectbox plugin
 *
 * Copyright (c) 2007 Sadri Sahraoui (brainfault.com)
 * Licensed under the GPL license and MIT:
 *   http://www.opensource.org/licenses/GPL-license.php
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * The code is inspired from Autocomplete plugin (http://www.dyve.net/jquery/?autocomplete)
 *
 * Revision: $Id$
 * Version: 0.6
 * 
 * Changelog :
 *  Version 0.6
 *  - Fix IE scrolling problem
 *  Version 0.5 
 *  - separate css style for current selected element and hover element which solve the highlight issue 
 *  Version 0.4
 *  - Fix width when the select is in a hidden div   @Pawel Maziarz
 *  - Add a unique id for generated li to avoid conflict with other selects and empty values @Pawel Maziarz
 */
jQuery.fn.extend({
	selectbox: function(options) {
		return this.each(function() {
			new jQuery.SelectBox(this, options);
		});
	}
});
if (!window.console) {
	var console = {
		log: function(msg) { 
	 	}
	}
}
/* */
jQuery.SelectBox = function(selectobj, options){
	var opt = options || {};
	var keys = [];
	var prevKey = false;
	var hasChanged = false;
	opt.formname = opt.formname || false;
	opt.inputClass = opt.inputClass || "selectbox";
	opt.inputSmallClass = opt.inputSmallClass || "selectbox_small";
	opt.containerClass = opt.containerClass || "selectbox-wrapper";
	opt.containerSmallClass = opt.containerSmallClass || "selectbox-wrapper_small";
	opt.extradivClass = opt.extradivClass || "selectbox-extradiv";
	opt.hoverClass = opt.hoverClass || "current";
	opt.currentClass = opt.selectedClass || "selected"
	opt.disabledClass = opt.disabledClass || "selectbox-disabled"
	opt.disabledSmallClass = opt.disabledSmallClass || "selectbox-disabled-small"
	opt.debug = opt.debug || false;
	opt.maxitems = opt.maxitems || 15;
	opt.scrollheight = opt.scrollheight || 200;
	
	var elm_id = selectobj.id;
	var disabled = selectobj.getAttribute('disabled');
	var small = false;
	if($(selectobj).hasClass('sort_list_small')) {
		var small = true;
	}
	
	if(opt.debug) console.log(disabled)
	var active = 0;
	var inFocus = false;
	var hasfocus = 0;
	//jquery object for select element
	var $select = $(selectobj);
	// jquery container object
	var $container = setupContainer(opt);
	//jquery input object 
	var $input = setupInput(opt);
	//var $extradiv = setupExtradiv(opt);
	// hide select and append newly created elements
	$select.hide().before($input).before($container);

	init();

	$input
	.click(function(){
    if (!inFocus) {
				if (opt.debug) console.log('click on : input');
			if(disabled=='disabled'||disabled == true) {
				$input.blur();
				return false;
			} else {
				$container.toggle();
			}
    }
	})


	//});
	/*.focus(function(){
	   if ($container.not(':visible')) {
	       inFocus = true;
	       $container.show();
	   }
	})*/
	.keydown(function(event) { 
		if (event.keyCode >= 48 && event.keyCode <= 90) {
			var i = 0;
			var match = false;
			$select.children('option').each(function() {
				if(String.fromCharCode(event.keyCode).toLowerCase() == $(this).text().charAt(0).toLowerCase()) {
					if(match == false) {
						if(i>0) {
							//$container.show();
							match = true;
							letterSelect(i);
						}
					}
				}
				i++;
			});
		} else {
			switch(event.keyCode) {
				case 38: // up
					event.preventDefault();
					moveSelect(-1);
					break;
				case 40: // down
					$container.show();
					event.preventDefault();
					moveSelect(1);
					break;

				case 13: // return
					event.preventDefault(); // seems not working in mac !
					$('li.'+opt.hoverClass).trigger('click');
					break;
				case 9: // tab
					if ($container.is(':visible')) {
						event.preventDefault(); // seems not working in mac !
						$('li.'+opt.hoverClass).trigger('click');
					}
					$input.focus();
					break;
				case 27: //escape
					hideMe();
					break;
			}
		}
	})
	.blur(function() {
		if ($container.is(':visible') && hasfocus > 0 ) {
			if(opt.debug) console.log('container visible and has focus')
		} else {
		  // Workaround for ie scroll - thanks to Bernd Matzner
		  if($.browser.msie || $.browser.safari){ // check for safari too - workaround for webkit
        if(document.activeElement.getAttribute('id').indexOf('_container')==-1){
          hideMe();
        } else {
          $input.focus();
        }
      } else {
        hideMe();
      }
		}
	});
	function hideMe() { 
		hasfocus = 0;
		$container.hide(); 
	}

	function init() {
		if(disabled=='disabled'||disabled == true) {
		} else {
			$container.append(getSelectOptions($input.attr('id'))).hide();
		}
		var width = $input.css('width');
    }
	
	function setupExtradiv(options) {
		var extradiv = document.createElement("div");
		$extradiv = $(extradiv);
		$extradiv.attr('id', elm_id+'_extradiv');
		$extradiv.addClass(options.extradivClass);
		return $extradiv;
	}
	function setupContainer(options) {
		var container = document.createElement("div");
		$container = $(container);
		$container.attr('id', elm_id+'_container');
		if($select.children('option').length >  opt.maxitems) {
			$container.css({height:opt.scrollheight,overflow:'auto',overflowX:'hidden'});
		}
		if(disabled=='disabled'||disabled == true) {
			$container.addClass(options.containerClass);
			$container.addClass(options.disabledClass).hide();
		} else {
		
		if(small) {
			$container.addClass(options.containerClass);
			$container.addClass(options.containerSmallClass);
		} else {
			$container.addClass(options.containerClass);
		}
		}
		return $container;
	}
	function setupInput(options) {
		var input = document.createElement("input");
		var $input = $(input);
		$input.attr("id", elm_id+"_input");
		$input.attr("type", "text");
		if(disabled=='disabled'||disabled == true) {
			$input.addClass(options.inputClass);
			$input.addClass(options.disabledClass);
			if(small) {
				$input.addClass(options.disabledSmallClass);
			}
			$select.children('option').each(function() {
			if ($(this).is(':selected')) {
				$input.val($(this).text());
				//$(li).addClass(opt.currentClass);
			}
			});

		} else {
			if(small) {
				$input.addClass(options.inputClass);
				$input.addClass(options.inputSmallClass);
			} else {
				$input.addClass(options.inputClass);
			}
		}
		$input.attr("autocomplete", "off");
		$input.attr("readonly", "readonly");
		$input.attr("tabIndex", $select.attr("tabindex")); // "I" capital is important for ie
		
		return $input;	
	}

	function moveSelect(step) {
		var lis = $("li", $container);
		if (!lis || lis.length == 0) return false;
		active += step;
    //loop through list
		if (active < 0) {
			active = lis.size();
		} else if (active > lis.size()) {
			active = 0;
		}

    scroll(lis, active);
		lis.removeClass(opt.hoverClass);
		$(lis[active]).addClass(opt.hoverClass);
		if(active < lis.length) {
			var fl = $('li.'+opt.hoverClass, $container).get(0);
			$input.val($(fl).text());
			hasChanged = true;
			console.log(hasChanged);
		}
	}

	function letterSelect(itemno) {
		var lis = $("li", $container);
		if (!lis || lis.length == 0) return false;
		lis.removeClass(opt.hoverClass);
		lis.removeClass(opt.selectedClass);
		$(lis[itemno]).addClass(opt.hoverClass);
    scroll(lis, itemno);
	active = itemno;
		if(active < lis.length) {
			var fl = $('li.'+opt.hoverClass, $container).get(0);
			$input.val($(fl).text());
			var el = fl.getAttribute('rel');
			$select.val(el);
			hasChanged = true;
			console.log(hasChanged);
			$(document).click(function(event) {
				if(event.target.className.search(/selectbox/)!= 0) {
					$select.change();
				}
			});
		}
	}

	function scroll(list, active) {
      var el = $(list[active]).get(0);
      var list = $container.get(0);
      
      if (el.offsetTop + el.offsetHeight > list.scrollTop + list.clientHeight) {
        list.scrollTop = el.offsetTop + el.offsetHeight - list.clientHeight;      
      } else if(el.offsetTop < list.scrollTop) {
        list.scrollTop = el.offsetTop;
      }
	}
	
	function setCurrent() {	

		var li = $("li."+opt.currentClass, $container).get(0);
		//var ar = (''+li.id).split('_');
		var el = li.getAttribute('rel');
		$select.val(el);
		$input.val($(li).text());
		return true;
	}
	
	// select value
	function getCurrentSelected() {
		return $select.val();
	}
	
	// input value
	function getCurrentValue() {
		return $input.val();
	}
	function getSelectOptions(parentid) {
		var select_options = new Array();
		var ul = document.createElement('ul');
		$select.children('option').each(function() {
			keys.push($(this).text().charAt(0).toLowerCase());
			var li = document.createElement('li');
			li.setAttribute('id', parentid + '_' + $(this).val());
			li.setAttribute('rel', $(this).val());
			li.innerHTML = $(this).html();
			if ($(this).is(':selected')) {
				$input.val($(this).text());
				$(li).addClass(opt.currentClass);
			}
			ul.appendChild(li);
			$(li)
			.mouseover(function(event) {
				hasfocus = 1;
				if (opt.debug) console.log('over on : '+this.id);
				jQuery(event.target, $container).addClass(opt.hoverClass);
			})
			.mouseout(function(event) {
				hasfocus = -1;
				if (opt.debug) console.log('out on : '+this.id);
				jQuery(event.target, $container).removeClass(opt.hoverClass);
			})
			.click(function(event) {
			  var fl = $('li.'+opt.hoverClass, $container).get(0);
				if (opt.debug) console.log('click on :'+this.id);
				$('li.'+opt.currentClass).removeClass(opt.currentClass); 
				$(this).addClass(opt.currentClass);
				setCurrent();
				$select.change();
				$select.get(0).blur();
				if(opt.formname){
					document.getElementById(opt.formname).submit();
				}
				hideMe();
			});
		});
		return ul;
	}
};
function registerDropDownClickEvents(){
	$('#countrySelect_input').click(
		function(eventObject, element){
      if (eventObject) eventObject.cancelBubble = true;
      if (eventObject.stopPropagation) eventObject.stopPropagation();
			setPagemenuOverflow((document.getElementById('countrySelect_container').style.display == 'block' ? 'visible' : 'hidden'));
		}
	);
	$('#expertiseSelect_input').click(
		function(eventObject, element){
      if (eventObject) eventObject.cancelBubble = true;
      if (eventObject.stopPropagation) eventObject.stopPropagation();
			setPagemenuOverflow((document.getElementById('expertiseSelect_container').style.display == 'block' ? 'visible' : 'hidden'));
		}
	);
	$(document.body).click(
		function(element){
			setPagemenuOverflow('hidden');
		}
	);
}
$(function(){
	registerDropDownClickEvents();
});

function setPagemenuOverflow(overflow){
	document.getElementById('pagemenu').style.overflow = overflow;
}

function countryGetExpertises(selectedValue) {
	if(selectedValue.value == ''){
		setAllExpertises();
	}
	else {
		var selected = $("#expertiseSelect")[0].value;
		$("#expertiseSelect").removeOption(/./);
		for (expertise in countries[selectedValue.value].expertises){
			$("#expertiseSelect").addOption(countries[selectedValue.value].expertises[expertise].id, countries[selectedValue.value].expertises[expertise].value);
		}
		$("#expertiseSelect_input").remove();
		$("#expertiseSelect_container").remove();
		$("#expertiseSelect").selectOptions(selected);
		$('#expertiseSelect').selectbox();
		registerDropDownClickEvents();
	}
}

function expertiseGetCountries(selectedValue){
	if(selectedValue.value == ''){
		setAllCountries();
	}
	else{
		var selected = $("#countrySelect")[0].value;
		$("#countrySelect").removeOption(/./);
		for (county in expertises[selectedValue.value].countries){
			$("#countrySelect").addOption(expertises[selectedValue.value].countries[county].id, expertises[selectedValue.value].countries[county].value);
		}
		$("#countrySelect_input").remove();
		$("#countrySelect_container").remove();
		$("#countrySelect").selectOptions(selected);
		$('#countrySelect').selectbox();
		registerDropDownClickEvents();
	}
}

function setAllCountries(){
	var selected = $("#countrySelect")[0].value;
	$("#countrySelect").removeOption(/./);
	for (county in allCountries){
		$("#countrySelect").addOption(allCountries[county].id, allCountries[county].value);
	}
	$("#countrySelect_input").remove();
	$("#countrySelect_container").remove();
	$("#countrySelect").selectOptions(selected);
	$('#countrySelect').selectbox();
	registerDropDownClickEvents();
}

function setAllExpertises(){
	var selected = $("#expertiseSelect")[0].value;
	$("#expertiseSelect").removeOption(/./);
	for (expertise in allExpertises){
		$("#expertiseSelect").addOption(allExpertises[expertise].id, allExpertises[expertise].value);
	}
	$("#expertiseSelect_input").remove();
	$("#expertiseSelect_container").remove();
	$("#expertiseSelect").selectOptions(selected);
	$('#expertiseSelect').selectbox();
	registerDropDownClickEvents();
}

function validate(){
	if($("#countrySelect")[0].value == '' || $("#expertiseSelect")[0].value == ''){
		if($("#countrySelect")[0].value == ''){
			$("#countryError").addClass("error");
		}
		else{
			$("#countryError").removeClass("error");
		}
		if($("#expertiseSelect")[0].value == ''){
			$("#expertiseError").addClass("error");
		}
		else{
			$("#expertiseError").removeClass("error");
		}
		$(".errortext").show();
	}
	else{
		$("#jobSearch").submit();
	}
	return false;
}
