
/* HiztegiaOnline v1.0
   (C) Eleka S.L.
   grego at eleka dot net
*/

function todo_blancos(valor_campo_texto){
var todo_blancos_temp=1; 
 
 for (var p=0;p<valor_campo_texto.length;p++) {
	
	
  if ((valor_campo_texto.charCodeAt(p) != 32) && (valor_campo_texto.charCodeAt(p) != 13) && (valor_campo_texto.charCodeAt(p) != 10)){
	
   todo_blancos_temp=0;
   
  }
 } 
return(todo_blancos_temp)
}

function errore_mezua() {
itzul=window.open('','itzulleiho','menubar=0,width=490,height=400,scrollbars=1');
itzul.document.open();
itzul.document.write('<html>');
itzul.document.write('<head>');
itzul.document.write('<title>');
itzul.document.write('Diccionario');
itzul.document.write('</title>');
itzul.document.write('<link rel="stylesheet" href="hizt.css" type="text/css">');

itzul.document.write('</head>');
itzul.document.write('<body bgcolor="#FFFFFF" text="#000000">');
itzul.document.write('<table width="471" border="0" cellspacing="0" cellpadding="1" bgcolor="#649579">');
itzul.document.write('<tr><td>');
itzul.document.write('<table width="470" border="0" cellspacing="0" cellpadding="0" bgcolor="#649579">');
itzul.document.write('<tr><td bgcolor="#F9F9F9" colspan="2"><object width="470" height="60"><param name="banner470x60" value="banner470x60.swf"><embed src="banner470x60.swf" width="470" height="60"></embed></object></td></tr>');
itzul.document.write('<tr><td bgcolor="#99CCCC" bordercolor="#99CCCC"><span class="titulua"> No se ha seleccionado ninguna palabra o no se puede traducir el contenido seleccionado (por ejemplo, imágenes)');
itzul.document.write('</td></tr></span>');
itzul.document.write('</table></td></tr></table>');
itzul.document.write('</body>');
itzul.document.write('</html>');
itzul.document.close();
itzul.focus();
return true;

}
function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

function itzuli(){

 if (document.getSelection) {
	
    var hitza = document.getSelection();
  } else if (document.selection && document.selection.createRange) {
	var range = document.selection.createRange();
    var hitza = range.text;
	if (hitza.length==0) {
		range.moveToPoint(window.event.x,window.event.y);
		range.expand("word",1);
		hitza=range.text;}
  } else {
    var hitza = "Error";
  }
  


if (hitza.length>30)
{ hitza="";
}


 
if (todo_blancos(hitza))
{  
	hitza="";
}
if (hitza.length==0) {errore_mezua(); return true}

// Tildeak moldatu
hitza = replaceSubstring(hitza,"á","'a");
hitza = replaceSubstring(hitza,"é","'e");
hitza = replaceSubstring(hitza,"í","'i");
hitza = replaceSubstring(hitza,"ó","'o");
hitza = replaceSubstring(hitza,"ú","'u");
hitza = replaceSubstring(hitza,"Á","'A");
hitza = replaceSubstring(hitza,"É","'E");
hitza = replaceSubstring(hitza,"Í","'I");
hitza = replaceSubstring(hitza,"Ó","'O");
hitza = replaceSubstring(hitza,"Ú","'U");
hitza = replaceSubstring(hitza,"ü","2u");
hitza = replaceSubstring(hitza,"Ü","2U");
hitza = replaceSubstring(hitza,"ñ","8");
// Netscape-k sortu ditzakeen erroreak konpondu
hitza = replaceSubstring(hitza,'"',"");
hitza = replaceSubstring(hitza,'(',"");
hitza = replaceSubstring(hitza,')',"");
hitza = replaceSubstring(hitza,':',"");

hitza = '9'+hitza;



//itzul=window.open('/hiztelh.nsf/itzuli/?OpenAgent&'+hitza+'&gazt&bai&ez','itzulleiho','menubar=0,width=550,height=400,scrollbars=1');
itzul=window.open('http://kantauri.eleka.net/hiztegiaonline/ItzuliEleka.php?hitza='+hitza+'&hizk=gazt&bil=bai&infor=ez','itzulleiho','menubar=0,width=550,height=400,scrollbars=1');

itzul.focus();
return true;

}
function sakatu(evt) {
  
  evt = (evt) ? evt : ((event) ? event : null);

   if (evt) {
// F12   
//     if(evt.keyCode==123) itzuli();
// C
//     if(evt.keyCode==67) itzuli();
// ALT + C
//     if(evt.keyCode==67 && evt.altKey==true) itzuli();
// CTRL + 0
     if(evt.keyCode==48 && evt.ctrlKey==true) itzuli();
    
    }
}
document.onkeydown = sakatu;


