/****************************************
*   Copyright © 2005 Somalism.com,
*   All rights reserved
*   Author: Said
*
*   Last mod.: 20.sept 2005
****************************************/


var req = null;
var bla = "";

function getEl(id) { return document.getElementById(id); }
function Process()
{
    if (req.readyState == 4)
        {
            if (req.status == 200)
            {
                document.getElementById('info').innerHTML='';
                document.getElementById('info').className='info';

                //alert(req.getAllResponseHeaders())
                if(req.responseText.indexOf('<i>1.&nbsp;&nbsp;</i>')==-1){                   
                  string="<div style='color:red;font-size: 16px;'><img src='no.png'>Sorry, there were no results for <b>\""+bla+"\" </b><br>";
                  string+="<img src='no.png'> Xarafka <b>\""+bla+"\" </b>lama helin, <h3><b>Fiiro gaar ah:</b><font color=\"#0180fe\"><br>Haddii aadan hubin sida loo qoro, kalimada inta hore (2-3 xaraf) kaliya qor, wixii ku xiga way kuusoo baxayaan markaas..</font></h3>";
				string+="<h3><font color=\"#ff0000\">TIP of the year:</font><br><font color=\"#0180fe\">Type LESS and the see the suggested words</font></h3></div>"
                  elm=getEl("liveQuery");
                  elm.innerHTML =string;
                  elm.style.width='550px'
                }
                else
                {
                    toggleView("liveQuery",true);
                   // getEl("footer").style.position='absolute';
                    getEl("footer").style.display='none';
                    getEl("notice").style.display='none';
                    getEl("liveQuery").innerHTML =req.responseText;

                }
            }
            else
            {
                getEl("liveQuery").innerHTML="roof on fire :<br>"+req.statusText;
            }
        }
}


//linear array search
Array.prototype.inArray = function (value)
{
	var i;
	for (i=0; i < this.length; i++) {
		// Matches identical (===)
		if (this[i] === value) 
			return true;
	}
	return false;
};


function init() {
	var inputs = document.getElementsByTagName('input');
	for (var i=0; i<inputs.length; i++) {
		var input = inputs[i];
		if (input.getAttribute('type') == 'text') {
			if (document.all) {

				//IE needs onkeydown for tab and backspace [fool]
				input.onkeydown = reactToKeypress;
				input.onkeyup = reactToKeypress;
			}
			else {
				//sane browsers use onkeypress
				input.onkeyup = reactToKeypress;
			}
		}
	}
   
    document.form1.keyword.focus();
}

function inrng(x,a,b){
     return x >= a && x <= b
}

/* Running query upon allowed keys..
  check upon what is allowed, and not what is not .
  alpha=[65-90] + some control keys */
function isAllowed(key){
//   var controlKeys = [8,9,32,34,35,41,45,46,8,46,190,191];
   var controlKeys = [8,46,32,191];

return (controlKeys.inArray(key) || (inrng(key,65,90))|| (inrng(key,105,122)))
}


function reactToKeypress(e){
	if (!e)
   var e = window.event; // e gives access to the event in all browsers	

   var kc = e.keyCode ? e.keyCode : e.charCode;
	if (isAllowed(kc) && getEl('dicButton').disabled==true){
	  e.returnValue = true;
	  urchinTracker('/dictionary/');
	  //urchin(kc)
	  sendQuery(document.forms.form1.keyword.value,e)
	 }

	// arrow keys, allow but don't run a query
	else if(inrng(kc,37,40) || inrng(kc,35,36)){
	  e.returnValue = true;
	}

	else
	 {
	  if (document.all){
	    e.cancelBubble = true;
	    e.returnValue = false;
	    }
	  else{
	    e.preventDefault();
	    e.stopPropagation();
	  }
	}

  //getEl("info").innerHTML+=", "+(filter(e))?e.charCode:"";//?e.charCode:e.keyCode;
}


function Initialize()
{
    req = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
    if(!req && typeof XMLHttpRequest!="undefined")
      req= new XMLHttpRequest();


}


function toggleView(divid,flag)
{
   if (document.layers){
	 document.layers[divid].display=(flag)?"block":"none";
	}
   else {
	getEl(divid).style.display=(flag)?"block":"none";
	}

}

function op(t){var o=parseFloat(t.style.opacity);if(o<0.08){t.style.display='none';}else{o -= 0.07;t.style.opacity=o;setTimeout(function(){op(t);},20);}return true;};