/**
*	Opis: funkcja sprawdza, czy grafika jest aktywna, czy nie
*/
function sendForm( txt )
{
	var fNames = Array( 'company_name', 'address', 'name_surname', 'medium' );
	var ok = 1;
	for( var i = 0; i <= 3; i++ )
	{
		if( checkIsEmpty( fNames[i] ) == 0 )
		{
			ok = 0;
			min = 11;
		}
	}
	if( checkPhone( 'phone' ) == 0 )
	{
		ok = 0;
	}
	if( checkPhone( 'fax' ) == 0 )
	{
		ok = 0;
	}
	if( checkEmailOnForm( 'email' ) == 0 )
	{
		ok = 0;
	}
	
	var fNumber = Array( 'cisnienie', 'temp_od', 'temp_do', 'otemp_od', 'otemp_do' );
	for( var i = 0; i <= 4; i++ )
	{
		if( checkIsNumber( fNumber[i] ) == 0 )
		{
			ok = 0;
		}
	}
	

	if( checkSelect( 'polaczenie', 1 ) == 0 )
	{
		ok = 0;
	}
	
	if( checkSelect( 'podcisnienie', 1 ) == 0 )
	{
		ok = 0;
	}
	
	if( checkSelect( 'przyrzad', 1 ) == 0 )
	{
		ok = 0;
	}
	
	if( checkSelect( 'separator', 1 ) == 0 )
	{
		ok = 0;
	}
	
	if( $( 'polaczenie' ).value == 1 )
	{
		if( checkIsNumber( 'd_kapilary' ) == 0 )
		{
			ok = 0;
		}
	}
	
	if( $( 'podcisnienie' ).value == 1 )
	{
		if( checkIsNumber( 'max_podcisnienie' ) == 0 )
		{
			ok = 0;
		}
	}
	
	if( $( 'przyrzad' ).value == 1 )
	{
		var fRadio = Array( 'sr_tarczy', 'poz_zlacza' );
		for( var i = 0; i <= 1; i++ )
		{
			if( checkRadioChecked( fRadio[i] ) == 0 )
			{
				ok = 0;
			}
		}
		if( checkSelect( 'kontakty_alarmowe', 1 ) == 0 )
		{
			ok = 0;
		}
		if( $( 'kontakty_alarmowe' ).value == 1  )
		{
			if( checkRadioChecked( 'kontakty_model' ) == 0 )
			{
				ok = 0;
			}
		}
	}
	else if( $( 'przyrzad' ).value == 2 )
	{
		if( checkSelect( 'sygnal_wy', 1 ) == 0 )
		{
			ok = 0;
		}
		if( $( 'sygnal_wy' ).value == 3 )
		{
			if( checkIsEmpty( 'inne_sygnal_wy' ) == 0 )
			{
				ok = 0;
			}
		}
	}
	
	if( $( 'separator' ).value == 1  )
	{
		if( checkSelect( 'gwint', 1 ) == 0 )
		{
			ok = 0;
		}
		if( $( 'gwint' ).value == 1  )
		{
			if( checkSelect( 'zw_gwint', 1 ) == 0 )
			{
				ok = 0;
			}
			if( $( 'zw_gwint' ).value == 11  )
			{
				if( checkIsEmpty( 'inne_zw_gwint' ) == 0 )
				{
					ok = 0;
				}
			}
		}
		if( $( 'gwint' ).value == 2 )
		{
			if( checkSelect( 'we_gwint', 1 ) == 0 )
			{
				ok = 0;
			}
			if( $( 'we_gwint' ).value == 5 )
			{
				if( checkIsEmpty( 'inne_we_gwint' ) == 0 )
				{
					ok = 0;
				}
			}
		}
	}
	
	if( $( 'separator' ).value == 2  )
	{
		if( checkRadioChecked( 'w_nominalny' ) == 0 )
		{
			ok = 0;
		}
		if( checkRadioChecked( 'c_nominalne' ) == 0 )
		{
			ok = 0;
		}
	}
	if( $( 'separator' ).value == 3  )
	{
		if( checkSelect( 'norma', 1 ) == 0 )
		{
			ok = 0;
		}
		if( $( 'norma' ).value == 10 )
		{
			if( checkIsEmpty( 'inne_norma' ) == 0 )
			{
				ok = 0;
			}
		}
		
		
		if( $( 'norma' ).value == 1 )
		{
			if( checkSelect( 'w_nom_1', 1 ) == 0 )
			{
				ok = 0;
			}
			if(  $( 'w_nom_1' ).value == 5 )
			{
				if( checkIsEmpty( 'inne_norma_1' ) == 0 )
				{
					ok = 0;
				}
			}
		}
		
		if( $( 'norma' ).value == 2 )
		{
			if( checkSelect( 'w_nom_2', 1 ) == 0 )
			{
				ok = 0;
			}
			if(  $( 'w_nom_2' ).value == 3 )
			{
				if( checkIsEmpty( 'inne_norma_1' ) == 0 )
				{
					ok = 0;
				}
			}
		}
		
		if( $( 'norma' ).value == 3 )
		{
			if( checkSelect( 'w_nom_3', 1 ) == 0 )
			{
				ok = 0;
			}
			if(  $( 'w_nom_3' ).value == 5 )
			{
				if( checkIsEmpty( 'inne_norma_1' ) == 0 )
				{
					ok = 0;
				}
			}
		}
		
		if( $( 'norma' ).value == 4 )
		{
			if( checkSelect( 'w_nom_4', 1 ) == 0 )
			{
				ok = 0;
			}
			if(  $( 'w_nom_4' ).value == 6 )
			{
				if( checkIsEmpty( 'inne_norma_1' ) == 0 )
				{
					ok = 0;
				}
			}
		}
		
		if( $( 'norma' ).value == 5 )
		{
			if( checkSelect( 'w_nom_3', 1 ) == 0 )
			{
				ok = 0;
			}
			if(  $( 'w_nom_3' ).value == 5 )
			{
				if( checkIsEmpty( 'inne_norma_1' ) == 0 )
				{
					ok = 0;
				}
			}
		}
		
		if( $( 'norma' ).value == 6 )
		{
			if( checkSelect( 'w_nom_3', 1 ) == 0 )
			{
				ok = 0;
			}
			if(  $( 'w_nom_3' ).value == 5 )
			{
				if( checkIsEmpty( 'inne_norma_1' ) == 0 )
				{
					ok = 0;
				}
			}
		}
		
		if( $( 'norma' ).value == 7 )
		{
			if( checkSelect( 'w_nom_5', 1 ) == 0 )
			{
				ok = 0;
			}
			if(  $( 'w_nom_5' ).value == 7 )
			{
				if( checkIsEmpty( 'inne_norma_1' ) == 0 )
				{
					ok = 0;
				}
			}
		}
		
		if( $( 'norma' ).value == 8 )
		{
			if( checkSelect( 'w_nom_6', 1 ) == 0 )
			{
				ok = 0;
			}
			if(  $( 'w_nom_6' ).value == 3 )
			{
				if( checkIsEmpty( 'inne_norma_1' ) == 0 )
				{
					ok = 0;
				}
			}
		}
		
		if( $( 'norma' ).value == 9 )
		{
			if( checkSelect( 'w_nom_7', 1 ) == 0 )
			{
				ok = 0;
			}
			if(  $( 'w_nom_7' ).value == 10 )
			{
				if( checkIsEmpty( 'inne_norma_1' ) == 0 )
				{
					ok = 0;
				}
			}
		}
	}

	if( ok == 1 )
	{
		$( 'formType' ).value = 1;
		$( 'reserve' ).submit();
		//alert( 'Submit!' );
	}
	else
	{
		alert( txt );
	}
}

/**
*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
*/
function checkPhone( id )
{
	if( checkIsEmpty( id ) == 0 )
	{	
		ok = 0;
	}
	else
	{
		oObj = $( id );
		var ok = 1;
		re = /^[0-9\(\)\- ]+$/;
		if( oObj.value.match( re ) )
		{
			oObj.className = 'long0';
			ok = 1;
		}
		else
		{
			oObj.className = 'long1';
			ok = 0;
		}
	}
	return ok;
}

/**
*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
*/
function checkIsNumber( id )
{
	mode = 2;
	oObj = $( id );
	var number = new String( oObj.value );
	//number = number.myTrim();
	number = number.replace( /,/g , ".");
	number = number.replace( / /g , "");
	if( mode == 1 )
	{
		re = /^[0-9]+([\.][0-9]{0,})?$/g;
	}
	else
	{
		re = /^([\-])?[0-9]+([\.][0-9]{0,})?$/g;
	}
	if( number.match( re, "" ) )
	{
		oObj.className = 'long0';
		ok = 1;
	}
	else
	{
		oObj.className = 'long1';
		ok = 0;
	}
	return ok;
}

/**
*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
*/
function checkNameSurname( id )
{
	oObj = $( id );
	var ok = 1;
	re = /^[a-zA-ZęóąśłżźćńĘÓĄŚŁŻŹĆŃ]+$/;
	if( oObj.value.match( re ) )
	{
		oObj.className = 'long0';
		ok = 1;
	}
	else
	{
		oObj.className = 'long1';
		ok = 0;
	}
	return ok;
}

/**
*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
*/
function checkIsEmpty( id )
{
	oObj = $( id );
	var ok = 1;
	re = /^[\s\n\r\f]+/;
	oObj.value = oObj.value.replace( re, '' );
	re = /[\s\n\r\f]+$/;
	oObj.value = oObj.value.replace( re, '' );
	if( oObj.value != '' )
	{
		oObj.className = 'long0';
		ok = 1;
	}
	else
	{
		oObj.className = 'long1';
		ok = 0;
	}
	return ok;
}

/**
*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
*/
function checkIsEmptyShort( id )
{
	oObj = $( id );
	var ok = 1;
	re = /^[\s\n\r\f]+/;
	oObj.value = oObj.value.replace( re, '' );
	re = /[\s\n\r\f]+$/;
	oObj.value = oObj.value.replace( re, '' );
	if( oObj.value != '' )
	{
		oObj.className = 'short0';
		ok = 1;
	}
	else
	{
		oObj.className = 'short1';
		ok = 0;
	}
	return ok;
}

/**
*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
*/
function checkPostCodeOnForm( id )
{
	oObj = $( id );
	var ok = 1;
	re = /^[0-9]{2,2}-[0-9]{3,3}$/;
	if( oObj.value.match( re ) )
	{
		oObj.className = 'short0';
		ok = 1;
	}
	else
	{
		oObj.className = 'short1';
		ok = 0;
	}
	return ok;
}

/**
*	Opis: sprawdza, czy e-mail i haslo do rejestracji nie sa puste
*/
function checkEmailOnForm( id )
{
	oObj = $( id );
	var ok = 1;
	
	if( oObj.value != '' )
	{
		if( isEMail( oObj.value ) )
		{
			oObj.className = 'long0';
			ok = 1;
		}
		else
		{
			oObj.className = 'long1';
			ok = 0;
		}
	}
	else
	{
		oObj.className = 'long1';
		ok = 0;
	}
	return ok;
}

/**
*	Opis: funkcja sprawdza, czy ciag jest poprawnym adresem e-mail
*/
function isEMail( email )
{
	re = /^[-a-z0-9!#$%&\'*+\/=?^_`{|}~]+(\.[-a-z0-9!#$%&\'*+\/=?^_`{|}~]+)*@(([a-z]([-a-z0-9]*[a-z0-9]+)?){1,63}\.)+([a-z]([-a-z0-9]*[a-z0-9]+)?){2,63}$/g;
	check = email.replace( re, "" );
	if( check == '' )
	{
		return 1;
	}
	return 0;
}

/**
*	Opis: funkcja sprawdza, czy ciag jest poprawnym adresem e-mail
*/
function setChosenField()
{
	var re = /^http:\/\/(www\.)?.+\/formularz.html#analog$/;
	var loc = new String( window.location );
	if( loc.match( re ) )
	{
		$( 'television1' ).checked = true;
	}
	else
	{
		$( 'television0' ).checked = true;
	}
}

function showHide( id, id2 )
{
	if( $( id2 ).checked == true )
	{
		$( id ).style.display= 'block';
	}
	else
	{
		$( id ).style.display= 'none';
	}
}

function showHide1( divId, id )
{
	$( divId+'1' ).style.display= 'none';
	
	if( ( $( id ).value == 1 ) )
	{
		$( divId+$( id ).value ).style.display= 'block';
	}
}

function showHide2( divId, id )
{
	$( divId+'1' ).style.display= 'none';
	$( divId+'2' ).style.display= 'none';
	
	if( ( $( id ).value == 1 ) || ( $( id ).value == 2 ) )
	{
		$( divId+$( id ).value ).style.display= 'block';
	}
}

function showHide3( divId )
{
	$( divId+'1' ).style.display= 'none';
	$( divId+'2' ).style.display= 'none';
	$( divId+'3' ).style.display= 'none';
	
	if( ( $( 'separator' ).value == 1 ) || ( $( 'separator' ).value == 2 ) || ( $( 'separator' ).value == 3 ) )
	{
		$( divId+$( 'separator' ).value ).style.display= 'block';
	}
}

function showHide4( id )
{
	oObj1 = $$( '.w_norma' );
	for( i = 0;  i < oObj1.length;  i++)
	{
		oObj1[i].style.display = 'none';
	}
	oObj2 = $$( '.w_nom' );
	for( i = 0;  i < oObj2.length;  i++)
	{
		oObj2[i].options[0].selected= true;
	}
	$( 'inne_norma_1' ).className= 'long0';
	$( 'w_nom_inne' ).style.display = 'none';
	if( ( id > 0   ) && ( id  < 10 ) )
	{
		var id2 = new Array();
		id2[1] = 1;
		id2[2] = 2;
		id2[3] = 3;
		id2[4] = 4;
		id2[5] = 3;
		id2[6] = 3;
		id2[7] = 5;
		id2[8] = 6;
		id2[9] = 7;
		$( 'nom_'+id2[id]  ).style.display = 'block';
	}
}

function showHide5( id, id2 )
{
	if( ( $( 'gwint0' ).checked == true ) || (  $( 'gwint1' ).checked == true ) )
	{
		$( id ).style.display= 'block';
		$( id2 ).style.display= 'none';
	}
	else
	{
		$( id ).style.display= 'none';
		$( id2 ).style.display= 'none';
	}
}


function checkRadioChecked( name )
{
	oObj = document.getElementsByName( name );
	ok = 0;
	for( i = 0;  i < oObj.length;  i++ )
	{
		if( oObj[i].checked == true )
		{
			ok = 1;
		}
	}
	
	if( ok == 0 )
	{
		cObj = $$( '.'+name+'0' );
		for( l = 0;  l < cObj.length;  l++ )
		{
			cObj[l].className = name+'1' ;
		}
	}
	else
	{
		cObj = $$( '.'+name+'1' );
		for( l= 0;  l < cObj.length;  l++ )
		{
			cObj[l].className = name+'0' ;
		}
	}
	return ok;
}

function checkRadioChecked2( name, type )
{
	oObj = document.getElementsByName( name );
	ok = 0;
	for( i = 0;  i < oObj.length;  i++ )
	{
		if( oObj[i].checked == true )
		{
			ok = 1;
		}
	}
	
	if( ok == 0 )
	{
		cObj = $$( '.'+name+'0' );
		for( l = 0;  l < cObj.length;  l++ )
		{
			cObj[l].className = name+'1' ;
		}
	}
	else
	{
		cObj = $$( '.'+name+'1' );
		for( l= 0;  l < cObj.length;  l++ )
		{
			cObj[l].className = name+'0' ;
		}
		if( ( type == 1 ) && ( $( name+'_inne' ).checked == true ) )
		{
			if( checkIsEmpty( 'inne_'+name ) == 0 )
			{
				ok = 0;
			}
		}
		else
		{
			$( 'inne_'+name ).className = 'long0';
		}
	}
	return ok;
}

function showHideInput( value )
{
	if( value ==  'zw_inne'  )
	{
		$( 'zw_gwint_inne' ).style.display = 'block';
	}
	else
	{
		$( 'zw_gwint_inne' ).style.display = 'none';
	}
}

function checkSelect( id, type )
{
	
	if( $( id ).value != 0 ) 
	{
		$( id ).className = 'slong0';
		ok = 1;
	}
	else if ( type == 1 )
	{
		$( id ).className = 'slong1';
		ok = 0;
	}
	return ok;
}

function showHideOthers( sid,  svalue )
{
	if( $( sid ).value == svalue )
	{
		$( ''+sid+'_inne' ).style.display = 'block';
	}
	else
	{
		$( ''+sid+'_inne' ).style.display = 'none';
	}
	
}

function showHideOthers1( sid,  svalue )
{
	if( $( sid ).value == svalue )
	{
		$( 'w_nom_inne' ).style.display = 'block';
	}
	else
	{
		$( 'w_nom_inne' ).style.display = 'none';
	}
	
}
