/* stop IE6 flicker */
try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {}

// Return true if browser is Internet Explorer and version 6 or earlier
$.IE6Below = function() {
	if ($.browser.msie) {
		try {
			if (ScriptEngineMajorVersion() <= 5 && ScriptEngineMinorVersion() < 7) { // ie 6- only
				return true;
			}
		} catch(err) { return false; };
		return false;
	} else {
		return false;
	};
};

// ** Misc **
// **      **

$(document).ready(function(){	
	// on click show-hide sibling
	$("#showCont").hide();
	$("a#show").click(function(){
		$(this).siblings("#showCont").toggle("fast");
		return false;
	});	
	$("a#subscribeToList").click(function(){
	    
	});	
	/* deal of day email address field */
	$("[id$=_txtDodEmail]").focus(function(){
	    $(this).val("");
	});	 
	/* deal of day email address field */
});

 $(function(){
	// show - hide qty pricing table
	$("td table.qty-table").hide();
	$("a.qty").click(function(){
		$(this).siblings("table.qty-table").toggle("fast");
		return false;
	});
	
	// show po option on checkout5.aspx
	$("#showPO1").click(function(){ $("#poContainer").slideToggle(); return false; });

   //   $("a#freeShipDetails").click(function(){ $("#dialog").dialog("open"); return false;  });
});

$(function() { 
     $("#dialog").dialog({autoOpen:false ,resizable:false, dialogClass: "dialog", 
        width: 300, hide:"fadeOut",  bgiframe: true});
     $("#dialog").css("display","block");
     $(".ui-resizable-handle").css("display","none");
     $(".ui-dialog-titlebar-close > span").html('<img src="/images/layout/buttons/btn-close.gif" alt="close" style="float:right;" />'); 
     $("#freeShipDetails").click(function(){ $("#dialog").dialog("open"); return false;});
     $("#closeDialog").click(function(){ $("#dialog").dialog("close"); return false;});
});

$(function() { 
     $("#leMsg").dialog({autoOpen:true ,resizable:false, dialogClass: "dialog", 
        width: 330, hide:"fadeOut", bgiframe: true});
     $("#leMsg").css("display","block");
     $(".ui-resizable-handle").css("display","none");
     $(".ui-dialog-titlebar-close > span").html('<img src="/images/layout/buttons/btn-close.gif" alt="close" style="float:right;" />'); 
     $(".hideMsgBox").click(function(){ $("#leMsg").dialog("close"); return false;});
});


 $(function(){ 
  $("ul#share").mouseover(function(){ $("ul#social").show(); }).mouseout(function(){ $("ul#social").hide(); });
 });
 
 function isValidEmail(email){
    var reg = new RegExp(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/);
    
    if(reg.test(email) == false) {
        return false;
    }
    else{
        return true;
    }
 }
  
//subscribe to email list
function subscribeToList(email,listName,invalidEmailSelector,successMsgSelector,errorMsgSelector,emailFieldSelector,toHideSelector){
    if(email == "" || email == null){
        //get email from html element
       email = $(emailFieldSelector).val();   
    }
    //else email is present
        
    if (isValidEmail(email) == false){
        //show invalid email error
        $(invalidEmailSelector).show();
    }
    else{
        //subscribe to list
        $(invalidEmailSelector).hide();
        $.ajax({
            type: "POST",
            url: "/wsUsers.asmx/subscribeToEmailList",
            data: "{email:'" + email + "',listName:'" + listName + "'}",
            contentType: "application/json; charset=utf-8",        
            dataType: "json",
            error: function(){ $(errorMsgSelector).show();  },
            cache: false,
            success: function(r) {        
                    var json = eval(r);
                  if(json.success == true){    
                        //show success message
                        $(toHideSelector).slideUp("slow", function(){
                            $(successMsgSelector).show();     
                        });                   
                  }
                  else{
                        $(errorMsgSelector).show();
                  }
            } // end success
        }); //end AJAX   
    }    
}