function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function mouse_event(obj, newClass) {
	obj.className = newClass;
}

function EnableLogin()
{
	document.getElementById("lgndiv").innerHTML="<input type='text' name='nzona_login' value='' id='logiukas' class='input_login' onBlur='DisableLogin();'>";
	setTimeout("document.getElementById('logiukas').focus();",100);
}
function DisableLogin()
{
	if (document.login_form.nzona_login.value == '') {
	document.getElementById("lgndiv").innerHTML="<input type='text' name='nzona_login' value='prisijungimo vardas' id='logiukas' class='input_login_inactive' onFocus='EnableLogin();'>";
	}
}
function EnablePassword()
{
	document.getElementById("pswdiv").innerHTML="<input type='password' name='nzona_password' value='' id='slapukas' class='input_login' onBlur='DisablePassword();'>";
	setTimeout("document.getElementById('slapukas').focus();",100);
}
function DisablePassword()
{
	if (document.login_form.nzona_password.value == '') {
	document.getElementById("pswdiv").innerHTML="<input type='text' name='nzona_password' value='slaptažodis' id='slapukas' class='input_login_inactive' onFocus='EnablePassword();'>";
	}
}

function getElement(formId, objName) {
	var obj = new Object();
	obj = eval("document."+formId+"."+objName);
	if (obj == null) { // div tag for example
		obj = document.all ? document.all(objName) :
		      document.getElementById ? document.getElementById(objName) :
		      document.layers ? document.layers[objName] : null;
	}
	return obj;
} 

function changeSelBox(formName, srcValue, destObjName) {
	var destObj = eval("document."+formName+"."+destObjName);
	var selId = 0;

    for(county=1;county<destObj.options.length;county++) {

        if(destObj.options[county].value==srcValue)
        {
			selId=county;
		}
		
	}

	destObj.selectedIndex = selId;
	<!-- destObj.focus(); -->
}

function setCookie(name, value) {
  var curCookie = name + "=" + escape(value);
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function hideIt(object)
{
	obj = document.getElementById(object);
	if(obj.style.display=='none')
	{
		obj.style.display = 'block';
	}else{
		obj.style.display = 'none';
	}
}

	/**
	* check/uncheck all checkboxes in a form
	* @param form - form name
	* @param name - checkbox that must be checked name
	* @param value - true to check, false to uncheck	
	*/
	function check_all(form, name, value)
	{
		var form = document.forms[form];
		var i = 0;
		var element;
		
		for( i = 0; i < form.elements.length; i++ )
		{
			element = form.elements[i];
			if( element.name == name )
			{
				element.checked = value;
			}
		}
	};

//
// Open centered window
//
function open_wnd(exp_bar,width,height,url) {
  winName = "_blank";
  theURL = 'http://'+url;
  //theURL = url;
  page_height = (height != '')?height:600;
  page_width = (height != '')?width:500;
  toolbar = (exp_bar == 1)?'yes':'no';
  page_top = Math.round((screen.height-page_height)/2);
  page_left = Math.round((screen.width-page_width)/2);
  size = "width="+page_width+",height="+page_height+",top="+page_top+",left="+page_left;
    features = 'status=yes,toolbar='+toolbar+',scrollbars=yes,resizable=yes,'+size;
    //var newWnd = null;
    //alert(theURL);
    window.open(theURL,winName,features);
    //newWnd.focus();
}
function open_wnd2(width,height,url,desc) {
  winName = "_blank";
  theURL = url;
  //height=height/1+50;
  //theURL = url;
  salyga = (desc == 1)?90:0;
  page_height = (height != '')?(height/1+salyga):600;
  page_width = (height != '')?width:500;
  page_top = Math.round((screen.height-page_height)/2);
  page_left = Math.round((screen.width-page_width)/2);
  size = "width="+page_width+",height="+page_height+",top="+page_top+",left="+page_left;
    features = 'status=no,toolbar=no,scrollbars=no,resizable=no,'+size;
    //var newWnd = null;
    //alert(theURL);
    window.open(theURL,winName,features);
    //newWnd.focus();
}

function open_sendlink(mylink) {
  winName = "_blank";
  theURL = mylink;
  page_height = 320;
  page_width = 400;
  page_top = Math.round((screen.height-page_height)/2);
  page_left = Math.round((screen.width-page_width)/2);
  size = "width="+page_width+",height="+page_height+",top="+page_top+",left="+page_left;
    features = 'status=no,toolbar=no,scrollbars=no,resizable=no,'+size;
    window.open(theURL,winName,features);
}

function open_objektas(mylink) {
  winName = "_blank";
  theURL = mylink;
  page_height = 450;
  page_width = 650;
  page_top = Math.round((screen.height-page_height)/2);
  page_left = Math.round((screen.width-page_width)/2);
  size = "width="+page_width+",height="+page_height+",top="+page_top+",left="+page_left;
    features = 'status=yes,toolbar=no,scrollbars=yes,resizable=no,'+size;
    window.open(theURL,winName,features);
}
function open_news(width,height,url) {
  winName = "_blank";
  theURL = url;
  page_height = (height != '')?height:600;
  page_width = (height != '')?width:500;
  page_top = Math.round((screen.height-page_height)/2);
  page_left = Math.round((screen.width-page_width)/2);
  size = "width="+page_width+",height="+page_height+",top="+page_top+",left="+page_left;
    features = 'status=no,toolbar=no,scrollbars=no,resizable=no,'+size;
    window.open(theURL,winName,features);
    //newWnd.focus();
}

function open_wnd3(width,height,url) {
  winName = "_blank";
  theURL = url;
  //theURL = url;
  page_height = (height != '')?height:600;
  page_width = (height != '')?width:500;
  page_top = Math.round((screen.height-page_height)/2);
  page_left = Math.round((screen.width-page_width)/2);
  size = "width="+page_width+",height="+page_height+",top="+page_top+",left="+page_left;
    features = 'status=yes,toolbar=no,scrollbars=yes,resizable=no,'+size;
    //var newWnd = null;
    //alert(theURL);
    window.open(theURL,winName,features);
    //newWnd.focus();
}

function cleanSlot(slotNr) {

	document.getElementById("button_image_slot"+slotNr).style.visibility="visible";
	document.getElementById("button_image_slot"+slotNr).style.overflow="auto";
	document.getElementById("button_image_slot"+slotNr).style.height="auto";
	document.getElementById("image_box"+slotNr).style.visibility="hidden";
	document.getElementById("image_box"+slotNr).style.overflow="hidden";
	document.getElementById("image_box"+slotNr).style.height="1px";
	document.getElementById("image_slot"+slotNr).innerHTML="";
	document.getElementById("bt_img_thumb"+slotNr).value="";
	document.getElementById("bt_img_big"+slotNr).value="";
	
}

function cleanFile(slotNr) {

	document.getElementById("button_file_slot"+slotNr).style.visibility="visible";
	document.getElementById("button_file_slot"+slotNr).style.overflow="auto";
	document.getElementById("button_file_slot"+slotNr).style.height="auto";
	document.getElementById("file_box"+slotNr).style.visibility="hidden";
	document.getElementById("file_box"+slotNr).style.overflow="hidden";
	document.getElementById("file_box"+slotNr).style.height="1px";
	document.getElementById("file_slot"+slotNr).innerHTML="";
	document.getElementById("bt_file"+slotNr).value="";

}


$(document).ready(function(){

	$("#loginForm").keypress(
		function (e) {
			if (e.which == 13) $(this).submit();
		}
	);

	$("#loginName").val('vartotojo vardas');

	$("#loginName").focus(
		function(){
			if ($(this).val() == 'vartotojo vardas') $(this).val('');
		}
	);

	$("#loginName").blur(
		function(){
			if ($(this).val() == '') $(this).val('vartotojo vardas');
		}
	);

	$("#loginPasw").hide();
	$("#loginPaswText").show();

	$("#loginPaswText").focus(
		function(){
			$(this).hide();
			$("#loginPasw").show().focus();
		}
	);

	$("#loginPasw").blur(
		function(){
			if ($(this).val() == '') {
				$(this).hide();
				$("#loginPaswText").show();
			}
		}
	);

	$("#searchForm").keypress(
		function (e) {
			if (e.which == 13) $(this).submit();
		}
	);

	$("#searchName").val('paieška svetainėje');

	$("#searchName").focus(
		function(){
			if ($(this).val() == 'paieška svetainėje') $(this).val('');
		}
	);

	$("#searchName").blur(
		function(){
			if ($(this).val() == '') $(this).val('paieška svetainėje');
		}
	);

});