
function pullDownAction( id ) {
	objDiv = document.getElementById(id);
	if (objDiv.style.display == 'none') objDiv.style.display = '';
}

function pullUpAction( id ) {
	objDiv = document.getElementById(id);
	if (objDiv.style.display == '') objDiv.style.display = 'none';
}

function DisplayWindow(url, w, h)
{
  var myWin = window.open(
    url,
    'MyWindow',
    'width='+w+',height='+h+',resizable=no,scrollbars=yes,menubar=no'
  );
  myWin.focus();
}

function PlanMieszkania(url, w, h) {
  DisplayWindow('imgshow.php?imgfile='+url, w, h);
}

function UkrytyNapiszDo(user, domain, subject, attrib) {
	var adr = user + '&#64;' + domain;
	document.write('<a');
	if (attrib.length > 0) document.write(' '+p);
	document.write(' hr' + 'ef="ma');
	document.write('ilto:' + adr);
	if (subject.length > 0) document.write('?' + subject);
	document.write('">' + adr + '</a>');
}




function InputFocus(obj) {
    obj.className = 'inputOn';
};

function InputBlur(obj) {
    if (!obj.value || true) {
        obj.className = 'inputOff';
    }
    else {
        obj.className = 'inputOn'
    }
};

function showMini2(mini2, w, h) {
	overlib(
		'<img class="gallery" src="'+mini2+'" width="'+w+'" height="'+h+'" />',
		FGCOLOR, '#FFFFFF', BGCOLOR, '#000000', HAUTO, VAUTO
	);
}

// -------------------- formularz filtrow

function owFFSubmit() {

	var argv = owFFSubmit.arguments;
	var form = null;
	if (argv[0]=='opener')
		form = opener.document.getElementById('owFiltryForm');
	else
		form = document.getElementById('owFiltryForm');

	for (i=1; i<(argv.length); i+=2) {
		if (form.elements[argv[i]] != null) {
			form.elements[argv[i]].value = argv[i+1];
		}
		else {
			window.alert('Brak filtra ' + argv[i]);
			return false;
		}
	}
	form.submit();
	return true;
}


// -------------------- validacja formularza oferty

function OfferCheckLocation( formid ) {

	f = document.getElementById( formid );
	if ( f.elements['miejscowosc'].value.match( /^bydgoszcz$/i ) ) {
		f.elements['dzielnica_id'].disabled = false;
	}
	else {
		f.elements['dzielnica_id'].selectedIndex = 0;
		f.elements['dzielnica_id'].disabled = true;
	}
}


function CheckSetHasAnyChecked( elem ) {
	chckdCounter = 0;
	for (i=0; i<elem.length; i++) {
		if (elem[i].checked) chckdCounter++;
	}
	return chckdCounter;
}


// ------------------------------- walidacja formularza zgłoszeniowego Katalogu

function KatalogObiektWalidacja( f ) {

	var alertPrefix = 'Niżej wymienione pola pozostały puste:\n\n';
	var alerts = new Array();

	// nazwa
	if ( f.elements['name'] != null && f.elements['name'].value == '' )
	{ alerts.push('Pole [Nazwa] jest puste'); }

    // adres
    if ( f.elements['adr1'].value == '' || f.elements['adr2'].value == '' )
	{ alerts.push('Pole [Adres] jest niewypełnione'); }

    // [tel1]
    if ( f.elements['tel1'].value == '' )
	{ alerts.push('Pole [Telefon 1] jest puste'); }

    // [email]
    if ( f.elements['email'].value == '' )
	{ alerts.push('Pole [e-mail] jest puste'); }

    // [logo] - niewymagane, dozwolone .jpg .png
    if ( f.elements['logo'].value != '' && !f.elements['logo'].value.match( /(jpe?g|png)$/i ) )
  	{ alerts.push('Plik z logo - tylko JPG lub PNG'); }

    // wpis podstawowy
    if ( f.elements['desc'].value == '' )
	{ alerts.push('Pole [Krótki opis] jest puste'); }
	if ( f.elements['desc'].value.length > 300 )
	{ alerts.push('Pole [Krótki opis] może zawierać max 300 znaków, a zawiera '+f.elements['desc'].value.length); }

	// kod bezpieczenstwa
	if ( f.elements['SecCode'].value.length != 4  )
	{ alerts.push('Przepisz kod wyswietlany na obrazku.'); }

    if ( alerts.length > 0 ) {
        window.alert( alertPrefix + '- ' + alerts.join('\n- ') );
        return false;
    }
    else
        return true;
}

// ------------------------------- walidacja formularza rejestracyjnego dla oferentow

function OferentRejestrWalidacja( f ) {

	var alertPrefix = 'Niżej wymienione pola pozostały niewypełnione:\n\n';
	var alerts = new Array();
	tinyMCE.triggerSave();

	// login
	if ( f.elements['login'].value == '' )
	{ alerts.push('Pole [Nazwa] jest puste'); }

	// haslo - wymagane
	if (
		//!f.elements['haslo'].value.match( /[a-z]/ ) || // male litery
		//!f.elements['haslo'].value.match( /[A-Z]/ ) || // wielkie litery
		//!f.elements['haslo'].value.match( /[0-9]/ ) || // cyfry
		f.elements['haslo'].value==f.elements['login'].value || // rozne od loginu
		f.elements['haslo'].value.length < 6 // min 6 znaków
	)
	{ alerts.push('Hasło min. 6 znaków - różne od loginu'); }
	
	// haslo - powtorzenie
	if ( f.elements['haslo'].value != f.elements['haslo2'].value )
	{ alerts.push('Błędne powtórzenie hasła.'); }
	
	// nazwa firmy
	if ( f.elements['nazwa'].value == '' )
	{ alerts.push('Pole [Nazwa firmy] jest puste'); }

    // adres
    if ( f.elements['adres1'].value == '' || f.elements['adres2'].value == '' )
	{ alerts.push('Pole [Adres] jest niewypełnione'); }

	// skrocona nazwa firmy
	if ( f.elements['nazwak'].value == '' )
	{ alerts.push('Pole [Skrócona nazwa firmy] jest puste'); }

    // [logo] - niewymagane, dozwolone .jpg .png
    if ( f.elements['logo'].value != '' && !f.elements['logo'].value.match( /(jpeg|jpg|png)$/i ) )
  	{ alerts.push('Plik z logo - tylko JPG lub PNG'); }

	// imie i nazwisko
	if ( f.elements['imienazwisko'].value == '' )
	{ alerts.push('Pole [Imię i nazwisko] jest puste'); }

    // [tel1]
    if ( f.elements['tel1'].value == '' )
	{ alerts.push('Pole [Telefon 1] jest puste'); }

    // [email]
    if ( f.elements['email'].value == '' )
	{ alerts.push('Pole [e-mail] jest puste'); }

    // opis
	if ( f.elements['opis'].value.length < 500 )
	{ alerts.push('Pole [Opis firmy] musi zawierać min 500 znaków, a zawiera '+f.elements['opis'].value.length); }

	// kod bezpieczenstwa
	if ( f.elements['SecCode'].value.length != 4  )
	{ alerts.push('Przepisz kod wyswietlany na obrazku.'); }

    if ( alerts.length > 0 ) {
        window.alert( alertPrefix + '- ' + alerts.join('\n- ') );
        return false;
    }
    else
        return true;
}

// ------------------------------- walidacja formularza rejestracyjnego dla oferentow

function OferentRecoverWalidacja( f ) {

	var alertPrefix = '';
	var alerts = new Array();

    // [email]
    if ( f.elements['email'].value == '' )
	{ alerts.push('Podaj adres e-mail'); }

	// kod bezpieczenstwa
	if ( f.elements['SecCode'].value.length != 4  )
	{ alerts.push('Przepisz kod wyswietlany na obrazku.'); }

    if ( alerts.length > 0 ) {
        window.alert( alertPrefix + '- ' + alerts.join('\n- ') );
        return false;
    }
    else
        return true;
}


function okno_rejestr_licencji()
{
	winRejestrLicencji = window.open(
		'http://www.mi.gov.pl/2-48231af366e78.htm',
		'bazarejestrow',
		'width=800,height=550,resizable=yes,scrollbars=yes,menubar=no'
	);
}

