function tgl_f(did)
	{
	$("#t1").attr("class","");
	$("#t2").attr("class","");
	$("#t3").attr("class","");
	$("#f1").hide();
	$("#f2").hide();
	$("#f3").hide();
	$("#t"+did).attr("class","selected");
	$("#f"+did).show();
	}

function add_to_cart(pid,q)
	{
	if(!q) q = 1;
	if(q=='get') q = $("#quantity").val().trim();
	$.post("_ajax.php",
		{'load': 'add_to_cart','pid': pid, 'quantity': q}, function(data)
			{
			if(data.trim().substr(0,3)=="Cos") $('#cart').html(data);
			else alert(data);
			});
	}

function remove_from_cart(pid)
	{
	$.post("_ajax.php",
		{'load': 'remove_from_cart','pid': pid}, function(data)
			{
			if(data.trim().substr(0,3)=="<td")
				{
				$("#cid_"+pid).animate({opacity:'toggle'},300,function(){
					$("#cid_"+pid).remove();
					$('#total').html(data);
					});
				if($('#buy_form').css('display')=='block') box_toggle('#buy_form');
				}
			else alert(data);
			});
	}
	
function tw(widget_id,btn)
	{
	$("#w"+widget_id).animate({opacity: 'toggle', height: 'toggle'},500);
	$(btn).find('span').toggleClass('wtv2');
	if($(btn).find('span').attr('class')=='wtv wtv2') var cls='hidden'; else var cls='visible';
	$.cookie('w'+widget_id, cls)
	}

function zoom(x)
	{
	if(x=='show') $("#zoomed").animate({opacity: '1',visibility: 'show'},300);
	else $("#zoomed").animate({opacity: '0',visibility: 'hide'},300);
	}
	
function get_last_tweet()
	{
	var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
	var username='izvorulsanatati'; var format='json'; 
	var url='http://api.twitter.com/1/statuses/user_timeline/'+username+'.'+format+'?callback=?';
	$.getJSON(url,function(tweet){ 
			$("#tweet").html(tweet[0].text.replace(regexp,'<a href="$1" rel="nofollow">$1</a>'));
		});
	}
	
function newsletter()
	{
	$.post("_ajax.php",
		{'load': 'newsletter_subscribe','nume': $('#nl_name').val(),'email': $('#nl_email').val()}, function(data)
			{
			if(data.trim()=="abonat") $('#newsletter_form').html("<p id='nls'>Ai fost abonat cu succes la newsletter.</p>");
			else $("#nl_response").html(data);
			});
	return false;
	}
	
function logout()
	{
	$.post("_ajax.php",
		{
		'load': 'logout',	
		},
		function(data)
			{
			if(data.trim()=="logged_out") { window.location.reload(); }
			else { alert(data); }
			}
		);
	}
	
function cform()
		{
		if($('#cform_nume').val()=="") alert("Va rugam completati formularul cu numele sau societatea Dvs.");
		else if($('#cform_email').val()=="") alert("Va rugam completati formularul cu o adresa de email valida.");
		else if($('#cform_mesaj').val()=="") alert("Va rugam scrieti un mesaj pentru noi.");
		else if($('#cform_captcha').val().length!=5) alert("Codul de verificare trebuie sa contina 5 caractere.");
		else
			{
			$('#cform_response').html("<img src='template/ajax-loader.gif' alt=''/>");
			$.post("_ajax.php",
			{
			'load': 'cform',
			'nume': $('#cform_nume').val(),
			'email': $('#cform_email').val(),
			'telefon': $('#cform_telefon').val(),
			'captcha': $('#cform_captcha').val(),
			'mesaj': $('#cform_mesaj').val()
			}, function(data)
				{
				if(data.trim()=="trimis") { $('#cform_response').html("Mesajul a fost trimis cu succes."); $("#captcha_img").attr('src',$("#captcha_img").attr('src')+'?'); }
				else $('#cform_response').html(data);
				});
			}
		}
		
function lc(article_id)
		{
		if($('#lc_nume').val()=="") alert("Va rugam completati formularul cu numele Dvs.");
		else if($('#lc_email').val()=="") alert("Va rugam completati formularul cu o adresa de email valida.");
		else if($('#lc_mesaj').val()=="") alert("Scrieti un text pentru comentariu.");
		else if($('#lc_captcha').val().length!=5) alert("Codul de verificare trebuie sa contina 5 caractere.");
		else
			{
			$('#lc_submit').val("Se trimite");
			$.post("_ajax.php",
			{
			'load': 'lc',
			'article_id': article_id,
			'nume': $('#lc_nume').val(),
			'email': $('#lc_email').val(),
			'site': $('#lc_site').val(),
			'captcha': $('#lc_captcha').val(),
			'subscribe': $('#lc_subscribe').attr('checked'),
			'msg': $('#lc_msg').val()
			}, function(data)
				{
				if(data.trim()=="trimis") { $('#leave_comment').html("<span>Comentariul a fost trimis cu succes.<br />In curand va fi moderat si afisat pe site.</span>"); }
				else { $('#lc_response').html(data); $('#lc_submit').val("Trimite"); }
				});
			}
		}
		
function slide_questions(id)
	{
	var next = id+1;
	if($("#q"+next).length){} else next=1;
	$("#q"+id).animate({opacity: 'toggle'},300,function(){ $("#q"+next).animate({opacity: 'toggle'},300); });
	setTimeout('slide_questions('+next+')',5000);
	}
	
function ask_dr()
	{
	$.post("_ajax.php",
		{
		'load': 'ask_dr',
		'nume': $('#ask_nume').val(),
		'varsta': $('#ask_varsta').val(),
		'captcha': $('#ask_captcha').val(),
		'text': $('#ask_text').val()
		},
		function(data)
			{
			if(data.trim()=="trimis") { $('#ask_box').html("<b>Intrebarea ta a fost trimisa cu success.</b><br />Te rugam sa reveniti periodic pentru a afla raspunsul la intrebarea Dvs."); }
			else { alert(data); }
			}
		);
	}
	
function box_toggle(obj)
	{
	$(obj).animate({opacity: 'toggle', height: 'toggle'},400);
	}
	
function check_cart(btn)
	{
	$(btn).val('Se incarca...');
	$.post("_ajax.php",
		{'load': 'check_cart'},
		function(data)
			{
			$(btn).val('Plaseaza comanda');
			if(data.trim()=="pass") {if($('#buy_form').css('display')!='block') box_toggle('#buy_form'); $('#cferr').hide();}
			else {$('#cferr').html(data).show(); }
			}
		);
	
	}
	
$(document).ready(function(){
	get_last_tweet();
	if($("#buy_form").length!=0) $("#buy_form").animate({opacity: 'toggle', height: 'toggle'},1);
	if($("#recommend").length!=0) setTimeout("slide_questions(1)",5000);
	if($("#ask_trigger").length==0) $('#ask_box').animate({opacity: 'toggle', height: 'toggle'},1);
	if($.cookie('w1')=='hidden' && $("w1")) $('#w1').animate({opacity: 'toggle', height: 'toggle'},1);
	if($.cookie('w2')=='hidden' && $("w2")) $('#w2').animate({opacity: 'toggle', height: 'toggle'},1);
	if($.cookie('w3')=='hidden' && $("w3")) $('#w3').animate({opacity: 'toggle', height: 'toggle'},1);
	if($.cookie('w4')=='hidden' && $("w4")) $('#w4').animate({opacity: 'toggle', height: 'toggle'},1);
	if($.cookie('w5')=='hidden' && $("w5")) $('#w5').animate({opacity: 'toggle', height: 'toggle'},1);
	if($.cookie('w6')=='hidden' && $("w6")) $('#w6').animate({opacity: 'toggle', height: 'toggle'},1);
	if($.cookie('w7')=='hidden' && $("w7")) $('#w7').animate({opacity: 'toggle', height: 'toggle'},1);
	if($.cookie('w8')=='hidden' && $("w8")) $('#w8').animate({opacity: 'toggle', height: 'toggle'},1);
});

