var DOM = (document.getElementById)? true : false;
var OP = (window.opera)? true : false;
var OP5 = (OP && DOM)? true : false;
var NS = (window.outerWidth && !OP)? true : false;
var MOZ = (NS && DOM)? true : false;
var NS4 = (NS && !DOM)? true : false;
var IE = (document.all && !OP)? true : false;
var IE5 = (IE && DOM)? true : false;
var IE4 = (IE && !DOM)? true : false;
var WIN=(navigator.userAgent.indexOf('Win')!=-1)? true : false;
function thisObj(objName) { if(IE4) { return document.all[objName].style;} else if(DOM) {return document.getElementById(objName).style;} else if(NS4) {return document.layers[objName];} else return null; }
function moveObjTo(objName,x,y) {thisObj(objName).left=x;thisObj(objName).top=y;}

var InAction="";
var NewsID="";
EdelXorg=210;
EdelYorg=187;
var subdir = "";
var lang = "";
var href = document.location.href;
var s = href.split("/"); 
for (var i=2;i<(s.length-1);i++) {lang=s[i];}

if (lang == 'eng' || lang == 'swe' || lang == 'ger') {subdir="../"} else {lang='fin'};

MinusDown= new Image(); 
MinusDown.src = subdir+"images/btn_minus01.gif";    

MinusUp = new Image();
MinusUp.src = subdir+"images/btn_minus02.gif";     

PlusDown = new Image(); 
PlusDown.src = subdir+"images/btn_plus01.gif";    

PlusUp = new Image();
PlusUp.src = subdir+"images/btn_plus02.gif";     

Lang01= new Image(); 
Lang01.src = subdir+"images/language_01.gif";    

Lang02= new Image(); 
Lang02.src = subdir+"images/language_02.gif";    

Lang03= new Image(); 
Lang03.src = subdir+"images/language_03.gif";    

Lang04= new Image(); 
Lang04.src = subdir+"images/language_on.gif";    

CloseDown= new Image(); 
CloseDown.src = subdir+"images/close1.gif";    

CloseUp = new Image();
CloseUp.src = subdir+"images/close2.gif";     

function PutImage(img,Name,laye)
{
  if (navigator.platform && laye != '0' && document.layers)
  {
    document.layers[laye].document [Name].src =  eval(img+'.src');
  }
  else
  {
    document [Name].src = eval(img+'.src');
  }
}

function ShowLayer(LayerName)
{
  if(document.layers)
  {
    document.layers[LayerName].visibility = 'show';
  }
  else if(document.all)
  {
    document.all[LayerName].style.visibility = 'visible';
  }
  else if(document.getElementById)
  {
    document.getElementById(LayerName).style.visibility = 'visible';
  }
}

function HideLayer(LayerName)
{
  if(document.layers)
  {
    document.layers[LayerName].visibility = 'hide';
  }
  else if(document.all)
  {
    document.all[LayerName].style.visibility = 'hidden';
  }
  else if(document.getElementById)
  {
    document.getElementById(LayerName).style.visibility = 'hidden';
  }
}


korjausX=0;korjausY=0;
korjausX=8;korjausY=-100;
FixedX=450;
InfoLastOne="Info01";
PalautusAsia="odottaa";

function FormStart()
{
  if (getCookie('TilimaticUsername')) window.document.lomake.nimi.value=getCookie('TilimaticUsername');
  if (getCookie('TilimaticUserTitle')) window.document.lomake.titteli.value=getCookie('TilimaticUserTitle');
  if (getCookie('TilimaticUserCompany')) window.document.lomake.yritys.value=getCookie('TilimaticUserCompany');
  if (getCookie('TilimaticUserEmail')) window.document.lomake.email.value=getCookie('TilimaticUserEmail');
  if (getCookie('TilimaticUserGSM')) window.document.lomake.gsm.value=getCookie('TilimaticUserGSM');

  window.document.lomake.nimi.focus();
  window.document.lomake.ottakaa_yhteytta_sahkopostitse.checked=false;
  window.document.lomake.ottakaa_yhteytta_puhelimitse.checked=false;
}

function HelpCursorOn(LayerName)
{
  if (!is.ns4) ShowLayer(LayerName);
  if (window.event && !is.ns) moveObjTo(LayerName,window.event.clientX+korjausX,window.event.clientY+korjausY);
}

function HelpCursorOff(LayerName)
{
  if (!is.ns4) HideLayer(LayerName);
  if (window.event && !is.ns) moveObjTo(LayerName,1,1);
}

function Checking(Name)
{
  if(window.document.lomake[Name].checked)
  {
    window.document.lomake[Name].checked=false;
  }
  else
  {
    window.document.lomake[Name].checked=true;
  }
}

function RadioChecking(NameOn,NameOff)
{
  window.document.lomake[NameOn].checked=true;
  window.document.lomake[NameOff].checked=false;
  PalautusAsia="ok";
}

function RadioOff(NameOff)
{
  window.document.lomake[NameOff].checked=false;
  PalautusAsia="ok";
}

function FormCheck2()
{
  setCookie('TilimaticUsername', window.document.lomake.nimi.value, expire,'/');
  setCookie('TilimaticUserTitle', window.document.lomake.titteli.value, expire,'/');
  setCookie('TilimaticUserCompany', window.document.lomake.yritys.value, expire,'/');
  setCookie('TilimaticUserEmail', window.document.lomake.email.value, expire,'/');
  setCookie('TilimaticUserGSM', window.document.lomake.gsm.value, expire,'/');

  var lastpath = "";
  var pathwithoutlast = "";
  var pathwithlast = "";
  var pagename = "";
  var begin = window.location.protocol + "//"
  if (begin == "") begin = "http://";
  var href = document.location.href;
  var s = href.split("/"); 
  for (var i=2;i<(s.length-1);i++)
  {
    if (i<s.length-2) pathwithoutlast+=s[i] + "/";
    pathwithlast+=s[i] + "/";
    lastpath=s[i];
  }
  window.document.lomake.kiitossivu.value=begin+pathwithlast+'thankyou.html';


  window.document.lomake.submit();
}

function FormCheck()
{
  setCookie('TilimaticUsername', window.document.lomake.nimi.value, expire,'/');
  setCookie('TilimaticUserTitle', window.document.lomake.titteli.value, expire,'/');
  setCookie('TilimaticUserCompany', window.document.lomake.yritys.value, expire,'/');
  setCookie('TilimaticUserEmail', window.document.lomake.email.value, expire,'/');
  setCookie('TilimaticUserGSM', window.document.lomake.gsm.value, expire,'/');

  if(window.document.lomake.nimi.value && window.document.lomake.titteli.value && window.document.lomake.yritys.value && window.document.lomake.email.value)
  {
    var lastpath = "";
    var pathwithoutlast = "";
    var pathwithlast = "";
    var pagename = "";
    var begin = window.location.protocol + "//"
    if (begin == "") begin = "http://";
    var href = document.location.href;
    var s = href.split("/"); 
    for (var i=2;i<(s.length-1);i++)
    {
      if (i<s.length-2) pathwithoutlast+=s[i] + "/";
      pathwithlast+=s[i] + "/";
      lastpath=s[i];
    }
    window.document.lomake.kiitossivu.value=begin+pathwithlast+'thankyou.html';

    window.document.lomake.submit();
  }
  else
  {
      if (lang == 'fin') { alert("Täytä vähintään (*)-merkityt kohdat."); return false;}
      if (lang == 'ger') { alert("Please fill in all the fields filled with asterisk (*)."); return false;}
      if (lang == 'eng') { alert("Please fill in all the fields filled with asterisk (*)."); return false;}
      if (lang == 'swe') { alert("De fält som är märkta med (*) är obligatoriska."); return false;}
  }
}

function FormEmpty()
{
  setCookie('TilimaticUsername', '', expire,'/');
  setCookie('TilimaticUserTitle', '', expire,'/');
  setCookie('TilimaticUserCompany', '', expire,'/');
  setCookie('TilimaticUserEmail', '', expire,'/');
  setCookie('TilimaticUserGSM', '', expire,'/');
  window.document.lomake.nimi.value = '';
  window.document.lomake.titteli.value = '';
  window.document.lomake.yritys.value = '';
  window.document.lomake.email.value = '';
  window.document.lomake.gsm.value = '';
  window.document.lomake.viesti.value = '';
  window.document.lomake.ottakaa_yhteytta_sahkopostitse.checked=false;
  window.document.lomake.ottakaa_yhteytta_puhelimitse.checked=false;
  window.document.lomake.ei_halua_mainospostia.checked=false;
  window.document.lomake.nimi.focus();
}

function getArgs(  ) {
  var args = new Object(  );
  var query = location.search.substring(1);     
  var pairs = query.split(",");
  for(var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf('=');
    if (pos == -1) continue;
    var argname = pairs[i].substring(0,pos);
    var value = pairs[i].substring(pos+1);
    args[argname] = unescape(value);
    // Store as a property
    // In JavaScript 1.5, use decodeURIComponent(  ) 
    // instead of escape(  )
  }
  return args;
}

var today = new Date()
var expire = new Date()
expire.setTime(today.getTime() + 1000*60*60*24*365)

function setCookie(name, value, expire,path) {
  var currentCookie = name + "=" +
  escape(value) +
  ((expire == null) ?
    ("; expires=" + defaultExpire.toGMTString()) : 
    ("; expires=" + expire.toGMTString()));
  if (path=="/") {currentCookie+=";path="+path+";";}
  document.cookie = currentCookie;
}

function getCookie(name) {
  var prefix = name + "="
  var cookieStartIndex = document.cookie.indexOf(prefix)
  if (cookieStartIndex == -1)
    return null
  var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
  if (cookieEndIndex == -1)
    cookieEndIndex = document.cookie.length
  return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function deleteCookie(name) { 
  var exp = new Date(); 
  exp.setTime(exp.getTime() - 1); 
  var cval = getCookie(name); 
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var sURL = window.location.pathname;

function reload()
{
  window.location.href = sURL;
}

function FontSize (dir)
{
  fontsize = parseInt(fontsize);
  if (dir == 1) fontsize -= 1;
  if (dir == 2) fontsize += 1;
  if (fontsize >= 15) fontsize=15;
  if (fontsize <= 8) fontsize=8;

  setCookie('TilimaticFont', fontsize, expire);

  if (is.ie) {
    ChangePageFonts();
  }
  else {
    reload();
  }
}

function GoLink(where)
{
  window.location = where+'?fontsize='+fontsize;
}

function GoNews(where,news)
{
  window.location = where+'?fontsize='+fontsize+',news='+news;
}

function ChangeLang(lang)
{
  var lastpath = "";
  var pathwithoutlast = "";
  var pathwithlast = "";
  var pagename = "";
  var begin = window.location.protocol + "//"
  if (begin == "") begin = "http://";
  var href = document.location.href;
  var s = href.split("/"); 
  for (var i=2;i<(s.length-1);i++) {
  if (i<s.length-2) pathwithoutlast+=s[i] + "/";
  pathwithlast+=s[i] + "/";
  lastpath=s[i];
  }
  i=s.length-1;
  pagename=s[i];
  var gopage = pagename.split("?"); 
  pagename=gopage[0];

  setCookie('TilimaticLangu', lang, expire,'/');

  if (lang == 'ger' && (lastpath == 'swe' || lastpath == 'eng')) GoLink(begin+pathwithoutlast+'ger/'+pagename);
  if (lang == 'ger' && lastpath != 'eng' && lastpath != 'swe' && lastpath != 'ger') GoLink(begin+pathwithlast+'ger/'+pagename);
  if (lang == 'eng' && (lastpath == 'swe' || lastpath == 'ger')) GoLink(begin+pathwithoutlast+'eng/'+pagename);
  if (lang == 'eng' && lastpath != 'eng' && lastpath != 'swe' && lastpath != 'ger') GoLink(begin+pathwithlast+'eng/'+pagename);
  if (lang == 'swe' && (lastpath == 'eng' || lastpath == 'ger')) GoLink(begin+pathwithoutlast+'swe/'+pagename);
  if (lang == 'swe' && lastpath != 'swe' && lastpath != 'eng' && lastpath != 'ger') GoLink(begin+pathwithlast+'swe/'+pagename);
  if (lang == 'fin' && (lastpath == 'eng' ||  lastpath == 'swe' ||  lastpath == 'ger')) GoLink(begin+pathwithoutlast+pagename);
}

var actiontime=0;

function Encore ()
{
  setCookie('TilimaticLangu', lang, expire,'/');
}

function ShowNavi ()
{
  if (actiontime==0) {
    actiontime=1;
    setTimeout("PutImage('Lang01','langbarani','languagetease');",100);
    setTimeout("PutImage('Lang02','langbarani','languagetease');",200);
    setTimeout("PutImage('Lang03','langbarani','languagetease');",300);
    setTimeout("PutImage('Lang04','langbarani','languagetease');",400);
    setTimeout("ShowLayer('languagebar');actiontime=0;",800);
    FadingTimer=setTimeout("HideNavi();",3000);
  }
}

function HideNavi ()
{
  if (actiontime==0) {
    actiontime=1;
    setTimeout("HideLayer('languagebar');",10);
    setTimeout("PutImage('Lang04','langbarani','languagetease');",100);
    setTimeout("PutImage('Lang03','langbarani','languagetease');",200);
    setTimeout("PutImage('Lang02','langbarani','languagetease');",300);
    setTimeout("PutImage('Lang01','langbarani','languagetease');actiontime=0;",400);
  }
}

function LetNaviLive (ok)
{
  if (ok==0) FadingTimer=setTimeout("HideNavi();",100);
  if (ok==1) clearTimeout(FadingTimer);
}

function ShowImage(thislayer,TargImg)
{
  window.focus();
  if(document.layers)
  {
    document.layers[thislayer].visibility = 'show';
  }
  else if(document.all)
  {
    document.all[thislayer].style.visibility = 'visible';
  }
    else if(document.getElementById)
  {
    document.getElementById(thislayer).style.visibility = 'visible';
  }
  if (navigator.platform && thislayer != '0' && document.layers)
  {
     document.layers[thislayer].document ['TheImage'].src = subdir+TargImg;
  }
  else
  {
    document ['TheImage'].src = subdir+TargImg;
  }
}






function DynLayer(id,nestref,frame) {
	if (!DynLayer.set && !frame) DynLayerInit()
	this.frame = frame || self
	if (is.ns) {
		if (is.ns4) {
			if (!frame) {
				if (!nestref) var nestref = DynLayer.nestRefArray[id]
				if (!DynLayerTest(id,nestref)) return
				this.css = (nestref)? eval("document."+nestref+".document."+id) : document.layers[id]
			}
			else this.css = (nestref)? eval("frame.document."+nestref+".document."+id) : frame.document.layers[id]
			this.elm = this.event = this.css
			this.doc = this.css.document
		}
		if (is.ns5) {
			this.elm = document.getElementById(id)
			this.css = this.elm.style
			this.doc = document
		}
		this.x = this.css.left
		this.y = this.css.top
		this.w = this.css.clip.width
		this.h = this.css.clip.height
	}
	else if (is.ie) {
		this.elm = this.event = this.frame.document.all[id]
		this.css = this.frame.document.all[id].style
		this.doc = document
		this.x = this.elm.offsetLeft
		this.y = this.elm.offsetTop
		this.w = (is.ie4)? this.css.pixelWidth : this.elm.offsetWidth
		this.h = (is.ie4)? this.css.pixelHeight : this.elm.offsetHeight
	}
	this.id = id
	this.nestref = nestref
	this.obj = id + "DynLayer"
	eval(this.obj + "=this")
}
function DynLayerMoveTo(x,y) {
	if (x!=null) {
		this.x = x
		if (is.ns) this.css.left = this.x
		else this.css.pixelLeft = this.x
	}
	if (y!=null) {
		this.y = y
		if (is.ns) this.css.top = this.y
		else this.css.pixelTop = this.y
	}
}
function DynLayerMoveBy(x,y) {
	this.moveTo(this.x+x,this.y+y)
}
function DynLayerShow() {
	this.css.visibility = (is.ns)? "show" : "visible"
}
function DynLayerHide() {
	this.css.visibility = (is.ns)? "hide" : "hidden"
}
DynLayer.prototype.moveTo = DynLayerMoveTo
DynLayer.prototype.moveBy = DynLayerMoveBy
DynLayer.prototype.show = DynLayerShow
DynLayer.prototype.hide = DynLayerHide
DynLayerTest = new Function('return true')

// DynLayerInit Function
function DynLayerInit(nestref) {
	if (!DynLayer.set) DynLayer.set = true
	if (is.ns4) {
		if (nestref) ref = eval('document.'+nestref+'.document')
		else {nestref = ''; ref = document;}
		for (var i=0; i<ref.layers.length; i++) {
			var divname = ref.layers[i].name
			DynLayer.nestRefArray[divname] = nestref
			var index = divname.indexOf("Div")
			if (index > 0) {
				eval(divname.substr(0,index)+' = new DynLayer("'+divname+'","'+nestref+'")')
			}
			if (ref.layers[i].document.layers.length > 0) {
				DynLayer.refArray[DynLayer.refArray.length] = (nestref=='')? ref.layers[i].name : nestref+'.document.'+ref.layers[i].name
			}
		}
		if (DynLayer.refArray.i < DynLayer.refArray.length) {
			DynLayerInit(DynLayer.refArray[DynLayer.refArray.i++])
		}
	}
	else if (is.ie) {
		for (var i=0; i<document.all.tags("DIV").length; i++) {
			var divname = document.all.tags("DIV")[i].id
			var index = divname.indexOf("Div")
			if (index > 0) {
				eval(divname.substr(0,index)+' = new DynLayer("'+divname+'")')
			}
		}
	}
	return true
}
DynLayer.nestRefArray = new Array()
DynLayer.refArray = new Array()
DynLayer.refArray.i = 0
DynLayer.set = false

// Clip Methods
function DynLayerClipInit(clipTop,clipRight,clipBottom,clipLeft) {
	if (is.ie) {
		if (arguments.length==4) this.clipTo(clipTop,clipRight,clipBottom,clipLeft)
		else if (is.ie4) this.clipTo(0,this.css.pixelWidth,this.css.pixelHeight,0)
	}
}
function DynLayerClipTo(t,r,b,l) {
	if (t==null) t = this.clipValues('t')
	if (r==null) r = this.clipValues('r')
	if (b==null) b = this.clipValues('b')
	if (l==null) l = this.clipValues('l')
	if (is.ns) {
		this.css.clip.top = t
		this.css.clip.right = r
		this.css.clip.bottom = b
		this.css.clip.left = l
	}
	else if (is.ie) this.css.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"
}
function DynLayerClipBy(t,r,b,l) {
	this.clipTo(this.clipValues('t')+t,this.clipValues('r')+r,this.clipValues('b')+b,this.clipValues('l')+l)
}
function DynLayerClipValues(which) {
	if (is.ie) var clipv = this.css.clip.split("rect(")[1].split(")")[0].split("px")
	if (which=="t") return (is.ns)? this.css.clip.top : Number(clipv[0])
	if (which=="r") return (is.ns)? this.css.clip.right : Number(clipv[1])
	if (which=="b") return (is.ns)? this.css.clip.bottom : Number(clipv[2])
	if (which=="l") return (is.ns)? this.css.clip.left : Number(clipv[3])
}
DynLayer.prototype.clipInit = DynLayerClipInit
DynLayer.prototype.clipTo = DynLayerClipTo
DynLayer.prototype.clipBy = DynLayerClipBy
DynLayer.prototype.clipValues = DynLayerClipValues

// Write Method
function DynLayerWrite(html) {
	if (is.ns) {
		this.doc.open()
		this.doc.write(html)
		this.doc.close()
	}
	else if (is.ie) {
		this.event.innerHTML = html
	}
}
DynLayer.prototype.write = DynLayerWrite

function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = ((this.b=="ie" && this.v>=4) || this.v>=6)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.min = (this.ns||this.ie)
}
is = new BrowserCheck()

var FixX = -80;
var FixY = -120;
var FX = 0;
var FY = 0;
EdelX=EdelXorg;
EdelY=EdelYorg;
DragPoint=0;

function init() {
  dragObject = new DynLayer("ImageDrag")
  dragObject.dragActive = false
  dragObject2 = new DynLayer("ImageZoom")
  dragObject3 = new DynLayer("DragBar")
  dragObject3.dragActive = false	
  document.onmousedown = mouseDown
  document.onmousemove = mouseMove
  document.onmouseup = mouseUp
  if (is.ns) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
  ClickingOff();
}

function mouseDown(e) {
  if ((is.ns && e.which!=1) || (is.ie && event.button!=1)) return true
  var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft
  var y = (is.ns)? e.pageY : event.y+document.body.scrollTop
  if (x>=dragObject.x && x<=dragObject.x+dragObject.w && y>=dragObject.y && y<=dragObject.y+dragObject.h) {
    dragObject.dragActive = true
    return false;
  }
  if (x>=dragObject3.x && x<=dragObject3.x+dragObject3.w && y>=dragObject3.y && y<=dragObject3.y+dragObject.h) {
    dragObject3.dragActive = true
    return false;
  }
  else { return true; }
}

function mouseMove(e) {
  var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft
  var y = (is.ns)? e.pageY : event.y+document.body.scrollTop
  if (dragObject.dragActive || dragObject3.dragActive) {
    if (DragPoint==0) { DragPoint=1; FX=EdelX-x;FY=EdelY-y;}	
    window.focus();
    if (x+FX <= 0) { x=0-FX }
    if (y+FY <= 14) { y=14-FY }
    dragObject.moveTo(x+FX,y+FY)
    dragObject2.moveTo(x+FX,y+FY-14)
    dragObject3.moveTo(x+FX,y+FY-14)
    EdelX=x+FX; EdelY=y+FY;
    return false;
  }
  else { return true; }
}

function ClickingHelp() {
  window.focus();
  if (ImageOpened==0){
    var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft
    var y = (is.ns)? e.pageY : event.y+document.body.scrollTop
    DragPoint=0;
  }
}

function mouseUp(e) {
  var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft
  var y = (is.ns)? e.pageY : event.y+document.body.scrollTop
  dragObject.dragActive = false;
  dragObject3.dragActive = false;
  DragPoint=0;
  return true;
}

var ImageOpened=0;

function ClickingPlace()
{
  if (is.ns4 || is.ie) {
    EdelX=EdelXorg; EdelY=EdelYorg;
    dragObject2.moveTo(EdelX,EdelY-14)
    dragObject3.moveTo(EdelX,EdelY-14)
    dragObject.moveTo(EdelX,EdelY)
    ImageOpened=1;
  }
}

function ClickingOff()
{
  if (is.ns4 || is.ie) {
    EdelX=EdelXorg; EdelY=EdelYorg;
    dragObject2.moveTo(-400,-400)
    dragObject3.moveTo(-400,-400)
    dragObject.moveTo(-400,-400)
    var ImageOpened=0;
  }
}

