/* Skrypty do obslugi menu rozwijanego oraz menu rozsuwanego *
/* po co rozgrzebywać rozwijanie menu na  50 linii kodu jeżeli mozna to zrobić bez for() w 10? */
/*


function expand_menu(id) {
	var d = document.getElementById(id);
	var rozwin = true;
	if (d && d.style.display == 'block')
		rozwin = false;
	for (var i = 1; i<=50; i++) {
		if (document.getElementById('sub_menu'+i)) { document.getElementById('sub_menu'+i).style.display='none'; }
	}
	if (d && rozwin) { d.style.display='block'; }
}	

function expand_deepmenu(executor,id) {
	var d = document.getElementById(id);
	var e = document.getElementById('current-exp');
	var rozwin = true;
	if (e) e.id='none';
	if (d && d.style.display == 'block') 
		rozwin = false;
	for (var i = 1; i<=350; i++) {
		if (document.getElementById('deep_menu'+i)) { document.getElementById('deep_menu'+i).style.display='none'; }
	}
	if (d && rozwin) { 
		d.style.display='block'; 
		executor.id='current-exp';
	}
}	



onItemClick = function() {
  var li = this.parentNode;
  if (! li) return true;
  li.className = (li.className.indexOf('expanded') == -1) ? 'expanded' : '';
  return false;
}
activateMenu = function() {
  var menu = document.getElementById('menu');
  if (! menu) return false;
  var a = menu.getElementsByTagName('A');
  for ( var i=0; i<a.length; i++ ) {
    var tag = a[i].nextSibling;
    // je[li tekst to pobierz nastpny element
    if (tag && tag.nodeType == 3) tag = tag.nextSibling;
    // je[li element listy zawiera podlist
    if (tag && tag.tagName == 'UL') {
      a[i].onclick = onItemClick;
    }
  }
}

	
*/

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

function getElement(el) {
	return document.all ? document.all[el] : document.getElementById (el);
}

function triggerError (errorId, msg) {
	errorId += 'Error';
	if (msg != '') {
		getElement(errorId).innerHTML = msg;
	}
	getElement(errorId).style.display = 'block';
}
function hideError (errorId) {
	errorId += 'Error';
	getElement(errorId).style.display = 'none';
}


// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateEmail(addr,man,db) {
	if (addr == '' && man) {
   		if (db) alert('email address is mandatory');
   		return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
   		if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      		if (db) alert('email address contains invalid characters');
      			return false;
   		}
	}
	for (i=0; i<addr.length; i++) {
   		if (addr.charCodeAt(i)>127) {
      		if (db) alert("email address contains non ascii characters.");
      		return false;
   		}
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
	return true;
}

function autoVerifyForm(f) {
	// sprawdzam, czy DOM jest dostepny
	if(!document.getElementById || !document.createTextNode){ return false; }
	
	var result=true; // poprawnosc formularza  
	
	// czyszczenie komunikatow
    for (i=0; i<f.length; i++) {
		if ( f.elements[i].className == "required" ) {
			var message=f.elements[i].nextSibling; // nastepnik
			message.nextSibling.className="error-hide"; // wlasciwy obiekt i zmiana klasy 	
		}
    }
	
	// pobranie elementow formularza i przetwarzanie tych z class="required" 	
	for (i=0; i<f.length; i++) {
		if ( f.elements[i].className == "required" ) {
			switch( f.elements[i].type.toLowerCase() ) {
				case 'text':
					if(f.elements[i].value=='' && f.elements[i].disabled==false) {
						var message=f.elements[i].nextSibling; /* nastepnik */
						message.nextSibling.className="error-show"; /* wlasciwy obiekt i zmiana klasy */
						result=false;
					}
				break;
				case 'textarea':
					if(f.elements[i].value=='' && f.elements[i].disabled==false) {
						var message=f.elements[i].nextSibling; /* nastepnik */
						message.nextSibling.className="error-show"; /* wlasciwy obiekt i zmiana klasy */
						result=false;	
					}
				break;
				case 'checkbox':
				    if(!f.elements[i].checked && f.elements[i].disabled==false) {
				    	
				    }
				break;
				case 'select-one':
				    if(!f.elements[i].selectedIndex && f.elements[i].selectedIndex==0 && f.elements[i].disabled==false) {
				    			    	
				    }
				break;
			} // end switch 			
		}
	} // end for
	
	return result;
}

/* onload */
window.onload = function() {
 // activateMenu();
}
