/* Alert */
var IE6 = false
function modalBox(content, width, callback)
{
	if(!content){ $('#ntz_modal').remove(); $('#ntz_overlay').fadeOut(function(){$(this).remove();}); try{if(IE6){$('body').find('select').visibility('visible');}}catch(err){}; return false; }
	try{if(IE6){$('body').find('select').visibility('hidden');}}catch(err){};
	$('body').append('<div id="ntz_overlay"><\/div>');
	$('#ntz_overlay').css({ width:'100%', height:$(document).height(), position:'absolute', left:0, top:0, backgroundColor:'#000', zIndex:9990, opacity:0 }).fadeTo(200, 0.5).click(function(){modalBox()});
	$('body').append('<div id="ntz_modal"><\/div>');
	$('#ntz_modal').css({ width:width ? width : 408, position:'absolute', border:'1px solid #E7E7E7', backgroundColor:'#E7E7E7', left:'50%', top:$(document).scrollTop()+250, zIndex:9995, marginLeft: -(Math.ceil((width ? width : 300)/2)) }).append(content);
	$('#ntz_modal a:eq(0), #ntz_modal input, #ntz_modal textarea').focus();
	try{ callback.call(); }catch(err){};  
	$(document).bind('scroll', function(){ $('#ntz_modal').css({top:$(document).scrollTop()+250}); });
};

/* 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+'');
}

/* Cauta produse */
function cautareVexio(prefix) {
	document.cauta.action='https://www.vexio.ro/'+prefix+'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='https://www.vexio.ro/'+prefix+'cauta-in-site/'+produs+'Categorie,'+document.cautas.camp_categorie.value+'/Pagina1';
}

/* Cauta categorii */
var xmlHttp
function autosuggest()
{
	categorie = document.getElementById('cautaCategorii').value;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) { return }
	var url="https://www.vexio.ro/Ajax_cautaCategorii.php"
	url = url+"?categorie="+categorie
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4){
			var e = document.getElementById('rezultatSCategorii');
			var raspuns = xmlHttp.responseText;
			if(raspuns!=""){ e.innerHTML=raspuns; e.style.display="block"; }
			else { e.style.display="none"; }
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

/* Meniu */
function actiuneMeniu(idMeniu)
{
	var idActiune = document.getElementById(idMeniu);
	if(idActiune.style.display=="none") { $('#'+idMeniu).slideDown(100); status=0; }
	else { $('#'+idMeniu).slideUp(100); status=1; }

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) { return }
	var url="https://www.vexio.ro/Ajax_meniuVizitator.php"
	url = url+"?idMeniu="+idMeniu
	url = url+"&status="+status

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById("inchideTot").innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function actiuneToate(tip)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) { return }
	var url="https://www.vexio.ro/Ajax_meniuVizitatorToate.php"
	url = url+"?tip="+tip

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			var id = xmlHttp.responseText;
			splitV = id.split(',');

			none=(tip=='inchis')?"block":"none";
			for(i=0;i<splitV.length;i++) {
				if(document.getElementById("subcat_"+splitV[i])) document.getElementById("subcat_"+splitV[i]).style.display = none;
			}

			if(tip=='deschis') inchideTotx = "Kategoriler<a href=\"javascript:void(0);\" title=\"Deschide tot meniul\" onclick=\"actiuneToate('inchis');\" class=\"btnBox tooltip\"><img src=\"./img/btn_deschide_mn.jpg\" alt=\"\" /></a>";
			else inchideTotx = "Kategoriler<a href=\"javascript:void(0);\" onmouseover=\"Inchide tot meniul\" onclick=\"actiuneToate('deschis');\" class=\"btnBox tooltip\"><img src=\"./img/btn_inchide_mn.jpg\" alt=\"\" /></a>";
			document.getElementById("inchideTot").innerHTML = inchideTotx;
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function actiuneMeniuUt(idMeniu)
{
	var idActiune = document.getElementById(idMeniu);
	if(idActiune.style.display=="none") { $('#'+idMeniu).slideDown(100); status=1; }
	else { $('#'+idMeniu).slideUp(100); status=0; }

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) { return }
	var url="https://www.vexio.ro/Ajax_meniuUtilizator.php"
	url = url+"?idMeniu="+idMeniu
	url = url+"&status="+status

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById("inchideTot").innerHTML = xmlHttp.responseText;
		}
	}

	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function actiuneToateUt(tip)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) { return }
	var url="https://www.vexio.ro/Ajax_meniuUtilizatorToate.php"
	url = url+"?tip="+tip

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			var id = xmlHttp.responseText;
			splitV = id.split(',');

			none=(tip=='inchis')?"block":"none";
			for(i=0;i<splitV.length;i++) {
				document.getElementById("subcat_"+splitV[i]).style.display = none;
			}
			if(tip=='deschis') inchideTotx = "Kategoriler<a href=\"javascript:void(0);\" title=\"Deschide tot meniul\" onclick=\"actiuneToateUt('inchis');\" class=\"btnBox tooltip\"><img src=\"./img/btn_deschide_mn.jpg\" alt=\"\" /></a>";
			else inchideTotx = "Kategoriler<a href=\"javascript:void(0);\" title=\"Inchide tot meniul\" onclick=\"actiuneToateUt('deschis');\" class=\"btnBox tooltip\"><img src=\"./img/btn_inchide_mn.jpg\" alt=\"\" /></a>";
			document.getElementById("inchideTot").innerHTML = inchideTotx;
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

/* Cos cumparaturi */
var xmlHttp
auxx = "";
function adaugaincos(idprodus, tip,tipM) {
	if (!auxx) 
	{
		if(tip == 1) document.getElementById("adauga_"+idprodus).innerHTML = '<a href=\"javascript:void(0);\" class=\"icoAdaugaA\">Adauga in cos</a>';
		else if(tip == 2) document.getElementById("adauga_"+idprodus).innerHTML = '<a href=\"javascript:void(0)\" id=\"adaugaCosA\">Adauga in cos</a>';
		else if(tip == 3) document.getElementById("adauga_"+idprodus).innerHTML = '<a href=\"javascript:void(0)\"><img src=\"./img/indicator.gif\" alt=\"\" /></a>';
		else if(tip == 4) document.getElementById("adauga_"+idprodus).innerHTML = '<a href=\"javascript:void(0);\" id=\"addCosA\"></a>';

		auxx = idprodus;
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) { return }
		var url="https://www.vexio.ro/Ajax_Coscumparaturi.php"
		url = url+"?id="+idprodus
		url = url+"&tipM="+tipM

		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				if(tip == 1) document.getElementById("adauga_"+idprodus).innerHTML = '<a href="javascript:void(0);" onclick="adaugaincos('+idprodus+','+tip+',\''+tipM+'\')" class="icoAdauga">Adauga in cos</a>';
				else if(tip == 2) document.getElementById("adauga_"+idprodus).innerHTML = '<a href="javascript:adaugaincos('+idprodus+','+tip+',\''+tipM+'\')" title="Adauga in cos" id="adaugaCos">Adauga in cos</a>';
				else if(tip == 3) document.getElementById("adauga_"+idprodus).innerHTML = '<a href="javascript:adaugaincos('+idprodus+','+tip+',\''+tipM+'\')" title="Adauga in cos" class="tooltip"><img src="https://www.vexio.ro/img/ico_adaugacos.png" alt="" /></a>';
				else if(tip == 4) document.getElementById("adauga_"+idprodus).innerHTML = '<a href="javascript:adaugaincos('+idprodus+','+tip+',\''+tipM+'\')" title="Adauga in cos" id="addCos"></a>';

				document.getElementById("cosproduse").innerHTML = xmlHttp.responseText;
				document.getElementById("golestecos").innerHTML = 'Cos cumparaturi<a href="javascript:golestecos();" title="Goleste cosul de cumparaturi" class="btnBox tooltip"><img src="https://www.vexio.ro/img/btn_cos_golire.jpg" alt="" /></a>';
				modalBox('<div id="popup_container"><div id="popup_content"><b>Produsul a fost adaugat in cosul de cumparaturi.</b><br />&#187; <a href="https://www.vexio.ro/cos-cumparaturi"><b>Vizualizati cosul de cumparaturi</b></a><br />&#187; <a href="https://www.vexio.ro/date-personale">Finalizati comanda</a><br />&#187; <a href="#" onclick="modalBox();return false;">Continuati cumparaturile</a></div></div>');
				auxx = "";
			}
		}
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
}
function golestecos() 
{
	document.getElementById("cosproduse").innerHTML = '<img src="./img/indicator.gif" title="Va rugam sa asteptati." alt="Va rugam sa asteptati." />';
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) { 
		return 
	}
	var url="https://www.vexio.ro/Ajax_Golestecos.php"

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById("golestecos").innerHTML = xmlHttp.responseText;
			document.getElementById("cosproduse").innerHTML = 'Nu aveti produse in cos.';
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

/* Wishlist */
auxx = "";
function adaugainwishlist(idprodus,tip,tipM) {
	if (!auxx) 
	{
		if(tip == 1) document.getElementById("wishlist_"+idprodus).innerHTML = '<a href=\"javascript:void(0);\" class=\"icoWishlistA\">Adauga in wishlist</a>';
		else if(tip == 2) document.getElementById("wishlist_"+idprodus).innerHTML = '<a href=\"javascript:void(0);\" id=\"adaugaWishlistA\">Adauga in wishlist</a>';
		else if(tip == 3) document.getElementById("wishlist_"+idprodus).innerHTML = '<a href=\"javascript:void(0)\"><img src=\"./img/indicator.gif\" alt=\"\" /></a>';
		else if(tip == 4) document.getElementById("wishlist_"+idprodus).innerHTML = '<a href=\"javascript:void(0);\" id=\"addWishlistA\"></a>';

		auxx = idprodus;
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) { return }
		var url="https://www.vexio.ro/Ajax_Wishlist.php"
		url = url+"?id="+idprodus
		url = url+"&tipM="+tipM

		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				if(tip == 1) document.getElementById("wishlist_"+idprodus).innerHTML = '<a href="javascript:void(0);" onclick="adaugainwishlist('+idprodus+','+tip+',\''+tipM+'\')" class="icoWishlist">Adauga in wishlist</a>';
				else if(tip == 2) document.getElementById("wishlist_"+idprodus).innerHTML = '<a href="javascript:adaugainwishlist('+idprodus+','+tip+',\''+tipM+'\')" title="Adauga in wishlist" id="adaugaWishlist">Adauga in wishlist</a>';
				else if(tip == 3) document.getElementById("wishlist_"+idprodus).innerHTML = '<a href="javascript:adaugainwishlist('+idprodus+','+tip+',\''+tipM+'\')" title="Adauga in wishlist" class="tooltip"><img src="https://www.vexio.ro/img/ico_wishlist.png" alt="" /></a>';
				else if(tip == 4) document.getElementById("wishlist_"+idprodus).innerHTML = '<a href="javascript:adaugainwishlist('+idprodus+','+tip+',\''+tipM+'\')" title="Adauga in wishlist" id="addWishlist"></a>';
				

				document.getElementById("wishlistproduse").innerHTML = xmlHttp.responseText;
				document.getElementById("golestewishlist").innerHTML = 'Wishlist <a href="javascript:golestewishlist();" title="Goleste Wishlist-ul" class="btnBox tooltip"><img src="https://www.vexio.ro/img/btn_wishlist_golire.jpg" alt="" /></a>';
				modalBox('<div id="popup_container"><div id="popup_content"><b>Produsul a fost adaugat in cosul de wishlist.</b><br />&#187; <a href="#" onclick="modalBox();return false;">Continua cumparaturile</a><br />&#187; <a href="https://www.vexio.ro/wishlist">Acceseaza wishlist-ul</a></div></div>');
				auxx = "";
			}
		}
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
}
function golestewishlist() 
{
	document.getElementById("wishlistproduse").innerHTML = '<./img/indicator.gif" title="Va rugam sa asteptati." alt="Va rugam sa asteptati." />';
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) { 
		return 
	}
	var url="https://www.vexio.ro/Ajax_Golestewishlist.php"
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById("golestewishlist").innerHTML = xmlHttp.responseText;
			document.getElementById("wishlistproduse").innerHTML = 'Nu aveti produse in wishlist.';
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

/* Pret */
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,ramburs) {
if (!taxasuplimentara)
{
	if(tip==1) { 
		var ica = 'none';
		var taxaTransport = 0;
		var pretTotal = valoare-transport;
	}
	else if(tip==2) {
		var ica = 'none';
		var taxaTransport = transport;
		var pretTotal = valoare;
	}
	else if(tip==3) { 
		var ica = 'block';
		var taxaTransport = transport;
		var pretTotal = valoare+ramburs;
	}
	var pretTotalT = pretTotal/1.19;
	var pretTotalT = pretTotalT.toFixed(2)
	var pretTotal = pretTotal.toFixed(2)

	pretTotalT = addSeparatorsNF(pretTotalT, '.', ',', '.')
	pretTotal = addSeparatorsNF(pretTotal, '.', ',', '.')

	document.getElementById("ica").style.display = ica;
	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
}

/* Tooltip */
this.tooltip = function()
{
	xOffset = 10;
	yOffset = 20;
	$(".tooltip").click(function(e){ this.title = this.t; $("#tooltip").remove(); });
	$(".tooltip").hover(function(e) { this.t = this.title; this.title = ""; if(this.t!="undefined") { $("body").append("<p id='tooltip'>"+ this.t +"</p>"); $("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("fast"); } },
	function(){ this.title = this.t; $("#tooltip").remove(); });
	$(".tooltip").mousemove(function(e){ $("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px"); });
};
$(document).ready(function(){ tooltip(); });