function textar1(idtext,text){
	if (document.getElementById(idtext).value==''){
		document.getElementById(idtext).className='maigri';
		document.getElementById(idtext).value=text;
	}
}

function textar(idtext){
	document.getElementById(idtext).value='';
	document.getElementById(idtext).className='mainegru';
}

var ExpandCollapse=Class.create({
	initialize:function(ec_elem){
		var self=this;
		this.ec_elem=ec_elem;
		this.ec_content=$(this.ec_elem.readAttribute('id')+'_content');
		this.ec_elem.setStyle({cursor:'pointer'});

		if(this.ec_elem.readAttribute('type')=="radio"){
			radio_elems=$$('input[name='+this.ec_elem.readAttribute('name')+']');
			radio_elems.each(function(r_elem){
				Event.observe(r_elem, 'click', self.showHide.bindAsEventListener(self))
			})
		}
		else
			Event.observe(this.ec_elem, 'click', this.showHide.bindAsEventListener(this))
	},

	showHide:function(event){
		var self=this;
		if(Effect.Queue.effects.length!=0){
			return false;
		}
		ec_elem=event.element();
		if(this.ec_content!=undefined){
			if(ec_elem.hasClassName('ec-trigger')){
				event.stop();
				new Effect.toggle(this.ec_content, 'blind',{
					duration:0.5,
					afterFinish:function(){
						ec_elem.checked=self.ec_content.visible();
					}
				})
			}
			else
				this.ec_content.hide()			
		}
	}
});

Event.observe(window,'load',function(){
	/* Pentru close button la notices
	--------------------------------------------------------*/
	$$('.has-close-button').each(function(error_div){
		close_button=Builder.node('a',{className:'close-icon', href:"#"}, "Inchide");
		error_div.insert({top:close_button});
		Event.observe(close_button, 'click', function(event){
			event.stop();
			new Effect.Fade(error_div,{duration:0.5});
		});
	});
    $$('.ec-trigger').each(function(ec_elem){
        new ExpandCollapse(ec_elem);
    })
});

/* Pentru search-ul din header
--------------------------------------------------------*/
SearchOptions=Class.create({
	initialize:function(){
		$('#search_options_select').hide();
		$('#search_options_link').show();
		
		myself = this;
		this.search_options=$('search_options');
		this.search_options_link=$('search_options_link');
		this.select=$('search_options_select');
		
		Event.observe(this.search_options_link, 'click', this.showOptions.bindAsEventListener(this));
		document.observe('click', this.showOptions.bindAsEventListener(this));

		$A(this.search_options.select('ul li a')).each(function(option_link){
			Event.observe(option_link, 'click', myself.selectOption.bindAsEventListener(myself))
		})

	},

	showOptions:function(event){

		if(this.search_options.visible()){
			if(event.findElement('a#search_options_link')!=undefined)
				return;

			if(event.findElement('div#search_options')!=undefined && event.findElement('a#search_options_close')==undefined){
				return;
			}

			event.stop();
			this.search_options.hide();
			this.search_options_link.removeClassName('selected');
			if(Prototype.Browser.IE6)
					$$('select').invoke('setStyle', {visibility:'visible'});
		}else{
			if(event.findElement('a#search_options_link')!=undefined){
				this.search_options.show();
				if(Prototype.Browser.IE6)
					$$('select').invoke('setStyle', {visibility:'hidden'});
				event.stop();
				this.search_options_link.addClassName('selected');
			}

		}

	},

	selectOption:function(event){
		event.stop();
		option_link=event.findElement('a');

		this.search_options_link.innerHTML = option_link.innerHTML;
		this.select.value = option_link.readAttribute('rel');
		this.search_options.hide();
		if(Prototype.Browser.IE6)
			$$('select').invoke('setStyle', {visibility:'visible'});
		this.search_options_link.removeClassName('selected');
	}
})

/* Pentru search toggle
--------------------------------------------------------*/
var SearchToggle = Class.create({
	initialize:function(){
	
		var search_field_default_val="medic, farmacie, spital, articol, termen, etc.";
		
		Event.observe('search_input', 'blur', function(){
			if($F('search_input')==''){
				$('search_input').value=search_field_default_val;
				$('search_input').removeClassName('searchfield-focus');
			}
		})
		
		Event.observe('search_input', 'focus', function(){
			if($F('search_input')==search_field_default_val){
				$('search_input').value='';
				$('search_input').addClassName('searchfield-focus');
			}else{
				$('search_input').select();
			}
		})
		
	}
})

/* Pentru taburi
--------------------------------------------------------*/
var Tabs = Class.create({
  initialize:function(tab_container){
    this.tab_container=tab_container;
    this.tab_links=this.tab_container.select('a.tab-link');
    this.tab_contents=this.tab_container.select('div.tab-content');
    this.observeTabs();
  },

  observeTabs:function(){
    var self = this; // pastram referinta la this
    // Atasez observere la actiunea de click pe taburi
    self.tab_links.each(function(tab_link){
      tab_link.observe('click',self.showTab.bindAsEventListener(self))
    })
  },

  showTab:function(event){
    tab_index=this.tab_links.indexOf(event.element()); // pe al cat-lea tab am dat click

    this.tab_links.invoke('removeClassName','selected');
    this.tab_contents.invoke('hide');

    event.element().addClassName('selected');
    this.tab_contents[tab_index]!=undefined ? this.tab_contents[tab_index].show() : '';
    event.stop();
  }

});

/* Pentru detectarea versiunei de IE
--------------------------------------------------------*/
Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7; 
