function cauta_plus() {
	var cauta_div = $('cauta_produse_hot');
	var plus = $('plus');
	var h = cauta_div.getStyle("height").toInt();
	var new_h, alt, inner;
	if (h == 15) {
		new_h = 30;
		title = 'Mai Putine Produse Hot';
		inner = '-';
	}
	else {
		new_h = 15;
		title = 'Mai Multe Produse Hot';
		inner = '+';
	}
	cauta_div.tween('height', new_h);
	plus.innerHTML = inner;
	plus.title = title;
	return false;
}
function openTab(key,id){
	if (id == null) id = 'cluba';
	$$('#'+id+' a.tb_selected').each(function(item){
		item.removeClass('tb_selected');
		item.addClass('tb');
	});
	var i=0;
	$$('#'+id+' a.tb').each(function(item){
		if(key==i){
			item.removeClass('tb');
			item.addClass('tb_selected');
		}
		i++;
	});
	var i=0;
	$$('#'+id+' #'+id+'_content div.tb_option').each(function(item){
		if(key==i){
			item.set('style','display:block;');
		}else	
			item.set('style','display:none;');
		
		i++;
	});
}
function default_lcf_js(id, divid) {
	var mydivs = new Array("default_lcf_1_locatie", "default_lcf_1_alfabetic", "default_lcf_1_tip_firma");
	var mylinks = new Array("default_lcf_1_loc", "default_lcf_1_alf", "default_lcf_1_tip");
	mydivs.each(function(item){ $(item).setStyle("display", "none");});
	$(divid).setStyle('display', 'block');
	mylinks.each(function(item){ $(item).set("style","text-decoration:none;font-weight:normal");});
	$(id).set("style","text-decoration:underline;font-weight:bold");
	
}
function default_lcf_js2(id, divid) {
	var mydivs = new Array("default_lcf_2_locatie", "default_lcf_2_alfabetic");
	var mylinks = new Array("default_lcf_2_loc", "default_lcf_2_alf");
	mydivs.each(function(item){ $(item).setStyle("display", "none");});
	$(divid).setStyle('display', 'block');
	mylinks.each(function(item){ $(item).set("style","text-decoration:none;font-weight:normal");});
	$(id).set("style","text-decoration:underline;font-weight:bold");
	
}
function parse_search_word(max,maxstr) {
	/*maxstr < max - ca sa aiba relevanta codul*/
	var inpt;
	var fw;
	inpt = document.getElementById("cauta_what");
	fw=inpt.value;
	fw = word_no_spaces(fw,maxstr);
	fw = get_paragraph(fw,max,maxstr);
	document.getElementById("cauta_what").value = document.getElementById("cauta_what").value.substring(0,fw.length);
}
function word_no_spaces(str,maxstr) {
	var lsp;
	lsp = str.lastIndexOf(" ");
	if( lsp==-1 && str.length>maxstr) str=str.substring(0,maxstr);
	return str;
}
function get_paragraph(str,max,maxstr) {
	var chk;
	var lsp;
	if(str.length>max) {
		chk=str.substring(0,max);
		chk=word_no_spaces(chk,maxstr);
		if(chk.length>=max+1 && str[max+1]==" ") str=chk;
		else {
			lsp = chk.lastIndexOf(" ");
			if(lsp!=-1) {
				chk=chk.substring(0,lsp);
				str=chk;
			}
		}
		
	}
	return str;
}
function submit_cautare(form_h){
    form_what = form_h.cauta_what.value;
    form_what=form_what.replace('/',' ')
    form_what=form_what.replace('&',' ')
	form_where = getCheckedValue(form_h.cauta_where_value);
	form_h.action = '/cauta/'+ form_where + '/' + form_what + '/';
	if (form_what=='') alert('Introduceti termenii cautarii');
	else {
		if(form_where=='') alert('Alegeti sectiunea pentru cautare');
		else form_h.submit();
	}
}
function getCheckedValue(inputObj){
	if(inputObj.value!='') return inputObj.value;
	else return 'produse';
} 
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
function description_check(obj, desc) {
	var t = obj.innerHTML;
	if (t == desc) obj.innerHTML = '';
}
function save_tel(id) {
	var req = new Request({
		url: '/salveaza-tel/'+id,
		onSuccess: function(txt){
			$('click_aici').set('text', '');
		},
		onFailure: function(){
			alert('The request failed2.');
			$('click_aici').set('text', 'The request failed.');
		}
	});
	req.send();
}
function save_ym(id,ym) {
	var req = new Request({
		url: '/salveaza-ym/'+id,
		onSuccess: function(txt){
			window.location='ymsgr:sendim?'+ym+'&m=Buna%20ziua.%20Va%20contactez%20de%20pe%20site-ul%20www.ClubAfaceri.ro%0A';
		},
		onFailure: function(){
			alert('The request failed2.');
		}
	});
	req.send();
	return false;
}
function save_tel2(id) {
	var req = new Request({
		url: '/salveaza-tel/'+id,
		onSuccess: function(txt){
			$('pclick_aici').set('text', txt);
		},
		onFailure: function(){
			$('pclick_aici').set('text', 'The request failed.');
		}
	});
	req.send();
}


function zoom2(id){
	$$('#'+ id +' div.prod_details').each(function(item){
		if(item.getStyle('z-index')=='50'){
			$('pic_bg_top_'+id).dispose();
			$('pic_bg_bottom_'+id).dispose();
			item.set('style','z-index:150');
			$$('#'+ id +' a.lupaOut').each(function(item1){
				item1.removeClass('lupaOut');
				item1.addClass('lupaIn');
			});
			$$('#'+ id +' div.pic_bg').each(function(item2){
				item2.removeClass('pic_bg');
				item2.addClass('prod_pic_container');
			});
		}else{
			$(id).adopt(new Element('div', {'class': 'pic_bg_top','id':'pic_bg_top_'+id}));
			$(id).adopt(new Element('div', {'class': 'pic_bg_bottom','id':'pic_bg_bottom_'+id}));
			item.set('style','z-index:50');
			$$('#'+ id +' a.lupaIn').each(function(item1){
				item1.removeClass('lupaIn');
				item1.addClass('lupaOut');
			});
			
			$$('#'+ id +' div.prod_pic_container').each(function(item2){
				item2.removeClass('prod_pic_container');
				item2.addClass('pic_bg');
			});
			
		}
	});
	
}

function zoom(id){
	height=parseInt($('prod_details_'+id).getStyle('margin-top'));
		if(height<0) {
			$('lupa_'+id).morph('.lupaIn');
		} else {
			$('lupa_'+id).morph('.lupaOut');
		}
	var slideMe = new Fx.Slide('prod_details_'+id,{
	    duration: 600,
	    transition: Fx.Transitions.Linear
	});
	slideMe.toggle().chain(function() {
		
	});
	/*
	$$('#'+ id +' a.lupaIn').each(function(itemLupa){
		itemLupa.morph('.lupaOut');
		removeClass('lupaIn');
	});
	$$('#'+ id +' a.lupaOut').each(function(itemLupa){
		itemLupa.morph('.lupaIn').chain(removeClass('lupaOut'));
	});
	*/
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function sh(id) {
	var op;
	var i = $(id);
	op = i.getStyle('display');
	if (op == 'none') {
		i.fade(1);
		i.setStyle('display', 'block');
	}
	else {
		i.fade(0);
		i.setStyle('display', 'none');
	}
}
function onlyNumbers(e) {
	var keynum;
	var keychar;
	var numcheck;
	
	if(window.event) // IE
	  {
	  keynum = e.keyCode;
	  }
	else if(e.which) // Netscape/Firefox/Opera
	  {
	  keynum = e.which;
	  }
	if (keynum==8 || keynum==46 || typeof(keynum)=='undefined') return true;
	else {
		keychar = String.fromCharCode(keynum);
		numcheck = /\d/;
		return numcheck.test(keychar);
	}
}
var step_slide=1;
function scrollTopSlide(){
	var scrollExample = new Fx.Scroll($('top_slide'),{
		transition: Fx.Transitions.Cubic.easeOut
	});
	scrollExample.start(0, (30 * step_slide));
	var li=$('top_slide_content').getChildren(li);
	li[step_slide-1].clone().inject($('top_slide_content'));
}
function scrollHotSlide(){
	var scrollExample = new Fx.Scroll($('hot_slide'),{
		transition: Fx.Transitions.Cubic.easeOut
	});
	scrollExample.start(0, (100 * step_slide));
	var li=$('hot_slide_content').getChildren(li);
	li[step_slide-1].clone().inject($('hot_slide_content'));
}
function scrollMainSlide(){
	var scrollExample = new Fx.Scroll($('main_slide'),{
		transition: Fx.Transitions.Cubic.easeOut
	});
	scrollExample.start(0, (30 * step_slide));
	var li=$('main_slide_content').getChildren(li);
	li[step_slide-1].clone().inject($('main_slide_content'));
}
function showQuickViewBox(el,href,src,c,c_link,c_contact_link){
	var parent_size=el.getCoordinates();
	var listare_box=$('listare').getCoordinates();
	var scroll_top=f_scrollTop();
	var client_height=f_clientHeight();
	if(client_height+scroll_top-parent_size.top>350){
		var offset=parent_size.top-listare_box.top;
		$('QuickViewBoxArrow').set('style','top:10px');
	}else{
		var offset=client_height+scroll_top-listare_box.top-350;
		$('QuickViewBoxArrow').set('style','top:'+(parent_size.top-listare_box.top+10-offset)+'px');
	}
	$('MiniImgBox').set('html','');
	var myAnchor = new Element('a', {
    	href: href,
    	'class':'iconLayer',
    	html: '&nbsp;'
    });
    $('MiniImgBox').adopt(myAnchor);
	$$('#QuickViewBox .FullImage').set('html','<a href="'+href+'" title="" class="prod_gal_img_big" ><img src="/i/tr.gif" style="width: 0px;height:300px" alt="" /><img src="'+src+'" alt="imagine mare"/></a>');
	$$('#QuickViewBox .QuickViewBoxFirma').set('href',c_link);
	$$('#QuickViewBox .QuickViewBoxFirma').set('html',c);
	$$('#QuickViewBox .QuickViewBoxContactNow').set('href',c_contact_link);
	$('QuickViewBox').set('style','visibility:visible;top:'+offset+'px;display:block;');
	$('MiniImgBox').set('style','visibility:visible;top:'+(parent_size.top-listare_box.top)+'px;display:block;');
}
function hideQuickViewBox(){
	$('QuickViewBox').set('style','visibility:hidden;');
	$('MiniImgBox').set('style','visibility:hidden;');
}
function checkYMonline(ym_id) {
	yahooUrl="http://opi.yahoo.com/online?u="+ym_id+"&m=a&t=1";
	var req = new Request({
	method: 'get',
	url: yahooUrl,
	data: { 'do' : '1' },
	onRequest: function() { },
	onComplete: function(response) { alert('Response: ' + response); }
	}).send();
}
