//muokataan avointa hakemusta
function muokkaa(){
	var hakemusid = document.getElementById("hakemus_id").value;
	window.location = "index.php?page=hakemukset&hakemus="+hakemusid;
}

//poistetaan liite
function removeFile(file){
 
 	var tyyppi = "hakemuksen";
 	
 	if(file=="tiedosto1"){ tyyppi = "CV:n"; }
 	
 	if(confirm("Haluatko varmasti poistaa "+tyyppi+"?")){
		document.getElementById("removeFile").innerHTML = "<input type='hidden' name='"+file+"' value=''>";
		document.lomake.submit();
	}
}

//kentän tyhjennys
function clearInput(value){
	if(value=="tunnus"){
		document.getElementById(value).value = "";
	}
}

//inputin muunnos password:iksi
function changeType(value,obj){
	if(value=="salasana"){
		document.getElementById(value).value = "";

		var newO=document.createElement('input');
		newO.setAttribute('type','password');
		newO.setAttribute('name',obj.getAttribute('name'));
		newO.setAttribute('id',obj.getAttribute('name'));
		obj.parentNode.replaceChild(newO,obj);
		setTimeout("document.getElementById('salasana').focus()",10);
	}
}

//uutta hakemusta luodessa tarkistetaan, että onko tunnus jo käytössä == löytyykö jo lomake
//jos hakijalla on jo lomake niin virheilmoitus ja ohjaus kirjautumissivulle
function tarkistaTunnus(email){	
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Selaimessasi tapahtui virhe!");
				return false;
			}
		}
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(ajaxRequest.responseText=="1"){
				alert('Sähköpostiosoitteesi löytyy jo Personnelin cv-tietokannasta.\nVoit muokata vanhaa hakemustasi kirjautumalla osoitteessa https://www.pib.fi/sivu/jata_cv\n\nJos olet hukannut salasanasi niin voit palauttaa sen \"Unohditko salasanasi?\" -kohdasta\ntai suoraan osoitteesta https://www.pib.fi/avoimet/salasana.php');
				window.location='https://www.pib.fi/sivu/jata_cv#alas';
			}
		}
	}
	var queryString = "?email=" + email + "&r="+Math.round(Math.random() * 10000);
	ajaxRequest.open("GET", "https://www.pib.fi/avoimet/check_user.php" + queryString, true);
	ajaxRequest.send(null); 

}
