var ficheroOut = "";

	  
function chtts(texto){
        var idiomatts = 'es';
        var urldemanada = document.location.href;
        if (urldemanada.indexOf('.cat.')>0) { idiomatts='ca';}
;        if (urldemanada.indexOf('softly.cat')>0) { idiomatts='ca';}
        if (urldemanada.indexOf('.gal.')>0) { idiomatts='gl';}
        if (urldemanada.indexOf('.bra.')>0) { idiomatts='pt';}
		saySomething(texto,idiomatts);
}
function llegeixhelp(){
        var oHelp = document.getElementById("help");
        chtts(gettextdenode(oHelp));
}
function llegeix(e){
//alert(window.event.keyCode);
    var code;
    var ambctrl;
    if (document.all){
        code = window.event.keyCode;
        ambctrl = window.event.shiftKey & window.event.ctrlKey;
    }
    else {
        code = e.which;
        ambctrl = e.shitfKey & e.ctrlKey;
        // posar per Firefox
    }
        //F8 per llegir menu
    if (code == 119) {
        var textallegir;
        var oMenu = document.getElementById("menu");
        chtts(gettextdenode(oMenu));
    }
    //F9 per llegir cos
    if (code == 120) {
        var textallegir;
        var oCos = document.getElementById("cos");
        chtts(gettextdenode(oCos));
    }
   
    if (ambctrl && code == 123) {
        if (document.getElementById("player").height == 0){
            document.getElementById("player").height = 200;
            document.getElementById("player").width = 700;
            document.getElementById("player").style.zIndex = 1000;
            
        }
        else {
            document.getElementById("player").height = 0;
            document.getElementById("player").width = 0;
        }
    }
    
    //F7 per ajuda
    if (code == 118) {
        var textallegir;
        var oHelp = document.getElementById("help");
        chtts(gettextdenode(oHelp));
    }
    if (ambctrl && code == 69) {
        document.location="/empresa.asp";
    }
    if (ambctrl && code == 83) {
        document.location="/serveis.asp";
    }
    if (ambctrl && code == 80) {
        document.location="/producte.asp";
    }
    if (ambctrl && code == 78) {
        document.location="/noticies.asp";
    }
    if (ambctrl && code == 88) {
        document.location="/experiencies.asp";
    }
   

    return false;
   
}

function gettextdenode( node ) {
    var textenodes="";
    var i;
    var oChilds = node.childNodes;
    if (oChilds != undefined){
             for (i=0;i<oChilds.length;i++){
                if ((oChilds[i].attributes != null) && (oChilds[i].getAttribute("lectura") == "si")){
                        textenodes += oChilds[i].innerText + ".\n";
                }
                else{
                    textenodes += gettextdenode(oChilds[i]);
                }
             }
        return textenodes;
    }
    
}
function quitaImpurezas(value){
		var re = /[\t\v\n\r\f]/g; //Con la es para reemplazar todas las ocurrenciaaassss!
		return value.replace(re, " ");
}

function saySomething(txt2tts, idiomaFinal) {

	var textoFinal = txt2tts;

    //Aqui se encuentra el evento de enviar/recibir el mensaje, y se comienzan a emitir los mensajes
    var d = new Date();
    var curr_year = d.getFullYear();
    var curr_month = d.getMonth();
    var curr_date = d.getDate();
    var curr_hour = d.getHours();
    var curr_min = d.getMinutes();
    var curr_sec = d.getSeconds();
    var curr_msec = d.getMilliseconds();
    var numeroSecuencial = curr_year.toString() + curr_month.toString() + curr_date.toString() + curr_hour.toString() + curr_min.toString() + curr_sec.toString() + curr_msec.toString();

    ficheroOut = "textoWeb_"+numeroSecuencial+".mp3";

  	var texto_final=quitaImpurezas(textoFinal);
	  var texto_final_2= escape(texto_final);
    var idiomaeti = idiomaFinal;
		if(idiomaeti.indexOf('es')>-1 || idiomaeti.indexOf('ca')>-1 || idiomaeti.indexOf('gl')>-1 || idiomaeti.indexOf('pt')>-1 || idiomaeti.indexOf('-')==0 || idiomaeti.indexOf("no")>-1){
			processa(ficheroOut, texto_final_2,idiomaeti);
		}

}


function processa( nombreFicheroOut, texto,idioma) {

//var dataurl = "nombreFicheroOut=" + nombreFicheroOut + "&idioma=" + idioma + "&texto=" + texto;
	window.frames['playerform'].fplayer.idioma.value = idioma;
	window.frames['playerform'].fplayer.nombreFicheroOut.value = nombreFicheroOut;
	window.frames['playerform'].fplayer.texto.value = texto;
	window.frames['playerform'].fplayer.submit();
//window.frames['player'].location = 'tts/player.asp?'+dataurl;
      	

}

