function mycarousel_initCallback(carousel)
{
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 4,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});

// Meniu expandabil ------------------------------------------------------------------------
currentSubCategory = "";  
function toggleSubMeniu(target)
{
	var ceva = document.getElementById("nr_categorii").innerHTML;
	for(i=1;i<=ceva;i++) {
		if(document.getElementById('submeniu_'+i+'_trigger')) document.getElementById('submeniu_'+i+'_trigger').style.backgroundPosition = "0 0";
	}
	var trigger = document.getElementById(target + '_trigger');
	
	if (currentSubCategory) {	
		if (document.getElementById(currentSubCategory)) {	
			document.getElementById(currentSubCategory).style.display = 'none';	
			trigger.style.backgroundPosition = "0 -29px";
		}
	}
	if(currentSubCategory==target) {
		document.getElementById(target).style.display = 'none';
		currentSubCategory = "";
		trigger.style.backgroundPosition = "0 0";
	}else
	if (target) {	
		if (document.getElementById(target)) {
			document.getElementById(target).style.display = 'block';	
			currentSubCategory = target;	
			trigger.style.backgroundPosition = "0 -29px";
		}
	}
}

/* Pop-up *****************************/
function popUpWindow(URLStr, left, top, width, height) 
{
	if(width==0 && height==0) { var fullsc = 'fullscreen=yes,'; var marime = ""; } 
	else { var fullsc = ""; var marime = ',width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+''; }
	popUpWin = open(URLStr,'_blank',''+fullsc+'toolbar=no,location=no,,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes'+marime+'');
}

// Cautare ------------------------------------------------------------------------------------------
function cautareAdina() {
	document.cauta.action='http://www.echipamentemilitare.ro/cauta-in-site/'+document.cauta.camp_produs.value+'/Categorie,toate/Pagina1';
}

function cautaProdus(prefix) {
	var produs = (document.cautas.camp_produs.value=="")?"":document.cautas.camp_produs.value+'/';
	document.cautas.action='http://www.echipamentemilitare.ro/cauta-in-site/'+produs+'Categorie,'+document.cautas.camp_categorie.value+'/Pagina1';
}

function schimbaimagine(id,extensie,nume,tip) {
	if(tip==1) document.getElementById("imagProdus").innerHTML = '<a href="javascript:popUpWindow(\'http://www.echipamentemilitare.ro/imagine.php?imagine='+id+'\',0,0,600,600);" title="" onmouseover="Tip(\'Mareste imaginea\')" onmouseout="UnTip()"><img src="http://www.echipamentemilitare.ro/continut/produse/produs160/'+id+extensie+'" alt="'+nume+'" /></a>';
	else document.getElementById("imagProdus").innerHTML = '<img src="http://www.echipamentemilitare.ro/continut/produse/produs160/'+id+extensie+'" alt="'+nume+'" />';
}


// Cos cumparaturi ------------------------------------------------------------------------
var xmlHttp
auxx = "";
function adaugaincos(idprodus,tip) {
if (!auxx) 
{
	var det=(tip==1)?"":"Det";
	document.getElementById("adauga_"+idprodus).innerHTML = '<a href=\"javascript:void(0);\" class=\"icoAdaugaA\">Asteptati</a>';
	
	var marime='na';
	var talie='na';
	var culoare='0';
	var cantitate='1';
	var campspecial='';
	if(tip=='2') {
		var marime=document.getElementById("camp_marimeProdus").value;
		var talie=document.getElementById("camp_talieProdus").value;
		var culoare=document.getElementById("camp_culoareProdus").value;
		var cantitate=document.getElementById("camp_cantitateProdus").value;
		if(document.getElementById("camp_campSpecial")) var campspecial=document.getElementById("camp_campSpecial").value;
		else var campspecial='';

		marime=(marime=="")?"na":marime;
		talie=(talie=="")?"na":talie;
		culoare=(culoare=="")?"0":culoare;
		cantitate=(cantitate=="")?"0":cantitate;
	}
	var auxx = idprodus;
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) { return }
	var url="http://www.echipamentemilitare.ro/Ajax_Coscumparaturi.php"
	url = url+"?id="+idprodus
	url = url+"&marime="+marime
	url = url+"&talie="+talie
	url = url+"&culoare="+culoare
	url = url+"&cantitate="+cantitate
	url = url+"&campspecial="+campspecial


	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById("adauga_"+idprodus).innerHTML = '<a href="javascript:adaugaincos('+idprodus+','+tip+')" class="adaugaCos'+det+'">Adauga in cos</a>';
			document.getElementById("cosCumparaturi").innerHTML = xmlHttp.responseText;
				
			document.getElementById("cosLinks").innerHTML = "            <p><a href=\"http://www.echipamentemilitare.ro/cos-cumparaturi\">Vezi cosul</a></p>\n            <p><a href=\"http://www.echipamentemilitare.ro/date-personale\">Trimite comanda</a></b></p>\n";
			alert('Produsul a fost adaugat in cosul de cumparaturi. \n\nPentru a finaliza comanda faceti click pe butonul \'Trimite comanda\', situat in partea dreapta-sus a paginii.');
			auxx = "";
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
}


function addSeparatorsNF(nStr, inD, outD, sep)
{
	nStr += '';
	var dpos = nStr.indexOf(inD);
	var nStrEnd = '';
	if (dpos != -1) {
		nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
		nStr = nStr.substring(0, dpos);
	}
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(nStr)) {
		nStr = nStr.replace(rgx, '$1' + sep + '$2');
	}
	return nStr + nStrEnd;
}


taxasuplimentara = "";
function taxaSuplimentara(tip,valoare,transport) {
if (!taxasuplimentara)
{
	if(tip==1) { 
		var taxaTransport = 0;
		var pretTotal = valoare-transport;
	}
	else if(tip==2 || tip==3) {
		var taxaTransport = transport;
		var pretTotal = valoare;
	}
	
	var pretTotalT = pretTotal/1.19;
	var pretTotalT = pretTotalT.toFixed(2)
	var pretTotal = pretTotal.toFixed(2)
	
	pretTotalT = addSeparatorsNF(pretTotalT, '.', ',', '.')
	pretTotal = addSeparatorsNF(pretTotal, '.', ',', '.')
	
	document.getElementById("pretTotal").innerHTML = pretTotal+" Ron";
	document.getElementById("pretTotalT").innerHTML = "Pret fara TVA: "+pretTotalT+" Ron";
	
	//document.getElementById("valoareTransport").innerHTML = taxaTransport;
	//document.getElementById("valoareTransportT").innerHTML = taxaTransport;
	taxasuplimentara = "";
}
}

function GetXmlHttpObject() {
	var objXMLHttp=null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}