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) {
			$('#content').html(data);
	});
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function Set_Cookie( name, value) {
	document.cookie = name + "=" +escape( value );
	alert(name);
}
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

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: '/full_produs_zoom.htm?pr_id='+pr_id
	});
	return false;
}


	$(function(){
		var origText; 
		var idInterv;
		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() {
				var val = $('#textul').val();
				if (val == $('#textul').attr('alt')) {
					$(this).val('');
				}
				//if (loaded == 0) {
				//	origText = $('#textul').val();
				//	$(this).val('');
				//}
				$('#cautaprod').html('');
				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;
									$('#content').html(data);
									$('#textul').removeClass('ind_loading');									
							});
							x = 1;
						} 
					} else
						x = 0;
					lastUrl = txt;
				}, 1000);
			})
			.blur(function() {
				var val = $('#textul').val();
				if (val == '') {
					$(this).val($('#textul').attr('alt'));
				}
				clearInterval(idInterv);
			});
	});


