﻿	var booValue=Boolean(true);
	var SuggFlag=true;
	var LastPart='';
	var DIV_BG_COLOR = '#ffffff';
	var DIV_HIGHLIGHT_COLOR = '#c9daf9';
	var DIV_FONT = 'Mangal';
	var DIV_PADDING = '2px 5px 0px 5px';
	var DIV_BORDER = '1px solid Black';
		
				function GetSuggest() {
				if (!booValue || !SuggFlag)
				return;
					if(BKD==true)
					{
					val = queryField.value.substring(0, globalCursorPos);
					secondPart = queryField.value.substring(globalCursorPos,queryField.value.length); 
					}
 					else
 					{
					val = queryField.value;
 					}
					if(lastVal != val && searching == false && val.length >2){
 					LastPart=secondPart;
 					_GetSuggestions(val);
					lastVal=val;
					}
					else
					{
						if(val.length <=2)
						showDiv(false);
					}					  
					return true;
					}
					
             	
var queryField;
var divName;
var lastVal = "";
var val = ""
var xmlHttp;
var cache = new Object();
var searching = false;
var globalDiv;
var divFormatted = false;


function InitQueryCode (queryFieldName)
{
queryField = GD(queryFieldName);
queryField.autocomplete = "off";
divName = "querydiv";
addToCache("", new Array());
  }

function addToCache (queryString, resultArray1)
{
  cache[queryString] = new Array(resultArray1);
}
function getDiv (divID)
{
if (!GD(divID)) {
    var newNode = document.createElement("div");
    newNode.setAttribute("id", divID);
    document.body.appendChild(newNode);
}    
globalDiv = GD(divID);  
calculateposition("hindi_text");
globalDiv.style.backgroundColor = DIV_BG_COLOR;
globalDiv.style.borderLeft = DIV_BORDER;
globalDiv.style.borderBottom = DIV_BORDER;
globalDiv.style.borderRight = DIV_BORDER;
globalDiv.style.fontFamily = DIV_FONT;
globalDiv.style.padding = DIV_PADDING;
globalDiv.style.width = "297px";
globalDiv.style.height = "auto";
globalDiv.style.fontSize = "12px";
globalDiv.style.position = "absolute";
globalDiv.style.visibility = "hidden";
PlaceDiv();
return globalDiv;
}

function PlaceDiv()
{
try
{
globalDiv = GD(divName);
if(globalDiv)
{
if(browser_name=='IE'){
globalDiv.style.left = mydivleft + "px";
//if(SHMP=='Result')
//globalDiv.style.top = (mydivtop+7) + "px"; 
//else
globalDiv.style.top = (mydivtop+47) + "px"; 
}
else
{
globalDiv.style.left = (mydivleft)+ 1 + "px";
//if(SHMP=='Result')
//globalDiv.style.top = (mydivtop+3) + "px"; 
//else
globalDiv.style.top = (mydivtop+44) + "px"; 
}
}
}
catch(ex4)
{}
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}


function showQueryDiv (queryString, resultArray1)
{
if(resultArray1==null)
{
showDiv(false);
return;
}
var div = getDiv(divName);
LastPart=ltrim(LastPart);
div.innerHTML='';
div.innerHTML="<div class='ADiv' id='ASugg'></div><div class='ACDiv' onclick='showDiv(false);SuggFlag=false;'><img align='absMiddle' border='0' src='http://blogs.raftaar.in/header/images/Del1.jpg' /></div>";
var div2=GD("ASugg");
div2.style.backgroundColor = DIV_BG_COLOR;
var result='';
for (var i = 0; i < resultArray1.length; i++)
{
result+="<div style='cursor:pointer;width:100%;height:17px;' onmousedown='_selectResult(this);' onmouseover='_highlightResult(this);' onmouseout='_unhighlightResult(this);'>";
result+="<span class='result1' style='height:17px;color:#000033;text-align:left;'>"+ resultArray1[i]+LastPart+"</span></div>";
}
result+="<div style='cursor:pointer;width:100%;height:18px;' onmousedown='_selectResult(this);' onmouseover='_highlightResult(this);' onmouseout='_unhighlightResult(this);'>";
result+="<span class='result1' style='height:18px;font-weight:bold;color:black;text-align:left;'>"+ val+LastPart+"</span></div>";
div2.innerHTML=result;
var spans = div2.getElementsByTagName("div");
for (var i = 0; i < spans.length; i++)
_unhighlightResult(spans[i]);
LastPart="";
var isCached = cache[queryString];
if (!isCached)
addToCache(queryString, resultArray1);
showDiv(resultArray1.length > 0);
}

function selectResult()
{
  _selectResult(this);
}

function _selectResult(item)
{
try
{
  var spans = item.getElementsByTagName("span");
  if (spans) {
    for (var i = 0; i < spans.length; i++) {
      if (spans[i].className == "result1") {
        queryField.value = spans[i].innerHTML;
        lastVal = val = escape(queryField.value);
        searching = false;
        queryField.focus();
        break;
      }
    }
  }
  }
  catch(ex7)
  {}
  searching=false;
  LastPart="";
}

function highlightResult()
{
  _highlightResult(this);
}

function _highlightResult(item)
{
  item.style.backgroundColor = DIV_HIGHLIGHT_COLOR;
}


function unhighlightResult()
{
  _unhighlightResult(this);
}

function _unhighlightResult(item)
{
  item.style.backgroundColor = DIV_BG_COLOR;
}

function showDiv (show)
{
var div = GD(divName);
var x=GD(divName);
	if(div)
	{
		if (show)
		{
		if(div.style.visibility == "hidden")
		{
		if(browser_name=='IE')
		swipe(div, 2, 20, 5);
		else
		div.style.visibility = "visible";
		}
		else
		div.style.visibility = "visible";
		if(WSD==true)
		div.style.visibility = "hidden";
		}
		else
		{
			if(div.style.visibility == "visible")
			{
			div.style.visibility = "hidden";
			x.parentNode.removeChild(x);
			}
		}
	}
}


function hideDiv()
{
  showDiv(false);
}

function getSelectedSpanNum (div)
{

  var count = -1;
  var spans = div.getElementsByTagName("div");
  if (spans) {
    for (var i = 0; i < spans.length; i++) {
      count++;
      if (spans[i].style.backgroundColor != div.style.backgroundColor)
        return count;
      }
  }
  return -1;
}

function setSelectedSpan (div, spanNum)
{
  var count = -1;
  var thisSpan;
  var spans = div.getElementsByTagName("div");
  if (spans) {
    for (var i = 0; i < spans.length; i++) {
      if (++count == spanNum) {
        _highlightResult(spans[i]);
        thisSpan = spans[i];
            } else {
        _unhighlightResult(spans[i]);
      }
    }
  }
  
  return thisSpan;
}

window.status = "Loading swipe package...";
var swipeSteps = 4;
var swipemsec = 25;
var swipeArray = new Array();	

function swipe(el, dir, steps, msec) {

	if (steps == null) steps = swipeSteps;
	if (msec == null) msec = swipemsec;

	if (el.swipeIndex == null)
		el.swipeIndex = swipeArray.length;
	if (el.swipeTimer != null)
		window.clearTimeout(el.swipeTimer);
		
	swipeArray[el.swipeIndex] = el;

	el.style.clip = getClip(-99999, -999999, 99999, 99999);

	if (el.swipeCounter == null) {		// No animation yet!
		el.orgLeft  = el.offsetLeft;
		el.orgTop  = el.offsetTop;
		el.orgWidth = el.offsetWidth;
		el.orgHeight  = el.offsetHeight;
	}
	else if (el.swipeCounter == 0) {	// The Animation has stopped! It's now safe to update the position.
		el.orgLeft  = el.offsetLeft;
		el.orgTop  = el.offsetTop;
		el.orgWidth = el.offsetWidth;
		el.orgHeight  = el.offsetHeight;
	}
	
	el.style.left = el.orgLeft;
	el.style.top  = el.orgTop;
	
	el.swipeCounter = steps;
	el.style.clip = getClip(0,0,0,0);
	window.setTimeout("repeat(" + dir + "," + el.swipeIndex + "," + steps + "," + msec + ")", msec);
}


function repeat(dir, index, steps, msec) {
	el = swipeArray[index];
	var left   = el.orgLeft;
	var top    = el.orgTop;
	var width  = el.orgWidth;
	var height = el.orgHeight;
	
	if (el.swipeCounter == 0) {
		el.style.clip = getClip(-99999, -99999, 99999, 99999);
		return;
	}
	else {
		el.swipeCounter--;
		el.style.visibility = "visible";
		switch (dir) {
			case 2:		//down (see the numpad)
				// getClip(left, top, width, height);
				el.style.clip = getClip(0, height * el.swipeCounter / steps, width, height);
				el.style.top  = top - height * el.swipeCounter / steps + "px";
				break;
			case 8:
				el.style.clip = getClip(0, 0, width, height * (steps - el.swipeCounter) / steps);
				el.style.top  = top + height * el.swipeCounter / steps + "px";
				break;
			case 6:
				el.style.clip = getClip(width * el.swipeCounter / steps, 0, width, height);
				el.style.left  = left - width * el.swipeCounter / steps + "px";
				break;
			case 4:
				el.style.clip = getClip(0, 0, width * (steps - el.swipeCounter) / steps, height);
				el.style.left  = left + width * el.swipeCounter / steps + "px";
				break;
			case 3:
				el.style.clip = getClip(width * el.swipeCounter / steps, height * el.swipeCounter / steps, width, height);
				el.style.left  = left - width * el.swipeCounter / steps + "px";
				el.style.top  = top - height * el.swipeCounter / steps + "px";
				break;
			case 1:
				el.style.clip = getClip(0, height * el.swipeCounter / steps, width * (steps - el.swipeCounter) / steps, height);
				el.style.left  = left + width * el.swipeCounter / steps + "px";
				el.style.top  = top - height * el.swipeCounter / steps + "px";
				break;
			case 7:
				el.style.clip = getClip(0, 0, width * (steps - el.swipeCounter) / steps, height * (steps - el.swipeCounter) / steps);
				el.style.left  = left + width * el.swipeCounter / steps + "px";
				el.style.top  = top + height * el.swipeCounter / steps + "px";
				break;
			case 9:
				el.style.clip = getClip(width * el.swipeCounter / steps, 0, width, height * (steps - el.swipeCounter) / steps);
				el.style.left  = left - width * el.swipeCounter / steps + "px";
				el.style.top  = top + height * el.swipeCounter / steps + "px";
			}
		if(WSD==false)
		el.swipeTimer = window.setTimeout("repeat(" + dir + "," + index + "," + steps + "," + msec + ")", msec);
		else
		el.style.visibility = "hidden";
	}
}

function hideSwipe(el) {
	window.clearTimeout(el.swipeTimer);
	el.style.visibility = "hidden";
	el.style.clip = getClip(-99999, -99999, 99999, 99999);
	el.swipeCounter = 0;
}

function getClip(left, top, width, height) {
	if (document.all)	// ugly browser test
		return "rect(" + top + "," + width + "," + height + "," + left + ")";
	else if (document.getElementById)
		return "rect(" + top + "px," + left + "px," + height + "px," + width + "px)";
}

window.status = "";

