jQuery.noConflict();


function htmlEncode(value){ 
   return jQuery('<div/>').text(value).html(); 
} 

function htmlDecode(value){ 
   return jQuery('<div/>').html(value).text(); 
}

//create a function scope so we dont pollute the global namespace
(function ($) {
   
   /**
   Input Watermark plugin
   Allows the insertion of text into an input that will fill it until the user enters 
   some text
   */
	$.fn.inputWatermark = function(waterMarkText, options)
   {
      var defaults = {
				color: '#000',
				'font-style': 'normal'
		};
      //override defaults with any supplied options
      var settings = $.extend({}, defaults, options);	      
      
      //store some current css values so we can toggle between and watermark css
      var startingCSS = {
         color: this.css('color'),
         'font-style': this.css('font-style')
      };
      
      //set init text
      //note: using htmlDecode to handle non asscii characters
      var decodedWaterMarkText = waterMarkText ? htmlDecode(waterMarkText) : '';            
      this.val(decodedWaterMarkText);
      
      this.focus(function(){
         //if watermark text is set then remove it
         if($(this).val() === decodedWaterMarkText)
         {
            $(this).val('');
            $(this).css({
                   'color': settings['color']
                  ,'font-style': settings['font-style']
               });
         }
      });
        
      this.blur(function(){
         //if input is empty then put the watermark back in
         if($(this).val() === '')
         {
            $(this).val(decodedWaterMarkText);
            $(this).css({
                   'color': startingCSS['color']
                  ,'font-style': startingCSS['font-style']
               });
         }      
      });
      
	};

})(jQuery);


function doSearchOnEnter(e) {    
    var keynum = 0;
    if (window.event) {
        keynum = window.event.keyCode;
    } else if (e.which) {
        keynum = e.which;
    }
    // Enter key pressed
    if (keynum == 13) {   
        if (validateQueryTextLength()) {
            if (mySearchButton != null) {
                 mySearchButton.click();
            } else {
                 window.alert("Search button was not found.");
            }
        }         
    }  
    return false;
}

function validateQueryTextLength() {
    var searchTextVal = searchText.value;
    if (searchTextVal != null) {       
        if (searchTextVal.length < 2) {
            window.alert("Search text must be at least 2 characters in length!");
            return false;
        }   
    }   
    return true;
}

function ToggleVisibility(item) {        
    var divstyle = document.getElementById(item).style;
    if (divstyle.visibility.toLowerCase() == "visible" || divstyle.visibility == "") {
        divstyle.visibility = "hidden";       
    }
    else {                           
        divstyle.visibility = "visible";                                     
    }      
}

//Clear the default search term out of the help search
function clearSearch() {
    var searchinput = jQuery('#helpSearch input.text, #contactform input');
    searchinput.focus(function() {
        if((this).value == 'enter keywords' || (this).value == 'type your subject here') {
            this.value = '';
            jQuery(this).css({'color': 'black', 'font-style': 'normal'});
        }
    });
}

//Toggle the search tips
function searchTipsDropdown() {
    var jQuerysearchTipsTrigger = jQuery('#searchTipsTrigger');
    var jQuerysearchTipsPanel = jQuery('#tips');
    var jQueryoverlay = getOverlay();
    var searchTipsDisplayed = false;
    jQuerysearchTipsTrigger.click(function() {
    	if (searchTipsDisplayed) {
    		hideSearchTips(jQueryoverlay, jQuerysearchTipsPanel);
    	} else {
    		showSearchTips(jQueryoverlay, jQuerysearchTipsPanel);
    		jQuerysearchTipsPanel.click(function() {
    			hideSearchTips(jQueryoverlay, jQuerysearchTipsPanel);
    		});
    		jQuery('#close').click(function() {
    			hideSearchTips(jQueryoverlay, jQuerysearchTipsPanel);
    		});
    		jQuery('#inner').click(function(event) {
    			event.stopPropagation();
    		});
        }
    });
}

function showSearchTips (jQueryoverlay, jQuerysearchTipsPanel) {
	jQueryoverlay.show();
	jQuerysearchTipsPanel.show();
}

function hideSearchTips (jQueryoverlay, jQuerysearchTipsPanel) {
	jQuerysearchTipsPanel.hide();
	jQueryoverlay.hide();
}

function getOverlay () {
 	if (!document.getElementById('overlay')) {
 		var overlay = document.createElement('div');
 		overlay.id = "overlay";
 		document.body.appendChild(overlay);
 	}
 	return jQuery('#overlay');
 }

var isIE6 = false;
/*@cc_on
@if (@_jscript_version == 5.7)
	if(!window.XMLHttpRequest) {
		isIE6 = true;
	};
@elif (@_jscript_version == 5.6)
	isIE6 = true;
@end
@*/

function fixPng (bgImageContainerId) {
	if (isIE6) {
		var container = jQuery('#' + bgImageContainerId);
		if (container) {
			var imageUrl = container.css("backgroundImage");
			imageUrl = imageUrl.substring(5, imageUrl.length - 2);
			container.css("backgroundImage", "none");
			container.css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='crop', src='" + imageUrl + "')");
		}
	}
}
function fixPngs () {
	for (var i = 0; i < arguments.length; i++) {
		fixPng(arguments[i]);
	}
}


//When the documents ready run all the fucntions that need to be run
 
jQuery(window).ready( function () {
	searchTipsDropdown();
	clearSearch();
});

