function trim(s) {
	var tmp = "" + s + "";
	return tmp.replace(/^\s*|\s*$/g, "");
}

function ltrim(s) {
	var tmp = "" + s + "";
	return tmp.replace(/^\s*/g, "");
}

function rtrim(s) {
	var tmp = "" + s + "";
	return tmp.replace(/\s*$/g, "");
}


function PswdConfirm (s1, s2) {

	if (s1 != s2) {
		alert("Passwords do not match!  Please re-enter...");
	}
	return false;

}



function isDate(theDate) {

    var dtval
    
    theDate = theDate.replace(".", "/");
	theDate = theDate.replace(".", "/");
    theDate = theDate.replace("-", "/");
    theDate = theDate.replace("-", "/");

	dtval = theDate.split("/");
    if (dtval.length != 3) {
		return "ERROR: Format is 'mm/dd/yyyy'" 
	} else { 
    	var mo = dtval[0]-1+1;
    	var day = dtval[1]-1+1;
    	var yr = dtval[2]-1+1;

//    	yr = (yr < 100) ? yr + 2000 : yr;
    	if (yr > 9999) {
    		return "ERROR: Maximum year 9999.";
    	}

		if (yr < 100) {
    		return "ERROR: Please enter 4 digit year.";
		}
		  	
    	var days = 0
    	if (mo >= 13) { 
    		return "ERROR: Maximum 12 months.";
    	} else {
    		switch (mo) {
    			case 2:
    				// for February (implements 400 year cycle calculation)
    				days = (((yr%4 == 0 && yr%100 != 0) || yr%400 ==0) ? 29 : 28 );
    				break;

    			default:
    				// for January thru December except February
    				days = 30 + ((mo < 8) ? mo%2 : (mo%7)%2);
	   		}
    		if (days < day) {
    			return "ERROR: Maximum of "+days+" for month "+mo+".";
    		} else {
    			return mo+"/"+day+"/"+yr;
    		}
    		//return dtval[0]-1+1
    	}	
    }
}


function StateToCaps(myState) {

	document.getElementById(myState).value = document.getElementById(myState).value.toUpperCase();
	return false;

}



function State2Caps() {

	document.frmUser.state.value = document.frmUser.state.value.toUpperCase();
	return false;

}


function ChkPhone() {

	document.frmUser.Phone.value = FormatPhone(document.frmUser.Phone.value);
	return false;
}


function ChkFax() {

	document.frmUser.Fax.value = FormatPhone(document.frmUser.Fax.value);
	return false;
}

function CheckPhone(myPhone) {

	document.getElementById(myPhone).value = FormatPhone(document.getElementById(myPhone).value);
    return false;
}

function FormatPhone(orgPhone) {

	var nLen, i, n;
	var strPhone="";
	
	nLen = orgPhone.length;
	if (nLen > 0) {
		for (i=0; i < nLen; ++i) {
			n = parseInt(orgPhone.charAt(i));
			if (isNaN(n) == false) {
				strPhone = strPhone + n.toString();
			}
		}
		nLen = strPhone.length;
		switch (nLen) {
			case  7:
				orgPhone = strPhone.substr(0,3) + "-" + strPhone.substr(3,4);
				alert("Area code missing from phone #!  Please re-enter...");
				break;

			case 10:
				orgPhone = strPhone.substr(0,3) + "-" + strPhone.substr(3,3) + "-" + strPhone.substr(6,4);
				break;

			default:
				orgPhone = "";
				alert("Invalid Phone Number!  Please re-enter...");
		}
	}	
	return orgPhone;
}

