/*****************
 Function setmask
******************
 replace 'position1,position2' with the locations where you want the delimiter to follow
 replace the 'delimiter' with the separating character you would like 
 javascript:return setmask(this.value,this,'position1,position2','delimiter') i.e.:
 onKeyUp="javascript:return setmask(this.value,this,'3,8','-');" onBlur="javascript:return setmask(this.value,this,'3,8','-');"
*/
//capture event for netscape
function captureKey(e)
{
    if (document.all) {
        nKeyCode = event.keyCode;
    } else{
        nKeyCode = e.keyCode
    }
}
function setmask(str,inputbox,pos,delim){
var positions = pos.split(',');
window.removed = captureKey();
for (var i = 0; i <= positions.length; i++){
	for (var k = 0; k <= str.length; k++){
	 if (k == positions[i]){
	  if (str.substring(k, k+1) != delim){
	   if (nKeyCode != 8 && nKeyCode != 0){ //check for backspace
	    str = str.substring(0,k) + delim + str.substring(k,str.length);
       }
	  }
	 }
	}
 }
inputbox.value = str
}

//Sees if a value passed to it has a length.
function hasValue(str) {
	var isOK = false;
	if ( str.length > 0 && str.substring(0,1) != " " ) {
		isOK = true;
	}
	return isOK;
}

function isNumeric(val,type) {
	var isOK = false;
	switch ( type.toUpperCase() ) {
		case "POSITIVE_WHOLE" :
			if ( parseInt( val ).toString() == val && val > 0 ) {
				isOK = true;
			}
			break;
	}
	return isOK;
}

function isDate(str) {
	//REPattern = /\d{4}[-]\d{2}[-]\d{2}/;
	REPattern = /\d{2}[/]\d{2}[/]\d{4}/;
	return str.match( REPattern );
}

function confirmDelete( url ) {
	if ( confirm("Are you sure you want to delete this record? It will be unretrievable.") ) {
		window.location.href = url;
	}
	return false;
}
/** DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */
//check to see if the email address is a valid format
function echeck(str)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("You entered an Invalid Email Address, Please re-enter your Email Address.");
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("You entered an Invalid Email Address, Please re-enter your Email Address.");
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("You entered an Invalid Email Address, Please re-enter your Email Address.");
	    return false;
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("You entered an Invalid Email Address, Please re-enter your Email Address.");
	    return false;
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("You entered an Invalid Email Address, Please re-enter your Email Address.");
	    return false;
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("You entered an Invalid Email Address, Please re-enter your Email Address.");
	    return false;
	 }
	 if (str.indexOf(" ")!=-1){
	    alert("You entered an Invalid Email Address, Please re-enter your Email Address.");
	    return false;
	 }
	 return true					
}
//check for allowed characters in the input box
function checkchars(field)
{
	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,-@ "
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		alert("Invalid entry!  Only letters, numbers and , and . are accepted!");
		field.value = "";
		field.focus();
		return false;		
   }
   else{
		return true;	
   }	
}
//check for numeric value in the input box
function checknum(field)
{
	var valid = "0123456789.$,"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		alert("Invalid entry!  Please enter numeric values only!");
		field.value = "";
		field.focus();
		return false;		
   }
   else{
		return true;	
   }	
}

function cancelform()
{
	if (confirm("Are you sure you want to leave this page without saving any changes?")){
		window.history.back();
	}
	return false;			
}

//user can not use the enter key to submit the form
function noenter()
{
	if (window.event && window.event.keyCode == 13){
	//return !(window.event && window.event.keyCode == 13);
	alert("Please click on the button to process your request.\nHitting the ENTER key will not process your request.");	
	return false;
	}
}
//popup, center and give new window focus
function popup_window(url, width, height) 
{
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2));
	var winfeatures = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + 'screenX=' + left + ',screenY=' + top;
	mywin = window.open(url,"newwin", winfeatures);
	mywin.focus()

}