var IE  = (document.all) ? true : false;                      // ie4+

function dialog(url, _width, _height) {
	if(IE) window.event.cancelBubble = true; //Kad neeitu i ta linka kuri paspaudeme
	if(IE) window.event.returnValue = false; //paspaudej - ir nieko negrazino tau!!!
	var pav;
	nr_temp=Math.floor(Math.random()*1000);
	if (arguments[3]) pav=arguments[3];
		else pav=nr_temp;
	if (arguments[4]) scrollbar="yes";
		else scrollbar="no";
	window.open(url, pav, "top=100, left=100, width="+_width+", height="+_height+", menubar=no, resizeable=yes, scrollbars="+scrollbar+", staus=1, toolbar=no, location=no, directories=no");
}

function get_width() {
	return Math.max(Math.round(document.body.clientWidth/2), 390) - 176;
}

function get_menu(obj) {
	var temp_obj=obj;
	for (i=0; i<3; i++)
		temp_obj = (IE) ? temp_obj.parentElement : temp_obj.parentNode;
	return temp_obj.offsetLeft + Math.max(Math.round(document.body.clientWidth/2)-394, -5);
}

function get_height() {
	return Math.max(Math.round(document.body.clientHeight/2), 280) - 195;
}

///// menu

var im_src=new Array('arrow','arrow.over','arrow.menu','arrow.menu.over', 'plus.gif', 'minus.gif', 'bullet.gif');
var im=new Array();
for (i=0; i<im.length; i++) {
	im[i]=new Image();
	im[i].src="images/"+im_src[i]+".gif";
}

var last_obj = new Object();
var menu_obj = new Object();
var menu_arr = new Array();
var menu_nr=1;
var menu_top = 161;

						 //new menu   parent    naujo_nr
function menu_over(tr_obj, menu_name, obj_name, temp_nr) {
	var x, y, tr_obj, temp, offset_x=(IE) ? 0: 5;
	if (IE)	event.cancelBubble=true; //!!
	menu_obj = document_all("menu_"+menu_name);
		menu_kill(temp_nr);
		menu_arr[temp_nr]=menu_obj;
	tr_obj.className="menu_tr_over";
	if (arguments.length<5) { //From sub menu
		last_obj = document_all("menu_"+obj_name);
		if (IE) x = last_obj.style.pixelLeft  + last_obj.clientWidth + offset_x;
		else {
			temp=last_obj.style.left;
			x=temp.substr(0, temp.length-2)*1 + tr_obj.offsetWidth + offset_x + "px";//last_obj.style.width;
		}
		if (IE) y = last_obj.style.pixelTop   + tr_obj.offsetTop;
		else {
			temp=last_obj.style.top;
			y=temp.substr(0, temp.length-2)*1 + tr_obj.offsetTop + "px";
		}
	} else { //From main menu
		x = arguments[4];
		y = menu_top + tr_obj.offsetTop;
	}
	if (is_object(menu_obj)) { //draw menu
		menu_obj.style.left=x;
		menu_obj.style.top =parseInt(y)-10+"px";
	}
}


function menu_make (menu_name) { //shot name
	var all="", arrow, tr_over, arr, row;
		var re = new RegExp("([_]+)", "g");
			var temp_len = menu_name.replace(re, "");
		temp_nr = menu_name.length - temp_len.length; //kiek "_";
	all ="<DIV ID=\"menu_"+menu_name+"\" class=air onmouseover=\"event.cancelBubble=true;\" width=1 height=1>";  //ID=>IE,
	all+="<TABLE cellpadding=0 cellspacing=0><TR><TD valign=top><IMG src=\"images/spacer.gif\"  width=5 height=29></TD><TD>";
	all+="<TABLE cellpadding=0 cellspacing=0 style='border: 0px solid #013364; background-color: #288EC1;'>";
	all+=row="<TR class=menu_tr height=10><TD colspan=3></TD></TR>";
	for (var i=1; i<arguments.length; i++) {
		arr=arguments[i];
		if (!arr[2]) arr[2]=arrow="";
				else arrow="class=arrow_menu";
		tr_over="onmouseover=\"menu_over(this, '"+arr[2]+"','"+menu_name+"',"+(temp_nr+1)+");\"";
		//all+="<TR class=menu_tr height=2><TD colspan=3></TD></TR>";
		all+="<TR ID=tr_"+arr[2]+" "+tr_over+" class=menu_tr onmouseout=\"menu_out(this);\" onclick=\"menu_click('"+arr[1]+"');\" height=19><TD width=15></TD><TD>"+arr[0]+"</TD><TD width=22 "+arrow+"></TD></TR>";
		//all+="<TR class=menu_tr height=2><TD colspan=3></TD></TR>";
	}
	all+=row;
	all+="</TABLE>";
	all+="</TD></TR></TABLE>";
	all+="</DIV>";
	document.writeln(all);
}


function menu_kill(temp_nr, evn) {
	if (!IE && !temp_nr && (evn.target.tagName=="TD" || evn.target.tagName=="A")) //for body
			return false; //panasiai kaip cancelBubble
	if (temp_nr>10) temp_nr=1;
	for (var i=temp_nr; i<=menu_nr; i++) {
		temp_obj = menu_arr[i];
		if (is_object(temp_obj)) {
			temp_obj.style.left="-1000px";
			menu_arr[i].last_tr.className="menu_tr";
		}
	}
	menu_nr=temp_nr; //sumaziname menu_nr, kad greiciau veiktu po to
}


function menu_out (tr_obj) {
	///2004-07-29
	if (is_object(menu_arr[menu_nr]))
		 menu_arr[menu_nr].last_tr=tr_obj; //nuoroda i paskutini pazymeta "tr"
	else
		 tr_obj.className="menu_tr";
}


function menu_click(temp_href) {
	window.document.location.href=temp_href;
}


function document_all(temp_id) {
	return (IE) ? document.all[temp_id]: document.getElementById(temp_id);
}


function is_object(temp_obj) {
	return (temp_obj=="[object]" || temp_obj=="[object HTMLDivElement]");
}


//////// for resizing iframe height /////////
function adjustIFrameSize (iframeWindow) {
	if (iframeWindow.document.height) {
		var iframeElement = parent.document.getElementById(iframeWindow.name);
		iframeElement.style.height = iframeWindow.document.height + 'px';
//		iframeElement.style.width = iframeWindow.document.width + 'px';
	}
	else if (document.all) {
		var iframeElement = parent.document.all[iframeWindow.name];
		if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') {
			iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 3 + 'px';
//			iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
		}
		else {
			iframeElement.style.height = iframeWindow.document.body.scrollHeight + 3 + 'px';
//			iframeElement.style.width = iframeWindow.document.body.scrollWidth + 5 + 'px';
		}
  	}
}


function valid_email(){
	if(checkMail(document.forms['news'].elements['email'].value)) 
		document.forms['news'].submit();
	else
		alert('Neteisingai įvestas el. paštas.');
}

function checkMail(x)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function checkZmoniuSkaicius(count, obj){
	var x = count.value;
	if(valid_number(x)){
		if(x>kedes_list[obj.options[obj.selectedIndex].value]){
			alert('Žmonių skaičius per didelis');
			count.value = '';
		}else{
			return true;
		}
	}else{
		alert('Neteisingas skaičius');
		count.value = '';
	}
	return false;
}

function valid_number(x)
{
	var filter  = /^([0-9])*$/;
	if (filter.test(x)) return true;
	else return false;
}

function inputFocus(field){
	if(document.getElementById(field.name + '_').value != 1) 
		field.value='';
}

function inputBlur(field, text){
	if(document.getElementById(field.name + '_').value != 1 && field.value != '') 
		document.getElementById(field.name + '_').value = 1;
	if(document.getElementById(field.name + '_').value != 1) 
		field.value = text;
}

function show_hide(id){
	var obj = document.getElementById(id);
	if(obj.style.display=='none'){
		//obj.style.visibility='visible';
		//obj.style.position='static';
		obj.style.display = 'block';
	}else{
		//obj.style.visibility='hidden';
		//obj.style.position='absolute';
		obj.style.display = 'none';
	}
	
}

function selectCalendarDay(day_id){
	
	var Iobj = document.getElementById('day_' + day_id);
	var Aobj = document.getElementById('day_id_' + day_id);
	if(Iobj.value==1){
		Aobj.className = 'passive';//style.background = '#FFFFFF';
		Iobj.value = 0;
	}else{
		Aobj.className = 'active';//style.background = '#55DD55';
		Iobj.value = 1;
	}
	
}

function selectDateTime(day_id){

	var Iobj = document.getElementById('time_' + day_id);
	var Aobj = document.getElementById('time_id_' + day_id);
	if(Iobj.value==1){
		Aobj.className = 'passive';
		Iobj.value = 0;
	}else{
		Aobj.className = 'active';
		Iobj.value = 1;
	}

}
