var onfocus;

function clearField(id){

		if(document.getElementById(id).name != onfocus){	
			document.getElementById(id).value = '';
			onfocus = document.getElementById(id).name;
		}
}
function changeField(id,ftype){
//	alert(document.getElementById(id).type);
//	document.getElementById(id).type = ftype;
	


//	alert(document.getElementById(id).type);
}
function checkFiled(id,fvalue){
	if(document.getElementById(id).value.length==0){
		document.getElementById(id).value = fvalue;
		
	}
}

function log(){
	
	if(keycode==13){
		onfocus = 0;
		document.getElementById('log_form').submit();
	}
	return false;
}


function setSelected(id){
	if(document.getElementById(id))
	document.getElementById(id).checked = true;
	return false;
}

var sRegion = '';
function addRegion(sclass, inputclass, selectclass){
	
	if(inputclass == null) inputclass = 'small_input';
	if(selectclass == null) selectclass = 'smaller_select';
	if(document.getElementById('region_label'))
		if(document.getElementById('region_label').style.color=='#ff0000') var color = ' style="color:red"';

	if(document.getElementById('country').value=='Polska'){
		
	var code = '<label for="region" id="region_label" class="'+sclass+'" '+color+'>Województwo:</label><select name="region" id="region" class="'+selectclass+'"><option value="">---</option><option value="Dolnośląskie">Dolnośląskie</option><option value="Kujawsko-pomorskie">Kujawsko-pomorskie</option><option value="Lubelskie">Lubelskie</option><option value="Lubuskie">Lubuskie</option><option value="Łódzkie">Łódzkie</option><option value="Małopolskie">Małopolskie</option><option value="Mazowieckie">Mazowieckie</option><option value="Opolskie">Opolskie</option><option value="Podkarpackie">Podkarpackie</option><option value="Podlaskie">Podlaskie</option><option value="Pomorskie">Pomorskie</option><option value="Śląskie">Śląskie</option><option value="Świętokrzyskie">Świętokrzyskie</option><option value="Warmińsko-mazurskie">Warmińsko-mazurskie</option><option value="Wielkopolskie">Wielkopolskie</option><option value="Zachodniopomorskie">Zachodniopomorskie</option></select>';
	
	document.getElementById('region_change').innerHTML = code.replace(">"+sRegion," selected=\"selected\">"+sRegion);
	sRegion = '';
	}
	else{
		document.getElementById('region_change').innerHTML = '<label for="region" id="region_label" class="'+sclass+'" '+color+'>Województwo:</label><input id="region" value="'+sRegion+'" name="region" type="text" class="'+inputclass+'" >';
	}
	return false;
}

function detectEnter(keycode){
	if(keycode==13)
		document.log_user.submit();
}



var Today = new Date()
var snolimit = 1;
var syear = null;
var smonth = null;
var sday = null;
var ayear = 1925;
var lyear = Today.getFullYear();
var withoutnull = 0;
var month = new Array('---','styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień');
var month_num = new Array('','01','02','03','04','05','06','07','08','09','10','11','12');
function days(formname){
	var year = document.forms[formname].year.value%4;
	var month = document.forms[formname].month.value;
	var selday = parseInt(document.forms[formname].day.value);
	if(month == 2){
		if(year == 0){
			document.forms[formname].day.options[31-withoutnull] = null;
			document.forms[formname].day.options[30-withoutnull] = null;
			document.forms[formname].day.options[29-withoutnull] = new Option('29','29');
			
		} else {
			document.forms[formname].day.options[31-withoutnull] = null;
			document.forms[formname].day.options[30-withoutnull] = null;
			document.forms[formname].day.options[29-withoutnull] = null;
		}
	}
	else{
		
		 	if((month%2 == 0 && month<8) || (month%2 != 0 && month>=8)){
				document.forms[formname].day.options[29-withoutnull] = new Option('29','29');
				document.forms[formname].day.options[30-withoutnull] = new Option('30','30');
				document.forms[formname].day.options[31-withoutnull] = null;
			}
			else{
				document.forms[formname].day.options[29-withoutnull] = new Option('29','29');
				document.forms[formname].day.options[30-withoutnull] = new Option('30','30');
				document.forms[formname].day.options[31-withoutnull] = new Option('31','31');
			}
	}
	if(document.forms[formname].day.options[selday-withoutnull])
		document.forms[formname].day.options[selday-withoutnull].selected = true;
		
	
}
function makeForm(formname){
	if(document.forms[formname]){
	var i;
	if(document.forms[formname].day){
	if(withoutnull == 0) document.forms[formname].day.options[0] = new Option('---','');
	for(i=1;i<=31;i++){
		if(i<=9) document.forms[formname].day.options[i-withoutnull] = new Option('0'+i,'0'+i);
		else  document.forms[formname].day.options[i-withoutnull] = new Option(i,i);
		if(i==sday) document.forms[formname].day.options[i-withoutnull].selected = true;
	}
	}
	document.forms[formname].year.options[0] = new Option('---','');

	for(i=lyear;i>=ayear;i--){
		document.forms[formname].year.options[lyear-i+1-withoutnull] = new Option(i,i);
		if(i==syear) document.forms[formname].year.options[lyear-i+1-withoutnull].selected = true;
	}
	if(document.forms[formname].month){
	for(i=0+withoutnull;i<=12;i++){
		document.forms[formname].month.options[i-withoutnull] = new Option(month[i],month_num[i]);
		if(i==smonth) document.forms[formname].month.options[i-withoutnull].selected = true;
	}
	}
	if(snolimit==0) calendarOff();
	else if(document.forms[formname].day) days();
	snolimit = 1;
	}
}
