// when the document is ready:
$(document).ready(function(){
	
	eqHeights('.recommended .productImageLink');
	
	// tests to see if we're in IE and ie less that 7
	leftNav();
	loginNav();
	var isIE = $.browser.msie;
	var isBadIE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent);						   
	
	// functions found below
	formHelpers();
		
	extraFormHelpers(isIE,isBadIE);
	
	// this is interface.js - it needs to be linked to from the pages with jquery
	/*$(document).ScrollToAnchors(700);*/
	
});

function eqHeights(sel) {
	var hightest = 0;
	
	$(sel).each(function(i, el) {
		if ($(el).height() > hightest) hightest = $(el).height();			
	});
	
	$(sel).height(hightest);
}

// this function search and replaces a string and returns the new string
// http://www.daveshuck.com/blog/index.cfm/2006/12/13/Javascript-examples--removeElement-and-replaceAll
function replaceAll( str, searchTerm, replaceWith, ignoreCase )   {
   var regex = "/"+searchTerm+"/g";
   if( ignoreCase ) regex += "i";
   return str.replace( eval(regex), replaceWith );
}

// parse url
// http://lawrence.ecorp.net/inet/samples/regexp-parse.php

function formHelpers() {
	
	
	// add class "checkBox" to all inputs of type checkbox
	$(':checkbox').addClass("checkBox");
						   
	// add class "submit" to all inputs of type submit
	$(':submit').addClass("submit");
	
	// and for input type file
	$(':file').addClass("file");
	
	// and for input type radio
	$(':radio').addClass("radio");
	
	// switch classes on input type "submit" on roll over
	$(':submit').hover(function() {
		$(this).addClass("submitHover");
	},function(){
		// remove it on roll off
		$(this).removeClass("submitHover");
	});
}

function extraFormHelpers(isIE,isBadIE) {
	if (isIE) {
		$("#searchBox input.submit, .featuredProduct input.submit, .emailSignUp input.submit, #center ul.searchResults li div.buyBtns fieldset input.submit").attr("value","");
	}
}

// Simple redirect with querystring
function RedirectToSearch(dat){
	 window.location = '/CharlesBirchWH/pages/searchresults.aspx?keyword=' + dat
	}

// On enter evaluate function
function trapEnter(e, enterFunction){
  if (!e) e = window.event;
  if (e.keyCode == 13){
    e.cancelBubble = true;
    if (e.returnValue) e.returnValue = false;
    if (e.stopPropagation) e.stopPropagation();
    if (enterFunction) eval(enterFunction);
    return false;
  } else {
    return true;
  }      
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

    function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal) {

         // re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon
         re = new RegExp('.*' + aspCheckBoxID)

        for(i = 0; i < document.forms[0].elements.length; i++) {

            elm = document.forms[0].elements[i]

            if (elm.type == 'checkbox') {

                if (re.test(elm.name)) {

                    elm.checked = checkVal

                }
            }
        }
    }
	
function leftNav() {
	$('#left ul li:first').addClass('top');	
}
function loginNav() {
	$('.loginList ul li:nth-child(4n)').addClass('noRightMargin');
}


