
// isEmpty
	function isEmpty (strValue) {
		return (! strValue.replace (/^(\s*)/, "", strValue));
	}

// isValidEmail
	function isValidEmail (emailStr) {

		var emailPat=/^(.+)@(.+)$/; 
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]"; 
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+'; 
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) {
			return false;
		}
		
		var user=matchArray[1];
		var domain=matchArray[2];
		
		if (user.match(userPat)==null) {
			return false;
		}
		
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					return false;
				}
			}
			return true;
		}
		
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
		    return false;
		}

		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>4) {
			return false;
		}
	
		if (len<2) {
			return false;
		}

		return true;
	}

	function isValidCurrency(strValue)  {
		var objRegExp = /(^\${0,1}\d{1,3}(,{0,1}\d{3})*(\.\d{2})*$)|(^\(\${0,1}\d{1,3}(,{0,1}\d{3})*(\.\d{2}\))*$)/;
		return objRegExp.test( strValue );
	}

// isValidDate
	function isValidDate (strValue) {
		var datePat = /^(\d{2})(\/|-)(\d{2})\2(\d{4})$/;
		var matchArray = strValue.match(datePat); 
		if (matchArray == null) { return false;	}
		day = matchArray[1]; month = matchArray[3]; year = matchArray[4];
		if (month < 1 || month > 12) { return false; }
		if (day < 1 || day > 31) { return false; }
		if ((month==4 || month==6 || month==9 || month==11) && day==31) { return false; }
		if (month==2) {
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) { return false; }
		}
		return true;
	}

// reduceToDigits
	function reduceToDigits (strValue) {
		return (strValue.replace (/([^0-9])/g, "", strValue));
	}

function checkAll(formObj, formFieldName, formFieldState) {
	formFieldObj = eval('formObj.' + formFieldName);
	if (formFieldObj[1]) {
		noOfCheckBoxes =  formFieldObj.length;
		for(i=0; i < noOfCheckBoxes; i++) {
			formFieldObj[i].checked = formFieldState;
		}
	}
	else {
		formFieldObj.checked = formFieldState;
	}
}

// convertToDigits
function convertToDigits (strValue,pad,upperLimit) {
	if (strValue == "") return "";
	var newValueArray = (strValue.replace(/([^0-9\.])/g, "")).split(".");
	var newValue = "";
	if (pad) {
		if (newValueArray[1] == null) newValue = newValueArray[0] + ".00";
		else if (newValueArray[1].length == 1) newValue = newValueArray[0] + "." + newValueArray[1] + "0";
		else newValue = newValueArray[0] + "." + newValueArray[1].substr(0,2);
	} else {
		if (newValueArray[1] == null) {
			if (strValue.indexOf(".") > -1) newValue = newValueArray[0] + ".";	else newValue = newValueArray[0];
		} else newValue = newValueArray[0] + "." + newValueArray[1].substr(0,2);
	}
	if ((upperLimit != null) && newValue > parseFloat(upperLimit)) return upperLimit;
	else return newValue;
}
	
function reduceToChars (strValue) {
	return (strValue.replace (/([^a-zA-Z0-9\`\-\=\[\]\\\;\'\,\.\/\~\!\@\#\$\%\^\&\*\(\)\_\+\{\}\|\:\"\<\>\? \f\n\r\t\v])/g, "", strValue));
}

function copytoObj(fromObj,toObj) {
  var sel = false;
  for (i=0;i<fromObj.options.length;i++)  {
    var current = fromObj.options[i];
    if (current.selected) {
      sel = true;
      if (current.value == '0') {
        alert ('You cannot move this option!');
        return;
      }
	  if (toObj.options.length == 1 && toObj.options[0].value == '0')  {
	    toObj.options.length = 0;
	  }
      txt = current.text;
      val = current.value;
      toObj.options[toObj.length] = new Option(txt,val);
      fromObj.options[i] = null;
      i--;
    }
  }
  if (!sel) alert ('You haven\'t selected any options!');
}

function allSelect(listObj) {
  for (i=0;i<listObj.length;i++) {
     listObj.options[i].selected = true;
  }
}


function checkAdminImageForm(formObj) {  

	var alert_message = "";
	if (isEmpty(formObj.imgLocation.value)) {
		alert_message = alert_message + "   An Image\n";
	}

	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}


function checkAdminRelatedURLForm(formObj) {  
	var alert_message = "";
	if (isEmpty(formObj.urlTitle.value)) {
		alert_message = alert_message + "   A Title\n";
	}
	if (isEmpty(formObj.urlString.value)) {
		alert_message = alert_message + "   A Link\n";
	}

	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}

function checkAdminRelatedDocForm(formObj) {  
	var alert_message = "";
	if (isEmpty(formObj.docTitle.value)) {
		alert_message = alert_message + "   A Title\n";
	}
	if (isEmpty(formObj.docFile.value)) {
		alert_message = alert_message + "   A Document\n";
	}

	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}



function checkCategoryAddForm(formObj) {  

	var alert_message = "";
	if (isEmpty(formObj.catTitle.value)) {
		alert_message = alert_message + "   A Title\n";
	}

	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}


function checkProductAddForm(formObj) {  

	var alert_message = "";
	if (isEmpty(formObj.prdTitle.value)) {
		alert_message = alert_message + "   A Title\n";
	}

	if (isEmpty(formObj.prdDescription.value)) {
		alert_message = alert_message + "   A Description\n";
	}

	if (!isValidCurrency(formObj.prdPrice.value)) {
		alert_message = alert_message + "   A Valid Price\n";
	}

	if (formObj.FK_lpc_catID.selectedIndex == -1) {
		alert_message = alert_message + "   At Least One Category\n";
	}
	
	
	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}


function checkNewsAddForm(formObj) {  

	var alert_message = "";
	if (!isValidDate(formObj.nwsDate.value)) {
		alert_message = alert_message + "   A Valid Date\n";
	}
	if (isEmpty(formObj.nwsTitle.value)) {
		alert_message = alert_message + "   A Title\n";
	}
	if (isEmpty(formObj.nwsDescription.value)) {
		alert_message = alert_message + "   A Description\n";
	}

	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	} 
}



// checkEventAddForm
function checkEventAddForm(formObj) {  

	var alert_message = "";

	if (!isValidDate(formObj.evtStartDate.value)) {
		alert_message = alert_message + "   A Valid Start Date\n";
	}
	if (!isValidDate(formObj.evtEndDate.value)) {
		alert_message = alert_message + "   A Valid End Date\n";
	}
	if (isEmpty(formObj.evtTitle.value)) {
		alert_message = alert_message + "   Title\n";
	}
	if (isEmpty(formObj.evtDescription.value)) {
		alert_message = alert_message + "   Description\n";
	}
	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}
