function on_box() {
          a = document.getElementsByTagName("input");
		  for(i=0; i<a.length; i++){
                   a[i].checked = true;
                   }
}

function off_box() {
          a = document.getElementsByTagName("input");
          for(i=0; i<a.length; i++){
                   a[i].checked = false;
                   }
          }
		  
function confirmLink_Text(theLink, text)
{
	qs = confirm(text);
	if(qs)
	{
		window.location=theLink;
	}
}
function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else
		countfield.value = maxlimit - field.value.length;
}

function confirmLink(theLink)
{
	qs = confirm("Usunięcie jest nieodwracalne.\nCzy napewno usunąć?");
	if(qs)
	{
		window.location=theLink;
	}
}

function OpenWindow(theURL,winName,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=no'
	window.open(theURL,winName,settings);
}



function OpenFormatWindow(theURL,winName,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
	pop = window.open(theURL,winName,settings);
	pop.document.write('<title>GALERIA</title><body bgcolor="white" topmargin="0" leftmargin="0"><center>');
	pop.document.write('<a href="javascript:window.close();"><img src="'+theURL+'" alt="Zamknij okno" border=0></a></center>');
	pop.document.write('</body>');
}

function dodaj_element(kontener, name){
	var znacznik = document.createElement('input');
	znacznik.setAttribute('type', 'text');
	znacznik.setAttribute('name', name);
	znacznik.className = 'rozmiary';
	var kontener = document.getElementById(kontener);
	kontener.appendChild(znacznik);
}

$(document).ready(function()
{
	$('.customer').click(function() {
		$('#hurtCustomer').toggle();
		$('#detalCustomer').toggle();
		$('#hurtLogin').toggle();
		$('#detalLogin').toggle();		
	});
	
	// polec znajomemu
	$('#recommend a').click(function() {
		$('#recommend form').toggle('slow');
	});
	
	// zmiana stylu numeracji
	$('.prod_size input').change(function() {
		var size = $(this).val();
		var td_id = $(this).attr('id').substr(3);
		if ( size > 0 ) {
			$('.prod_size #td_'+td_id).css({'background':'#58585a', 'color':'#fff', 'font-weight':'bold'});
		}
		else
		{
			$('.prod_size #td_'+td_id).css({'background':'#fff', 'color':'#58585a', 'font-weight':'normal'});
		}
	});	
	
	// okno z wydrukami sladow
	$('.print_trace').click(function() {
		var ids = '';
		$('.styled[type=checkbox]').each(function(index) {
			if ( $(this).is(':checked') ) {
				//alert(index + ': ' + $(this).val());
				ids += $(this).val() + ',';
			}	
		});	
		window.open('print.php?idg='+ids, '_blank');
	});			
	
	/* Tips */
	$('.icohelp').mouseover(function(e) {
		 
		var sw = screen.width/2;
		var tip = $(this).html();   
		
		if (tip != '')
		{
			$('body').append('<div id="tooltip">' + tip + '</div>');    
			 
			//Set the X and Y axis of the tooltip
			if (e.pageX < sw) {
				$('#tooltip').addClass("tip_right");
				$('#tooltip').css('top', e.pageY + 10 );
				$('#tooltip').css('left', e.pageX + 15 );
			} else {
				$('#tooltip').addClass("tip_left");
				$('#tooltip').css('top', e.pageY + 10 );
				$('#tooltip').css('left', e.pageX - tw - 30);
			}
			 
			//$('#tooltip').fadeIn('1000');
			//$('#tooltip').fadeTo('10',0.5);
		}
		 
	}).mousemove(function(e) {
		var sw = screen.width/2;	
		var tw = $('#tooltip').width();
		
		$('#tooltip').css('top', e.pageY + 10 );
		if (e.pageX < sw) {
			$('#tooltip').css('left', e.pageX + 15 );
		} else {
			$('#tooltip').css('left', e.pageX - tw -30);			
		}

	}).mouseout(function() {
		$('body').children('div#tooltip').remove();
	});	
});


