var test = true;
var Mver = "";

window.name = "vertiTop";

function getLangCode(){
// for VERTI 2.3
    var r = "";
    if (typeof menu.mLangcode=="string" ) {
        r = menu.mLangcode;
    }
return r;
}

function getLang(){
// for VERTI 2.3
    var r = "";
    if (typeof menu.mLangkey != "undefined" ) {
        r = menu.mLangkey;
    }
return r;
}

function setLang(code){
// deprecated
if (typeof(ds.document.SESSION)=="object" ) {
 ds.document.SESSION.lang.value=code;
 }
}

function getNext(){
var r = "";
if (typeof(ds.document.SESSION)=="object" ) {
 r = ds.document.SESSION.next.value;
 if (isMenu() && r.substring(0,1) != "/") r = getMenudir() + r;
 r=r.replace("!",getLang());
 }
return r;
}

function setNext(next){
if (typeof(ds.document.SESSION)=="object" ) {
 ds.document.SESSION.next.value=next;
 }
}

function getQname(){
var r = "";
if (typeof(ds.document.SESSION)=="object" ) {
 r = ds.document.SESSION.qname.value;
 }
return r;
}

function setQname(code){
if (typeof(ds.document.SESSION)=="object" ) {
//show("setQname", ds.document.SESSION.qname.value,code); 
 ds.document.SESSION.qname.value=code;
 }
}

function getDblist(){
var r = "";
if (typeof(ds.document.SESSION)=="object" ) {
 r = ds.document.STATFILE.dblist.value;
 }
return r;
}

function getQtlist(){
var r = "";
if (typeof(ds.document.SESSION)=="object" ) {
 r = ds.document.STATFILE.qtlist.value;
 }
return r;
}

function getQlist(){
var r = "";
if (typeof(ds.document.SESSION)=="object" ) {
 r = ds.document.SESSION.qlist.value;
 }
return r;
}

function setQlist(list){
if (typeof(ds.document.SESSION)=="object" ) {
 ds.document.SESSION.qlist.value=list;
 }
}

function getQlistText(){
var r = "";
if (typeof(ds.document.SESSION)=="object" ) {
 r = ds.document.SESSION.qlisttext.value;
 }
return (r + ";;").split(";");  
}

function getQlistName(){
var r = "";
if (typeof(ds.document.SESSION)=="object" ) {
 r = ds.document.SESSION.qlistname.value;
 }
return r;
}

function toFrontpage(sw){
    if (!sw) sw = 1;
    var r = "";
    if (typeof(ds.document.SESSION)=="object" ) {
        openFrontpage();
        if (sw) {
		    if (sw==1 && isMenu()) {
                if (typeof showMenu != "undefined") showMenu();
                sel("");
                /*
                var msel = getHttpItem(menu.location,"mpar");
			    if (msel.length>0) msel = " " + msel;
			    (msel.length>0) ? menu.m_Do(msel) : sel("");
			    */
		    }
		    // sw=0
		    return;
	    }
        if (isMenu()) {
            if (typeof showMenu != "undefined") showMenu();
 		    sel("");
 	    }
    }
}

function openFrontpage() {
//toFrontpage subfn; called directly by menu.setSch()
if (typeof(ds.document.SESSION)!="object" ) return "";
 r =ds.document.SESSION.frontpage.value
 r = r.replace("!",getLang());
 r = setVirtualPath("",r);
px.location = r;
}

function openSearchInfo() {
    vertiTop.px.location = setVirtualPath("/searchInfo.aspx",gappl + "/menu");
    status = "";
}


function getListItem(list,key,eq){
// key:ssä ensimmäisenä erotinmerkki
// key:n loppuun "="
var r = "";
var sep = key.substring(0,1);
if (!eq) eq = "=";
if (list.length > 0) {
 list = sep + list;
 var i = list.toUpperCase().indexOf(key.toUpperCase() + eq);
 if (i > -1) {
 		list = list.substring(i);
		r = list.split(sep)[1];
 		}
 }
return r;
}

function dropListItem(list,key) {
// key:ssä ensimmäisenä erotinmerkki
// key:n loppuun "="
var r = list;
if (r.length == 0) return r;
var sep = key.substring(0,1);
list = sep + list + sep;
var i = list.toUpperCase().indexOf(key.toUpperCase() + "=");
if ( i == -1) return r;
r = list.substring(0,i);
list = list.substring(i+1);
if (list.indexOf(sep) == 0) list = list.substring(1);
list = list.substring(list.indexOf(sep));
list = (list.length > 1) ? list.substring(0,list.length-1) : "";
return (r + list).substring(1);
}

function setListItem(list,key,valu) {
// key:ssä ensimmäisenä itemien välinen erotinmerkki
// key-value erotumerkki joko keyn lopussa tai valun alussa
var sep;
list = dropListItem(list,key);
sep  = (list.length > 0) ? key.substring(0,1): ""; 
return key.substring(1) + "=" + valu + sep + list;
}

function isListItem(list,key){
// key:ssä ensimmäisenä erotinmerkki
var r = false;
if (list.length >= key.length -1) {
 list = key.substring(0,1) + list;
 r = list.toUpperCase().indexOf(key.toUpperCase()) > -1;
 }
return r
}

function getListItemKeys(list,sep) {
list = list.split(sep);
if (list.length == 0) return "";
var k,i,l;
k = "";
for (i = 0; i < list.length; i++) {
		l = list[i];
		k += l.substring(0,l.indexOf("=")) + sep;
		}
return k.substr(0,k.length-1);
}

function getNewListItemKey(list,sep, prefix) {
var keys = sep + getListItemKeys(list,sep) + sep;
if (!sep) {alert("getNewListItemKey: separator missing");return;}
if (!prefix) prefix = "";
var seek = true;
var k,i;
for (i = 0; seek; i++) {
		k = sep + prefix + i;
		seek = keys.indexOf(k) > -1;
		}
return k;
}

function setListCol(list,nr,valu,sep) {
valu = valu.substring(1).split(valu.substring(0,1));
var sep1 = sep.substring(0,1);
var sep2 = sep.substring(1,2);
list = list.split(sep1);
var i,j,k,v;
for (i=0 ; i<list.length; i++) {
		k = getItemKey(list[i]);
		v = getItemValue(list[i]).split(sep2);
		v[nr] = (valu.length == 1) ?  valu[0] : valu[i];
		list[i] = k + "=" + v.join(sep2);
		}
return list.join(sep1);		
}


function getItemKey(itm) {
return itm.substring(0,itm.indexOf("="));
}

function getItemValue(itm) {
return itm.substring(1+itm.indexOf("="));
}

function getDbname() {
// Tietokannan näyttönimi
var r = "";
if (typeof(ds.document.STATFILE)=="object" ) {
 r = ds.document.STATFILE.dbnames.value.split(",");
 r = r[getLang()-1];
 }
return r
}

function getQtname() {
// Pikatietokannan näyttönimi
var r = "";
if (typeof(ds.document.STATFILE)=="object" ) {
 r = ds.document.STATFILE.dbquicknames.value;
 r = r.split(",")[getLang()-1];
 }
return r
}

function getDbdir() {
var r = "";
if (typeof(ds.document.STATFILE)=="object" ) {
 r = ds.document.STATFILE.dbdir.value;
 }
return r
}

function getQtdir() {
var r = "";
if (typeof(ds.document.STATFILE)=="object" ) {
 r = ds.document.STATFILE.dbquick.value;
 }
return r
}
function getParmtext1() {
return getParmtext() + getParmtext2();
}

function getParmtext() {
var r = "";
if (typeof(ds.document.SESSION)=="object" ) {
 r = "?lang=" + ds.document.SESSION.lang.value;
 }
return r
}

function getParmtext2() {
var r = getVarParm();
if (r.length > 0) return r;
if (typeof(ds.document.SESSION)=="object" ) {
 r = "&xu=" + ds.document.SESSION.user.value
	 + "&yp=" + ds.document.SESSION.password.value;
 }
return r
}


function setUser(user) {
if (typeof(ds.document.SESSION)=="object" ) {
 ds.document.SESSION.user.value=user;
 }
}

function setPassword(psw) {
if (typeof(ds.document.SESSION)=="object" ) {
 ds.document.SESSION.password.value=psw;
 }
}

function writeStatFileHidden(doc)
{
if (typeof(ds.document.SESSION)!="object" ) return;
var lang = getLangCode();
var d 	 = getDblist().split(";"); 
var h 	 = d.length;
var i 	 = new Array(0,0);
var k;
for (var j = 0; j < h-1 ; j++) { 
		k = d[j].split(",");
		if (k.length > 2) { 
			 i[0]++; 
			 i[1] += (k[2].indexOf(lang) > -1) ? (k.length>3 && k[3] == "-") ? 0 : 1 : 0 ;	
			 }
		}
		h = (i[0] == 0) ? h : i[1] ;
	 doc.write('<input type="hidden" name="nodb" value="' + h + '">');
}

function writeStatFileList(doc, dir)
{
var r 	 = "";
var lc = getLangCode();
var lang = getLang();
var parmtext = getParmtext();
var dbcase = dir == "db";
var db = (dbcase) ? getDbdir() : getQtdir();
var d = (dbcase) ? getDblist() :getQtlist();
var	dname = (dbcase) ? "" : ""; //getQtname() + '/';
d = d.split(";"); 
var a1 	 = '<li><b><a href="../' + db + '/';
var a2   = '<li><b><a href="" onclick="javascript:vertiTop.loginTo(\'Login' + lang;
var b1 	 = '.asp' + parmtext + '">' + dname ;
var b3   = '\');return false;">' + dname ;
var c 	 = ' </a></b></li>\n';
var i,k,w,q;
for (i = 0; i < d.length-1; i++) { 
 k = d[i].split(",");
 w = false;
 if (k.length < 3) { w = true; }
 else { if (k[2].indexOf(lc) > -1 && (k[3].length == 0 || k[3].charAt(0) != '-')) w = true; }
 q = (k.length < 4) ? true : k[3].toUpperCase() != "TRUE";
 // ei kirjautumista 
 if (w && q) doc.write(a1 + k[0] + '/' +  k[0] + b1 + k[1] + c); 
 // kirjautuminen pääryhmään
 if (w && !q) {
	  r = (isMbchecked(k[0])) ? getMbparmtext(k[0]) : getParmtext2();
		r = a2 + '.asp' + parmtext + r + '&xs=mb&key=' + k[0] + '&next=';
		r += '../' + db + '/' + k[0] + '/' + k[0] + '.asp' 
		+ '?key=' + k[0] + '&case=mb&header=' + k[1] + b3 + k[1] + c;
		doc.write(r);}
 }
} 

function getLoginHref(path,url,d, h,lang) {
// virtual path of px application 
// tietokanta db "Database" "Quicktables"
// kirjautumista vaativa päähakemisto d
// hakemiston näyttönimi: h
var parmtext = getParmtext();
var a = '\');return false;"';
var b = (isMbchecked(d)) ? getMbparmtext(d) : getParmtext2();
return'javascript:vertiTop.loginTo(\'' + path + '/Dialog/Login' + lang
		  + '.asp' + parmtext + b + '&xs=mb&key=' + d + '&next='
			+ escape(url)	+ '?key=' + d + '&case=mb&header=' + h + '\');';
}

function isLogged(key) {
 return isMbchecked(key) || isInlog();
}

function loginTo(h){
// Statfile-aliohjelma. 
// writeStatFileList kirjoittaa tämän kirjautumista vaativan päähaaran linkkiin 
// asettaa next-kentän arvoksi paluuosoitteen, jota kirjautumissivu käyttää
var i = h.indexOf("&next=");
setNext(h.substring(i + 6));
px.location.href=h;
}

function checkLogin(){
// IncHeader body onload-funktio
// tarkistaa loginin tarpeen, kun tullaan searchpx2- tai view-sivuille
var ok,lh,j,key,item,r,l,s,h,dbl,a2;
h = px.location.href;
if (h.indexOf("searchpx2.asp") == -1 && h.indexOf("view.asp") == -1) return;
l = px.document.links;
s  = "path=../" + getDbdir() + "/";
a2 = "javascript:vertiTop.loginTo('Login" + getLang() + ".asp" + getParmtext();
dbl = getDblist();
for (var i = 0; i < l.length; i++) {
	lh=l[i].href;
	ok = lh.indexOf("varval.asp?") > -1 && lh.indexOf(s) > -1;
	if (ok) {	
		 j = lh.indexOf(s);
		 key = lh.substring(j + s.length);
		 key = key.substring(0,key.indexOf("/"));
		 item = getListItem(dbl,";" + key, ",")
		 item = item.split(",");
		 if (item.length > 3){
		 		if (item[3].toUpperCase() == "TRUE") {
					 if (lh.indexOf("&xu=") > -1) lh = lh.substring(0,lh.indexOf("&xu="));
					 if (lh.indexOf("&case=mb") == -1) lh += "&case=mb";  	 
					 if (lh.indexOf("&key=") == -1) lh += "&key=" + key;
					 r = (isMbchecked(key)) ? getMbparmtext(key) : getParmtext2();
					 lh = a2 + r + "&xs=mb" + "&header=" + item[1] + "&next=" + lh + "')";			 
					 }
				l[i].href = lh;		 	 
	 			 //show("checkLogin:key",key,"item",item,"result href:",l[i].href);
				} 
		 } 
	} 
}

function toStatfile(l) {
// Statfile-sivun haku (kielen vaihto, oletuskielisen lataus) 
if (arguments.length > 0) setLang(l);
startDs(getLang());
}

function startDs(lang) {
var x="";
var y ="";
if (typeof(ds.document.SESSION)== "object") {
	 x = ds.document.SESSION.user.value;
	 y = ds.document.SESSION.password.value;
}
var s = getHttpItem(vertiTop.location.search,"Msel");
if (s.length>0) s = "&Msel=" + s;
var p = getHttpItem(vertiTop.location.search,"Mpar");
if (p.length>0) s += "&Mpar=" + p;
ds.location=ds.location.pathname + "?Lang=" + lang + "&xu=" + x + "&yp=" + y + 
		"&frontfile=" + getFrontfile() + "&isinlogged=" + isInlogged() + s;
}


function setMbcheck(v) {
if (typeof(ds.document.SESSION)=="object" ) {
	if (!v) v = "";
	ds.document.SESSION.mbcheck.value = v;
	}
}

function isMbcheck() {
var h = px.location.href.toString();
if (h.toUpperCase().indexOf("SAVESHOW.ASP") > -1) {h = previousStatPageLocation();}
var r = h.indexOf("&case=mb") > -1;
return r;
}

function isInlog() {
// vaaditaanko koko kantaan kirjautuminen
var r = false;
if (typeof(ds.document.SESSION)=="object" ) {
  var d = ds.document.SESSION;
	r = d.dbinlog.value.toUpperCase() == "TRUE"; // || isMbcheck();
	}
return r;
}

function isInlogged(){
if (!isInlog()) return true;
var f= ds.document.forms["SESSION"];
return f.isinlogged.value=="true" && f.user.value.length>0;
}


function getVarParm(doc) {
var r,x,y,c,k,v;
r = "";
if (!doc)doc = px.document;
if (doc.forms[0] && doc.forms[0].varparm) {
	 v = doc.forms[0].varparm.value;
	 x = getHttpItem(v,"xu");
	 y = getHttpItem(v,"yp");
	 c = getHttpItem(v,"case");
	 k = getHttpItem(v,"key");
	 if (x.length>0) { r += "&xu=" + x;}
	 if (y.length>0) { r += "&yp=" + y;}
	 if (c.length>0) { r += "&case=" + c;}
	 if (k.length>0) { r += "&key=" + k;}
	 }
return r;
}

function isGraph() {
return typeof(gdoc) == "string";
}

function toGraph() {
// PX-Web graphics (no Dinosoft graph application)
return true;
}

function chkInlog(doc) {
if (isInlog()) {
;	var loc = doc.location.toString();
	if ((!isInlogged()) && 
		 (loc.indexOf("Statfile")>-1 || isMenu() && (loc.indexOf("Frontpage")>-1 || loc.indexOf("PageQtUpd")>-1))) {
	 	 			var f = doc.forms[0].elements;
					if (!(f.length==1 && f[0].onclick.toString().indexOf("history.go(-1)")>-1)) {
 						 ds.document.SESSION.isinlogged.value="true";
						 if (isMenu()) menu.startMenu("");
	  		     }
      } 
  }
}

function setHrefs(hrefs) {
if (typeof(ds.document.SESSION)=="object" ) {
	 ds.document.SESSION.hrefs.value=hrefs.join("!");
	 }
}

function getHrefs() {
var r ="";
if (typeof(ds.document.SESSION)=="object" ) {
	 r = ds.document.SESSION.hrefs.value;
	 }
return r;
}

function Link(ind) {
	var hrefs = getHrefs().split("!");
	if (isGedit() && hrefs[ind].indexOf("Gedit=true") >-1){ 
		 vertiTop.menu.saveMsel();
	}
    vertiTop.px.location.href = hrefs[ind];
	window.status = ""; 
}

function showLinks(fr) {
// util
// list hrefs of links of document fr
var p,i,max;
if (typeof fr == "undefined")  p = getHrefs().split("!");
else {
    p = "";
    var l = fr.document.links;
    max = l.length;
    for(i = 0;i<max;i++) {
        p += "!" + l[i].href; 
    }
    if (p.length>0) p = p.substring(1).split("!");    
}
var r = ""
max = p.length;
for ( i=0; i<max; i++) r += i + ":" + p[i] + "\n";
	show(r);
}

function setLinkToStatpage(href,form) {
// varparm-kenttä koodataan saveStatPage()-metodissa skandien takia
return unescape(href);
}

function toSearchpx() {
// Etsintäsivulle Statfsivulta 
var p = setVirtualPath("/Searchpx.asp","/Dialog");
px.location.href = p + getParmtext1();
}

function setInlog(f) {
// Kirjautumistietojen tallennus
var s = px.location.href.toString();
var xu,yp,i,key,l;
if (arguments.length > 0) {
	xu = f.xu.value;
	yp = f.yp.value;
} else {
	xu = getHttpItem(s,"xu");
	yp = getHttpItem(s,"yp");
}
if (s.indexOf("&case=mb") == -1) {
	 // true =  kirjautuminen koko kantaan
	setUser(xu);
	setPassword(yp);
	} else {
	key = getHttpItem(s,"key");
	updMblist(key,xu,yp);
	}
}
function updMblist(key,xy,yp) {
// Password sivun setInlog -apufunktio
var list, l;
l = ";" + key + "=" + xy + "," + yp;
list = getMblist();
l = l + dropListItem(list,";" + key);
setMblist(l);
}

function getMblist() {
var r ="";
if (typeof(ds.document.SESSION)=="object" ) {
	 r = ds.document.SESSION.mblist.value;
	 }
return r;
}

function setMblist(list){
if (typeof(ds.document.SESSION)=="object" ) {
 ds.document.SESSION.mblist.value=list;
 }
}

function isMbchecked(key) {
var list = getMblist();
return isListItem(list,";" + key);
}

function getMblistItem(key) {
var list =getMblist();
return getListItem(list,";" + key);
}

function getMbparmtext(key) {
	var r = getMblistItem(key).split(",");
	return "&xu=" + r[0].substring(1+r[0].indexOf("=")) + "&yp=" + r[1]; 
}


function addLang(h) {
// lisää kieliparametrih href-stringiin
if (h.toUpperCase().indexOf("LANG=") == -1) {
	 var sep = (h.indexOf("?") > -1) ? "&" : "?";
	 h = h + sep + "lang=" + getLang();
	 }
return h;	 
}


function getMenupars() {
var r = "";
var f = (typeof(menu.document.MENU)=="object" ) ? menu.document.MENU : ds.document.MENU;
if (typeof(f) == "object") {
 r = f.menupars.value;
 }
return r; 
}

function getMenuPage(lst,vers) {
var r = "";
if (!isInlogged()) lst = "";
var f = (typeof(menu.document.MENU)=="object" ) ? menu.document.MENU : ds.document.MENU; 
if (typeof(f) == "object") {
 r = f.menu.value;
 r = r.replace("!",lst);
 if (!vers) vers = "1.15";
 r = r.replace("!",vers);
 }
return r
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "; path=/") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function getCookieNames(prefix,ds) {
	var r="";
	var j = prefix.length;
	var k;
  if (arguments.length < 2) {ds = document.cookie;}
	if (ds.charAt(0) != ";") { ds = ";" + ds;}
	while (ds.indexOf("; ") > -1) { 
			ds = ds.replace("; ",";");
			}			
	ds = ds.substring(1).split(";");
	for (var i = 0; i < ds.length; i++) {
			if ( ds[i].length >= j) {
				 if (ds[i].substring(0,j) == prefix) {
				 		k = ds[i].indexOf("=");
						if (k > -1) { 
							  r += (r.length >0) ? ";" + ds[i].substring(0,k) : ds[i].substring(0,k);
						}
				 }  
			}			
	}
	return r;
}

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 = dc.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


function setCookie(name, value, expires, path, domain, secure) {
  var r;
	var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "; path=/") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
		if (isOkToSave(curCookie)) {	
			 document.cookie = curCookie;
			 r = true;
			 }
		else {
			 alert("This query is too long to be saved into cookie.");
			 r = false;
			 }
return r;
}

function getNewCookieName(prefix) {
var seek = true;
var i = 0;
var c = document.cookie;
var n = "item" + i;
if (c.length > 0) {
	for (i = 0; seek; i++) {
		n = prefix + i;
		seek = c.indexOf(n + "=") > -1;
	  }
	}	
return n;
}
 
function isOkToSave(cook) {
var r = true;
if (navigator.appName.indexOf("Microsoft") > -1) {
	 if (!(px.location.search.indexOf("ACTION=EDIT")) > -1) {
	 		var l = document.cookie.length;
	 		if ((l + cook.length) > 4000) {
				 r = false;
				 }
	 		}
	 }
return r;	 
} 
/**
 * replaces previous getSearch() function
 * returns prevous StatPage location now stored in vertiTop.StatPage.Location
 */
function previousStatPageLocation(page) {
if (typeof vertiTop.StatPage != "object" || vertiTop.StatPage == null) return "";
if (typeof vertiTop.StatPage.Location != "string") return "";
if (page) return vertiTop.StatPage[page];
else return vertiTop.StatPage.Location;
} 
/*
function updateLinks(doc) {
// incHeader-skripti: linkkitietojen muokkaus
// gdoc,gappl: graph.js
if (isMenu() && vertiTop.scrollTop) vertiTop.scrollTop(); // for iframe version
  var max = doc.links.length;
	if (max > 0 ) {
		 var hrefs = new Array(max);
		 var p2 = getParmtext2();
  	     var p1 = getParmtext1();
		 var i,r;
		 var m = isMenu();
		 var isinfo = isInfo();
		 //var gappl = "/graph";
		 var loc = px.location.toString().toLowerCase();
		 var sch = loc.indexOf("searchpx2.asp") > -1;
		 for ( i=0; i<max; i++) {
		 		var pg = gappl + "/Statpage.aspx";
 		 		doc.links[i].href=doc.links[i].href.replace("/Dialog/varval.asp",pg);											 
		 		 r = doc.links[i].href;
				 if (r.toLowerCase().indexOf("statpage.aspx")>-1) {
				 			 if (getPage(doc.location.pathname,5) == "SAVES") {
									r = setVirtualPath(pg,gappl) +  "?" + vertiTop.StatPage.Form.varparm
							 		r = replaceHttpItem(r,"ACTION","ACTION=RETURN");
									if (px.sortVars) px.sortVars();
							 }
				 			 if (getPage(doc.location.pathname,6) == "GRAPHP") {									
							 		if (r.toUpperCase().indexOf("ACTION")== -1) r = replaceHttpItem(r,"ACTION","ACTION=RETURN");
							 } 
							 if (r.indexOf("RETURN")>-1) doc.links[i].href = setLinkToStatpage(r,doc.forms[0]);
				 }	 
				 if (m && isTableDir(doc.links[i])) {
				 			 if (getAction(doc) == "UPDATEPIC") hrefs[i]="javascript:vertiTop.toFrontpage(1);";
							 else hrefs[i] = (m) ? "javascript:vertiTop.menu.m_Do()" : doc.links[i].href;		
				 }			 							 
		 		 else {
				 			if (m && isSa(doc.links[i])) {
				 			 	 hrefs[i]="javascript:vertiTop.menu.m_Back();"; 
				 			}
		 		 			else {
				 					 if (sch) {
									    if (doc.links[i].href.indexOf(getQtdir())>-1 ){
								 				 r = (isGraph() && isQtPicture()) ? gappl + gdoc : "/Dialog/view.asp";
						 				  	 doc.links[i].href=doc.links[i].href.replace("/Dialog/varval.asp",r);
											}																						 
									 }
				 					 hrefs[i] = doc.links[i].href;
									 // isGedit-parametrin asetus
									 if (isGedit()) {
				 				 		 if ((isGraph() && hrefs[i].indexOf(gappl + gdoc) > -1) 
								 		 || (m && hrefs[i].indexOf("/Dialog/varval")>-1))
								  	 		{ hrefs[i] = replaceHttpItem(hrefs[i],"Gedit","Gedit=true");}
									 }
							 		if (hrefs[i].indexOf("&ACTION=SUBMIT") > -1) { hrefs[i]=hrefs[i].replace("&ACTION=SUBMIT","");}
		 		 			 		if (hrefs[i].indexOf("#") < 0 && hrefs[i].indexOf("javascript:")< 0 && hrefs[i].indexOf("vertiTop.") < 0) {
			 		 				 	 if (-1 < hrefs[i].indexOf("?")) {
								 				//if (-1 == hrefs[i].indexOf("xu=")) hrefs[i] += p2;
							       }
		 		  		    //else { hrefs[i] += p1; }
						  }
					 }		
				}
		if (doc.links[i].target != null) {
			 var t = doc.links[i].target;		
 	 	 	 if(t.length == 0 || t == "px") {
		 	 doc.links[i].href="javascript:vertiTop.Link(" + i + ");";}
		 	 }			
		 }
		 setHrefs(hrefs);
	}
}
*/
function isInfo() {
// true if Dinosoft Info tools are in use
// info tools: Details, Footnote, StatInfo
return isGraph();
}

function onIncheaderLoad(doc) {
show("onIncheaderLoad",onIncHeaderLoad.caller);
} 

function setIncFooterWidth(doc) {
    if (doc.getElementById("incfooter") == null) return;
    if (typeof currentBlkWidth != "function") return;
    doc.getElementById("incfooter").style.width = currentBlkWidth();
}

function getAction(doc) {
    return getHttpItem(doc.location.search,"ACTION");
}

function getPage(s,l) {
// s = doc.location.pathname
var p = s.toString().toUpperCase();
p = p.substring(1+p.lastIndexOf("/"));
p = p.substring(0,p.indexOf("."));
if (l) p = p.substring(0,l);
//alert(p);
return p;
}

function getVarFromQue(doc,valname) {
var a =getHttpItem(doc.location.search,"selidx");
while(a.indexOf(":")>-1) a=a.replace(":","=");
while(a.indexOf("¤")>-1) a=a.replace("¤","&");
return getItemValue(getListItem(a,"&" + valname));
}

function setSel(valu) {
    if (valu.indexOf("#") >- 1) {
        valu = valu.substring(0,valu.indexOf("#"));
    }
    if (typeof(ds.document.SESSION) == "object") { 
        ds.document.SESSION.selidx.value = valu;
    }
}

function getSel(valname) {
r = "";
if (typeof(ds.document.SESSION) == "object") {
	 r= ds.document.SESSION.selidx.value;
	 if (r.length == 0) return "";
	 if (typeof(valname) == "string") {
	 		return getItemValue(getListItem(r,"&" + valname));
	 }
     if (typeof(valname) == "number"){
	 		return getItemValue(r.split("&")[valname]);
	 }
}	 
return r;
}

function isSel() {
	 return getSel().length>0;
}

function getVarSel(valname) {
	 return getItemValue(getListItem(getSel(),"&" + valname));
}

function toSelections() {
if (typeof showMenu != "undefined") showMenu();
var p = setVirtualPath("/Selections.asp","/Dialog")
		+ "?lang=" + getLang();
px.document.location = p;
}

function toTransfer() {
if (typeof showMenu != "undefined") showMenu();
var p = setVirtualPath("/GraphTransfer.aspx",vertiTop.gappl)
		+ "?lang=" + getLang();
px.document.location = p;
}

var activeDsn = "te";

function isDs(dsn) {
// ds.DATA.qrs
if (!dsn) dsn = activeDsn;
else activeDsn = dsn;
var r = false;
if (typeof(ds.document.DATA)=="object" && typeof(ds.document.DATA.elements[dsn])=="object" ) {
	 var d = ds.document.DATA.elements[dsn];
	 if (typeof(d) == "object") r = d.value == "true";
	 }
return r;
}

function getDsItemByName(dsn,name) {
var dir = getDsDir(dsn);
if (dir.length == 0) return "";
var l,i;
dir = dir.split(";");
name = name.toUpperCase();
for(i = 0; i < dir.length; i++) {
				l = dir[i].indexOf("=" + name);
				if (l > -1) {
					 key = dir[i].substring(0,l);
					 return  getDsItem(dsn + "." + key); 
				}
	}			
return "";
}		 

function getDsItem(key) {
key = (key + ".").split("."); // ensure two elements
if (typeof(ds.document.DATA) != "object") return "";
var d = ds.document.DATA.elements[key[0]];
if (typeof(d) != "object") return "";
d.load(key[0]);
var r = "";
if (key[1].length > 0) r = d.getAttribute(key[1]);
return (r) ? r : "";
}

function setDsItemByName(dsn,name,valu) {
var dir,key,l;
dir = getDsDir(dsn);
key = "";
if (dir.length > 0)
	 dir = dir.split(";");
	 name = name.toUpperCase();
	 for(i = 0; i < dir.length; i++) {
				l = dir[i].indexOf("=" + name);
				if (l > -1) {
					 key = dir[i].substring(0,l);
				}
	 }
if (key == "") {key=getNewDsItemKey(dsn,"cl");}				
setDsItem(dsn + "." + key + "." + name, valu);
}

function setDsItem(key,valu) {
if (!valu) valu ="";
if (typeof(ds.document.DATA) != "object") return false;
key = (key + "..").split("."); // key =<dsn>.<item>.<name>; ensure three element
var d = ds.document.DATA.elements[key[0]];
if (typeof(d) != "object") return false;
d.load(key[0]);
var dir = updDsDir(d.getAttribute(key[0]),key[1],key[2]);
d.setAttribute(key[1],valu);
d.setAttribute(key[0],dir);
d.save(key[0]);
return true;
}

function dropDsItemByName(dsn,name) {
var dir = getDsDir(dsn);
if (dir.length == 0) return false;
var l,i;
dir = dir.split(";");
name = name.toUpperCase();
for(i = 0; i < dir.length; i++) {
				l = dir[i].indexOf("=" + name);
				if (l > -1) {
					 key = dir[i].substring(0,l);
					 return  dropDsItem(dsn + "." + key); 
				}
	}			
return false;
}		 

function dropDsItem(dsn) {
if (typeof(ds.document.DATA) != "object") return false;
dsn = (dsn + ".").split("."); // ensure two element
var d = ds.document.DATA.elements[dsn[0]];
if (typeof(d) != "object") return false;
d.load(dsn[0]);
d.removeAttribute(dsn[1]);
var dir = d.getAttribute(dsn[0]);
if (dir) {
	 dir = dropListItem(dir,";" + dsn[1]);
	 d.setAttribute(dsn[0],dir);
	 }
d.save(dsn[0]);
return true;
}

function updDsDir(dir,key,name) {
dir =(!dir) ? "" : dir; //dir might be null
name = (!name) ? "" : name.toUpperCase();
var k = ";" + key;
if (isListItem(dir,k)) { 
	 var d = dir;
	 dir = dropListItem(dir,k);
	 }
dir = (dir.length > 0) ? ";" + dir : ""; 
return key + "=" + name + dir;
}

function setDsDir(dsn,dir) {
if (typeof(ds.document.DATA) != "object") return false;
var d = ds.document.DATA.elements[dsn];
if (typeof(d) != "object") return false;
d.load(dsn);
d.setAttribute(dsn,dir);
d.save(dsn);
}

function getDsDir(dsn) {
return getDsKeys(dsn,true);
}

function showDsDir(dsn) {
var dir = getDsDir(dsn);
while (dir.indexOf(";") > -1) dir = dir.replace(";", "\n","g");
show(dir);
}

function getDsKeys(dsn, values) {
if (!values) values = false;
if (typeof(ds.document.DATA) != "object") return "";
d = ds.document.DATA.elements[dsn];
if (typeof(d) != "object") return "";
d.load(dsn);
var dir = d.getAttribute(dsn);
if (!dir) return "";
if (values) return dir;
dir = dir.split(";");
for (var i = 0; i < dir.length; i++) { dir[i] = dir[i].substring(0,dir[i].indexOf("="));}
dir = dir.join(";");
return dir;
}

function getNewDsItemKey(dsn,prefix) {
if (!prefix) prefix = "item";
var dir = ";" + getDsKeys(dsn) + ";";
var r;
var seek = true;
for (i = 0; seek; i++) {
		r = prefix + i;
		if (dir.indexOf(";" + r + ";") == -1) seek = false;
		}
return r;
}

function getDefs() {
// ds.DATA.cls
return getDsItem("cls.defs");
}

function showDefs() {
var list = getDefs();
while (list.indexOf("¤")>-1) { list=list.replace("¤","\n");}
show(list);
}

function setDefs(list) {
setDsItem("cls.defs",list);
}

function getDef(varname, key) {
var itm = getDefItem(varname);
if (itm.length == 0) return "";
var lst = getDsItemByName("cls",varname);
return getListItem(lst,"¤" + itm);
}

function getDefItem(key) {
var list,itm;
list = getDsItem("cls.defs");
if (list.length == 0) return "";
itm = getListItem(list,"¤" + key);
if (itm.length == 0) return "";
return getItemValue(itm);
}

function setDef(key,valu) {
var list = getDsItem("cls.defs");
list = setListItem(list,"¤" + key,valu);
setDsItem("cls.defs",list);
}

function dropDef(varname,key) {
if (key != getDefItem(varname)) return; 
var list = getDsItem("cls.defs");
list = dropListItem(list,"¤" + varname);
setDsItem("cls.defs",list);
}

function qLoad(name){
if (typeof(ds.document.SESSION)=="object" ) {
 ds.document.SESSION.qlist.value=qSortGet("cls",name);
 ds.document.SESSION.qlistname.value=name;
 }
}

function qSortGet(key,name){
	return getDsItemByName(key,name).split("¤").sort(qSortFun).join("¤");
}

function qSortFun(a,b) {
	a = a.substring(1+a.indexOf("="));
	b = b.substring(1+b.indexOf("="));
	if (a>b) return 1;
	if (b>a) return -1;
	return 0; 
}

function qSave() {
if (typeof(ds.document.SESSION)=="object" ) {
 	var name =ds.document.SESSION.qlistname.value;
	if (name.length == 0) {alert("Saving failed, list name missing");return;}
	var v = ds.document.SESSION.qlist.value;
 	if (v.length > 0) { setDsItemByName("cls",name,v);} 
	else {dropDsItemByName("cls",name);}  
  }
}

function qSet(key,valu) {
var list = getQlist();
if (!valu) {
	 valu = key;
	 key  = getNewListItemKey(list,"¤");
	 }
list = setListItem(list,key,valu);
setQlist(list);
qSave();
return list;
}

function qGet(key) {
var list = getQlist();
return getListItem(list,key);
}

function qDrop(key) {
var list = getQlist();
list = dropListItem(list,key);
setQlist(list);
qSave();
return list;
}

function qSize(list) {
if (!list) list = getQlist();
var r =(list.length == 0) ? 220 : list.split("¤").length * 23 + 310;
return r;
}

function qColSet(nr,valu) {
var list = getQlist();
list = setListCol(list,nr,valu,"¤!");
setQlist(list);
qSave();
return list;
}

function getVal(valnr,valname){
var r = "";
if (typeof(ds.document.SESSION)=="object" ) {
 r = ds.document.SESSION.val.value;
 while (r.indexOf("?") > -1) {
 			 r = r.replace("?",valnr,"g");
 			 }
 while (r.indexOf("!") > -1) {
 			 r = r.replace("!",valname, "g");
 			 }
 }
//show("valnr="+valnr,"valname=" + valname, r);
return updVal(r,valname);
}

function updVal(cd,valname){
cd = cd.split("¤");
var r0 = cd[0];
var r2 = cd[1];
var ds = "";
var isds = isDs("cls");
if (isds) {
	 qLoad(valname);
	 ds = getQlist();
 }
if (ds.length > 0){
	 r0 += valRows(ds, cd[2]);
  }
if (isds) {r0 += valButtons(ds.length>0);}
return r0 + r2;
}

function valRows(ds, r0) {
	 var a0 = '<tr><td valign="top" width="10%"><input type="radio" name="sel" onclick="window.opener.vertiTop.pickQList(this)"value="'; // d[0] "checked" attribute removed 2004-04-09
	 var a1 = '<tr><td width="10%" valign="top"><input type="radio" name="sel" onclick="window.opener.vertiTop.pickQList(this)" value="'; // d[0]
	 var a2 = '"></td><td width="40%">'; // valinnan nimi
	 var b  = '</td><td>';
	 var c  = '</td></tr>';
	 var i,k,sel,ti,r1,t;
	 ds = ds.split("¤"); 
	 for (i = 0; i < ds.length; i++) { 
	  	 r1 = (i==0) ? a0: a1;
  		 k= getItemKey(ds[i]);
			 sel=getItemValue(ds[i]).split("!"); // key,name,date,default,sum,query
 			 r1 += k + a2 + sel[0] + b + sel[1] + b + valDefault(sel[2],k) + c;
 			 r0 += r1;
 			 }
return r0;
}

function valDefault(sel,key) {
var r = '<input type="checkbox" name="' + "def" + key + '" '; 
if (sel =="1") r += 'checked ';
return r += ' onclick="window.opener.vertiTop.updDefCheckBox(this)" />';
}

function updDefCheckBox(ctl) {
var nm = ctl.name;
var key = nm.substring(3);
if (ctl.checked == false) {
	 dropDef(ctl.document.title, key);
	 }
else {
	 setDef(ctl.document.title,key);
	 }
var f = ctl.form.elements;
var v = "";
for (var i = 0; i<f.length; i++) {
		if (f[i].type == "checkbox" && f[i].name.indexOf("def") == 0) {
			 if (f[i].name != nm) {f[i].checked = false;}
			 v += ";"; 
			 v += (f[i].checked) ? "1" : "0";
		   }
		}
qColSet(2,v);
}

function valButtons(isList) {
var t,r;
t = getQlistText();
r = '<tr><td></td><td colspan="3">'
if (isList) {
	 r += '<input TYPE="BUTTON" VALUE="' + t[0] + '" name="SUBMIT1" onclick="javascript:window.opener.vertiTop.exeQList(this)">'
	 +    '<input TYPE="BUTTON" VALUE="' + t[1] + '" name="SUBMIT2" onclick="javascript:window.opener.vertiTop.dropQList(this)">'
	 +    '<input TYPE="BUTTON" VALUE="' + t[5] + '" name="SUBMIT3" onclick="javascript:window.opener.vertiTop.updQList(this)">';
	 }
return r;
}

function exeQList(ctl) {
var r = selQList(ctl);
if (r.length > 0) {
 ctl.form.expr.value=r[r.length-1]; 
 ctl.form.submit();
 }
return false;
}

function pickQList(ctl) {
var r = selQList(ctl);
if (r.length > 0) {
 ctl.form.expr.value=r[r.length-1]; 
 }
return false;
}

function selQKey(ctl) {
var f,k;
f = ctl.form.sel;
k = "¤";
if (!f) {alert("Error in selQKey");return "";}
if (f.length) {
	for (var i = 0; i < f.length; i++) {
	 		if (f[i].checked) {k += f[i].value;break;}
	 		} 
	if (k == "¤") {alert(getQlistText()[6]); ctl.focus();return "";}
	}
else {
	if (!f.checked) {alert(getQlistText()[6]); ctl.focus(); return "";}
	k += f.value;
	}
return k;
}

function selQList(ctl) {
var k = selQKey(ctl);
if (k.length == 0) return "";
return getItemValue(qGet(k)).split("!");
}

function dropQList(ctl) {
var r = selQKey(ctl);
if (r.length == 0) return false;
if(!dropConfirm(r,getQlistText()[4])){ val.focus(); return false;}
dropDef(ctl.document.title,r);
var h = qDrop(r)
h = qSize(h);
var w = (h>550) ? 730 : 680;
px.val.document.write(getVal(getValnr(),getQlistName()));
px.val.document.close();
px.val.resizeTo(w,h);
px.val.document.form1.expr.focus();
return false;
}

function updConfirm(r,cl) {
var s = "\n\n";
r = r[0] + ":" + s + getQlistText()[7] + "\n"  +  r[r.length-1] + s + getQlistText()[8] + s + cl;
return confirm(r);
}

function dropConfirm(k,txt) {
var s = "\n\n";
var r = getItemValue(qGet(k)).split("!");
r = txt + ":" + s + r[0]+ ", "  + r[1] + ":" + s + r[r.length-1]; 
return confirm(r);
}

function newQList(ctl) {
var f = ctl.form;
var t = f.expr.value;
var p = f.prompt.value;
var d = "";
window.focus();
d=qPrompt(p,d);
f.expr.focus();
if (!d) return false;
//var list = getQlist();
t =(t.length==0) ?  t + "*" : t; 
var h = qSet(d +  "!" + px.timeStamp() + "!0!0!" + t);
h = qSize(h)
var w = (h>550) ? 730 : 680;
px.val.document.write(getVal(getValnr(),getQlistName()));
px.val.document.close();
px.val.resizeTo(w,h);
px.val.document.form1.expr.focus();
return false;
}

function updQList(ctl) {
var key = selQKey(ctl);
if (key.length == 0) return false;
var r = getItemValue(qGet(key)).split("!")
var t = ctl.form.expr.value;
t =(t.length==0) ?  t + "*" : t; 
r[1] = timeStamp();
if(!updConfirm(r,t)){ val.focus(); return false;}
r[r.length-1] = t;
var h = qSet(key,r.join("!"));
val.document.form1.expr.focus();
return false;
}

function qPrompt(p,d) {
d=prompt(p,d);
if (!d) return d;
while (d.indexOf("!") >-1) d=d.replace("!","");
while (d.indexOf("¤") >-1) d=d.replace("¤","");
if (d.length > 0) return d;
else return null;
}

function getQuery(name) {
return (isDs()) ? getDsItem(activeDsn + "." + name) : getCookie(name);
}

function deleteQuery(name) {
if (isDs()) {dropDsItem(activeDsn + "." + name); }
else {deleteCookie(name); }
}

function getQueryNames(prefix) {
return (isDs()) ? getDsKeys(activeDsn) : getCookieNames(prefix);
}

function getNewQueryName(prefix) {
return (isDs()) ? getNewDsItemKey(activeDsn,prefix) : getNewCookieName(prefix);
}

function deleteAllQueries(prefix) {
var dir = getQueryNames(prefix);
if (dir.length == 0) return;
dir = dir.split(";");
var i = dir.length;
for (i = 0 ; i < dir.length; i++) {
		deleteQuery(dir[i]);
		}
}
/*
function isQueryTimeout() {
var r = false;
if (typeof(ds.document.SESSION)=="object" ) {
	 if (typeof(ds.document.SESSION.qtimeout)=="object" ) {
 	 		r = ds.document.SESSION.qtimeout.value == "TRUE";
	 }		
 }
return r
}

function setQueryTimeout(val){
if (arguments.length == 0) val="TRUE"; 
if (typeof(ds.document.SESSION)=="object" ) {
 	 if (typeof(ds.document.SESSION.qtimeout)=="object" ) {
	 		ds.document.SESSION.qtimeout.value=val;
	 }		
 }
}

function startQueryTimeout() {
setQueryTimeout("FALSE");
setTimeout("setQueryTimeout()",30000);
}				 

function odota() {
openMsgWindow("Haku kesken. Odota...");
}
*/
function openMsgWindow(msg) {
var code = getMsgWindow(msg);
var props = 'left=300,top=100,toolbar=no,location=no,directories=no,menubar=no,status=no,copyhistory=no,scrollbars=no,resizable=YES,width=350,height=100';
if (code.length > 0) {
 if (typeof(msgw)!="object" || (typeof(msgw)=="object" && isProp(msgw,"closed") && msgw.closed)) {
 	 		 msgw = window.open("","msgw",props);
	}
	if (typeof(msgw)=="object" && msgw != null) { 
 		 	 msgw.document.write(code);
 		 	 msgw.document.close();
	} else {
		 while (msg.indexOf("<br>")>-1) msg = msg.replace("<br>","\n");
		 alert(msg);
	}
 }
}

function isProp(obj, prop) {
if (obj != null) {
for (var i in obj) {
		if (i == prop) return true;
		}
}		
return false;
}

function closeMsgWindow() {
if (typeof(msgw)=="object" && msgw != null) {
	 if (!msgw.closed) msgw.close();
	 }
}

function getMsgWindow(msg) {
var r = "";
if (typeof(ds.document.SESSION)=="object" ) {
 r = ds.document.SESSION.msgwindow.value;
 r = r.replace("!",msg);
 }
return r
}

function closeWindow(w) {
if (typeof(w)=="object") {
	 if (!w.closed) w.close();
	 }
}

function chkQueryTimeout() {
if (isQueryTimeout()) 
	 { 
	 startQueryTimeout();
	 return true;
 	 }
else { odota();
	 return false;
	 }
}

function startDemo() {
px.location=gappl;
}

function isMenu() {
	 return typeof(menu)=="object";
}
		
function isSa(lnk) {
// varval ja varvalagg: kertoo missä aihealuelinkki
var t ="";
if (typeof(lnk.outerText)=="string") t = lnk.outerText;
if (typeof(lnk.text)=="string") t = lnk.text;
return t == getSaName();
}

function getSaName() {
var r ="";
if (typeof(ds.document.MENU)=="object" ) {
 r = ds.document.MENU.saname.value;
 }
return r; 
}

function isTableDir(lnk) {
// varval ja varvalagg: kertoo missä taulukkoluettelon linkki
var t ="";
if (typeof(lnk.outerText)=="string") t = lnk.outerText;
if (typeof(lnk.text)=="string") t = lnk.text;
return t == getTableDirName();
}

function getTableDirName() {
var r ="";
if (typeof(ds.document.MENU)=="object" ) {
 r = ds.document.MENU.tdname.value;
 }
return r; 
}

/*
function getMenuRole(){
	 var r = "";
	 var f = ds.document.MENU.role;
	 if (typeof(f) =="object") r = f.value;
	 return r; 
}
*/
function getMenufile(){
	 var f = (typeof(menu.document.MENU) == "object") ? menu.document.MENU : ds.document.MENU;
	 if (typeof(f) =="object") return f.menufile.value;
	 else return ""; 
}
function getMenudir(){
	 var f = (typeof(menu.document.MENU) == "object") ? menu.document.MENU : ds.document.MENU;
	 if (typeof(f) =="object") return f.menudir.value;
	 else return ""; 
}

function getFrontfile(){
	 var r = "";
	 var f = ds.document.SESSION.frontpage;
	 if (typeof(f) =="object") r = f.value;
	 return r; 
}

function toPx(url,path, name) {
 url = url.replace("!",getLang());
 if (px) {
  if (path) { // if path (and name) <==> Subject Area login  
		 var d = url.split("/");
		 url = getLoginHref(path,url,d[2],name,getLang())
		 }
	else {
		 if (isQtPicture() && url.indexOf(getQtdir())>-1) {
		 		var r = url.substring(url.lastIndexOf("/"),4 + url.indexOf(".asp"));
				url = url.replace(r,"");
				menu.toPxdir(url); return;
		    } 
		 url = setVirtualPath("",url);
		 }
	px.location = url;
	}
}
/*
sel() is used in menu commands
**/
function sel(a,b,c) {
if (menu.mSel && a == menu.mSel) {
// return one step backwards, if the selected row is the active row
    a = a.substring(0,a.length-1);
    a = a.replace(/ /g ,"");
    for (var i = 0;i<menu.mComm.length;i++) {
        if (menu.mComm[i].indexOf("sel('" + a + "'")>-1) {
            if (menu.mComm[i].indexOf("js:")) eval(menu.mComm[i].substring(3));
            else eval(menu.mComm[i]);
            return;
        }
    }
}
// move one step forward 
menu.mSel = a;
if (b){
    if (navigator.appName == "Opera") {
        setTimeout('menu.toPxDir("' + b + '","' + c + '")',300);
    }
    else menu.toPxDir(b,c);
}
menu.setMenu(a);
}

/*
selx() used navigation link commands 
where the backward step of sel is not appropriate
see main.js buildNaviControls()
**/

function selx(a,b,c) {
if (showLogo && isGedit()) showLogo(); //when returning from StatPage
menu.mSel = a;
if (b){
    if (navigator.appName == "Opera") {
        setTimeout('menu.toPxDir("' + b + '","' + c + '")',300);
        }
    else menu.toPxDir(b,c);
    }
menu.setMenu(a);
}


function startMenuPage(restart) {
	if (isMenu()) {
		 var m = (menu.location != "empty.htm") ? menu.location.pathname: getMenufile();
		 if (!restart) restart = false;
		    show("ds.onload","startMenupage()requests for frame mb:",
				m + getMenupars(),
				"restart=" + restart,
				"will call mb=" + (menu.location == "empty.htm" || restart),
				"menu.location now:",
				menu.location);		 
		 if (menu.location == "empty.htm" || restart) {
		 		menu.location= m + getMenupars();
		 }
	}			
}

function isQtPicture(){
var r = false;
if (typeof(ds.document.STATFILE)=="object" ) {
 r = ds.document.STATFILE.qtype.value == "PICTURE";
 }
return r;
}

function getInfo(cs,ptr) {
switch (cs) {
  case "DB" :
			 px.location=setVirtualPath("/DbInfo.aspx",gappl + "/menu") + "?case=DB";
	 		 return;
	case "QT" :
			 		px.location=setVirtualPath("/DbInfo.aspx",gappl + "/menu") + "?case=QT";
			return;
	case "SA" :
			 if (typeof(ptr)=="string") {
  		    px.location=setVirtualPath("/SaInfo.aspx",gappl + "/menu") + "?SA=" + ptr;
					}
			 return;
	default :
			return;
	}
}

function writeInfo(topic,cs,doc) {
var f = ds.document.STATFILE;
if (typeof(f) == "object") {
	 		switch (cs) {
  				 case "DB" :
			 		 			doc.write(getDbInfo(topic+"DB",f.dbinfo));
	 		 					return;
					 case "QT" :
			 		 			doc.write(getDbInfo(topic+"QT",f.qtinfo));
			 					return;
					 }
		 }			 
}

function getDbInfo(topic,f) {
	 		switch (topic){
	 		  case "HEADINGDB" :
	 					return getDbname();
	 		  case "HEADINGQT" :
	 					return getQtname();
				case "INFODB" :
				case "INFOQT" :
						return getInfoByLang(f);
				default:
				    return "";								
				}
}

function getInfoByLang(f) {
var lc = getLangCode();
var info = f.value;
var r = "";
var i = info.indexOf(lc + ":");
if (i > -1) {
	 r = info.substring(i+3).split("$")[0];
	 }
return r;
}

function isGedit() {
if (!isMenu()) return false;
return typeof(menu.document.GEDIT)=="object";
}

function setCtype(ctl) {
if (isEnabled()) {
	 document.forms[0].elements["_ctype"].value=ctl.name;
	 return true;
	 }
else return false;	 
}

/*
function restoreSaveShow() {
if (!hide.document.forms[0]) return;
	 var f =hide.document.forms[0];
	 for(var i = 0; i<f.elements.length; i++) {
	 f.elements[i].value=f.elements[i].value;
	 }
	 if (f.action.indexOf("Saveshow")>-1) f.submit();
}
*/
function copyHiddenFields(fr1,fr2) {
// copy fields from f2 to f1
// relevant field names in f2 are lowercase
f1 = fr1.document.forms[0];
f2 = fr2.document.forms[0];
var nm;
for (var i = 0; i<f1.elements.length; i++) {
		if (f1.elements[i].type == "hidden") {
				 nm = f1.elements[i].name.toLowerCase();
				 if (typeof(f2.elements[nm]) == "object") f1.elements[i].value = f2.elements[nm].value;
		}
  }
}

function submitForm(fm,path,target) {
var act = fm.action;
var tar = fm.target;
var met = fm.method;
fm.action = path;
fm.target = target;
fm.submit();
fm.action = act;
fm.target = tar;
fm.method = met;
}

function startWait() {
var w =logo.document.getElementById("wait");
if (w) w.style.visibility="visible";
}
function stopWait() {
var w =logo.document.getElementById("wait");
if (w) w.style.visibility="hidden";
}

function trim(value) {
// remove trailing and leading whitespace, \n,\r etc
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   return temp;
}
