/**
*   @version $Id$
*/

/**--------------------------------------------------------------------
*	konfigurator
*---------------------------------------------------------------------*/

	/**
	*	Opis: resetuje konfiguracje
	*/
	function resetConfig()
	{
		document.getElementById( "reset" ).value = "1";
		document.forms.configuratorForm.submit();
	}

	/**
	*	Opis: zarzadza przeladowaniami w konfiguratorze
	*/
	function configuratorSubmit( paramNumber, txt, type )
	{
		iVal = 0;
		iName = "";
		if( type == 1 )
		{
			i = 1;
			id = "value"+i+"";
			found = 0;
			while( ( found == 0 ) && ( oObj = document.getElementById( id ) ) )
			{
				if( oObj.checked )
				{
					iVal = document.getElementById( "confval"+i+"" ).value;
					iName = document.getElementById( "confvalname"+i+"" ).value;
					found = 1;
				}
				i++;
				id = "value"+i+"";
			}
		}
		else
		{
			found = 1;
		}
		if( found == 1 )
		{
			document.getElementById( "currentPar" ).value = paramNumber;
			document.getElementById( "chosenVal" ).value = iVal;
			document.getElementById( "chosenValName" ).value = iName;
			document.forms.configuratorForm.submit();
		}
		else
		{
			alert( txt );
		}
	}

/**-------------------------------------------------------------------*/


/**--------------------------------------------------------------------
*	tabbed panel i kody produktow w karcie katalogowej
*---------------------------------------------------------------------*/

	/**
	*	Opis: funkcja podswietla tabbed panel
	*/
	function lightTabbed( a_name, on )
	{
		obj = document.getElementById( a_name );
		iname = a_name+"div";
		//if( ( obj.style.fontWeight == 'normal' ) || ( obj.style.fontWeight == '400' ) )
		if( ( obj.style.color == '#993366' ) || ( obj.style.color == 'rgb(153, 51, 102)' ) || ( obj.style.color == '#142a3b' ) || ( obj.style.color == 'rgb(20, 42, 59)' ) )
		{
			if( on == 1 )
			{
				obj.style.color = '#993366';
				idiva = iname+"a";
				document.getElementById( idiva ).style.display = "none"
				idivb = iname+"b";
				document.getElementById( idivb ).style.display = "block"
			}
			else
			{
				obj.style.color = '#142a3b';
				idiva = iname+"a";
				document.getElementById( idiva ).style.display = "block"
				idivb = iname+"b";
				document.getElementById( idivb ).style.display = "none"
			}
			
		}
	}

	/**
	*	Opis: funkcja zarzadza przelaczaniem tabbed panel
	*/
	function showTabbed( a_name, a_num, a_id ) 
	{
		// a_name to nazwa wspolna dla grupy paneli
		// a_num to ilosc paneli w grupie [ 1..n ]
		// a_id to numer panelu w grupie [ 0..n-1 ]
		for( i = 0; i < a_num; i++ )
		{
			l_tab = ''+a_name+''+i+'';
			obj = document.getElementById( l_tab );
			obj.style.display = 'none';
			l_tabtop = ''+a_name+''+i+'top';
			if( objtop = document.getElementById( l_tabtop ) )
			{
				objtop.style.color = '#142a3b';
				//objtop.style.fontWeight = 'normal';
				idiva = l_tabtop+"diva";
				document.getElementById( idiva ).style.display = "block"
				idivb = l_tabtop+"divb";
				document.getElementById( idivb ).style.display = "none"
			}
		}
		l_tab = ''+a_name+''+a_id+'';
		obj = document.getElementById( l_tab );
		obj.style.display = 'block';
		l_tabtop = ''+a_name+''+a_id+'top';
		objtop = document.getElementById( l_tabtop );
		objtop.style.color = '#9a3366';
		//objtop.style.fontWeight = 'bold';
		idiva = l_tabtop+"diva";
		document.getElementById( idiva ).style.display = "none"
		idivb = l_tabtop+"divb";
		document.getElementById( idivb ).style.display = "block"
	}

	/**
	*	Opis: obsluguje kody produktow na karcie katalogowej
	*/
	function zmien_kod()
	{
		vkod = document.getElementById( "kod" );
		vdkod = document.getElementById( "dkod" );
		vkod.value = vdkod.value;
		vcena = document.getElementById( "cena" );
		vdcena = document.getElementById( "dcena" );
		vcena.value = vdcena.value;
		vcenavat = document.getElementById( "cenavat" );
		vvat = document.getElementById( "dvat" );
		numer = 1;
		chks = "chks" + numer;
		chkc = "chkc" + numer;
		while( ( checks = document.getElementById( chks ) ) )
		{
			if( checks.checked )
			{
				vkod.value = vkod.value + checks.value;
				checkc = document.getElementById( chkc );
				new_valuec = parseFloat( checkc.value );
				old_value_plus = parseFloat( vcena.value );
				vcena.value = old_value_plus + new_valuec;
			}
			numer++;
			chks = "chks" + numer;
			chkc = "chkc" + numer;
		}
		cena_float = vcena.value;
		pos_cena = cena_float.indexOf( "." );
		if( pos_cena < 0 )
		{
			pos_cena = cena_float.indexOf( "," );
			if( pos_cena < 0 )
			{
				cena_float = cena_float + ".00";
			}
			else
			{
				s1 = cena_float.substring( 0, pos_cena );
				s1 = parseInt( s1 );
				s2 = cena_float.substring( pos_cena+1, pos_cena+2 );
				s2 = parseInt( s2 );
				v1 = cena_float.substring( pos_cena+2, pos_cena+3 );
				v1 = parseInt( v1 );
				v2 = cena_float.substring( pos_cena+3, pos_cena+4 );
				v2 = parseInt( v2 );
				if( v2 > 5 )
				{
					v1++;
					if( v1 > 9 )
					{
						v1 = 0;
						s2++;
						if( s2 > 9 )
						{
							s2 = 0;
							s1++;
						}
					}
				}
				cena_float = s1 + "." + s2 + v1;
			}
		}
		//vcena.value = cena_float;
		vcenaval = cena_float;
		somelen = vcenaval.length;
		dotpos = vcenaval.indexOf( "." ) + 3;
		if( dotpos < somelen )
		{
			vcenaval = vcenaval.substring( 0, dotpos )
		}
		vcena.value = vcenaval;
		new_vat = parseFloat( vvat.value );
		vcenavatval = vcena.value * new_vat;
		vcenavat.value = vcenavatval;
		new_vcenavat = vcenavat.value;
		pos = new_vcenavat.indexOf( "." );
		if( pos >= 0  )
		{
			ns1 = new_vcenavat.substring( 0, pos );
			ns1 = parseInt( ns1 );
			ns2 = new_vcenavat.substring( pos+1, pos+2 );
			ns2 = parseInt( ns2 );
			nv1 = new_vcenavat.substring( pos+2, pos+3 );
			if( nv1 != "" )
			{
				nv1 = parseInt( nv1 );
			}
			else
			{
				nv1 = 0;
			}
			nv2 = new_vcenavat.substring( pos+3, pos+4 );
			if( nv2 != "" )
			{
				nv2 = parseInt( nv2 );
			}
			else
			{
				nv2 = 0;
			}
			if( nv2 > 5 )
			{
				nv1++;
				if( nv1 > 9 )
				{
					nv1 = 0;
					ns2++;
					if( ns2 > 9 )
					{
						ns2 = 0;
						ns1++;
					}
				}
			}
			someval = ns1 + "." + ns2 + nv1
			somelen = someval.length;
			dotpos = someval.indexOf( "." ) + 3;
			if( dotpos < somelen )
			{
				someval = someval.substring( 0, dotpos )
			}
			vcenavat.value = someval;
		}
		else
		{
			vcenavat.value = new_vcenavat + ".00";
		}
	}

/**-------------------------------------------------------------------*/


/**--------------------------------------------------------------------
*	wyszukiwarka parametryczna
*---------------------------------------------------------------------*/

	/**
	* Global array PARAM_ARRAY that contains all param data MUST be provided!
	* Global variable EMPTY_OPTION_VALUE that contains first element name in param select MUST be provided!
	*/

	/**global array that contains product data*/
	var products = new Array();

	/**
	* Class used for managing parameter data
	* 
	* @param paramId       parameter id 
	* @param name          parameter name
	*/
	function ParameterObj( paramId, name )
	{
		this.id = paramId;              //parameter id
		this.valueCount = 0;            //number of parameter values
		this.valueId = new Array();     //array that contains specified parameter value ids
		this.valueIdIndex = new Array();
		this.useValues = 'undefined';   //determines using all values in parameter or any value in product search
		this.name = name;
		this.isParamVisible = true;
	}

	/**
	* Function used to add parameter value id
	* @param valueId       id of parameter value
	*/
	function ParameterObj_addValueId( valueId )
	{
		this.valueId[this.valueCount] = valueId;
		this.valueIdIndex[valueId] = valueId;
		this.valueCount++;
	}

	/**
	* Function used to get parameter name
	* @return string that contains parameter name
	*/
	function ParameterObj_getName( name )
	{
		return this.name;
	}

	/**
	* Function used to get parameter id
	* @return string that contains parameter id
	*/
	function ParameterObj_getId()
	{
		return this.id;
	}

	/**
	* Function used to check if parameter is visible
	* @return boolean true - if parameter is visible, false - otherwise
	*/
	function ParameterObj_isVisible()
	{
		return this.isParamVisible;
	}

	/**
	* Function sets parameter visible state
	* @param state         boolean that is true if parameter is visible, false - otherwise
	*/
	function ParameterObj_setVisible( state )
	{
		this.isParamVisible = state;
	}

	/**
	* Function checks if specified parameter fullfill search conditions specified by input parameter
	* Checks if parameters have same id, and compares parameters values.
	* If specified parameter must have all values provided by input parameter function checks if parameters have same values
	* If specified parameter must have any of inputed parameter values even only one value is enought to fullfill search conditions
	*
	* @param parameter     ParameterObj that contains search conditions
	*
	* @return boolean      true - specified parameter fullfills search conditions
	*                      false - specified parameter does not fullfill search conditions
	*/
	function ParameterObj_fullfill( parameter )
	{
		if( this.id != parameter.id )
		{
			return false;
		}
		if( parameter.useValues == 'all' )
		{
			var id = null;
			for( var i=0; i < parameter.valueId.length; i++ )
			{
				id = parameter.valueId[i];
				if( this.valueIdIndex.length <= id )
				{
					return false;
				}
				if( this.valueIdIndex[id] != id )
				{
					return false;
				}
			}
			return true;
		}
		if( parameter.useValues == 'any' )
		{
			for( var i=0; i < parameter.valueId.length; i++ )
			{
				id = parameter.valueId[i];
				if( this.valueIdIndex.length <= id )
				{
					continue;
				}
				if( this.valueIdIndex[id] == id )
				{
					return true;
				}
			}
			return false;
		}
	}

	/**
	* Function used for debug purposes.
	* Function shows parameter data in alert window
	* @param title         string that contains popup window title
	*/
	function ParameterObj_showData( title )
	{
		var text = 'Param id = ' + this.id + '\nValues:\n';
		for( var i = 0; i < this.valueId.length; i++ )
		{
			text += this.valueId[i] + ', ';
		}
		text += '\nUse values: ' + this.useValues;
		if( ( title != '' ) && ( title != 'undefined' ) && ( title != null ) )
		{
			text += '\nTitle: ' + title;
		}
		alert( text );
	}

	/**adding functions to prototype*/
	ParameterObj.prototype.addValueId = ParameterObj_addValueId;
	ParameterObj.prototype.isVisible = ParameterObj_isVisible;
	ParameterObj.prototype.setVisible = ParameterObj_setVisible;
	ParameterObj.prototype.getId = ParameterObj_getId;
	ParameterObj.prototype.getName = ParameterObj_getName;
	ParameterObj.prototype.fullfill = ParameterObj_fullfill;
	ParameterObj.prototype.showData = ParameterObj_showData;

	/**
	* Class used for managing product data
	* @param prodId       product id
	*/
	function ProductObj( prodId )
	{
		this.id = prodId;               //product id
		this.params = new Array();      //contains product parameters object
		this.paramCount = 0;            //parameters number
		this.found = true;              //determines if product fullfills search conditions
	}

	/**
	* Function used to add ParameterObj object to product
	* @param param instance of ParameterObj class
	*/
	function ProductObj_addParam( param )
	{
		this.params[param.id] = param;
		this.paramCount++;
	}

	/**
	* Function used to check if product fullfills search conditions defined by parameter paramToCheck
	* @param paramToCheck  instance of ParameterObj that contains search conditions
	*/
	function ProductObj_checkParam( paramToCheck )
	{
		var position = paramToCheck.id
		if( this.params.length >= position )
		{
			var param = this.params[position];
			if( typeof( param ) == 'object' )
			{
				if( param.fullfill( paramToCheck ) )
				{
					return;
				}
			}
		}
		
		this.found = false;
	}

	/**
	* Function checks if product fullfills search conditions.
	* Function checks only actual product state. State can change after parameters check
	* @return boolean      true - if product fullfills search conditions
	*                      false - if product does not fullfill search conditions
	*/
	function ProductObj_isFound()
	{
		return this.found;
	}

	/**
	* Function reset product state to start state
	*/
	function ProductObj_resetFound()
	{
		this.found = true;
	}

	//adding functions to prototype
	ProductObj.prototype.addParam = ProductObj_addParam;
	ProductObj.prototype.checkParam = ProductObj_checkParam;
	ProductObj.prototype.isFound = ProductObj_isFound;
	ProductObj.prototype.resetFound = ProductObj_resetFound;

	/**
	* Function used to copy search parameter div defined by id like 'paramSearchDiv_PARAMID_prototype' prototypes MUST be provided.
	* Function manages parameter select html object data
	* @param paramId       contains parameter id
	*/
	function showSearchParam( paramId )
	{
		var paramDiv = document.getElementById( 'paramSearchDiv_' + paramId + '_prototype' ).cloneNode(true);
		paramDiv.id = 'paramSearchDiv_' + paramId;
		paramDiv.name = 'paramSearchDiv_' + paramId;
		paramDiv.style.display = 'block';
		document.getElementById( 'paramSearchPanelDiv' ).appendChild( paramDiv );
		manageParamSelect( paramId, true );
		countProducts();
	}

	/**
	* Function hides search parameter div defined by id like 'paramSearchDiv_PARAM_ID'.
	* Function manages parameter select html object data
	* @param paramId       contains parameter id
	*/
	function hideSearchParam( paramId )
	{
		var paramDiv = document.getElementById( 'paramSearchDiv_' + paramId );
		paramDiv.parentNode.removeChild( paramDiv );
		manageParamSelect( paramId, false );
		countProducts();
	}

	/**
	* Function manages html select object state that contains parameter data.
	* Id and name attribute of this object MUST be 'paramSearchSelect'
	* Document MUST contain summary div html object 'paramSearchSummaryDiv1' and 'paramSearchSummaryDiv2'
	*
	* @param paramId       string id of parameter in select
	* @param isReduced     boolean determines action on parameter describbed by id
	*                      true - parameter must be added to select object
	*                      false - parameter must be removed from select object
	*/
	function manageParamSelect( paramId, isReduced )
	{
		var paramSelect = document.getElementById( 'paramSearchSelect' );
		//updating global parameters visibility
		for( var i = 0; i < PARAM_ARRAY.length; i++ )
		{
			if( PARAM_ARRAY[i].getId() == paramId )
			{
				PARAM_ARRAY[i].setVisible( !isReduced );
				break;
			}
		}
		//cleaning paramSelect
		for( var i = 0; i < paramSelect.options.length; i++ )
		{
			paramSelect.options[i] = null;
		}
		//generating paramSelect parameter options
		var optionEl = null;
		paramSelect.options[0] = new Option( EMPTY_OPTION_VALUE, '' );
		var optionCounter = 1;
		for( var i = 0; i < PARAM_ARRAY.length; i++ )
		{
			if( PARAM_ARRAY[i].isVisible() )
			{
				paramSelect.options[optionCounter] = new Option( PARAM_ARRAY[i].getName(), PARAM_ARRAY[i].getId() );
				optionCounter++;
			}
			
		}
		paramSelect.selectedIndex = 0;
		var hiddenOptionCount = 0;
		if( isReduced )
		{
			if( paramSelect.options.length == 1 )
			{
				paramSelect.style.display = 'none';
			}
			document.getElementById( 'paramSearchSummaryDiv1' ).style.display = 'block';
			document.getElementById( 'paramSearchSummaryDiv2' ).style.display = 'block';
		}
		else
		{
			paramSelect.style.display = 'block';
			if( paramSelect.options.length == PARAM_ARRAY.length + 1 ) 
			{
				document.getElementById( 'paramSearchSummaryDiv1' ).style.display = 'none';
				document.getElementById( 'paramSearchSummaryDiv2' ).style.display = 'none';
			}
		}
	}

	/**
	* Function counts products that fullfill search conditions
	* Search conditions must be defined in 'paramSearchForm' html form
	*
	* Search conditions MUST be defined as elements with name and id as:
	*
	* checkboxes - 'paramSearchParameter_PARAMETERID_VALUEID' where PARAMETERID - is parameter id and VALUEID is id of specified parameter value
	*
	* radios - 'paramSearchAllowedValues_PARAMETERID' determines if product must contain all checked values (element value 'all') or only one of them (element value 'any')
	*
	* Function sets html object values:
	* 'productNumber1' - number of products that fullfill search criteria
	* 'productNumber2' - number of products that fullfill search criteria
	* 'selectedProduct' - id of products that fillfill search criteria separated by comma
	* Those elements MUST be provided.
	*/
	function countProducts()
	{
		var form = document.getElementById( 'paramSearchForm' );
		var params = new Array();
		var inputs = form.getElementsByTagName( 'input' );
		var paramMem = '';
		var parCount = 0;
		var parOrder = new Array();
		for( var i = 0; i < inputs.length; i++ )
		{
			var paramId = '';
			var valueId = '';
			//searching checked values
			if( ( inputs[i].type == 'checkbox' ) && ( inputs[i].name.match( /^paramSearchParameter_[0-9]+_[0-9]+$/ ) != null ) )
			{
				if( inputs[i].checked )
				{
					var paramString = new String( inputs[i].name ).replace( /^paramSearchParameter_/, '' );
					paramId = paramString.replace( /_[0-9]+$/, '' );
					valueId = paramString.replace( /^[0-9]+_/, '' );
					if( params[paramId] == null )
					{
						params[paramId] = new ParameterObj( paramId );
					}
					params[paramId].addValueId( valueId );
					//
					if( ( parCount == 0 ) || ( ( parCount > 0 ) && ( parOrder[parCount-1] != paramId ) ) )
					{
						parOrder[parCount] = paramId;
						parCount++;
					}
					//
				}
			}
			//searching all or any param criteria
			if( ( inputs[i].type == 'radio' ) && ( inputs[i].name.match( /^paramSearchAllowedValues_[0-9]+$/ ) != null ) )
			{
				if( inputs[i].checked )
				{
					inputs[i].focus();
					var paramId = new String( inputs[i].name ).replace( /^paramSearchAllowedValues_/, '' );
					if( params[paramId] == null )
					{
						params[paramId] = new ParameterObj( paramId );
					}
					params[paramId].useValues = inputs[i].value;
				}
			}
		}
		//
		var was = 0;
		for( i = 0; i < parCount; i++ )
		{
			if( ( typeof( params[parOrder[i]] ) == 'object' ) && ( params[parOrder[i]] != null ) )
			{
				if( was != 0 )
				{
					paramMem += ';';
				}
				paramMem += '' + params[parOrder[i]].id + '';
				for( j = 0; j < params[parOrder[i]].valueCount; j++ )
				{
					paramMem += ',' + params[parOrder[i]].valueId[j] + '';
				}
				paramMem += ',' + params[parOrder[i]].useValues + '';
				was = 1;
			}
		}
		//paramMem = '' + document.getElementById( "paramSearchGroup" ).value + '.' + paramMem + '';
		document.getElementById( "paramSearchMemory" ).value = paramMem;
		//alert(paramMem);
		var i,j;
		var searchInProducts = true;
		//reseting product found status
		for( i = 0; i < products.length; i++ )
		{
			products[i].resetFound();
		}
		//checking if products fillfill search criteria
		for( i = 0; i < params.length; i++ )
		{
			if( ( typeof( params[i] ) == 'object' ) && ( params[i] != null ) )
			{
				if( params[i].valueCount == 0 )
				{
					searchInProducts = false;
					break;
				}
				for( j = 0; j < products.length; j++ )
				{
					if( products[j].isFound() )
					{
						products[j].checkParam( params[i] )
					}
				}
			}
		}
		//generating selectedProduct value
		var searchCount = 0;
		var searchProductId = '';
		for( i = 0; i < products.length && searchInProducts; i++ )
		{
			if( products[i].isFound() )
			{
				searchCount++;
				searchProductId += products[i].id + ';';
			}
		}
		document.getElementById( 'productNumber1' ).innerHTML = searchCount;
		document.getElementById( 'productNumber2' ).innerHTML = searchCount;
		//document.getElementById( 'selectedProduct' ).value = searchProductId;
		document.getElementById( 'checked_product' ).value = searchProductId;
	}

	/**
	*	Opis: przesyla dane z formularza wyszukiwarki parametrycznej
	*/
	function submitParamSearchForm( formName, inputName, errorMessage )
	{
		var element = document.getElementById( inputName );
		if( ( typeof( element ) == 'object' ) && ( element != null ) )
		{
			if( ( element.value != '' ) && ( element.value != '0' ) )
			{
				var form = document.getElementById( formName );
				if( ( typeof( form ) == 'object' ) && ( form != null ) )
				{
					form.submit();
					return;
				}
			}
			alert( errorMessage );
		}
	}

/**-------------------------------------------------------------------*/


/**--------------------------------------------------------------------
*	funkcje dodajace produkty do koszyka
*---------------------------------------------------------------------*/

	/**
	*	Opis: przeladowuje formularz na podana strone i ustawia pamiec
	*/
	function sendMemory( adr )
	{
		setMemory();
		document.forms.catalogsortform.action = adr;
		document.forms.catalogsortform.submit();
	}

	/**
	*	Opis: sprawdza, czy wartosc w polu jest wlasciwa
	*/
	function checkValue( id )
	{
		oInp = document.getElementById( "basket"+id+"" );
		if( !( myIsInt( oInp.value, 1, 999999999 ) && ( oInp.value >= 0 ) ) )
		{
			oInp.value = 0;
		}
	}

	/**
	*	Opis: ustawia w pamieci ilosci produktow
	*/
	function setMemory()
	{
		num = 0;
		mem = "";
		while( oId = document.getElementById( "bNum"+num+"" ) )
		{
			oInp = document.getElementById( "basket"+oId.value+"" );
			if( myIsInt( oInp.value, 1, 999999999 ) && ( oInp.value > 0 ) )
			{
				mem += ""+oId.value+"+"+oInp.value+"|";
			}
			num++;
		}
		document.getElementById( "orderCountMem" ).value = mem;
	}

	/**
	*	Opis: dodaje kilka produktow do koszyka
	*/
	function addToBasketMultiple( txt, txt2 )
	{
		zam = '';
		ok = 1;
		num = 0;
		while( ( ok == 1 ) && ( oId = document.getElementById( "bNum"+num+"" ) ) )
		{
			oCode = document.getElementById( "code"+oId.value+"" );
			oNum = document.getElementById( "basket"+oId.value+"" );
			if( myIsInt( oNum.value, 1, 999999999 ) )
			{
				if( oNum.value > 0 )
				{
					zam += ""+oCode.value+"+"+oNum.value+"|";
				}
			}
			else
			{
				ok = 0;
			}
			num++;
		}
		if( ok == 1 )
		{
			if( zam != '' )
			{
				document.getElementById( "koszykadd" ).value = zam;
				document.forms.koszykmem.submit();
			}
			else
			{
				alert( txt2 );
			}
		}
		else
		{
			alert( txt );
		}
	}

	/**
	*	Opis: dodaje kilka produktow do koszyka
	*/
	function addToUtilization( txt, txt2 )
	{
		zam = '';
		ok = 1;
		num = 0;
		while( ( ok == 1 ) && ( oId = document.getElementById( "bNum"+num+"" ) ) )
		{
			oCode = document.getElementById( "code"+oId.value+"" );
			oNum = document.getElementById( "basket"+oId.value+"" );
			if( myIsInt( oNum.value, 1, 999999999 ) )
			{
				if( oNum.value > 0 )
				{
					zam += ""+oCode.value+"+"+oNum.value+"|";
				}
			}
			else
			{
				ok = 0;
			}
			num++;
		}
		if( ok == 1 )
		{
			if( zam != '' )
			{
				document.getElementById( "utilityBasket" ).value = zam;
				document.forms.utilityMem.submit();
			}
			else
			{
				alert( txt2 );
			}
		}
		else
		{
			alert( txt );
		}
	}

	/**
	*	Opis: dodaje produkt w trybie listy do koszyka
	*/
	function addToBasket3( a_id, a_price, a_code, txt )
	{
		bask = document.getElementById( "basket"+a_id+"" );
		if( myIsInt( bask.value, 1, 999999999 ) && ( bask.value > 0 ) )
		{
			l_zam = a_id+"+"+a_code+"+"+a_price+"+"+bask.value+"|";
			document.getElementById( "koszykadd2" ).value = l_zam;
			document.forms.catalog_words_search.submit();
		}
		else
		{
			alert( txt );
		}
	}

	/**
	*	Opis: dodaje produkt w trybie listy do koszyka
	*/
	function addToBasket2( a_id, a_price, a_code, txt )
	{
		bask = document.getElementById( "basket"+a_id+"" );
		if( myIsInt( bask.value, 1, 999999999 ) && ( bask.value > 0 ) )
		{
			l_zam = a_id+"+"+a_code+"+"+a_price+"+"+bask.value+"|";
			document.getElementById( "koszykadd" ).value = l_zam;
			document.forms.koszykmem.submit();
		}
		else
		{
			alert( txt );
		}
	}

	/**
	*	Opis: dodaje produkt w karcie katalogowej do koszyka
	*/
	function addToBasket( a_id, a_txt )
	{
		numer = 1;
		chks = "chks" + numer;
		ok = 1;
		oktmp = 0;
		oldname = "";
		while( ( checks = document.getElementById( chks ) ) )
		{
			name = checks.name;
			if( oldname != name )
			{
				if( ( oktmp == 0 ) && ( oldname != "" ) )
				{
					ok = 0;
				}
				oldname = name;
				oktmp = 0;
			}
			if( checks.checked )
			{
				oktmp = 1;
			}
			numer++;
			chks = "chks" + numer;
		}
		if( ( oktmp == 0 ) && ( oldname != "" ) )
		{
			ok = 0;
		}
		if( ok == 1 )
		{
			l_cena = document.getElementById( "cena" ).value;
			l_kod = document.getElementById( "kod" ).value;
			l_zam = a_id+"+"+l_kod+"+"+l_cena+"+1|";
			document.getElementById( "koszykadd" ).value = l_zam;
			document.forms.koszykmem.submit();
		}
		else
		{
			alert( a_txt );
			showTabbed( "tab", 5, 2 );
		}
	}

/**-------------------------------------------------------------------*/

	/**
	*	Opis: odznacza zaznaczony produkt
	*/
	function unCheck( a_id, a_mem_id )
	{
		a_num = "chks"+a_id
		check = document.getElementById( a_num );
		memory = "mem"+a_mem_id;
		chk = document.getElementById( memory );
		if( chk.value == a_id )
		{
			check.checked = false;
			chk.value = 0;
		}
		else
		{
			chk.value = a_id;
		}
	}

	/**
	*	Opis: sprawdza, czy zaznaczony jest przynajmniej jeden produkt
	*/
	function isProductChecked( a_tekst, a_type )
	{
		jest = 0;
		numer = 0;
		chk = "chk" + numer;
		while( ( check = document.getElementById( chk ) ) && ( jest == 0 ) )
		{
			if( check.checked == true )
			{
				jest = 1;
			}
			numer++;
			chk = "chk" + numer;
		}
		if( ( jest == 1 ) || ( a_type == 0 ) )
		{
			document.forms.check_prod.submit();
		}
		else
		{
			alert( a_tekst );
		}
	}

	/**
	*	Opis: sprawdza, czy zaznaczony jest przynajmniej jeden produkt
	*/
	function isProductChecked2( a_tekst, a_adr )
	{
		jest = 0;
		numer = 0;
		chk = "chk" + numer;
		zaz = "";
		while( check = document.getElementById( chk ) )
		{
			if( check.checked == true )
			{
				zaz += check.value+";";
				jest = 1;
			}
			numer++;
			chk = "chk" + numer;
		}
		if( jest == 1 )
		{
			/*document.forms.check_prod.target = "_blank";
			document.forms.check_prod.action = a_adr;
			document.forms.check_prod.submit();*/
			a_adr += "/" + zaz;
			winObj = window.open( a_adr, "_blank", "channelmode=no, toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, titlebar=yes, fullscreen=no, width=800, height=600" );
		}
		else
		{
			alert( a_tekst );
		}
	}

	/**
	*	Opis: sprawdza, czy zaznaczony jest przynajmniej jeden produkt
	*/
	function openAuctionProduct( adr )
	{
		winObj = window.open( adr, "_blank", "channelmode=no, toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, titlebar=yes, fullscreen=no, width=800, height=600" );
	}

	/**
	*	Opis: sprawdza, w jakiej jestesmy przegladarce i zmienia adres parenta
	*/
	function openerUrl( url )
	{
		/*nav = window.navigator.userAgent
		if( nav.indexOf( "Opera" ) > -1 )
		{
			winObj = window.parent;
		}
		else
		{*/
			winObj = window.opener;
		//}
		winObj.location = url;
		winObj.focus();
	}

	/**
	*	Opis: sprawdza, czy zaznaczony jest przynajmniej jeden parametr
	*/
	function isParamChecked( a_tekst )
	{
		jest = 0;
		numer = 0;
		chk = "chk" + numer;
		while( ( check = document.getElementById( chk ) ) && ( jest == 0 ) )
		{
			if( check.checked == true )
			{
				jest = 1;
			}
			numer++;
			chk = "chk" + numer;
		}
		if( jest == 1 )
		{
			document.forms.check_param.submit();
		}
		else
		{
			alert( a_tekst );
		}
	}

	/**
	*	Opis: zaznacza wszystkie checkboxy
	*/
	function check_all()
	{
		numer = 0;
		chk = "chk" + numer;
		while( ( check = document.getElementById( chk ) ) )
		{
			check.checked = true;
			numer++;
			chk = "chk" + numer;
		}
	}

	/**
	*	Opis: odznacza wszystkie checkboxy
	*/
	function check_none()
	{
		numer = 0;
		chk = "chk" + numer;
		while( ( check = document.getElementById( chk ) ) )
		{
			check.checked = false;
			numer++;
			chk = "chk" + numer;
		}
	}

	/**
	*	Opis: resetuje filtry globalne
	*/
	function dropFilters()
	{
		document.getElementById( "dropFilters" ).value = 1;
		document.forms.paramFilterForm.submit();
	}

	/**
	*	Opis: resetuje filtry w grupie
	*/
	function dropGroupFilters()
	{
		document.getElementById( "dropGroupFilters" ).value = 1;
		document.forms.paramGroupFilterForm.submit();
	}

	/**
	*	Opis: usuwa parametr lub produkt z porownania
	*/
	function alterComparison( value, type )
	{
		if( type == 0 )
		{
			document.getElementById( "dropProduct" ).value = value;
		}
		else
		{
			document.getElementById( "dropParam" ).value = value;
			document.getElementById( "reloadCheck" ).value = "yes";
		}
		document.forms.dropForm.submit();
	}

	/**
	*	Opis: ustawia sortowanie w trybie akcesoria
	*/
	function setSort( sortBy, sortType )
	{
		setMemory();
		document.getElementById( "catalogSortBy" ).value = sortBy;
		document.getElementById( "catalogSortType" ).value = sortType;
		document.forms.catalogsortform.submit();
	}

	/**
	*	Opis: sprawdza, czy w wyszukiwarce dla katalogu 
	*/
	function checkCatalogWords( a_txt, a_txt2, a_loc )
	{
		if( ( document.getElementById( "katname" ).checked != true ) && ( document.getElementById( "katdesc" ).checked != true ) && ( document.getElementById( "katcode" ).checked != true ) )
		{
			alert( a_txt2 );
		}
		else
		{
			words_container = document.getElementById( "catalog_words2" );
			send_text = words_container.value;
			newstr = "";
			len = send_text.length;
			i = 0;
			while( ( send_text.charAt(i) != "" ) && ( i < len ) )
			{
				if( send_text.charAt(i) == " " )
				{
					i++;
				}
				else
				{
					while( ( send_text.charAt(i) != "" ) && ( send_text.charAt(i) != " " ) && ( i < len ) )
					{
						newstr = newstr + send_text.charAt(i);
						i++;
					}
					newstr = newstr + " ";
					i++;
				}
			}
			len = newstr.length;
			if( newstr.charAt(len-1) == " " )
			{
				newstr = newstr.substr( 0, len-1 );
			}
			if( newstr != "" )
			{
				document.getElementById( "catalog_words" ).value = newstr;
				document.forms.catalog_words_search.action = a_loc;
				document.forms.catalog_words_search.submit();
			}
			else
			{
				words_container.value = "";
				document.getElementById( "catalog_words" ).value = "";
				alert( a_txt );
			}
		}
	}


