function pviiClassNew(obj, new_style) { //v2.7 by PVII
  obj.className=new_style;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function check_form(lan) { //Jere Tiihonen
	var errors=''
	var fields = new Array('nimi','lahiosoite','postinumero','postitoimipaikka','puhelin','sahkoposti','maksutapa');
	var k_fields = new Array('kortinnumero','kortinkuukausi','kortinvuosi','kortintunnus')
	var k_test = new Array('n','r','r','n')
	
	if (lan == 'fin'){
		var names = new Array('Nimi','Lähiosoite','Postinumero','Toimipaikka','Puhelin','Sähköposti','Maksutapa');
		var test = new Array('r','r','r','r','r','e','m')
		var error_msg = new Array(' puuttuu\n','- Valitse ','- Valitse maksutapa\n','- Sähköpostiosoite ei ole oikein\n')
		var k_names = new Array('Luottokortin numero','Luottokortin kuukausi','Luottokortin vuosi','Luottokortin tunnus')
		var card_errors = new Array('numeroissa ei saa olla välejä\n',' pitää olla numero\n')
		var error_txt = 'Tilauksesta puuttuu seuraavat tiedot tai ne ovat virheellisiä:\n'
	}else{
		fields[6] = 'country'
		fields[7] = 'maksutapa'
		var names = new Array('Name','Address','Zip/postal code','City','Phone','E-mail address','country','Payment');
		var test = new Array('r','r','r','r','r','e','c','m')
		var error_msg = new Array(' missing\n','- Choose ','- Choose payment\n','- E-mail address is not valid\n')
		var error_txt = 'The following error(s) occurred:\n'
		k_names = new Array('Credit card number','Month','Year','Card verification number')
		card_errors = new Array('umber has space(s)\n',' has to be number\n')
	}

	for (i = 0; i<fields.length; i+=1) { 
		val=MM_findObj(fields[i]);
    	if (val) { 
			if (val.value != "") {
    	  		if (test[i] == 'e') { 
					p = val.value.indexOf('@');
        			if (p < 1 || p == (val.length-1)) errors += error_msg[3];
				} else if (test[i] == 'm') {
					if (val[0].checked || val[1].checked){
						for (ii = 0; ii < k_fields.length; ii += 1){
							test_obj = MM_findObj(k_fields[ii]);
							if (test_obj.value != ""||test_obj.type == 'select-one'){
								if (k_test[ii] == 'n' && isNaN(test_obj.value)){
									if (test_obj.value.indexOf(' ') != -1){
										errors += '- ' + k_names[ii].substr(0,13) + card_errors[0]
									}else errors += '- ' + k_names[ii] + card_errors[1]
								}else if (k_test[ii]=='r'){
									if (test_obj.selectedIndex==0) errors += error_msg[1] + k_names[ii] + '\n';
								}
							}else errors += '- ' + k_names[ii] + error_msg[0];
						}
					}else if(lan == 'fin'){
						if (!val[2].checked && !val[3].checked && !val[4].checked && !val[5].checked) errors += error_msg[2];
					}else{
						errors += error_msg[2];
					}
				} else if (test[i]=='c'){
					if (val.selectedIndex==0) errors += error_msg[1] + names[i] + '\n';
				}
			} else errors += '- '+names[i]+error_msg[0]; 
		}
	} 
	if (errors) alert(error_txt + errors);
	document.return_value = (errors == '');
}
function cancel_order(lan,id){
	msg_txt = "Haluatko varmasti peruuttaa tilauksen ?";
	re_url = "ostoskori.asp?lan="+lan
	if (lan == 'eng'){
		msg_txt = "Are you sure ?";
	}else if (id != null){
		re_url = "tilauslomake.asp?lan="+lan+"&id="+id
	}
	agree=confirm(msg_txt)
	if(agree==true){
		window.location.replace(re_url);
	}
}

function update_ostoskori(job,tuote_id,sub_id,osasto_kieli) {
	var tilaus_data = new Array();
	var tuote_maara
	var tuote_old_maara;
	var new_cookie = "";
	var i = 0
	if 	(WM_readCookie('teraasekeskus') != false)
		{
		tilaus_data = WM_readCookie('teraasekeskus').split("-");
		}
	loop = tilaus_data.length - 1;
	write_cookie = true;

	switch (job){
		case 1: // lisays
			tuote_is = false;
			//write_cookie = false;
			new_cookie = WM_readCookie('teraasekeskus');
			tuote_koko = MM_findObj('koko_'+ tuote_id +'_'+ sub_id);
			if (tuote_koko != null && tuote_koko.options[tuote_koko.selectedIndex].value == "")
				{
				alert('Valitse tilattava koko!');
				write_cookie = false;
				}else if(tuote_koko)
					{
					tuote_koko = '_'+ tuote_koko.options[tuote_koko.selectedIndex].value;
					//alert(tuote_koko);
					}
			for (i = 0 ; i < loop ; i++) 
				{
				if (tilaus_data[i].substring(0,(tilaus_data[i].indexOf("/"))) == tuote_id && tilaus_data[i].substring((tilaus_data[i].indexOf("/") + 1),(tilaus_data[i].indexOf("/") + 2)) == sub_id)
					{
					alert("tuote on jo ostoskorissa!");
					tuote_is = true;
					write_cookie = false;
					break;
					}
				}
			if (tuote_is != true)
				{
				if (tuote_koko == null)
					{
					tuote_koko = "";
					}
				new_cookie = new_cookie + tuote_id +'/'+  sub_id + tuote_koko +'/1-'
				}
			break
		case 2: // maara
			for (i = 0 ; i < loop ; i++) 
				{
				tuote_new_maara = document.ostoskori.elements['tuote_kpl_' + i].value;
				tuote_maara = tilaus_data[i].substring((tilaus_data[i].indexOf("/") + 3),(tilaus_data[i].length));
				if(tuote_new_maara != tuote_maara)
					{
					tilaus_data[i] = tilaus_data[i].substring(0,((tilaus_data[i].length) - 1)) + tuote_new_maara;
					}
				new_cookie = new_cookie + tilaus_data[i] + "-";
				}
			break    
		case 3:	// tyhjennys
			write_cookie = false
			confirm_delete = confirm('Haluatko varmasti tyhjentää ostoskorin ?')
			if (confirm_delete == true) 
				{
				new_cookie = "";
				write_cookie = true;
				}
			break
		case 4: // poisto
			while(i < loop)
				{
				if (tilaus_data[i].substring(0,(tilaus_data[i].indexOf("/"))) == tuote_id && tilaus_data[i].substring((tilaus_data[i].indexOf("/") + 1),(tilaus_data[i].indexOf("/") + 2)) == sub_id)
					{
					i++;
					}
					else
						{
						new_cookie = new_cookie + tilaus_data[i] + "-";
						i++;
						}
				}
			break
		}
	if (write_cookie == true)
		{
		WM_setCookie("teraasekeskus",new_cookie,'','/');
		if (job != 1)
			{
			window.location.replace("ostoskori.asp?lan=" + osasto_kieli)
			}else
				{
				window.parent.ostoskori.location = "ostoskori_info.asp?lan=" + osasto_kieli;
				}
		}
	}
	
function WM_setCookie (name, value, hours, path, domain, secure) {
	var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.

}

function WM_readCookie(name) {
    if(document.cookie == '') {return false; 
    	}else{var firstChar, lastChar;var theBigCookie=document.cookie;firstChar=theBigCookie.indexOf(name);var NN2Hack=firstChar+name.length;
		if((firstChar!=-1)&&(theBigCookie.charAt(NN2Hack)=='=')){firstChar+=name.length+1;lastChar=theBigCookie.indexOf(';', firstChar);
	    if(lastChar==-1) lastChar = theBigCookie.length;
	    return unescape(theBigCookie.substring(firstChar, lastChar));
	}else{return false;}}	
}

function checkPalaute(lan) {
	if (lan == 'fin'){
		alert_txt = 'Et ole kirjoittanut mitään palautetta !';
	}else{
		alert_txt = 'Please, write some feedback !';
	}
	document.return_value = true
	if (document.palauteLomake.palaute.value==""){
		alert(alert_txt);
		document.return_value = false;
	}
}

function openBrWindow(lan,ID) {
	if(ID=='ehdot'){openwin="sopimusehdot.htm"}
	else if(ID=='ohje'){openwin="ohje.htm"}
	else{openwin="ostoskori_tuote_info.asp?ProductID="+ID+"&lan="+lan}
	window.open(openwin,"popup","scrollbars=yes,width=495,height=450");
}

function actFloatLayer(slideTime,layer_top,layer_height,browser) // modded by Jere Tiihonen
	{  
	switch(browser)
		{
			case (1):
				//find = document.body.clientHeight;
				find = (document.compatMode=="CSS1Compat")?document.documentElement.clientHeight:document.body.clientHeight;
				current = menu_base.style.pixelTop;
				scrollAt = (document.compatMode=="CSS1Compat")?document.documentElement.scrollTop:document.body.scrollTop;
				break;
			case (2): 
				find = window.innerHeight;
				current = document.menu_base.top;
				scrollAt = window.pageYOffset;
				break;
			case (3): 
				find = window.innerHeight;
				current = parseInt(document.getElementById('menu_base').style.top);
				scrollAt = window.scrollY;
				break;
		}

	if (isNaN(Math.log(scrollAt-=layer_top))) scrollAt = 0;
	newTarget = scrollAt;
	if (find < layer_height)
		{
		do_this_shit = false;
		if (scrollAt - (layer_height - find) > current)
			{
			newTarget -= (layer_height - find);
			do_this_shit = true;
			}
			else if (scrollAt < current)
				{
				do_this_shit = true;
				}
		}
		else
			{
			do_this_shit = true;
			}

	if ( current != newTarget && do_this_shit == true)
		{        
		if (newTarget !=  this.target ) 
			{ 
			target = newTarget;
			now = new Date();
			Mul = target - current; // 
			Wave = Math.PI / ( 2 * slideTime );
			Pass = now.getTime();
			if (Math.abs(Mul) > find) 
				{ 
				Dis = (Mul > 0) ? target - find : target + find ;
				Mul = (Mul > 0) ? find : -find ;
				}
				else
					{
					Dis = current
					} 
			}
		now = new Date();
		newPosition = Mul * Math.sin( Wave * ( now.getTime() - Pass ) ) + Dis;
		newPosition = Math.round(newPosition);
		if (( Mul > 0 && newPosition > current ) || ( Mul < 0 && newPosition < current )) 
			{ 
			switch(browser)
				{
					case (1):
						menu_base.style.pixelTop = newPosition;
						break;
					case (2):
						document.menu_base.top = newPosition;
						break;
					case (3):
						document.getElementById('menu_base').style.top = newPosition + 'px';
						break;
				}
			}       
		}
	}

function startFloatLayer() 
	{
	var browser;
	if (document.all)  //ie4
		{
		browser = 1;
		layer_height = document.all['menu_main'].clientHeight;
		layer_top = document.all['menu_base'].offsetTop;
		}
	if (document.layers)  //ns4
		{
		browser = 2;
		layer_top = 77;
		layer_height = document.menu_base.document.menu_main.document.height
		}
	if (!document.all && document.getElementById) //ns6 
		{
		browser = 3;
		layer_height = parseInt(document.getElementById('menu_main').offsetHeight);
		layer_top = parseInt(document.getElementById('menu_base').offsetTop);
		}
	//alert(browser)
	//alert(document.getElementById('menu_base').style.top);
	setInterval("actFloatLayer(600," + layer_top + "," + layer_height +"," + browser + ")",10);
	}
function openPictureWindow_Fever(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) {  // v4.01
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	if (imageType == "swf"){
	newWindow.document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
	newWindow.document.write('<param name=movie value=\"'+imageName+'\"><param name=quality value=high>');
	newWindow.document.write('<embed src=\"'+imageName+'\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
	newWindow.document.write('</embed></object>');	}else{
	newWindow.document.write('<img src=\"'+imageName+'\" width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\">'); 	}
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}