function customAppCalendar(theForm,theField){
	windowURL = '/popupCalendar.cfm?formName=' + theForm + '&formField=' + theField;
	if(window.screen){
    cw = Math.floor(screen.availWidth/2);
	  ch = Math.floor(screen.availHeight/2);
	} else {
		cw = 100;
		ch = 100;
	}
	var newWind = window.open(windowURL,'remote','width=225,height=265,top=' + ch + ',left=' + cw);
	if(newWind && newWind.opener == null){
		newWind.opener = window;
	}
}

function resizeQuickLook(){
  var maxQL = 110;
  $("div.quicklook").each(function(){
    var thisQL = $(this).children("a:first").children("img").height();
    if(thisQL > maxQL) maxQL = thisQL;
  });
  if(maxQL > 110) $("div.quicklook").height(maxQL);
}

// Onload When Document Ready
$(function() {
  $('a[rel=external]').attr('target', '_blank');
  $('.equalize').equalHeights('true');
  $("img[src$=png],.pngfix").pngfix();
  //$(document).stickyfooter();
  $("ul#footernav li:not(:last),div#subnav ul li:not(:last)").append("<span class=\"spacer\">|</span>");
  $("div.buttons a,div.buttons button").prepend("<div class=\"button-right\">&nbsp;</div>");
  $(".white-box").prepend("<div class=\"top\">&nbsp;</div>");
  $(".bgAlt").prepend("<div class=\"cap\">&nbsp;</div>");
  $(".treatment ul").append("<li class=\"clears\">&nbsp;</li>");
  $('.photocap > img[title]').each(function(){$(this).after("<p>"+this.title+"</p>").parent().css("width", $(this).width());});
  $("img.photocap").each(function(){
     if($(this).css("float") === 'right'){
         $(this).css("margin", "0 0 15px 20px")
     } else if($(this).css("float") === 'left'){
         $(this).css("margin", "0 20px 15px 0")
     }
  });
  $('a.popup').live('click',function(){var data=$(this).metadata();var name=(data.name==null)?'popup':data.name;w=screen.availWidth;h=screen.availHeight;var leftPos=(w-data.width)/2,topPos=(h-data.height)/2;window.open($(this).attr('href'),name,'width='+data.width+',height='+data.height+',toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=yes,top='+topPos+',left='+leftPos);return false;});

	if($("input.datepicker").length) $('input.datepicker').datepicker();

  if ($('a.photobox').length) {
    $("a.photobox").fancybox({
      'hideOnContentClick': true
    });
  }

  if ($('a.contentbox').length) {
    $("a.contentbox").each(function() {
      $(this).fancybox({
        'height'   : 400,
        'width'    : 600,
        'type'     : 'iframe',
        'hideOnOverlayClick': false,
        'hideOnContentClick': false
      });
    });
  }

  if ($('a.videobox').length) {
    $('a.videobox').fancybox();
  }


  $("a.compareItems").bind("click.compare", function(){
  	if($("input[name='compareIDs']:checked").length > 6){
  		alert('You may only compare 6 products at once.');
  		return false;
  	}
  	$("#prodCompare").submit();
  	return false;
  });

  $("form.validate").validate({
  	errorClass: "invalid",
  	validClass: "valid",
  	errorPlacement: function(error, element){
  		element.attr("title", error.text());
  		return true;
  	}
  });

  resizeQuickLook();
  // Safari has decided to start executing this before the document is actually ready, so adding a timeout
  setTimeout('resizeQuickLook();', 700);
});
