/*************************************************************************
              Shemaroo Entertainment Pvt. Ltd.          
                Shemaroo Autosearch Plugin (Version 3.0)       
                    By Manish Sathe                    
           Copyright (c) 2008 Shemaroo Ent. Pvt. Ltd.      


    WARNING: This software program is protected by copyright      
    law and international treaties. Unauthorized reproduction     
    or distribution of this program, or any portion of it, may    
    result in severe civil and criminal penalties, and will be 
    prosecuted to the maximum extent possible under the law.
    
    Note: This scrit is diferent from "SHEM_AutoSearch.js" foudn in root directory
          This script has been modified for shemaroo online shopping

***************************************************************************/
var AutoSearch_http;
var AutoSearch_Ticker=0;
var AutoSearch_State=0;
var AutoSearch_totalRows=0;
var AutoSearch_CurrentRow=0;
var AutoSearch_LastStr="";
var AutoSearch_SelTitleName="";
AutoSearch_http=AJAX();
var Autosearch_ConSearch;
Autosearch_ConSearch="yes";
var Autosearch_timer;

function SHEM_Autosearch(e)
{
clearTimeout(Autosearch_timer)
Autosearch_ConSearch="no";
AutoSearch_http.abort();
if(AutoSearch_target==""){alert("AutoSearch_target value not assigned");return;}
var e = e || event;
if(e.keyCode==38)
 {
 return;
 }
if(e.keyCode==40)
 {
 return;
 }
 xstr=document.getElementById(AutoSearch_target).value;
if(xstr=="" || xstr.length <=2){return;}
if(AutoSearch_LastStr==document.getElementById(AutoSearch_target).value){return;}
AutoSearch_LastStr=document.getElementById(AutoSearch_target).value;
document.getElementById(AutoSearch_target).onmousemove=SHEM_AutoSearch_stay;
document.getElementById(AutoSearch_target).onmouseout=SHEM_AutoSearch_TickTimer;
document.getElementById(AutoSearch_target).onkeydown=AutoSearch_checkKey;
str=document.getElementById(AutoSearch_target).value
CreateAutoSearchBox();
Autosearch_timer=setTimeout("SHEM_AutoSearch_RequestData(str)",'100')
}

function AutoSearch_checkKey(e)
{
var e = e || event;
if(e.keyCode==38)
 {
 AutoSearch_xMoveUP();
 }
if(e.keyCode==40)
 {
 AutoSearch_xMoveDown();
 }
if(e.keyCode==13)
 {
 AutoSearch_SetThis2(AutoSearch_CurrentRow);
 Product_Search();
 //xSetThis2(xBoxSelRow);void(0);
 }
}


function AutoSearch_xMoveDown()
{
if(AutoSearch_State==1)
{
 if(AutoSearch_CurrentRow==0)
 {
 AutoSearch_CurrentRow=0;
 }else{
   ddx=document.getElementById("xBox_row_"+AutoSearch_CurrentRow);
  ddx.bgColor='#6585A3';
  ddx.style.color='white';
 }
 if(AutoSearch_CurrentRow==AutoSearch_totalRows){AutoSearch_CurrentRow=0;}
 AutoSearch_CurrentRow++;
 if(AutoSearch_CurrentRow<=AutoSearch_totalRows){
 ddx=document.getElementById("xBox_row_"+AutoSearch_CurrentRow);
   ddx.bgColor='#EFF4FA';
   ddx.style.color='#000000';
   AutoSearch_SetThis2(AutoSearch_CurrentRow);
 }
 }

}

function AutoSearch_xMoveUP()
{
if(AutoSearch_State==1)
 {
 if(AutoSearch_CurrentRow==0){
  AutoSearch_CurrentRow=AutoSearch_totalRows+1;
  }else{
  ddx=document.getElementById("xBox_row_"+AutoSearch_CurrentRow);
  ddx.bgColor='#6585A3';
  ddx.style.color='white';
  }
  AutoSearch_CurrentRow--;
  if(AutoSearch_CurrentRow >=1)
   {
   ddx=document.getElementById("xBox_row_"+AutoSearch_CurrentRow);
   ddx.bgColor='#EFF4FA';
   ddx.style.color='#000000';
   AutoSearch_SetThis2(AutoSearch_CurrentRow);
   }
 }
}


function CreateAutoSearchBox()
{
if(document.getElementById("auto_s_box")){return;}
box_div=document.createElement("div")
box_div.id="auto_s_box"
box_div.style.position="absolute";
box_div.onmouseover=SHEM_AutoSearch_stay;
box_div.style.visibility="hidden";
box_div.onmouseout=SHEM_AutoSearch_TickTimer;
document.body.appendChild(box_div);
AutoSearch_Repos_Box()
}

function SHEM_AutoSearch_TickTimer()
{
clearTimeout(AutoSearch_Ticker)
AutoSearch_Ticker=setTimeout(SHEM_AutoSearch_hide,'1000')
}

function SHEM_AutoSearch_stay()
{
clearTimeout(AutoSearch_Ticker);
}

function SHEM_AutoSearch_hide()
{
clearTimeout(AutoSearch_Ticker);
AutoSearch_State=0;
document.getElementById("auto_s_box").innerHTML="";
document.getElementById("auto_s_box").style.visibility="hidden";
}

function isBorwserType(str)
{
nav=navigator.appName
if(nav.indexOf(str) <= -1)
 {
 return false;
 }else{
 return true;
 }
}

function AutoSearch_Repos_Box()
{
box_div=document.getElementById("auto_s_box");
t_field=document.getElementById(AutoSearch_target);
box_div.style.width=t_field.offsetWidth;
search_box_height=box_div.offsetHeight
tar_fld_top=t_field.offsetTop;
box_div.style.left=t_field.offsetLeft;
if(isBorwserType("Internet Explorer")==true)
 {
 box_div.style.top=tar_fld_top-search_box_height-0;
 }else{
 box_div.style.top=tar_fld_top-search_box_height;
 }
}

function SHEM_AutoSearch_RequestData(str)
{
if(str==""){return;}
AutoSearch_http.abort();
xfld=document.frmMain.strFld.value;
AutoSearch_http.open('get',"tt_resp.asp?str="+str+"&fld="+xfld+"&time="+Date);
AutoSearch_http.onreadystatechange=SHEM_AutoSearch_DataArrived;
Autosearch_ConSearch="yes";
AutoSearch_http.send(null);
}

function SHEM_AutoSearch_DataArrived()
{
if(Autosearch_ConSearch=="no"){return;}
if(AutoSearch_http.readyState != 4)
 {

 }
if(AutoSearch_http.readyState == 4)
 {
 re=AutoSearch_http.responseText
 if(re==""){SHEM_AutoSearch_hide();return;}
 document.getElementById("auto_s_box").innerHTML=re;
 document.getElementById("auto_s_box").style.visibility="";
 AutoSearch_State=1;
 AutoSearch_totalRows=document.getElementById("tablexbox").rows.length;
 AutoSearch_CurrentRow=0;
 AutoSearch_Repos_Box()
 }
}


function SetThis(str,rid)
{
SHEM_AutoSearch_hide()
document.getElementById(AutoSearch_target).value=str;
Product_Search();
}

function AutoSearch_SetThis2(rowID2)
{
clearTimeout(AutoSearch_Ticker);
if(rowID2>=1)
 {
 str=document.getElementById("xBox_row_"+rowID2).innerText;
 if(str==undefined)
 {
 str=document.getElementById("xBox_row_"+rowID2).title;
 //Product_Search();
 }
 //alert(str);
 document.getElementById(AutoSearch_target).value=str;
 AutoSearch_LastStr=str;
 //Product_Search();
 }
}

function AutoSearch_Filter_str(str)
{
str=str.replace('<font face="Arial" size="1">','')
str=str.replace('</font>','')
str=str.replace('<font face="Arial" size="1">','')
str=str.replace('</font>','')
str=str.replace('<font color="yellow" size="1"><b>','')
str=str.replace("</b></font>","")
str=str.replace("</b>","")
str=str.replace("<font size='1' color='yellow'><b>","")
str=str.replace("</b></font>","")
return str;
}

////////////////////////////////////////////
