/*------------------------------------------------------------------
//	MyGymCoach.com / GTZFitness.com Websites
//	Copyright Structured Fitness Solutions, Inc.
//	By Michael Burford
//----------------------------------------------------------------*/

function VerifyNumber(min, max, zeroOK, value, label, labelUnit) {
	if (zeroOK && (parseFloat(value)==0.0 || value=="")) {
		//Zeros or blank are OK, even if out of the range.
	} else if (value<min || value>max) {
		alert(label+" should be between "+min+" and "+max+labelUnit+".");
		return true;
	} 
	return false;
}

function VerifyDate(value) {
    if (value=="Today" || value=="today") return false;
    
    var month = value.split("/")[0];
    var day = value.split("/")[1];
    var year = value.split("/")[2];
    var validdate = true;
    
    month = parseInt(month);
    day = parseInt(day);
    year = parseInt(year);
    
    var dt = new Date(year, month-1, day, 0, 0, 0, 0);
    if (dt.getDate()!=day) validdate = false; 
    if (dt.getMonth()!=month-1) validdate = false; 
    
    if (!validdate || month<1 || month>12 || day<1 || day>31 || year<1980 || year>2050) {
		alert("The date is not valid.");
		return true;
    }
	return false;
}

function VerifyMaxLength(elem, showchars) {
    if (!elem.getAttribute) return;
    
    var max = parseInt(elem.getAttribute("maxlength"));    
    var cur = elem.value.length;
    if (cur>max) {
        elem.value = elem.value.substring(0, max);
    }
    
    if (showchars!="") {
	    var xchars = document.getElementById(showchars);
	    if (xchars) {
	        xchars.innerHTML = cur + "/" + max;
	    }
	}
}