

function ValidateForm(oForm) {
	var bStatus =true;
	//GAErr.style.display = "none";
	/// Check Date
					
			var oElement = document.frmNewsLetter.EDD;
			var valid = VAL_CheckDate(oElement);
	
			if (valid ==1){
				var isfuturedate = VAL_FutureDateOnly(oElement);
	
				if (isfuturedate =="0"){
					EDDErr.innerHTML = "<font color='#FF0000' style='font-size:12px'>EDD is a date in future.</font>";
					EDDErr.style.display = "block";
					bStatus = false;
					return bStatus;
				}
				
							}// if valid
				
			if (valid !=1){
				EDDErr.innerHTML = "<font color='#FF0000' style='font-size:12px'>EDD is required in Date Format:mm/dd/yyyy.</font>";
				EDDErr.style.display = "block";
				bStatus = false;
				return bStatus;
							}
			if (isfuturedate =="1"){
				var iscorrectFuture = FutureNineMonth(oElement);
				//alert('iscorrectFuture='+iscorrectFuture);
				if (iscorrectFuture =="0"){
					EDDErr.innerHTML = "<font color='#FF0000' style='font-size:12px'>EDD is not more than 9 month in future.</font>";
					EDDErr.style.display = "block";	
					bStatus = false;
					return bStatus;		
									}
									}//end if
							
	//alert('Status='+bStatus);
	return	bStatus;
}//end function


function VAL_CheckDate(oTargetElement) {
	var oDateArray = oTargetElement.value.split("/")
	var SUCCESS = 1;
	var INVALID_FORMAT = -1;
	var INVALID_MONTH = -2;
	var INVALID_DAY = -3;
	var INVALID_YEAR = -4;

	if (oDateArray.length < 3)
		return INVALID_FORMAT;
	else { 
		if (VAL_CheckDateMonth(oDateArray[0])) {
			if (VAL_CheckDateDay(oDateArray[1], oDateArray[0])) {
				if (VAL_CheckDateYear(oDateArray[2])) {
					try {
						var oDate = new Date(oTargetElement.value);
					}//end try
					catch (e) {
						return INVALID_FORMAT;
					}//end catch
						
					if (isNaN(oDate))
						return INVALID_FORMAT;
					else {
						VAL_FormatDate(oDate, oTargetElement);
						return SUCCESS;
						//return 
					}//end else
				}//end if
				else
					return INVALID_YEAR;
			}//end if
			else
				return INVALID_DAY;
		}//end if
		else
			return INVALID_MONTH;
	}//end else
	
	
	
}//end function

function FutureNineMonth(oElement){
	//alert('isValidFutureNEWFUNCTION');
	var oDateArray = oElement.value.split("/")
	var BASE = 10;
	var iMonth = parseInt(oDateArray[0], BASE);
	var iDay = parseInt(oDateArray[1], BASE);
	var iYear = parseInt(oDateArray[2]);
	var Ok ="1";
	
	var today = new Date( )
	var cyear, cmonth, cday;
	cyear = today.getYear();
	cmonth = today.getMonth() + 1;
		// if sama year to check the possible range
		if(iYear==cyear){
			
			/*if((iMonth-cmonth) < 9){
			alert('diflessthan9');
				Ok = "0";
									}*/
			if((iMonth-cmonth) <= 9){
			//alert('yearsamemnthdif<9');
							
				 					}
			if((iMonth-cmonth) > 9){
				Ok="0";
				 					}
						}
	
		if((iYear-cyear) == 1){
				if(((12-cmonth)+ iMonth) > 9){
				//alert('yaerdif=1_cannotbemore9');
					Ok = "0";
								}
							  }
		if((iYear - cyear) > 1){
			//alert('yeardifmore2years');
				Ok="0";
								}
//alert('beforeexitValidfutureOk='+Ok);
return Ok;

}//end function

function VAL_CheckDateMonth(sMonth) {
	var BASE = 10;
	var iMonth = parseInt(sMonth, BASE);
	return (iMonth >= 1 && iMonth <= 12) ? true : false;
}//end function

function VAL_CheckDateDay(sDay, sMonth) {
	var BASE = 10;
	var iDay = parseInt(sDay, BASE);
	var iMonth = parseInt(sMonth, BASE);
	
	switch (iMonth) {
		//31 days
		case  1 :
		case  3 : 
		case  5 :
		case  7 :
		case  8 :
		case 10 :
		case 12 :
			return (iDay >=1 && iDay <= 31) ? true : false;
			break;

		//30 days
		case  4 :
		case  6 :
		case  9 :
		case 11 :
			return (iDay >=1 && iDay <= 30) ? true : false;
			break;
			
		//28/29 days
		case  2 :
			return (iDay >=1 && iDay <= 29) ? true : false;
			break;
	}//end switch
}//end function

function VAL_CheckDateYear(sYear) {
	var iYear = parseInt(sYear);
	return (iYear >= 1000 && iYear < 10000) ? true : false;
}//end function

function VAL_FutureDateOnly(oTargetElement) {

	var iNowMS = Date.parse(new Date());
	var iSuppliedMS = Date.parse(oTargetElement.value);
	if (iNowMS - iSuppliedMS < 0)
		return "1";
	else
		return	"0";		//" must be a date in the future.";
}//end function	



/*function ValidateForm(oForm) {

	var bStatus = true;

	NewPassErr.style.display = "none";

	if (oForm.txtNewPass.value != oForm.txtNewPassVerify.value) {
		NewPassErr.innerHTML = "<font color='#FF0000' style='font-size:12px'>New Password and Verify New Password do not match.</font>";
		NewPassErr.style.display = "block";
		bStatus = false;
	}//end if
	else 	
		bStatus = VAL_ValidateForm(oForm);
	
	return bStatus;
}//end function*/

/*var subscribe = oForm.btnUnReg.value;

	var GAVal = oForm.GA.value;
	
	if (GAVal != ""){
		
		for (var i=0; i < GAVal.length; i++){
			var oneChar = GAVal.charAt(i);
			if (oneChar < "0" || oneChar > "9"){
				GAErr.innerHTML = "<font color='#FF0000' style='font-size:12px'>Gestational Age format is Numeric.</font>";
				GAErr.style.display = "block";
				bStatus = false;
				return bStatus;
												}//end for
											}// end if
					
	
				if (GAVal.length != 2){
					GAErr.innerHTML = "<font color='#FF0000' style='font-size:12px'>Gestational Age format is two digits.</font>";
					GAErr.style.display = "block";
					bStatus = false;
					return bStatus;
									}//end if
				else{// two digits
					if (GAVal > 42){
					GAErr.innerHTML = "<font color='#FF0000' style='font-size:12px'>Gestational Age can not be more than 42 weeks.</font>";
					GAErr.style.display = "block";
					bStatus = false;
					return bStatus;	
									}//end if > 4
					}//end else
		}//end if !="" 					
		if (GAVal==""){
			GAErr.innerHTML = "<font color='#FF0000' style='font-size:12px'>Gestational Age is required , format is two digits.</font>";
			GAErr.style.display = "block";
			bStatus = false;
			return bStatus;
		}//end if
	*/	
