//
// UWAGA: Jesli nie ma ktoregos elementu id=  to validacja moze nie dzialac
//


function checkCheckbox()
{

    var pole     = document.getElementById( 'zgoda' 	)   
	var pole_ok  = document.getElementById( 'zgoda_ok'	); 
	var pole_bad = document.getElementById( 'zgoda_bad' ); 

	if ( pole.checked )
	{
		pole_ok.style.display = ''; 
		pole_bad.style.display = 'none'; 
		return 0;
    }
    else
    {   	
		pole_ok.style.display = 'none'; 
		pole_bad.style.display = ''; 
		return 1;
    }
 
}

/////////////////////////////////////////////////////////////////////////////////

function checkEmail()
{

    var pole     = document.getElementById( 'email1' 	)   
	var pole_ok  = document.getElementById( 'email1_ok'	); 
	var pole_bad = document.getElementById( 'email1_bad' );
	var pole_error = document.getElementById( 'email1_error' );  

	
	if ( pole.value.match( /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/ ) )
	{
		pole_ok.style.display = ''; 
		pole_bad.style.display = 'none';
		pole_error.style.display = 'none';  
		return 0;
    }
    else if(!pole.value)
    {
        pole_ok.style.display = 'none'; 
		pole_bad.style.display = ''; 
		pole_error.style.display = 'none'; 
		return 1;
    }
    else
    {   	
		pole_ok.style.display = 'none'; 
		pole_bad.style.display = 'none'; 
		pole_error.style.display = ''; 
		return 1;
    }
 
}

/////////////////////////////////////////////////////////////////////////////////

function checkValues()
{
	var ok=0;
	var pola = Array();

	pola[0]='name1';	
	pola[1]='birthday';
	pola[2]='address1';
	pola[3]='suburb';
	pola[4]='postcode';
	pola[5]='phone';
	pola[6]='education';
	pola[7]='experience';
	pola[8]='courses';
	pola[9]='other';
	pola[10]='computer';
	pola[11]='expectations';

	
	for( i=0; i<pola.length; i++)
	{
    	var pole     = document.getElementById( pola[i] );    
		var pole_ok  = document.getElementById( pola[i]+'_ok');
		var pole_bad = document.getElementById( pola[i]+'_bad'); 

    
    	if( pole )
    		if ( pole.value ){
				pole_ok.style.display = ''; 
				pole_bad.style.display = 'none'; 		
    		}else{   	
				pole_ok.style.display = 'none'; 
				pole_bad.style.display = '';
				ok++; 
    		}
    	
	}//for

	return ok; 
}




/////////////////////////////////////////////////////////////////////////////////
// Jesli wszystkie funkcje zwracaja 0 to formularz jest OK 
/////////////////////////////////////////////////////////////////////////////////

function checkAnswers() {
	
    var ok = 0;
    
    ok += checkValues();
    ok += checkEmail()   
 	ok += checkCheckbox();   
    
    if(  ok == 0  )
	{
		document.forms.cv.submit(); 
	}

}
