function return_date(days){
	var today=new Date()
	today.setDate(today.getDate()+days) //today now is set to be 3 days into the future
	var year=today.getFullYear();
	var month=today.getMonth()+1;
	if(month<10) month = '0' + month;
	var day=today.getDate();
	if( day<10 ) day = '0' + day;
	
	return year + '-' + month +'-'+ day;
}

function matomasNematomas( divid ){
	if( document.getElementById(divid) ){
		var clname = document.getElementById(divid).className ;
		if( clname == 'nematomas' ){
			clname = 'matomas';
		}else{
			clname = 'nematomas';
		}
		document.getElementById(divid).className = clname ; 
	}
	return false;
}

function clickTab(idvalue){
	var actTabId = document.getElementById('act_tab').value ;
	if( actTabId != idvalue ){
		if( document.getElementById(actTabId) ){
			document.getElementById(actTabId).className = 'block-tab' ;
			if( document.getElementById('div_'+actTabId) ){
				document.getElementById('div_'+actTabId).className = 'nematomas';
			}
		}
		if( document.getElementById(idvalue) ){
			document.getElementById(idvalue).className = 'block-tab-o' ;
			if( document.getElementById('div_'+idvalue) ){
				document.getElementById('div_'+idvalue).className = 'matomas';
			}
		}
		document.getElementById('act_tab').value = idvalue ;
	}

	return false;
}

function setFormDisable( fi, strDisable, strMatomas ){
	;
	var arrDisable = strDisable.split(',');
	var arrMatomas = strMatomas.split(',');
	
	for(var key in arrDisable){
	
		if( document.getElementById( arrDisable[key] ) ){
		
			document.getElementById( arrDisable[key] ).disabled = (fi==1)?false:true ;
			document.getElementById( arrDisable[key] ).className = (fi==1)?'class-input':'class-input-disable' ;
			
		}
	}
	for(var keym in arrMatomas){
		if( document.getElementById( arrMatomas[keym] ) ){
			document.getElementById( arrMatomas[keym] ).className = (fi==1)?'form-left':'form-left-disable' ;
		}
	}
	
	return false;
}
var triddoc = new Array();
function return_backgr(obj, setnr , doc){
	doc = typeof(doc) != 'undefined' ? doc : 'doc';

	var bcolor;
	if(setnr==1){
		bcolor = '#FFFFFF';
	}else{
		bcolor = '#F2F3F5';
	}

	if( obj.getAttribute('id') == triddoc[doc] ){
		return false;
	}

	var objtd = obj.getElementsByTagName('td');
	if(objtd){
		for (var i=0; i<objtd.length; i++) {
			objtd[i].style.backgroundColor = bcolor ;

		}
	}
	var objdiv = obj.getElementsByTagName('div');
	if(objdiv){
		for (var i=0; i<objdiv.length; i++) {
		//	objdiv[i].style.backgroundColor = bcolor ;
		}
	}
	return false;
}

function ch_backgr(obj, setnr, doc){
	doc = typeof(doc) != 'undefined' ? doc : 'doc';
	if(setnr==1){
		var bcolor = '#E6E7EB';
	}else{
		var bcolor = '#E2E3E7';
	}
	//alert(obj.getAttribute('id') +' =='+ triddoc[doc] );
	if( obj.getAttribute('id') == triddoc[doc] ){
		return false;
	}
	if( obj.tagName =='TR' ){
		var objtd = obj.getElementsByTagName('td');
		if(objtd){
			for (var i=0; i<objtd.length; i++) {
				objtd[i].style.backgroundColor = bcolor;
			}
		}
	}else if(obj.tagName =='DIV'){
		var objdiv = obj.getElementsByTagName('div');
		if(objdiv){
			for (var i=0; i<objdiv.length; i++) {
				//objdiv[i].style.backgroundColor = bcolor;
			}
		}
	}
	return false;
}




function input_value(obid,values){
	if( document.getElementById(obid) ){
		document.getElementById(obid).value =values;
	}else{
		alert( 'nerastas objektas '+document.getElementById(obid) );
	}

}
function showpasswd(newpasswd){

	if( document.getElementById('showpasswd') ){
		
		if( document.getElementById('showpasswd').innerHTML == '******' ){
		
			document.getElementById('showpasswd').innerHTML = newpasswd;
			document.getElementById('butonpasswd').innerHTML = '(Paslėpti)';
			
		}else{
		
			document.getElementById('showpasswd').innerHTML = '******';
			document.getElementById('butonpasswd').innerHTML = '(Rodyti)';
		}
	
	}
}



function show_foto(url_foto,titl){
		var urlf  = escape(url_foto);
		//var ttile = escape(titl);
	window.open( 'show.php?furl='+urlf+'&titl='+titl ,'image','width=800,height=600,scrollbars=no,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=20');

}
function popup(url,w,h){ 
 	w = typeof(w) != 'undefined' ? w : 1000;
 	h = typeof(h) != 'undefined' ? h : 800;
 	day = new Date();
 	id = day.getTime();
	newwin = window.open( url ,'image'+id,'width='+w+',height='+h+',scrollbars=yes,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=20');
	if (window.focus) {newwin.focus()}
}


function confirmation(textas,to) {
	var answer = confirm(textas);
	if (answer){
		window.location = to;
	}
	
}

function visiSelect(thisobj,texts){
	var taip = confirm(texts);
	if (taip){
	var seldabar = thisobj.value;
		var objSel = document.getElementById('forma').getElementsByTagName('SELECT');
		for (var ise=0; ise<objSel.length; ise++){
			var sel = objSel[ise];
			getid = sel.getAttribute('id');
			if(  eregas( "^selpt", getid ) ){
				sel.value = seldabar;
			}
		}
	}
}

function validRegEx(regepr,inputid){
	var tf = true;
	if(regepr!=''){
	
		if(arrEreg[regepr]){
			ereg	= arrEreg[regepr];
		}else{
			ereg = regepr;
		}
		
		var re = new RegExp(ereg);
		if ( !re.test( document.getElementById(inputid).value ) ){ 
			
			tf = false;
			if (document.getElementById(inputid).value == ""){ 
				document.getElementById(inputid).style.background = '#FFFFFF'; 
				tf = true;
			}else{
				tf = false;
				alert(Klaida_iv_duom);
				document.getElementById(inputid).style.background = '#FFB7B7'; 
				document.forma.aaa.focus();
			}
			
		}else{
			document.getElementById(inputid).style.background = '#FFFFFF';
			tf = true;
		}
		
	}
	return tf;
		
}
/*
function openMenu(idg,idm){
	window.location.href = '?m='+menu[idg][idm];
}
 */

//---------------------------------------
function lenth_textarea_span(obj, maxsymbol){

	var textt;
  	eil = maxsymbol - obj.value.length; 	
  	if (eil < 1 ){   
		textt = obj.value.substr(0,maxsymbol);  
		obj.value =  textt;    
		if (eil <= 0) eil = 0 ; 
   	} 

	var idobj = obj.getAttribute('id');
	if( document.getElementById('count_'+idobj) ){
	var i=document.getElementById('count_'+idobj);
		i.innerHTML= eil; 
		
	}
}
  
function chclass1(thisid,trclass){
	document.getElementById(thisid).className = trclass ;
}


function chclass(thisid,toclass,thisid2,toclass2){
	document.getElementById(thisid).className = toclass ;
	document.getElementById(thisid2).className = toclass2 ;
}





    function CheckLastNumber(asm_kodas)
    {
        var chSum = 0;
                
        for (var i=1;i<=10;i++)
        {
            if (i < 10)
            {
               chSum += asm_kodas.substr(i-1,1)*i;
            }
            else
            {
               chSum += asm_kodas.substr(i-1,1)*1;
            }
        }
        chSum = chSum % 11;
        if (chSum == 10)
        {
            chSum = 0;
            for (var i=1;i<=10;i++)
            {
                if (i < 8)
                {
                    chSum += asm_kodas.substr(i-1,1)*(i+2);
                }
                else
                {
                    chSum += asm_kodas.substr(i-1,1)*(i-7);
                }
            }

            chSum = chSum % 11;
            if (chSum == 10)
            {
                chSum = 0;
            }
        }
        
        return (chSum == asm_kodas.charAt(10));
    }

function gerasAsmKodas(sis){
    var asm_kodas = sis.value;
	if( CheckLastNumber(asm_kodas) ){
		
		sis.style.backgroundColor = '#FFFFFF';
	}else{
		sis.style.backgroundColor = '#FF5B5B';
		alert('Klaida: neteisingas asmens kodas');
	}
	return false;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function eregas( pattern, str ){
	var res = new RegExp(pattern);
	if (res.test(str) ){ 
		return true;
	}else{
		return false;
	}
}









//////////////// kalendorius ////////////////
var ds_i_date = new Date();
var ds_c_month = ds_i_date.getMonth() + 1;
var ds_c_year = ds_i_date.getFullYear();
var ds_c_day = ds_i_date.getDate();

// Get Element By Id
function ds_getel(id) {
	return document.getElementById(id);
}

// Get the left and the top of the element.
function ds_getleft(el) {
	var tmp = el.offsetLeft;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetLeft;
		el = el.offsetParent;
	}
	return tmp;
}
function ds_gettop(el) {
	var tmp = el.offsetTop;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetTop;
		el = el.offsetParent;
	}
	return tmp;
}

// Output Element
var ds_oe = ds_getel('ds_calclass');
// Container
var ds_ce = ds_getel('ds_conclass');

// Output Buffering
var ds_ob = '';
function ds_ob_clean() {
	ds_ob = '';
}
function ds_ob_flush() {
	ds_oe.innerHTML = ds_ob;
	ds_ob_clean();
}
function ds_echo(t) {
	ds_ob += t;
}

var ds_element; // Text Element...

var ds_monthnames = [
'Sausis', 'Vasaris', 'Kovas', 'Balandis', 'Gegužė', 'Birželis',
'Liepa', 'Rugpjūtis', 'Rugsėjis', 'Spalis', 'Lapkritis', 'Gruodis'
]; // You can translate it for your language.

var ds_daynames = [
 'Pir', 'Anr', 'Tre', 'Ket', 'Pen', 'Šeš','Sek'
]; // You can translate it for your language.

// Calendar template
function ds_template_main_above(t) {
	return '<table cellpadding="1" cellspacing="1" class="ds_tbl">'
	     + '<tr id="cal_tr_head">'
		 + '<td class="ds_head" style="cursor: pointer;font-size:10px;" onclick="ds_py();return false;">&lt;&lt;</td>'
		 + '<td class="ds_head" style="cursor: pointer;font-size:10px;" onclick="ds_pm();return false;">&lt;</td>'
		 + '<td class="ds_head" style="cursor: pointer;font-size:10px;" onclick="ds_now();return false;" colspan="3" >šendien</td>'
		 + '<td class="ds_head" style="cursor: pointer;font-size:10px;" onclick="ds_nm();return false;">&gt;</td>'
		 + '<td class="ds_head" style="cursor: pointer;font-size:10px;" onclick="ds_ny();return false;">&gt;&gt;</td>'
		 + '</tr>'
	     + '<tr>'
		 + '<td colspan="7" class="ds_head2">' + t + '</td>'
		 + '</tr>'
		 + '<tr>';
}

function ds_template_day_row(t) {
	var scolor;
	if( t=='Šeš' || t=='Sek' ){
		scolor = 'style="color:#8C0000;"';
	}else{
		scolor = '';
	}
	return '<td class="ds_subhead" '+scolor+'>' + t + '</td>';
	// Define width in CSS, XHTML 1.0 Strict doesn't have width property for it.
}

function ds_template_new_week() {
	return '</tr><tr>';
}

function ds_template_blank_cell(colspan) {
	return '<td colspan="' + colspan + '"></td>'
}

function ds_template_day(d, m, y) {
	var colorsav;
	var my_date = new Date();
	my_month = my_date.getMonth() + 1;
	my_year = my_date.getFullYear();
	my_day = my_date.getDate();

	var gDate=new Date();
	gDate.setFullYear(y,(m-1),d);
	var sday = gDate.getDay();
	if(sday==6||sday==0){
		colorsav = 'color:#8C0000;';
	}else{
		colorsav = '';
	}


	var strday;
	//window.status = d+'=='+ds_c_day+'&'+m+'=='+ds_c_month+'&'+y+'=='+ds_c_year;
	if( d==my_day && m==my_month && y==my_year ){ //sendien
		strday =  '<span style="font-weight:bold;color:blue;">' + d + '</span>';
	}else{
		strday =  '' + d + '';
	}

	//window.status = d+'=='+ds_c_day+'&'+m+'=='+ds_c_month+'&'+y+'=='+ds_c_year;

	if(d==sel_day && m==sel_month && y==sel_year){
		return '<td class="ds_cell" style="border:1px solid #303030;' + colorsav + '" onclick="ds_onclick(' + d + ',' + m + ',' + y + ')">' + strday + '</td>';
	}else{
		return '<td class="ds_cell" style="' + colorsav + '" onclick="ds_onclick(' + d + ',' + m + ',' + y + ')">' + strday + '</td>';
	}
	// Define width the day row.
}

function ds_template_main_below() {
	return '</tr>'
	     + '</table><div align="right"><a class="trinti" href=" " onclick="emtyCal();return false;">trinti datą</a></div>';
}
function emtyCal(){

	if( calobj ){
		calobj.value='';
		
			deleteNode(divcal);
		
	}
	return false;
}
// This one draws calendar...
function ds_draw_calendar(m, y) {
	// First clean the output buffer.
	ds_ob_clean();
	// Here we go, do the header
	ds_echo (ds_template_main_above(ds_monthnames[m - 1] + ' ' + y));
	for (i = 0; i < 7; i ++) {
		ds_echo (ds_template_day_row(ds_daynames[i]));
	}
	// Make a date object.
	var ds_dc_date = new Date();
	ds_dc_date.setMonth(m - 1);
	ds_dc_date.setFullYear(y);
	ds_dc_date.setDate(1);
	if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
		days = 31;
	} else if (m == 4 || m == 6 || m == 9 || m == 11) {
		days = 30;
	} else {
		days = (y % 4 == 0) ? 29 : 28;
	}
	var first_day = ds_dc_date.getDay();

	var first_loop = 1;
	// Start the first week
	ds_echo (ds_template_new_week());
	// If sunday is not the first day of the month, make a blank cell...
	if (first_day != 1) {

		if( first_day==0){
			colspa = 6;
		}else{
			colspa = first_day-1
		}
		ds_echo (ds_template_blank_cell( colspa ));
	}
	var j = first_day;
	for (i = 0; i < days; i ++) {
		// Today is sunday, make a new week.
		// If this sunday is the first day of the month,
		// we've made a new row for you already.
		if (j == 1 && !first_loop) {
			// New week!!
			ds_echo (ds_template_new_week());
		}
		// Make a row of that day!

		ds_echo (ds_template_day(i + 1, m, y));
		// This is not first loop anymore...
		first_loop = 0;
		// What is the next day?
		j ++;
		j %= 7;
	}
	// Do the footer
	ds_echo (ds_template_main_below());
	calbody.innerHTML = ds_ob;
	// And let's display..
	//ds_ob_flush();
	// Scroll it into view.
	//ds_ce.scrollIntoView();


	//ds_ob_clean();

}

// A function to show the calendar.
// When user click on the date, it will set the content of t.
/*function ds_sh(t) {
	// Set the element to set...
	ds_element = t;
	// Make a new date, and set the current month and year.
	var ds_sh_date = new Date();
	ds_c_month = ds_sh_date.getMonth() + 1;
	ds_c_year = ds_sh_date.getFullYear();
	// Draw the calendar
	ds_draw_calendar(ds_c_month, ds_c_year);
	// To change the position properly, we must show it first.
	ds_ce.style.display = '';
	// Move the calendar container!
	the_left = ds_getleft(t);
	the_top = ds_gettop(t) + t.offsetHeight;
	ds_ce.style.left = the_left + 'px';
	ds_ce.style.top = the_top + 'px';
	// Scroll it into view.
	ds_ce.scrollIntoView();
} */

// Hide the calendar.
/*function ds_hi() {
	ds_ce.style.display = 'none';
} */

// Moves to the next month...
function ds_nm() {
 senasNemTrue = false;
	// Increase the current month.
	ds_c_month ++;
	// We have passed December, let's go to the next year.
	// Increase the current year, and set the current month to January.
	if (ds_c_month > 12) {
		ds_c_month = 1;
		ds_c_year++;
	}
	// Redraw the calendar.
	ds_draw_calendar(ds_c_month, ds_c_year);
}
function ds_now(){
 senasNemTrue = false;
	var ds_sh_date = new Date();
		ds_c_month = ds_sh_date.getMonth() + 1;
		ds_c_year = ds_sh_date.getFullYear();
	ds_draw_calendar(ds_c_month, ds_c_year);
}
// Moves to the previous month...
function ds_pm() {
 	senasNemTrue = false;
	ds_c_month = ds_c_month - 1; // Can't use dash-dash here, it will make the page invalid.
	// We have passed January, let's go back to the previous year.
	// Decrease the current year, and set the current month to December.
	if (ds_c_month < 1) {
		ds_c_month = 12;
		ds_c_year = ds_c_year - 1; // Can't use dash-dash here, it will make the page invalid.
	}
	// Redraw the calendar.
	ds_draw_calendar(ds_c_month, ds_c_year);
}

// Moves to the next year...
function ds_ny() {
 	senasNemTrue = false;
	// Increase the current year.
	ds_c_year++;
	// Redraw the calendar.
	ds_draw_calendar(ds_c_month, ds_c_year);
}

// Moves to the previous year...
function ds_py() {

	// Decrease the current year.
	 senasNemTrue = false;
	ds_c_year = ds_c_year - 1; // Can't use dash-dash here, it will make the page invalid.
	
	// Redraw the calendar.
	ds_draw_calendar(ds_c_month, ds_c_year);
	//this.onclick=function (){
	//	return false;
	//}
	//alert(2);
	return false;
}

// Format the date to output.
function ds_format_date(d, m, y) {
	// 2 digits month.
	m2 = '00' + m;
	m2 = m2.substr(m2.length - 2);
	// 2 digits day.
	d2 = '00' + d;
	d2 = d2.substr(d2.length - 2);
	// YYYY-MM-DD
	return y + '-' + m2 + '-' + d2;
}

// When the user clicks the day.
function ds_onclick(d, m, y) {
	if( calobj && calobj.tagName=='INPUT' ){
		calobj.value = ds_format_date(d, m, y);
	}else{
		location.href = '?dnew='+y+'-'+m+'-'+d;
	}
	//deleteNode( divcal );
	divcal.className = 'cal-nera';
}

// And here is the end.

// ]]> -->
function selectYNcal( obj , idd ){
	if( document.getElementById(idd) ){

		senasNematomas( idd );
		clearTimeout(st);
		if( document.getElementById(idd).className == 'cal-nera' ){
			document.getElementById(idd).className = 'cal-yra';

			st = setTimeout('senasNematomas(\'docOnclick\')', timeOutSelect);

			var pos = fjs_findPos( obj );
			document.getElementById(idd).style.top = pos[1]+19;
			document.getElementById(idd).style.left = pos[0];

			kalendorius(obj,'day',idd);
		}else{
			document.getElementById(idd).className = 'cal-nera';
		}
	}
	return false;
}

 function fjs_findPos( obj ){
	var pos = Array(0,0);

	if (!obj) return pos;

	while (obj) {
		if (obj.currentStyle) {
			if (obj.currentStyle.position == 'absolute') break;
		} else {
			if (document.defaultView.getComputedStyle(obj, '').getPropertyValue('position') == 'absolute') break;
		}

		var is_div = obj.tagName.toUpperCase() == "DIV" ? true : false;
		pos[0] += obj.offsetLeft - (is_div?obj.scrollLeft:0);
		pos[1] += obj.offsetTop - (is_div?obj.scrollTop:0);

		obj = obj.offsetParent;
	}
	if (navigator.appName=="Microsoft Internet Explorer"){
		//pos[0] = pos[0]+1;
	}


	return pos;
}
function findPos( obj ){
	return fjs_findPos( obj ) ;
}

function draw_time(objj){
	var ob_time = '<table cellpadding="1" cellspacing="3" class="ds_tbl" width="100%"><tbody>'
	     + '<tr><td class="ds_cell" onclick="wrtime(this);">08:00</td><td class="ds_cell" onclick="wrtime(this);">12:00</td><td class="ds_cell" onclick="wrtime(this);">16:00</td></tr>'
	     + '<tr><td class="ds_cell" onclick="wrtime(this);">08:30</td><td class="ds_cell" onclick="wrtime(this);">12:30</td><td class="ds_cell" onclick="wrtime(this);">16:30</td></tr>'
	     + '<tr><td class="ds_cell" onclick="wrtime(this);">09:00</td><td class="ds_cell" onclick="wrtime(this);">13:00</td><td class="ds_cell" onclick="wrtime(this);">17:00</td></tr>'
	     + '<tr><td class="ds_cell" onclick="wrtime(this);">09:30</td><td class="ds_cell" onclick="wrtime(this);">13:30</td><td class="ds_cell" onclick="wrtime(this);">17:30</td></tr>'
	     + '<tr><td class="ds_cell" onclick="wrtime(this);">10:00</td><td class="ds_cell" onclick="wrtime(this);">14:00</td><td class="ds_cell" onclick="wrtime(this);">18:00</td></tr>'
	     + '<tr><td class="ds_cell" onclick="wrtime(this);">10:30</td><td class="ds_cell" onclick="wrtime(this);">14:30</td><td class="ds_cell" onclick="wrtime(this);">18:30</td></tr>'
	     + '<tr><td class="ds_cell" onclick="wrtime(this);">11:00</td><td class="ds_cell" onclick="wrtime(this);">15:00</td><td class="ds_cell" onclick="wrtime(this);">19:00</td></tr>'
	     + '<tr><td class="ds_cell" onclick="wrtime(this);">11:30</td><td class="ds_cell" onclick="wrtime(this);">15:30</td><td class="ds_cell" onclick="wrtime(this);">19:30</td></tr>'
	     + '</tbody></table>';
	
	objj.innerHTML = ob_time;
	objj.onclick = function (){
		removeNode( this );
	}

}

var divcal;
var calobj;
var calbody;
var sel_year= 0;
var sel_month = 0;
var sel_day = 0;
function kalendorius(obj,men,idd){
		 idd = typeof(idd) != 'undefined' ? idd : 'cal_data'  ;
		sel_year = 0;
		sel_month = 0;
		sel_day = 0;
		ds_c_month = 0;
		ds_c_year = 0;
		ds_c_day = 0;
		
		if( typeof(obj)=='object' ){
			calobj = obj;
		}else{
			calobj = document.getElementById(obj) ;
		}
		 
	
		 if( divcal ) deleteNode(divcal);
		 divcal = document.createElement('div');
		 divcal.setAttribute('id',idd);
		 
		calobj.parentNode.appendChild(divcal);
		// document.getElementsByTagName("body")[0].appendChild(divcal);
		 
		 
		 //document.getElementById(idd);
			//divcal.setAttribute('id', 'cal_' );
//------- cal title ----------
			var divcaltitl = document.createElement('div');
				with(divcaltitl){
					className = 'cal_title';
					onclick = function(){
						deleteNode(divcal);
					}
				//	onmousedown = function (ev){
				//		if(dragObject != divcal){
				//			dragObject = divcal;
				//			mouseOffset = getMouseOffset( dragObject, ev );
							//toTop(winfname);
				//		}
				//	}
				}
			var divcalclos = document.createElement('span');
				with(divcalclos){
					innerHTML = 'X';
					onclick = function(){
						deleteNode(divcal);
					}
					
				}	
				divcaltitl.appendChild(divcalclos);
				divcal.appendChild(divcaltitl);
			calbody = document.createElement('div');
				divcal.appendChild(calbody);
				
				
			divcal.className = 'cal-yra'; 
			divcal.style.zIndex = 32767;
			if( men=='day' ){
				divcal.style.width = '160px';
			}else{
				divcal.style.width = '130px';
			}
			//divcal.style.height = '120px';
		var pos= findPos( calobj );
		//var posthis= findPos( this );
		divcal.style.left = pos[0]+102;
		divcal.style.top =  pos[1];
		
		//divcal.style.left = mousePos.x-30;ds_c_month, ds_c_year
		//divcal.style.top = mousePos.y+16;
		

		if( men=='day' ){
			var ds_sh_date = new Date();

			var dval ;
			if( calobj.value != '' ){
				dval = calobj.value.split('-')
				ds_c_month = parseInt(dval[1].replace(/^[0]+/,'') );
				ds_c_year = parseInt(dval[0]);
				
				ds_c_day = parseInt( dval[2].replace(/^[0]+/,'') );
			}

			if( ds_c_year>=1000  && ds_c_year <= 3000 ){
			 	if( ds_c_month>=1 && ds_c_month<=12 ){
			 		if( ds_c_day >=1  && ds_c_day <= 31 ){
			 			
						sel_year= ds_c_year;
						sel_month = ds_c_month;
						sel_day = ds_c_day;
						
			 		}else{

			 			ds_c_day = 1 ;

			 		}
			 	}else{
			 		ds_c_month = 1 ;
			 		ds_c_day = 1 ;
			 	}
			}else{
				ds_c_year = ds_sh_date.getFullYear();
				ds_c_month = ds_sh_date.getMonth() + 1;
				ds_c_day = ds_sh_date.getDate();
				
				
				
			}
			
// calobj.value = ds_c_year + '-' +((ds_c_month<10)?'0':'') +  ds_c_month + '-' + ((ds_c_day<10)?'0':'') + ds_c_day;
			
			
			
			
			ds_draw_calendar(ds_c_month, ds_c_year);
			
			
		}else if( men=='time' ){
			draw_time(divcal);
		}

		toTop(divcal);
		
	return false;

}










