get_element = document.all ?
	function (s_id) { return document.all[s_id] } :
	function (s_id) { return document.getElementById(s_id) };


function show(x) {
	get_element(x).style.display = '';
}

function hide(x) {
	get_element(x).style.display = 'none';
}

function navigate(url) {
	window.location.href=url;	
}


function showPic(img) {
	
}

function show_loading() {
	window.scroll(0,0);
	$('#loading').show();
	setTimeout(function () {		
		$('#loading').hide();
		//alert('Operatia solicitata va mai dura o perioada !');
	},25000);
}

function load_content_url(url) {
	$.get(url,function(data,textStatus) {
			$('#textulcontent').html(data);
	});
}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function show_details(pr_id) {
	$.nyroModalManual({
		 url: '/poze/'+pr_id+'/2/'+pr_id+'.jpg'
	});
	return false;
}


function upsellclick(pr_id,lei){
	var elm = $('#upsell_'+pr_id);
	if (elm.is(':checked')) {
		var url = "/AdaugaInCos.jsp?pr_id="+pr_id+"&setcant=1&retlink=/afiseazaTotal.ftl?full=1";
		$.get(url,function(data) {
			$('#CosHeader').load('/afiseazaCosHeader.ftl?full=1');
		});
	} else {
		var url = "/AdaugaInCos.jsp?pr_id="+pr_id+"&setcant=0&retlink=/afiseazaTotal.ftl?full=1";
		$.get(url,function(data){
			$('#CosHeader').load('/afiseazaCosHeader.ftl?full=1');
		});
	}
	return true;
}

$(function(){
	var origText; 
	var idInterv = 0;
	var lastUrl="";
	var x = 0;
	var loaded = 0;
	$('#textul')
		/*.autocomplete("/cautaProduse.jsp?ax=cautaAjax",{
			minChars:1 , 
			autoFill:false,
			width:400,
			selectFirst: false,
			selectOnly: false,
			formatItem: function(row,i,num){
					return '<div><img width="50" src="/poze/'+row[1]+'/3/poza.jpg" />'+row[0]+'</div>';
					}
			})
		.result(function(event,data,formatted){
				if (data[1]!='0'){
					document.location = "/AfiseazaProdus.jsp?pr_id="+data[1];
				}
			})*/
		.click(function() {
			if (loaded == 0) {
				origText = $('#textul').val();
				$(this).val('');
			} else 
				$(this).select();
			$('#cautaprod').html('');
		})
		.keypress(function() {
			var vv = $(this).val();
			if (vv.length > 4) {
			$('#textul').addClass('ind_loading');
			if (idInterv != 0)
				clearInterval(idInterv);
			idInterv = setInterval(function() {
				var txt = $('#textul').val();
				if (lastUrl == txt) {
					if (txt.length > 2 && x == 0) {
						//$('#textul').addClass('ind_loading');
						var url = "/cautaProduse.jsp?ax=cautaProduseAx&q="+txt;
						$.get(url,function(data,textStatus) {
								if (data  && data.length > 10)
									loaded = 1;
								else
									loaded = 0;
								$('#textulcontent').html(data);
								$('#textul').removeClass('ind_loading');									
						});
						x = 1;
					} 
				} else
					x = 0;
				lastUrl = txt;
			}, 300);
			}
		})
		.blur(function() {
			if (loaded == 0)
				$(this).val(origText);
			clearInterval(idInterv);
		});

	$('span.zoom img').mouseover(function(){
		$(this).css('border','1px solid #eee');
	}).mouseout(function(){
		$(this).css('border','0px none');
	});
});


if (window == window.top) {
	url = document.location.pathname;
	if (document.location.search != '')
		url += document.location.search;
	document.location = "http://apps.facebook.com/digitus"+url;
}


function wishFB(pr_id) {
	FB.login(function(response){	
		if (response.session) {
			$.getJSON('feed.jsp?type=json-wish&mt=application/json&pr_id='+pr_id,function(data) {
				var share = data;
				if (typeof(data.error) == 'undefined') {
					FB.ui(share,function (response) {
						//alert(response);
					});
				} else {
					alert('Eroare: '+data.error);
				}
			});
		} else {
			alert('Pentru a putea adauga in wishlist trebuie sa fiti conectat cu aplicatia Digitus !');
		}
	});
	return false;
}

function unwishFB(pr_id) {
	$.getJSON('feed.jsp?type=json-unwish&mt=application/json&pr_id='+pr_id,function(data) {
		var share = data;
		if (typeof(data.error) == 'undefined') {
			document.location="/wishlist.htm";
		} else {
			alert('Eroare: '+data.error);
		}
	});
	return false;
}


function shareFB(pr_id) {
	FB.login(function(response){	
		if (response.session) {
			$.getJSON('feed.jsp?type=json-share&mt=application/json&pr_id='+pr_id,function(data) {
				var share = data;
				if (typeof(data.error) == 'undefined') {
					FB.ui(share,function (response) {
						//alert(response);
					});
				} else {
					alert('Eroare: '+data.error);
				}
			});
		} 
	});
	return false;
}

function isIEOrSafari() {
	return (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) || /safari/i.test(navigator.userAgent);
}
