function validatePhone(number) {
/*	new version by Laurence 2004 Nov 26
	RegExp is a Javascript1.2 feature; tested successfully in WinIE 5.0+, MacIE 5.1, Safari 1.0, WinNN 4.7, WinNN 6.2, WinMoz 1.7
	The pattern matches groups of 3, 3 and 4 digits found in that order anywhere in the string.
*/
	var myRegExp = /(\d{3}).*(\d{3}).*(\d{4})/;	
	var sPos = number.search(myRegExp);
	if ( sPos >= 0 ) {
	//	number = "(" + RegExp.$1 + ")" + RegExp.$2 + "-" + RegExp.$3; this would format as (000)000-0000
		return true;
	} else {
		return false;
	}
}

function validateInternationalPhone(number) {
/*	by Laurence 2005 Apr 29
	similar to validatePhone(), above
	The pattern matches a total of 10 digits found anywhere in the string; it's better than nothing...
*/
	var myRegExp = /(\d.*){9,}\d/;
	var sPos = number.search(myRegExp);
	if ( sPos >= 0 ) {
		return true;
	} else {
		return false;
	}
}

function validateEmail(email) {
/*	new version by Laurence 2004 Nov 26
	revised 2005 Nov 04 by Laurence: allow hyphens before @ symbol; rename 'verifyEmail' to 'validateEmail'

	RegExp is a Javascript1.2 feature; tested successfully in WinIE 5.0+, MacIE 5.1, Safari 1.0, WinNN 4.7, WinNN 6.2, WinMoz 1.7
	The pattern matches: 
	- at least one word character ( a-zA-Z0-9_ )
	- followed by any number more including periods and hyphens
	- then a single @
	- then at least one alphanumeric character plus any number more including hyphens and periods
	- plus an ending of an alphanumeric char, a single period, and at least 2 more letters. 
	There can be nothing before or after the pattern; all whitespace, punctuation, etc. not explicitly allowed is forbidden.
*/
	var myRegExp = /^[\w][\w\.\-]*@[a-zA-Z0-9]+[\w\.\-]*[a-zA-Z0-9]\.[a-zA-Z]{2,}$/;
	var sPos = email.search(myRegExp);
	if (sPos >= 0) {
		return true;
	} else {
		return false;
	}
}


function validateDate(theValue){
	var strMask = "mm/dd/yyyy";
	var iMaskMonth = strMask.lastIndexOf("m") - strMask.indexOf("m") + 1;
	var iMaskDay = strMask.lastIndexOf("d") - strMask.indexOf("d") + 1;
	var iMaskYear = strMask.lastIndexOf("y") - strMask.indexOf("y") + 1;
	var errorMessage = "";
	
	var strDate = theValue;

	
	// find the delimiter
	var delim = "", lstMask = "mdy";
	for( var i=0; i < strMask.length; i++ ){
		if (lstMask.indexOf(strMask.substring(i, i+1)) == -1){
			delim = strMask.substring(i, i+1);
			break;
		}
  }
  

  
	aMask = strMask.split(delim);
	

	if( aMask.length == 3 ){
		dt = strDate.split(delim);
				
		if( dt.length != 3 ) errorMessage = "An invalid date was provided.";
		
		//alert(errorMessage);
		
		for( i=0; i < aMask.length; i++ ){
			if( aMask[i].indexOf("m") > -1 ) var sMonth = dt[i];
			else if( aMask[i].indexOf("d") > -1 ) var sDay = dt[i];
			else if( aMask[i].indexOf("y") > -1 ) var sYear = dt[i];
		}
	} else if( mask.length == 1 ){
		var sMonth = strDate.substring(strMask.indexOf("m")-1, strMask.lastIndexOf("m"));
		var sDay = strDate.substring(strMask.indexOf("d")-1, strMask.lastIndexOf("d"));
		var sYear = strDate.substring(strMask.indexOf("y")-1, strMask.lastIndexOf("y"));
	} else {
		errorMessage = "An invalid date mask was provided.";
	}

	var iMonth = parseInt(sMonth, 10);
	var iDay = parseInt(sDay, 10);
	var iYear = parseInt(sYear, 10);

  
	
	if( isNaN(iMonth) || sMonth.length > iMaskMonth ) iMonth = 0;
	if( isNaN(iDay) || sDay.length > iMaskDay ) iDay = 0;
	if( isNaN(sYear) || sYear.length != iMaskYear ) sYear = null;


	
	lst30dayMonths = ",4,6,9,11,";

	// if there are no other errors, check for input errors
	if( errorMessage.length == 0 ){
		if( sYear == null ){
			errorMessage = "An invalid year was provided. The year \n   should be a " + iMaskYear + " digit number.";
		} else if(  (iMonth < 1) || (iMonth > 12 ) ){
			errorMessage = "An invalid month was provided.";
		} else {
			if( iYear < 100 ) var iYear = iYear + ((iYear > 20) ? 1900 : 2000);
			var iYear = (sYear.length == 4) ? parseInt(sYear, 10) : parseInt("20" + sYear, 10);
			if( lst30dayMonths.indexOf("," + iMonth + ",") > -1 ){
				if( (iDay < 1) || (iDay > 30 ) ) errorMessage = "An invalid day was provided.";
			} else if( iMonth == 2 ){
				if( (iDay < 1) || (iDay > 28 && !( (iDay == 29) && (iYear%4 == 0 ) ) ) ) errorMessage = "An invalid day was provided.";
			} else {
				if( (iDay < 1) || (iDay > 31 ) ) errorMessage = "An invalid day was provided.";
			}
		}
	}	
	
	if(errorMessage != ""){
		return false;
	}
	else{
		return true;
	}
}

function validateFormat(theValue,mask,type){
	var mask = _param(arguments[1]);
	var type = _param(arguments[2], "numeric").toLowerCase();
	var strErrorMsg = "";
	var errorMessage = "";

	var strMaskLC = mask.toLowerCase();
		
	var description = "";


	var string = _stripInvalidChars(theValue, type);
	var masklen = _stripInvalidChars(mask, "x").length;

	// check to make sure the string contains the correct number of characters
	if( string.length != masklen && theValue.length > 0){
		if( strErrorMsg.length == 0 ) strErrorMsg = "The "+description+" field requires at least " + masklen + " valid characters. Please \nmake sure to enter the value in the format: \n   " + mask + "\n(where 'x' is a valid "+type+" character.)";
		errorMessage = strErrorMsg;

	// else re-format the string as defined by the mask
	} else if( string.length == masklen ){
		// find the position of all non "X" characters
		var stcMask = new Object();
		var lc = mask.toLowerCase();
		// loop through the string an make sure each character is an valid character
		for( var i=0; i < mask.length; i++ ){
			if( lc.charAt(i) != "x" ) stcMask[i] = mask.charAt(i);
	  }

	  	
		// put all the non-"X" characters back into the parsed string
		var iLastChar = 0;
		var newString = "";
		var i = 0;
		for( var pos in stcMask ){
			pos = parseInt(pos, 10);
			if( pos > iLastChar ){
				newString += string.substring(iLastChar, pos-i) + stcMask[pos];
				iLastChar = pos-i;
			} else {
				newString += stcMask[pos];
			}
			i++;
		}
		if( i == 0 ){
			newString = string;
		} else {
			newString += string.substring(iLastChar);
		}
		
		// set the value of the field to the new string--make sure not to perform the onBlur event
		//this.setValue(newString, true, false);
	}
	
	if(errorMessage != ""){
		return false;
	}
	else{
		return true;
	}
}


// define the _param(value, default, type) function
function _param(v, d, t){
	// if no default value is present, use an empty string
	if( typeof d == "undefined" ) d = "";
	// if no type value is present, use "string"
	if( typeof t == "undefined" ) t = "string";
	// if datatype should be a number and it's a string, convert it to a number
	if( t == "number" && typeof v == "string" ) var v = parseFloat(arguments[0]);
	// get the value to return, if the v param is not equal to the type, use default value
	var value = (typeof v != "undefined" && typeof v == t.toLowerCase()) ? v : d;
	return value;
}


function _stripInvalidChars(string, type){
	var string = _param(arguments[0]);
	var type = _param(arguments[1], "numeric").toLowerCase();
	var validchars = type;

	stcTypes = new Object();
	stcTypes.numeric = "1234567890";
	stcTypes.alpha = "abcdefghijklmnopqrstuvwxyz";
	stcTypes.alphnumeric = "abcdefghijklmnopqrstuvwxyz1234567890";

	if( stcTypes[type] ) validchars = stcTypes[type];

	var tmp = "";
	var lc = string.toLowerCase();
	// loop through the string an make sure each character is an alpha character
	for( var i=0;i < string.length;i++ ){
		if (validchars.indexOf(lc.charAt(i)) != -1) tmp += string.charAt(i);
  }
	return tmp;
}

function isCurrency(txtValue) {
  isValidCurrency = RegExp(/^[0-9\,]+(\.\d{2})?$/).test(String(txtValue).replace(/^\s+|\s+$/g, ""));
  return isValidCurrency;
}

function confirmSubmit()
{
var agree=confirm("Are you sure you wish to delete this record?");
if (agree)
	return true ;
else
	return false ;
}



function chkdate(objName) {
var strDatestyle = "US"; //United States date style (the dame as the canadian date format)
//var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
//strDate = datefield.value;
strDate = datefield
//alert(strDate);
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}
else {
datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

/* used in view/admin/add , view/admin/edit
	check that required fields are filled in
*/
function validateLogin() {
	var theForm = document.frmLogin;
	var emptyFields = "";

	if (theForm.username.value == ""){
		emptyFields += "The username cannot be blank." + "\n" ;
	} 
	
	 if (theForm.password.value == ""){
		emptyFields += "The password cannot be blank." + "\n" ;
	} 
	
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		theForm.submit();
		return true;
	}
}

function validateSearch(thisForm) {
	var theForm = document.frmSearch;
	var emptyFields = "";
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		theForm.submit();
		return true;
	}
}

function validateCustomer(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";

	if (theForm.firstName.value == ""){
		emptyFields += "The First Name cannot be blank." + "\n" ;
	} 
	
	 if (theForm.lastName.value == ""){
		emptyFields += "The Last Name cannot be blank." + "\n" ;
	} 
	
	 if (theForm.emailAddress.value == ""){
		emptyFields += "The Email Address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddress.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	 if (theForm.password.value == ""){
		emptyFields += "The Password cannot be blank." + "\n" ;
	} 
	
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}


function validateLibrary(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";

	if (theForm.itemCode.value == ""){
		emptyFields += "The Item Code cannot be blank." + "\n" ;
	} 
	
	 if (theForm.name.value == ""){
		emptyFields += "The Library name cannot be blank." + "\n" ;
	} 
	
	if (theForm.shortDescription.value == ""){
		emptyFields += "The Short Description cannot be blank." + "\n" ;
	} else if (theForm.shortDescription.value.length > 200) {
		emptyFields += "The Short Description cannot exceed 200 characters." + "\n" ;
	}
	
	if (theForm.longDescription.value == ""){
		emptyFields += "The Long Description cannot be blank." + "\n" ;
	} else if (theForm.longDescription.value.length > 1000) {
		emptyFields += "The Short Description cannot exceed 1000 characters." + "\n" ;
	}
	
	if (theForm.price.value == ""){
		emptyFields += "The Price cannot be blank." + "\n" ;
	} 
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}


function validateOrder1(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";

	
	 if (theForm.emailAddress.value == ""){
		emptyFields += "The Email Address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddress.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateOrder2(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";

	
	 if (!(thisForm.libraries.checked) && !(thisForm.collections.checked) && !(thisForm.tracks.checked)) {
		emptyFields += "You must check at least one type of item to continue." + "\n" ;
	} 
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateCollection(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";

	if (theForm.itemCode.value == ""){
		emptyFields += "The Item Code cannot be blank." + "\n" ;
	} 
	
	 if (theForm.name.value == ""){
		emptyFields += "The Collection name cannot be blank." + "\n" ;
	} 
	 
	 if(theForm.libraryId.value == ""){
		 emptyFields += "You must select a library that this collection belongs to." + "\n" ;
	 }
	
	if (theForm.longDescription.value == ""){
		emptyFields += "The Long Description cannot be blank." + "\n" ;
	} else if (theForm.longDescription.value.length > 1000) {
		emptyFields += "The Short Description cannot exceed 1000 characters." + "\n" ;
	}
	
	if (theForm.price.value == ""){
		emptyFields += "The Price cannot be blank." + "\n" ;
	} 
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateTrack(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";

	if (theForm.itemCode.value == ""){
		emptyFields += "The Item Code cannot be blank." + "\n" ;
	} 
	
	 if (theForm.name.value == ""){
		emptyFields += "The Track name cannot be blank." + "\n" ;
	} 
	 
	 if(theForm.popularity.value == ""){
		 emptyFields += "The popularity cannot be blank." + "\n" ;
	 }
	 
	 if (theForm.shortDescription.value == ""){
		emptyFields += "The Short Description cannot be blank." + "\n" ;
	} else if (theForm.shortDescription.value.length > 200) {
		emptyFields += "The Short Description cannot exceed 200 characters." + "\n" ;
	}
	
	if (theForm.longDescription.value == ""){
		emptyFields += "The Long Description cannot be blank." + "\n" ;
	} else if (theForm.longDescription.value.length > 1000) {
		emptyFields += "The Short Description cannot exceed 1000 characters." + "\n" ;
	}
	
	if (theForm.trackLength.value == ""){
		emptyFields += "The Track Length cannot be blank." + "\n" ;
	} 
	
	if (theForm.price.value == ""){
		emptyFields += "The Price cannot be blank." + "\n" ;
	}
	
	if (theForm.collectionId.value == ""){
		emptyFields += "You must select at least one COLLECTION this track belongs to." + "\n" ;
	} 
	
	if (theForm.composerId.value == ""){
		emptyFields += "You must select at least one COMPOSER for this track." + "\n" ;
	} 
	
	if (theForm.genreId.value == ""){
		emptyFields += "You must select at least one GENRE for this track." + "\n" ;
	} 
	
	if (theForm.moodId.value == ""){
		emptyFields += "You must select at least one MOOD for this track." + "\n" ;
	} 
	
	if (theForm.instrumentId.value == ""){
		emptyFields += "You must select at least one INSTRUMENT for this track." + "\n" ;
	}
	
	if (theForm.fkTempoId.value == ""){
		emptyFields += "You must select a TEMPO for this track." + "\n" ;
	}
	
	if (theForm.fkVocalId.value == ""){
		emptyFields += "You must select a VOCAL for this track." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateFeatures(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	if ((theForm.libraryId.value == "") && (theForm.collectionId.value == "")) {
		emptyFields += "You must select either a library OR a collection for the main feature." + "\n" ;
	}
	
	if ((theForm.libraryId1.value == "") && (theForm.collectionId1.value == "")) {
		emptyFields += "You must select either a library OR a collection for sub feature 1." + "\n" ;
	}
	
	if ((theForm.libraryId2.value == "") && (theForm.collectionId2.value == "")) {
		emptyFields += "You must select either a library OR a collection for sub feature 2." + "\n" ;
	}
	
	if ((theForm.libraryId.value != "") && (theForm.collectionId.value != "")) {
		emptyFields += "You must select either a library OR a collection for the main feature." + "\n" ;
	}
	
	if ((theForm.libraryId1.value != "") && (theForm.collectionId1.value != "")) {
		emptyFields += "You must select either a library OR a collection for sub feature 1." + "\n" ;
	}
	
	if ((theForm.libraryId2.value != "") && (theForm.collectionId2.value != "")) {
		emptyFields += "You must select either a library OR a collection for sub feature 2." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateComposer(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	if (theForm.firstName.value == ""){
		emptyFields += "The first name cannot be blank." + "\n" ;
	}
	
	if (theForm.lastName.value == ""){
		emptyFields += "The last name cannot be blank." + "\n" ;
	}
	
	if (theForm.emailAddress.value == ""){
		emptyFields += "The email address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddress.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	if (theForm.password.value == ""){
		emptyFields += "The password cannot be blank." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateCategories(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	var isChecked = false;
	
   for (i=0; i<theForm.categoryId.length; i++){
	if (theForm.categoryId[i].checked==true)
		isChecked = true;
	}
	
	if (isChecked == false) {
		alert("Please check at least one category" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
	
}

function validateRegister(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	if (theForm.firstName.value == ""){
		emptyFields += "The first name cannot be blank." + "\n" ;
	}
	
	if (theForm.lastName.value == ""){
		emptyFields += "The last name cannot be blank." + "\n" ;
	}
	
	if (theForm.emailAddress.value == ""){
		emptyFields += "The email address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddress.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	if (theForm.emailAddressConfirm.value == ""){
		emptyFields += "The email address confirmation cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddressConfirm.value)) {
		emptyFields += "The email address confirmation must be correctly formatted." + "\n" ;
	}
	
	if (theForm.emailAddress.value != theForm.emailAddressConfirm.value) {
		emptyFields += "The email address and the confirmation email address must be the same." + "\n" ;
	}
	
	if (theForm.password.value == ""){
		emptyFields += "The password cannot be blank." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateLogin(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	if (theForm.emailAddress.value == ""){
		emptyFields += "The email address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddress.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	if (theForm.password.value == ""){
		emptyFields += "The password cannot be blank." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validatePassword(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	if (theForm.emailAddress.value == ""){
		emptyFields += "The email address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddress.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}


function validateProfile(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	if (theForm.firstName.value == ""){
		emptyFields += "The first name cannot be blank." + "\n" ;
	}
	
	if (theForm.lastName.value == ""){
		emptyFields += "The last name cannot be blank." + "\n" ;
	}
	
	if (theForm.emailAddress.value == ""){
		emptyFields += "The email address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddress.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	if (theForm.emailAddressConfirm.value == ""){
		emptyFields += "The email address confirmation cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddressConfirm.value)) {
		emptyFields += "The email address confirmation must be correctly formatted." + "\n" ;
	}
	
	if (theForm.emailAddress.value != theForm.emailAddressConfirm.value) {
		emptyFields += "The email address and the confirmation email address must be the same." + "\n" ;
	}
	
	if (theForm.password.value == ""){
		emptyFields += "The password cannot be blank." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateCuesheetItem(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	if (theForm.track_name.value == ""){
		emptyFields += "The Track Name cannot be blank." + "\n" ;
	}
	else{
		if (theForm.trackID.value == ""){
			emptyFields += "Not a valid Track Name." + "\n" ;
		}		
	}
	
	if (theForm.item_duration.value == ""){
		emptyFields += "The Timing/Duration of Use cannot be blank." + "\n" ;
	}
	else{
		if(!validateFormat(theForm.item_duration.value,'xx:xx') && !validateFormat(theForm.item_duration.value,'xxx:xx')){
			emptyFields += "The Timing/Duration must be in the format mm:ss." + "\n" ;
		}		
	}

	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}	
	
}	

function validateCuesheet(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	if (theForm.CuesheetProgramTitle.value == ""){
		emptyFields += "The Project/Program Title cannot be blank." + "\n" ;
	}
	
	if (theForm.CuesheetEstimatedAirDate.value != ""){
		
		if(!validateDate(theForm.CuesheetEstimatedAirDate.value)){
			emptyFields += "Estimated Air Date must be in the format mm/dd/yyyy." + "\n" ;
		}
	}
	
	if (theForm.CuesheetProgramLength.value != ""){		
		if(!validateFormat(theForm.CuesheetProgramLength.value,'xxx:xx') && !validateFormat(theForm.CuesheetProgramLength.value,'xx:xx')){
			emptyFields += "Program Length must be in the format mm:ss." + "\n" ;
		}
	}
	
	if(theForm.cuesheetItemCount.value == 0){
		emptyFields += "You must speficy at least one cuesheet item." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}	
	
}	

function verifyTerms() {
	if(document.getElementById("chkTerms").checked == false){
		alert("You must agree to the terms before proceeding.");
		return false;
	} else {
		return true;	
	}
}

function validateCustomMusic(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	var flag = 0;
	
	if (theForm.FullName.value == ""){
		emptyFields += "The Full Name cannot be blank." + "\n" ;
	}
	
	if (theForm.Email.value == ""){
		emptyFields += "The email address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.Email.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	
	
	for (var i = 0; i< 12; i++) {
	if(theForm.usage[i].checked){ 
	flag = 1;
	}
	}
	if (flag != 1) {
	emptyFields += "You must check at least one usage." + "\n" ;
	}

	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateExtendedLicensing(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";

	
	if (theForm.FullName.value == ""){
		emptyFields += "The Full Name cannot be blank." + "\n" ;
	}
	
	if ((theForm.trackNum.value == "") && (theForm.collectionID.value == "")) {
		emptyFields += "You must select a collection OR enter the number of tracks required." + "\n" ;
	}
	
	if (theForm.Email.value == ""){
		emptyFields += "The email address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.Email.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	

		
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function getKeys(value1)
	{
		var theForm = document.frmSearch;
		var rightKeyword = value1;
		//alert(value1);
		theForm.keywords.value = rightKeyword;
		theForm.submit();
	}

