var ddClicked = false;

function show_cal(el) {

	cal_obj = new RichCalendar();
	cal_obj.user_onchange_handler = data_pasirinkta;
	cal_obj.show_at_element(el, "adj_right-bottom");
}

// Vartotojui pasirinkus datą, užrašome ją į atitinkamą elementą
function data_pasirinkta(cal, object_code) {
	if (object_code == 'day') {
		var data = cal.get_formatted_date(); 
		document.getElementById(cal.value_el.id+'_val').value = data;
		document.getElementById(cal.value_el.id+'_vis').innerHTML = data;
		cal.hide();
	}
}

function 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 showDD(el){
	ddClicked = true;
	if (o = document.getElementById('rezervacijosDD')){
		pos = findPos(el);
		o.style.left = pos[0]+'px';
		o.style.top = pos[1]+20+'px';
		o.style.display = 'block';			
	}
}

function setVal(el, act_id){
	if (o = document.getElementById('src_rezervavimai_vis')){
		o.innerHTML = el.firstChild.innerHTML;
	}
	if (o = document.getElementById('rezervavimai_val')){
		o.value = act_id;
	}	
}

 //-------- nauji ------------------
 function showSel(el){
	ddClicked = true;
	
	if( el.getAttribute("id") ){
	
	
		var idList;
		idList = el.getAttribute("id") ;
		
		arrayElementFalse[idList+'_list']= true;
		
		if (o = document.getElementById(idList+'_list')){
			o.style.width = (parseInt(el.style.width))+'px';
			pos = findPos(el);
			o.style.left = pos[0]+'px';
			o.style.top = pos[1]+20+'px';
			o.style.display = 'block';	
		}
	}
	
	return false;
}
 function setValue(el,idInput,InputVal){
 	if (a = document.getElementById( idInput + '_vis' )){
		a.innerHTML = el.innerHTML;
	}
 	if (o = document.getElementById( idInput + '_val' )){
		o.value = InputVal;
	}
	/*if(e = document.getElementById( idInput + '_list')){	
		if (e.style.display == 'block'){
			e.style.display = 'none';
		}
	} */
	return false;
 }
 
 
 
 
var sm1;
var sm2;
var sm3;


function chclass_sm(thisid){

	sm1 = document.getElementById('sm1').className;
	sm2 = document.getElementById('sm2').className;
	sm3 = document.getElementById('sm3').className;
	
	document.getElementById('sm1').className = 'mn_elem passive' ;
	document.getElementById('sm2').className = 'mn_elem passive' ;
	document.getElementById('sm3').className = 'mn_elem passive' ;
	
	
	document.getElementById(thisid).className = 'mn_elem active' ;
}


function return_class(){
	document.getElementById('sm1').className = sm1 ;
	document.getElementById('sm2').className = sm2 ;
	document.getElementById('sm3').className = sm3 ;
}
 
 
 
//------------- /-------------------------------

 //-------- nauji ------------------
 function showSel(el){
	ddClicked = true;
	
	if( el.getAttribute("id") ){
		
		var idList;
		idList = el.getAttribute("id") ;
		
//		arrayElementFalse[idList+'_list']= true;
		
		if (o = document.getElementById(idList+'_list')){
			o.style.width = (parseInt(el.style.width))+'px';
			pos = findPos(el);
			o.style.left = pos[0]+'px';
			o.style.top = pos[1]+20+'px';
			o.style.display = 'block';	
		}
	}
	
	return false;
 }

 function setValue(el,idInput,InputVal){
 	if (a = document.getElementById( idInput + '_vis' )){
		a.innerHTML = el.innerHTML;
	}
 	if (o = document.getElementById( idInput + '_val' )){
		o.value = InputVal;
	}
	if(e = document.getElementById( idInput + '_list')){	
		if (e.style.display == 'block'){
			e.style.display = 'none';
		}
	} 
	return false;
 }

// foto

// ----- foto funkcijos -----

function confirmation(textas,to) {
	var answer = confirm(textas);
	if (answer){
		window.location = to;
	}
	
}

function show_foto(url_foto,titl){
		var urlf  = escape(url_foto);
		//var ttile = escape(titl);
	window.open( 'foto_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 show_staliukai( defico, nr ){

	
	document.defico.src = icoarr[nr].src;
	//document.defico.onclick = icoarr[nr].ock;
	document.getElementById('defico').onclick = function ns(){  show_foto( icoarr[nr].ock , ' ')   ; }
	//alert(icoarr[nr].ock);
	return false;
}

	var p_right = new Image(); 
	p_right.src = "images/pagination_right.gif";
	var p_left = new Image(); 
	p_left.src = "images/pagination_left.gif";
	var p_empty_pil = new Image(); 
	p_empty_pil.src = "images/pagination_empty_pil.gif"; 
	
	var cnrl = -1;
	var cnrr = 1;
	var timerID = false;
	
function bodyonload(){
	if(document.getElementById('defico')){
		//clicrod('right');
	}
}
	
function clicrod(lr){
	if(timerID){	
		//clearTimeout(timerID);
	}
	if(lr=='left'){
	if(cnrl==-1){
		cnrl = icom.length - 1;
	}
		clicknr( cnrl );
	}else{
		clicknr( cnrr );
	}
	//timerID = setTimeout("clicrod('"+lr+"')",1000);
	return false;
}
	
function clicknr( cnr ){
	show_staliukai( 'defico', cnr );

	for(kyc in icom){
		if(cnr == kyc){
			document.getElementById('pnr'+kyc).className = 'pusl-nr-o';
		}else{
			document.getElementById('pnr'+kyc).className = 'pusl-nr';
		}
	}
	//alert(cnr+' != '+kyc);
	
	if( cnr == kyc ){
		cnrr = 0;
		document.rright.src = p_right.src ; //p_empty_pil.src ;
	}else{
		cnrr = (cnr+1);
		document.rright.src = p_right.src ;
	}
	//alert(cnr+' == '+kyc+' ; l:'+cnrl +' r:'+cnrr);
	if(cnr > 0){
		document.rleft.src = p_left.src ;
		cnrl = (cnr - 1);
	}else{
		cnrl = kyc;
		document.rleft.src = p_left.src ; //p_empty_pil.src ;
	}
	
	return false;
}