var tipx = 0, tipy = 0, deltaY = new Array( 500 ), deltaX = new Array( 500 );
var semafor = new Array( 500 ), tabelki = new Array( 500 ), miey = new Array( 500 );
var presentLayer;
var ns4 = ( document.layers ) ? true : false;
var ns6 = ( document.getElementById ) ? true : false;
var ie4 = ( document.all ) ? true : false;
var ie5 = false;

if( ie4 ){
	if( ( navigator.userAgent.indexOf( 'MSIE 5' ) > 0 ) || ( navigator.userAgent.indexOf( 'MSIE 6' ) > 0 ) )ie5 = true;
	if( ns6 )ns6 = false;
}
if( ns4 || ie4 || ns6 ){
	document.onmousemove = setpos;
	if( ns4 )document.captureEvents( Event.MOUSEMOVE )
}

function setpos( evt ){
	if( ns4 || ns6 ){
		tipx = evt.pageX;
		tipy = evt.pageY;
	}
	if( ie4 ){
		tipx = event.x;
		tipy = event.y;
	}
	if( ie5 ){
		tipx = event.x + document.body.scrollLeft;
		tipy = event.y + document.body.scrollTop;
	}
	tipx += 20; tipy += 20;
}

function makeLayer( LayerName, LayerText, X, Y, Width, Height ){
	if( ie4 || ns6 || ns4 ){
//		str = '<div class="tip" onMouseOver="semafor['+LayerName+']++;window.status=\'S=\'+semafor['+LayerName+']" onMouseOut="semafor['+LayerName+']--;if( semafor['+LayerName+'] == 0 )hideTip( '+LayerName+' );" ID="' + LayerName + '"><table ' + ( Width ? 'width=' + Width : '' ) + ' bgcolor="#000000" cellspacing="1" cellpadding="0"><tr><td><table bgcolor="#FFFFFF" border="0" cellspacing="5" cellpadding="0"><tr><td class=text><div align=justify>' + LayerText + '</div></td></tr></table></td></tr></table></div>';
//		document.write( str );
		hideLayer( LayerName );
		moveLayer( LayerName, 0, 0 );
	}
	deltaY[LayerName] = ( Y ? Y : 0 );
	deltaX[LayerName] = ( X ? X : 0 );
	semafor[LayerName] = 0;
}

function showLayer( LayerName ){
	if( ns4 )
		document[LayerName].visibility = 'visible';
	if( ns6 )
		document.getElementById( LayerName ).style.visibility = 'visible';
	if( ie4 )
		document.all[LayerName].style.visibility = 'visible';
}

function moveLayer( LayerName, x, y ){
	if( ns4 ){
		document.layers[LayerName].left = x;
		document.layers[LayerName].top = y;
	}
	if( ns6 ){
		document.getElementById( LayerName ).style.left = x;
		document.getElementById( LayerName ).style.top = y;
	}
	if( ie4 ){
		document.all[LayerName].style.left = x;
		document.all[LayerName].style.top = y;
	}
}

function hideLayer( LayerName ){
	if( ns4 )
		document[LayerName].visibility = 'hidden';
	if( ns6 )
		document.getElementById( LayerName ).style.visibility = 'hidden';
	if( ie4 )
		document.all[LayerName].style.visibility = 'hidden';
}

function showTip( LayerName, x, y ){
	moveLayer( LayerName, 
		x ? x : tipx + ( deltaX[LayerName] != 0 ? deltaX[LayerName] : ( tipx > 400 ? -200 : 0 ) ),
		y ? y : tipy + deltaY[LayerName] );
	showLayer( LayerName );
}

function hideTip( LayerName ){
	hideLayer( LayerName );
}

function omov( LayerName, tabelka, N ){

semafor[LayerName]++;
if( tabelka )tabelki[LayerName] = tabelka;
if( semafor[LayerName] == 1 ){
    presentLayer = LayerName;
    if( !miey[LayerName] )miey[LayerName] = 295 + N * 20;
    s = 'opoznijPokazanie( \'' + LayerName + '\' )';
    setTimeout( s, 1 );
}
//document.all[tabelka].style.position = 'absolute';
//window.status='S='+document.all[tabelka].style.position.posTop;
}

function omou( LayerName ){

var s;
if( semafor[LayerName] == 1 ){
    presentLayer = '';
    s = 'opoznijUkrycie( \'' + LayerName + '\' )';
    setTimeout( s, 1 );
}
semafor[LayerName]--;
//window.status='S='+semafor[LayerName];
}

function opoznijUkrycie( LayerName ){

if( presentLayer != LayerName || semafor[LayerName] < 1 ){
    document.all[tabelki[LayerName]].bgColor='';
    hideTip( LayerName );
}
}

function opoznijPokazanie( LayerName ){

document.all[tabelki[LayerName]].bgColor='#FFFFFF';
//showLayer( LayerName );
//document.all[LayerName].style.top;
showTip( LayerName, 130, miey[LayerName] );

}
function __trySubmit(form)
{
  if (__pageIsValid(form))
    return true;
  else
  {
    alert('Nie wybrałeś ilości dodawanych artykułów, lub wpisana ilość jest niepoprawna.');
    return false;
  }
}
function __pageIsValid(form) 
{
	var validators = document.all.tags("stoperValidator");
	if(validators == null)
		return true;

	var isValid = false;
	for(i=0;i<validators.length;i++)
	   isValid = isValid || __StoperValidator(form, validators[i]);

    return isValid;
}
function __StoperValidator(form, validator)
{
    var controlToValidate = validator.getAttribute('ControlToValidate');

    if(document.forms[form].item(controlToValidate) == null) 
		return false;

    var value = document.forms[form].item(controlToValidate).value;

    if (value == "") 
		return false;
    var n=Number(value)

    if(n>=0)
		return true;
    else
		return false;
}
