function MesajRecomanda()
{
    window.location.href = window.location.href + '?recomanda=ok';
}


$(function() {
    $(".carousel").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible: 4
	});
});

function getCant( pid )
{
	var cant = document.getElementById('cant').value;
	update_cart( pid, cant ); 
}

function checkAlertPret( e, tip, def_mail )
{
	var val = document.getElementById('real_pret_val').value;
	var mail = document.getElementById('pret_mail').value;
	
	if( (tip == 1 && e.keyCode == 13 ) || tip == 0 )
    {
		if( !mail || mail == def_mail)
	    {
	        alert("Introduceti adresa de e-mail");
	        return false;
	    }
		
		if ( !pcre_email.test( mail ) )
		{
			alert('Adresa de email este invalida!');
			return false;
		}
		
		if( !val || val == 0)
		{
			alert("Introduceti pragul de pret");
			return false;
		}		
		document.frm_npret.submit();			
		return true;
   } 
}

function checkAlertStoc( e, tip, def_mail )
{
	var mail = document.getElementById('stoc_mail').value;
	if( (tip == 1 && e.keyCode == 13 ) || tip == 0 )
	{
		if( !mail || mail == def_mail)
	    {
	        alert("Introduceti adresa de e-mail");
	        return false;
	    }
		
		if ( !pcre_email.test( mail ) )
		{
			alert('Adresa de email este invalida!');
			return false;
		}	
	    document.frm_nstoc.submit();		
		return true;
   } 
}

function setPretValue( def )
{
	var pret = document.getElementById('pret_val');
	
	if( pret.value != def )
	{
		if( !isNaN( parseFloat(pret.value) ) )
		{
			pret.value = parseFloat(pret.value);
		}
		else
		{
			pret.value = "";
		}
	}
}
function showTab( id )
{
	var tab = document.getElementById("tab" + id );
	if( tab ) 
	{
		tab.className = "tab_visible";		
		tab.onmouseover = "";
		tab.onmouseout = "";
	}	
}
function hideTab( id )
{
	var tab = document.getElementById("tab" + id );
	if( tab ) 
	{
		tab.className = "tab_hidden";
		tab.onmouseover = function() { this.className='tab_visible'; };
		tab.onmouseout = function() { this.className='tab_hidden'; };
	}	
}
function switchTab( tab, http, pid )
{
	var url = http + "server/produs_view_tabs_ajax.php?prod_id=" + pid + "&tab=" + tab;
	var div = document.getElementById('continut_tab');
	
	switch( tab )
	{
		case 0:
			showTab( 0 );	
			hideTab( 1 );
			hideTab( 2 );
			hideTab( 3 );			
		break;
		case 1:
			hideTab( 0 );
			showTab( 1 );
			hideTab( 2 );
			hideTab( 3 );			
		break;
		case 2:
			hideTab( 0 );
			hideTab( 1 );
			showTab( 2 );
			hideTab( 3 );	
		break;	
		case 3:
			hideTab( 0 );
			hideTab( 1 );
			hideTab( 2 );
			showTab( 3 );	
		break;	
	}
	
	setTimeout( 'make_tab_request("'+url+'")' , 10 );	
}

var can_make_request = true;

function can_request()
{
	can_make_request = true;
}
function make_tab_request( url )
{
	if ( can_make_request )
	{
		can_make_request = false;
		$.get(url,
		    function(data)
    		{
    		    var div = document.getElementById('continut_tab');				
                div.innerHTML = data;
				
				setTimeout( "can_request()" , 10 );
    		}
		);		
	}
	else
	{
		setTimeout( 'make_tab_request("'+url+'")' , 10 );
	}
}
