﻿// Escape framesets
//if (window != top) top.location.href = location.href;

// open user initiated popup window
function openWin(url, title, tool, scroll, h, w){
	newWin=null;
	var pos = "center";
	var h = h;
	var w = w;
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",toolbar=" + tool + ",scrollbars=" + scroll + ",location=no,directories=no,status=no,menubar=no,resizable=yes";
	newWin=window.open(url,title,settings);
	newWin.focus();	
}

/* Spell Check with UltimateSpell */
(function($) {
	$.fn.checkSpelling = function() {
		var button = '<a class="spellCheck" href="#" title="Check spelling on this field"><img src="/images/framework/spellcheck.gif" alt="Check spelling" /></a>';
		var spellID = $('span[id$=ucSpellChecker]:first').attr('id');
		return this.each(function() {
			var $field = $(this);
			if(!$field.data('checkspelling')) {
				$field.data('checkspelling', 'true');
				$(button).insertAfter($field).bind('click', function() {
					if($field.val() != '') {
						UltimateSpells[spellID].SetControlIdsToCheck($field.attr('id'));
						UltimateSpellClick(spellID);
					}
					else {
						alert('Nothing to check. Please enter text before using spell check.');
						$field.focus();
					}
					return false;
				});
			}
		});
	};
})(jQuery);

// helper tooltips
jQuery(function() {

	// get each tooltip image
	jQuery('.helpMeOut').each(function() {
	
		// create the tooltip after the image, populate with image's title, and hide it
		jQuery('<div class="helpMeText"></div>').html(jQuery(this).attr('title')).insertAfter(jQuery(this)).hide();
		
		// if ie6, create an iframe after the tooltip and hide it
		// prevents form elements from showing through
		if(jQuery.browser.msie && jQuery.browser.version == '6.0') {
			jQuery('<iframe src="/assets/js/iframe.html" frameborder="0" scrolling="no" class="fixTip"></iframe>').insertAfter(jQuery(this).next('.helpMeText')).hide();
		}
		
		// set blank title on the image, so we don't get the browser-default tooltip
		jQuery(this).attr('title', '');
		
		// when you hover over the image
		jQuery(this).bind('mouseenter', function() {
		
			// fade out visible tooltips and iframes
			jQuery('div.helpMeText:visible, .fixTip').fadeOut("fast");
			
			// get the position of the image, and position the tooltip accordingly
			var theOffset = jQuery(this).position();
			jQuery(this).next('div.helpMeText').css({ "left": (theOffset.left - 30) + 'px', "top": (theOffset.top - 10) + 'px' }).fadeIn("fast");
			
			// if ie6, position the iframe so it sits perfectly behind the tooltip
			if(jQuery.browser.msie && jQuery.browser.version == '6.0') {
				var theWidth = jQuery(this).siblings('.helpMeText:animated').outerWidth();
				var theHeight = jQuery(this).siblings('.helpMeText:animated').outerHeight();
				var thePosition = jQuery(this).siblings('.helpMeText:animated').position();
				
				jQuery(this).siblings('.helpMeText:animated').next('.fixTip').width(theWidth).height(theHeight).css({ "left": thePosition.left + 'px', "top": thePosition.top + 'px' }).fadeIn("fast");
			}
		});
	});
	
	// when you move away from the tooltip
	jQuery('div.helpMeText').bind('mouseleave', function() {
	
		// fade out the current tooltip and iframe
		jQuery(this).next('.fixTip').andSelf().fadeOut();
	});

	// injected ad click actions
	jQuery("td.injectedAd").not(".bannerAd").click(function() {
	    var theURL = jQuery(this).find("a:first").attr("href");
	    window.location = theURL;
	    return false;
	});
});