function submitenter(myfield,e)
{
    var keycode;
    if (window.event) 
        keycode = window.event.keyCode;
    else if (e) 
        keycode = e.which;
    else 
        return true;

    if (keycode == 13)
    {
        Search();
        return false;
    }
    else
        return true;
}

function submitenter_login(myfield,e)
{
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13)
    {
        aspnetForm.ctl00_ContentPlaceHolder1_btnLogin.click();
        return false;
    }
    else
        return true;
}

// ---------------------------------------------------------------------------
//	Use this function to confirm deletions. It has 3 parameters:
//		iname:   name of the item to delete (show to the user)
//		delURL:  URL the client should be redirected to to delete the item
//		referer: if the delete script supports it, this is the URL the client
//		         will be redirected to after the item is deleted
// ---------------------------------------------------------------------------
function confirmDelete(iname, delURL, referer) {
	if (confirm("Are you sure you wish to delete '" + iname + "'?")) {
		location.href = (delURL + "&referer_page=" + referer);
	}
}

var submitcount=0 
function QbDcTEST(s)
{	var d = s.options[s.selectedIndex].value;
    if (s.selectedIndex > 0)
	{
       parent.location.href = d;
    }
		s.selectedIndex=0;
}
function AddCount()
{ 
	submitcount++; 
} 

function SurveyPopUp()
{ 
	if (submitcount == 0) 
	{ 
		var app = navigator.appName; 
		if (app == "Microsoft Internet Explorer") 
		{ 
			var mywin=window.open("http://www.followup.net/profile/survey/survey.cfm?sname=268X982","mynew","width=700,height=500,scrollbars=yes,resizable=yes,left=0,top=0") 
		}
		else
		{ 
			var mywin=window.open("http://www.followup.net/profile/survey/survey.cfm?sname=268X982","mynew","width=700,height=500,screenX=0,screenY=0,scrollbars=yes,resizable=yes") 
		} 
	} 
} 

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function AddToCart(product_ID,qty)
{
    document.location.href='tools/addcart.aspx?qty=' + eval("aspnetForm.ctl00_ContentPlaceHolder1_gvProducts_ctl" + getID(qty) + eval(qty) + "_txtQty.value") + '&product_ID=' + product_ID;
    return false;
}

function QuickAddToCart(product_ID)
{
    document.location.href='tools/addcart.aspx?qty=1&product_ID=' + product_ID;
    return false;
}

function Search()
{
    document.location.href = 'search.aspx?search=' + document.getElementById("search").value;
    return false;
}

function getID(num)
{
    if ((num)<10)
        return "0";
    else
        return "";
}

if (window.jQuery) {
    jQuery(document).ready(function() {
        initMaster();
        if (window.addImages)
            addImages.init();
        initOverimages();
    });
}

// Initializes regular page based on master page
function initMaster() {
    MM_preloadImages(
        'images/shopbybrand_on.jpg',
        'images/shopbycat_on.jpg',
        'images/giftcard_on.jpg',
        'images/wishlist_on.jpg',
        'images/giftideas_on.jpg');
    //tabdropdown.initializetabmenu("shademenu");
    jsddm.init();
    addressControl.initStatesTaxes();
    addressControl.initStatesProvince();
    addressControl.initSameAddresses();
    jQuery(".secured-banners-container").html('<table align="center" style="width: 100px;" border="0" cellpadding="0" cellspacing="5"><tr><td align="center" valign="top" width="120"><a title="Business Certified" name="trustlink" href="http://secure.trust-guards.com/certificates/www.dkhardware.com" target="_blank" class="trustlink business"></a></td><td align="center" valign="top" width="120"><a title="Trust Guard Certified" name="trustlink" href="http://secure.trust-guards.com/certificates/www.dkhardware.com" target="_blank" class="trustlink certificates"></a></td><td align="center" valign="top" width="120"><a title="Privacy Verified" name="trustlink" href="http://secure.trust-guards.com/certificates/www.dkhardware.com" target="_blank" class="trustlink privacy"></a></td><td align="center" valign="top" width="120"><a title="Security Seal" name="trustlink" href="http://secure.trust-guards.com/certificates/www.dkhardware.com" target="_blank" class="trustlink security"></a></td></tr></table>');
    jQuery(".trustlink", ".secured-banners-container").live("click", showTrustLink);
    
    //InitShadeMenu();
}

function initOverimages() {
    $(".product_over").each(
        function() {
            $(this).wTooltip(
                {
                    ajax: 'tools/ajax-info.aspx?ID=' + $(this).attr('rel'),
                    style: { //the default style rules of the tooltip 
                            background: "white", 
                            color: "#000", 
                            padding: "5px", 
                            zIndex: "1000", 
                            textAlign: "left" 
                        }
                }
            );
        }
    );
}

function showTrustLink(ev) {
    var nonwin = navigator.appName != 'Microsoft Internet Explorer' ? 'yes' : 'no'; 
    window.open(this.href, 
        'welcome',
        'location=' + nonwin + ',scrollbars=yes,width=517,height=' + screen.availHeight + ',menubar=no,toolbar=no'); 
    ev.preventDefault();
}
function ToCenter(box) {
    var $box = $(box);
    var leftPos = Math.floor(($(window).width() - $box.width()) / 2);
    var topPos = 
        Math.floor(($(window).height() - $box.height()) / 2) + $(window).scrollTop();
    $box.css({
        "top": topPos + "px", 
        "left": leftPos + "px" 
    });
    return box;
}
function pinShadow(box) {
    if (!box.get(0).shadow) {
        var shadow = $("<div class='box shadow'>&nbsp;</div>");
        box.get(0).shadow = shadow;
        shadow.appendTo("body");
    } else {
        shadow = $(box.get(0).shadow);
    }
    shadow.css({
        "top": (box.position().top + 10) + "px",
        "left": (box.position().left + 10) + "px",
        "width": (box.outerWidth()) + "px",
        "height": (box.outerHeight()) + "px",
        "visibility": "visible"
    });
}
function removeShadow($box) {
    if ($box.get(0).shadow) {
        $($box.get(0).shadow).remove();
        $box.get(0).shadow = null;
    }
}
function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

var addressControl = {
    initStatesTaxes: function() {
        if (window.taxes) {
            $("select.states").bind("change", function() { addressControl.findTax(this) });
        }
    },
    findTax: function(item) {
        var taxControl = $(item).siblings("span.tax");
        if (taxControl.length > 0) {
            var tax = window.taxes[$(item).val()];
            if (tax) {
                taxControl.html("<b>" + $(item).val() +
                    "</b> residents are subject to a " + tax +
                    "% sales tax").css("display", "block");
            } else {
                taxControl.css("display", "none");
            }
        }
    },
    initStatesProvince: function() {
        $("input.text.state").bind("change", function() {
            var $this = $(this);
            var related = document.getElementById($this.attr("rel"));
            if (!related)
                return;
            if ($this.val() != "") {
                $this.data("relValue", related.selectedIndex);
                related.selectedIndex = 0;
            } else {
                if ($this.data("relValue")) {
                    related.selectedIndex = $this.data("relValue");
                }
            }
            addressControl.findTax(related);
        });
    },
    initSameAddresses: function() {
        var $cbsame = $(".cb-same :checkbox");
        if ($cbsame.length > 0) {
            if (!$cbsame.get(0).checked) {
                addressControl.disableBilling();
            } else {
                addressControl.enableBilling();
            }
            $cbsame.bind("click", function() {
                if (!this.checked) {
                    addressControl.disableBilling();
                } else {
                    addressControl.enableBilling();
                }
            });
        }
    },
    disableBilling: function() {
        $(".panel-billing-address").css("display", "none");
    },
    enableBilling: function() {
        $(".panel-billing-address").css("display", "block");
    },
    checkSameAddresses: function() {
    }
}

var addImages = {
    init: function() {
        this.images = [];
        this.containerTd = $(".image-container td");
        var hoverList = $(".additional-images a.image-hover");
        this.itemsToLoad = hoverList.length;
        addImages.allInited = false;
        for (var idx = 0; idx < this.itemsToLoad; idx++) {
            var d1 = new Image();
            d1.isLoaded = false;
            $(d1).load(function() {
                addImages.checkLoadedImageSize(this);
            });
            d1.src = hoverList[idx].href;
            this.images.push(d1);
            if (d1.width) {
                addImages.checkLoadedImageSize(d1);
            }
        }
        addImages.allInited = true;
        $(".additional-images a.image-hover")
            .hover(addImages.showImage)
            .click(function() {
                window.open("images_gallery.aspx?product=" + productId,
                    "Gallery",
                    "width=1024,height=800,scrollbars=yes,resizable=yes");
                return false;
            });
        this.mainImage = $("img.main-image").get(0);

    },
    checkLoadedImageSize: function(loadedImage) {
        if (loadedImage.width > addImages.containerTd.width()) {
            addImages.containerTd.width(loadedImage.width);
        }
        if (loadedImage.height + 3 > addImages.containerTd.height()) {
            addImages.containerTd.height(loadedImage.height + 3);
        }
    },
    showImage: function() {
        addImages.newImage = $(this).attr("href");
        if (addImages.mainImage.src == addImages.newImage)
            return;

        $(addImages.mainImage).attr("src", addImages.newImage);
        $(".product_image.enlarge").attr("href", "tools/image-resize.aspx?image=" + $(this).attr("rel"));
    }
}

var jsddm = {
    timeout: 500,
    closetimer: 0,
    ddmenuitem: 0,
    open: function() {
        jsddm.canceltimer();
        jsddm.close();
        jsddm.ddmenuitem = $(this).find('ul').css('visibility', 'visible');
    },

    close: function() {
        if (jsddm.ddmenuitem)
            jsddm.ddmenuitem.css('visibility', 'hidden');
    },

    timer: function() {
        jsddm.closetimer = window.setTimeout(jsddm.close, jsddm.timeout);
    },

    canceltimer: function() {
        if (jsddm.closetimer) {
            window.clearTimeout(jsddm.closetimer);
            jsddm.closetimer = null;
        }
    },
    init: function() {
        $('#jsddm > li').bind('mouseover', jsddm.open)
        $('#jsddm > li').bind('mouseout', jsddm.timer)
        $(document).click(jsddm.close);
    }
}

