codeminlength = 5
codemaxlength = 12
titleminlength = 5
titlemaxlength = 150
errorMessage="";
//=========================================================================================================

function checkDeliveryEditForm(form){
	form.contentCode.value = trim(form.contentCode.value)
	form.contentTitle.value = trim(form.contentTitle.value)
	var code = form.contentCode.value
	var title = form.contentTitle.value
	var year = form.contentYear.selectedIndex
	var categoryid = form.categoryid
	var summary = trim(form.contentSummary.value)
	var filecontents = form.filecontents.value
	var updatecontentdate = form.updatecontentdate.selectedIndex
	
	// Check the code field
	if (!isAlphaNumeric(code)){
		alert("The Code must contain letters and numbers only.")
		return false
	}
	if (code.length<codeminlength || code.length>codemaxlength){
		alert("The Code must be between "+codeminlength+" and "+codemaxlength+" characters long.")
		return false
	}
	
	// Check the title field
	if (invalidTitle(title)){
		alert("The Title must contain letters,numbers,spaces and any of '&()_-',' only.")
		return false
	}
	if (title.length<titleminlength || title.length>titlemaxlength){
		alert("The Title must be between "+titleminlength+" and "+titlemaxlength+" characters long.")
		return false
	}
	
	// Check the TPIP year
	if(year==0){
		alert("Please choose the Year of completion.")
		return false
	}
	
	// Check the category
	var cnt=-1
	for (var i=categoryid.length-1; i > -1; i--) {
	   if (categoryid[i].checked) {cnt = i; i = -1;}
	}
   	if(cnt==-1){
		alert("Please choose a Category.")
		return false
	}
	
	// Check the summary
	if (summary.length<1){
		alert("Please enter a Summary.")
		return false
	}
	
	// Check the filecontents
	if(filecontents!=""){
		var fileext;
		filename = getFilenameFromPath(filecontents);
		fileext = getExtensionFromFilename(filename)
	
		if (!validateGlobalFileExtension(fileext)){
			alert("Please ensure that the file you are trying to upload is an Acrobat PDF, Word, Excel, Powerpoint document or a Zip file.")
			return false
		}
	
	}
	
	if (updatecontentdate==0){
		alert("Please choose the Upload date.")
		return false
	}
	
	return true
	
}

function checkCurriculumEditForm(form){
	var courseName = trim(form.courseName.value)
	//var stateCode = trim(form.stateCode.value)
//	var nationalCode = trim(form.nationalCode.value)
	var summary = trim(form.summary.value)
	var filecontents = form.filecontents.value
	var filecontents2 = form.filecontents2.value
	var superseed = form.filerarchive.checked 
	var filesToUpload = 0;
	
	// Check the title field
	if (invalidTitle(courseName)){
		alert("The Course title must contain letters,numbers,spaces and any of '&()_-',' only.")
		return false
	}
	if (courseName.length<titleminlength || courseName.length>titlemaxlength){
		alert("The Course title must be between "+titleminlength+" and "+titlemaxlength+" characters long.")
		return false
	}
	
	// Check the code field
	/*if (!isAlphaNumeric(stateCode)){
		alert("The State code must contain letters and numbers only.")
		return false
	}
	if (stateCode.length<4){
		alert("The State code must be at least 4 characters long.")
		return false
	}*/
	/*if (stateCode.length<codeminlength || stateCode.length>codemaxlength){
		alert("The Code must be between "+codeminlength+" and "+codemaxlength+" characters long.")
		return false
	}*/
	
	// Check the code field
	/*if (!isAlphaNumeric(nationalCode)){
		alert("The National code must contain letters and numbers only.")
		return false
	}
	if (nationalCode.length<4){
		alert("The National code must be at least 4 characters long.")
		return false
	}*/
	/*if (nationalCode.length<codeminlength || nationalCode.length>codemaxlength){
		alert("The Code must be between "+codeminlength+" and "+codemaxlength+" characters long.")
		return false
	}*/
	
	// Check the summary
	if (summary.length<1){
		alert("Please enter a Summary.")
		return false
	}
	
	if(superseed){
		if(filecontents!=""){
		}else{
		alert("Please select an executive summary file to upload.")
		return false
		}
	}
	// Check the filecontents
	if(filecontents!=""){
		var fileext;
		filename = getFilenameFromPath(filecontents);
		fileext = getExtensionFromFilename(filename)
		
		if (fileext == "pdf" ){
			filesToUpload = filesToUpload+1;
		}
		else{
			alert("Please ensure that the Executive summary file you are trying to upload is an Acrobat PDF file. XXX")
			return false
		}
	
	}
	
	// Check the filecontents
	if(filecontents2!=""){
		var fileext;
		filename = getFilenameFromPath(filecontents2);
		fileext = getExtensionFromFilename(filename);
			//if (fileext == "pdf" || fileext == "zip"){
		if (fileext == "pdf" || fileext == "zip" ){
			filesToUpload =filesToUpload+1
		}
		else{
			alert("Please ensure that the Curriculum file you are trying to upload is an Acrobat PDF.")
			return false
		}
	
	}
	form.filesToUpload.value = filesToUpload;
	return true
}
function checkCurriclumFinishUpdate(form){
	
	var filecontents = form.execSummaryFile.value
	var filecontents2 = form.curriculumFile.value
	var superseed = form.filerarchive.checked 
	var filesToUpload = 0;
	var sType = form.specialType.value
	var uType = form.updateType.value
	
	if(superseed){
			if(filecontents!=""){
			}else{
				alert("Please select an executive summary file to upload.")
				return false
			}
	}
	// Check the filecontents
	if(filecontents!=""){
			var fileext;
			filename = getFilenameFromPath(filecontents);
			fileext = getExtensionFromFilename(filename);
		
			if (fileext == "pdf" ){
				filesToUpload = filesToUpload+1;
			}
			else{
				alert("Please ensure that the Executive summary file you are trying to upload is an Acrobat PDF file.")
				return false
			}
	
	}else{
				msg ="Please select an Executive summary file to upload."
	}
	
	// Check the filecontents
	if(filecontents2!=""){
		var fileext;
		filename = getFilenameFromPath(filecontents2);
		fileext = getExtensionFromFilename(filename);
			//if (fileext == "pdf" || fileext == "zip"){
		if (fileext == "pdf" || fileext == "zip" ){
			filesToUpload =filesToUpload+1
		}
		else{
			alert("Please ensure that the Curriculum file you are trying to upload is an Acrobat PDF.")
			return false
		}
	
	}	else{
		msg ="Please select a Curriculum file to upload.."
	}
	
	if( sType ==uType && filesToUpload == 0){
		alert("Please select an Executive summary file and a Curriculum file to upload");
		return false
	}
	if( sType ==uType && filesToUpload !=2){
		alert(msg);
		return false
	}
		if( sType !=uType && filesToUpload < 1){
		alert("Please select a file to upload.");
		return false
	}
	form.filesToUpload.value = filesToUpload;
	return true
}

function checkCurriculumCreateShell(form){
	var courseName = trim(form.courseName.value)
	var nationalCode = trim(form.nationalCode.value)
	var cmmareaID = trim(form.cmmareaID.value)
	
		if (cmmareaID == 0){
		alert("Please select a Curriculum Maintenance Manager.")
		return false
	}
	
	// Check the title field
	if (invalidTitle(courseName)){
		alert("The Course title must contain letters,numbers,spaces and any of '&()_-',' only.")
		return false
	}
	if (courseName.length<titleminlength || courseName.length>titlemaxlength){
		alert("The Course title must be between "+titleminlength+" and "+titlemaxlength+" characters long.")
		return false
	}
	
	// Check the code field
	if (!isAlphaNumeric(stateCode)){
		alert("The State code must contain letters and numbers only.")
		return false
	}
	if (stateCode.length<4){
		alert("The State code must be at least 4 characters long.")
		return false
	}

	// Check the code field
			if (!isAlphaNumeric(nationalCode)){
				alert("The National code must contain letters and numbers only.")
				return false
			}
			if (nationalCode.length<4){
				alert("The National code must be at least 4 characters long.")
				return false
			}
			
			return true
}
function checkCurriculumUpdate(form){
	var courseName = trim(form.courseName.value)
	var stateCode = trim(form.stateCode.value)
	/*var nationalCode = trim(form.nationalCode.value)
	var nationalCode = trim(form.nationalCode.value)*/
	var updateType = trim(form.updateType.value)
		if(updateType == 3){
			// Check the title field
			if (invalidTitle(courseName)){
				alert("The Course title must contain letters,numbers,spaces and any of '&()_-',' only.")
				return false
			}
			if (courseName.length<titleminlength || courseName.length>titlemaxlength){
				alert("The Course title must be between "+titleminlength+" and "+titlemaxlength+" characters long.")
				return false
			}
			
			// Check the code field
			if (!isAlphaNumeric(stateCode)){
				alert("The State code must contain letters and numbers only.")
				return false
			}
			if (stateCode.length<4){
				alert("The State code must be at least 4 characters long.")
				return false
			}
			
			// Check the code field
			/*if (!isAlphaNumeric(nationalCode)){
				alert("The National code must contain letters and numbers only.")
				return false
			}
			if (nationalCode.length<4){
				alert("The National code must be at least 4 characters long.")
				return false
			}*/
		}
 
	return true
}


function checkCurriculumAddForm(form){
	var courseName = trim(form.courseName.value)
	var stateCode = trim(form.stateCode.value)
	/*var nationalCode = trim(form.nationalCode.value)*/
	var summary = trim(form.summary.value)
	var filecontents = form.filecontents.value
	var filecontents2 = form.filecontents2.value
	
	// Check the title field
	if (invalidTitle(courseName)){
		alert("The Course title must contain letters,numbers,spaces and any of '&()_-',' only.")
		return false
	}
	if (courseName.length<titleminlength || courseName.length>titlemaxlength){
		alert("The Course title must be between "+titleminlength+" and "+titlemaxlength+" characters long.")
		return false
	}
	
	// Check the code field
	if (!isAlphaNumeric(stateCode)){
		alert("The State code must contain letters and numbers only.")
		return false
	}
	if (stateCode.length<4){
		alert("The State code must be at least 4 characters long.")
		return false
	}
	/*if (stateCode.length<codeminlength || stateCode.length>codemaxlength){
		alert("The Code must be between "+codeminlength+" and "+codemaxlength+" characters long.")
		return false
	}*/
	
	// Check the code field
	/*if (!isAlphaNumeric(nationalCode)){
		alert("The National code must contain letters and numbers only.")
		return false
	}
	if (nationalCode.length<4){
		alert("The National code must be at least 4 characters long.")
		return false
	}*/
	/*if (nationalCode.length<codeminlength || nationalCode.length>codemaxlength){
		alert("The Code must be between "+codeminlength+" and "+codemaxlength+" characters long.")
		return false
	}*/
	
	// Check the summary
	if (summary.length<1){
		alert("Please enter a Summary.")
		return false
	}
	
	// Check the filecontents
	if(filecontents!=""){
		var fileext;
		filename = getFilenameFromPath(filecontents);
		fileext = getExtensionFromFilename(filename)
		if (fileext == "pdf"){
			
		}
		else{
			alert("Please ensure that the Executive summary file you are trying to upload is an Acrobat PDF file.")
			return false
		}
	}else{
		alert("Please select an Executive summary file to upload.")
		return false
	}
	
	// Check the filecontents
	if(filecontents2!=""){
		var fileext;
		filename = getFilenameFromPath(filecontents2);
		fileext = getExtensionFromFilename(filename)
		
		if (fileext == "pdf" || fileext == "zip"){
			
		}
		else{
			alert("Please ensure that the Curriculum file you are trying to upload is an Acrobat PDF.")
			return false
		}
	}else{
		alert("Please select a Curriculum file to upload.")
		return false
	}
	return true
}

/**New Functionality 
 		Validation was reomoved of the following fields:
		 - form.contentCode
		 - form.contentTitle
		 - form.categoryid

*/
function checkTpResources_createShell(form){
	form.contentCode.value = trim(form.contentCode.value)
	form.contentTitle.value = trim(form.contentTitle.value)
	var code = form.contentCode.value
	var title = form.contentTitle.value
  var categoryid = form.categoryid
	var dDay = form.eventDay.value
	var dMonth = form.eventMonth.value
	var dYear = form.eventYear.value
	
	var pbDay = form.eventDay2.value
	var pbMonth = form.eventMonth2.value
	var pbYear = form.eventYear2.value
	
	//
	resetErrorMessage();
 	// Check the code field
	if(hasValue(code)) validateResourceCode(code);
	
	// Check the title field
	 validateTitle(title);
	
	// Check the category
	//For the Add form :  check if anything is selected first
	if(isSelectChecked(categoryid)) validateResourceCategory(categoryid);
	
	if(dDay <1 || dMonth <1 || dYear < 1){
			//alert("Please choose the due date.")
				//return false
			msg="Please choose the due date.";
		 setErrorMessage(msg);
	
	}
  if(pbDay < 1 || pbMonth < 1 || pbYear < 1){
			//alert("Please choose the Year of Project Brief Commissioned date.")
				//return false
				msg="Please choose the Year of Project Brief Commissioned date";
		 		setErrorMessage(msg);
	
	}
	if(hasValue(errorMessage)){
		 showErrorMessage(); 
		 return false;
	}
	
	return true
	
}





function checkTpResources_updateShell(form){
	form.contentCode.value = trim(form.contentCode.value)
	form.contentTitle.value = trim(form.contentTitle.value)
  form.summary.value = trim(form.summary.value)
	var code = form.contentCode.value
	var title = form.contentTitle.value
	var categoryid = form.categoryid
  var summary = trim(form.summary.value)
	
   //
	resetErrorMessage();
	
	// Check the code field
	validateResourceCode(code);
	
	// Check the title field
	validateTitle(title);
	
	// Check the category
  validateResourceCategory(categoryid);
	
	//Summary check
	var msg = "Please enter a Summary.";	
	validateTextContent(summary,msg);
	
		if(hasValue(errorMessage)){
		 showErrorMessage(); 
		 return false;
	}
		
	
	return true
	
}
function checkTpResources_finishUpdate(form){
				
	var year = form.contentYear.selectedIndex
	var filecontents = form.filecontents.value	
 	var updateType = trim(form.updateType.value)
var updatecontentdate ="";
		if(updateType == 1){
			 updatecontentdate = form.updatecontentdate.selectedIndex	
		}
	
	// Check the filecontents
	if(filecontents!=""){
		var fileext;
		filename = getFilenameFromPath(filecontents);
		fileext = getExtensionFromFilename(filename)
		
		if(!validateGlobalFileExtension(fileext)){
			alert("Please ensure that the file you are trying to upload is an Acrobat PDF, Word, Excel, Powerpoint document or a Zip file.")
			return false
		}
		
	}
	else{
			alert("Please select a file to upload.")
		return false
		}
		
	
		// Check the TPIP year
	if(year==0){
		alert("Please choose the Year of completion.")
		return false
	}
	
	if (updatecontentdate==0 && updateType == 1){
		alert("Please choose the Upload date.")
		return false
	}
	
	return true
	
}



function checkDeliveryAddForm(form){
	form.contentCode.value = trim(form.contentCode.value)
	form.contentTitle.value = trim(form.contentTitle.value)
	var code = form.contentCode.value
	var title = form.contentTitle.value
	var year = form.contentYear.selectedIndex
	var categoryid = form.categoryid
	var summary = trim(form.contentSummary.value)
	var filecontents = form.filecontents.value
	
	// Check the code field
	if (!isAlphaNumeric(code)){
		alert("The Code must contain letters and numbers only.")
		return false
	}
	if (code.length<codeminlength || code.length>codemaxlength){
		alert("The Code must be between "+codeminlength+" and "+codemaxlength+" characters long.")
		return false
	}
	
	// Check the title field
	if (invalidTitle(title)){
		alert("The Title must contain letters,numbers,spaces and any of '&()_-',' only.")
		return false
	}
	if (title.length<titleminlength){
		alert("The Title must be at least "+titleminlength+" characters long.")
		return false
	}
	
	// Check the TPIP year
	if(year==0){
		alert("Please choose the Year of completion.")
		return false
	}
	
	// Check the category
	var cnt=-1
	for (var i=categoryid.length-1; i > -1; i--) {
	   if (categoryid[i].checked) {cnt = i; i = -1;}
	}
   	if(cnt==-1){
		alert("Please choose a Category.")
		return false
	}
	
	// Check the summary
	if (summary.length<1){
		alert("Please enter a Summary.")
		return false
	}

	// Check the filecontents
	if(filecontents!=""){
		var fileext;
		filename = getFilenameFromPath(filecontents);
		fileext = getExtensionFromFilename(filename)
		if (!validateGlobalFileExtension(fileext)){
			alert("Please ensure that the file you are trying to upload is an Acrobat PDF, Word, Excel, Powerpoint document or a Zip file.")
			return false
		}
	
	}
	else{
		alert('Please select a file.')
		return false
	}
	
	return true
	
}
// Validates the c_purchasingguide_update_finish.cfm form
function checkPurchasingFinish(form){	
	var file = trim(form.filecontents.value)
	
	if (file == ""){
		alert("Please select a file to upload.")
		return false
	}
	if(!purchasingGuideUpload(file)){
		alert("The file type type must be 'pdf' or 'zip', please select another file to upload.")
		return false
	}
	
}

function checkPurchasingGuideInfo(form){
	
	var code =trim(form.trgpkCode.value);
	var importance = form.importance.value;
	var title = trim(form.contentTitle.value);
	var tpVersion = trim(form.tpVersion.value);

	var newTitle ;
	
 //
	resetErrorMessage();
	
	// Check the code field
	validateResourceCode(code);
	
	// Check the title field
	validateTitle(title);

   newTitle = formatPGTitle(title);
	
	//
	checkValidTpVersion(tpVersion);
	
	if(hasValue(errorMessage)){ 
	     showErrorMessage(); 
		 form.contentTitle.value = newTitle ;
			 return false
	}
 
	return true;
}  
function checkPGEditFinishedshedUpdateInfo(form){
	
	var dayValue = form.eventDay.value;   
	var monthValue = form.eventMonth.value; 
	var yearValue = form.eventYear.value;
	var dbdate = form.dbDate.value;
	var dbdate_disp = form.dbDate_display.value;
	
	
	var thisdate = new Date(yearValue,monthValue-1,dayValue).getTime();	
   // var thisdate2 = thisdate.getTime();
	
	 var thedbdate = new Date(dbdate).getTime();
	 
	

	resetErrorMessage();
	
     if (dateCompare(thisdate,thedbdate) == 1) setErrorMessage("The NTIS date must be before the TSN upload date ("+dbdate_disp+")");

	
	if(hasValue(errorMessage)){ 
	     showErrorMessage(); 
			 return false
	}
 
	
	return true;
}

function checkCurriculumEditFinishedUpdate(form){
	
	var dayValue = form.eventDay.value;   
	var monthValue = form.eventMonth.value; 
	var yearValue = form.eventYear.value;
	var dbdate = form.dbDate.value;
	var dbdate_disp = form.dbDate_display.value;
	
	
	var thisdate = new Date(yearValue,monthValue-1,dayValue).getTime();	
   // var thisdate2 = thisdate.getTime();
	
	 var thedbdate = new Date(dbdate).getTime();
	 
	

	resetErrorMessage();
	
     if (dateCompare(thisdate,thedbdate) == 1) setErrorMessage("The VRQA date must be before the TSN upload date ("+dbdate_disp+")");

	
	if(hasValue(errorMessage)){ 
	     showErrorMessage(); 
			 return false
	}
 
	
	return true;
}

// Validates the c_purchasingEdit.cfm form

function checkCurriculumPurchasingEdit(form){
	var title =  form.contentTitle.value
	var file = trim(form.filecontents.value)
	
	var imp = form.importance
	var desc = form.updatedescription.value
	
	
	if (file == ""){
		alert("Please select a file to upload.")
		return false
	}
	if(!validateFileExtension(file)){
		alert("The file type type must be 'pdf', please select another file to upload.")
		return false
	}
	var ok = -1
	for(var i=0; i<imp.length; i++){
		if (imp[i].checked){
			ok = i		
			break
		}
	}
	
	if (ok<0){
		alert("Please select a level of importance.")
		return false
	}
	else if (ok>0){
		if(desc==""){
			alert("Please enter a description of the update.")
			return false
		}
	}
	
	return true
}
// Validates the c_editOccupation form

function checkEditOccupation(form){
	
	var occupationName = form.occupationName.value;
	var licensingSector = form.licensingSector.value;
	var regulationName = form.regulationName.value;
	var qualificationName = form.qualificationName.value;
	//var additionalInformation = form.additionalInformation.value;

	if(trim(occupationName) == ""){
		alert("Please insert an occupation name.");
		return false ;
	}
	if(trim(regulationName) == ""  ){
		alert("Please insert a regulation name.");
		return false ;
	}		
	if(trim(qualificationName) == ""){
		alert("Please insert the qualification/course/unit of competency that is accepted by the regulator as meeting the requirements of the license, permit etc. If none available insert NIL.");
		return false ;
	}
		
	return true;
	
}
// Validates the c_addOccupation form

function checkAddOccupation(form){
	
	var occupationName = form.occupationName.value;
	var licensingSector = form.licensingSector.value;
	var regulationName = form.regulationName.value;
	var qualificationName = form.qualificationName.value;
	var additionalInfo = form.additionalInfo.value;

	if(trim(occupationName) == ""){		
		alert("Please insert an occupation name.");
		return false ;
	}
	
	if(trim(regulationName) == "" ){
		alert("Please insert a regulation name.");
		return false ;
	}	
	if(trim(qualificationName) == ""){
		alert("Please insert the qualification/course/unit of competency that is accepted by the regulator as meeting the requirements of the license, permit etc. If none available insert NIL.");
		return false ;
	}
		
	return true;
	
}

// Validates the c_addNewOccupation.cfm

function checkAddAuthority(form){
	
	var authorityName = form.authorityName.value;
	var webAddress = form.webAddress.value;
	//var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
	var urlRegxp = /^(http(s?):)+\/\/(([a-zA-Z0-9])+([a-zA-Z0-9\-])+\.)+([a-zA-Z])/;
	if(trim(authorityName) == ""){
		alert("Please insert the Responsible Government Department or Authority Name.");
		return false ;
	}
	if(trim(webAddress) == "" ){
		alert("Please insert the Responsible Government Department or Authority web Address.");
		return false ;
	}else{	
		var OK = urlRegxp.exec(webAddress);
		if (!OK){  
			alert("Please enter the valid Responsible Government Department or Authority web Address.");
			form.webAddress.focus();
			form.webAddress.select();
			return false; 
		}
	}
	
			
	return true;
	
}

// Validates the c_editOccupation.cfm

function checkEditAuthority(form){
	
	var authorityName = form.authorityName.value;
	var webAddress = form.webAddress.value;
	//var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}(\/[\w]+)+|\/$/;
	var urlRegxp = /^(http(s?):)+\/\/(([a-zA-Z0-9])+([a-zA-Z0-9\-])+\.)+([a-zA-Z])/;
	
	if(trim(authorityName) == ""){
		alert("Please enter the government department or authority name.");
		return false ;
	}
	if(trim(webAddress) == "" ){
		alert("Please insert the government department or authority web Address.");
		return false ;
	}else{	
		var OK = urlRegxp.exec(webAddress);
		if (!OK){  
			alert("Please enter a valid government department or authority web Address.");
			form.webAddress.focus();
			form.webAddress.select();
			return false; 
		}
	}
	return true;
	
}

// Validates the _cmm_report_date_filter.cfmform

function checkCmmReportDataForm(form){	
	//javascript is enabled in users browser
	form.jsEnabled.value =true;
	
	var startmonth = form.report_start_month_select.selectedIndex;
	var startyear = form.report_start_year_select.selectedIndex; 
	var endmonth =form.report_end_month_select.selectedIndex;
	var endyear = form.report_end_year_select.selectedIndex;
	
	
	
	resetErrorMessage();
	
	setErrorMessage(validateDateFilterSelection(startmonth,startyear,endmonth,endyear));
	
	if(hasValue(errorMessage)){ 
	     showErrorMessage(); 
			 return false
	}
 
	form.displayResult.value =true;
	
	return true ;
}
// Validates the _statistics_report_filter_template.cfm form

function checkDataForm(form){	
	
	/*var startmonth = form.startmonth.selectedIndex;
	var startyear = form.startyear.selectedIndex; 
	var endmonth =form.endmonth.selectedIndex;
	var endyear = form.endyear.selectedIndex;*/
	 var startingDate =form.startingDateSelect.selectedIndex;
	 var endingDate =form.endingDateSelect.selectedIndex;
	if (startingDate > endingDate){	
		alert("Please enter a valid date. \nThe end month should be greater than the start month \nThe end year should be greater than the start year.");
		return false ;
	}
	/*if (startmonth > endmonth  && startyear >endyear ){	
		alert("Please enter a valid date. \nThe end month should be greater than the start month \nThe end year should be greater than the start year.");
		return false ;
	}
	
	if (startyear == endyear && startmonth > endmonth ){	
		alert("Please enter a valid date. \nThe end month should be greater than the start month.");
		return false ;
	}
	
	if (startyear > endyear){	
		alert("Please enter a valid date. \nThe end year should be greater than the start year.");
		return false ;
	}*/
	
	form.displayResult.value =true;
	
	return true ;
}

/* Validates the file extensions before uploading in this case pdf
	when adding another extension make sure you change the message in 
	the checkCurriculumPurchasingEdit(form) function 
*/
function validateFileExtension(filename){
	
	var validExtension = new Array('pdf');	
	var fileExtension = getExtensionFromFilename(filename)
	
	
	for(var i=0 ; i<validExtension.length; i++){
		if(fileExtension == validExtension[i]){
			return true
		}	
	}
	
}
function purchasingGuideUpload(filename){
	
	var validExtension = new Array('pdf', 'zip');	
	var fileExtension = getExtensionFromFilename(filename)
	
	
	for(var i=0 ; i<validExtension.length; i++){
		if(fileExtension == validExtension[i]){
			return true
		}	
	}
	
	return false;
	
}
function validateGlobalFileExtension(fileext){
	if ((fileext == "pdf")||(fileext == "doc")||(fileext == "docx")||(fileext == "ppt") ||(fileext == "pptx")||(fileext == "pps")||(fileext == "xls")||(fileext == "xlsx")||(fileext == "zip")) return true;

	
	return false;
}

function validFilepath(filepath){
	
}

function invalidTitle(str){
	var validchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_()&-', "
	var isInvalid = false
	for (var i=0; i<str.length; i++){
		if (validchars.indexOf(str.charAt(i))<0){
			isInvalid = true
			//alert(str.charAt(i))
			//alert(str + " " + str.charAt(i))
			break
		}
	}
	return isInvalid
}

/**
validResourceCode
Teacher/Trainer resources

*/
function validateResourceCode(code){

			if (!isAlphaNumeric(code)){
				msg="The Code must contain letters and numbers only.";
				setErrorMessage(msg);				
			}
			if (code.length<codeminlength || code.length>codemaxlength){
					msg="The Code must be between "+codeminlength+" and "+codemaxlength+" characters long.";
				 setErrorMessage(msg);				
			}
		return;
}
/**
validResourceCode
Teacher/Trainer resources

*/
function validateTitle(title){
	   //if it has invalid characters
		if (invalidTitle(title)){
				 msg="The Title must contain letters,numbers,spaces and any of '&()_-',' only.";
				 setErrorMessage(msg);
			
			}
	    //Too short		
		if ( title.length<titleminlength){
					msg="The Title must be at least "+titleminlength+" characters long.";
					setErrorMessage(msg);
				
		}
		
		return;
}
//Contains training packag, purchasing guides
function formatPGTitle(title){
	 var matchResult = new Array();
	 var pattern = /training package|purchasing guide/gi;
	
	
	 if( pattern.test(title)){
  		  msg="The title should not include the phrase 'training package' or 'purchasing guide'.";
		  setErrorMessage(msg);
		  
	      return trim(title.replace(pattern, ''));
	 }
     
	return title;
}
/**
validateResourceCategory
Teacher/Trainer resources
 <category> radio button select
*/
function validateResourceCategory(category){
  	
	 if( !isSelectChecked(category)){
			msg="Please choose a Category.";
			setErrorMessage(msg);		
	}
	
	return;
}
/**
 isSelectChecked
 returns true, if an option is checked
 **/
function isSelectChecked(optionSelector){
	
	for (var i=optionSelector.length-1; i > -1; i--) {
	   if (optionSelector[i].checked)  return true;
	}
	
	return false;
}
/**
  validateTextContent
	<str> the text content of a text area. input, etc ...
	<msg> The informatio/ error messsge to display
*/
function validateTextContent(str,msg){
	
	if(!hasValue(str)){
			setErrorMessage(msg);		 
	 }
	 
	 return;
}

/**
hasValue
Checks if varialble is not empty
*/
function hasValue(str){
	var temp = trim(str);
	if(temp.length < 1) return false;
	
	return true;
}

/**
hasValue
Checks if varialble is not empty
*/
function hasItem(theArray){

	if(theArray.length >0) return true;
	
	return false;
}
/** VALIDATE FEDBACK FORM*****************/
function checkFeedackForm(form){
	// Form variables to check
	var answer1 = trim(form.txtAnswer1.value)
	var answer2 = trim(form.txtAnswer2.value)
	var answer3 = trim(form.txtAnswer3.value)
	var answer4= trim(form.txtAnswer4.value)
	var answer5 = trim(form.txtAnswer5.value)
	
	// variables
	var msg = ""
	
	// Validate firstname ------------------------------------------------
	if (answer1.length == 0 && answer2.length == 0 && answer3.length == 0 && answer4.length == 0 && answer5.length == 0 ){
		alert("The feedback form is empty.\n You have to answer one of the questions before submitting.");
		return false;		
	}	
		return false;
	
}

/**
setErrorMessage
**/
function setErrorMessage(message){
	
	if(errorMessage.length > 0) errorMessage +="\n";

  errorMessage += message
	
}
/**
resetErrorMessage
**/
function resetErrorMessage(){

     errorMessage="";

}
/**
showErrorMessage
**/
function showErrorMessage(){
	if(hasValue(errorMessage))	alert(errorMessage);	
	
	return;
	
}
/**
displayErrorOnPage
**/
function displayErrorOnPage(intructTxt,msgArray,containerID){
	
	var instructions=intructTxt;
	
	var txt ="<p>"+ instructions +"<p>" ;
	
	txt +="<ul>";
	
	for (var i=0; i<msgArray.length;i++){
		
		txt += "<li>"+msgArray[i].msg+"</li>";
	
		markErrorLabel(getLabelId(getIntfromString(msgArray[i].id)));
	}
		txt +="</ul>";
		
		$(containerID).html(txt);
    $(containerID).css( { "display":'block'});
	
}
/**
displayErrorOnPage
**/
function hideErrorOnPage(containerID){	

    $(containerID).css( { "display":'none'});
	
}

function getLabelId(int){
	return '#lbl'+int;
}
/**
Mark red
**/
function markErrorLabel(lblID){	
		$(lblID).addClass("error_");	
}
/**
Mark red
**/
function unmarkErrorLabel(lblID){	
		$(lblID).removeClass("error_");	
}
/**
Returns one match
To return more than one use m as an array <m[0]>
**/
function getIntfromString(str){
	//var re = new RegExp(/^\d+/); //starts with digit, one or more

	var re = new RegExp(/\d+/); //find a digit //
  var m = re.exec(str);

 return m;

}


/**
Contact us / Helpdesk
**/
function checkHelpDeskForm(form){
	/*alert(form);*/	
	var error_messsage= new Array();

	var name = form.name.value;
	//removes the error css class
	unmarkErrorLabel(getLabelId(getIntfromString(form.name.id)));
	if (!hasValue(form.name.value)) error_messsage.push({id:form.name.id,msg:"Please enter your name / Organization.\n"}) ;
		
	var phone = form.phone.value;	
		unmarkErrorLabel(getLabelId(getIntfromString(form.phone.id)));
	if (hasValue(phone)){
		var phoneChk=checkPhoneNumber(phone);
		if(phoneChk != true)  error_messsage.push({id:form.phone.id,msg:phoneChk});			
	}

  var email = checkEmailHelp(form.useremail.value);
	unmarkErrorLabel(getLabelId(getIntfromString(form.useremail.id)));
	if (email !=true) error_messsage.push({id:form.useremail.id,msg:email});		
	
	var postcode =  form.postcode.value;
	unmarkErrorLabel(getLabelId(getIntfromString(form.postcode.id)));
	
	if (hasValue(postcode) && !isInteger(postcode))	error_messsage.push({id:form.postcode.id,msg:"Please enter a valid postcode."});		
			
	
   var area = checkProblemArea(form.problem_area);	 
	 unmarkErrorLabel(getLabelId(getIntfromString(form.problem_area.id)));
		if (!area) error_messsage.push({id:form.problem_area.id,msg:"Please select the area where the area error/problem occured.\n"});
	
	/**This the form message text area*/
   var message = form.message.value;	 	
	 unmarkErrorLabel(getLabelId(getIntfromString(form.message.id)));
	if(!hasValue(message)) error_messsage.push({id:form.message.id,msg:"Please enter Comments / Error messages.\n"});		
	
	
	if(hasItem(error_messsage)){		
		var instructions= 'There were errors submitting the form. Please correct the marked fields and try again.\n '
		displayErrorOnPage(instructions,error_messsage,'#corresp_err');
		return false;
		
	}else{
		
		hideErrorOnPage('#corresp_err');
		return true;
		
	}
	
	
}

function checkProblemArea(selectList){
	var x =selectList.options[selectList.selectedIndex].value
	var y = trim(x)=="dummy" ? false : true
	if (!y){
	/*	alert("Please select the area where the area error/problem occured occurred.")*/
		return false
	}
	else{
		return true  
	}
}
function isValidPhoneNumber(phone){
	
	if ((phone ==null)||(phone =="")){
		/*alert("Please Enter your Phone Number")*/
			return false
	}
	if (checkInternationalPhone(phone)==false){
	/*	alert("Please Enter a Valid Phone Number")*/
				return false
	}
	return true
 }
 
 function checkPhoneNumber(phone){
	
	if ((phone ==null)||(phone =="")){
				return "Please Enter your Phone Number";
	}

		if (!isPhoneNumber(phone) && !checkInternationalPhone(phone)  ){
				return "Please Enter a Valid Phone Number";
		}
	
	
	return true
 }
 
 /**
**/
function checkValidTpVersion(str){
	
	if (!hasValue(str)) {
					msg="Please enter the Training Package version number.";
				 setErrorMessage(msg);
	}else	if (!isValidTpVersion(str)){
			msg="Please enter a valid Training Package version number. e.g. 2.0 ";
		 setErrorMessage(msg);
	}
								
	return true;
	
}










