
//---------------------------------------------------------------------------------------------
//Filename:		GlobalValidate.js
//---------------------------------------------------------------------------------------------

//-------------------------------------
// Function:     bIsBlank(sFieldValue)
// Check a field value
//-------------------------------------

function bIsBlank(sFieldValue){
	if (sFieldValue == "") {
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidFirstName(sFirstName)
// check to see if the field is blank
//-------------------------------------

function bIsValidFirstName(sFirstName){
	if (sFirstName == "") {
			alert("\nThe First Name field is blank.\n\nPlease enter your first name.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidLastName(sLastName)
// check to see if the field is blank
//-------------------------------------

function bIsValidLastName(sLastName){
	if (sLastName == "") {
			alert("\nThe Last Name field is blank.\n\nPlease enter your last name.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsPassword(sPassword)
//check to see if the field is blank
//-------------------------------------

function bIsValidPassword(sPassword){
	if (sPassword == "") {
			alert("\nThe Password field is blank.\n\nPlease enter your password.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidDOB(sDOB)
//check to see if the field is blank
//-------------------------------------

function bIsValidDOB(sDOB){
	if (sDOB == "") {
			alert("\nThe Date of Birth is required.\n\nPlease select your date of birth by clicking on Calendar icon.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidMorningPhone(sMorningPhone)
//check to see if the field is blank
//-------------------------------------

function bIsValidMorningPhone(sMorningPhone){
	if (sMorningPhone == "") {
			alert("\nThe Morning Phone field is blank.\n\nPlease enter your morning phone.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidDaytimePhone(sDaytimePhone)
//check to see if the field is blank
//-------------------------------------

function bIsValidDaytimePhone(sDaytimePhone){
	if (sDaytimePhone == "") {
			alert("\nThe Daytime Phone field is blank.\n\nPlease enter your daytime phone.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidEveningPhone(sEveningPhone)
//check to see if the field is blank
//-------------------------------------

function bIsValidEveningPhone(sEveningPhone){
	if (sEveningPhone == "") {
			alert("\nThe Evening Phone field is blank.\n\nPlease enter your evening phone.")
			return false;
		}
	return true;
}


//-------------------------------------
//Function:     bIsValidEveningPhone(sEveningPhone)
//check to see if the field is blank
//-------------------------------------

function bIsValidCity(sListenerCity){
	if (sListenerCity == "") {
			alert("\nThe City field is blank.\n\nPlease enter your City.")
			return false;
		}
	return true;
}




//-------------------------------------
//Function:     AddArtistDetailsValidate(sArtistName)
//check to see if the field is blank
//-------------------------------------

function bIsValidArtistName(sArtistName){
	if (sArtistName == "") {
			alert("\nThe Artist Name field is required.\n\nPlease enter the artist name.")
			return false;
		}
	return true;
}


//-------------------------------------
//Function:     AddConcertListingValidate(sConcertDate)
//check to see if the field is blank
//-------------------------------------

function bIsValidConcertDate(sConcertDate){
	if (sConcertDate == "") {
			alert("\nThe Concert Date field is required.\n\nPlease enter the concert date by clicking on Calendar icon.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     AddShowValidate(sShowName)
//check to see if the field is blank
//-------------------------------------

function bIsValidShowName(sShowName){
	if (sShowName == "") {
			alert("\nThe Show Name field is required.\n\nPlease enter the show name.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidShowDescription(sShowDescription)
//check to see if the field is blank
//-------------------------------------

function bIsValidShowDescription(sShowDescription){
	if (sShowDescription == "") {
			alert("\nThe Show Description field is required.\n\nPlease enter the show description.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidFunFilesTitle(sFunFilesTitle)
//check to see if the field is blank
//-------------------------------------

function bIsValidFunFilesTitle(sFunFilesTitle){
	if (sFunFilesTitle == "") {
			alert("\nThe Articles Title field is required.\n\nPlease enter the article title.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidSpecialEventTitle(sSpecialEventTitle)
//check to see if the field is blank
//-------------------------------------

function bIsValidSpecialEventTitle(sSpecialEventTitle){
	if (sSpecialEventTitle == "") {
			alert("\nThe Head Line field is required.\n\nPlease enter the head line.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidNewsletterName(sNewsletterName)
//check to see if the field is blank
//-------------------------------------

function bIsValidNewsletterName(sNewsletterName){
	if (sNewsletterName == "") {
			alert("\nThe Newsletter Name field is required.\n\nPlease enter the newsletter name.")
			return false;
		}
	return true;
}


//-------------------------------------
//Function:     bIsValidNewsTitle(sNewsTitle)
//check to see if the field is blank
//-------------------------------------

function bIsValidNewsTitle(sNewsTitle){
	if (sNewsTitle == "") {
			alert("\nThe Article Title field is required.\n\nPlease enter the article title.")
			return false;
		}
	return true;
}


//-------------------------------------
//Function:     bIsValidWeatherTypeName(sWeatherTypeName)
//check to see if the field is blank
//-------------------------------------

function bIsValidWeatherTypeName(sWeatherTypeName){
	if (sWeatherTypeName == "") {
			alert("\nThe Weather Type Name field is required.\n\nPlease enter the weather type name.")
			return false;
		}
	return true;
}


//-------------------------------------
//Function:     bIsValidContestName(sContestName)
//check to see if the field is blank
//-------------------------------------

function bIsValidContestName(sContestName){
	if (sContestName == "") {
			alert("\nThe Contest Name field is required.\n\nPlease enter the contest name.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsValidWeatherIcon(sWeatherIcon)
//-------------------------------------

function  bIsValidWeatherIcon(sWeatherIcon){
	if (sWeatherIcon == "") {
			alert("\nThe Weather Icon field is required.\n\nPlease submit the weather icon image by clicking on Browse button.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:    bIsValidBannerName(sBannerName)
//-------------------------------------

function  bIsValidBannerName(sBannerName){
	if (sBannerName == "") {
			alert("\nThe Banner Name field is required.\n\nPlease submit the banner name.")
			return false;
		}
	return true;
}



//-------------------------------------
//Function:    bIsValidBannerData(sBannerData)
//-------------------------------------

function  bIsValidBannerData(sBannerData){
	if (sBannerData == "") {
			alert("\nPlease submit a banner file by clicking on Browse button.\n\nThe Banner File field is required.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:    bIsValidBannerURL(sBannerURL)
//-------------------------------------

function  bIsValidBannerURL(sBannerURL){
	//alert(sBannerURL)
	if (sBannerURL == "") {
			alert("\nThe Banner URL address is required.  Please enter a valid URL address for the banner.")
			return false;
		}
	return true;
}


//-------------------------------------
//Function:   bIsValidAlbumName(sAlbumName)
//-------------------------------------

function  bIsValidAlbumName(sAlbumName){
	if (sAlbumName == "") {
			alert("\nThe Album Name field is required.\n\nPlease enter the album name.")
			return false;
		}
	return true;
}


//-------------------------------------
//Function:   bIsValidAppearanceTitle(sAppearanceTitle)
//-------------------------------------

function  bIsValidAppearanceTitle(sAppearanceTitle){
	if (sAppearanceTitle == "") {
			alert("\nThe Appearance Title field is required.\n\nPlease enter the appearance title.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:   bIsValidConcertName(sConcertName)
//-------------------------------------

function  bIsValidConcertName(sConcertName){
	if (sConcertName == "") {
			alert("\nThe Concert Name field is required.\n\nPlease enter the concert name.")
			return false;
		}
	return true;
}

//-------------------------------------
//Function:     bIsDayTimeSelected(form)
//-------------------------------------
function  bIsDayTimeSelected(form){
	var found = false;
	//var bOvernightfound = false;
	
	for (i=0;i<form.rbDayWeatherTypeID.length;i++) {
		if (form.rbDayWeatherTypeID[i].checked) {
			found = true;
			break;
		}
	}
	if (!found) {
		alert('You must select one Daytime weather selections. This is a required field.');
		return false;
	}
	
	return true;
}
//-------------------------------------
//Function:     bIsOvernighteSelected(form)
//-------------------------------------
function bIsOvernighteSelected(form){
	var found = false;
		
	for (i=0;i<form.rbNightWeatherTypeID.length;i++) {
		if (form.rbNightWeatherTypeID[i].checked) {
			found = true;
			break;
		}
	}
	if (!found) {
		alert('You must select one Overnight weather selections. This is a required field.');
		return false;
	}
	
	return true;
}


//-------------------------------------
//Function:     bIsSongRequestValid(form)
//-------------------------------------

function  bIsSongRequestValid(form){
	if (form.cbSongRequest) {
		if (form.cbSongRequest.length != null) {
			for (i=0;i<form.cbSongRequest.length;i++) {
				if (form.cbSongRequest[i].checked) {
					return true;
				}
			}
		} else {
			if (form.cbSongRequest.checked) {
				return true;
			}
		}
	}
	
	if (form.cbSongNotFound.checked) {
		return true;
	}
	
	alert('You must put a checkmark beside the track you wish to request or you need to check the "Did not find my song in the search" checkbox before submitting');
	
	return false;
}


//-------------------------------------
//Function:    bIsValidLength(iLength,iMaxChar)
//-------------------------------------

function bIsValidLength(iLength,iMaxChar){
		
    if (iLength > iMaxChar) {
        diff= iLength - iMaxChar;
        if (diff>=1)
          diff = diff + " characters";
                    
        alert("Show Description field is limited to " + iMaxChar + " characters (with spaces)\n" + "Please reduce the text by " + diff);
				return (false);
   }

	return true;
}

//-------------------------------------
//Function:     bIsDate(sDate)
//check to see if the field is blank
//-------------------------------------

function bIsDate(sDate){
	if (sDate == "") {
		return false;
		}
	return true;
}

//------------------------------------
//Function:     checktime
//------------------------------------

function bIsTime(timeV) {
	var textTime = timeV; 
	var timeExpression = /^([1][0]|[0][1-9]|[1][1-2]|[1-9]):([0-5]\d|\d)$/;
	var valresult = textTime.match(timeExpression);
	
	if (valresult==null) {
	  //alert("Time entry in this field is invalid. Please enter a valid time in hh:mm or h:mm format (e.g. 08:00, 8:00)");
		return false;
}
return true;
}

//------------------------------------
//Function:     bIsEmail(sEmail)
//------------------------------------

function bIsValidEmail(sEmail){
	
	//It allows for everything from ipaddress and country-code domains, to very rare characters in the username. 
		
	var emailPat = /^^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

	var matchArray = sEmail.match(emailPat);
	
	if (matchArray == null) {
		alert("Your email address seems incorrect.  Please try again (check the '@' and '.'s in the email address)");
		return false;
	}

	// make sure the IP address domain is valid
	
	var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (IPArray != null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!")
				return false;
			}
		}
	}

return true;
}

//------------------------------------
//Function:     textCounter(field, countfield, maxlimit)
//------------------------------------
function textCounter(field, countfield, maxlimit) {
		 if (field.value.length > maxlimit) // if too long...trim it!
		 		 field.value = field.value.substring(0, maxlimit);
		 else
		 		 countfield.value = maxlimit - field.value.length;
}

//------------------------------------
//Function:     compareStartEndDate(sStartDate, sEndDate)
//------------------------------------
function compareStartEndDate(sStartDate, sEndDate){
	var sStartDate = new Date(sStartDate)
	var sEndDate   = new Date(sEndDate)
	
	var valueStartDate = sStartDate.valueOf()
	var valueEndDate   = sEndDate.valueOf()
	
	//--EndDate must be greater than StartDate
	if (parseInt(valueStartDate) > parseInt(valueEndDate)){
		return false;
	}	
}

//------------------------------------
//Function:     compareStartEndDateTime(sStartDate, sEndDate)
//Compare end time and start time:
//if start date = end date then end time must be greater than start time
//------------------------------------

function compareStartEndDateTime(sStartDate, sEndDate, sStartTime, sEndTime, sStartAMPM, sEndAMPM){
	
	var sStartDate = new Date(sStartDate)
	var sEndDate   = new Date(sEndDate)
	
	var valueStartDate = sStartDate.valueOf()
	var valueEndDate   = sEndDate.valueOf()
	
	//--EndDate must be greater than StartDate
	if (parseInt(valueStartDate) > parseInt(valueEndDate)){
		alert("\nPlease check the appearance end date field. It must be greater than OR equal to the appearance start date field.")
		return false;
	}	
	
	//--If EndDate = StartDate
	//--split hh and mm
	
	var sStartTimeColon = sStartTime.indexOf(":")
	var sStartHours     = sStartTime.slice(0,sStartTimeColon) 
	var sStartMins      = sStartTime.slice(sStartTimeColon+1)
	
	var sEndTimeColon   = sEndTime.indexOf(":")
	var sEndHours       = sEndTime.slice(0,sEndTimeColon)
	var sEndMins        = sEndTime.slice(sEndTimeColon+1)
	//alert(sStartHours);
	//alert(sStartAMPM);
	//alert(sEndHours);	
	//alert(sEndAMPM);
	//--check if hh in PM or AM
	if (sStartAMPM == "PM"){
		if (parseInt(sStartHours)!=12){
			sStartHours=parseInt(sStartHours) + 12;	
		}
	}
	
	if (sEndAMPM == "PM"){
		if (parseInt(sEndHours)!=12){
			sEndHours=parseInt(sEndHours) + 12;
	    }
	}	
	
	if (sStartAMPM == "AM"){
		if (parseInt(sStartHours)==12){
			
			sStartHours=parseInt(sStartHours) - 12;	
			
		}
	}
	
	if (sEndAMPM == "AM"){
		if (parseInt(sEndHours)==12){
			sEndHours=parseInt(sEndHours) - 12;
		}
	}
	//alert(sStartHours);
	//alert(sEndHours);
	if (valueStartDate == valueEndDate){
		var totalStartTimeMins = (parseInt(sStartHours)*60) + parseInt(sStartMins);
		//alert(totalStartTimeMins);		
		var totalEndTimeMins = (parseInt(sEndHours)*60) + parseInt(sEndMins);
		//alert(totalEndTimeMins);	
		if (parseInt(totalEndTimeMins) <= parseInt(totalStartTimeMins)){
			alert("\nYour appearance end date is the same with the appearance start date.\nThe appearance end time must be greater than the appearance start date.")
			return false;
		}
	}


}

//-------------------------------------
//Function:     bIsNumeric(string)
//-------------------------------------

function bIsNumeric(string){
	if (string.length != 0){    
			if (string>0){
				return true;}
		}
	
 return false;
}


function LostPasswordBodyValidate(form) {
// checks if the e-mail address is valid

	var sEmail 
	var bValidEmail
	var bValidLogin

	sEmail      = form.LoginEmailAddress.value
	bValidLogin = true
	
	bValidEmail = bIsValidEmail(sEmail)
		if (bValidEmail == false){
			form.LoginEmailAddress.select()
			form.LoginEmailAddress.focus()
			bValidLogin = false
			return bValidLogin
			
		}
		
	return bValidLogin

}


function textCounter(field) {
	//if (field.value.length > 7999) // if too long...trim it!
	if (field.value.length > 6700) // if too long...trim it!
		window.alert("You have surpassed the maximum number of characters for this Text Area. \n Please edit your entry.")
		field.value = field.value.substring(0, 6700);
// otherwise, update 'characters left' counter
}

//-----------------------end body
//-->
