﻿//For Top control Search
//Right Side Zone Smartsearch
function funShowSmartSearch(cur)
{       
    try
    {   
        switch(cur)
        {
            case 'USD':
            case 'AUD':
            case 'CAD':
            case 'NZD':
            case 'SGD':
                $('USD').style.display='block';
                $('INR').style.display='none';
                $('GBP').style.display='none';
                $('ZAR').style.display='none';
            break;
            case 'INR':
                $('USD').style.display='none';
                $('INR').style.display='block';
                $('GBP').style.display='none';
                $('ZAR').style.display='none';                
            break;
            case 'GBP':
            case 'EUR':
                $('USD').style.display='none';
                $('INR').style.display='none';
                $('GBP').style.display='block';
                $('ZAR').style.display='none'; 
            break;
            case 'ZAR':
                $('USD').style.display='none';
                $('INR').style.display='none';
                $('GBP').style.display='none';
                $('ZAR').style.display='block';
            break;
        }
        funSSOnLoad();
    }
    catch(e)
    {
        alert('@ funShowSmartSearch');
    }
}
function funSSOnLoad()
{   
    try
    {    
        funSmartHandler('Ctg1|');   
        $('dvCtg2').innerHTML='';         
    }
    catch(e)
    {
        alert('@ funSSOnLoad')
    }
}
function funCallSSHandler()
{

    //Function call SmartSearch.ashx 
    try
    {
        var qStr='Ctg2|'+$('ddlCtg1').value;
        var selectedOption = $A($('ddlCtg1').options).find(function(option) { return option.selected; } );
        $('dvSmartSrch').innerHTML='In '+ selectedOption.text + ' <img src='+$F('hdnAppPath')+'image/EsHomePageImages/CbCloseBtn.gif onclick=funSSOnLoad() title="Back" style="cursor: pointer;" />';
        funSmartHandler(qStr);
    }
    catch(e)
    {
        alert('@ funCallSSHandler');
    }
}
function funSmartHandler(qStr)
{   
    try
    {   
        new Ajax.Request($F('hdnAppPath')+'GenetricHandler/SmartSearch.ashx?qStr='+qStr,
        {
            method: 'get',
            onSuccess: funGetSmartSuccess,
            onFailure: funGetSmartFailure
        });
    }
    catch(e)
    {
//        alert('@ funSmartHandler');
    }
}
function funGetSmartSuccess(OrigionalRequest)
{
    arrCtg=new Array();
    try
    { 
        arrCtg=OrigionalRequest.responseText.split("|")
        if(arrCtg.length>1)
        {
            switch(arrCtg[1])
            {
                case 'Ctg1':
                    $('dvSmartSrch').innerHTML = arrCtg[0];
                    break;
                case 'Ctg2':
                    $('dvCtg2').innerHTML = arrCtg[0];
                    break;
            }
        }
    }
    catch(e)
    {
        alert('@ funGetSmartSuccess')
    }
}
function funGetSmartFailure()
{
    try
    {
        alert(OrigionalRequest.responseText);
    }
    catch(e)
    {
        alert('@ funGetSmartFailure');
    }
   
}

function funCheckDdl(range)
{
    
    try
    {   
        if($('ddlCtg1')!=undefined)
        {
            if($F('ddlCtg1')=='-1')
                alert('Select Level 1 Category');
        }
        else if($F('ddlCtg2')=='-1')
            alert('Select Level 2 Category');        
        else
        {   
            var selectedOption = $A($('ddlCtg2').options).find(function(option) { return option.selected; } );
            strText=(selectedOption.text).replace(/ /gi,'-').toLowerCase();
            var strExp = ($('chkExp').checked) ? 'express-shipping/' : '';            
            switch(range)
            {                
                case '0-100':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-below-100-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '101-200':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-101-200-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '201-300':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-201-300-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '301-500':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-301-500-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '501-1000':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-above-500-c-"+$F('ddlCtg2')+".html ";
                    break;                    
                case '0-1000':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-below-1000-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '1001-3000':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-1001-3000-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '3001-5000':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-3001-5000-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '5001-10000':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-5001-10000-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '10001-20000':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-above-10000-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '0-50':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-below-50-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '51-100':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-51-100-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '101-200':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-101-200-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '201-400':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-201-400-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '401-1000':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-above-401-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '0-800':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-below-800-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '801-1600':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-801-1600-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '1601-2400':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-1601-2400-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '2401-4000':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-between-2401-4000-c-"+$F('ddlCtg2')+".html ";
                    break;
                case '4001-10000':
                    window.location.href=$F('hdnAppPath').toLowerCase()+strText+"/"+strExp+Currency.toLowerCase()+"-price-above-4001-c-"+$F('ddlCtg2')+".html ";
                    break;
            }
        }
    }
    catch(e)
    {        
        alert('@ funCheckDdl');
    }
}

// Begin Whatsnew this week

CursorStyle = "hand";
function findObj(id)
{	
    var obj = null;
	
	if (document.getElementById)
		obj = document.getElementById(id);
	else if (document.all)
		obj = document.all[id];
	return obj;
}

function hideAll()
{
	return;
	
	var i = 0;
	var obj = null;
	var id = "";
	for (i = 1; i <= 9; i++)
	{
		id = i;
		obj = findObj(id);
		
		if (obj) obj.style.display = "none";
	}
}
function showHide(id)
{
	var obj = findObj(id);	
	
	if(obj)
	{
		var s = null;
		s = obj.style;
		
		// switch on/off the clicked block
		if (s.display == "none") s.display = "block";
		else if (s.display == "block") s.display = "none";

		// swich on/off the last selected block
		if (window.curOpenDiv)
		{
			if (window.curOpenDiv != obj)
			{
				s = window.curOpenDiv.style;
				if (s.display == "block") s.display = "none";
				window.curOpenDiv = obj;
			}
		}
		else
		{
			window.curOpenDiv = obj;
		}
	}
	return false;
}

//Estore Menu

    menu_status = new Array();
    var currentOpenItemName=""; 
    function CBMenuShow(theid)
    {    
        var switch_id = document.getElementById(theid);
        switch_id.className = 'CBMenushow';
        menu_status[theid] = 'CBMenushow';
        currentOpenItemName = theid;
            
    }
    function CBMenuHide(theid)
    {    
        var switch_id = document.getElementById(theid);
        switch_id.className = 'CBMenuhide';
        menu_status[theid] = 'CBMenuhide';
        currentOpenItemName = '';        
    }   
    

//EsCbTop.ascx & EsTopLt2.ascx

//<script language="javascript" type="text/javascript">   
    funClrSearch=function(){ 
        if($F('txtProductSearch')=='Product Search')
             $('txtProductSearch').value='';
     } 
    funChkPrdSearch=function(){     
        if($F('txtProductSearch')==''||$F('txtProductSearch')=='Product Search'||funInvalidText($F('txtProductSearch'))==false){
              alert('Search Keyword Missing / Invalid');
              return false;
        }
        else 
            return true;
     }
    funGo=function(){   
        if(funChkPrdSearch()==true)
//           window.location.href='Products.aspx?mode=ser&searchtext='+ $F('txtProductSearch');         
            window.location.href=$F('hdnAppPath')+"search/" + $F('txtProductSearch').trim().replace(/ /gi,'-').toLowerCase()+".html";  
    } 
    funInvalidText=function(param){
        flg=0;
        str="";
        spc=""
        arw="";
        for (var i=0;i< param.length;i++){
            cmp="<>?;'%$~`@#^&*()_-=+[]{}\|:;,./"
            tst=param.substring(i,i+1)
            if (cmp.indexOf(tst)>-1){
                flg++;
                str+=" "+tst;
                spc+=tst;
                arw+="^";
            }
            else{arw+=" ";}
        }
        if (flg!=0){
            if (spc.indexOf(" ")>-1) {
                str+=" and a space";
            }
            return false;
        }
     }
     funDefaultSearch=function(e){ 
        var key; 
        try{
            key=(e.which) ? e.which : e.keyCode; 
            if(key==13) { 
                $('btnGo').focus(); 
            } 
            return true; 
        }
        catch(e){
            alert('@ funDefaultSearch')
        }    
    } 
//</script>

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/,"");
}

///<script language="javascript" type="text/javascript">

function s(divID) 
{
    document.getElementById(divID).style.display = "block";     
}
function h(divID) 
{
    document.getElementById(divID).style.display = "none";     
}
///</script>

///<script type="text/javascript"> 	
	function DivPosition(elementID) 
	{
		var element = document.getElementById(elementID);
		if (element != null) 
		{
			element.style.display = "block";
			browserSize = getBrowserSize();
			element.style.position = "absolute";
			element.style.left = browserSize[0]/2 - element.offsetWidth /2;
			element.style.top = browserSize[1]/8 - element.offsetHeight /8;
		}
	}

	function getBrowserSize() 
	{
		var myWidth=0, myHeight=0;
		if( typeof( window.innerWidth ) == 'number' ) 
		{
			/*Non-IE*/
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			/*IE 6+ in 'standards compliant mode'*/
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			/*IE 4 compatible*/
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		return new Array(myWidth, myHeight);
	}

//</script>

// for category level page & product type page
 function funHideSmartSearch()
    {
        try
        {
            $('CollapsiblePanel3').style.display="none";
        }
        catch(e)
        {
            alert('@ funHideSmartSearch');
        }
    }    
    
    
//Session currency change in Category level page
function funCurrChange(Curr)
{   
    try
    {           
        new Ajax.Request($F('hdnAppPath')+'GenetricHandler/SmartSearch.ashx?qStr=Curr|'+Curr,
        {
            method: 'get',
            onSuccess: funCurrChangeSuccess,
            onFailure: funCurrChangeFailure
        });
    }
    catch(e)
    {
        alert('@ funCurrChange');
    }
}
function funCurrChangeSuccess(OrigionalRequest)
{   
    try
    { 
        if (OrigionalRequest.responseText=='Y')            
            window.location.href=document.location.href;
    }
    catch(e)
    {
        alert('@ funSSuccess')
    }
}
function funCurrChangeFailure()
{
    try
    {
        alert(OrigionalRequest.responseText);
    }
    catch(e)
    {
        alert('@ funSFailure');
    }
   
}

// Sign up opens in new window to receive special offers and promotions
function funEmailSignUp()
{   
    try
    {           
        new Ajax.Request($F('hdnAppPath')+'GenetricHandler/SmartSearch.ashx?qStr=SignUp|'+$F('txtEmailSignUp'),
        {
            method: 'get',
            onSuccess: funEmailSignUpSuccess,
            onFailure: funEmailSignUpFailure
        });
    }
    catch(e)
    {
        alert('@ funCurrChange');
    }
}
function funEmailSignUpSuccess(OrigionalRequest)
{   
    try
    { 
        if (OrigionalRequest.responseText=='Y')
        {
            alert('Thanks for your query. We will contact you soon.');        
            document.getElementById('txtEmailSignUp').value='';
        }
    }
    catch(e)
    {
        alert('@ funSSuccess')
    }
}
function funEmailSignUpFailure()
{
    try
    {
        alert(OrigionalRequest.responseText);
    }
    catch(e)
    {
        alert('@ funSFailure');
    }
   
}

function funValidateEmail(EmailId) 
{    
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(reg.test(EmailId) == false) 
        return false;    
}

//Footer E-mail exclusives
function emailCheck(param) 
{
   var len=0;   
   len=param.length;   
   if (param.indexOf("@")<1 || param.indexOf(".")<1 || param.indexOf(".")==(len-1))
   {
       return false;
   }   
 }

function funChkValidSignUp()
{
    var ErrMsg=''; 
    if(document.getElementById('txtEmailSignUp').value==''|| emailCheck(document.getElementById('txtEmailSignUp').value)==false || funValidateEmail(document.getElementById('txtEmailSignUp').value)==false)    
        ErrMsg='\n Email Id is Missing/Invalid';
    if(ErrMsg!='')
    {   
        alert(ErrMsg);                    
        return false;            
    }
    else
    {
        funEmailSignUp();
        return true;
    }
}
