﻿	//Global XMLHTTP Request object
var XmlHttp;
//var AjaxServerPageName;
//AjaxServerPageName = "tbBranchM.aspx";
var childID = null;

function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

function LoadOffset(path)
{
	 var requestUrl = null;
	 var now = new Date();        
	 var offset = now.getTimezoneOffset();
	 //document.forms[0].hdClient.value = -offset
    jQuery.get(path,{ 
        TimeZoneOffset: parseInt(-offset),time: GetcurrentDatetime(), RNumber: GetRandomNumber()
    }, function(html) {    
            
        document.forms[0].submit();		        
        
    }); 
}

function GetRandomNumber()
{
    var n = 10000;
    return (Math.floor(Math.random()*n));
}
function GetcurrentDatetime()
{
    try
    {
        var _slsTimestamp = "";
        var _slsMyDate = new Date();
	    _slsTimestamp  = _slsMyDate.getMonth() +'/'+ _slsMyDate.getDay()  +'/'+ _slsMyDate.getFullYear() +' '+ _slsMyDate.getHours() +':' + _slsMyDate.getMinutes() +':'+ _slsMyDate.getSeconds();
	    if(_slsMyDate.getHours() > 11)
	        _slsTimestamp = _slsTimestamp + ' ' + 'PM';
	    else
	        _slsTimestamp = _slsTimestamp + ' ' + 'AM';
    }
    catch(ex)
    {}
    return _slsTimestamp;
}

$(document).ready(function()
{
    CategoryBrandTabInitialize("");
});


function CategoryBrandTabInitialize(objActiveMenuID)
{
    if(objActiveMenuID.length == 0)
    {
        $("#dvCategoryBrandMenu").addClass("tabfirstselected");
        
        $("#uxCategory").css({display: "inline"});
        $("#uxBrand").css({display: "none"});
        
        $("#dvCategoryBrandMenu > div").filter(".tabfirst").click(function()
        {
            $("#uxCategory").css({display: "inline"});
            $("#uxBrand").css({display: "none"});
            $("#dvCategoryBrandMenu").removeClass();
            $("#dvCategoryBrandMenu").addClass("tabfirstselected");
        });

        $("#dvCategoryBrandMenu > div").filter(".tabsecond").click(function()
        {
            $("#uxCategory").css({display: "none"});
            $("#uxBrand").css({display: "inline"});
            $("#dvCategoryBrandMenu").removeClass();
            $("#dvCategoryBrandMenu").addClass("tabsecondselected");
        });
    }
    else
    {
        if(objActiveMenuID.toLowerCase() == "uxbrand")
        {
            $("#dvCategoryBrandMenu").addClass("tabsecondselected");
            
            $("#uxCategory").css({display: "none"});
            $("#uxBrand").css({display: "inline"});
        }
        else
        {
            $("#dvCategoryBrandMenu").addClass("tabfirstselected");
            
            $("#uxCategory").css({display: "inline"});
            $("#uxBrand").css({display: "none"});
        }  
    }

}


$(document).ready(function()
{
    var url = window.location.href;
    $("#mainDiv").each(function()
    {
        $(this).find("a").each(function()
        {
            var strparentDivID = "";

            strparentDivID = $(this).parent().parent().attr("id");  
            
            var parentCategoryUrl = GetParentCategoryUrl(url).toLowerCase();
            
           
            if(this.href.toLowerCase() == url.toLowerCase() || this.href.toLowerCase() == parentCategoryUrl)
            {
                if($(this).parent().hasClass("sub-category-outer"))
                {
                    $(this).removeClass();
                    $(this).addClass("sub-category-active-link");
                    $(this).parent().removeClass("sub-category-outer-brand");
                    $(this).parent().prev(".main-category").find("div").removeClass();
                    $(this).parent().prev(".main-category").find("div").addClass("selectedcategorytitle");
                }
                else if($(this).parent().hasClass("main-category"))
                {
                    $(this).parent().next(".sub-category-outer").each(function(){
                        if($(this).find("a").length > 0)
                        {
                            $(this).removeClass("sub-category-outer-brand");
                        }   
                     });
                
                    $(this).find("div").each(function(){

                        $(this).removeClass();
                        $(this).addClass("selectedcategorytitle");
                    });
                }
                
                CategoryBrandTabInitialize(strparentDivID);

            }
            else
            {
                if($(this).parent().hasClass("sub-category-outer"))
                {
                    if(this.href.toLowerCase() == parentCategoryUrl)
                    {
                        $(this).addClass("sub-category-active-link");
                        $(this).removeClass("sub-category-outer-brand");
                    }
                    else
                    {
                        $(this).addClass("sub-category-normal-link");
                        $(this).hover(function()
                        {
                            $(this).removeClass();
                            $(this).addClass("sub-category-active-link");
                            
                        },function()
                        {
                            $(this).removeClass();
                            $(this).addClass("sub-category-normal-link");
                       
                        });
                    }
                }
            }
        });
    });
});

$(document).ready(function()
{
    $(".categorytitle").click(function(){

        if($(this).hasClass("link-categorytitle"))
        {
            $(this).removeClass("link-categorytitle");    
            $(this).addClass("selectedcategorytitle");
            $(this).parent().next(".sub-category-outer").removeClass("sub-category-outer-brand");
        }
        else
        {
            $(this).removeClass("selectedcategorytitle");
            $(this).addClass("link-categorytitle");
            $(this).parent().next(".sub-category-outer").addClass("sub-category-outer-brand");
        }

    });
 
    $(".selectedcategorytitle").click(function(){

        if($(this).hasClass("link-categorytitle"))
        {
            $(this).removeClass("link-categorytitle");    
            $(this).addClass("selectedcategorytitle");
            $(this).parent().next(".sub-category-outer").removeClass("sub-category-outer-brand");
        }
        else
        {
            $(this).removeClass("selectedcategorytitle");
            $(this).addClass("link-categorytitle");
            $(this).addClass("categorytitle");
            $(this).parent().next(".sub-category-outer").addClass("sub-category-outer-brand");
        }
    });
});


function GetParentCategoryUrl(url)
{
    var pattern = new RegExp("\/our-range\/","i");
     
    if(url.search(pattern) != -1)
    {
        var qStringProductName = "";
        var qString = window.location.search;
        var desiredpattern = /\?ap=/;
        
        if(qString.length > 0 && qString.search(desiredpattern)!= -1)
        {
            url = url.substring(0,url.search(desiredpattern));
            
            qStringProductName = qString.substring(qString.lastIndexOf("/"), qString.length);
                                   
        }  
        
        url = url.substring(0,url.lastIndexOf("/"));
        
        if(qStringProductName.length > 0)
        {
          url += qStringProductName + ".aspx"; 
        }
        else
        {
          url += ".aspx"; 
        }

    }
    return url;

}

$(document).ready(function(){

    var url = window.location.href;
    
    $("a").each(function(){
        if(this.href == url)
        {
            $(this).addClass("active");
        }
    });
});

//store locator state selecting

$(document).ready(function(){

    var url = window.location.href;

    var pattern = new RegExp("\/Your-Local-Snooze\/","i");
     
    if(url.search(pattern) != -1)
    {
       var statename = $("div#divstorestatename").text();
       statename = (statename != null) ? $.trim(statename): null;

       $("a[@title='"+statename+"']").addClass("active");
    }
});

$(document).ready(function(){

    var url = window.location.href;

    var pattern = new RegExp("\/brand\/","i");
     
    if(url.search(pattern) != -1)
    {
       var productname = $("span[id$='lblHeading']").text();
       
       productname = (productname != null) ? $.trim(productname): null;
       
        $("a").each(function(){
            
           var txt = $(this).find("div").text();
           txt = (txt != null) ? $.trim(txt): null; 
            if(txt == productname)
            {
                $(this).find("div").removeClass();
                $(this).find("div").addClass("selectedcategorytitle");
                
                if($(this).parent().next(".sub-category-outer").hasClass("sub-category-outer-brand"))
                {
                    $(this).parent().next().removeClass("sub-category-outer-brand");
                }
                
                CategoryBrandTabInitialize("uxBrand");
            }
        });
    }
});


$(document).ready(function()
{
   var $hdnObj = $("input:hidden[id$='hfOptionID']");
   var $hdnMessageObj = $("input:hidden[id$='hfMessage']");
   var $hdnIsEditObj = $("input:hidden[id$='hfIsEdit']");
   
   var Message = "";
   var value = ",";
   $hdnObj.attr("value",value);
   $hdnMessageObj.attr("value", Message);
   
   var blnIsEdit = false;
   
   $("table").filter(".productoptiongrid").find("input:checkbox").each(function(){
   
        if(this.checked == true)
        {
            blnIsEdit = true;
        }
   });
    
   if(blnIsEdit)
   {
        $hdnIsEditObj.attr("value", "true");
   }
   else
   {
        $hdnIsEditObj.attr("value", "false");
   }
   
    
   $("table").filter(".productoptiongrid").find("input:checkbox").click(function(){
        
      $(this).parent().parent().find("input:text").attr("disabled","true");

        var $objhiddenSkuID = $(this).parent().parent().find("input:hidden[id$='hdnskuID']");
        var $objhiddenPopularOptionID = $(this).parent().parent().find("input:hidden[id$='hdnIsPopularOption']");
        
        var isPopularOption = $objhiddenPopularOptionID.val();
        
        value = $hdnObj.val();
        var r = "," + $objhiddenSkuID.val().toString() + ",";

        var reg = new RegExp(r,"i");
        if(this.checked == false)
        {
           if(isPopularOption == 1)
           {
                Message = $hdnMessageObj.val();
                Message +=  $(this).parent().next().text().toString() + " Option is popular option.If you unchecked it then it is no more visible as popular option.";
           } 
           
           if(value.search(reg) == -1)
           {
                value += $objhiddenSkuID.val().toString() + ",";
           }
        }
        else
        {
            var m = $(this).parent().next().text().toString() + " Option is popular option.If you unchecked it then it is no more visible as popular option.";

            Message = $hdnMessageObj.val();
            var oregExp = new RegExp(m,"g");  
            Message = Message.replace(oregExp,"");
            
           if(value.search(reg) != -1)
           {    
                var replcestr = $objhiddenSkuID.val().toString() + ",";
                var regReplace = new RegExp(replcestr,"i");
                value = value.replace(regReplace,"");
           }
           $(this).parent().parent().find("input:text").removeAttr("disabled");
        }
        $hdnObj.attr("value",value);
        $hdnMessageObj.attr("value",Message);
        
   });
   
});


function ProductOptionSave()
{
   var $hdnIsEditObj = $("input:hidden[id$='hfIsEdit']");
   
   var blnIsEdit = false;
   
   var count = 0;
   
   $("table").filter(".productoptiongrid").find("input:checkbox").each(function(){
            
        count++;     
        if(this.checked == true)
        {
            blnIsEdit = true;
        }
   });

   if($hdnIsEditObj.val() == "true")
   { 
       var $hdnMessageObj = $("input:hidden[id$='hfMessage']");
       
       if($hdnMessageObj.val().length > 0)
       {
           return window.confirm($hdnMessageObj.val());
       }
   }
   else if(blnIsEdit == false && $hdnIsEditObj.val() == "false")
   {
        if(count > 0)
        {
            alert("Please check atleast one option");
            return false;
        }
        else
        {
            return true;
        }
   }
       
   return true;
}


function ValidateProductOptionOnSave(source, arguments)
{
    var IsValid = true;
    
    $("table").filter(".productoptiongrid").find("input:checkbox").each(function(){
    
        if(this.checked)
        {
            $(this).parent().parent().find("input:text").each(function(){
            
                var value = $(this).val().replace(/^\s*/, "").replace(/\s*$/, "");        
                
                if(value.length == 0)
                {
                    var r = $(this).val().toString() + ",";
                    IsValid = false;
                }
                else
                {
                     if(isNaN(value) == true)
                     {
                        IsValid = false;
                     }
                }
            
            });
        }
    
    });
    arguments.IsValid = IsValid;
    return IsValid;
}

//Show Pop Up

function ShowPopUp(obj)
{
    $(".only-internal").each(function(){

        var clienHeight = this.offsetParent.clientHeight;
        $(this).prev(".aboutus-popup").addClass("popup");
    
    });
}


function ClosePopUp(appendID)
{
    $(".aboutus-popup").each(function(){

        var clienHeight = this.offsetParent.clientHeight;
        $(this).removeClass("popup");
    });
}


$(document).ready(function()
{
    var divheight = 0;

    $("#dvProductDetailTabMenu").addClass("tabProductDetailfirstselected");
    $("#divfeaturecontent").css({display: "inline-block"});
    $("#divspecificationcontent").css({display: "none"});
    $("#divpopularconfigcontent").css({display: "none"});
    $("#divproducttipcontent").css({display: "none"});
    
    divheight = $(".pd-outer").height();
    $(".pd-seleted-outertd").siblings().height(divheight);    
    


    $("#dvProductDetailTabMenu > div").filter(".tabProductDetailfirst").click(function()
    {
        $("#divfeaturecontent").css({display: "inline-block"});
        $("#divspecificationcontent").css({display: "none"});
        $("#divpopularconfigcontent").css({display: "none"});
        $("#divproducttipcontent").css({display: "none"});

        $("#dvProductDetailTabMenu").removeClass();
        $("#dvProductDetailTabMenu").addClass("tabProductDetailfirstselected");
        $(".pd-seleted-outertd").parent().find("td").css({height: "auto",margin: "0px"});

        divheight = $(".pd-outer").height();
        $(".pd-seleted-outertd").siblings().height(divheight);

    });

    $("#dvProductDetailTabMenu > div").filter(".tabProductDetailsecond").click(function()
    {

        $("#divfeaturecontent").css({display: "none"});
        $("#divspecificationcontent").css({display: "inline-block"});
        $("#divpopularconfigcontent").css({display: "none"});
        $("#divproducttipcontent").css({display: "none"});

        $("#dvProductDetailTabMenu").removeClass();
        $("#dvProductDetailTabMenu").addClass("tabProductDetailsecondselected");
        $(".pd-seleted-outertd").parent().find("td").css({height: "auto",margin: "0px"});

        divheight = $(".pd-outer").height();
        $(".pd-seleted-outertd").siblings().height(divheight);
        
    });

    $("#dvProductDetailTabMenu > div").filter(".tabProductDetailthird").click(function()
    {  

        $("#divfeaturecontent").css({display: "none"});
        $("#divspecificationcontent").css({display: "none"});
        $("#divpopularconfigcontent").css({display: "inline-block"});
        $("#divproducttipcontent").css({display: "none"});

        $("#dvProductDetailTabMenu").removeClass();
        $("#dvProductDetailTabMenu").addClass("tabProductDetailthirdselected");
        $(".pd-seleted-outertd").parent().find("td").css({height: "auto",margin: "0px"});
        
        divheight = $(".pd-outer").height();
        $(".pd-seleted-outertd").siblings().height(divheight);
        
        
    });

    $("#dvProductDetailTabMenu > div").filter(".tabProductDetailfourth").click(function()
    {  
        $("#divfeaturecontent").css({display: "none"});
        $("#divspecificationcontent").css({display: "none"});
        $("#divpopularconfigcontent").css({display: "none"});
        $("#divproducttipcontent").css({display: "block"});

        $("#dvProductDetailTabMenu").removeClass();
        $("#dvProductDetailTabMenu").addClass("tabProductDetailfourthselected");
        $(".pd-seleted-outertd").siblings().css({height: "auto",margin: "0px"});

        divheight = $(".pd-outer").height();
        $(".pd-seleted-outertd").siblings().height(divheight);
        
    });

});


//Search

function ValidateSearch(source,arguments)
{
    var productPattern = /valProduct/i;
    var pagePattern = /valPage/i;

    var idprefix;
    var value = arguments.Value.replace(/^\s*/, "").replace(/\s*$/, "");        
    
    if(source.id.search(productPattern) != -1)
    {
        idprefix = source.id.replace(productPattern, "");
        
        if(document.getElementById(idprefix + "uxProduct").checked)
        {
            arguments.IsValid = (value.length > 0);
            return value.length > 0;
        }
    }
    
    if(source.id.search(pagePattern) != -1)
    {
        idprefix = source.id.replace(pagePattern, "");

        if(document.getElementById(idprefix + "uxPages").checked)
        {
            arguments.IsValid = (value.length > 0);
            return value.length > 0;
        }
    }
    
    arguments.IsValid = true;
    return true;
}

function ValidatePopularOption(source,arguments)
{
    var Pattern = /valOption/i;

    var idprefix;
   
    if(source.id.search(Pattern) != -1)
    {
        idprefix = source.id.replace(Pattern, "");
        
        if(document.getElementById(idprefix + "chkIsDelete").checked)
        {
            if(arguments.Value.length == 0)
            {
                arguments.IsValid = false;
                return arguments.IsValid;
            }
            else
            {
                arguments.IsValid = true;
                return arguments.IsValid;
            }
        }
    }
    else
    {
            arguments.IsValid = true;
            return true;
    }

}

function checkIsDeleteCheckBox(rdoButton,id)
{
    if(rdoButton.checked == true)
    {
        document.getElementById(id).checked = true;    
    }
    else
    {
        document.getElementById(id).checked = false;    
    }
}

// Corporate Top Menu In Home

$(document).ready(function()
{
    var obj = document.getElementById("corporateHome");
    
    if(obj != null)
    {
        if($(".top_menu").hasClass("top-menu-home-bg") == true)
            $(".top_menu").removeClass("top-menu-home-bg");
    }
    
});

// Consumer Home

$(document).ready(function()
{
    var obj = document.getElementById("hdnconsumerhome");
    
    if(obj != null)
    {
            $(".body_bg_footer").addClass("home-footer");
            $(".body_bg_footer").removeClass("body_bg_footer");
            $(".body_bg").removeClass("zonecontent");

            //home right navigation top image

            if($(".top-menu-middle").hasClass("home-topmenu-middle") == false)
            {
                $(".top-menu-middle").addClass("home-topmenu-middle");
            }
    }
});



$(document).ready(function()
{
    var obj = document.getElementById("hdnProductDetail");
    if(obj != null)
    {
        var objDiv = document.getElementById('divZoneRight');
        if(objDiv != null)
        {
            objDiv.style.display = "none";
        }
    }
});

//print

function print(divId,siteUrl)
{
    var _strStyleSheetUrl = '<link rel="Stylesheet" media="print" type="text/css" href="'+siteUrl+ '" />\n';
    newwin=window.open('','printwin','left=400,top=200,width=220,height=20');
    newwin.document.write('<HTML>\n<HEAD>\n');
    newwin.document.write('<TITLE>Print Page</TITLE>\n');
    newwin.document.write(_strStyleSheetUrl);
    newwin.document.write('<script>\n');
    newwin.document.write('function chkstate(){\n');
    newwin.document.write('if(document.readyState){\n');
    newwin.document.write('if(document.readyState=="complete"){\n');
    newwin.document.write('window.close()\n');
    newwin.document.write('}\n');
    newwin.document.write('else{\n');
    newwin.document.write('setTimeout("chkstate()",2000)\n');
    newwin.document.write('}\n');
    newwin.document.write('}\n');
    newwin.document.write('else{\n');
    newwin.document.write('window.close();');
    newwin.document.write('}\n');
    newwin.document.write('}\n');
    newwin.document.write('function print_win(){\n');
    newwin.document.write('window.print();\n');
    newwin.document.write('chkstate();\n');
    newwin.document.write('}\n');
    newwin.document.write('<\/script>\n');
    newwin.document.write('</HEAD>\n');
    newwin.document.write('<BODY onload="print_win()">\n');
    newwin.document.write('<div>');
    var oPrintDiv = jQuery("div[id*='" + divId + "']").html();  
    newwin.document.write(oPrintDiv);
    newwin.document.write('</div>');
    newwin.document.write('</BODY>\n');
    newwin.document.write('</HTML>\n');
    newwin.document.close();
    
    return false;

}

function ValidateContactUsform()
{
  var ocoll = document.body.getElementsByTagName("input");

  var i;
  var message = "";    
  var value = "";

  for(i = 0; i < ocoll.length; ++i)
  {
    if(ocoll[i].type == "text")
    {
        if(ocoll[i].id == "first_name")
        {
            value =  $.trim(ocoll[i].value);
            if(value.length == 0)
            {
              message +=  "Please enter First Name \n";
            }
        }

        if(ocoll[i].id == "last_name")
        {
            value =  $.trim(ocoll[i].value);
            if(value.length == 0)
            {
              message +=  "Please enter Last Name \n";
            }
        }
        
        if(ocoll[i].id == "email")
        {
            value =  $.trim(ocoll[i].value);
            if(value.length == 0)
            {
              message +=  "Please enter email \n";
            }
            else
            {
                var pattern = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i;
                if(pattern.test(value) == false)
                {
                    message += "Please enter valid email \n";
                }
            }
        }
        
        if(ocoll[i].id == "phone")
        {
            value =  $.trim(ocoll[i].value);
            if(value.length == 0)
            {
              message +=  "Please enter phone \n";
            }
            else
            {
                var pattern = /\d/;
                
                if(pattern.test(value) == false)
                {
                    message += "Please enter valid phone \n";
                }
            
            }
        }
        
        if(ocoll[i].id == "description")
        {
            value =  $.trim(ocoll[i].value);
            if(value.length == 0)
            {
              message +=  "Please enter comment \n";
            }
        }

    
    }
  
  }  
   
   if(message.length > 0)
   {
        alert(message);
        return false;
   }
   else
   {
        document.forms[0].action = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
        document.forms[0].method = "post";
        
        document.forms[0].submit();
   }
}