// Returns a flag indicating if the ENTER key has been pressed
function isEnterKeyPressed() {
	if (window.event.keyCode == 13)
		return true;

	return false;
}

// Clicks on the specified form field
function clickField(strFieldName) {
	document.forms[0].elements[strFieldName].click();
}

function admin_onkeypress() {

	if(event.type == 'keypress' && event.keyCode == 13)
	{
	       verifyUser();
	}
}

// Returns a flag indicating if the specified checkbox is selected
function isCheckboxSelected(strFieldName) {
	return document.forms[0].elements[strFieldName].checked;
}

// Checks if the specified form field is a valid email address - must contain @ symbol
function isEmailAddress(strFieldName){
	var strFieldValue;

	strFieldValue = document.forms(0).item(strFieldName).value;

	if ( (strFieldValue.indexOf("@") != -1) && (strFieldValue.indexOf(".") != -1) ) 

		return true;

	return false;
}

function validateDatefield(strDateField) {
		
	var strDate;
	var strDay;
	var strMonth;
	var strYear;

	if (fieldLength(strDateField) != 10 ) {
		return false;
		
	}

	strDate = getFieldValue(strDateField);
	strDay = strDate.substr(0,2);
	strMonth = strDate.substr(3,2);
	strYear = strDate.substr(6,4);
	//alert(strDay + strMonth + strYear);
	if (!isValidDate(strDay, strMonth, strYear)) {
		return false;
	}
	
	return true;
}

// Convert a month from an integer (1,2,3 ...) to string (Jan,Feb,Mar, ...)
function MonthToStr(intMonth) {

	switch(intMonth) {
		case  1: return "Jan";
		case  2: return "Feb";
		case  3: return "Mar";
		case  4: return "Apr";
		case  5: return "May";
		case  6: return "Jun";
		case  7: return "Jul";
		case  8: return "Aug";
		case  9: return "Sep";
		case 10: return "Oct";
		case 11: return "Nov";
		case 12: return "Dec";
	}
	
	return "Unknown";
}

// sets a field attribute
function setFieldAttribute(strFieldName, strAttrName, strAttrValue) {
	document.forms[0].elements[strFieldName].setAttribute(strAttrName,strAttrValue);
}

// get a field attribute value by name
function getFieldAttribute(strFieldName, strAttrName) {
	return document.forms[0].elements[strFieldName].getAttribute(strAttrName);
}

// Sets the contents of the specified form field to the specified value
function setFieldValue(strFieldName, strFieldValue) {
	document.forms[0].elements[strFieldName].value = strFieldValue;
}

// Returns the contents of the specified form field
function getFieldValue(strFieldName) {
	return document.forms[0].item(strFieldName).value;
}

// Returns a flag indicating if the contents of the specified form field are a valid date
function isValidDate(strDayFieldName, strMonthFieldName, strYearFieldName) {
	
	var intDayFieldValue;
	var intMonthFieldValue;
	var intYearFieldValue;

	// Numeric field Checking
	if (!isNumeric(strDayFieldName) )
		return false;

	if (!isNumeric(strMonthFieldName) )
		return false;

	if (!isNumeric(strYearFieldName) )
		return false;

	intDayFieldValue = parseInt(strDayFieldName, 10);
	intMonthFieldValue = parseInt(strMonthFieldName, 10);
	intYearFieldValue = parseInt(strYearFieldName, 10);

	// Day field validation
	if (intDayFieldValue < 1 || intDayFieldValue > 31)
		return false;

	// Month field validation
	if (intMonthFieldValue < 1 || intMonthFieldValue > 12)
		return false;

	// Year field validation
	if (intYearFieldValue == "0000")
		return false;
	
	return true;
}

// Returns the length of data in the specified form field
function fieldLength(strFieldName) {
	var strFieldValue;
	
	strFieldValue = document.forms(0).item(strFieldName);
	
	if (strFieldValue == null)
		return 0;
		
	return strFieldValue.value.length;
}

// Returns a flag indicating if the contents of the specified form field are numeric
function isNumeric(strFieldName) {
	var intFieldValue;
	var intLength;

	intFieldValue = strFieldName;
	
	if (isNaN(Math.abs(intFieldValue)) ) {
		if (isNumeric.arguments.length == 1)
			return false;
	}

	return true;
}

// Sets the cursor position back to form field if error
function gotoField(strFieldName) {
	document.forms(0).item(strFieldName).focus();
	document.forms(0).item(strFieldName).select();
}

// Sets the class of the specified form field to 'enabled field' style
function enableField(strFieldName) {
	with (document.forms[0].elements[strFieldName]) {
		disabled = false;
		className = "enabledField";
	}
}

// Sets the class of the specified form field to 'disabled field' style
function disableField(strFieldName) {
	with (document.forms[0].elements[strFieldName]) {
		disabled = true;
		value = "";
		className = "disabledField";
	}
}

// Displays an error message and returns FALSE to the caller
function errorBox(strMsg) {
	alert(strMsg);
	return false;
}

// Displays an error message and returns FALSE to the caller
function errorMsg(strFieldName,strMsg) {
	alert(strMsg);	
	gotoField(strFieldName);
	return false;
}

// Displays a yes/no prompt and returns the selected outcome (TRUE/FALSE) to the caller
function warningMsg(strMsg) {
	return confirm(strMsg);
}

// Displays an information message and returns TRUE to the caller
function infoMsg(strMsg) {
	alert(strMsg);
	
	return true;
}

// header
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}