/* 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(){	
	try {
	    $("a#subscribeToList").click(function(){
    	    
	    });	
	    /* deal of day email address field */
	    $("[id$=_txtDodEmail]").focus(function(){
	        $(this).val("");
	    });	 
	    /* deal of day email address field */
	}
	catch (e){
	    
	}
	
});
function showHide(){
    // on click show-hide sibling
	$("#showCont").hide();
	$("a#show").click(function(){
		$(this).siblings("#showCont").toggle("fast");
		return false;
	});	
}

function showSearchOffer() { 
     $("#dialog-search-offer").dialog({autoOpen:true ,resizable:false, dialogClass: "dialog", width: 280, hide:"fadeOut",  bgiframe: true});
     $("#dialog-search-offer").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;" />'); 
     $("#closeDialogSearch").click(function(){ $("#dialog-search-offer").dialog("close"); return false;});
    };
    
 $(function(){
	// show - hide qty pricing table
	if($("td table.qty-table") != null){
	    $("td table.qty-table").hide();
	    $("a.qty").click(function(){
		    $(this).siblings("table.qty-table").toggle("fast");
		    return false;
	    });
	}

   //   $("a#freeShipDetails").click(function(){ $("#dialog").dialog("open"); return false;  });
});

$(function() { 
    if($("#dialog") != null){ 
         $("#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() { 
    if($("#leMsg") != null){
         $("#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(){ 
if($("ul#share") != null){
    $("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   
    }    
}


