/**
*   @version $Id: galeria.js 52 2010-04-08 13:37:59Z paulinad $
*	@package frontend
*	@author piotrj
*/
	
	/**
	 * ustawia sortowanie na liscie zdjec
	 * @author		paulinad
	 * @param		Integer		sortField		pole
	 * @param		String		sortType		typ sortowania ASC/DESC
	 */
	function setGallerySort( sortField, sortType )
	{
		$( 'gallerySortField' ).value = sortField;
		$( 'gallerySortType' ).value = sortType;
		$( 'gallerySortForm' ).submit();
	}
	
	/**
	 * ustawia sortowanie na liscie zdjec
	 * @author		paulinad
	 * @param		Integer		sortField		pole
	 * @param		String		sortType		typ sortowania ASC/DESC
	 */
	function setGalleryRowSort( sortField, sortType )
	{
		$( 'galleryRowSortField' ).value = sortField;
		$( 'galleryRowSortType' ).value = sortType;
		$( 'galleryRowSortForm' ).submit();
	}
	
	/**
	 * submituje formularz stronicowania wyszukanych zdjec 
	 * @author		paulinad
	 * @param		Integer		sortField		pole
	 * @param		String		sortType		typ sortowania ASC/DESC
	 */
	function sendPagingGlSearcher( a_adres )
	{
		$( 'glSearcherPagForm' ).action = a_adres;
		$( 'glSearcherPagForm' ).submit();
	}

/**--------------------------------------------------------------------
*	modul e-kartki
*---------------------------------------------------------------------*/

	/**
	*	Opis: funkcja wysyla e-kartke
	*/
	function sendECard( txt, t1, t2 )
	{
		getWysiwyg( 0 );
		sAdr = $( "adresat" ).value;
		sNad = $( "nadawca" ).value;
		if( ( sAdr != "" ) && ( sAdr != t1 ) && ( sNad != "" ) && ( sNad != t2 ) )
		{
			$( "eCardForm" ).submit();
		}
		else
		{
			alert( txt );
		}
	}

	var currentStamp = 2;

	/**
	*	Opis: funkcja przelacza znaczki w e-kartkach
	*/
	function changeStamp( direction, number )
	{
		oLeft = $( "cardPrevDiv" );
		oStamp = $( "stamp" + currentStamp + "" );
		oRight = $( "cardNextDiv" );
		if( direction == "prev" )
		{
			if( currentStamp > 2 )
			{
				currentStamp--;
			}
		}
		else
		{
			if( currentStamp < number )
			{
				currentStamp++;
			}
		}
		oStamp.style.display = "none";
		oStamp2 = $( "stamp" + currentStamp + "" );
		oStamp2.style.display = "block";
		$( "znaczek" ).value = "" + currentStamp + "";
		if( currentStamp > 2 )
		{
			oLeft.style.display = 'block';
		}
		else
		{
			oLeft.style.display = 'none';
		}
		if( currentStamp < number )
		{
			oRight.style.display = 'block';
		}
		else
		{
			oRight.style.display = 'none';
		}
	}

/**-------------------------------------------------------------------*/
	
	
	
	/**
	 * submituje formularz dodawnia/edycji elementu galerii
	 * @author		paulinad
	 * @param		Integer		type		0-nowy wpis, else-edycja
	 * @param		String		alert1		komunikat bledu - brak wypelnionych wymaganych pol
	 */
	function submitMyGalleryForm( type, alert1 )
	{
		var ok = true;
		
		var Obj = $( 'myGalName' );
		Obj.className = '';
		var val = Obj.value.trim();
		if( val == '' )
		{
			//alert( alert1 );
			Obj.className = 'cfFormError';
			ok = false;
		}
		
		if( type == 0 )
		{ // nowy element
			
		}
		if( ok )
		{
			$( 'myGalForm' ).submit();
		}
		else
		{
			alert( alert1 );
		}
	}
	
	/**
	 * submituje formularz dodawnia/edycji elementu galerii
	 * @author		paulinad
	 * @param		Integer		type		0-nowy wpis, else-edycja
	 * @param		String		alert1		komunikat bledu - brak wypelnionych wymaganych pol
	 * @param		String		alert2		komunikat bledu - niewlasciwe rozszerzenie pliku
	 * @param		String		alert2		komunikat bledu - musisz dodac plik
	 */
	function submitMyGalleryRowForm( type, alert1, alert2, alert3 )
	{
		var ok1 = 0;
		var ok2 = 0;
		
		var Obj = $( 'myGalRowName' );
		Obj.className = '';
		var val = Obj.value.trim();
		if( val == '' )
		{
			//alert( alert1 );
			Obj.className = 'cfFormError';
			ok1 = 1;
		}
		if( type == 0 )
		{ // nowy element
			if( $( 'myGalRowDelFile' ) )
			{
				$( 'myGalRowDelFile' ).value = 0;
			}
			if( $( 'myGalRowAddFile' ) )
			{
				$( 'myGalRowAddFile' ).value = 0;
			}
			/*
			if( $( 'myGalRowFileDiv' ) )
			{
				Obj = $( 'myGalRowFileDiv' );
				Obj.className = '';
				var tmpString = new String( $( 'myGalRowFile' ).value.trim() );
				var re = /^.+\.(jpg|gif|jpeg)$/i;
				if( tmpString == '' )
				{
					//alert( alert1 );
					Obj.className = 'cfFormError';
					ok = 1;
				}
				else if( !tmpString.match( re ) )
				{
					//alert( alert2 );
					Obj.className = 'cfFormError';
					ok = 1;
				}
			}
			else 
			*/
			if( $( 'myGalRowFileId' ) && $( 'myGalRowFileDiskName' ) )
			{
				Obj = $( 'myGalRowFileId' );
				if( ( Obj.value.trim() == '' ) || ( Obj.value.trim() == 0 ) || !myIsInt( ''+Obj.value.trim(), 1, 12 ) )
				{
					ok2 = 3;
				}
				else
				{
					var tmpString = new String( $( 'myGalRowFileDiskName' ).value.trim() );
					var re = /^.+\.(jpg|gif|jpeg)$/i;
					if( tmpString == '' )
					{
						ok2 = 2;
					}
					else if( !tmpString.match( re ) )
					{
						ok2 = 2;
					}
				}
			}
			else
			{
				ok2 = 3;
			}
		}
		if( ( ok1 == 0 ) && ( ok2 == 0 ) )
		{
			$( 'myGalRowForm' ).submit();
		}
		else
		{
			var msg = '';
			var was = false;
			if( ok1 != 0 )
			{
				was = true;
				msg += alert1;
			}
			if( ok2 != 0 )
			{
				if( ok2 == 2 )
				{
					if( was )
					{
						msg += "\n\r";
					}
					msg += alert2;
				}
				else 
				{
					if( was )
					{
						msg += "\n\r";
					}
					msg += alert3;
				}
			}
			alert( msg );
		}
	}
	
	function submitMyGalleryRowDelFile()
	{
		$( 'myGalRowDelFile' ).value = 1;
		if( $( 'myGalRowAddFile' ) )
		{
			$( 'myGalRowAddFile' ).value = 0;
		}
		if( $( 'myGalRowFile' ) )
		{
			$( 'myGalRowFile' ).value = '';
		}
		$( 'myGalRowForm' ).submit();
	}
	
	function submitMyGalleryRowAddFile( a_txt1, a_txt2, Obj, txt, left, top )
	{
		var ok = 0
		if( $( 'myGalRowFileDiv' ) )
		{
			Obj = $( 'myGalRowFileDiv' );
			Obj.className = 'FormField2';
			var tmpString = new String( $( 'myGalRowFile' ).value.trim() );
			var re = /^.+\.(jpg|gif|jpeg)$/i;
			if( tmpString == '' )
			{
				//alert( alert1 );
				Obj.className = 'FormField2 cfFormError';
				ok = 1;
			}
			else if( !tmpString.match( re ) )
			{
				//alert( alert2 );
				Obj.className = 'FormField2 cfFormError';
				ok = 2;
			}
		}
		if( ok == 0 )
		{
			showLoader( Obj, txt, left, top );
			$( 'myGalRowAddFile' ).value = 1;
			if( $( 'myGalRowDelFile' ) )
			{
				$( 'myGalRowDelFile' ).value = 0;
			}
			$( 'myGalRowForm' ).submit();
		}
		else if( ok == 1 )
		{
			alert( a_txt1 );
		}
		else
		{
			alert( a_txt2 );
		}
	}
	
	/**
	 *
	 */
	function submitMyGalleryDeleteForm( galDocId, confirm1 )
	{
		if( confirm( confirm1 ) )
		{
			$( 'myGalleryDelDocId' ).value = galDocId;
			$( 'myGalleryDelForm' ).submit();
		}
	}
	
	
	/**
	 *
	 */
	function submitMyGalleryRowDeleteForm( picDocId, confirm1 )
	{
		if( confirm( confirm1 ) )
		{
			$( 'myGalleryRowDelDocId' ).value = picDocId;
			$( 'myGalleryRowDelForm' ).submit();
		}
	}
	
	

	/**
	*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
	*/
	function checkLoginCM( a_text )
	{
		if( ( $( "cmemail" ).value != "" ) && ( $( "cmhaslo" ).value != "" ) )
		{
			$( "cmlogin" ).submit();
		}
		else
		{
			alert( a_text );
		}
	}

