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(){
	$$('.ec-trigger').each(function(ec_elem){
		new ExpandCollapse(ec_elem);
	})
})

/* Pentru meniul dropdown
--------------------------------------------------------*/
sfHover = function() {
	if (document.getElementById("drop-nav")) {
	var sfEls = document.getElementById("drop-nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
				$$('select').invoke('setStyle', {visibility:'hidden'});
				
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				$$('select').invoke('setStyle', {visibility:'visible'});
			}
		}
	}
}

parentAct = function(id){
    $(id).className='activ parent';
}

parentDez = function(id){
    $(id).className='parent';
}

/* Pentru search-ul din header
--------------------------------------------------------*/
SearchOptions=Class.create({
	initialize:function(){
		myself = this;
		this.search_options=$('search_options');
		this.search_options_link=$('search_options_link');
		this.search_categ=$('search_categ');
		this.search_options_close=$('search_options_close');

		Event.observe(this.search_options_link, 'click', this.showOptions.bindAsEventListener(this));
		Event.observe(this.search_options_close, 'click', this.showOptions.bindAsEventListener(this));
		//new Draggable(this.search_options);
		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();
			new Effect.Fade(this.search_options,{duration:0.2});
			this.search_options_link.removeClassName('selected');
		}else{
			if(event.findElement('a#search_options_link')!=undefined){
				//this.search_options.show();
				event.stop();
				new Effect.Appear(this.search_options,{duration:0.2});
				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.search_categ.value = option_link.readAttribute('rel');
		//this.search_options.hide();
		new Effect.Fade(this.search_options,{duration:0.2});
		this.search_options_link.removeClassName('selected');
	}
})

/* Pentru page scroller
--------------------------------------------------------*/
var PageScroller = Class.create({
	initialize:function(){
		var myself = this;
		this.scroll_links=$$('a[href^=#]').reject(function(sl){return sl.readAttribute('href')=='#'});

		$A(this.scroll_links).each(function(scroll_link){
			Event.observe(scroll_link, 'click', myself.scroll.bindAsEventListener(myself));
		})
	},

	scroll:function(event){

		my_link = event.findElement('a');
		scroll_id=my_link.readAttribute('href').gsub('#', '');
		scroll_target = null;
		if($(scroll_id)!=undefined)
			scroll_target=$(scroll_id);

		if($$('a[name='+scroll_id+']').first() != undefined)
			scroll_target=$$('a[name='+scroll_id+']').first()

		if(scroll_target != null){
			event.stop();
			Effect.ScrollTo(scroll_target, {duration:0.5});
		}
	}
})

/* 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('textfield-focus');
			}
		})
		
		Event.observe('search_input', 'focus', function(){
			if($F('search_input')==search_field_default_val){
				$('search_input').value='';
				$('search_input').addClassName('textfield-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; 
