function toUrl(url) {
	return '/'+window._current_language_code+url;
}

function toParams(parameters) {
	if(typeof(parameters) == 'string') {
		return parameters+'&authenticity_token='+window._authenticity_token;
	} else if(typeof parameters == 'object'){
		parameters['authenticity_token'] = window._authenticity_token;
		return $H(parameters).toQueryString();
	} else {
		return 'authenticity_token='+window._authenticity_token;
	}
}

function removeSelectOption(select, value) {
	var option = $A(select.options).find(function(option) { return option.value == value; });
	option = null;
}

function addSelectOption(select, text, value, selected) {
	select.options[select.options.length] = new Option(text, value, false, selected);
}

function selectSelectOption(select, value) {
	var option = $A(select.options).find(function(option) { return option.value == value; });
	option.selected = true;
}

function attachFleurons(element) {
	var fleuronWidth = 51;
	var fleuronHeight = 12;
	var paddingHorizontal = 10;
	var paddingVertical = 5;
	
	var element = $(element);
	var fleuronLeft = new Element('span', { 'class': 'fleuron_left_transparent' });
	var fleuronRight = new Element('span', { 'class': 'fleuron_right_transparent' });
	
	// the span is only used to determine the size of the text
	var span = element.down('span');
	var offset = span.positionedOffset();
	span.insert({ before: fleuronLeft, after: fleuronRight });
	fleuronLeft.setStyle({ left: (offset.left-fleuronWidth-paddingHorizontal)+'px', top: (offset.top+paddingVertical)+'px' });
	fleuronRight.setStyle({ left: (offset.left+span.getWidth()+paddingHorizontal)+'px', top: (offset.top+paddingVertical)+'px' });
}

function loadScript(sScriptSrc, callbackfunction)   
{  
  // gets document head element  
  var oHead = document.getElementsByTagName('head')[0];  
  if(oHead)  
  {  
    // creates a new script tag        
    var oScript = document.createElement('script');  
              
    // adds src and type attribute to script tag  
    oScript.setAttribute('src',sScriptSrc);  
    oScript.setAttribute('type','text/javascript');  

    // calling a function after the js is loaded (IE)  
    var loadFunction = function()  
    {  
      if (this.readyState == 'complete' || this.readyState == 'loaded')  
      {  
        callbackfunction();   
      }  
    };  
    oScript.onreadystatechange = loadFunction;  

    // calling a function after the js is loaded (Firefox)  
    oScript.onload = callbackfunction;  
      
    // append the script tag to document head element          
    oHead.appendChild(oScript);  
  }  
}  

function resizeBannerContainer() {
	$('banner_container').addClassName('squished');
}

function changeUrl(url) {
	window.location.href = url;
}

Event.observe(document, 'dom:loaded', function() {
	// empty "ask us" text area on click
	if($('ask_us')) {
		var textArea = $('ask_us').down('textarea');
		defaultAskUsValue = textArea.value;
		textArea.observe('click', function() {
			if(this.value == defaultAskUsValue) {
				this.value = '';
			}
		});
	}
	
	// make language selection links respect link data after the hash
	if($('language_selection')) {
		$('language_selection').select('a').each(function(link) {
			link.observe('click', function(event) {
				Event.stop(event);
				var hash = typeof dhtmlHistory !== 'undefined' ? '#'+dhtmlHistory.getCurrentLocation() : '';
				window.location.href = this.href + hash;
			});
		});
	}
});