
//  sprawdza czy nie otworzyno popupu w nowym oknie
// ****************************************************
function SprImgWindow( DNS_ )
{
if ( window.name == '' )
  {
	window.location.replace( 'http://'+DNS_ );
}
} // koniec SprImgWindow()



//  zamyka okno popapu
// ***********************************
function ZamknijOkno()
{
window.close();

return false; 
} // koniec ZamknijOkno()



//  wycina wszystkie spacje
// *****************************
function KillAllSpace( Ciag_ )
{

while ( Ciag_.indexOf( " " ) >= 0 )
  {
	Ciag_ = Ciag_.replace( ' ' , '' );	
}	

return Ciag_
} // koniec KillAllSpace()





//  wstępne ładowanie obrazków
// *****************************
function PreloadImeges()
{
var TabImg_ = new Array();
var Path_ = 'images'; 

TabImg_[ 0] = 'logo.jpg';

for ( Kolejny_=0 ; Kolejny_ < TabImg_.length ; Kolejny_ ++ )
  {
  Obrazek_ = new Image();
  Obrazek_.src = Path_+'/'+TabImg_[Kolejny_];    
}   

return false;
} // koniec PreloadImeges()




//  otwiera okno popapu
// *************************************************
function OtworzPopup( Plik_ , Wys_, Szer_, DodParam_, WindowNazwa_ )
{
DodParam_ = ( DodParam_ == null ) ? "" : DodParam_;
WindowNazwa_ = ( WindowNazwa_ == null ) ? "" : WindowNazwa_;
WindowParam_ = '';

if( Wys_ != null && Wys_ != '' &&  Szer_ != null && Szer_ != '' )
  {
  WindowParam_ = 'top=50,left=50,width='+Wys_+',height='+Szer_;
  WindowNazwa_ = 'szczegoly_'+Wys_+Szer_;   
}  

okienko = window.open( Plik_ , WindowNazwa_ , WindowParam_+DodParam_ );

return false;
} // koniec OtworzPopup()



// sprawdza istnienie ramek
//*********************************
function IsFrameExist( DNS_ )
{
var Zwrot_ = true;
if ( top.window.location == self.window.location || top.window.frames.length == 0 )
  {
  top.window.location.replace('http://'+DNS_);  
  Zwrot_ = false;
}
return Zwrot_;
} // koniec IsFrameExist()



// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *





// ************************************
function ZaladujNowyPlik()
{
var Go_ = true;

if ( Go_ && document.getElementById('n_source_file').value == '' )
  {
  alert( 'brak pliku do pobrania' );
  Go_ = false;
}  

if ( Go_ )
  {
  document.getElementById('formSourceImg').submit();
}  

return false;
} // koniec ZaladujNowyPlik()





// ************************************
function UsunPlik()
{
document.getElementById('ImageAction').value = 'UsunFotke1';
document.getElementById('formSourceImg').submit();

return true;
} // koniec ZaladujNowyPlik()





// *****************************************
function WyczyscPlikTarget()
{

if ( top.frameRight.document && top.frameRight.document.getElementById('formTargetImg') )
  {
  
  if ( top.frameRight.document.getElementById('n_szerokosc').value == 0 || top.frameRight.document.getElementById('n_wysokosc').value == 0 )
    {  
    top.frameRight.document.getElementById('n_szerokosc').value = top.frameLeft.document.getElementById('SzerFotki1').value;
    top.frameRight.document.getElementById('n_wysokosc').value = top.frameLeft.document.getElementById('WysFotki1').value;
  }  
  top.frameRight.SprProporcje( 'x' );
  top.frameRight.document.getElementById('ImageAction').value = 'UsunFotkeTarget';
  top.frameRight.document.getElementById('formTargetImg').submit();
}

} // koniec WyczyscPlikTarget()






// ************************************
function Transformacja()
{
var Go_ = true;
//alert( '1' );
//alert( window.top.frames['frameLeft'].document.getElementById('PlikFotki1').value );
//alert( document.getElementById('PlikFotki1').value );

if ( Go_ && top.frameLeft.document.getElementById('PlikFotki1').value == "" )
  {
  alert( 'brak pliku do przetworzenia' )
  Go_ = false;  
}

if ( Go_ && Math.ceil( document.getElementById('n_szerokosc').value ) < 20 )
  {
  alert( 'podana szerokość jest zbyt mała' ) ;
  document.getElementById('n_szerokosc').value = 20;  
  SprProporcje( 'x' );
  document.getElementById('n_szerokosc').focus()
  Go_ = false;  
}

if ( Go_ && Math.ceil( document.getElementById('n_wysokosc').value ) < 20 )
  {
  alert( 'podana wysokość jest zbyt mała' ) ;
  document.getElementById('n_wysokosc').value = 20;
  SprProporcje( 'y' );    
  document.getElementById('n_wysokosc').focus()
  Go_ = false;  
}

if ( Go_ && ( parseInt( document.getElementById('n_szerokosc').value ) > parseInt( top.frameLeft.document.getElementById('MaxSzerFotki1').value ) ) )
  {
  alert( 'podana szerokość jest zbyt duża' ) ;
  document.getElementById('n_szerokosc').value = top.frameLeft.document.getElementById('MaxSzerFotki1').value;  
  SprProporcje( 'x' );
  document.getElementById('n_szerokosc').focus()
  Go_ = false;  
}

if ( Go_ && ( parseInt( document.getElementById('n_wysokosc').value ) > parseInt( top.frameLeft.document.getElementById('MaxWysFotki1').value ) ) )
  {
  alert( 'podana wysokość jest zbyt duża' ) ;
  document.getElementById('n_wysokosc').value = top.frameLeft.document.getElementById('MaxWysFotki1').value;
  SprProporcje( 'y' );    
  document.getElementById('n_wysokosc').focus()
  Go_ = false;  
}  



if ( Go_ )
  {
  top.frameRight.document.getElementById('NazwaFotkiZrodla').value = top.frameLeft.document.getElementById('NazwaFotki1').value;
  top.frameRight.document.getElementById('PlikFotkiZrodla').value = top.frameLeft.document.getElementById('PlikFotki1').value;
  top.frameRight.document.getElementById('ImageAction').value = 'PrzerobFotke1';
  top.frameRight.document.getElementById('formTargetImg').submit();
}

return false;
} // koniec ZaladujNowyPlik()




// ****************************************
function SprProporcje( Zmienna_ ) 
{

if ( Zmienna_ == 'x' )
  {
  if ( !(Math.ceil( document.getElementById('n_szerokosc').value ) > 0 ) )
    {
    document.getElementById('n_szerokosc').value = 0;
  }         
  document.getElementById('n_szerokosc').value = Math.round( document.getElementById('n_szerokosc').value ); 
  
  ProporcjaX_ = ( top.frameLeft.document.getElementById('MaxSzerFotki1').value != 0 ) ? top.frameLeft.document.getElementById('MaxWysFotki1').value / top.frameLeft.document.getElementById('MaxSzerFotki1').value : 0;
  top.frameRight.document.getElementById('n_wysokosc').value = Math.round( document.getElementById('n_szerokosc').value * ProporcjaX_ );
}  

if ( Zmienna_ == 'y' )
  {
  if ( !(Math.ceil( document.getElementById('n_wysokosc').value ) > 0 ) )
    {
    document.getElementById('n_wysokosc').value = 0;
  }         
  document.getElementById('n_wysokosc').value = Math.round( document.getElementById('n_wysokosc').value ); 

  ProporcjaY_ = ( top.frameLeft.document.getElementById('MaxWysFotki1').value!= 0 ) ? top.frameLeft.document.getElementById('MaxSzerFotki1').value / top.frameLeft.document.getElementById('MaxWysFotki1').value : 0;  
  top.frameRight.document.getElementById('n_szerokosc').value = Math.round( document.getElementById('n_wysokosc').value * ProporcjaY_ );  
}  

} // koniec SprProporcje() 


