function isDate(d){
var checkstr = "0123456789";
var DateField = d
var Datevalue = "";
var DateTemp = "";
var seperator = ".";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
err = 0;

  DateValue = d;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;

date_parts=d.split("/")
	
if(date_parts.length!=3)
	return false
	
month		= parseInt(date_parts[0], 10)
day		= parseInt(date_parts[1], 10)
year		= parseInt(date_parts[2], 10)

  if (!isNumber(month)){
     err = 50;
  }
  if (!isNumber(day)){
     err = 51;
  }

  if (!isNumber(year)){
     err = 52;
  }


   /* year is wrong if year = 0000 */

   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/

   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/

   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      return true
   }
   /* Error-message if err != 0 */
   else {
     return false
   }

}

//Check for a valid number
function isNumber(inputVal){
	oneDecimal=false
	inputStr=inputVal.toString()
	for(var i = 0; i < inputStr.length; i++){
		var oneChar=inputStr.charAt(i)
		if(i==0&&oneChar=="-")
			continue
		if(oneChar=="."&&!oneDecimal){
			oneDecimal=true
			continue
		}
		if(oneChar<"0" || oneChar > "9")
			return false
	}
	return true
}




function isInteger(inputVal){
	var inputStr
	inputStr=inputVal.toString()
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if (i == 0 && oneChar == "-") {
			continue
		}
		if (oneChar < "0" || oneChar > "9") {
			return false
		}
	}
	return true
}

function doValidate(f){
		
		if(f.start_month.value==""){
			alert("Please enter a Month for the Start Date.")
			f.start_month.focus()
			return(0)
		}
		if(f.start_month.value > 12 || f.start_month.value < 1 ){
			alert("Please enter a valid Month for the Start Date.")
			f.start_month.focus()
			return(0)
		}
		if(!isInteger(f.start_month.value)){
			alert("Please enter only digits in the Month field for the Start Date.")
			f.start_month.focus()
			return(0)
		}


		if(f.start_day.value==""){
			alert("Please enter a Day for the Start Date.")
			f.start_day.focus()
			return(0)
		}
		if(f.start_day.value > 31 || f.start_day.value < 1 ){
			alert("Please enter a valid Day for the Start Date.")
			f.start_day.focus()
			return(0)
		}
		if(!isInteger(f.start_day.value)){
			alert("Please enter only digits in the Day field for the Start Date.")
			f.start_day.focus()
			return(0)
		}

		
		if(f.start_year.value==""){
			alert("Please enter a Year for the Start Date.")
			f.start_year.focus()
			return(0)
		}
		if(!isInteger(f.start_year.value)){
			alert("Please enter only digits in the Year field for the Start Date.")
			f.start_year.focus()
			return(0)
		}

		if(!isDate(f.start_month.value+"/"+f.start_day.value+"/"+f.start_year.value)){
			alert("Please enter a valid date for the Start Date.")
			f.start_month.focus()
			return(0)
		}

		if(f.end_month.value==""){
			alert("Please enter a month for the End Date.")
			f.end_month.focus()
			return(0)
		}
		if(f.end_month.value > 12 || f.end_month.value < 1 ){
			alert("Please enter a valid Month for the End Date.")
			f.end_month.focus()
			return(0)
		}
		if(!isInteger(f.end_month.value)){
			alert("Please enter only digits in the Month field for the End Date.")
			f.end_month.focus()
			return(0)
		}


		if(f.end_day.value==""){
			alert("Please enter a Day for the End Date.")
			f.end_day.focus()
			return(0)
		}
		if(f.end_day.value > 31 || f.end_day.value < 1 ){
			alert("Please enter a valid Day for the End Date.")
			f.end_day.focus()
			return(0)
		}
		if(!isInteger(f.end_day.value)){
			alert("Please enter only digits in the Day field for the End Date.")
			f.end_day.focus()
			return(0)
		}

		
		if(f.end_year.value==""){
			alert("Please enter a Year for the End Date.")
			f.end_year.focus()
			return(0)
		}
		if(!isInteger(f.end_year.value)){
			alert("Please enter only digits in the Year field for the End Date.")
			f.end_year.focus()
			return(0)
		}

		if(!isDate(f.end_month.value+"/"+f.end_day.value+"/"+f.end_year.value)){
			alert("Please enter a valid date for the End Date.")
			f.end_month.focus()
			return(0)
		}
		
		if(f.title.value==""){
			alert("Please enter a Title.")
			f.title.focus()
			return(0)
		}

		if (f.title.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Title field.')
			f.title.focus()
			return(0)
		}

		if (f.description.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Description field.')
			f.description.focus()
			return(0)
		}
		
		if (f.cost.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Cost field.')
			f.cost.focus()
			return(0)
		}
		
		if (f.cost_notes.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Cost Notes field.')
			f.cost_notes.focus()
			return(0)
		}
		
		if (f.schedule.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Schedule field.')
			f.schedule.focus()
			return(0)
		}

		if (f.special_notes.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Special Notes field.')
			f.special_notes.focus()
			return(0)
		}

		if (f.location_business.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Location Business/Building field.')
			f.location_business.focus()
			return(0)
		}

		if (f.location_address.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Location Address field.')
			f.location_address.focus()
			return(0)
		}
		if ((f.presenter1_name.value=="" && f.presenter1_company.value=="") && (f.presenter2_name.value!="" || f.presenter2_company.value!="")) {
			alert('You must enter a #1 Presenter')
			f.presenter1_name.focus()
			return(0)
		}

		if (f.presenter1_name.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the #1 Presenter Name field.')
			f.presenter1_name.focus()
			return(0)
		}

		if (f.presenter1_company.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the #1 Presenter Company field.')
			f.presenter1_company.focus()
			return(0)
		}
		if (f.presenter2_name.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the #2 Presenter Name field.')
			f.presenter2_name.focus()
			return(0)
		}

		if (f.presenter2_company.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the #2 Presenter Company field.')
			f.presenter2_company.focus()
			return(0)
		}
		
		if ((f.documentupload1.value=="") && (f.attachment1_caption.value!="")){
			alert('You must have an attachment uploaded if you have a caption, please upload Document #1 or remove Caption #1.')
			f.attachment1_caption.focus()
			return(0)
		}
		
		if ((f.documentupload2.value=="") && (f.attachment2_caption.value!="")){
			alert('You must have an attachment uploaded if you have a caption, please upload Document #2 or remove Caption #2.')
			f.attachment2_caption.focus()
			return(0)
		}
		
		if ((f.documentupload3.value=="") && (f.attachment3_caption.value!="")){
			alert('You must have an attachment uploaded if you have a caption, please upload Document #3 or remove Caption #3.')
			f.attachment3_caption.focus()
			return(0)
		}

		if (f.contact_name.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Contact Name field.')
			f.contact_name.focus()
			return(0)
		}

		if (f.contact_phone.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Contact Phone field.')
			f.contact_phone.focus()
			return(0)
		}

		if (f.contact_email.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Contact Email field.')
			f.contact_email.focus()
			return(0)
		}

		if (f.info_link.value.indexOf('"')!=-1){
			alert('Please remove the double quotes from the Contact Website Link field.')
			f.info_link.focus()
			return(0)
		}
		f.submit()
	}

