function ValidateRequiredField(Field, FieldDisplayName){
	//alert('debug ' + Field + ":" + FieldDisplayName);
	if(Field.value.replace(/[\s]+/g, "").length == 0){
		Errors = Errors + "<nobr>Please fill in required information [" + FieldDisplayName + "]</nobr>\n";
		Field.focus();
		IsValid = false;
	}
}
function ValidateRequiredEmailField(Field, FieldDisplayName){
	if(!ValidEmail(Field.value)){
		Errors = Errors + "<nobr>Please enter [" + FieldDisplayName + "]</nobr>\n";
		Field.focus();
		IsValid = false;
	}
}
function ValidateRequiredHiddenField(Field, FieldDisplayName){
	if(Field.value.replace(/[\s]+/g, "").length == 0){
		Errors = Errors + "<nobr>Please fill in required information [" + FieldDisplayName + "]</nobr>\n";
		IsValid = false;
	}
}
function ValidateRequiredListField(Field, FieldDisplayName){
	if(Field[Field.selectedIndex].value.length == 0){
		Errors = Errors + "<nobr>Please select required option [" + FieldDisplayName + "]</nobr>\n";
		Field.focus();
		IsValid = false;
	}
}
function ValidateRequiredDateField(Field, FieldDisplayName){
	//if(Field.value.replace(/[\s]+/g, "").replace("/", "").length == 0 || Field.value == "1000-01-01"){
	if(Field.value == "1000-01-01" || Field.value == ""){
		Errors = Errors + "<nobr>Please fill in required information [" + FieldDisplayName + "]</nobr>\n";
		//Field.focus();
		IsValid = false;
	}
}

function ShowErrorMessage(DivSourceID){
    var oDivSource = document.getElementById(DivSourceID);
    var oDivTarget = document.getElementById("divErrorDisplay");
	
    if(oDivTarget.style.visibility=="hidden"){
	    oDivTarget.innerHTML = oDivSource.innerHTML;
	    oDivTarget.style.visibility = "visible";
    }else{
	    oDivTarget.style.visibility = "hidden";
	    oDivTarget.innerHTML = "";
    }
}

function IsInteger(e, TextBox){

    if(window.event){
    // Backspace (8) 
      if(isNaN(String.fromCharCode(e.keyCode)) || e.keyCode == 8 || e.keyCode == 32){
       event.keyCode = 0;
       return false;
      }else{
       return true;
      }
    } else {
        // Backspace (8) 
        if (e.which == 8 || e.which == 32) {
            return true;
        }
		keychar = String.fromCharCode(e.which);
		numcheck = /\d/;
		return numcheck.test(keychar); 
    }
}
		
function IsNumber(e, TextBox){
	var retval;
	if(window.event){
	  if(e.keyCode == 46){
	   // 45=-, 46=.
	   retval = true;
	  }

	  if(!retval){
	   /*e.keyCode == 32 is white space */
	   if(isNaN(String.fromCharCode(e.keyCode)) || e.keyCode == 32){
		event.e = 0;
		retval = false;
	   }else{
		retval = true;
	   }
	  }
	}else{
		if(e.which == 8 || e.which == 0 || e.which == 46){
			/*allow delete and back/forward cursor move*/
			retval = true;
		}else{
			keychar = String.fromCharCode(e.which);
			numcheck = /\d/;
			retval = numcheck.test(keychar); 
		}
	}
	return retval;
}

function ValidEmail(Email){
    var re = new RegExp("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    return re.test(Email);
}

function PopUpLink(Url, Title, Width, Height){
	window.open(Url, Title, 'menubar=0,resizeable=1,scrollbars=1,width=' + Width + ',height=' + Height);
}

function ConfirmDelete(){
		return confirm("Delete this item?\nNote that this action can not be undone!");
	}
	
function ConfirmCancel(){
    return confirm("Cancel changes and close this page?");
}

// Limit number or charactes in a textarea
function TextCounterLimit(field, maxCount) {
    if (field.value.length > maxCount) // if too long...trim it!
        field.value = field.value.substring(0, 200);
}

function IsDigits(argvalue) {
    argvalue = argvalue.toString();

    if (argvalue.length == 0)
        return false;

    for (var n = 0; n < argvalue.length; n++)
        if (argvalue.substring(n, n + 1) < "0" || argvalue.substring(n, n + 1) > "9")
        return false;

    return true;
}

// Single Select Checkbox
function SingleSelectCheckBox(regex, current) {
    re = new RegExp(regex);

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];

        if (elm.type == 'checkbox' && elm.id != current.id) {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
}