var now_loading=false;

function submitBlockDate(id, url){
	if(document.getElementById('y'+id) && document.getElementById('m'+id) && document.getElementById('d'+id) && document.getElementById('b_events'+id) && !now_loading){
		now_loading=true;
		var obj=document.getElementById('b_events'+id);
		obj.style.opacity=0.3;
		obj.style.filter='alpha(opacity=30)';
		url=url.replace(/__y__/, document.getElementById('y'+id).value);
		url=url.replace(/__m__/, document.getElementById('m'+id).value);
		url=url.replace(/__d__/, document.getElementById('d'+id).value);
		execRequest(url, 'b_createInfo', obj);
	}
}

function b_createInfo(content, obj){
	obj.innerHTML=content.responseText;
	obj.style.opacity=1;
	obj.style.filter='alpha(opacity=100)';
	now_loading=false;
}

function b_parseYear(sdate){ //reikia
	var metai=sdate.getYear();
	metai=metai.toString();
	if(metai.length!=2){
		metai='20'+metai.substring((metai.length-2),metai.length);
	}
	else{
		metai='19'+metai;
	}
	return metai;
}

function b_select_index_by_val(obj, val){ //reikia
	for(var i=0; i<obj.options.length; i++){
		if(obj.options[i].value==val){
			obj.options[i].selected=true;
			break;
		}
	}
}

function b_rFormat(val){ //reikia
	val=val.toString();
	if(val.length<2){
		val='0'+val;
	}
	return val;
}

function fix_date(id){ //reikia
	var yel=document.getElementById('y'+id);
	var mel=document.getElementById('m'+id);
	var del=document.getElementById('d'+id);
	var yy=Math.abs(yel.value)-1900;
	var m=Math.abs(mel.value)-1;
	var d=Math.abs(del.value);
	if(d>0 && m>-1){
		var tmpd=new Date(yy, b_rFormat(m), b_rFormat(d), 01, 01, 01);
		var utm=tmpd.getTime();
		var ntmpd=new Date();
		ntmpd.setTime(utm);
		b_select_index_by_val(yel, b_parseYear(ntmpd));
		b_select_index_by_val(mel, (ntmpd.getMonth()+1));
		b_select_index_by_val(del, ntmpd.getDate());
	}
	else if(m<0){
		b_select_index_by_val(mel, 0);
		b_select_index_by_val(del, 0);
	}
	else{
		b_select_index_by_val(del, 0);
	}
}
