﻿//search specific functions starts here 
//-------------------search validation function starts here-----------------------------

function activemenu(ctrl)
  {
  document.getElementById("tab1").cssclass="";
  document.getElementById("tab2").cssclass="";
  document.getElementById("tab3").cssclass="";
  ctrl.className="select";
  }
  
function searchvalidation()
{
var txtsearch=document.getElementById("searchtext");
    if(txtsearch.value==""||txtsearch.value=="Search")
    {
        txtsearch.value="Please enter text";
        //return false;
    }
	
var txt=document.getElementById("searchtext").value;
var index=document.getElementById("ddsearchopt").selectedIndex;

switch(index)
{
case 1:
document.location="search.aspx?searchtext="+txt+"&typeofsearch=1";
break;
case 0:
document.location="advancesearch.aspx?searchtext="+txt+"&typeofsearch=1";
break;
}

//return false;
}

//-------------------ends here-----------------------------

//-------------------change year function starts here-----------------------------
    function changeyear()
      {
      var ctrl=document.getElementById("ddyear");
        window.location="pressroom.aspx?year="+ctrl.options[ctrl.selectedIndex].value;
     }
     
//-------------------ends here-----------------------------
     
     
//-------------------get search data function is use for getting the search text parametere through query string. starts here-----------------------------     
      function getsearchdata()
      {
        var stext=document.getElementById("txtsearchtext").value;
        var btype=1;
        if(document.getElementById("rdExactMatch").checked==true)
        {
            btype=0;
        }
        else if(document.getElementById("rdAllWord").checked==true)
        {
          btype=2;
        }
        window.location="search.aspx?searchtext="+stext+"&typeofsearch="+btype;
      //ajaxRequest(null,'true','GET','','search.aspx?searchtext='+stext+'&typeofsearch='+btype+'&pagenumber=0&strip=strip&test=test','myspan');
      return false;
      }
//-------------------ends here-----------------------------      

//-------------------this function is use to get the query string from the url starts here-----------------------------
function querySt(ji) {

hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
if(ft[1]!=null)
{
return ft[1];
}else
{return 1;}
}
}


return 1;
}


//------------------- ends here-----------------------------

//search specific functions ends here

//category and product page related javascript starts here


//-------------------open panel function is use to open the compare box panel starts here-----------------------------
  function openpanel(ctrl)
      {

      return hs.htmlExpand(ctrl, { outlineType: 'rounded-white', objectType: 'iframe' } );
      }
       function removeproduct()
      {
      var pageurl="Addedproduct.aspx?strip=strip&check=false";
      var i;
      var strid="";            
      var c = new Array();
      c = document.getElementsByTagName('input');
    for (var i = 0; i < c.length; i++)
    {
        if (c[i].type == 'checkbox')
        {
                if(c[i].checked)
                { 
                     if(strid!="")
                        {
                        strid+="-"+c[i].id;
                        }
                    else          
                        {
                        strid=c[i].id;
                        }
                        
                }
          }
    }
      
      pageurl+="&CompareProductID="+strid+"&test=test";
      pageurl=pageurl.replace(/amp;/g, "");
       ajaxRequest(null,'true','GET','',pageurl,'divcompareresult');
       return false;
      }
      
//-------------------ends here-----------------------------


//-------------------read div function is use to idetified that whethere is there any checkbox on the page if yes then needs to display the div otherwise hide it.starts here-----------------------------      
     function readDiv(val)
      {        
        var c = new Array();
        c =  document.getElementsByTagName('input');
        var count=0;
        for (var i = 0; i < c.length; i++)
        {
            if (c[i].type == 'checkbox')
            {
                
                count++;
                //////alert(count);
                //break;
            }
        }                
        if(count<=1)        
        {
            slideindiv();//if there is no checkbox means div needs to be hide.
            hidepanelbuttons();
        }        
        else
        {
            slideoutdiv();//if there are checkboxes means div needs to be shown.
            
        }
        return false;
      }
      
//-------------------ends here-----------------------------      

//-------------------slideoutdiv function is use to open the div using slider style starts here-----------------------------
  function slideoutdiv()//open div
  {
    //$('#divcompareresult').show('slow');
    try { $('.mover').slideDown(); } catch(e) { }
    try { $("#divhidelink").show(); } catch(e) { }
    
    try { $("#divshowlink").hide(); } catch(e) { }
    try { createCookie("panel", "open", 1); } catch(e) { }
  }
//-------------------ends here-----------------------------  

//-------------------slideoutdiv function is use to close the div using slider style starts here-----------------------------
  function slideindiv()//close div
  {
    try { $('.mover').slideUp(); } catch(e) { }
    try { $("#divhidelink").hide(); } catch(e) { }
    
    try { $("#divshowlink").show(); } catch(e) { }
    try { createCookie("panel", "close", 1); } catch(e) { }
  }
  
//-------------------ends here-----------------------------  

//-------------------hidepanelbuttons function is use to hide the compare panel buttons starts here-----------------------------
   function hidepanelbuttons()
  {
    try { document.getElementById("divhidelink").style.display="none"; } catch(e) { }
    try { document.getElementById("divshowlink").style.display="none"; } catch(e) { }
  }  
//-------------------ends here-----------------------------  

//-------------------disableimgButtons function is use to disable the image buttons starts here-----------------------------  
  function disableimgButtons(pids)
  {
    var arr=new Array();
    ////alert(pids);
      if(pids!="")
      {
      arr=pids.split(',');
      var i=0;
      ////alert(arr.length);
      while(i<arr.length)
      {
        try { document.getElementById("img"+arr[i]).disabled="true"; } catch(e) { }
        i++;
      }
      }
  }
  
//-------------------ends here-----------------------------  

//-------------------createcookie function is use to set the cookie on the browser starts here-----------------------------
  function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

//-------------------ends  here-----------------------------

//-------------------read cookie function is use to read the cookie from the browser starts here-----------------------------
function readCookie(name) {
	try
	{
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	    }
	} catch(e) { }
	return null;
}

//-------------------ends here-----------------------------

//-------------------rease cookie function is use to delete the cookie from the browser starts here-----------------------------
function eraseCookie(name) {
	createCookie(name,"",-1);
}
//-------------------ends here-----------------------------

//-------------------disableids function is use to disable the image buttons starts here-----------------------------
function disableids(val)
{
var arr=new Array();
arr=ids.split(',');
var j=0; 
     for(j=0;j<arr.length;j++)
     {   
          try{ document.getElementById("img"+arr[j]).disabled=true; } catch(e) { }
     }

}

//-------------------ends here-----------------------------

//-------------------change image function is use to change the big image on the micro image click using ajax starts here-----------------------------
 function changimage(im,skuname,productid,ino)
      {
        ////alert("im:"+im+"--skuname:"+skuname+"productid:"+productid+"---ino:"+ino);
        var url="Largeimage.aspx?skuname="+skuname+"&productid="+productid+"&imageno="+ino+"&test=test";                
        ajaxRequest(null,'true','GET','',url,"lareimage"); 
      
      }
//-------------------ends here-----------------------------      
      
//-------------------showRecentlyViewPanel function is use to show-slide the recently viewed or visited products  starts here-----------------------------           
  function showRecentlyViewPanel()//open recentlyviewed div
  {
    //$('#divcompareresult').show('slow');
    try{ $('.moverRecent').slideDown(); } catch(e) { }
    try{ document.getElementById("divhidelinkRecently").style.display="block"; } catch(e) { }
    try{ document.getElementById("divshowlinkRecently").style.display="none"; } catch(e) { }
    try{ createCookie("recentlyviewedpanel","open",1); } catch(e) { }
  }
//-------------------ends here-----------------------------  

//-------------------hdieRecentlyViewPanel function is use to hide-slide the recnetly viewed or visited products starts here-----------------------------  
  function hideRecentlyViewPanel()//close recentlyviewed div
  {
    try{ $('.moverRecent').slideUp(); } catch(e) { }
    try{ document.getElementById("divhidelinkRecently").style.display="none"; } catch(e) { }
    try{ document.getElementById("divshowlinkRecently").style.display="block"; } catch(e) { }
    try{ createCookie("recentlyviewedpanel","close",1); } catch(e) { }
  }

//-------------------ends here-----------------------------  
  
//-------------------Removecomapreproduct function is use to remove the product from the compare product panel starts here-----------------------------  

function removecompareproduct(pid)
      {
      //////alert("inside function");
      var pageurl="productcompareXSL.aspx?strip=strip&check=false";
      var i;
      var strid=pid;            
      var c = new Array();
    
      if(strid!="")
      {
      pageurl+="&RemoveProductID="+strid+"&test=test";
      pageurl=pageurl.replace(/amp;/g, "");
       ajaxRequest(null,'true','GET','',pageurl,'cmpresult');
       }       
       return false;
      }
//-------------------ends here-----------------------------      
//category and product page related javascript ends here 

//shopping cart and wishlist related javascript starts here
//-------------------movetoshopping function is use move the product from wish list to shopping cart starts here-----------------------------      
      
        function movetoshopping()
      {
        var c = new Array();
        c =  document.getElementsByTagName('input');
        var count=0;
        var str="";
        for (var i = 0; i < c.length; i++)
        {
            if (c[i].type == 'checkbox')
            {   
                if(str!="")
                {
                    str+="#"+c[i].id;
                }
                else
                {
                    str=c[i].id;
                }
            
            }
        }
        var url='addtocart.aspx?Move=1&ProductID='+str+'&test=test&strip=strip&iframe';
        document.location.href=url;
      }
      
//-------------------ends here-----------------------------      

//-------------------checkHit function is use to move the product id into a hidden variable when check on the product checkbox starts here-----------------------------
      
    function checkHit(ctrl)
    {        
        if(ctrl.checked==true)
        {        
        IsExist(ctrl.id,true);            
        }
        else
        {
         IsExist(ctrl.id,false);            
        }
    }
    
//-------------------ends here-----------------------------    

//-------------------IsExist function is use to check the duplicate values in the hidden variable starts here-----------------------------

    function IsExist(id,condition)
    {
        var hid=document.getElementById("hidchk");
        var i=0;
        var arr=hid.value.split('#');
        var flag=false;
        for(i=0;i<arr.length;i++)
        {
            if(arr[i]==id)
            {
                flag=true;
                break;
            }
        }
        if(!flag&&condition)
        {
            if(hid.value!="")
            {
                hid.value=hid.value+"-"+id;
            }
            else
            {
                hid.value=id;
            }
        }
        else if(!condition&&flag)
        {
            var j=0;
            var strResult="";
             for(j=0;j<arr.length;j++)
               {
                    if(arr[j]!=id)
                    {   
                            if(strResult!="")
                                {
                                    strResult=strResult+"-"+arr[j];
                                 }//inner if end
                            else
                                 {
                                    strResult=arr[j];
                                 }//inner else end
                        
                    }//outer if end
                }//for end
                 hid.value=strResult;
        }//outer else if end 
        //////alert(hid.value);
        
    }//function exit
    
//-------------------ends here-----------------------------    

//-------------------getElementValue function is use to get the value from the control starts here-----------------------------
    
    function getElementValue(id)
    {
       return  document.getElementById(id).value;
    }
//-------------------ends here-----------------------------    

//-------------------movetocart function is use to move the move the product from wishlist to shopping cart starts here-----------------------------
    function movetoCart()
    {
        if(!validatecheck())
        {   
            ////alert("please select atleast one product to move into cart!!");
        }
        else
        {
        document.location.href="addtowishlist.aspx?iframe&Move=1&ProductID="+getElementValue("hidchk")+"&test=test";
        }
    }
    
//-------------------ends here-----------------------------    


//-------------------validatecheck function is use to check whether any product is being selected for move or not starts here-----------------------------    
    function validatecheck()
    {
        var c = new Array();
        c =  document.getElementsByTagName('input');
        var count=0;
        var str="";
        var flag=false;
        for (var i = 0; i < c.length; i++)
        {
            if (c[i].type == 'checkbox')
            {   
                if(c[i].checked)
                {
                flag=true;
                break;
                }
            
            }
        }
        return flag;    
    }
    
//-------------------ends here-----------------------------    

//-------------------DeletefromCart function is use to delete the product from shopping cart starts here-----------------------------    
    function DeletefromCart(skuid,productid)
    {
    ////alert("pid="+productid+"----skuid="+skuid);
    document.location.href="addtocart.aspx?iframe&ProductID="+productid+"&SKUID="+skuid+"&Delete=1&test=test";
    }
    
//-------------------ends here-----------------------------    

//-------------------registehandles function is use to register the jquery on the ajax call this function is needs to call in the interfaceajax.js file when the ajax response comes .starts here-----------------------------    
    function registerhandles(url)
{
//////alert("url:"+url);
var p_minprice=gup("p_minPrice",url);
var p_maxprice=gup("p_maxPrice",url);
var maxprice=gup("maxPrice",url);
////alert("Min price:"+p_minprice+"<br />MaxPrice:"+p_maxprice+"<br />Price:"+maxprice);
try { document.getElementById("minPrice").innerHTML = p_minprice; } catch(e) { }
try { document.getElementById("maxPrice").innerHTML = p_maxprice; } catch(e) { }
try { 
 $("#slider").slider(
	   {
    max:maxprice,min:0,
     range:'min', values: [p_minprice,p_maxprice],step: 5,
    
	   change: function(event, ui) 
	   {
	    //////alert(ui.value);
        var arrMinMax = ui.values;
        //////alert(arrMinMax[0]);
      //  ////alert(arrMinMax[1]);
	   },
     stop: function(event,ui)
     {
      
     var arrMinMax = ui.values;
      document.getElementById("minPrice").innerHTML = arrMinMax[0];
      document.getElementById("maxPrice").innerHTML = arrMinMax[1];
     }
//var max = $('.slider').slider('option', 'max');
//setter

	   
  });
 }catch(e) { }		
}

//-------------------ends here-----------------------------

//-------------------a function is use for slider starts here-----------------------------
function a(p) { $('#slider').css('left', p/10);
   } 
//------------------ends here-----------------------------   

//-------------------gup function is use to extract the query stirng from the provided url starts here-----------------------------
function gup( name ,url){  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  var regexS = "[\\?&]"+name+"=([^&#]*)";  var regex = new RegExp(regexS);  var results = regex.exec(url);  if( results == null )    return "";  else    return results[1];}
//-------------------ends here-----------------------------

//ends here

