// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
Effect.SlideRightOutOfView = function(element) {
  element = $(element);
  element.makeClipping();
  return new Effect.Scale(element, 0,
    Object.extend({ scaleContent: false, 
      scaleY: false, 
      restoreAfterFinish: true,
      afterFinishInternal: function(effect) {
        effect.element.remove().undoClipping();
      } 
    }, arguments[1] || {})
  );

}

SlidingBanner = Class.create();
Object.extend(SlidingBanner.prototype, {
  initialize: function(interval, pagesize, pagecount, containerelement, newpageurl, newpageparam, startpage, newstyle){
	this.interval = interval;
	this.page_size = pagesize;
    this.page_count = pagecount; 
	this.container_element = $(containerelement); 
	this.new_page_url = newpageurl; 
	this.new_page_param = newpageparam;
	this.current_page = startpage;
	this.newstyle = newstyle;
  },
  play: function(){
	new PeriodicalExecuter(function(pe) {
	  childs = $A(this.container_element.getElementsByClassName('slidingElement'));
	  if (childs.size()<(2*this.page_size)) {
		if (this.current_page==this.page_count) {
			this.current_page=0
		}
		this.current_page=this.current_page+1;
		req = this.new_page_url+"?"+this.new_page_param+"="+this.current_page;
		if (this.newstyle) {
			req = req+"&newstyle=1";
		}
		new Ajax.Request(req, {
		  method: 'get',
		  onSuccess: function(transport) {
			new Insertion.Bottom(this.container_element, transport.responseText);
		  }.bind(this)
		});		
	  }
	  var el = childs.find(function(e){
					return !e.hasClassName('fixed_banner');
			   });
	  new Effect.SlideRightOutOfView(el);
	}.bind(this), this.interval);
  }
});

SlidingStrip = Class.create();
Object.extend(SlidingStrip.prototype, {
  initialize: function(interval, containerelement, randomize, to_remove_on_start){
	
	// setup the callbacks
	this.pe_callback = this.append_to_container.bind(this);
	this.halt = this.stop.bindAsEventListener(this);
	this.go = this.start.bindAsEventListener(this);
	
	this.interval = interval;
	this.container = $(containerelement); 
	var childs = $A(this.container.getElementsByClassName('slidingElement'));
	
	//reordering the sliding elements
	if (randomize) {
		childs.sort(function() {return 0.5 - Math.random();});
		childs.each(function(e) {
			this.container.appendChild(e);			
		}.bind(this));
	}
	
	
	if ($(to_remove_on_start)) {
		new Effect.SlideRightOutOfView($(to_remove_on_start));
	}
  },
  animate: function(){
	//adding the hover effect
	this.container.observe('mouseover', this.halt)
	this.container.observe('mouseout', this.go)
	this.start();
  },
  start: function(){
	if (!this.pe) {
			this.pe = new PeriodicalExecuter(function(pe) {
			  var childs = $A(this.container.getElementsByClassName('slidingElement'))
			  new Effect.SlideRightOutOfView(childs[0], { afterFinishInternal: this.pe_callback });
			}.bind(this), this.interval);		
		}
  },
  stop: function(){
	if(this.pe) {
		this.pe.stop();
		this.pe = null;		
	}
  },
  append_to_container: function(effect) {
	this.container.appendChild(effect.element);
  }
});

FadingBanner = Class.create();
Object.extend(FadingBanner.prototype, {
  initialize: function(container, elements, interval, slice_size, container_static, sub_container_prefix, divider_div_class){
	this.halt = this.stop.bindAsEventListener(this);
	this.go = this.start.bindAsEventListener(this);

	this.container_elements = new Array();
	this.interval = interval;
	this.container = $(container);
	this.elements = $A(elements);
	this.elements.sort(function() {return 0.5 - Math.random();});
	this.current = 0;
	var idx = 0;
	this.elements.eachSlice(slice_size, function(sl){
		var d = Element.extend(document.createElement('div'));
		d.style.display = 'none'
		d.id = sub_container_prefix+"_"+idx;
		var cnt = 0;
		sl.each(function(el){
			d.appendChild(el);
			if (divider_div_class && cnt<(slice_size-1)) {
				new Insertion.Bottom(d, "<div class='"+divider_div_class+"'> </div>");
			}
			cnt = cnt+1;
		});
		this.container.appendChild(d);
		this.container_elements[idx] = d;
		idx = idx+1;
	}.bind(this));

	//adding the hover effect
	this.container.observe('mouseover', this.halt)
	this.container.observe('mouseout', this.go)

	$(container_static).hide();
	// this.container_elements[this.current].show();
	new Effect.Appear(this.container_elements[this.current], { queue: 'end', duration: 0.4 });
  },
  start: function(){
	if (this.container_elements.size()>1 && !this.pe) {
		this.pe = new PeriodicalExecuter(function(pe) {
		  	current_el = this.container_elements[this.current];
			this.current = (this.current+1)%this.container_elements.size();
		  	next_el = this.container_elements[this.current];
		  	new Effect.Fade(current_el, { queue: 'end', duration: 0.6 });
			new Effect.Appear(next_el, { queue: 'end', duration: 0.6 });
		}.bind(this), this.interval);		
	}
  },
  stop: function(){
	if(this.pe) {
		this.pe.stop();
		this.pe = null;		
	}
  }
});

function ajax_fading_banner(container_id, container_size, area) {
	Event.observe(window, 'load', function() {
	   new Ajax.Request('/p/cb/'+area, 
	       { asynchronous:true, 
			 method:'get',
			 onSuccess: function(transport) {
				new Insertion.Bottom(document.body, transport.responseText);
				cb = new FadingBanner(container_id, $$('#customer_banners_hidden .logo_sx'), 7, container_size, 'customer_banners_hidden', 'customer_banners', 'rigo3' ); 
				cb.start();
			 }.bind(this)
		   }
	   );		
	});
}
function ajax_redboxes(facets, terms) {
	Event.observe(window, 'load', function() {
	   new Ajax.Request('/p/f/'+facets+'?terms='+terms, 
	       { asynchronous:true, 
			 method:'get'
		   }
	   );		
	});
}

function do_search(base_url) {
  t = $F('terms');
  a = $F('search_area');
  r = $F('search_region');
  
  url = base_url
  if (a!="-1") {
	url += "/area_name-"+a;
  }
  if (r!="-1") {
	if (r=='estero') {
		url += "/offer_location_country-estero";
	} else {
		url += "/offer_location_region-"+r;
	}
  }
  if (t) {
	url += "?terms="+t
  }
/*  if (url == base_url) {
	alert("Seleziona almeno un criterio di ricerca.");
  } else {
*/	
	document.location = url
/*	$('cercaOfferte').action = url;
	$F('terms').value = '';
	$F('search_area').value = -1;
	$F('search_region').value = -1;
	$('cercaOfferte').submit();
  }
*/  
  return false;
}
function fill_skills_combo_for_category(category, profile_skill_id, object_id) {
	if (!profile_skill_id) {
		profile_skill_id = 'new';	
	}
	target_url = 'competenze;skills_for_category'
	if (object_id) {
		if (object_id == 'new_offer') {
			target_url = '/aziende/area-riservata/offerte/new/skills_for_category';	
		} else {
			target_url = object_id+'/'+target_url;				
		}
	}
	container_id = 'profile_skill_'+profile_skill_id+'_skills_container';
	if (category) {
	    new Ajax.Updater(container_id, target_url, 
	        {parameters: { category_id: category, profile_skill_id: profile_skill_id }, asynchronous:true, method:'get' }
	        );		
	}
	
}
function fill_regions_combo_for_country(country, profile_location_id, prefix, object_id ) {
	if (!profile_location_id) {
		profile_location_id = 'new';	
	}
	if(!prefix) {
		container_id = 'profile_location_'+profile_location_id+'_regions_container';		
	} else {
		container_id = prefix+'_location_'+profile_location_id+'_regions_container';
	}
	target_url = 'luoghi;regions_for_country'
	if (object_id) {
		if (object_id == 'new_offer') {
			target_url = '/aziende/area-riservata/offerte/new/regions_for_country';	
		} else {
			target_url = object_id+'/'+target_url;				
		}
	}
	if (country) {
	    new Ajax.Updater(container_id, target_url, 
	        {parameters: { country_id: country, profile_location_id: profile_location_id }, asynchronous:true, method:'get' }
	        );		
	}
	
}
function fill_provinces_combo_for_region(region, profile_location_id, prefix, object_id ) {
	if (!profile_location_id) {
		profile_location_id = 'new';	
	}
	if(!prefix) {
		container_id = 'profile_location_'+profile_location_id+'_provinces_container';
	}else{
		container_id = prefix+'_location_'+profile_location_id+'_provinces_container';		
	}
	target_url = 'luoghi;provinces_for_region'
	if (object_id) {
		if (object_id == 'new_offer') {
			target_url = '/aziende/area-riservata/offerte/new/provinces_for_region';	
		} else {
			target_url = object_id+'/'+target_url;				
		}
	}
	if (region) {
	    new Ajax.Updater(container_id, target_url, 
	        {parameters: { region_id: region, profile_location_id: profile_location_id }, asynchronous:true, method:'get' }
	        );		
	}
	
}
function fill_cities_for_province( province, object_id, for_profile_location ) {
	if (for_profile_location) {
		container_id = 'profile_location_new_cities_container';				
		target_url = 'luoghi;cities_for_province?province_id='+province;
		if (object_id) {
			if (object_id == 'new_offer') {
				target_url = '/aziende/area-riservata/offerte/new/cities_for_province?province_id='+province;	
			} else {
				target_url = object_id+'/'+target_url;				
			}
		}
	} else {
		container_id = 'candidate_cities_container';	
		target_url = '/candidati/'+object_id+'/cities_for_province/'+province;
	}
	if (province) {
	    new Ajax.Updater( container_id, target_url, 
						  {asynchronous:true, method:'get' }
	        			);		
	}
	
}
function fill_cities_for_province_on_area_aziende( province, container_id ) {
	target_url = '/aziende/area-riservata/cities_for_province?province_id='+province;
	if (province) {
	    new Ajax.Updater( container_id, target_url, 
						  {asynchronous:true, method:'get' }
	        			);		
	}
	
}
function fill_cities_for_province_on_admin( province, customer_id, container_id ) {
	target_url = '/admin/customer/cities_for_province/'+customer_id+'?province_id='+province;
	if (province) {
	    new Ajax.Updater( container_id, target_url, 
						  {asynchronous:true, method:'get' }
	        			);		
	}
	
}

function fill_study_subtypes_combo_for_type(type, profile_study_id, prefix) {
	if (!profile_study_id) {
		profile_study_id = 'new';	
	}
	if(!prefix) {
		container_id = 'profile_study_'+profile_study_id+'_subtypes_container';
	}else{
		container_id = prefix+'_study_'+profile_study_id+'_subtypes_container';
	}
	if (type) {
	    new Ajax.Updater(container_id, 'studi;subtypes_for_type', 
	        {parameters: { type_id: type, profile_study_id: profile_study_id }, asynchronous:true, method:'get' }
	        );		
	}
	
}

function fill_studies_combo_for_subtype(subtype, profile_study_id, prefix) {
	if (!profile_study_id) {
		profile_study_id = 'new';	
	}
	if(!prefix) {
		container_id = 'profile_study_'+profile_study_id+'_studies_container';
	}else{
		container_id = prefix+'_study_'+profile_study_id+'_studies_container';
		
	}
	if (subtype) {
	    new Ajax.Updater(container_id, 'studi;studies_for_subtype', 
	        {parameters: { subtype_id: subtype, profile_study_id: profile_study_id }, asynchronous:true, method:'get' }
	        );		
	}
	
}

function fill_studies_combo_for_type(type, profile_study_id, prefix, object_id) {
	if (!profile_study_id) {
		profile_study_id = 'new';	
	}
	if(!prefix) {
		container_id = 'profile_study_'+profile_study_id+'_studies_container';
	}else{
		container_id = prefix+'_study_'+profile_study_id+'_studies_container';
		
	}
	target_url = 'studi;studies_for_type';
	if (object_id) {
		if (object_id == 'new_offer') {
			target_url = '/aziende/area-riservata/offerte/new/studies_for_type';	
		} else {
			target_url = object_id+'/'+target_url;				
		}
	}
	if (type) {
	    new Ajax.Updater(container_id, target_url, 
	        {parameters: { type_id: type, profile_study_id: profile_study_id }, asynchronous:true, method:'get' }
	        );		
	}
	
}
function show_hide_notify_options(notify) {
	if(notify) {
		$('notify_suboptions').show();
	} else {
		$('notify_suboptions').hide();
	}
}
/*
function fill_profile_branches_for_sector(sector_id, profile_id) {
   if (sector_id&&sector_id!='' && sector_id!=undefined ) {
	   if (profile_id&&profile_id!='' && profile_id!=undefined ) {
		   new Ajax.Updater('branches_container', 'comparti;branches_for_sector', 
		       {parameters: { sector_id: sector_id }, asynchronous:true, method:'get' }
		       );		
	   }
   }
}
function fill_branches_for_sector(sector_id, action) {
   if (sector_id&&sector_id!='' && sector_id!=undefined ) {
	act = action
	if (!act) {
		act = 'esperienze';
	}
	   new Ajax.Updater('branches_container', act+';branches_for_sector', 
	       {parameters: { sector_id: sector_id }, asynchronous:true, method:'get' }
	       );		
   }
}
*/
function add_area_to_new_experience(area_id) {
	add = true;
	current_ids = $F('experience_area_ids');
	current_ids.scan(/\d+/, function(e){
		add = add && (e != area_id);
	});
	if(add) {
		new Insertion.Bottom('areas_selected', "<span id='selected_area_"+area_id+"'>"+areas_map[area_id]+" <a href='#' onclick=\"remove_area_from_new_experience("+area_id+");return false;\"><img src='/images/remove_facet.gif'></a></span>");
		$('experience_area_ids').value = current_ids+" "+area_id;
	}
}
function remove_area_from_new_experience(area_id) {
	remove = false;
	new_ids = '';
	$F('experience_area_ids').scan(/\d+/, function(e){
		if (e != area_id){
			new_ids = new_ids+" "+e;
		}
	});
	$('experience_area_ids').value = new_ids;
	if($("selected_area_"+area_id)) {
		$("selected_area_"+area_id).remove();
	}
}
function show_selected_job_definition(value){
	if (value) {
		$('selected_job_definition').innerHTML = 'Hai selezionato: <span>'+value+'</span>'
		if (!$('selected_job_definition').visible()) {
			$('selected_job_definition').show();
		}		
	} else {
		$('selected_job_definition').innerHTML = ''
		if ($('selected_job_definition').visible()) {
			$('selected_job_definition').hide();
		}		
	}
}
function show_alias_definition(text, element) {
	$('job_alias_description').innerHTML = '<p>'+element.attributes["job_alias_description"].value+'</p>';
}
function set_job_definition(text, element){
 var choosed = text.value;
 $("experience_job_title_id").value = element.attributes["job_title_id"].value;
 $("experience_job_definition").value = choosed;  
 show_selected_job_definition(choosed)
}
function all_areas(action) {
	act = action
	if (!act) {
		act = 'esperienze';
	}
	   new Ajax.Updater('areas_container', act+';areas_for_branch', 
	       {asynchronous:true, method:'get' }
	       );		
}
function fill_areas_for_branch(branch_id, action) {
   if (branch_id&&branch_id!='' && branch_id!=undefined ) {
	act = action
	if (!act) {
		act = 'esperienze';
	}
	   new Ajax.Updater('areas_container', act+';areas_for_branch', 
	       {parameters: { branch_id: branch_id }, asynchronous:true, method:'get' }
	       );		
   }
}
function fill_aliases_for_area(action, form_id) {
	$('all_aliases').value = '0';
	fill_aliases(action, form_id);
}
function load_all_aliases(action, form_id) {
	$('all_aliases').value = '1';
	fill_aliases(action, form_id);	
}
function fill_aliases(action, form_id) {
	act = 'esperienze';
	if(!form_id) {
		form_id = 'headhunter_job_title_form';
	}
	if (action) {
		act = action;
	}
   new Ajax.Request(act+';job_title_aliases', 
       {parameters: Form.serialize(form_id), asynchronous:true, method:'get' }
       );		
}
function fill_experience_description(selected_title){
   if (selected_title.value&&selected_title.value!='' && selected_title.value!=undefined ) {
		$('experience_job_definition').value = selected_title.text;	
		Element.update('description_container', job_descriptions_from_ajax[selected_title.value]);	
   } else {
		$('experience_job_definition').value = '';	
		Element.update('description_container','');		
   }
}

function fill_headhunter_job_description(selected_title){
   if (selected_title.value&&selected_title.value!='' && selected_title.value!=undefined ) {
		Element.update('description_container', job_descriptions_from_ajax[selected_title.value]);	
   }
}
var job_descriptions_from_ajax;

function show_loading(container) {
	$(container).innerHTML = '<img src="/images/ajax_small.gif" style="border:transparent 1px;" />'
}

function ajaxCalcolaIrpef2007() {
var lordo_value = document.getElementsByName("lordo").item(0).value;
var regione_value = document.getElementsByName("regione_appartenenza").item(0).value;
var coniugato_value = 0;
if( document.getElementsByName("con_coniuge").item(0).checked )  coniugato_value = 1;
var figli_min_3anni_value = document.getElementsByName("fgs3a").item(0).value;
var figli_mag_3anni_value = document.getElementsByName("fgs3to18").item(0).value;
var figli_mag_18anni_value = document.getElementsByName("fgs18a").item(0).value;
var perc_carico_figli_value = document.getElementsByName("fgperc").item(0).value;    
var altri_carico_value = document.getElementsByName("afac").item(0).value;

var params= 'lordo=' + lordo_value
        + '&regione=' + regione_value
        + '&con_coniuge=' + coniugato_value
       // + '&coniuge_a_carico=' + coniuge_a_carico_value
        + '&figli_min_3anni=' + figli_min_3anni_value
        + '&figli_mag_3anni=' + figli_mag_3anni_value
        + '&figli_mag_18anni=' + figli_mag_18anni_value

        + '&perc_carico_figli=' + perc_carico_figli_value
        + '&altri_carico=' + altri_carico_value;

return params

}
function open_region_in_home(id, name) {
   params = new Hash({ region_name: name, div: id });
   if ($('prov_'+id)) {
	  $('prov_'+id).toggle();
	  var i = $("im_"+id);
	  if( i.src.match(/freccia1\.jpg/) ) {
		i.src = '/images/freccia.jpg';
	  } else {
		i.src = '/images/freccia1.jpg';		
	  }
   } else {
	   new Ajax.Request('provinces_for_region', 
	       { parameters: params.toQueryString(), 
			 asynchronous:true, 
			 method:'get',
			 onSuccess: function(transport) {
				new Insertion.Bottom($(id), transport.responseText);
				$("im_"+id).src = '/images/freccia1.jpg';
			 }.bind(this)
		   }
	   );		
   }
	
}
function addBookmark(url,desc) {
	if(document.all) { window.external.AddFavorite(url, desc); } else if(window.sidebar) { window.sidebar.addPanel(desc, url, ''); } 
}

function show_signup_message(what) {
	if (what !== 'attesa') {
		$('signup_attesa').hide();
	}
	if (what !== 'risultato') {
		$('signup_risultato').hide();
	}
	if (what === 'attesa' || what === 'risultato') {
		$('signup_'+what).show();
	}
}
function check_login_at_signup(value, host){
	var pars = "username=" + encodeURIComponent(value) + "&timestamp=" + new Date().getTime();

	if ( !value.match(/^[a-zA-Z0-9]*$/) ) {
		Element.update("signup_risultato", '<H3 class="chk_user_fail">Nome utente non valido</H3>');
		show_signup_message('risultato');
	} else if (value != '') {
		//--- metto la gif di attesa
		show_signup_message('attesa');
		debugger
		//--- invoco il server, via AJAX
		var req = new Ajax.Request(	host+"/registrazione/ajaxService/"+value +"/chkUserId/uid",
									{ method: 'get', 
									  parameters: pars, 
									  onLoading: function () { }, 
									  onComplete: function(transport) {
										Element.update("signup_risultato", transport.responseText);
										show_signup_message('risultato');
									  }
									}
					              )
	} else {
		Element.update("signup_risultato", '<H3 class="chk_user_fail">Inserisci il Nome utente.</H3>');
		show_signup_message('risultato');
	}	
}

var message_redbox = new Template('	<div id="rb_bordo_superiore"><img src="/images/rb_bordo_sup_dx.gif"></div>'+
'	<div class="rb_body">'+
'		<#{title_tag}>#{redbox_title}<div class="rb_close"><a href="#" onclick="RedBox.close();return false;"><img src="/images/rb_close.gif"></a></div>'+
'		</#{title_tag}>'+
'		<div class="#{redbox_body_class}">'+
'    	#{message}'+
'		</div>'+
'		<div class="allunga"></div>'+
'	</div>'+
'	<div id="rb_bordo_inferiore"><img src="/images/rb_bordo_inf_dx.gif"></div>'
);

function show_message_redbox(message, options) {
	var opts = $H({ redbox_id: 'rb_messages', redbox_body_class: 'rb_content rb_message'});
	opts.merge(options);
	var title_tag = opts.redbox_title ? 'h3' : 'h5'
	var el = $(opts.redbox_id)
	if (!el) {
		el = Element.extend(document.createElement('div'));
		el.style.display = 'none';
		el.id = opts.redbox_id;
		Element.addClassName(el, "rb");
		document.body.appendChild(el);
	} 
	Element.update(el,message_redbox.evaluate({redbox_body_class: opts.redbox_body_class, redbox_title: opts.redbox_title, message: message, title_tag: title_tag}));
	setTimeout(function() {RedBox.showInline(el);}, 2); 
}

function show_box(box_id) {
	RedBox.showInline(box_id); 
	var p = new Flog.UriParser(window.location);
	pageTracker._trackPageview( "/redbox/"+box_id+p.pathname);
}

function track_links(offer_id) {
	links_to_attach = $$("a.candidacy_link"); 
	links_to_attach = links_to_attach.concat($$("#detail_container a"));
	links_to_attach.each(function(link){
		if(link && link.href ) {
			link.href = "/ca/"+offer_id+"?"+Hash.toQueryString({to: link.href});
			link.onclick = null;
		}		
	});
}
/**
 * FlogUriParser is freely distributable under the terms of an MIT-style license.
 * 
 * Copyright (c) 2006 Adam Burmister, Original author Poly9.com
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * ------------------------------------------------------------------------------------
 *
 * @author Adam Burmister, adam.burmister@gmail.com, www.flog.co.nz
 * @version 0.1
 * @namespace Flog
 *
 * Based on the Poly9.com url parser, modified to Prototype class and javascript conventions
 * 
 * Usage: var p = new Flog.UriParser('http://user:password@flog.co.nz/pathname?arguments=1#fragment');
 * p.host == 'flog.co.nz';
 * p.protocol == 'http';
 * p.pathname == '/pathname';
 * p.querystring == 'arguements=1';
 * p.querystring[arguements] | p.querystring.arguements == 1
 * p.fragment == 'fragment';
 * p.user == 'user';
 * p.password == 'password';
 *
 */

/* Fake a Flog.* namespace */
if(typeof(Flog) == 'undefined') var Flog = {};

Flog.UriParser = Class.create();

/* A prototype modification of poly9.com's original parser */
Flog.UriParser.prototype = {
	_regExp : /^((\w+):\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/,
	username : null,
	password : null,
	port : null,
	protocol : null,
	host : null,
	pathname : null,
	url : null,
	querystring : {},
	fragment : null,
	
	initialize: function(uri) {
		if(uri) this.parse(uri);	
	},
	
	_getVal : function(r, i) {
		if(!r) return null;
		return (typeof(r[i]) == 'undefined' ? null : r[i]);
	},
	
	parse: function(uri) {
		var r = this._regExp.exec(uri);
		if (!r) throw "FlogUriParser::parse -> Invalid URI"
		this.url		= this._getVal(r,0);
		this.protocol	= this._getVal(r,2);
		this.username	= this._getVal(r,4);
		this.password	= this._getVal(r,5);
		this.host		= this._getVal(r,6);
		this.port		= this._getVal(r,7);
		this.pathname	= this._getVal(r,8);
		this.querystring= new Flog.UriParser.QueryString(this._getVal(r,9));
		this.fragment	= this._getVal(r,10);
		return r;
	}
};

/* Querystring sub class */
Flog.UriParser.QueryString = Class.create();
Flog.UriParser.QueryString.prototype = {
	rawQueryString : '',
	length : 0,
	initialize : function(qs) {
		if(!qs) { 
			this.rawQueryString = '';
			this.length = 0;
			return;
		}
		this.rawQueryString = qs;
		var args = qs.split('&');
		this.length = args.length;
		for (var i=0;i<args.length;i++) {
			var pair = args[i].split('=');
			this[unescape(pair[0])] = ((pair.length == 2) ? unescape(pair[1]) : pair[0]);
		}
	},
	toString : function() {
		return this.rawQueryString;	
	}
};

function reload_menu_global() {
   new Ajax.Request('/menu_global', 
       { asynchronous:true, 
		 method:'get'
	   }
   );			
}

var Homebanner = Class.create();
Homebanner.prototype = {
  initialize: function() {
    this.current = 1;
	this.next = 1;
	this.pe = null;

	this.start();
  },
  show_next: function(){
	// gives the next image to insert
	this.next = (this.current+1)%3+1
	// $("big_box_"+this.current).hide();
	// $("big_box_"+this.next).show();
	new Effect.Fade($("big_box_"+this.current), { duration: 0.5 });
	new Effect.Appear($("big_box_"+this.next), { duration: 0.5, queue: 'end' });
	this.current = this.next;
	
  },
  start: function() {
	this.pe = new PeriodicalExecuter(this.show_next.bind(this), 6);
  }
}


function filter_offers(status, base) {
	
}