function browserCheck()
{
	this.br = navigator.appName.toLowerCase();
	this.version = navigator.appVersion.toLowerCase();
	this.agent = navigator.userAgent.toLowerCase();
	this.platform = navigator.platform.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.is_safari = ( this.version.indexOf( 'safari' ) != -1 );
	this.is_opera = ( this.agent.indexOf( 'opera' ) != -1 );
	this.is_mozilla = ( this.agent.indexOf( 'gecko' ) != -1 );
	this.is_ns = ( this.br == 'netscape' && !this.is_opera );
	this.is_ie = ( this.br == 'microsoft internet explorer' && !this.is_opera );
	this.is_ns4 = ( this.is_ns && this.major == 4 && !this.is_opera );
	this.is_ns6 = ( this.is_ns && this.major == 5 && !this.is_opera );
	this.is_ie4 = ( this.version.indexOf( 'msie 4.0' ) != -1 && !this.is_opera );
	this.is_ie5 = ( this.version.indexOf( 'msie 5.0' ) != -1 && !this.is_opera );
	this.is_ie55 = ( this.version.indexOf( 'msie 5.5' ) != -1 && !this.is_opera );
	if( this.is_ie55 ) this.is_ie5 = true;
	this.is_ie6 = ( this.version.indexOf( 'msie 6.0' ) != -1 && !this.is_opera );
	this.is_windows = ( this.platform.indexOf( 'win' ) != -1 );
	this.is_mac = ( this.agent.indexOf( 'mac' ) != -1 );
	this.is_linux = ( this.platform.indexOf( 'linux' ) != -1 || this.platform.indexOf( 'x11' ) != -1 ) ? true:false;
	this.is_dom = ( document.getElementById ) ? true:false;
}
br = new browserCheck();

function doTrim( trimThis )
{
 if( trimThis ) {
	 beginIndex = 0;
	 endIndex = trimThis.length;
	 while( trimThis.charAt( beginIndex ) == ' ' ) {
		 beginIndex++;
	 }
	 while( trimThis.charAt( endIndex - 1 ) == ' ' )  {
		 endIndex--;
	 }
	 return trimThis.slice( beginIndex, endIndex );
 }
 return '';
}


var cdate = new Date();
var year = cdate.getFullYear();
var cyear = year-16;

function checkForm(upd) 
{
	var f = document.forms['regform'];

	if(upd == 0) {
		// if(f.name_last.value == '' || f.name_first.value == '' || f.address.value == '' || f.postcode.value == '' || f.city.value == '' ||
		if(f.name_last.value == '' || f.name_first.value == '' || f.city.value == '' ||
			f.tel.value == '' || f.email.value == '' || f.username.value == '' || f.password1.value == '' || f.password2.value == '') {
			alert('Jokin pakollisista kentistä on tyhjä!');
			return false;
		}
		if(f.age.value != '') {
			if(isNaN(f.age.value)) {
				alert('Syntymävuosi: laita arvo numerona tai älä täytä kenttää ollenkaan!');	
				return false;
			}	
			alert(parseInt(f.age.value));
			if(parseInt(f.age.value) < 1900 || parseInt(f.age.value) > cyear ) {
				alert('Syntymävuosi: RE: Pro on tarkoitettu vain yli 18-vuotiaille osaaville freelancereille!');	
				return false;
			}
		}
		/*
		if((f.email.value.indexOf('@')==-1) || f.email.value.indexOf('.')==-1) {
			alert('Email-osoite väärin muotoiltu!');	
			return false;
		}
		*/
		if(f.username.value.length < 4) {
			alert('Käyttäjätunnuksen tulee olla vähintään 4 merkkiä pitkä');	
			return false;
		}
		if(f.password1.value != f.password2.value) {
			alert('Kirjoita sama salasana kaksi kertaa!');	
			return false;
		}
		if(f.password1.value.length < 6) {
			alert('Salasanan täytyy olla vähintään 6 merkkiä pitkä');	
			return false;
		}
	} else {
		// if(f.name_last.value == '' || f.name_first.value == '' || f.address.value == '' || f.postcode.value == '' || f.city.value == '' ||
		if(f.name_last.value == '' || f.name_first.value == '' || f.city.value == '' ||
			f.tel.value == '' || f.email.value == '' ) {
			alert('Jokin pakollisista kentistä on tyhjä!');
			return false;
		}
		if(f.age.value != '') {
			if(isNaN(f.age.value)) {
				alert('Syntymävuosi: laita arvo numerona tai älä täytä kenttää ollenkaan!');	
				return false;
			}						
			if(parseInt(f.age.value) < 1900 || parseInt(f.age.value) > cyear ) {
				alert('Syntymävuosi: RE: Pro on tarkoitettu vain yli 18-vuotiaille osaaville freelancereille!');	
				return false;
			}
		}
		/*
		if((f.email.value.indexOf('@')==-1) || f.email.value.indexOf('.')==-1) {
			alert('Email-osoite väärin muotoiltu!');	
			return false;
		}
		*/
		if(f.username.value.length < 4) {
			alert('Käyttäjätunnuksen tulee olla vähintään 4 merkkiä pitkä');	
			return false;
		}
		if(f.password1.value != f.password2.value) {
			alert('Kirjoita sama salasana kaksi kertaa!');	
			return false;
		}
		if(f.password1.value.length > 0 && f.password1.value.length < 6) {
			alert('Salasanan täytyy olla vähintään 6 merkkiä pitkä');	
			return false;
		}
	}
	return true;

}


function checkForm3(upd) 
{
	var f = document.forms['regform'];

	// checkMainExpertices() function is located in _content_register
	if(!checkMainExpertices(f)) {
		return false;
	}

	if(f.accept_terms.checked != true) {
		alert('Rekisteröityäksesi palveluun, sinun täytyy hyväksyä palvelun käyttöehdot!');
		return false;
	}

	if(upd == 0) {		
		// if(f.name_last.value == '' || f.name_first.value == '' || f.address.value == '' || f.postcode.value == '' || f.city.value == '' ||
		if(f.name_last.value == '' || f.name_first.value == '' || f.city.value == '' ||
			f.tel.value == '' || f.email.value == '' ||  f.username.value == '' || f.password1.value == '' || f.password2.value == '') {
			alert('Jokin pakollisista kentistä on tyhjä!');
			return false;
		}
		if(f.age.value != '') {
			if(isNaN(f.age.value)) {
				alert('Syntymävuosi: laita arvo numerona tai älä täytä kenttää ollenkaan!');	
				return false;
			}	
			if(parseInt(f.age.value) < 1900 || parseInt(f.age.value) > cyear ) {
				alert('Syntymävuosi: RE: Pro on tarkoitettu vain yli 18-vuotiaille osaaville freelancereille!');	
				return false;
			}
		}
		/*
		if((f.email.value.indexOf('@')==-1) || f.email.value.indexOf('.')==-1) {
			alert('Email-osoite väärin muotoiltu!');	
			return false;
		}
		*/
		if(f.username.value.length < 4) {
			alert('Käyttäjätunnuksen tulee olla vähintään 4 merkkiä pitkä');	
			return false;
		}
		if(f.password1.value != f.password2.value) {
			alert('Kirjoita sama salasana kaksi kertaa!');	
			return false;
		}
		if(f.password1.value.length < 6) {
			alert('Salasanan täytyy olla vähintään 6 merkkiä pitkä');	
			return false;
		}
	} else {
		// if(f.name_last.value == '' || f.name_first.value == '' || f.address.value == '' || f.postcode.value == '' || f.city.value == '' ||
		if(f.name_last.value == '' || f.name_first.value == '' || f.city.value == '' ||
			f.tel.value == '' || f.email.value == '' ) {
			alert('Jokin pakollisista kentistä on tyhjä!');
			return false;
		}
		if(f.age.value != '') {
			if(isNaN(f.age.value)) {
				alert('Syntymävuosi: laita arvo numerona tai älä täytä kenttää ollenkaan!');	
				return false;
			}
		
			if(parseInt(f.age.value) < 1900 || parseInt(f.age.value) > cyear ) {
				alert('Syntymävuosi: RE: Pro on tarkoitettu vain yli 18-vuotiaille osaaville freelancereille!');	
				return false;
			}
		}
		/*
		if((f.email.value.indexOf('@')==-1) || f.email.value.indexOf('.')==-1) {
			alert('Email-osoite väärin muotoiltu!');	
			return false;
		}
		*/
		if(f.username.value.length < 4) {
			alert('Käyttäjätunnuksen tulee olla vähintään 4 merkkiä pitkä');	
			return false;
		}
		if(f.password1.value != f.password2.value) {
			alert('Kirjoita sama salasana kaksi kertaa!');	
			return false;
		}
		if(f.password1.value.length > 0 && f.password1.value.length < 6) {
			alert('Salasanan täytyy olla vähintään 6 merkkiä pitkä');	
			return false;
		}
		if(f.remove.checked == true) {
			var rem_confirm = confirm('Oletko varma, että haluat poistaa tietosi RE:PRO-palvelusta?');
			if(!rem_confirm) {
				return false;
			}

		}
	}
	
	return true;

}

/*
* Asetellaan niitä "hidden" arvoja...
*/
function setValue(el) {
	if(!br.is_ie && el) {	
		document.getElementById('regformid').elements[el.getAttribute('did')].value = el.value;		
	}
}	

function parseMonth(str) {
	if(str != '') {
		if(str.indexOf('0') == 0) {
			str = str.charAt(1);
			return parseInt(str);
		}
	}
	return str;
}

/*
*	Työpaikka
*/
var job_index = 1;

function addNewJobForm(employer, job_title, job_description, _dbm, _dby, _dem, _dey) {

	var dbm=0;	var dby=0;	var dem=0;	var dey=0;  	
  	dbm = parseMonth(_dbm);
	dby = parseInt(_dby)
	dem = parseMonth(_dem);
	dey = parseInt(_dey);

	var month = new Array(12);
	month[1] = 'Tammikuu';
	month[2] = 'Helmikuu';
	month[3] = 'Maaliskuu';
	month[4] = 'Huhtikuu';
	month[5] = 'Toukokuu';
	month[6] = 'Kesäkuu';
	month[7] = 'Heinäkuu';
	month[8] = 'Elokuu';
	month[9] = 'Syyskuu';
	month[10] = 'Lokakuu';
	month[11] = 'Marraskuu';
	month[12] = 'Joulukuu';

	var emp_str = '<span id="sub_job_' + job_index + '"><table border=0 cellpadding=0 cellspacing=0 width="100%">' +
		'<tr><td><img src="graf/x.gif" width=145 height=13 alt="0" border=0></td>' +
		'	<td><img src="graf/x.gif" width=255 height=13 alt="0" border=0></td>' +
		'	<td><img src="graf/x.gif" width=155 height=13 alt="0" border=0></td></tr>' +
		'<tr><td style="text-align: right; padding: 10px;">Työnantaja:</td>' +
		'	<td><input onChange="setValue(this);" type="text" class="textBox" ' + (br.is_ie?'name':'did') + '="job[' + job_index + '][employer]" id="employer_'+job_index+'" size=40 maxlength="255" value="' + employer + '"></td></tr>' +
		'<tr><td style="text-align: right; padding: 10px;">Alkuaika:</td>' +
		'<td><select onChange="setValue(this);" ' + (br.is_ie?'name':'did') + '="job[' + job_index + '][job_begin_month]" id="job_begin_month_'+job_index+'" class="textBox">' +
		'	<option value="">';
		
	for (var i=1; i<month.length ; i++ ) {
		emp_str += '\n<option value="'+i+'" ';
	
		if(i == dbm) {			
			emp_str += 'selected';
		}
		emp_str += '>'+month[i];
	}

   D = new Date();
   curr_year = D.getFullYear();

	emp_str += '</select><select onChange="setValue(this);" ' + (br.is_ie?'name':'did') + '="job[' + job_index + '][job_begin_year]" id="job_begin_year_'+job_index+'" class="textBox">' +
		'	<option value="">';
	for (var i=1980; i<=curr_year ; i++ ) {
		emp_str += '\n<option value="'+i+'" ';
		if(i == dby) {
			emp_str += 'selected';
		}
		emp_str += '>'+i;
	}		
	
	emp_str += '</select></td></tr>' +
		'<tr><td style="text-align: right; padding: 10px;">Loppuaika:</td><td>' +
		'	<select onChange="setValue(this);" ' + (br.is_ie?'name':'did') + '="job[' + job_index + '][job_ending_month]" id="job_ending_month_'+job_index+'" class="textBox">' +
		'	<option value="">';
	for (var i=1; i<month.length ; i++ ) {
		emp_str += '\n<option value="'+i+'" ';
		if(i == dem) {
			emp_str += 'selected';
		}
		emp_str += '>'+month[i];
	}		
	
   D = new Date();
   curr_year = D.getFullYear();

	emp_str += '</select><select onChange="setValue(this);" ' + (br.is_ie?'name':'did') + '="job[' + job_index + '][job_ending_year]" id="job_ending_year_'+job_index+'" class="textBox">' +
		'	<option value="">';
	for (var i=1980; i<=curr_year ; i++ ) {
		emp_str += '\n<option value="'+i+'" ';
		if(i == dey) {
			emp_str += 'selected';
		}
		emp_str += '>'+i;
	}	
	emp_str += '</select></td></tr>' +
		'<tr><td>&nbsp;</td><td colspan=2 align="left" style="padding: 10px 0px 10px 0px;"><font style="font-size: 11px; color: #6e6e6e;">' +
		'	Mikäli työsuhde on yhä voimassa, jätä lopetusaika tyhjäksi.</font></td></tr>' +
		'<tr><td style="text-align: right; padding: 10px;">Työnimike:</td>' +
		'	<td><input onChange="setValue(this);" type="text" class="textBox" ' + (br.is_ie?'name':'did') + '="job[' + job_index + '][job_title]" id="job_title_'+job_index+'" size=40 maxlength="255" value="' + job_title + '"></td></tr>' +
		'<tr><td valign="top" style="text-align: right; padding: 10px;">Tehtävän kuvaus:</td>' +
		'	<td><textarea onChange="setValue(this);" ' + (br.is_ie?'name':'did') + '="job[' + job_index + '][job_description]" id="job_description_'+job_index+'" rows=5 cols=30 class="textBox">' + job_description + '</textarea></td>' +
		'	<td align="right" valign="bottom" style="padding-left: 10px;"><a href="javascript:delJobForm(' + job_index + ');"><img src="graf/btn_poista_tyopaikka.gif" alt="" border=0></a></td></tr>' + 
		'<tr><td colspan=3><hr></td></tr>' + 
		'</table></span>';

// document.write('<xmp>'+emp_str+'</xmp>');

	// Find correct place in html
	var div = ( document.all ) ? document.all[ 'job_div' ] : document.getElementById( 'job_div' );
	div.innerHTML = div.innerHTML + '\n' + emp_str;

	if(!br.is_ie && document.getElementById('regformid')) {		

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'job[' + job_index + '][employer]' );
		inputobj.setAttribute( 'maxlength', '255' );
		inputobj.setAttribute( 'value', employer );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);		

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'job[' + job_index + '][job_title]' );
		inputobj.setAttribute( 'maxlength', '255' );
		inputobj.setAttribute( 'value', job_title );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'job[' + job_index + '][job_begin_month]' );
		inputobj.setAttribute( 'value', dbm );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'job[' + job_index + '][job_begin_year]' );
		inputobj.setAttribute( 'value', dby );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'job[' + job_index + '][job_ending_month]' );
		inputobj.setAttribute( 'value', dem );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'job[' + job_index + '][job_ending_year]' );
		inputobj.setAttribute( 'value', dey );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);	

		var inputobj = document.createElement('TEXTAREA');
		// inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'job[' + job_index + '][job_description]' );
		inputobj.setAttribute( 'value', job_description );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		var textobj = document.createTextNode(job_description);
		inputobj.appendChild(textobj);
		document.getElementById('regformid').appendChild(inputobj);		
	}



	if(!br.is_ie && employer == '') {		
		for(var i=1; i<=job_index; i++) {	
			if(document.getElementById('employer_'+i)) {
				document.getElementById('employer_'+i).value = document.getElementById('regformid').elements[ 'job['+i+'][employer]' ].value;
				document.getElementById('job_title_'+i).value = document.getElementById('regformid').elements[ 'job['+i+'][job_title]' ].value;
				document.getElementById('job_description_'+i).value = document.getElementById('regformid').elements[ 'job['+i+'][job_description]' ].value;

				document.getElementById('job_begin_month_'+i).value = document.getElementById('regformid').elements[ 'job['+i+'][job_begin_month]' ].value;
				document.getElementById('job_begin_year_'+i).value = document.getElementById('regformid').elements[ 'job['+i+'][job_begin_year]' ].value;
				document.getElementById('job_ending_month_'+i).value = document.getElementById('regformid').elements[ 'job['+i+'][job_ending_month]' ].value;
				document.getElementById('job_ending_year_'+i).value = document.getElementById('regformid').elements[ 'job['+i+'][job_ending_year]' ].value;

			}
		}
	}

	job_index++;
}

function delJobForm(index) {
	if(confirm('Poista valittu työpaikka?')) {
		if(!br.is_ie) {
			document.getElementById('regformid').elements[ 'job[' + index + '][employer]' ].value = "";
			document.getElementById('regformid').elements[ 'job[' + index + '][job_title]' ].value = "";			
			document.getElementById('regformid').elements[ 'job[' + index + '][job_begin_month]' ].value = "";
			document.getElementById('regformid').elements[ 'job[' + index + '][job_begin_year]' ].value = "";
			document.getElementById('regformid').elements[ 'job[' + index + '][job_ending_month]' ].value = "";
			document.getElementById('regformid').elements[ 'job[' + index + '][job_ending_year]' ].value = "";
			document.getElementById('regformid').elements[ 'job[' + index + '][job_description]' ].value = "";
		}
		var sdiv = ( document.all ) ? document.all[ 'sub_job_'+index ] : document.getElementById( 'sub_job_'+index );
		sdiv.innerHTML = "";
	}
}

/*
*	Koulutus
*/
var std_index = 1;

function addNewStudyForm(study, school, course, _dbm, _dby, _dem, _dey) {

	var dbm=0;	var dby=0;	var dem=0;	var dey=0;  	
  	dbm = parseMonth(_dbm);
	dby = parseInt(_dby)
	dem = parseMonth(_dem);
	dey = parseInt(_dey);
	
	var month = new Array(12);
	month[1] = 'Tammikuu';
	month[2] = 'Helmikuu';
	month[3] = 'Maaliskuu';
	month[4] = 'Huhtikuu';
	month[5] = 'Toukokuu';
	month[6] = 'Kesäkuu';
	month[7] = 'Heinäkuu';
	month[8] = 'Elokuu';
	month[9] = 'Syyskuu';
	month[10] = 'Lokakuu';
	month[11] = 'Marraskuu';
	month[12] = 'Joulukuu';

	var emp_str = '<span id="sub_std_' + std_index + '"><table border=0 cellpadding=0 cellspacing=0 width="100%">' +
		'<tr><td><img src="graf/x.gif" width=145 height=13 alt="0" border=0></td>' +
		'	<td><img src="graf/x.gif" width=255 height=13 alt="0" border=0></td>' +
		'	<td><img src="graf/x.gif" width=155 height=13 alt="0" border=0></td></tr>' +
		'<tr><td style="text-align: right; padding: 10px;">&nbsp;</td>' + 
		'	<td><font style="font-size: 11px; color: #6e6e6e;">Listaa vain relevantit opinnot. </font></td></tr>' + 
		'<tr><td style="text-align: right; padding: 10px;">Tutkinto:</td>' + 
		'	<td><input onChange="setValue(this);" type="text" class="textBox" ' + (br.is_ie?'name':'did') + '="std[' + std_index + '][study]" id="study_'+std_index+'" size=40 maxlength="255" value="' + study + '"></td></tr>' + 
		'<tr><td style="text-align: right; padding: 10px;">Oppilaitos:</td>' + 
		'	<td><input onChange="setValue(this);" type="text" class="textBox" ' + (br.is_ie?'name':'did') + '="std[' + std_index + '][school]" id="school_'+std_index+'" size=40 maxlength="255" value="' + school + '"></td></tr>' + 
		'<tr><td style="text-align: right; padding: 10px;">Pääaine:</td>' + 
		'	<td><input onChange="setValue(this);" type="text" class="textBox" ' + (br.is_ie?'name':'did') + '="std[' + std_index + '][course]" id="course_'+std_index+'" size=40 maxlength="255" value="' + course + '"></td></tr>' + 
		'<tr><td style="text-align: right; padding: 10px;">Aloitusaika:</td>' + 
		'	<td><select onChange="setValue(this);" ' + (br.is_ie?'name':'did') + '="std[' + std_index + '][study_begin_month]" id="study_begin_month_'+std_index+'" class="textBox">' +
		'	<option value="">';	
		
	for (var i=1; i<month.length ; i++ ) {
		emp_str += '\n<option value="'+i+'" ';
		if(i == dbm) {
			emp_str += 'selected';
		}
		emp_str += '>'+month[i];
	}

   D = new Date();
   curr_year = D.getFullYear();

	emp_str += '</select><select onChange="setValue(this);" ' + (br.is_ie?'name':'did') + '="std[' + std_index + '][study_begin_year]" id="study_begin_year_'+std_index+'" class="textBox">' +
		'	<option value="">';
	for (var i=1980; i<=curr_year ; i++ ) {
		emp_str += '\n<option value="'+i+'" ';
		if(i == dby) {
			emp_str += 'selected';
		}
		emp_str += '>'+i;
	}		
	
	emp_str += '</select></td></tr>' +
		'<tr><td style="text-align: right; padding: 10px;">Lopetusaika:</td><td>' +
		'	<select onChange="setValue(this);" ' + (br.is_ie?'name':'did') + '="std[' + std_index + '][study_ending_month]" id="study_ending_month_'+std_index+'" class="textBox">' +
		'	<option value="">';
	for (var i=1; i<month.length ; i++ ) {
		emp_str += '\n<option value="'+i+'" ';
		if(i == dem) {
			emp_str += 'selected';
		}
		emp_str += '>'+month[i];
	}		
	
    D = new Date();
   curr_year = D.getFullYear();

	emp_str += '</select><select onChange="setValue(this);" ' + (br.is_ie?'name':'did') + '="std[' + std_index + '][study_ending_year]" id="study_ending_year_'+std_index+'" class="textBox">' +
		'	<option value="">';
	for (var i=1980; i<=curr_year ; i++ ) {
		emp_str += '\n<option value="'+i+'" ';
		if(i == dey) {
			emp_str += 'selected';
		}
		emp_str += '>'+i;
	}	
	emp_str += '</select></td></tr>' +
		'<tr><td>&nbsp;</td><td><font style="font-size: 11px; color: #6e6e6e;">' +
		'	Mikäli tutkinto ei ole vielä valmis, jätä lopetusaika tyhjäksi.</font></td>' +
		'	<td align="right" valign="bottom" style="padding-left: 10px;"><a href="javascript:delStudyForm(' + std_index + ');"><img src="graf/btn_poista_tutkinto.gif" alt="" border=0></a></td></tr>' + 
		'<tr><td colspan=3><hr></td></tr>' + 
		'</table></span>';

	// Find correct place in html
	var div = ( document.all ) ? document.all[ 'study_div' ] : document.getElementById( 'study_div' );
	div.innerHTML = div.innerHTML + '\n' + emp_str;

	if(!br.is_ie && document.getElementById('regformid')) {
		

// alert(study +','+ school+','+ course+','+ dbm+','+ dby+','+ dem+','+ dey);
		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'std[' + std_index + '][study]' );
		inputobj.setAttribute( 'maxlength', '255' );
		inputobj.setAttribute( 'value', study );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'std[' + std_index + '][school]' );
		inputobj.setAttribute( 'maxlength', '255' );
		inputobj.setAttribute( 'value', school );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'std[' + std_index + '][course]' );
		inputobj.setAttribute( 'maxlength', '255' );
		inputobj.setAttribute( 'value', course );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'std[' + std_index + '][study_begin_month]' );
		inputobj.setAttribute( 'value', dbm );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'std[' + std_index + '][study_begin_year]' );
		inputobj.setAttribute( 'value', dby );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'std[' + std_index + '][study_ending_month]' );
		inputobj.setAttribute( 'value', dem );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'std[' + std_index + '][study_ending_year]' );
		inputobj.setAttribute( 'value', dey );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);	
	}

	std_index++;

	if(!br.is_ie && study == '') {	
		for(var i=1; i<=std_index; i++) {
			if(document.getElementById('study_'+i)) {
				document.getElementById('study_'+i).value = document.getElementById('regformid').elements[ 'std['+i+'][study]' ].value;
				document.getElementById('school_'+i).value = document.getElementById('regformid').elements[ 'std['+i+'][school]' ].value;
				document.getElementById('course_'+i).value = document.getElementById('regformid').elements[ 'std['+i+'][course]' ].value;

				document.getElementById('study_begin_month_'+i).value = document.getElementById('regformid').elements[ 'std['+i+'][study_begin_month]' ].value;
				document.getElementById('study_begin_year_'+i).value = document.getElementById('regformid').elements[ 'std['+i+'][study_begin_year]' ].value;
				document.getElementById('study_ending_month_'+i).value = document.getElementById('regformid').elements[ 'std['+i+'][study_ending_month]' ].value;
				document.getElementById('study_ending_year_'+i).value = document.getElementById('regformid').elements[ 'std['+i+'][study_ending_year]' ].value;

			}
		}
	}
}

function delStudyForm(index) {
	if(confirm('Poista valittu tutkinto?')) {
		if(!br.is_ie) {
			document.getElementById('regformid').elements[ 'std[' + index + '][study]' ].value = "";
			document.getElementById('regformid').elements[ 'std[' + index + '][school]' ].value = "";
			document.getElementById('regformid').elements[ 'std[' + index + '][course]' ].value = "";
			document.getElementById('regformid').elements[ 'std[' + index + '][study_begin_month]' ].value = "";
			document.getElementById('regformid').elements[ 'std[' + index + '][study_begin_year]' ].value = "";
			document.getElementById('regformid').elements[ 'std[' + index + '][study_ending_month]' ].value = "";
			document.getElementById('regformid').elements[ 'std[' + index + '][study_ending_year]' ].value = "";
		}
		var sdiv = ( document.all ) ? document.all[ 'sub_std_'+index ] : document.getElementById( 'sub_std_'+index );
		sdiv.innerHTML = "";
	}
}


/*
*	Referenssit
*/
var ref_index = 1;

function addNewReferenceForm(name, desc, link) {

	var emp_str = '<span id="sub_ref_' + ref_index +'"><table border=0 cellpadding=0 cellspacing=0 width="100%">' +
		'<tr><td><img src="graf/x.gif" width=145 height=13 alt="0" border=0></td>' +
		'	<td><img src="graf/x.gif" width=255 height=13 alt="0" border=0></td>' +
		'	<td><img src="graf/x.gif" width=155 height=13 alt="0" border=0></td></tr>' +
		'<tr><td style="text-align: right; padding: 10px;">Nimi:</td>' + 
		'	<td><input onChange="setValue(this);" type="text" class="textBox" ' + (br.is_ie?'name':'did') + '="ref[' + ref_index + '][name]" id="ref_name_'+ref_index+'" size=40 maxlength="255" value="'+name+'"></td></tr>' + 
		'<tr><td valign="top" style="text-align: right; padding: 10px;">Rooli projektissa:</td>' + 
		'	<td><textarea onChange="setValue(this);" ' + (br.is_ie?'name':'did') + '="ref[' + ref_index + '][description]" id="ref_description_'+ref_index+'" rows=5 cols=30 class="textBox">'+desc+'</textarea></td></tr>' + 
		'<tr><td style="text-align: right; padding: 10px;">Linkki referenssiin:</td>' + 
		'	<td><input onChange="setValue(this);" type="text" class="textBox" ' + (br.is_ie?'name':'did') + '="ref[' + ref_index + '][link]" id="ref_link_'+ref_index+'" size=40 maxlength="255" value="'+link+'"></td>' + 
		'<td align="right" valign="bottom" style="padding-left: 10px;"><a href="javascript:delReferenceForm(' + ref_index + ');"><img src="graf/btn_poista_referenssi.gif" alt="" border=0></a></td></tr>' + 
		'<tr><td colspan=3><hr></td></tr>' + 
		'</table></span>';

	// Find correct place in html
	var div = ( document.all ) ? document.all[ 'ref_div' ] : document.getElementById( 'ref_div' );
	div.innerHTML = div.innerHTML + '\n' + emp_str;	

	if(!br.is_ie && document.getElementById('regformid')) {

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'ref[' + ref_index + '][name]' );
		inputobj.setAttribute( 'maxlength', '255' );
		inputobj.setAttribute( 'value', name );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('TEXTAREA');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'ref[' + ref_index + '][description]' );
		inputobj.setAttribute( 'value', desc );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		var textobj = document.createTextNode(desc);
		inputobj.appendChild(textobj);
		document.getElementById('regformid').appendChild(inputobj);

		var inputobj = document.createElement('INPUT');
		inputobj.setAttribute( 'type', 'text' );
		inputobj.setAttribute( 'name', 'ref[' + ref_index + '][link]' );
		inputobj.setAttribute( 'maxlength', '255' );
		inputobj.setAttribute( 'value', link );
		inputobj.style.setProperty( 'visibility', 'hidden', null );
		inputobj.style.setProperty( 'position', 'absolute', null );
		document.getElementById('regformid').appendChild(inputobj);
	}

	if(!br.is_ie && name == '') {	
		for(var i=1; i<=ref_index; i++) {
			if(document.getElementById('ref_name_'+i)) {		
				document.getElementById('ref_name_'+i).value = document.getElementById('regformid').elements[ 'ref['+i+'][name]' ].value;
				document.getElementById('ref_description_'+i).value = document.getElementById('regformid').elements[ 'ref['+i+'][description]' ].value;
				document.getElementById('ref_link_'+i).value = document.getElementById('regformid').elements[ 'ref['+i+'][link]' ].value;
			}
		}
	}

	ref_index++;
}

function delReferenceForm(index) {
	if(confirm('Poista valittu referenssi?')) {
		if(!br.is_ie) {
			document.getElementById('regformid').elements[ 'ref[' + index + '][name]' ].value = "";
			document.getElementById('regformid').elements[ 'ref[' + index + '][description]' ].value = "";
			document.getElementById('regformid').elements[ 'ref[' + index + '][link]' ].value = "";
		}
		var sdiv = ( document.all ) ? document.all[ 'sub_ref_'+index ] : document.getElementById( 'sub_ref_'+index );
		sdiv.innerHTML = "";
	}
}


function confirmRemove() {

	var rem = ( document.all ) ? document.all[ 'remove' ] : document.getElementById( 'remove' );
	if(rem.checked == true) {
		alert('Olet poistamassa profiiliasi!');
	}

}

function checkTafForm(){
	
	var email = ( document.all ) ? document.all[ 'taf_email' ] : document.getElementById( 'taf_email' );
	var name = ( document.all ) ? document.all[ 'taf_name' ] : document.getElementById( 'taf_name' );

	if((email.value.indexOf('@')==-1) || email.value.indexOf('.')==-1) {
		alert('Email-osoite väärin muotoiltu!');	
		return false;
	}	
	if(name.value == '') {
		alert('Ole hyvä ja syötä myös nimesi!');	
		return false;
	}
	return true;
}

function checkFpassForm(){
	
	var fpass_email = ( document.all ) ? document.all[ 'fpass_email' ] : document.getElementById( 'fpass_email' );
	if((fpass_email.value.indexOf('@')==-1) || fpass_email.value.indexOf('.')==-1) {
		alert('Email-osoite väärin muotoiltu!');	
		return false;
	}	
	if(name.value == '') {
		alert('Ole hyvä ja syötä myös nimesi!');	
		return false;
	}
	return true;
}

function checkFeedbackForm(){

	var subject = ( document.all ) ? document.all[ 'subject' ] : document.getElementById( 'subject' );
	var message = ( document.all ) ? document.all[ 'message' ] : document.getElementById( 'message' );
	var email = ( document.all ) ? document.all[ 'email' ] : document.getElementById( 'email' );
	
	if(subject.value == '' || message.value == '') {
		alert('Syötä ainakin aihe ja viesti lomakkeelle!');	
		return false;
	}	

	return true;
}

function checkPcontactForm(){

	var subject = ( document.all ) ? document.all[ 'subject' ] : document.getElementById( 'subject' );
	var message = ( document.all ) ? document.all[ 'message' ] : document.getElementById( 'message' );
	var email = ( document.all ) ? document.all[ 'email' ] : document.getElementById( 'email' );
	
	/*
	if(subject.value == '' || message.value == '') {
		alert('Syötä ainakin aihe ja viesti lomakkeelle!');	
		return false;
	}
	*/
	if(message.value == '') {
		alert('Syötä ainakin viesti lomakkeelle!');	
		return false;
	}

	if((email.value.indexOf('@')==-1) || email.value.indexOf('.')==-1) {
		alert('Email-osoite on väärin muotoiltu!');	
		return false;
	}	

	return true;
}

function confirmRemoveExpertice(exp) {

	if(exp > 0) {
		if(confirm('Haluatko varmasti poistaa osaamisalueen? Myös linkitykset profiileihin puretaan.')) {
			if(confirm('Osaamisalue poistetaan. Jatketaanko?')) {
				location.href = 'index.php?mode=aloginok&a=1&admin=2&save=1&deid='+exp;
			}
		}
	}
}