function ClearOptions(OptionList) {

   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x--) {
      OptionList[x] = null;
   }
}

function AddToOptionList(OptionList, OptionValue, OptionText) {
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}


function clickClear(f, str) {
	if(f.value == str)
		f.value = '';
};

function clickRecall(f, str) {
	if(f.value == '')
		f.value = str;
};


function deleteConfirm(url, msg)
{
	var r=confirm(msg);
	if (r==true)
	{
		window.location = url;
	}
};

function cancelConfirm(url, msg)
{
	var r=confirm(msg);
	if (r==true)
	{
		window.location = url;
	}
};

function addBookmark(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
};

function agreeTerms(cb,button) { //checkbox, button to enable.
	if(cb.checked) {
		eval(button).disabled = false;
	}
	else {
		eval(button).disabled = true;
	}
};

function mandatory(myfield) {
	if(eval(myfield).value == '') {
		alert("You must enter a value for this field");
		return false;
	}
	else
		return true;
};

function isEmpty(myfield) {
	if(eval(myfield).value == '')
		return true;
	else
		return false;
};

function checkEmail(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value)) {
		alert('Please provide a valid email address');
		email.focus
		return false;
	}
}

function onlyNumeric(field, val) {
	validchars = "0123456789";
	newstr = "";
	for(i = 0; i < val.length; i++) {
		thischar = val.substr(i, 1);
		if(thischar == ".") {//Our field in the database only takes an int so discard everything past the decimal point.
			field.value = newstr;
			return true;
		}
		if(validchars.indexOf(thischar) != -1)
			newstr += thischar;
	}
	field.value = newstr;
	return true;
}


function formatCurrency(val) {
	return 13.13;
}

function confirmPassword(cfmPwd, Pwd) {
	if(!this.isEmpty(Pwd)) {
		Pwd = eval(Pwd);
		cfmPwd = eval(cfmPwd);
		if(cfmPwd.value != Pwd.value) {
			alert('Your password\'s don\'t match. Please try again.');
			cfmPwd.value = '';
			Pwd.value = '';
			Pwd.focus();
			return false;
		}
		else
			return true;
	}
	else {
		alert('You must supply password.');
		return false;
	}
};