function chkSearch(sSearchVal) {
	//alert("|" + sSearchVal + "|")
	if (sSearchVal.length <= 3 || sSearchVal == 'Search') {
		alert("Please enter a keyword to search (must be greater than 3 characters).")
		return false;
	}
	else
		return true;
}

function clearSearchBox(txtSearch) {

	if (txtSearch.value == 'Enter Search') {
		txtSearch.value = ''
	}
	return true;
}

function UTCDate(){
   var s = "";
   var d = new Date();
   s += d.getUTCMonth() + ".";
   s += d.getUTCDate() + ".";
   s += d.getUTCFullYear() + ".";
   s += d.getUTCHours() + ".";
   s += d.getUTCMinutes() + ".";
   s += d.getUTCSeconds() + ".";
   s += d.getUTCMilliseconds();

   return(s);
}


function getRadioValue(strRadio, strFormName) {
	var strOut
	var objRadio = eval("document." + strFormName + "." + strRadio)
	
	var retVal = 0;
	
	if (objRadio) {
	
		if (!objRadio.length) {
			//if (strRadio == "rdoFeeList") { alert("objRadio.checked:" + objRadio.checked) }
			return objRadio.value;
		}
		else {
			for (var i=0; i < objRadio.length; i++) {
				if (objRadio[i].checked) {
					retVal = objRadio[i].value;
				}
			}
		}
		
		return retVal;
	}
	else
		return retVal;
	
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function checkEmailExist(strEmail) {
	var url = "/global/ajax_router_general.asp";
	var parms = "action=check-email-exists&email=" + strEmail;
	new Ajax.Request(url, { parameters: parms, onSuccess: checkEmailResponse } );
}

function checkEmailResponse(sRequest) {
	if (sRequest == "FAIL") {
		alert("Your email address was found in our database. If you belong to a member organisation, you MUST log in to receive member prices.")
	}
}

function ajaxPaginate(iPage, sRootDir, iSectionID) {
	$('sibling-articles').update('<img src="/images/oct07/icons/ajax-loader.gif" alt="Loading..." /> Loading... ')
	var url = "/global/ajax_router_general.asp"
	var parm = "action=paginate&page=" + iPage + "&root-dir=" + sRootDir + "&sectionid=" + iSectionID + "&x=" + UTCDate()
	new Ajax.Updater('sibling-articles', url, { parameters:parm } );
}


function handyTrim(strValue) 
{

	/* Strip leading spaces from input */
	startposn = 0;

	while((strValue.charCodeAt(startposn) == 32) && (startposn < strValue.length)) 
		{startposn++;}

	if(startposn == strValue.length) 
		{strValue = '';} 
	else 
	{
		/* If anything left of string after stripping leading spaces strip trailing spaces as well */
		strValue = strValue.substring(startposn, strValue.length);
		endposn = (strValue.length) - 1;
		
		while(strValue.charCodeAt(endposn) == 32) 
			{endposn--;}
		
		strValue = strValue.substring(0, endposn + 1);
	}
	
	return(strValue);
}


document.observe('dom:loaded', function() {

	// --------------- list portal drop down -----------------
	var sTimer;
	if ($('portal-hover')) {
		$('portal-hover').observe('mouseover', function() {
			clearTimeout(sTimer);
			if (!$('portal-list').visible()) {
				$('portal-list').slideDown({duration:0.15})
			}
		});

		$('portal-hover').observe('mouseout', function() {
			sTimer = setTimeout(function() {
				$('portal-list').slideUp({duration:0.15})
			}, 300);
		});

		$('portal-list').observe('mouseover', function() {
			clearTimeout(sTimer);
		});

		$('portal-list').observe('mouseout', function() {
			sTimer = setTimeout(function() {
				$('portal-list').slideUp({duration:0.15})
			}, 300);
		});
	}
	
	// --------------- Green Star tool flyout -----------------
	
	$$('.nav-parent').each(function(el) {
		var sNavTimer;
		el.observe('mouseover', function() {
			clearTimeout(sNavTimer);
			
			//$$('.nav-drop').each(function(elClear) {
			//	elClear.hide()
			//});
			
			el.select('.nav-drop').each(function(elDrop) {
				sNavTimer = setTimeout(function() {
					elDrop.appear({duration:0.2})
				},150);
			});
		});
		
		el.observe('mouseout', function() {
			clearTimeout(sNavTimer);
			el.select('.nav-drop').each(function(elDrop) {
				sNavTimer = setTimeout(function() {
					elDrop.fade({duration:0.2})
				},200);
				
			});
		});
		
		el.select('.nav-drop').each(function(el) {
			el.observe('mouseover', function() {
				clearTimeout(sNavTimer);
			});

			/*
			el.observe('mouseout', function() {
				sTimer = setTimeout(function() {
					el.fade({duration:0.2})
				}, 300);
			});
			*/
		});
		
	});
	
	/*
	if ($('nav-green-star')) {
		$('nav-green-star').observe('mouseover', function() {
			$('nav-greenstar-tools-flyout').appear({duration:0.2})
		});
		
		$('nav-green-star').observe('mouseout', function() {
			$('nav-greenstar-tools-flyout').fade({duration:0.2})
		});
		
		$$('#nav-green-star ul').observe('mouseover', function() {
			$('nav-greenstar-tools-flyout').appear({duration:0.2})
		});
		
		$$('#nav-green-star ul').observe('mouseout', function() {
			$('nav-greenstar-tools-flyout').appear({duration:0.2})
		});
	}
	*/
});
