/**
	* Sprawdzanie poprawności składni dla adresów e-mail
	* - email (xxx@xxx.pl)
	* - kod pocztowy (format 00-000)
**/

	function validate(type,string) 
	{

		if(type=='email')	
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(string)) 
			{ 
				return true; 
			} else { return false; }
		}

		if(type=='kodpocztowy') {
			if(/^[0-9]{2}-[0-9]{3}$/.test(string)) 
			{
				return true; 
			} else { return false; }
		}
	}

/**
	* Sprawdzanie poprawności wpisanych danych w formularzu newslettera
**/

function checkNewsletterForm( form )
{
	var msg = '';
	
	if( form.nl_email.value=='' ) { msg += '* podaj swój adres e-mail \n'; } 
	if (validate('email',form.nl_email.value)==false) { msg += '* podany e-mail ma nieprawidłową składnię !\n   Prawidłowa to np.: biuro@avatec.pl \n'; }

	if( msg ) { alert( 'Formularz zawiera błędy: \n\n'+msg ); return false; } else { return true; }

}

/**
	* Sprawdzanie poprawności wpisanych danych w formularzu kontaktowym
**/

function checkCommentForm( form )
{
	var msg = '';
	
	if( form.podpis.value=='' ) { form.podpis.style.background = "#ffffce"; msg += '* podaj swoje imię \n'; } else { form.email.style.background = "white"; }
	if( form.email.value=='' ) { form.email.style.background = "#ffffce"; msg += '* podaj swój adres e-mail \n'; } else { form.email.style.background = "white"; }
	if( form.komentarz.value=='' ) { form.komentarz.style.background = "#ffffce"; msg += '* wpisz swój komentarz \n'; } else { form.komentarz.style.background = "white"; }
	
	if (validate('email',form.email.value)==false) { form.email.style.background = "#ffffce"; msg += '* podany e-mail ma nieprawidłową składnię !\n   Prawidłowa to np.: biuro@avatec.pl \n'; } else { form.email.style.background = "white"; }

	if( msg ) { alert( 'Formularz zawiera błędy: \n\n'+msg ); 	return false; } else { showHide('comment-form'); showHide('comment-preview'); return true; }

}
	


function sleep(msecs)
{
  var start = new Date().getTime();
  var cur = start
  while(cur - start < msecs)
  {
		cur = new Date().getTime();
	}
	return true;
} 

function showHide(whichLayer) 
{
	var elem, vis;
  if( document.getElementById )
    elem = document.getElementById( whichLayer );
		
  else if( document.all ) 
      elem = document.all[whichLayer];
			
  else if( document.layers ) 
    elem = document.layers[whichLayer];
		
  var vis = elem.style;
	
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';

}

