
    function lahetaPyynto(kieli){
        var email = document.getElementById('kysy_email').value;
        var nimi = document.getElementById('kysy_nimi').value;
        var matto = document.getElementById('kysy_matto').value;

        var virhe='';
        
        if(email.length==0){
            if(kieli==1){
                virhe+=' Anna sähköpostiosoitteesi!';
            }else{
                virhe+=' Ge din e-adress!';
            }//end if
        }//end if

        if(nimi.length==0){
            if(kieli==1){
                virhe+=' Anna nimesi!';
            }else{
                virhe+=' Ge ditt namn!';
            }//end if
        }//end if
        
        if(virhe==''){
            parametrit='email=' + escape(email) + "&id=" + escape(matto) + "&nimi=" + escape(nimi);

            teeAjaxKutsu('ajax/lahetaMattokysely.php',parametrit,handleMattopyynto);
        }else{
            document.getElementById('kysy_valitus_tr').style.display='';
            asetaTeksti(document.getElementById('kysy_valitus_td'),virhe);
        }//end if

            
    }//end function


    function handleMattopyynto(){
        if (xmlhttp.readyState == 4) {
       	    if (xmlhttp.status == 200){
                document.body.style.cursor='default';
                var xmlDocument = xmlhttp.responseXML;
                
                var virhe=xmlDocument.getElementsByTagName('virhe');
                
                if(virhe.length>0){
                    switch(virhe[0].getAttribute('id')){
                        //Email-virhe
                        case 'email':
                            //alert(virhe[0].getAttribute('teksti'));
                            document.getElementById('kysy_email').focus();
                            document.getElementById('kysy_valitus_tr').style.display='';
                            asetaTeksti(document.getElementById('kysy_valitus_td'),virhe[0].getAttribute('teksti'));
                        break;
                        
                        //Yhteys-virhe
                        case 'yhteys':
                            document.getElementById('kysy_email').value='';
                            document.getElementById('kysy_nimi').value='';
                            //displayItem('kysymyslomake','none');
                            //alert(virhe[0].getAttribute('teksti'));
                            document.getElementById('kysy_valitus_tr').style.display='';
                            asetaTeksti(document.getElementById('kysy_valitus_td'),virhe[0].getAttribute('teksti'));
                        break;
                        
                        case 'parametrit':
                            document.getElementById('kysy_email').value='';
                            document.getElementById('kysy_nimi').value='';
                            //displayItem('kysymyslomake','none');
                            //alert(virhe[0].getAttribute('teksti'));
                            document.getElementById('kysy_valitus_tr').style.display='';
                            asetaTeksti(document.getElementById('kysy_valitus_td'),virhe[0].getAttribute('teksti'));
                        break;
                    }//end switch
                }else{
                    document.getElementById('kysy_email').value='';
                    document.getElementById('kysy_nimi').value='';
                    displayItem('kysymyslomake','none');
                    displayItem('kysymys_lahetetty','');
                }//end if
            }//end if
        }//end if
    }//end function
    

    function teeAjaxKutsu(ajaxFile,parametrit,handleFile){
    	if (xmlhttp!=null && xmlhttp.readyState !=0 && xmlhttp.readyState !=4) {

    	}else{
    	    xmlhttp.open("POST", ajaxFile, true);

    	    xmlhttp.onreadystatechange = handleFile;
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.send(parametrit);
     	} //end if
    }//end function


    function avaaEmail(otus,id,arvo){
        displayItem(id,arvo);
        document.getElementById(otus).focus();
    }//end function


    function suljeEmail(id,arvo){
        displayItem('kysy_valitus_tr','none');
        displayItem('kysymys_lahetetty','none');
        displayItem(id,arvo);
    }//end function

    function displayItem(id,arvo){
        if(document.getElementById(id)){
            document.getElementById(id).style.display=arvo;
        }//end if
    }//end function



    function asetaTeksti(otus,arvo){
        if(IEselain){
            otus.innerText=arvo;
        }else{
            otus.textContent=arvo;
        }//end if
    }//end if


