function echeck(str) {
		 var at="@"
		 var dot="."
		 var lat=str.indexOf(at)
		 var lstr=str.length
		 var ldot=str.indexOf(dot)
		 if (str.indexOf(at)==-1){return false}
     if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false}
		 if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false}
		 if (str.indexOf(at,(lat+1))!=-1){return false}
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false}
		 if (str.indexOf(dot,(lat+2))==-1){return false}
		 if (str.indexOf(" ")!=-1){return false}
 		 return true					
	}
	function highlight(id){
    document.getElementById(id).style.backgroundColor = '#bc4e4e;';
  }
  function normal(id){
    document.getElementById(id).style.backgroundColor = '#ffffff;';
  }
function fixit(){
  document.getElementById('fixit_url_id').value = document.location;
  errors=0;
  if(document.getElementById('fixit_podpis_id').value==''){
    errors++;
  }
  if(document.getElementById('fixit_tresc_id').value==''){
    errors++;
  }
  if(!errors){
    alert('Dziękujemy!');
    document.fixit_form.submit();
  }else{
    alert('Sprawdź poprawność formularza');
  }
}
function friendit(){
  document.getElementById('friendit_url_id').value = document.location;
  errors=0;
  if(!echeck(document.getElementById('friendit_adresat_email_id').value)){
    errors++;
  }
  if(!echeck(document.getElementById('friendit_mail_id').value) && document.getElementById('friendit_mail_id').value!=''){
    errors++;
  }
  if(document.getElementById('friendit_adresat_id').value==''){
    errors++;
  }
  if(document.getElementById('friendit_imie_id').value==''){
    errors++;
  }
  if(document.getElementById('friendit_komentarz_id').value==''){
    errors++;
  }
  if(!errors){
    alert('Dziękujemy!');
    document.friendit_form.submit();
  }else{
    alert('Sprawdź poprawność formularza');
  }
}

function show_fixit(){
  if(typeof(window.pageYOffset)=='number'){
    scrOfY = window.pageYOffset;
  }else if(document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    scrOfY = document.body.scrollTop;
  }else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
    scrOfY = document.documentElement.scrollTop;
  }
  document.getElementById('fixit').style.top = 100+scrOfY+"px";
  document.getElementById('fixit').style.display = 'block';
  mint.gui.RegisterDragObject('fixit');
}
function hide_fixit(){
  document.getElementById('fixit').style.display='none';
}


function show_powiadom(){
  if(typeof(window.pageYOffset)=='number'){
    scrOfY = window.pageYOffset;
  }else if(document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    scrOfY = document.body.scrollTop;
  }else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
    scrOfY = document.documentElement.scrollTop;
  }
  document.getElementById('powiadom').style.top = 100+scrOfY+"px";
  document.getElementById('powiadom').style.display = 'block';
  mint.gui.RegisterDragObject('powiadom');
}
function hide_powiadom(){
  document.getElementById('powiadom').style.display='none';
}
//patt
function patt(wh){
  //alert(wh);
  if(wh>0 && wh<5){
    document.body.style.backgroundImage = 'url(tpl/images/'+wh+'.gif)';
    document.getElementById('actual_patt_id').value = wh;
    document.getElementById('zapisz_patt_id').href = document.getElementById('org_page_id').value + ".html-patt=" + wh;
  }
}
function patt_next(){
  //alert('next');
  actual_patt = document.getElementById('actual_patt_id').value;
  actual_patt = parseInt(actual_patt);  
  next_patt=actual_patt+1;
  if(next_patt==5){
    next_patt=1;
  }
  patt(next_patt);
}
function patt_prev(){
  //alert('prev');
  actual_patt = document.getElementById('actual_patt_id').value;
  actual_patt = parseInt(actual_patt);
  prev_patt=actual_patt-1;
  if(prev_patt==0){
    prev_patt=4;
  }
  patt(prev_patt);
}
//
function grafik_submit(){
  errors = 0;
  errors2 = 0;
  if(document.getElementById('file_list_id').innerHTML==''){
    errors2++;
    alert('Proszę wysłać przynajmniej jeden plik');
  }
  if(document.getElementById('imie_nazwisko_id').value==''){
    errors++;
    highlight('imie_nazwisko_id');
  }else{
    normal('imie_nazwisko_id');
  }
  if(document.getElementById('email_id').value=='' || !echeck(document.getElementById('email_id').value)){
    errors++;
    highlight('email_id');
  }else{
    normal('email_id');
  }
  if(document.getElementById('telefon_id').value==''){
    errors++;
    highlight('telefon_id');
  }else{
    normal('telefon_id');
  }
  if(document.getElementById('upload_dir_id').value==''){
    errors2++;
    alert('Błąd - proszę o zgłoszenie problemu pod adresem admin@owocni.pl. Dziękujemy!');
  }
  if(!document.getElementById('ochrona_danych_id').checked){
    errors2++;
    highlight('ochrona_danych_id');
    alert('Musisz zapoznać się z ustawą o ochronie danych osobowych');
  }else{
    normal('ochrona_danych_id');
  }
  if(!errors && !errors2){
    document.praca.submit();
  }else if(errors && !errors2){
    alert('Proszę sprawdzić wprowadzone dane');
  }
}

function zdalna_submit(){
  errors = 0;
  errors2 = 0;
  if(document.getElementById('file_list_id').innerHTML==''){
    errors2++;
    alert('Proszę wysłać przynajmniej jeden plik');
  }
  if(document.getElementById('imie_nazwisko_id').value==''){
    errors++;
    highlight('imie_nazwisko_id');
  }else{
    normal('imie_nazwisko_id');
  }
  if(document.getElementById('email_id').value=='' || !echeck(document.getElementById('email_id').value)){
    errors++;
    highlight('email_id');
  }else{
    normal('email_id');
  }
  if(document.getElementById('telefon_id').value==''){
    errors++;
    highlight('telefon_id');
  }else{
    normal('telefon_id');
  }
  if(document.getElementById('upload_dir_id').value==''){
    errors2++;
    alert('Błąd - proszę o zgłoszenie problemu pod adresem admin@owocni.pl. Dziękujemy!');
  }
  if(!document.getElementById('ochrona_danych_id').checked){
    errors2++;
    highlight('ochrona_danych_id');
    alert('Musisz zapoznać się z ustawą o ochronie danych osobowych');
  }else{
    normal('ochrona_danych_id');
  }
  
  if(document.getElementById('kompetencje_id').value==''){
    errors++;
    highlight('kompetencje_id');
  }else{
    normal('kompetencje_id');
  }
  if(document.getElementById('czas_id').value==''){
    errors++;
    highlight('czas_id');
  }else{
    normal('czas_id');
  }
  if(document.getElementById('cechy_id').value==''){
    errors++;
    highlight('cechy_id');
  }else{
    normal('cechy_id');
  }
  if(document.getElementById('narzedzia_id').value==''){
    errors++;
    highlight('narzedzia_id');
  }else{
    normal('narzedzia_id');
  }
  if(document.getElementById('dokonania_id').value==''){
    errors++;
    highlight('dokonania_id');
  }else{
    normal('dokonania_id');
  }
  if(document.getElementById('www_id').value==''){
    errors++;
    highlight('www_id');
  }else{
    normal('www_id');
  }
  if(document.getElementById('info_dodatkowe_id').value==''){
    errors++;
    highlight('info_dodatkowe_id');
  }else{
    normal('info_dodatkowe_id');
  }
  if(document.getElementById('info_id').value==''){
    errors++;
    highlight('info_id');
  }else{
    normal('info_id');
  }
  
  if(!errors && !errors2){
    document.praca.submit();
  }else if(errors && !errors2){
    alert('Proszę sprawdzić wprowadzone dane');
  }
}

function stala_submit(){
  errors = 0;
  errors2 = 0;
  if(document.getElementById('file_list_id').innerHTML==''){
    errors2++;
    alert('Proszę wysłać przynajmniej jeden plik');
  }
  if(document.getElementById('imie_nazwisko_id').value==''){
    errors++;
    highlight('imie_nazwisko_id');
  }else{
    normal('imie_nazwisko_id');
  }
  if(document.getElementById('email_id').value=='' || !echeck(document.getElementById('email_id').value)){
    errors++;
    highlight('email_id');
  }else{
    normal('email_id');
  }
  if(document.getElementById('telefon_id').value==''){
    errors++;
    highlight('telefon_id');
  }else{
    normal('telefon_id');
  }
  if(document.getElementById('upload_dir_id').value==''){
    errors2++;
    alert('Błąd - proszę o zgłoszenie problemu pod adresem admin@owocni.pl. Dziękujemy!');
  }
  if(!document.getElementById('ochrona_danych_id').checked){
    errors2++;
    highlight('ochrona_danych_id');
    alert('Musisz zapoznać się z ustawą o ochronie danych osobowych');
  }else{
    normal('ochrona_danych_id');
  }
  
  if(document.getElementById('umiejetnosci_id').value==''){
    errors++;
    highlight('umiejetnosci_id');
  }else{
    normal('umiejetnosci_id');
  }
  if(document.getElementById('dokonania_id').value==''){
    errors++;
    highlight('dokonania_id');
  }else{
    normal('dokonania_id');
  }
  if(document.getElementById('www_id').value==''){
    errors++;
    highlight('www_id');
  }else{
    normal('www_id');
  }
  
  if(!errors && !errors2){
    document.praca.submit();
  }else if(errors && !errors2){
    alert('Proszę sprawdzić wprowadzone dane');
  }
}
