function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}



// bbCode control by
// subBlue design
// www.subBlue.com

// Startup variables
var imageTag = false;
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav  = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));

var is_win   = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac    = (clientPC.indexOf("mac")!=-1);


// Helpline messages
b_help = "Lihavointi: [b]text[/b]";
i_help = "Kursivointi: [i]text[/i]";
u_help = "Alleviivaus: [u]text[/u]";
q_help = "Lainaus: [quote]text[/quote]  (alt+q)";
e_help = "Lisää Email-linkki: [email]email[/email]";
l_help = "Luettelo: [list]text[/list] (alt+l)";
o_help = "Järjestetty luettelo: [list=]text[/list]  (alt+o)";
t_help = "Lisää Tabulointi (alt+t)";
w_help = "Lisää URL: [url]http://url[/url] or [url=http://url]URL text[/url]";
a_help = "Sulje kaikki avoimet bbCode tagit";
s_help = "Fontin väri: [color=red]text[/color]  Vihje: voit käyttää myös color=#FF0000";
f_help = "Fontin koko: [size=x-small]small text[/size]";

// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[email]','[/email]','[list]','[/list]','[list=]','[/list]','\t','\t','[url]','[/url]');
imageTag = false;

// Shows the help messages in the helpline window
function helpline(help) {
	document.post.helpbox.value = eval(help + "_help");
}


// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}


function checkForm() {

	formErrors = false;

	if (document.post.para_text.value.length < 2) {
		formErrors = "Sinun on kirjoitettava jotain tekstikenttään!";
	}

	if (formErrors) {
		alert(formErrors);
		return false;
	} else {
		bbstyle(-1);
		//formObj.preview.disabled = true;
		//formObj.submit.disabled = true;
		return true;
	}
}

function emoticon(text) {
	text = ' ' + text + ' ';
	if (document.post.para_text.createTextRange && document.post.para_text.caretPos) {
		var caretPos = document.post.para_text.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.post.para_text.focus();
	} else {
	document.post.para_text.value  += text;
	document.post.para_text.focus();
	}
}

function bbfontstyle(bbopen, bbclose) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			document.post.para_text.value += bbopen + bbclose;
			document.post.para_text.focus();
			return;
		}
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		document.post.para_text.focus();
		return;
	} else {
		document.post.para_text.value += bbopen + bbclose;
		document.post.para_text.focus();
		return;
	}
	storeCaret(document.post.para_text);
}


function bbstyle(bbnumber) {

	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (bbnumber == -1) { // Close all open tags & default button names
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			document.post.para_text.value += bbtags[butnumber + 1];
			buttext = eval('document.post.addbbcode' + butnumber + '.value');
			eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		document.post.para_text.focus();
		return;
	}

	if ((clientVer >= 4) && is_ie && is_win)
		theSelection = document.selection.createRange().text; // Get text selection

	if (theSelection) {
		// Add tags around selection
		document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
		document.post.para_text.focus();
		theSelection = '';
		return;
	}

	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				document.post.para_text.value += bbtags[butnumber + 1];
				buttext = eval('document.post.addbbcode' + butnumber + '.value');
				eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}
			document.post.para_text.focus();
			return;
	} else { // Open tags

		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			document.post.para_text.value += bbtags[15];
			lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
			document.post.addbbcode14.value = "Img";	// Return button back to normal state
			imageTag = false;
		}

		// Open tag
		document.post.para_text.value += bbtags[bbnumber];
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(bbcode,bbnumber+1);
		eval('document.post.addbbcode'+bbnumber+'.value += "*"');
		document.post.para_text.focus();
		return;
	}
	storeCaret(document.post.para_text);
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}



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 MM_validateForm() { //v4.0
// LOMAKETARKISTUS ================================
//
// KÄYTTÖOHJE
// Aseta lomakkeen lähettävän painikkeen onClick -metodiin MM_validateForm() funktionkutsu.
// Anna funktiolle parametriluettelo alla olevan esimerkin mukaan
// MM_validateForm('field_name_1','','param_1','header_1','field_name_2','','param_2','header_2'...'field_name_n','','param_n','header_n')
//
// PARAMETRIEN ARVOT
//  R = Kenttässä täytyy olla jokin syöte
// (R) parametrin edessä tekee ko. kentästä pakollisen
// (R)isEmail = Kenttässä täytyy olla nimi@domain.fi -muotoa oleva sähköpostiosoite
// (R)isNum = Kenttässä täytyy olla jokin numeerinen syöte
// (R)inRange1:10 = Kentän syötteen täytyy olla numeerinen väliltä 1 ... 10
// (R)isSelect = Listan valinta ei saa olla arvossa -1 (Oletusarvo, jolloin näkyvässä osassa teksti Valitse)
// (R)isPic(A/P) = isPicA määrittelee sallitut, isPicP määrittelee estetyt tiedostomuodot
// (R)isFile(A/P) = isFileA määrittelee sallitut, iFileP määrittelee estetyt tiedostomuodot
// (R)isCheck1:3 = Valittujen ruutujen määrä tulee olla välillä 1 ... 3
// (R)isRadio = Kenttä täytyy olla valittu
// (R)isLen5:e = Kentän pituus on oltava tarkalleen 5
// (R)isLen5:g = Kentän pituus on oltava suurempi 5
// (R)isLen5:l = Kentän pituus on oltava pienempi 5
// (R)isLen5:ge = Kentän pituus on oltava suurempi tai yhtäsuuri kuin 5
// (R)isLen5:le = Kentän pituus on oltava pienempi tai yhtäsuuri kuin 5
  
  var i,p,q,nm,test,title,num,min,max,boxlen,boxmin,boxmax,s,txtmin,txtmax,f,errors='',args=MM_validateForm.arguments;
  var picArray = new Array(".gif", ".jpg", ".png"); // Määrittelee sallitut/estetyt kuvatiedostomuodot
  var fileArray = new Array(".pdf", ".doc", ".xls"); // Määrittelee sallitut/estetyt tiedostomuodot
  var allowPics='',allowFiles='',allowSubmit = false;;

  
  for (i=0; i<(args.length-2); i+=4) { 
    test=args[i+2]; val=MM_findObj(args[i]); title=args[i+3]; boxval=MM_findObj(args[i]); boxlen = boxval.length;
    
	if (val) { 
	    nm=val.name;
		if ((val=val.value)!="") {
             if (test.indexOf('isEmail')!=-1) { 
			     p=val.indexOf('@');
                 if (p<1 || p==(val.length-1)) errors+='- '+title+'-kentään täytyy syöttää (nimi@domain.fi) -muotoa oleva sähköpostiosoite.\n';
             } 
			 else if (test!='R') { 
			     num = parseFloat(val);
				 if(test.indexOf('isPic') != -1) {
				    while (val.indexOf("\\") != -1) {
      				       val = val.slice(val.indexOf("\\") + 1);
      				       ext = val.slice(val.indexOf(".")).toLowerCase(); }
   			        for (var k = 0; k < picArray.length; k++) { 
					    if (picArray[k] == ext) { allowSubmit = true; }
						allowPics += picArray[k] + ' '; 
				    }
   				    if (!allowSubmit && test.substring(test.length-1) == 'A') { errors += '- '+title+' ei ole sallittua tyyppiä. ('+allowPics+')\n'; allowSubmit = false; }
					if (allowSubmit && test.substring(test.length-1) == 'P') { 
						errors += '- '+title+' -tyypin siirto on estetty. Ei sallittuja ('+allowPics+')\n'; allowSubmit = false; } 
				 }
				 else if(test.indexOf('isFile') != -1) {
				    while (val.indexOf("\\") != -1) {
      				       val = val.slice(val.indexOf("\\") + 1);
      				       ext = val.slice(val.indexOf(".")).toLowerCase(); }
   			        for (var t = 0; t < fileArray.length; t++) { 
					    if (fileArray[t] == ext) { allowSubmit = true; }
						allowFiles += fileArray[t] + ' '; 
				    } 
   				    if (!allowSubmit && test.substring(test.length-1) == 'A') { errors += '- '+title+' ei ole sallittua tyyppiä. ('+allowFiles+')\n';  allowSubmit = false; } 
					if (allowSubmit && test.substring(test.length-1) == 'P') { 
						errors += '- '+title+' -tyypin siirto on estetty. Ei sallittuja ('+allowFiles+')\n'; allowSubmit = false; }
				 }
				 else if(test.indexOf('isCheck') != -1) {
				 	    s=test.indexOf(':');
						if(test.substring(0,1) == 'R') { boxmin=test.substring(8,s); } else { boxmin=test.substring(7,s); } 
						boxmax=test.substring(s+1);
				 	    var total=0;
						for (var idx = 0; idx < boxlen; idx++) {
							 if (boxval[idx].checked == true) { total += 1; }
						}
						if(test.substring(0,1) == 'R') {
							if(!(total>=boxmin && total<=boxmax)) { 
								if(boxmin == boxmax) { errors+='- '+title+'-kentän valintojen määrä täytyy olla '+boxmin+' \n'; } 
								else { errors+='- '+title+'-kentän valintojen määrä täytyy olla väliltä '+boxmin+' ... '+boxmax+'.\n'; } 
								}
						}
						else if(total > 0) {
							if(!(total>=boxmin && total<=boxmax)) { 
							if(boxmin == boxmax) { errors+='- '+title+'-kentän valintojen määrä täytyy olla '+boxmin+' \n'; }
							else { errors+='- '+title+'-kentän valintojen määrä täytyy olla väliltä '+boxmin+' ... '+boxmax+'.\n'; }
							}
						}
 
				 }
				 else if(test.indexOf('isRadio') != -1) {
				 	    var total=0;
						for (var idx = 0; idx < boxlen; idx++) {
							 if (boxval[idx].checked == true) { total += 1; }
						}
						if(total < 1 && test.substring(0,1) == 'R') errors+='- '+title+'-täytyy olla valittu\n'; 
				 } 
				else if(test.indexOf('isLen') != -1) {
						f=test.indexOf(':');
						if(test.substring(0,1) == 'R') { txtmax=test.substring(6,f); } else { txtmax=test.substring(5,f); }
                		act=test.substring(f+1);
						if(act=='e' && val.length!=txtmax) errors+='- '+title+'-kentän pituus on oltava tarkalleen '+txtmax+' merkkiä.\n';
						if(act=='g' && val.length<=txtmax) errors+='- '+title+'-kentän pituus on oltava suurempi kuin '+txtmax+' merkkiä.\n';
						if(act=='ge' && val.length<txtmax) errors+='- '+title+'-kentän pituus on oltava suurempi tai yhtäsuuri '+txtmax+' merkkiä.\n';
						if(act=='l' && val.length>=txtmax) errors+='- '+title+'-kentän pituus on oltava pienempi kuin '+txtmax+' merkkiä (ei tyhjä).\n';
						if(act=='le' && val.length>txtmax) errors+='- '+title+'-kentän pituus on oltava pienempi tai yhtäsuuri kuin '+txtmax+' merkkiä (ei tyhjä).\n';
				} 
				 else {
                 	if (isNaN(val)) errors+='- '+title+'-kenttään täytyy syöttää numero.\n';
                 	if (test.indexOf('inRange') != -1) { 
				     	p=test.indexOf(':');
                     	min=test.substring(8,p); max=test.substring(p+1);
                     	if (num<min || max<num) errors+='- '+title+'-kentän arvo täytyy olla väliltä '+min+' ... '+max+'.\n';
                 	} 
				 	else if (test.indexOf('isSelect') != -1 && num < 0) { errors+='- '+title+' on valitsematta.\n'; }
				 }
			 } 
		}
		else if (test.charAt(0) == 'R') errors += '- '+title+'\n';
	}
  } 
  
  if (errors) alert('Tarkista seuraavat pakolliset kentät/valinnat:                                     \n\n'+errors);
  
  document.MM_returnValue = (errors == '');
} 