function check_apply() {
	if (document.applyform.applyok.checked=="false") {alert('Aby aplikowac do tej oferty pracy, musisz wyrazić zgodę na dołączenie swojego CV do listy aplikantów!'); return false;}
	else return true;
}

function change_region(obj) {
  if (obj.value != 255) {
    document.getElementById("wojewodztwo").value=17;
    document.getElementById("wojewodztwo").disabled=true;
  }
  if (obj.value == 255) {
    document.getElementById("wojewodztwo").selectedIndex=0;
    document.getElementById("wojewodztwo").disabled=false;
  }
  if (obj.value == 0) {
    document.getElementById("wojewodztwo").selectedIndex=0;
    document.getElementById("wojewodztwo").disabled=false;
  }
}

function $( id )  {
      return document.getElementById( id );
    }
  
function ShowTopLayer( banerFile,  dstLink,width )  {
  var body = document.getElementsByTagName( 'body' )[0];
  var div = document.createElement( 'div' )
  var divNapis = document.createElement( 'div' )
  var pic = document.createElement( 'img' );
  var divWidth = parseInt(width)+10;
  var divObrazek = document.createElement( 'div' );
  var link = document.createElement( 'a' );
  var close = document.createElement( 'span' );
  var content = body.innerHTML;
  
  div.setAttribute( 'id', 'TLmain' );
  div.style.position = 'absolute';
  div.style.zIndex = '999';
  div.style.width = '100%';
  div.style.marginTop = '20%';
  div.style.textAlign = 'center';
  
  close.style.color = 'black';
  close.style.cursor = 'pointer';
  close.style.margin = '3px 3px 0 0';
  close.innerHTML = '[x]';
  close.onmouseover = function ()  {
                                        close.style.color = 'red';
                                      }
  close.onmouseout = function ()  {
                                        close.style.color = 'black';
                                      }
  close.onclick = function CloseTopLayer()  {
                                body.removeChild( $( 'TLmain' ) );
                            }
                            
  
  divNapis.style.width = divWidth+'px';
  divNapis.style.backgroundColor = 'white';
  divNapis.style.fontSize = '10px';
  divNapis.style.fontFamily = 'Verdana, Tahoma, Arial, sns-serif';
  divNapis.style.textAlign = 'right';
  divNapis.style.margin = '0 auto';
  divNapis.innerHTML = 'zamknij ';
  
  divNapis.appendChild( close );
  
  div.appendChild( divNapis );
  
  divObrazek.style.width = divWidth+'px';
  divObrazek.style.backgroundColor = 'green';
  divObrazek.style.margin = '0 auto';
  divObrazek.style.margin = '0 auto';
  
  pic.setAttribute( 'src', banerFile );
  pic.style.border = '5px solid white';
  pic.style.cursor = 'pointer';
  pic.onclick = function ()  {
                          newWindow = window.open();
                          newWindow.location.href = dstLink;
                        }
  pic.setAttribute( 'border', '0' );
  
  divObrazek.appendChild( pic );
  
  div.appendChild( pic );
  
  body.innerHTML = '';
  body.appendChild( div );
  body.innerHTML += content;
}

function RemoveTopLayer()  {
  var body = document.getElementsByTagName( 'body' )[0]; 
  main = $( 'TLmain' ); 
  body.removeChild( main );
  //body.setAttribute( 'style', 'overflow: visible;');
}

function setblacklist(val) {
	if (val==true) {
	document.getElementById('blacklist').style.display="block";
	}
	else {
	document.getElementById('blacklist').style.display="none";
	}
}

function check_salary (shouldgive) {
	if (shouldgive=='0') {
		return true;
	}
	else {
	re = /^\d+(\.\d+)?$/;
	      if (document.applyform.oczekiwanewynagrodzenie.value=="" ||   re.test(document.applyform.oczekiwanewynagrodzenie.value)==false) {
	      	alert('Nie podałeś kwoty lub podana kwota jest w nieprawidłowym formacie!'); return false;
	      }
	      else return true;
	}
}

// Sprawdza formularz dodawania nowej aukcji
function check_auction_form(typ)
{
  if (typ == 0) {
    if (document.aukcja.aukcja_nazwa.value == "" ||
        document.aukcja.aukcja_opis.value == "" ||
        document.aukcja.aukcja_cenaminimalna.value == "" ||
        document.aukcja.aukcja_cenawywolawcza.value == "" ||
        document.aukcja.aukcja_grupa.selectedIndex == 0 ||
        document.aukcja.aukcja_datazakonczenia.selectedIndex == 0) {

        alert('Nieprawidłowo wypełniłeś formularz. Wypełnij wszystkie wymagane pola formularza oznaczone *');
        return false;
    } else {
      return true;
    }
  } else if (typ == 1) {
    if (document.aukcja.aukcja_nazwa.value == "" ||
        document.aukcja.aukcja_opis.value == "" ||
        document.aukcja.aukcja_cenakupteraz.value == "" ||
        document.aukcja.aukcja_grupa.selectedIndex == 0 ||
        document.aukcja.aukcja_grupa.selectedIndex == 0 ||
        document.aukcja.aukcja_datazakonczenia.selectedIndex == 0) {

        alert('Nieprawidłowo wypełniłeś formularz. Wypełnij wszyskie wymagane pola formulrza oznaczone *');
        return false;
    } else {
      return true;
    }
  } else {
    alert('bla bla');
    return false;
  }
}

// Sprawdza formularz edycji aukcji czy nazwa nie jest pusta
function check_auctionedit_form()
{
  if (document.aukcja.nazwa.value == "") {
    alert('Musisz podać nazwę aukcji.');
    return false;
  } else {
    return true;
  }
}

// Sprawdza czy format ceny przy kupowaniu jest prawidłowy
function check_price(cena)
{
  re = /^\d+(\.\d+)?$/;
  if (document.aukcja.nowacena.value < cena ||
      re.test(document.aukcja.nowacena.value) == false) {
    alert('Podana cena nie jest większa od ostatniej oferty kupna.');
    return false;
  } else {
    return true;
  }
}

// Sprawdza czy ilość jest liczbą całkowita
function check_number(ilosc)
{
  re = /^\d+$/; // wyrażenie regularne do sprawdzania czy podana została liczba całkowita (jedna lub więcej liczba)
  if (document.aukcja.kupowanailosc.value > ilosc ||
      document.aukcja.kupowanailosc.value <= 0     ||
      re.test(document.aukcja.kupowanailosc.value) == false) {
    alert('Podana ilość sztuk jest niepoprawna.');
    return false;
  } else {
    return true;
  }
}

function showpopup(url)
{
        var Win = window.open(url,'showpic','width=100,height=100,top=50,left=200,resizable=0,scrollbars=no,menubar=no,toolbar=no,status=no')
}

function showpopup2(url, width, height)
{
        LeftPosition=(screen.width)?(screen.width-width)/2:100;
     TopPosition=(screen.height)?(screen.height-height)/2:100;
        var Win = window.open(url,'showpic','width=' + width + ',height=' + height + ',top=50,left=200,resizable=0,scrollbars=no,menubar=no,toolbar=no,status=no')
}


function popupprint(url, width, height)
{
        LeftPosition=(screen.width)?(screen.width-width)/2:100;
     TopPosition=(screen.height)?(screen.height-height)/2:100;
        var Win = window.open(url,'showpic','width=' + width + ',height=' + height + ',top=50,left=200,resizable=0,scrollbars=yes,menubar=no,toolbar=no,status=no')
}

function showlangver(val) {
	if (val!="") {
		popupprint('other.php?lang='+val,550,600);
	}
}

function help ( content)
{
	if (content != '') return overlib (content);
}

function doff()
{
	return nd();
}



function check_commentform() {
	if (document.commentform.author.value=="" || document.commentform.email.value=="" ||
	document.commentform.title.value=="" ) {
		alert ('Nie wypełniłeś wszystkich pól oznaczonych *!'); return false;
	}
	else return true;
}

function check_contactform() {
	if (document.contactform.author.value=="" || document.contactform.email.value=="" ||
	document.contactform.title.value=="" ) {
		alert ('Nie wypełniłeś wszystkich pól oznaczonych *!'); return false;
	}
	else return true;
}

function check_noticeform() {
	if (document.noticeform.cats.value=="" || document.noticeform.title.value=="" ) {
		alert ('Nie wypełniłeś wszystkich pól oznaczonych *!'); return false;
	}
	else return true;
}

function check_agree() {
	if (document.newaccount.agree.checked!=true) {
		alert ('Aby założyć konto w serwisie, musisz zapoznać się z regulaminem!'); return false;
	}
	else return true;
}

function check_notification() {
	if (document.tellpanel.sender_email.value=="" || document.tellpanel.sender_email.value.indexOf('@')==-1 || document.tellpanel.receiver_email.value=="" || document.tellpanel.receiver_email.value.indexOf('@')==-1) {
		alert ('Musisz podać adresy e-mail nadawcy i odbiorcy w poprawnym formacie!'); return false;
	}
	else return true;
}


function check_notification2()
{
	if (document.tellpanel.sender_email.value=="" || document.tellpanel.sender_email.value.indexOf('@')==-1 || document.tellpanel.translation_text.value=="" || document.tellpanel.sender_telephone.value=="")
	{
		alert ('Musisz podać poprawny adres e-mail, tekst do tłumaczenia oraz numer kontaktowy!'); return false;
	}
	else return true;
}
