/**
*   @version $Id: extranet.js 38 2008-04-10 14:20:11Z paulinad $
*	@author		piotrj
*/

/**--------------------------------------------------------------------
*	modul messages (poczta)
*---------------------------------------------------------------------*/

	/**
	 *	zarzadza przeladowaniami sortowania w messages (poczta)
	 *	@author		paulinad
	 *	@param		String		sortItem		sorting field key
	 *	@param		String		sortOrder		sorting order ( 'ASC' / 'DESC' )
	 */
	function messagesChangeSort( sortItem, sortOrder )
	{
		$( 'messagesSortItem' ).value = sortItem;
		$( 'messagesSortOrder' ).value = sortOrder;
		$( 'messagesReloadForm' ).submit();
	}


/**--------------------------------------------------------------------
*	lista ulubionych
*---------------------------------------------------------------------*/
	
	/**
	 *	zarzadza przeladowaniami sortowania w ulubieni (friends)
	 *	@author		paulinad
	 *	@param		String		sortItem		sorting field key
	 *	@param		String		sortOrder		sorting order ( 'ASC' / 'DESC' )
	 */
	function friendsReload( sortItem, sortOrder )
	{
		$( 'friendsSortItem' ).value = sortItem;
		$( 'friendsSortOrder' ).value = sortOrder;
		$( 'friendsReloadForm' ).submit();
	}


/**--------------------------------------------------------------------
*	zamowienia/zapytania
*---------------------------------------------------------------------*/

	/**
	*	Opis: wysyla zamowienie
	*/
	function sendOrder( a_text, a_type, a_text2, a_logged, a_order )
	{
		if( a_logged == 1 )
		{
			if( $( "regulamin" ).checked == true )
			{
				ok = 1;
			}
			else
			{
				ok = 0;
			}
		}
		else
		{
			ok = 1;
		}
		if( ok == 1 )
		{
			if( ( a_type == 1 ) || ( ( document.getElementById( "exname" ).value != "" ) && ( document.getElementById( "exsurname" ).value != "" ) && ( document.getElementById( "exmail" ).value != "" ) && ( document.getElementById( "exphone" ).value != "" ) ) )
			{
				$( "ordzamow" ).value = 1;
				if( a_order == 1 )
				{
					$( "ordertype" ).value = 1;
				}
				else
				{
					$( "ordertype" ).value = 0;
				}
				setOrder( 0, 0 );
			}
			else
			{
				alert( a_text );
			}
		}
		else
		{
			alert( a_text2 );
		}
	}

	/**
	*	Opis: dodaje produkt do koszyka
	*/
	function setOrder( a_id, a_del )
	{
		oInp = $( "kpr"+a_id );
		if( !myIsInt( oInp.value, 1, 10 ) )
		{
			oInp.value = 1;
		}
		if( a_del == 1 )
		{
			todel = a_id;
		}
		else
		{
			todel = -1;
		}
		num = 0;
		name = "ordcode"+num;
		fullcode = "";
		while( l_code = $( name ) )
		{
			if( num != todel )
			{
				ilosc = $( "kpr"+num ).value;
				fullcode += l_code.value+"+"+ilosc+"|";
			}
			num++;
			name = "ordcode"+num;
		}
		$( "setfull" ).value = 1;
		$( "fullorder" ).value = fullcode;
		$( "orderform" ).submit();
	}

/**-------------------------------------------------------------------*/


/**--------------------------------------------------------------------
*	logowanie, formularz rejestracyjny
*---------------------------------------------------------------------*/

	/**
	*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
	*/
	/*  // przeniesione do common ! ! !
	function sendPassword( a_txt, a_adr )
	{
		if( $( "exemail" ).value != "" )
		{
			docFormExL = $( "exlogin" );
			docFormExL.action = a_adr;
			docFormExL.submit();
		}
		else
		{
			alert( a_txt );
		}
	}
	*/

	/**
	*	Opis: przelacza pomiedzy wyborem polskich wojewodztw, a zmiana kraju
	*/
	function changeCountry( a_id )
	{
		adiv = $( a_id );
		ainp = $( "exkraj" );
		asel = $( "exprovince" );
		if( $( "exinny" ).checked == true )
		{
			adiv.style.color = "#cccccc";
			ainp.style.borderColor = "#7c94a5";
			ainp.disabled = false;
			asel.disabled = true;
			asel.value = 0;
		}
		else
		{
			adiv.style.color = "#666666";
			ainp.value = "";
			ainp.style.borderColor = "#cccccc";
			ainp.disabled = true;
			asel.disabled = false;
		}
	}

	/**
	*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
	*/
	function checkRegistrationForm( a_text, a_pass_text, a_type, a_adr )
	{
		if( ( document.getElementById( "exname" ).value != "" ) && ( document.getElementById( "exsurname" ).value != "" ) && ( document.getElementById( "exmail" ).value != "" ) && ( document.getElementById( "exstreet" ).value != "" ) && ( document.getElementById( "expostcode" ).value != "" ) && ( document.getElementById( "excity" ).value != "" ) && ( document.getElementById( "exphone" ).value != "" ) && ( ( ( document.getElementById( "expass" ).value != "" ) && ( document.getElementById( "expass2" ).value != "" ) ) || ( a_type == 2 ) ) )
		{
			if( $( "expass" ).value == $( "expass2" ).value )
			{
				docFormExL = $( "exlogin" );
				if( a_type == 2 )
				{
					docFormExL.action = a_adr;
				}
				docFormExL.submit();
			}
			else
			{
				alert( a_pass_text );
			}
		}
		else
		{
			alert( a_text );
		}
	}

	/**
	*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
	*/
	/* // przeniesione do common.js
	function checkLogin( a_text )
	{
		if( ( $( "exemail" ).value != "" ) && ( $( "exhaslo" ).value != "" ) )
		{
			$( "exlogin" ).submit();
		}
		else
		{
			alert( a_text );
		}
	}
	*/

/**-------------------------------------------------------------------*/


/**--------------------------------------------------------------------
*	modul projekty
*---------------------------------------------------------------------*/

	/**
	*	Opis: resetuje filtry w module projekty
	*/
	function dropProjectFilters()
	{
		$( "dropPFilters" ).value = 1;
		$( "pWords2" ).value = "";
		$( "pWords" ).value = "";
		$( "projectFilterForm" ).submit();
	}

	/**
	*	Opis: ustawia slowa do wyszukania w module projekty
	*/
	function sendProjectWords( txt )
	{
		words = $( "pWords2" ).value;
		if( words != "" )
		{
			words = erase_space( words );
			re = /\+/g;
			words = words.replace( re, " " );
			document.getElementById( "pWords" ).value = words;
			//document.getElementById( "dropPFilters" ).value = 1;
			document.forms.projectFilterForm.submit();
		}
		else
		{
			alert( txt );
		}
	}

/**-------------------------------------------------------------------*/


/**--------------------------------------------------------------------
*	modul aukcje
*---------------------------------------------------------------------*/

	/**
	*	Opis: sbmituje zmiane w ofercie aukcyjnej
	*/
	function auctionFormSubmit( a_txt, a_txt2 )
	{
		formatPrice( "acprice" );
		formatNumber( "acpayment" );
		formatNumber( "acdelivery" );
		acprice = $( "acprice" ).value;
		acpayment = $( "acpayment" ).value;
		acdelivery = $( "acdelivery" ).value;
		if( ( acprice != "0.00" ) && ( acpayment != "0" ) && ( acdelivery != "0" ) )
		{
			if( confirm( a_txt2 ) )
			{
				$( "accheck" ).value = "1";
				$( "auctionForm" ).submit();
			}
		}
		else
		{
			alert( a_txt );
		}
	}



/**-------------------------------------------------------------------*/


/**--------------------------------------------------------------------
*	dodawanie bloga
*---------------------------------------------------------------------*/

	/**
	* Opis: submituje formularz dodajacy bloga
	* @author paulinad
	* @param String txt - tresc komunikatu jesli uzytkownik nie poda nazwy bloga
	*/
	function addBlogAction( txt )
	{
		vInp = document.getElementById( "addblogname" ).value;
		if( vInp != '' )
		{
			document.getElementById( "add_blog_name" ).value = vInp;
			document.forms.add_blog_form.submit();
		}
		else
		{
			alert( txt );
		}
	}

/**--------------------------------------------------------------------
*	dodawanie galerii
*---------------------------------------------------------------------*/

	/**
	* Opis: submituje formularz dodajacy galerie
	* @author paulinad
	* @param String txt - tresc komunikatu jesli uzytkownik nie poda nazwy galerii
	*/
	function addGalleryAction( txt )
	{
		vInp = document.getElementById( "addgalleryname" ).value;
		if( vInp != '' )
		{
			document.getElementById( "add_gallery_name" ).value = vInp;
			document.forms.add_gallery_form.submit();
		}
		else
		{
			alert( txt );
		}
	}
