/**
 * Enable superfish menus
 * In IE, can only use when Xinha is not used,
 * hence the initial conditional.
 */
$(document).ready(function() {
	if (typeof sf_menus === 'undefined') {
		return false;
	}
	if (sf_menus && (document.createCDATASection || undefined === window.andysflag)) {
		$('ul.sf-menu').superfish();
		return true;
	}
	return false;
});

/**
 * jQuery function to preload images
 */
(function($) {
  var cache = [];
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

/**
 * This one does the actual rollovers
 */
function rolover(target, source)
{
	$("#" + target).attr("src", source);
}

function fVoid() {
}

function toggleTips(chkbox) {
	var v = chkbox.checked;
	if (true == v) {
		$('.tip-hddn').removeClass('tip-hddn').addClass('tip')
	}
	else {
		$('.tip').removeClass('tip').addClass('tip-hddn');
	}
}

function toggleDelWarn(objElement,strTargetId)
{
	/**
	 *	This function is specifically written to show and/or hide
	 *	a warning message if the "delete" checkbox is ticked in
	 *	a number of opx system management forms
	 */
	if (objElement.checked == true)
	{
		document.getElementById(strTargetId).style.display = "block"
	}
	else
	{
		document.getElementById(strTargetId).style.display = "none"
	}
}

/****************************************************************/

function confAction(message)
{
	if(confirm(message) )
	{
		return true;
	}
	return false;
}

/**
 *	Two simple functions to show and hide elements by id
 *	These are used in the navigation menus
 */

function show(elementId)
{
	$("#" + elementId).css("display", "block");
}

function hide(elementId)
{
	$("#" + elementId).css("display", "none");
}

/**
 * Some jQuery effects functions
 */
function validateSearch(thisForm, phrase) {
	if (null == phrase) {
		phrase = "Keyword(s) or Part No...";
	}
	if (phrase == thisForm.s.value
	|| '' == thisForm.s.value) {
		alert("Please enter a valid search phrase");
		return false;
	}
	else
		return true;
}

function fOutLst(elementNm) {
	/**
	 * Note - for unordered lists
	 */
	var popup = $("ul#" + elementNm);
	setTimeout(popup.fadeOut(1000), 3000);
}

function fInLst (elementNm) {
	/**
	 * Note - for unordered lists
	 */
	var popup = $("ul#" + elementNm);
	setTimeout(popup.fadeIn(500), 3000);
}
/**
function fOutDiv(elementNm) {
	var popup = $("div#" + elementNm);
	setTimeout(popup.fadeOut(1000), 3000);
}
*/
function fOutDiv(elementNm) {
	var popup = $("#" + elementNm);
	setTimeout(popup.fadeOut("slow"), 3000);
}

function fInDiv (elementNm) {
	var popup = $("div#" + elementNm);
	setTimeout(popup.fadeIn(500), 3000);
}

function showElt(element) {
	document.getElementById(element).style.display='block';
}

function hideElt(element) {
	document.getElementById(element).style.display='none';
}

function changeClass(element, newClassNm) {
	document.getElementById(element).className=newClassNm;
}
function showEltSlow(elementId) {
	$("#" + elementId).show("slow");
}
function hideEltSlow (elementId) {
	$("#" + elementId).slideUp("slow");
}
