function esteIE()
	{
		var browser = navigator.appName;

		if(browser == "Microsoft Internet Explorer") 
			return true;
			
		return false;		
	}
function MakeObject() {
	var xmlhttp=false; 
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); 
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); 
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); 
        }
		return xmlhttp;
	}
	
	

function sterge(id)
{
	var request=MakeObject();
	
	


	total=1*$("#total_tot").html()-1*$("#pret_total_"+id).html();

var newtotal = new Number(total);
total = newtotal.toFixed(2);

	$("#total_tot").html(total);
$("#tr_"+id).remove();
	
			request.open('get', 'returnant.php?tip=stergecos&id=' + id);
		/*	request.onreadystatechange = function () {
				
						if(request.readyState == 4)
					{ 
						
						var raspuns = request.responseText;	
						alert(raspuns);
						/*
						var c = document.getElementById('select_localitati');
						if(esteIE() || (navigator.appName.indexOf("Opera") + 1))
						{
							c.outerHTML = '<select name="select_localitati">'+raspuns+'</select>';
						}
						else {
							c.innerHTML = raspuns;
						}
						
					} 
			}*/
			request.send(false);
						
		
}

function update_bucati(key,nr_bucati)
{
	var request=MakeObject();
	
	request.open('get', 'http://www.litera.ro/returnant.php?tip=updatecos&key='+key+'&buc='+nr_bucati);
	request.send(false);
    
	if ($("#collection_"+key).html()=='98' || $("#collection_"+key).html()=='124')
	   {
	   window.location='http://www.litera.ro/vizualizare_cos';
	   return true;
	   }


   $("#pret_total_"+key).html(nr_bucati*$("#pret_unitar_"+key).html()); 
		total=0.0;
			$("[id^=pret_total_]").each(function(){
				total +=parseInt(this.innerHTML*100)/100;
			})
		$("#total_tot").html(total);
		
}
// AM MODIFICAT FUNCTIA CA SA DEA REDUCEREA PT COLECTIA 98 ( DEDESUPT E FUNCTIA ORIGINALA )
function update_bucati_backup(key,nr_bucati)
{
	var request=MakeObject();
	
	
   $("#pret_total_"+key).html(nr_bucati*$("#pret_unitar_"+key).html()); 
		total=0.0;
			$("[id^=pret_total_]").each(function(){
				total +=parseInt(this.innerHTML*100)/100;
			})
		$("#total_tot").html(total);
	
			request.open('get', 'returnant.php?tip=updatecos&key='+key+'&buc='+nr_bucati);
			request.send(false);
						
		
}



$(document).ready(function(){
	
	$("#formular_nodex").submit(function(event){
		var cuvant = $("#cuvant_nodex").val();
		if(cuvant=="" || cuvant==null) alert("Trebuie sa introduci cel putin un cuvant");
		else window.open('http://nodex.litera.ro/cautare_dex/'+cuvant); 
		event.preventDefault();
	})
	
	 $(".carteopt").mouseover (function() {
		 $(this).addClass("hovered");
	 });
	 $(".carteopt").mouseout (function() {
		 $(this).removeClass("hovered");
	 });
	 $("li:last-child").addClass("borderless");
	 $("li:last-child a").addClass("borderless");
	 $("#bestseller1 li:last-child").removeClass("borderless");
	 $("#bestseller2 li:last-child").removeClass("borderless");
});

function rasfoieste(id) {
	var ok=false,j;
	if (document.getElementById("rasfoieste_"+id).style.display=='block') {ok=true;}
		else {clearTimeout(masa);}
		$("#rasfoieste_"+id).slideToggle();
		if (id==1) j=5;
		else j=id-1; 
		if (ok) {sch(j);$("#arasf"+id).html('rasfoieste cartea');}
		else {$("#arasf"+id).html('inchide cartea');}
	}	

$(function(){
	$('#pozecarte a').lightBox();
});

function arata(id) {
		$("#rasfoieste_1, #rasfoieste_2, #rasfoieste_3, #rasfoieste_4, #rasfoieste_5").hide();
		$("#promo .sevede").fadeOut("fast", function() {
			$("#promo .sevede").removeClass("sevede");
			$("#promo .visible").removeClass("visible");
				$("#carte"+id).fadeIn("fast", function () {
					$("#carte"+id).addClass("sevede");
					$("#arata"+id).addClass("visible");
			});
		});
		
		$("#arasf1").html('rasfoieste cartea');
		$("#arasf2").html('rasfoieste cartea');
		$("#arasf3").html('rasfoieste cartea');
		$("#arasf4").html('rasfoieste cartea');
		$("#arasf5").html('rasfoieste cartea');
		
}

function termeni(id) {
		$("#termen"+id).slideToggle("fast");
	}




function sch(id)
{
	if (id==5) id=1;else id++;
	arata(id);
	try
	{
	clearTimeout(masa);
	}
	catch(e)
	{
		
	}
	masa=setTimeout("sch('"+id+"')",15000); 
}	

function changeCurrencyGlobal(value)
{
	window.location = 'http://www.litera.ro/?currency='+value;
}
/*
function nextStepOnCart(){
	if( $(this).hasClass("current_step") ){
		// do nothing, we're clicking on the current step!
		alert('Suntem la acelasi pas!');
		return false;
	}
	//check if we're going to the second step
	if ($("#pasul_1").length > 0){
		$("#pasul_1").submit();
		return false;
	}else{
		//check if we're going to the third step
		if ($("#pasul_2").length > 0){
			$("#pasul_2").submit();
			return false;
		}else{
			//we're going back to the first step
			window.location = 'http://www.litera.ro/vizualizare_cos/';
		}
	}
}
*/
function forSecondButton(){

	//check if we're going to the third step
	if ($("#pasul_1").length > 0){
		$("#pasul_1").submit();
		return false;
	}else{
		if ($("#pasul_3").length > 0){
			//we're going back to the first step
			window.location = 'http://www.litera.ro/vizualizare_cos/';
		}
	}
	//else... we stay on current step
	return false;
}

function forThirdButton(){

	//check if we're going to the third step
	if ($("#pasul_2").length > 0){
		if($("#le_table").css('display')=='block'){
			$("#pasul_2").submit();
		}else{
			alert('Alegeti intai modul de efectuare a comenzii.');
		}
		return false;
	}else{
		if ($("#pasul_1").length > 0){
			$("#pasul_1").submit();
			return false;
		}
	}
	//else... we stay on current step
	return false;
}

