
$(document).ready(function(){ 
	
	//pt. pag. lista brand-uri sau personaje
	if(typeof chr_selectat != 'undefined')
	{
		$(".litera img").hover(
			function(){ if($(this).attr("src").indexOf(chr_selectat+'_hover.jpg')!=-1) return;  var src2 = $(this).attr("src").replace('_hover','').replace('.jpg','_hover.jpg');  if(src2 != $(this).attr("src")) $(this).attr("src",src2);  },
			function(){ if($(this).attr("src").indexOf(chr_selectat+'_hover.jpg')!=-1) return;  var src2 = $(this).attr("src").replace('_hover','');                               if(src2 != $(this).attr("src")) $(this).attr("src",src2);  });
	}	
});

function onoff_produs_cos(ick, ajx, xsource)
{
	function cknot(ckx){  $(ckx).get(0).checked = !$(ckx).get(0).checked;  }
	
	ajx || (ajx=false);
	xsource || (xsource='x');
	
	try{
		var ckx = $('#'+ick), labelx=$('#label_'+ick), cked = ckx.get(0).checked;
		if(ckx.length!=1 || isNaN(parseInt(ckx.val()))) return;
		var hx = base_url2+'cos/index/ip/'+ckx.val()+'/?cantitate='+(cked ? 1 : 0)+'&ignore_qty=1&upd_cos=x&xsource='+xsource;
		if(!ajx){
			window.location.href = hx;
			return;
		}
		
		$(ckx).hide().after("<span><img src='images/ajax-loader.gif' alt='' /></span>");
		if(labelx.length==1) labelx.hide();
		
		$.ajax({
		  type: 'POST',
		  url: hx+'&ajx=1',
		  data: {},
		  complete: function(){  $(ckx).show().next('span').remove();  if(labelx.length==1) labelx.show();  },
		  success: 
		  	function(msg){  //alert(msg);  return;
				if(msg.substr(0,2)!='ok'){ alert('Sesiunea a expirat (err2387).'); cknot(ckx); if($("#msg_noi").length) $("#msg_noi").html(msg);  return; }
				msg=msg.substr(2);  //alert(msg);
				//msg = msg.replace(/[\n\r]+/gi,' ');
				var ret = {};
				eval(msg);
				if(typeof ret['err']=='undefined'){ alert('err294'); cknot(ckx); } //$("#msg_ajx_que_aj").html('err294');
				else if(ret['err']!=''){ alert(ret['err']); cknot(ckx); } //$("#msg_ajx_que_aj").html(ret['err']);
				else if(ret['msg']!='') alert(ret['msg']); //$("#msg_ajx_que_aj").html(ret['msg']);
				
				else if(labelx.length==1) labelx.html(cked ? 'Produsul e in cos.' : 'Adauga si acest produs in cos');
				
				if(typeof ret['nr_prod_cos']!='undefined' && !isNaN(parseInt(ret['nr_prod_cos']))) $("#nr_produse").html(ret['nr_prod_cos']);
			},
		   error: function(){ },
		   dataType: 'text'
		});
		
		
		
	}catch(e){ }
}

var default_email="abc@x.ro";

function record_email4stoc(iprodus, obx)
{
	try{
		if(!iprodus || isNaN(parseInt(iprodus)) || iprodus<1){ alert('err568'); return false; }
		
		var em = prompt("Lasa-ne adresa ta de email si te vom informa pe email deindata ce produsul dorit este disponibil in stoc", default_email);
		
		if(em==null) return false;
		if(em==""){ alert('Introdu adresa de email.');   anunta_stoc(iprodus);   return false; }
		if(em.search(/[^@]+@[^@]/gi)==-1){ alert('Adresa de email nu e corecta.');   anunta_stoc(iprodus);   return false; }
		//alert('go');
		
		$(obx).hide().after("<span><img src='"+base_url2+"images/ajax-loader.gif' alt='' /></span>");
		
		$.ajax({
		  type: 'POST',
		  url: base_url2+'produs/record_email4stoc',
		  data: {'iprodus': iprodus, 'email': em},
		  complete: function(){  $(obx).show().next('span').remove();  },
		  success: 
		  	function(msg){  //alert(msg);  return;
				if(msg.substr(0,2)!='ok'){ alert('Sesiunea a expirat (err2387).'); return; }
				msg=msg.substr(2);  //alert(msg); //msg = msg.replace(/[\n\r]+/gi,' ');
				var ret = {};
				eval(msg);
				if(typeof ret['err']=='undefined'){ alert('err294'); }
				else if(ret['err']!=''){ alert(ret['err']); }
				else if(ret['msg']!='') alert(ret['msg']);
			},
		   error: function(){ },
		   dataType: 'text'
		});		
  		
	}catch(e){ }
	
	return false;
}


/*
var akmenu = 'categorii,varsta,personaje,brand,noutati,reduceri_selected'.split(',');

$(document).ready(function(){
	var kid, obx;
	for(kid in akmenu){
		obx=$("#"+akmenu[kid]);
		if(obx.length!=1) continue;
		obx.mouseover(function(){ 
				alert('top:'+$(this).position().top+'; left:'+$(this).position().left); 
			})
			.mouseout(function(){ 
				//alert(this.id); 
			});
	}
});
*/


