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="";

}

/**
* 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 changeRadioButton(form, value, name)
{
	var form = document.forms[form];
	var i = 0;
	var element;
	for( i = 0; i < form.elements.length; i++ )
	{
		element = form.elements[i];
		if( element.value == value )
		{
			element.checked = 'true';
		}
	}
};	

function getCheckedValue(radioObj) {
	if(!radioObj) return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	if(radioObj.checked)
	return radioObj.value;
	else return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function getCheckedValues(radioObj) {
	var getAll = "";
	if(!radioObj) return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	if(radioObj.checked)
	return radioObj.value;
	else return "";
	var sel = "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			getAll = getAll+sel+radioObj[i].value;
			sel=",";
		}
	}
	return getAll;
}
function getSelectedValues(radioObj) {
	var getAll = "";
	if(!radioObj) return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	if(radioObj.selected)
	return radioObj.value;
	else return "";
	var sel = "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].selected) {
			getAll = getAll+sel+radioObj[i].value;
			sel=",";
		}
	}
	return getAll;
}
function getSelectedValue(radioObj) {
	if(!radioObj) return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	if(radioObj.selected)
	return radioObj.value;
	else return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].selected) {
			return radioObj[i].value;
		}
	}
	return "";
}
function textlimit(Obj,maxcount,counter)
{
    function c_len(){    
        if(this.value.length > this.maxcount && this.maxcount != 0) 
            return false;
        update_count(this);    
    }
    
    function upd_count(){    update_count(this);}
    
    function update_count(elem){
        if(elem.counter != null){
            cnt = getObj(elem.counter);
            cnt.innerHTML = 'Liko simbolių ' + (maxcount-elem.value.length);
    }}
    
    function check(){
        if (this.value.length  > this.maxcount && this.maxcount != 0) 
            this.value = this.value.substr(0,this.maxcount);
        update_count(this); 
    }
    
    Obj.counter   = counter;
    Obj.maxcount  = maxcount;
    Obj.onkeypress= c_len;
    Obj.onkeydown = upd_count;    
    Obj.onkeyup   = check;
    Obj.onfocus   = check;
    Obj.onblur    = check;        
    Obj.onmouseup = check;

    update_count(Obj);
    
/*************** OTHER USED / NEEDED FUNCTIONS ***************************/
function getObj( ref ) { if( document.getElementById( ref ) != null )//W3C/
return document.getElementById(ref); else if(document.all[ref]!=null)//IE5/
return document.all[ ref ]; else if( document.layers[ ref ] != null )//NN4/
return document.layers[ref]; else alert('Object "'+ref+'" not Found')//ERR/
}/************************************************************************/
} 
