function elementById(x) { 
	if (document.getElementById) return document.getElementById(x); 
	else if (document.all) return document.all[x]; 
	else if (document.layers) return document.layers[x];
	else return null;
}

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

var today = new Date();
var zero_date = new Date(0,0,0);
today.setTime(today.getTime() - zero_date.getTime());

var todays_date = new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
var expires_date = new Date(todays_date.getTime() + (8 * 7 * 86400000));

function storeMasterCookie() {
    if (!Get_Cookie('MasterCookie'))
        Set_Cookie('MasterCookie','MasterCookie');
}

function storeIntelligentCookie(name,value) {
    if (Get_Cookie('MasterCookie')) {
        var IntelligentCookie = Get_Cookie(name);
        if ((!IntelligentCookie) || (IntelligentCookie != value)) {
            Set_Cookie(name,value,expires_date);
            var IntelligentCookie = Get_Cookie(name);
            if ((!IntelligentCookie) || (IntelligentCookie != value))
                Delete_Cookie('MasterCookie');
        }
    }
}
function PrimoSearch()
{

	var e;
	var i;
	var s;
	var c;
	var ar;
	
	var scopes = '';
	var scarr = new Array();
	var scopescount=0;
	var searcharg=encodeURI(document.LVB.find_request_1.value);
	var searchtyp=encodeURI(document.LVB.find_code_1.value);
	var surl='http://primo-v3.library.lt/primo_library/libweb/action/search.do?';
	surl=surl+'fn=search&ct=search&vid=LABT_VU1&vl(21276563UI2)=all_items&mode=Advanced&tab=elaba';
	surl=surl+'&vl(21276562UI0)='+searchtyp+'&vl(freeText0)='+searcharg+'&vl(1UI0)=contains&scp.scps=';
	
	var surl2='http://primo-v3.library.lt/primo_library/libweb/action/search.do?dscnt=1&scp.scps=scope%3A(ETD01)%2Cscope%3A(ELB01)%2Cscope%3A(HSM01)';
	surl2=surl2+'&tab=local&dstmp=1315463737141&srt=rank&mode=Advanced&vl(21276564UI4)=all_items&tb=t&indx=1&fromLogin=true&vl(21276563UI3)=all_items';
	surl2=surl2+'&fn=search&vid=LABT_VU1&frbg=&vl(73841238UI5)=all_items&ct=search&dum=true&fromLogin=true&vl(1UIStartWith0)=contains';
	surl2=surl2+'&vl(2114983UI0)='+searchtyp+'&vl(freeText0)='+searcharg;
	
		
	var surl3='http://primo-v3.library.lt/primo_library/libweb/action/search.do?dscnt=0&scp.scps=scope%3A%28ETD01%29%2Cscope%3A%28ELB01%29%2Cscope%3A%28HSM01%29';
	surl3=surl3+'&tab=local&vl(2114983UI0)=any&dstmp=1315465159552&srt=rank&mode=Advanced&vl(21276564UI4)=all_items&vl(21276562UI1)=any&vl(1UIStartWith1)=contains';
	surl3=surl3+'&indx=1&tb=t&vl(21276563UI3)=all_items&vl(freeText0)=lietuvos+respublika&fn=search&vid=LABT_VU1&vl(freeText2)=&vl(103437396UI2)=any&frbg=';
	surl3=surl3+'&vl(73841238UI5)=all_items&ct=search&vl(1UIStartWith2)=contains&dum=true&vl(1UIStartWith0)=contains&Submit=Paie%C5%A1ka&vl(freeText1)=';
	
	var surl4='http://primo-v3.library.lt/primo_library/libweb/action/search.do?dscnt=0&scp.scps=scope%3A%28ETD01%29%2Cscope%3A%28ELB01%29%2Cscope%3A%28HSM01%29';
	surl4=surl4+'&frbg=&tab=local&srt=rank&ct=search&mode=Basic&dum=true&fromLogin=true&vl(95041238UI1)=all_items&tb=t&indx=1&vl(1UIStartWith0)=contains';
	surl4=surl4+'&vl(103881588UI0)='+searchtyp+'&vl(freeText0)='+searcharg+'&fn=search&vid=LABT_VU1';
	

	
	ar=document.LVB.getElementsByTagName("INPUT");
	c="";
	
	scopescount=3;
	scopes = 'scope%3A(ETD01)%2Cscope%3A(ELB01)%2Cscope%3A(HSM01)';
	
	surl=surl+scopes;	
	
	
	c1=document.LVB.find_request_1.value;
	
	if (scopescount==0) {alert("0!");}
	else {	
		if (c1.length>0) open(surl4,"_blank");		
	}
}
function MetaLib()
{

	var e;
	var i;
	var s;
	var c;
	var ar;

	s="http://metalib.library.lt/V?func=meta-1-check&mode=advanced";
	s=s+"&find_code_2="+document.LVB.find_code_1.value;
	s=s+"&find_request_2="+document.LVB.find_request_1.value;
	
	ar=document.LVB.getElementsByTagName("INPUT");
	c="";
	for (i=1; i<=ar.length; i++)
	{
		e=ar[i-1];
		if (e.type=="checkbox")
		{
			if (e.value.length>0)
			{
				if (e.checked) {s=s+"&CKBOX="+e.value; c=c+e.value+".";}
			}
		}
	}
	if (c.length>0) c=c.substr(0,c.length-1);
	
	storeIntelligentCookie('MetaLibResources',c);
	c1=document.LVB.find_request_1.value;
	
	//alert(s);
	if (c1.length>0) open(encodeURI(s),"_blank");
}
function SetMetaLib()
{

	var cookie="";
	var e;
	var i;
	
	storeMasterCookie();
	cookie=Get_Cookie('MetaLibResources');
	if (cookie==null) return;
	ar=document.LVB.getElementsByTagName("INPUT");
	for (i=1; i<=ar.length; i++) 
	{
		e=ar[i-1]; 
		if (e.type=="checkbox") 
		{
			if (cookie.indexOf(e.value)>=0) {e.checked=true;} else {e.checked=false;}
		}
	} 
}
function select_all()
{

	var c="";
	var e;
	var i;
	var n=0;
	var chk=false;

	ar=document.LVB.getElementsByTagName("INPUT");
	for (i=1; i<=ar.length; i++) 
	{
		e=ar[i-1]; 
		if (e.type=="checkbox") 
		{
			if (n==0) chk=e.checked;
			if (n>0) e.checked=chk;
			if (chk) c=c+e.value+".";
			n++;
		}
	} 
	if (c.length>0) c=c.substr(0,c.length-1);
	storeIntelligentCookie('MetaLibResources',c);
}
function save_cookie()
{

	var c="";
	var e;
	var i;
	var n=0;

	ar=document.LVB.getElementsByTagName("INPUT");
	for (i=1; i<=ar.length; i++) 
	{
		e=ar[i-1]; 
		if (e.type=="checkbox") 
		{
			if (n>0) c=c+e.value+".";
			n++;
		}
	} 
	if (c.length>0) c=c.substr(0,c.length-1);
	storeIntelligentCookie('MetaLibResources',c);
}



