function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//------------- compara

function add2wish_list(idprodus)
{
	try{
		if(document.getElementById('focus_'+idprodus)){
			document.getElementById('focus_'+idprodus).innerHTML='';
			document.getElementById('focus_'+idprodus).blur();
		}
		if(document.getElementById('wait_'+idprodus)) document.getElementById('wait_'+idprodus).innerHTML='<img src="'+base_url+'images/wait.gif" alt="" />';
	}catch(e){ }
	
	//document.getElementById('iff').src = base_url+'ajax_general.php?ajax_act=wish_list&act=add&iprodus='+idprodus;	
	
	document.getElementById('divfr').innerHTML='';
	document.getElementById('divfr').innerHTML='<iframe style="width:1px; height:1px; border:solid 0px #000000;" src="'+base_url+'ajax_general.php?ajax_act=wish_list&act=add&iprodus='+idprodus+'"></iframe>';
	
}

function delete_from_wish_list(idprodus)
{
	try{
		if(document.getElementById('waitdelete_'+idprodus)) document.getElementById('waitdelete_'+idprodus).innerHTML='<img src="'+base_url+'images/wait.gif" alt="" />';
	}catch(e){ }
	//document.getElementById('iff').src = base_url+'ajax_general.php?ajax_act=wish_list&act=delete&iprodus='+idprodus;
	
	document.getElementById('divfr').innerHTML='';
	document.getElementById('divfr').innerHTML='<iframe style="width:1px; height:1px; border:solid 0px #000000;" src="'+base_url+'ajax_general.php?ajax_act=wish_list&act=delete&iprodus='+idprodus+'"></iframe>';
		
}

function refresh_box_wish_list()
{
	makeRequest('div_box_wish_list', base_url+'ajax_general.php?ajax_act=get_box_wish_list');
}

var cmp_tout=null;

function compara_produs(idp, sterge)
{
	try{
		sterge || (sterge=false);
		sterge = (sterge ? '&sterge_iprod='+idp : '');
		var idtag='btn_cmp_'+idp, ob = jQuery('#'+idtag), idwait = 'wait_cmp_'+idp;
		var htm_wait = ' <img id="'+idwait+'" src="images/wait.gif" alt="" align="middle" />';
		var xurl = base_url+'index.php?popup=popup_cmp&iprodus='+idp+sterge;
		
		jQuery('#'+idwait+', #cmp_raspuns').remove();
		
		ob.after(htm_wait);

		jQuery.get(xurl+'&ajax=1', function(data)
		{   //alert(data);
			jQuery('#'+idwait).remove();
			var nrp = parseInt(data), msgx='';
			
			if(sterge){   jQuery('#sticky_line_'+idp).remove();   }
			
			refresh_sticky_box();
			
			if(isNaN(nrp)) return;
			if(cmp_tout) clearTimeout(cmp_tout);
			
			if(sterge){ }
			else if(nrp==1){
				msgx = '<span class="text_negru_11px" style="font-size:10px;">Alege al doilea produs</span>';
				cmp_tout = setTimeout(function(){ jQuery('#cmp_raspuns').remove(); }, 2000);
			}else if(nrp>1){
				msgx = "<a class=\"buton_negru_11px_bold\" style=\"color:#336699; font-weight:normal; text-decoration:underline;\" href=\"#\" onclick=\"arata_popup_cmp('"+xurl+"'); jQuery(this).remove(); return false;\">Arata cele "+nrp+" produse alese</a>";
				//var wx=window.open(xurl,'wcmp','left=70,top=30,width=650,height=620,menubar=yes,resizable=yes,scrollbars=yes'); wx.focus(); 
			}
			if(msgx!='') ob.after('<div id="cmp_raspuns" style="font-weight:normal;">'+msgx+'</div>');
		});
	}catch(e){ }
	
	return false;
}

var wpopup_cmp = '';
function arata_popup_cmp(xurl)
{
	wpopup_cmp = window.open(xurl,'wcmp','left=70,top=30,width=650,height=620,menubar=yes,resizable=yes,scrollbars=yes'); 
	wpopup_cmp.focus();
}

var mysticky = '';

function arata_sticky_cmp()
{
	if(p_idc=='' || jQuery('#id_sticky').length==0) return;
		
	try{  if(wpopup_cmp) wpopup_cmp.location.href = wpopup_cmp.location.href + '&xer=1';  }catch(e){ }
	
	if(jQuery('#id_sticky').html().search(/[a-z]/gi)==-1){  jQuery('#id_sticky').hide();  try{ if(wpopup_cmp) wpopup_cmp.close(); }catch(e){ }    return;  }
	
	if(!mysticky)
	mysticky=new stickynote({
		content:{divid:'stickynote1', source:'inline'},
		pos:['right', 'center'],
		showfrequency:'always',
		hidebox:0
	});
	
	jQuery('#id_sticky').show();
	if(xcat_alias){  jQuery('#sticky_box_sbm').attr('class','buton_'+xcat_alias+'_11px').css('font-weight','bold');   jQuery('#id_sticky').css('border-color', jQuery('#sticky_box_sbm').css('color'));  }
}

var p_idc='', xcat_alias='';

jQuery(document).ready(function() 
{
	jQuery(window).resize(function(){  resize_window();  });

	resize_window();
	//if(p_idc && jQuery('#id_sticky').length && jQuery('#id_sticky').html().search(/[a-z]/gi)!=-1) 
	arata_sticky_cmp();
});

function resize_window(){
	try{
		if(jQuery('#stickynote1').length){
			var wx=jQuery(window).width(), wdiv = Math.round((wx-1025)/2); //, wdiv=jQuery('#id_sticky').width(), xdif = (wx - 990 - 100 - wdiv)/2;  //alert(''+wx+' - 990 - '+wdiv)
			if(wdiv<70) wdiv=90;
			jQuery('#stickynote1').css('width',''+wdiv+'px');
			//(wdiv<jQuery('#id_sticky').width()-30) ? jQuery('#id_sticky').hide() : jQuery('#id_sticky').show();
			jQuery('#id_sticky').show();
		}
	}catch(e){ }
}

function refresh_sticky_box()
{
	try{
		if(p_idc=='') return;
		jQuery('#id_sticky').html('<img src="images/wait.gif" alt="" align="middle" />');

		jQuery.get('index.php?&ajax=1&p_idc='+p_idc, function(data)
		{   
			//alert(data);
			jQuery('#id_sticky').html('');
			if(data.indexOf('<body')!=-1 || data.length>10000) return;
			jQuery('#id_sticky').html(data);
			arata_sticky_cmp();
		});	
	}catch(e){ }
}

