var SLO = Array();
SLO['TEKST'] = 'Tekst:';
SLO['OPIS'] = 'Opis:';
SLO['PODPIS'] = 'Podpis:';
SLO['TYTUL'] = 'Tytuł:';
SLO['TERMIN'] = 'Termin wyprawy:';
SLO['AUTORZY'] = 'Autorzy wyprawy:';
SLO['EMAIL'] = 'E-mail:';
SLO['PASSWORD'] = 'Kod wyprawy:';
SLO['F_EMAIL'] = 'E-mail znajomego:';
SLO['TEKST_ALERT'] = 'Wpisz treść wiadomości.';
SLO['OPIS_ALERT'] = 'Wpisz opis swojej wyprawy.';
SLO['PODPIS_ALERT'] = 'Wpisz podpis.';
SLO['TYTUL_ALERT'] = 'Wpisz tytuł.';
SLO['TERMIN_ALERT'] = 'Wpisz termin wyprawy.';
SLO['AUTORZY_ALERT'] = 'Wpisz autorów wyprawy.';
SLO['PLIK_ALERT'] = 'Wybierz plik obrazka.';
SLO['INSERT_EMAIL_ALERT'] = 'Podaj swój e-mail.';
SLO['INCORRECT_EMAIL_ALERT'] = 'Podaj swój poprawny e-mail.';
SLO['PASSWORD_ALERT'] = 'Wpisz 32-znakowy kod wyprawy otrzymany w mailu po wysyłaniu opisu Twojej wyprawy.';
SLO['PASSWORD_LENGTH_ALERT'] = 'Wpisane hasło zawiera nieprawidłową ilość znaków.';
SLO['PASSWORD_INCORRECT_ALERT'] = 'Wpisane hasło jest nieprawidłowe.';
SLO['INSERT_F_EMAIL_ALERT'] = 'Podaj e-mail znajomego.';
SLO['INCORRECT_F_EMAIL_ALERT'] = 'Podaj poprawny e-mail znajomego.';
SLO['TOKEN_ALERT'] = 'Nie wpisano kodu tokena lub wpisano niewłaściwą ilość znaków kodu.';
SLO['UPLOADING'] = 'Trwa zapisywanie pliku. Może to potrwać kilka minut. Proszę czekać...';

SLO['KOM_TEXT'] = 'Treść komentarza:';
SLO['KOM_TEXT_ALERT'] = 'Wpisz treść komentarza.';
/* ================================================= */

var TOKEN_LENGTH = 5;
var MY_ALERT = true;

var ajaxObj = create();

// zwraca obiekt XMLHttpRequest
function create() {
  var ajaxObj;
  if (window.XMLHttpRequest) {
    try {
      ajaxObj = new XMLHttpRequest();
    } catch (e) {
      ajaxObj = false;
    }
  }
  else if (window.ActiveXObject){
    try {
      ajaxObj = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {
      ajaxObj = false;
    }
  }
  return ajaxObj;
}

function ajax_check_password() {
  if ( ajaxObj ) {
		var up = document.getElementById('up').value;
    var url = './check_p.php?up='+up;
		ajaxObj.open( "GET", url );
    ajaxObj.onreadystatechange = function() {
      if ( ajaxObj.readyState == 4 && ajaxObj.status == 200 ) {
				var resp = ajaxObj.responseText;
				my_alert( resp );
      }
    }
    ajaxObj.send(null);
  }
}


function refresh_token(){
	/*document.location.reload();*/
}

function my_alert( msg ){
	if( MY_ALERT ){
		var a = document.getElementById('alert');
		a.innerHTML = msg;
		a.style.display='block';
	} else {
		alert( msg );
	}
}

function MM_preloadImages() { //v3.0
  var d=document; 
	if(d.images){ 
		if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function m_submenu( i ){
	var m = document.getElementById( 'menu-items' );
	var bm = m.getElementsByTagName('SPAN');
	for( var n = 0; n < bm.length; n++ ){
		if( bm[n].id != 'sbox_'+i ) bm[n].style.display = 'none';
	}
	//alert(i);
	var s = document.getElementById( 'sbox_'+i );
	if( s.style.display == 'none' ){
		s.style.display = 'block';
	} else {
		s.style.display = 'none';
	}
}

function check_email_address(adres){
	if (adres != "") {
		var re = new RegExp("[^@]{1,}[@]{1}[^@.]{1,}[.]{1}[^@]{1,}","gi");
		var wynik = re.test(adres);
		return wynik;
	}
}

/* --- add to favorites --- */
function AddToFavorites() {
	var title = document.title; 
 	var url = location.href;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); 
	}	else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}

function check_ksiega_form() {
	with ( document.ksiega_form ) {
		token.value = token.value.toUpperCase();
		if( text.value == '' || text.value == SLO['TEKST'] ) {
			my_alert ( SLO['TEKST_ALERT'] );
			text.focus();
			return false;	
		} else if( name.value == '' || name.value == SLO['PODPIS'] ){
			my_alert ( SLO['PODPIS_ALERT'] );
			name.focus();
			return false;
		} else if( email.value == '' || email.value == SLO['EMAIL'] ){
			my_alert ( SLO['INSERT_EMAIL_ALERT'] );
			email.focus();
			return false;
		} else if ( !check_email_address( email.value ) ) {
			my_alert( SLO['INCORRECT_EMAIL_ALERT'] );
			email.focus();
			return false;
		} else if( token.value == '' || token.value.length != TOKEN_LENGTH ){
			my_alert ( SLO['TOKEN_ALERT'] );
			token.focus();
			return false;
		} else {
			document.getElementById('alert').style.display = 'none';
			submit();
		}
	}
} 

function check_wyprawa_form() {
	with ( document.wyprawa_form ) {
		token.value = token.value.toUpperCase();
		if ( tytul.value == '' || tytul.value == SLO['TYTUL'] ) {
			my_alert ( SLO['TYTUL_ALERT'] );
			tytul.focus();
			return false;	
		} else if ( termin.value == '' || termin.value == SLO['TERMIN'] ) {
			my_alert ( SLO['TERMIN_ALERT'] );
			termin.focus();
			return false;	
		} else if ( autorzy.value == '' || autorzy.value == SLO['AUTORZY'] ) {
			my_alert ( SLO['AUTORZY_ALERT'] );
			autorzy.focus();
			return false;	

		} else if ( opis.value == '' || opis.value == SLO['OPIS'] ) {
			my_alert ( SLO['OPIS_ALERT'] );
			opis.focus();
			return false;	
		} else if( name.value == '' || name.value == SLO['PODPIS'] ){
			my_alert ( SLO['PODPIS_ALERT'] );
			name.focus();
			return false;
		} else if( email.value == '' || email.value == SLO['EMAIL'] ){
			my_alert ( SLO['INSERT_EMAIL_ALERT'] );
			email.focus();
			return false;
		} else if ( !check_email_address( email.value ) ) {
			my_alert( SLO['INCORRECT_EMAIL_ALERT'] );
			email.focus();
			return false;
		} else if( token.value == '' || token.value.length != TOKEN_LENGTH ){
			my_alert ( SLO['TOKEN_ALERT'] );
			token.focus();
			return false;
		} else {
			document.getElementById('alert').style.display = 'none';
			submit();
		}
	}
} 

function check_kontakt_form() {
	with ( document.kontakt_form ) {
		token.value = token.value.toUpperCase();
		if ( text.value == '' || text.value == SLO['TEKST'] ) {
			my_alert ( SLO['TEKST_ALERT'] );
			text.focus();
			return false;	
		} else if( name.value == '' || name.value == SLO['PODPIS'] ){
			my_alert ( SLO['PODPIS_ALERT'] );
			name.focus();
			return false;
		} else if(email.value == '' || email.value == SLO['EMAIL'] ){
			my_alert ( SLO['INSERT_EMAIL_ALERT'] );
			email.focus();
			return false;
		} else if ( !check_email_address( email.value ) ) {
			my_alert( SLO['INCORRECT_EMAIL_ALERT'] );
			email.focus();
			return false;
		} else if( token.value == '' || token.value.length != TOKEN_LENGTH ){
			my_alert ( SLO['TOKEN_ALERT'] );
			token.focus();
			return false;
		} else {
			document.getElementById('alert').style.display = 'none';
			submit();
		}
	}
} 

function check_polecam_form() {
	with ( document.polecam_form ) {
		token.value = token.value.toUpperCase();
		if( f_email.value == '' || f_email.value == SLO['F_EMAIL'] ){
			my_alert ( SLO['INSERT_F_EMAIL_ALERT'] );
			f_email.focus();
			return false;
		} else if( !check_email_address( f_email.value ) ){
			my_alert ( SLO['INCORRECT_F_EMAIL_ALERT'] );
			f_email.focus();
			return false;
		} else if( name.value == '' || name.value == SLO['PODPIS'] ){
			my_alert ( SLO['PODPIS_ALERT'] );
			name.focus();
			return false;
		} else if(email.value == '' || email.value == SLO['EMAIL'] ){
			my_alert ( SLO['INSERT_EMAIL_ALERT'] );
			email.focus();
			return false;
		} else if ( !check_email_address( email.value ) ) {
			my_alert( SLO['INCORRECT_EMAIL_ALERT'] );
			email.focus();
			return false;
		} else if( token.value == '' || token.value.length != TOKEN_LENGTH ){
			my_alert ( SLO['TOKEN_ALERT'] );
			token.focus();
			return false;
		} else {
			document.getElementById('alert').style.display = 'none';
			submit();
		}
	}
}

function show_wait(){
	var w = '<img src="images/litebox/loading.gif" alt="" style="margin:5px 10px 5px 30px;float:left;" />';
	w += '<div style="">' + SLO['UPLOADING'] + '</div>';
	document.getElementById('form-alert').innerHTML = w;
}

function get_wyprawa(){
	with ( document.galeria_form ) {
		submit();
	}
}

function check_galeria_form() {
	with ( document.galeria_form ) {
		token.value = token.value.toUpperCase();
		var c = count.value.valueOf();
		if ( up.value == '' || up.value == SLO['PASSWORD'] ) {
			my_alert ( SLO['PASSWORD_ALERT'] );
			up.focus();
			return false;
		} else if( plik.value == '' ){
			my_alert ( SLO['PLIK_ALERT'] );
			return false;
		} else if( tytul.value == '' || tytul.value == SLO['TYTUL'] ){
			my_alert ( SLO['TYTUL_ALERT'] );
			tytul.focus();
			return false;
		} else if( token.value == '' || token.value.length != TOKEN_LENGTH ){
			my_alert ( SLO['TOKEN_ALERT'] );
			token.focus();
			return false;
		} else {
			c++;
			count.value = c;
			document.getElementById('alert').style.display = 'none';
			document.getElementById('uploading').style.display = 'block';
			submit();
		}
	}
} 

function show_author_info( aa ){
	var ab = document.getElementById('authors');
	var aib = ab.getElementsByTagName('div');
	var c;
	for (c=0; c < aib.length; c++){
		aib[c].style.display = 'none';
	}
	document.getElementById('author-info-'+aa ).style.display = 'block';
}

/* ----------- KOMENTARZE ------------ */

function m_comm( mode, id ){
	with( document.komentarze_form ){
		if(mode == "undefined" ) mode = "";
		CommMode.value = mode;
		if( id == "undefined" ) id = "0";
		CommId.value = id;
		submit();
	}
}

function check_komentarze_form( m, i ) {
	with ( document.komentarze_form ) {
		token.value = token.value.toUpperCase();
		if (komentarz.value=='' || komentarz.value==SLO['KOM_TEXT']) {
			my_alert ( SLO['KOM_TEXT_ALERT'] );
			komentarz.focus();
			return false;
		} else if(podpis.value=='' || podpis.value==SLO['PODPIS']){
			my_alert ( SLO['PODPIS_ALERT'] );
			podpis.focus();
			return false;
		} else if(email.value == '' || email.value == SLO['EMAIL'] ){
			my_alert ( SLO['INSERT_EMAIL_ALERT'] );
			email.focus();
			return false;
		} else if ( !check_email_address( email.value ) ) {
			my_alert( SLO['INCORRECT_EMAIL_ALERT'] );
			email.focus();
			return false;
		} else if( token.value == '' || token.value.length != TOKEN_LENGTH ){
			my_alert ( SLO['TOKEN_ALERT'] );
			token.focus();
			return false;
		} else {
			document.getElementById('alert').style.display = 'none';
			m_comm( m, i );
		}
	}
} 

function subkat_control( ki ){
	var kbb = document.getElementById( 'subkat-' + ki );
	var i = document.getElementById( 'subbtn-' + ki );
	if( kbb.style.display == 'none' ){
		kbb.style.display = 'block';
		i.className = 'subbox-minus';
	} else {
		kbb.style.display = 'none';
		i.className = 'subbox-plus';
	}
}

function show_box_wyprawy( p ){
	var sel = document.getElementById( 'wyprawa-' + p );
	var ab = document.getElementById( 'wyprawy' );
	var dp = ab.getElementsByTagName('DIV');
	var ap = ab.getElementsByTagName('A');
	for( var n = 0; n < dp.length; n++ ){
		dp[n].style.display = 'none';
	}
	for( var n = 0; n < ap.length; n++ ){
		if(ap[n].className == 'icon-minus' ) ap[n].className = 'icon-plus';
	}	
	sel.style.display = 'block';
	document.getElementById( 'icon-' + p ).className = 'icon-minus';
}