﻿// JScript File
      var arrStores= new Array(33); 

        brr = new Array("","");crr = new Array("","");arrStores[0] = new Array("All Stores",brr,crr);  
	brr = new Array("Product Name");crr = new Array("title");arrStores[1] = new Array("Accessories",brr,crr);
	brr = new Array("Product Name");crr = new Array("title");arrStores[2] = new Array("Apparel",brr,crr);
	brr = new Array("Product Name");crr = new Array("title");arrStores[3] = new Array("Appliances",brr,crr);  
        brr = new Array("Title","Author","ISBN");crr = new Array("title","author","sku",""); arrStores[4] = new Array("Books",brr,crr);  
        brr = new Array("Product Name");crr = new Array("title");arrStores[5] = new Array("Cakes",brr,crr);
        brr = new Array("Product Name");crr = new Array("title");arrStores[6] = new Array("Cameras",brr,crr);
        brr = new Array("Product Name");crr = new Array("title");arrStores[7] = new Array("CDROMs",brr,crr);
	brr = new Array("Product Name");crr = new Array("title");arrStores[8] = new Array("Chocolates",brr,crr);
	brr = new Array("Product Name");crr = new Array("title");arrStores[9] = new Array("Condoms",brr,crr);      
        brr = new Array("Product Name");crr = new Array("title");arrStores[10] = new Array("Cosmetics",brr,crr);
	brr = new Array("Product Name");crr = new Array("title");arrStores[11] = new Array("Electronics",brr,crr);
        brr = new Array("Product Name");crr = new Array("title");arrStores[12] = new Array("Flowers",brr,crr);   
        brr = new Array("Product Name");crr = new Array("title");arrStores[13] = new Array("Foods",brr,crr);     
        brr = new Array("Product Name");crr = new Array("title");arrStores[14] = new Array("Furnishings",brr,crr);  
        brr = new Array("Product Name");crr = new Array("title");arrStores[15] = new Array("Giftarticles",brr,crr);  
        brr = new Array("Product Name");crr = new Array("title");arrStores[16] = new Array("Handicrafts",brr,crr);
        brr = new Array("Product Name");crr = new Array("title");arrStores[17] = new Array("Health",brr,crr);
	brr = new Array("Product Name");crr = new Array("title");arrStores[18] = new Array("Jewellery",brr,crr); 
	brr = new Array("Product Name");crr = new Array("title");arrStores[19] = new Array("Magazine",brr,crr);
     	brr = new Array("Product Name");crr = new Array("title");arrStores[20] = new Array("Miscellaneous",brr,crr);
	brr = new Array("Product Name");crr = new Array("title");arrStores[21] = new Array("Mobiles",brr,crr);
	brr = new Array("Product Name");crr = new Array("title");arrStores[22] = new Array("Movies",brr,crr); 
	brr = new Array("Album Name");crr = new Array("title");arrStores[23] = new Array("Music",brr,crr);
        brr = new Array("Product Name");crr = new Array("title");arrStores[24] = new Array("Paintings",brr,crr); 
        brr = new Array("Product Name");crr = new Array("title");arrStores[25] = new Array("Perfumes",brr,crr);
        brr = new Array("Product Name");crr = new Array("title");arrStores[26] = new Array("Spirituality",brr,crr);
        brr = new Array("Product Name");crr = new Array("title");arrStores[27] = new Array("Sports",brr,crr);
        brr = new Array("Product Name");crr = new Array("title","sku","");arrStores[28] = new Array("Stationery",brr,crr);
        brr = new Array("Product Name");crr = new Array("title");arrStores[29] = new Array("Sweets",brr,crr); 
	brr = new Array("Product Name");crr = new Array("title");arrStores[30] = new Array("Swissknives",brr,crr);    
        brr = new Array("Product Name");crr = new Array("title");arrStores[31] = new Array("Toys",brr,crr);   
     	brr = new Array("Product Name");crr = new Array("title");arrStores[32] = new Array("Watches",brr,crr);

        

 function LoadSearchData()
  {
    var x = document.getElementById("ctl00_searchStore"); 
    if(x == null)
        x = document.getElementById("searchStore");
    var i = 0;      
    var dispText=null;
    var dispVal;
    var isHavingStore=false;
    var curStore = document.getElementById("ctl00_CurrentStore");
    if(curStore == null)
        curStore = document.getElementById("CurrentStore");
    x.length = 0;
    
    if(curStore != null)
    {
        if(curStore.value != null)
            dispText= curStore.value;
    }
    
    for(intCol = 0 ; intCol < arrStores.length ; intCol++)
    {
        if(dispText.toLowerCase() == arrStores[intCol][0].toString().toLowerCase())
        {
            isHavingStore = true;
            x.length = 1;
            i = 1;
            break;
        }
        
    }
            
    for(intCol = 0 ; intCol < arrStores.length ; intCol++)
    {
        
      if(dispText != null)
      {
        if(dispText.toLowerCase() != arrStores[intCol][0].toString().toLowerCase())
        {
          x.length = x.length +1;
          x[i].text = arrStores[intCol][0];
          x[i].value = arrStores[intCol][0];
          i++;
        }
        else
          dispText = arrStores[intCol][0];
     }
   }
  
  if(isHavingStore == true)
  {  
      x[0].text = dispText;
      x[0].value = dispText;
  }
  else
    dispText ="All";
     
    var y = document.getElementById("ctl00_searchField");  
    if(y == null)
        y = document.getElementById("searchField");  
    y.length=0;
    for(intCol = 0 ; intCol < arrStores.length ; intCol++)
    {        
      if ( dispText.toLowerCase() == arrStores[intCol][0].toString().toLowerCase() )
      {
        var cvb = arrStores[intCol][1] ;
        var cvb1 = arrStores[intCol][2];
        for ( intRow = 0 ; intRow < cvb.length ; intRow++)
            {       
                y.length = y.length + 1;
                y[intRow].text =  cvb[intRow];
                y[intRow].value = cvb1[intRow]
            }
        break;
      }
    }
    
    var textbox1 = document.getElementById("ctl00_TextBox1");
    if(textbox1 == null)
        textbox1 = document.getElementById("TextBox1");
    textbox1.value= x.value;
    var textbox2 = document.getElementById("ctl00_TextBox2");
    if(textbox2 == null)
        textbox2 = document.getElementById("TextBox2");
    textbox2.value = y.value;
   }
        
function ChangeSearchFieldValues()
{ 
  var x = document.getElementById("ctl00_searchStore");  
  if(x == null)
       x = document.getElementById("searchStore");  
  var y = document.getElementById("ctl00_searchField");  
  if(y == null)
    y = document.getElementById("searchField");  
  var myindex  = x.selectedIndex;
  var SelValue = x.options[myindex].value;
    
  var textbox1 = document.getElementById("ctl00_TextBox1"); 
  if(textbox1 == null)
    textbox1 = document.getElementById("TextBox1"); 
  y.length=0;
   
  for(intCol = 0 ; intCol < arrStores.length ; intCol++)
  {
     if ( x.value == arrStores[intCol][0] )
      {
        var cvb = arrStores[intCol][1] ;
        var cvb1 = arrStores[intCol][2];
        for ( intRow = 0 ; intRow < cvb.length ; intRow++)
            {
                y.length = y.length + 1;
                y[intRow].text = cvb[intRow]
                y[intRow].value = cvb1[intRow]
                
            }
        break;
       }
  }
  
  if(SelValue.length != 0)
   {
     textbox1.value= SelValue;
   }
    var textbox2 = document.getElementById("ctl00_TextBox2");
    if(textbox2 == null)
        textbox2 = document.getElementById("TextBox2");
    textbox2.value = y.value;
}

function Fieldvalue()
{
    var y = document.getElementById("ctl00_searchField");
    if(y==null)
        y = document.getElementById("searchField");
    var myindex  = y.selectedIndex;
    var SelValue = y.options[myindex].value;
    var textbox2 = document.getElementById("ctl00_TextBox2");
    if(textbox2 == null)
        textbox2 = document.getElementById("TextBox2");  
    if(SelValue != null)
    {
       textbox2.value= SelValue;
    }
   
}


function ValidateSearchValues()
{
  var x = document.getElementById("ctl00_searchStore");    
  if(x == null)
     x = document.getElementById("searchStore"); 
  var y = document.getElementById("ctl00_searchField"); 
  if(y == null) 
    y = document.getElementById("searchField"); 
  if ( x.value == "")
      {
        alert("Please Select the Store");
        x.focus();
        return false;
      }
  if ( y.text == "")
      {
        alert("Please Select the Search Key");
        y.focus();
        return false;
      }    
        var z = document.getElementById("ctl00_searchVal"); 
        if(z== null)
            z = document.getElementById("searchVal");  
  if ( z.value == "")
      {
        alert("Please Enter the Search Value to Search");
        z.focus();
        return false;
      }
      
      
   alert(z.value);
   location.href = "/search.aspx?catalog="+x.value + "&srchkey="+y.value+"&srchval="+z.value;
    
}

function validatebutton(ouser,e)
{
    var x= document.getElementById("ctl00_CPMiddle_ListItems_lc1");
    if (x.value != "")
    {
    e.IsValid = false;
    }
    else
    {
    e.IsValid = true;
    }
}
function NumbersOnly(e)
{
    var unicode=e.charCode? e.charCode : e.keyCode;
    if (unicode!=8)
    	{
   		if (unicode>48||unicode<57||unicode==37||unicode==39||unicode==40||unicode==38)
  		    return true;
        else
            return false;
        }
        
 }
 
 
 function AlphaNumericsOnly(e)
{
    var unicode=e.charCode? e.charCode : e.keyCode;
    if (unicode!=8)
    	{
    		if ( (unicode >= 65 && unicode <=90) || (unicode>= 97 && unicode <= 132) || (unicode>=48 && unicode <= 57) || unicode == 44 )
    		        return true;
    		else
    		    return false;
        }	
 }
 
 function ShowpopupWindow(x)
  {
    x = x.toLowerCase();
    if ( x.indexOf("displayorder.aspx") >= 0 )
    {
       popWindow = window.open(x,"a","location=0,status=0,scrollbars=1,width=990,height=600");
    }
    else if(x.indexOf("usergiftcertificate.aspx") >= 0)
    {
        popWindow = window.open(x,"a","location=0,status=0,scrollbars=1,width=500,height=250");
        popWindow.moveTo(150,150);
    }
    else
    {
       popWindow = window.open(x,"a","location=0,status=0,scrollbars=1,width=500,height=150");
       popWindow.moveTo(150,150);
    }
  }
  

/* AJAXAutocompleteutilities.js*/

    // AJAXAutoComplete for ASP.NET 2.0 - v1.0, 2006-04-20
    // Wayne Hunt - http://blog.ourcurrentfuture.com

// ** function getObj(name) **
// parameters: name = id of the object to get
// performs: sets the variable to the DOM object associated with the ID
// returns: object (x)
function getObj(strName)
{
  if (document.getElementById)
  {
    return document.getElementById(strName);
  }
  else if (document.all)
  {
    return document.all[strName];
  }
  else if (document.layers)
  {
    return document.layers[strName];
  } 
  else 
  {
    return null;
  }
 }


// ** function fill AutoComplete **
// parameters:  result - pipe-delimited list of matching entries
// performs: Clears list, then fills matching values
// returns: none
function fillAutoComplete(strResult)
{
   var divResults = getObj('AutoCompleteResults');
   //divResults.style.display = "none";
   strFields = strResult.split('|');  // split the results into a string[]
   var strOptionString = "";
   if((strFields.length-2) >=1 && strFields[0] != "")
   {
              var strOptionID;
       for (var i = 0; i <  strFields.length-2; i++)
       {
               var searchvalue=strFields[i];
               searchvalue= searchvalue.replace("<b>","");
               searchvalue=searchvalue.replace("</b>","");
               searchvalue=searchvalue.replace("<font color='Red'>","");
               searchvalue=searchvalue.replace("</font>","");
               searchvalue= searchvalue.replace("<b>","");
               searchvalue=searchvalue.replace("</b>","");
               searchvalue=searchvalue.replace("<font color='Red'>","");
               searchvalue=searchvalue.replace("</font>","");
                if(document.getElementById("ctl00_searchField").options[document.getElementById("ctl00_searchField").selectedIndex].value=="Author")
                {
                    strOptionString += "<a href=\"http://www.indiaplaza.in/" + RemoveSplChar(searchvalue) + ".htm\"><div class=\"listOption\" onmouseover=\"this.className='listOptionHighlighted'\" onmouseout=\"this.className='listOption'\">" + strFields[i] + "</div></a>\n"; // add Results to result group
                }
                else
                {
                    strOptionString += "<a href=\"http://www.indiaplaza.in/search.aspx?catname=books&srchkey=Title&srchVal=" + searchvalue + "\"><div class=\"listOption\" onmouseover=\"this.className='listOptionHighlighted'\" onmouseout=\"this.className='listOption'\">" + strFields[i] + "</div></a>\n"; // add Results to result group
     		}
       }

       //added by hemanth @21/2/2009
       var txtQuery = getObj('ctl00_searchVal');
       var len=strFields[strFields.length-2].split('=')[1];
       //alert(getObj('ctl00_AutoSuggestResult'));
       var result=getObj('ctl00_AutoSuggestResult');
       if((txtQuery.value.length==parseInt(len) || txtQuery.value.length==parseInt(len-1) || txtQuery.value.length==parseInt(len-2))  && strFields.length>2)
       {
            divResults.style.display = "block";
            result.value=strOptionString;
            //divResults.innerHTML = strOptionString;
       }
       if(parseInt(len)!=2)
       {
       if(result.value!='')
               divResults.innerHTML = strOptionString;
       else
               divResults.style.display = "none";
       }
//        else
//       {
//        divResults.style.display = "none";
//        }
       if(txtQuery.value.length==0)
       {
        divResults.style.display = "none";
       }
   }
   else
   {
       divResults.style.display = "none";
   }
} 

function RemoveSplChar(searchvalue)
{
    var str1=searchvalue;
    for (var i = 0; i < str1.length; i++) 
    {
	    if ((str1.charCodeAt(i) >=48 && str1.charCodeAt(i) <= 57) || str1.charCodeAt(i) == 101 || str1.charCodeAt(i) == 126 || str1.charCodeAt(i) == 64 || str1.charCodeAt(i) == 35 || str1.charCodeAt(i) == 36 || str1.charCodeAt(i) == 37 || str1.charCodeAt(i) == 38 || str1.charCodeAt(i) == 40 || str1.charCodeAt(i) == 41 || str1.charCodeAt(i) == 42 || str1.charCodeAt(i) == 94 || str1.charCodeAt(i) == 95)
	    {
	                if(str1.charAt(i)!= "e")
	                {
	                    str1=str1.replace(str1.charAt(i),"-");
	                }
	                
        }
    }
    str1=str1.replace(" ","-");
	str1=str1.replace(":","-");
	str1=str1.replace(" - ","-");
    return str1;
}


// ** function Choose **
// parameters:  strSelectedTerm - selected value
// performs: Fills Querybox with selected value, and submits if AutoPostBack is enabled
function Choose(strSelectedTerm)
{
  var txtQuery = getObj(strQueryBoxName);
  txtQuery.value = strSelectedTerm;

  var divResults = getObj(strResultDivName);
  divResults.style.display = "none";

  if(blnAutoPostBack)
  {
    //var submitButton = getObj(strSubmitButtonName);
    //submitButton.click();
  }

}
// ** function onError(message) **
// parameters:  message - error message to be appended
// performs: pops up a Javascript alert when there's an error
// returns: none
function onError(strMessage) 
{
    alert("Error:\n" + strMessage);
}


// ** Hiding the result result div **//
document.onclick=check; 
function check(e)
{ 
    var target = (e && e.target) || (event && event.srcElement); 
    document.getElementById('AutoCompleteResults').style.display = "none";
}


String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};