// JavaScript Document

function trimT(str){return str.replace(/^\s*|\s*$/g,"");}
//RAVI SUGGEST CODE
var RvFilltDiv = "";
var RvFillControl = "";
var RvLoopControl = "";
var RvBtControl = "";
var ReurnContent = "";
var FinalBool = true;

function Search_SuggestOpen()
{

if(FinalBool == true)
{
document.getElementById(RvFilltDiv).style.display = "";
document.getElementById(RvFilltDiv).innerHTML='';
var r=ReurnContent.split("~");
var pp=r.length;
var kk="<table  border='0' cellspacing='0' cellpadding='0' style='border:1px solid #CFCFCF; background-color:#FAF5ED;'>";
var mvar = 1;
for(var j=0;j<pp-1;j++)
{
	var txtLen=r[j].length+4;
	var Final=r[j];
				
	if(mvar == 1)
	var Top = 0;
	else
	var Top = mvar-1;
	
	if(mvar == pp)
	var Down = 0;
	else
	var Down = mvar+1;
	
	LoopCnt = RvLoopControl+mvar;
	
				
	kk+="<tr><td align=left><input type=text name="+LoopCnt+" id="+LoopCnt+" value='"+Final+"' style='border:0px; background-color:#FAF5ED; cursor:pointer; padding:2px;' class='rvclass' onmouseover='this.style.backgroundColor = \"#CFCFCF\";' onmouseout='this.style.backgroundColor = \"#FAF5ED\"' onClick='document.getElementById(\""+RvFillControl+"\").value=this.value;document.getElementById(\""+RvFilltDiv+"\").style.display = \"none\";GoSearch();' size="+txtLen+" onBlur='this.style.backgroundColor = \"#FAF5ED\"' onKeyDown='Search_KeyUpDownFun("+mvar+","+Top+","+Down+",event,\""+RvLoopControl+"\",\""+RvFilltDiv+"\",\""+RvFillControl+"\")' onFocus='this.style.backgroundColor = \"#CFCFCF\";document.getElementById(\""+RvFillControl+"\").value=this.value;' readonly='readonly'></td></tr>";
				
	mvar++;	
}

kk+="</table>";

document.getElementById(RvFilltDiv).innerHTML=kk;
	
		//Position Code
		var el = document.getElementById(RvBtControl);
		var x = 0;
		var y = el.offsetHeight;

		//Walk up the DOM and add up all of the offset positions.
		while (el.offsetParent && el.tagName.toUpperCase() != 'BODY')
		{
			x += el.offsetLeft;
			y += el.offsetTop;
			el = el.offsetParent;
		}

		x += el.offsetLeft;
		y += el.offsetTop;

		document.getElementById(RvFilltDiv).style.left = x+1 + 'px';
		document.getElementById(RvFilltDiv).style.top = y+2 + 'px';
		//Position Code
}
else
Search_SuggestClose();

}

function Search_SuggestClose()
{
document.getElementById(RvFilltDiv).style.display = "none";
document.getElementById(RvFilltDiv).innerHTML = "";	
}

function Search_SuggestDelay()
{
var el = document.getElementById(RvBtControl);
		var x = 0;
		var y = el.offsetHeight;

		//Walk up the DOM and add up all of the offset positions.
		while (el.offsetParent && el.tagName.toUpperCase() != 'BODY')
		{
			x += el.offsetLeft;
			y += el.offsetTop;
			el = el.offsetParent;
		}

		x += el.offsetLeft;
		y += el.offsetTop;

		document.getElementById(RvFilltDiv).style.left = x+1 + 'px';
		document.getElementById(RvFilltDiv).style.top = y+2 + 'px';
		//Position Code
		
		document.getElementById(RvFilltDiv).style.display = "";
	document.getElementById(RvFilltDiv).innerHTML="<table border=0 cellspacing=0 cellpadding=0 style='border:1px solid #CFCFCF; background-color:#FAF5ED;width:198px;'><tr><td align=left>&nbsp;Loading... Please Wait!</td></tr></table>";

}


function Search_AjaxFun(val,e,cid,MyName,Type,FillCnt,LoopCnt,Btctr)
{
if(cid == 0)
return false;

var key;
RvFilltDiv = MyName;
RvFillControl = FillCnt;
RvLoopControl = LoopCnt;
RvBtControl = Btctr;


     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which; 
	
	if(key==27)
	{
	document.getElementById(MyName).style.display="none";
	return false;
	}	


if( (key>=48 && key<=57) || (key>=97 && key<=122) || (key>=65 && key<=90) || key==8 || key==46 || key==35 || key==33 || key==43 || key==45 || key==42 || key==32 || key==16 || key==109 )
{

var MainVal = trimT(val);

if(MainVal == "")
{
document.getElementById(MyName).style.display = "none";
FinalBool = false;
}

if(MainVal != "")
{
FinalBool = true;
var xmlhttp=false; 
				try {
						xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
				} catch (e) {
						try {
								xmlhttp = new
								ActiveXObject('Microsoft.XMLHTTP'); 
					} catch (E) {
						xmlhttp = false;
								}
				}
				if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
						xmlhttp = new XMLHttpRequest(); 
				}

			
			var page = "?keyword="+MainVal+"&cid="+cid+"&SType="+Type;
			 var file = 'RVsuggest_search.php'; 
	 
			xmlhttp.open('GET', file + page, true); 
			
			xmlhttp.onreadystatechange=function() 
			{
					if (xmlhttp.readyState==4) 
					{ 
							var content = xmlhttp.responseText; 
							if( content )
							{ 
								if(content != 0)
								{
								ReurnContent = content; 
								Search_SuggestOpen();
								}
								else
								Search_SuggestClose();

							}
							else
							Search_SuggestClose();
								
					}//Delay
					else
					Search_SuggestDelay();
					
					
				}
				xmlhttp.send(null) 
				return;

} //Keyword Null
else
Search_SuggestClose();
	
}	//Key Valid

}

function Search_KeyUpDownFun(cr,top,down,e,ContPref,DivName)
{
var key;
if(window.event)key = window.event.keyCode;  else key = e.which; 

var TopControl = ContPref + top;var DownControl = ContPref + down;var CurControl = ContPref + cr;

if(key==38) //Up
{
if(top !=0)document.getElementById(TopControl).focus();else document.getElementById(CurControl).focus();
 }

 if(key==40) //Down
 {
 if(down !=0)document.getElementById(DownControl).focus();else document.getElementById(CurControl).focus();
 }
			 
 if(key==13 || key==32 ) //Enter
{
document.getElementById(DivName).style.display = "none";document.getElementById(DivName).innerHTML = "";
if(key==13)
GoSearch();
}	

}

			//Suggest Close
