function test()
{
	alert('ok');
	return false;
	
}


function validateApplForm(f)
{	
	var errorCode = 0;
	var divs = document.getElementsByTagName('div');	
	for(var a=0; a<divs.length; a++)
	{
		
		if(divs[a].getAttribute('id') && divs[a].getAttribute('id').substr(0,7) == 'errdiv_')
		{			
			$(divs[a].getAttribute('id')).className = 'hidden';			
		}
	}		
	
	mreg = /^([0-9]{9})$/;	
	
	for(var i=0; i<f.length; i++)
	{
		if(		
		($F(f.elements[i]) == "" 
		||
		/*(
		 (f.elements[i].id == 'creditperiod' || f.elements[i].id == 'monthIncome' || f.elements[i].id == 'totalIncome' 
		|| f.elements[i].id == 'creditEncumberance' || f.elements[i].id == 'monthEncumberance') 
		 && (!isInt($F(f.elements[i])) && !isFloat($F(f.elements[i])))
		)		
		||*/ (f.elements[i].id == 'email' && !verifyEmail($F(f.elements[i])))
		|| (f.elements[i].id == 'mobile' && (!mreg.test($F(f.elements[i])) || $F(f.elements[i]) == '555555555') ) 	
		|| ((f.elements[i].id == 'pAgreement' || f.elements[i].id == 'mAgreement') && $(f.elements[i]).checked == false))
		&& $('errdiv_'+$(f.elements[i]).id)
		)
		{
			$('errdiv_'+$(f.elements[i]).id).className = 'applErrDiv';
			errorCode = 1;
		}
		
				
		
		if($(f.elements[i]).type == "radio" && f.elements[i].id.substr(f.elements[i].id.length-1) == '1')
		{
			
			var elName = f.elements[i].id.substr(0,f.elements[i].id.length-1);	
				
			if(!f.elements[i].checked && !$(elName+'2').checked && $('errdiv_'+elName))
			{
				$('errdiv_'+elName).className = 'applErrDiv';
				errorCode = 1;
			}			
		}
	}
	
	if(errorCode == 1)
	{
		return false;
		
	}
	
}

function isFloat(s)
{
var n = trim(s);
return n.length>0 && !(/[^0-9.]/).test(n) && (/\.\d/).test(n);
}

function isInt(x) {
   var y=parseInt(x);
   if (isNaN(y)) return false;
   return x==y && x.toString()==y.toString();
 } 

function validateAdmForm()
{	
	var errorCode = 0;
	var divs = document.getElementsByTagName('div');	
	for(var a=0; a<divs.length; a++)
	{		
		if(divs[a].getAttribute('id') && divs[a].getAttribute('id').substr(0,7) == 'errdiv_')
		{			
			$(divs[a].getAttribute('id')).className = 'hidden';			
		}
	}		
	
	if($F('login') == "" || $F('login').length<5 || $F('login').length>10)
	{
		$('errdiv_login').className = 'applErrDiv';
		errorCode = 1;
	}
	
	if($F('pass') == "" || $F('pass').length<4 || $F('pass').length>10)
	{
		$('errdiv_pass').className = 'applErrDiv';
		errorCode = 1;
	}
	
	if($F('passrep') != $F('pass'))
	{
		$('errdiv_passrep').className = 'applErrDiv';
		errorCode = 1;
	}
		
		
	if(errorCode == 1)
	{
		return false;
		
	}
	
}

function prepareDate()
{	
	//$('birthdate').value = $F('year')+'-'+$F('month')+'-'+$F('day');	
}

function checkDate(dateval)
{		
	
	if(!isInt(dateval) || dateval<18)	
		$('age').value = "";
	
	/*if(!verifyDate(dateval))
	{		
		$('birthdate').value = "";	
	}*/
	
}

function checkCreditLimits()
{
	if(!isInt($F('creditAmount')) || $F('creditAmount')<100000)
	   $('creditAmount').value = '';
	
	if(!isInt($F('esPropValue')) || $F('esPropValue')<$F('creditAmount'))
	   $('esPropValue').value = '';
	
		
}

function sumTotalIncome()
{
	var re = /\,/;
	
	$('monthIncome').value = $('monthIncome').value.replace(re,'.');
	
	if($('otherIncome').value == "")
	{
		$('otherIncome').value = 0;	
	}
	else
	{
		$('otherIncome').value = $('otherIncome').value.replace(re,'.');
	}
	
	var totalIncome = (parseFloat($('monthIncome').value)+parseFloat($('otherIncome').value));
	
	if(isNaN(totalIncome))	
	{	
		$('totalIncome').value = 0; 	
	}
	else
	{
		$('totalIncome').value = totalIncome; 
	}
}

function manageImage(imageVal,imageChk)
{
	
	
	if($(imageVal).value!=''){
		$(imageChk).checked = true;
	}else{
		$(imageChk).checked = false;
	}
	
}

function validatePageForm()
{
	if($F('title') == '')
	{
		alert('wstaw tytuł strony!');
		return false;
	}
	
	if($F('text') == '')
	{
		alert('wstaw treść strony!');
		return false;
	}
}

function verifyContactForm()
{
	var c=0;
	
	if($F('name') != '')c++;
	if($F('email') != '')c++;
	if($F('message') != '')c++;
	if($F('tel') != '')c++;
	
	if(c<4)
	{
		alert('Wszystkie pola formularza muszą być wypełnione');
		return false;
	}
	else
	{
		$('form').submit();
	}
}
