var IE = document.all?true:false;
function testimonial(trid)
{
  var isIE = /*@cc_on!@*/false;
  var trelem = document.getElementById(trid);
  if (isIE)
  {
		if (trelem.style.display != "none")
			trelem.style.display="none";
		else trelem.style.display="";
  }
  else
  {
		if (trelem.style.display == "table-row")
			trelem.style.display="none";
		else trelem.style.display="table-row";
  }
}

function toggleDiv(dv)
{
	dv.style.display = (dv.style.display == 'block')? 'none' : 'block';
}
function hideDiv(e)
{
	document.getElementById('portran').style.display = 'none';
}
function keyPressHandler(e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	if(keycode==37)
	{
		gotoind(-1);
	}
	else if (keycode==39)
	{
		gotoind(1);
	}
}
function df()
{
	return document.forms[0];
}
function sorder(param,otype)
{
	df().orderby.value = param;
	df().ascending.value = otype;
	df().submit();
}

function getn(v,n)
{
	if (v.xdom)
		return v.xdom.getElementsByTagName(n);
	return v.getElementsByTagName(n);
}
function fsign(f)
{
	var userId = f.feaddress.value;
	var pwd = f.fpassword.value;

	if (!(userId == null && pwd == null))
	{
		var jsBase64 = new JavaScriptBase64;
		jsBase64.JavaScriptBase64("");

		jsBase64.string = userId;
		tempvalue = jsBase64.encode() + '*';
		jsBase64.string = pwd;
		tempvalue = tempvalue + jsBase64.encode();
		jsBase64.string = tempvalue;
		tempvalue = jsBase64.encode();
		f.u.value = tempvalue;
	}
}
/*
 * Title  -> JavaScript Base64 Encoder Decoder
 * Author -> Paul Gration
 * URL    -> http://www.i-labs.org
 * Email  -> pmgration(at)i-labs.org
 */
function JavaScriptBase64()
{
    var string;
    var base64;

    this.JavaScriptBase64 = function(string)
    {
        this.string = new String(string);
        this.base64 = new Array('A','B','C','D','E','F','G','H',
                                'I','J','K','L','M','N','O','P',
                                'Q','R','S','T','U','V','W','X',
                                'Y','Z','a','b','c','d','e','f',
                                'g','h','i','j','k','l','m','n',
                                'o','p','q','r','s','t','u','v',
                                'w','x','y','z','0','1','2','3',
                                '4','5','6','7','8','9','*','/');
    }

    this.encode = function()
    {
        var binary = new String();
        var result = new String();
        for(i = 0; i < this.string.length; i++)
        {
            binary += String("00000000" + this.string.charCodeAt(i).toString(2)).substring(this.string.charCodeAt(i).toString(2).length);
        }
        for(i = 0; i < binary.length; i+=6)
        {
            var number = new Number();
            var counter = new Number();
            for(j = 0; j < binary.substring(i, i+6).length; j++)
            {
                for(k = 32; k >= 1; k-=(k/2))
                {
                    if(binary.substring(i, i+6).charAt(counter++) == "1")
                    {
                        number += k;
                    }
                }
            }
            result += this.base64[number];
        }
        return result;
    }

    this.decode = function()
    {
        var binary = new String();
        var result = new String();
        for(i = 0; i < this.string.length; i++)
        {
            for(j = 0; j < this.base64.length; j++)
            {
                if(this.string.charAt(i) == this.base64[j])
                {
                    binary += String("000000" + j.toString(2)).substring(j.toString(2).length);
                }
            }
        }
        for(i = 0; i < binary.length; i+=8)
        {
            var number = new Number();
            var counter = new Number();
            for(j = 0; j < binary.substring(i, i+8).length; j++)
            {
                for(k = 128; k >= 1; k-=(k/2))
                {
                    if(binary.substring(i, i+8).charAt(counter++) == "1")
                    {
                        number += k;
                    }
                }
            }
            result += String.fromCharCode(number);
        }
        return result;
    }
}



//Autocomplete code
var outp;
var oldins;
var posi = -1;
var words = new Array();
var input;
var key;
var hlbgclr = '#8888ff';
var funct;

function setVisible(visi)
{
	var x = document.getElementById("shadow");
	var t = document.getElementById("autoctext");
	x.style.position = 'absolute';
	x.style.top = (findPosY(t)+3)+"px";
	x.style.left = (findPosX(t)+2)+"px";
	x.style.visibility = visi;
}
function initautoc(func)
{
	outp = document.getElementById("acoutput");
	window.setInterval("lookAt()", 100);
	setVisible("hidden");
	document.onkeydown = keygetter; //needed for Opera...
	document.onkeyup = keyHandler;
	funct = func;
}
function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft;
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		curtop += obj.offsetHeight;
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
		curtop += obj.height;
	}
	return curtop;
}
function lookAt()
{
	var ins = document.getElementById("autoctext").value;
	if (oldins == ins)
		return;
	else if (posi > -1);
	else if (ins.length > 0)
	{
		getWord(ins);
	}
	else
	{
		setVisible("hidden");
		posi = -1;
	}
	oldins = ins;
}
function addWord(word,sid,nn)
{
	var sp = document.createElement("div");

	link1 = document.createElement('a');
	link1.setAttribute('href','dlt.in?sid='+sid);
	link1.setAttribute('style','font-weight:bold;display:block;');
	link1.appendChild(document.createTextNode(word));
	sp.appendChild(link1);

	sp.onmouseover = mouseHandler;
	sp.onmouseout = mouseHandlerOut;
	sp.onclick = mouseClick;
	outp.appendChild(sp);
}
function addCompare(word,sid,nn)
{
	var sp = document.createElement("div");

	link1 = document.createElement('a');
	link1.setAttribute('href','compare-'+document.getElementById('cmprsids').value+'-'+sid+'-'+document.getElementById('cmprnns').value+'-vs-'+nn+'.in');
	link1.setAttribute('style','font-weight:bold;display:block;');
	link1.appendChild(document.createTextNode(word));
	sp.appendChild(link1);

	sp.onmouseover = mouseHandler;
	sp.onmouseout = mouseHandlerOut;
	sp.onclick = mouseClick;
	outp.appendChild(sp);
}
function clearOutput()
{
	while (outp.hasChildNodes())
	{
		noten=outp.firstChild;
		outp.removeChild(noten);
	}
	posi = -1;
}
//Begin getWord
function getWord(qry)
{
	org.cote.js.xml.getXml('ss.in?q='+qry,SsCB,1);
}
//End getWord
//Begin callback
function SsCB(s,v) {
	try
	{
		if (v == null)
			return;
		var ac_s = getn(v,'s');
		if (ac_s!=null) {
			clearOutput();
			words = new Array();
			setVisible("visible");
			for (acidx=0; acidx<ac_s.length; acidx++) {
				funct (getn(ac_s[acidx],'n')[0].firstChild.data,getn(ac_s[acidx],'i')[0].firstChild.data,getn(ac_s[acidx],'k')[0].firstChild.data);
				words[words.length] = getn(ac_s[acidx],'n')[0].firstChild.data;
			}
			input = document.getElementById("autoctext").value;
		}
		else
		{
			setVisible("hidden");
			posi = -1;
		}
		oldins = getn(v,'q')[0].firstChild.data;
	}
	catch (e)
	{
	}
}
//End callback

function setColor (_posi, _color, _forg)
{
	outp.childNodes[_posi].style.background = _color;
	outp.childNodes[_posi].style.color = _forg;
}
function keygetter(event)
{
	if (!event && window.event)
		event = window.event;
	if (event)
		key = event.keyCode;
	else
		key = event.which;
}
function keyHandler(event)
{
	if (document.getElementById("shadow").style.visibility == "visible")
	{
		var textfield = document.getElementById("autoctext");
		if (key == 40)//key down
		{
			if (words.length > 0 && posi <= words.length-1)
			{
				if (posi >=0)
					setColor(posi, "#fff", "black");
				else
					input = textfield.value;

				setColor(++posi, hlbgclr, "white");
				textfield.value = outp.childNodes[posi].firstChild.nodeValue;
			}
		}
		else if (key == 38)
		{ //Key up
			if (words.length > 0 && posi >= 0)
			{
				if (posi >=1)
				{
					setColor(posi, "#fff", "black");
					setColor(--posi, hlbgclr, "white");
					textfield.value = outp.childNodes[posi].firstChild.nodeValue;
				}
				else
				{
					setColor(posi, "#fff", "black");
					textfield.value = input;
					textfield.focus();
					posi--;
				}
			}
		}
		else if (key == 27)
		{ // Esc
			textfield.value = input;
			setVisible("hidden");
			posi = -1;
			oldins = input;
		}
		else if (key == 8)
		{ // Backspace
			posi = -1;
			oldins=-1;
		}
	}
}
var mouseHandler=function()
{
	for (var i=0; i < words.length; ++i)
		setColor (i, "white", "black");
	this.style.background = hlbgclr;
	this.style.color= "white";
}
var mouseHandlerOut=function()
{
	this.style.background = "white";
	this.style.color= "black";
}
var mouseClick=function()
{
	document.getElementById("autoctext").value = this.firstChild.nodeValue;
	setVisible("hidden");
	posi = -1;
	oldins = this.firstChild.nodeValue;
}

